ifdef guarding of xwidget code. not complete
[emacs.git] / src / emacsgtkfixed.c
blob34daab7285fec6b64bd782357b37a8d3a83e587b
1 /* A Gtk Widget that inherits GtkFixed, but can be shrinked.
2 This file is only use when compiling with Gtk+ 3.
4 Copyright (C) 2011 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 #include <config.h>
23 #include "emacsgtkfixed.h"
24 #include <signal.h>
25 #include <stdio.h>
26 #include <setjmp.h>
27 #include "lisp.h"
28 #include "frame.h"
29 #include "xterm.h"
30 #ifdef HAVE_XWIDGETS
31 #include "xwidget.h"
32 #endif
33 struct _EmacsFixedPrivate
35 struct frame *f;
39 static void emacs_fixed_get_preferred_width (GtkWidget *widget,
40 gint *minimum,
41 gint *natural);
42 static void emacs_fixed_get_preferred_height (GtkWidget *widget,
43 gint *minimum,
44 gint *natural);
45 G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
47 #ifdef HAVE_XWIDGETS
48 /* void aloc_callback(GtkWidget* child, GtkWidget* fixed){ */
49 /* GtkAllocation child_allocation; */
50 /* GtkRequisition child_requisition; */
52 /* //TODO */
53 /* // if child is an xwidget, find its clipping area and modify allocation */
55 /* struct xwidget_view* xv = (struct xwidget_viev*) g_object_get_data (G_OBJECT (child), XG_XWIDGET_VIEW); */
56 /* printf("aloc callback %d %s\n", xv, gtk_widget_get_name(child)); */
57 /* if(xv){ */
58 /* printf(" allocation modification for xw\n"); */
59 /* gtk_widget_get_allocation(child, &child_allocation); */
60 /* child_allocation.width = xv->clip_right; */
61 /* child_allocation.height = xv->clip_bottom - xv->clip_top; */
62 /* gtk_widget_size_allocate (child, &child_allocation); */
63 /* //TODO find a way to remove this feeble workaround */
64 /* } */
66 /* } */
68 struct GtkFixedPrivateL
70 GList *children;
73 static void emacs_fixed_gtk_widget_size_allocate (GtkWidget *widget,
74 GtkAllocation *allocation){
75 //for xwidgets
78 //TODO 1st call base class method
79 EmacsFixedClass *klass;
80 GtkWidgetClass *parent_class;
81 struct GtkFixedPrivateL* priv;
83 printf(" emacs_fixed_gtk_widget_size_allocate\n");
84 klass = EMACS_FIXED_GET_CLASS (widget);
85 parent_class = g_type_class_peek_parent (klass);
86 parent_class->size_allocate (widget, allocation);
88 priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
89 GTK_TYPE_FIXED,
90 struct GtkFixedPrivateL);
91 //fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, GTK_TYPE_FIXED, GtkFixedPrivate);
92 //then modify allocations
93 /* gtk_container_foreach (widget, */
94 /* aloc_callback, */
95 /* widget); */
97 //begin copy paste extravaganza!!!
99 //GtkFixed *fixed = GTK_FIXED (widget);
100 //GtkFixedPrivate *priv = fixed->priv;
101 GtkFixedChild *child;
102 GtkAllocation child_allocation;
103 GtkRequisition child_requisition;
104 GList *children;
107 gtk_widget_set_allocation (widget, allocation);
109 if (gtk_widget_get_has_window (widget))
111 if (gtk_widget_get_realized (widget))
112 gdk_window_move_resize (gtk_widget_get_window (widget),
113 allocation->x,
114 allocation->y,
115 allocation->width,
116 allocation->height);
119 for (children = priv->children;
120 children;
121 children = children->next)
123 child = children->data;
125 if (!gtk_widget_get_visible (child->widget))
126 continue;
128 gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
129 child_allocation.x = child->x;
130 child_allocation.y = child->y;
132 if (!gtk_widget_get_has_window (widget))
134 child_allocation.x += allocation->x;
135 child_allocation.y += allocation->y;
138 child_allocation.width = child_requisition.width;
139 child_allocation.height = child_requisition.height;
143 struct xwidget_view* xv = (struct xwidget_viev*) g_object_get_data (G_OBJECT (child->widget), XG_XWIDGET_VIEW);
144 //printf("aloc callback %d %s\n", xv, gtk_widget_get_name(child));
145 if(xv){
146 //gtk_widget_get_allocation(child, &child_allocation);
147 child_allocation.width = xv->clip_right;
148 child_allocation.height = xv->clip_bottom - xv->clip_top;
149 //gtk_widget_size_allocate (child, &child_allocation);
150 //TODO find a way to remove this feeble workaround
151 printf(" allocation internal modification for xw %d %d,%d\n",xv, child_allocation.width, child_allocation.height);
154 gtk_widget_size_allocate (child->widget, &child_allocation);
160 #endif
162 static void
163 emacs_fixed_class_init (EmacsFixedClass *klass)
165 GtkWidgetClass *widget_class;
166 GtkFixedClass *fixed_class;
168 widget_class = (GtkWidgetClass*) klass;
169 fixed_class = (GtkFixedClass*) klass;
171 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
172 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
173 #ifdef HAVE_XWIDGETS
174 widget_class->size_allocate = emacs_fixed_gtk_widget_size_allocate;
175 #endif
176 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
179 static GType
180 emacs_fixed_child_type (GtkFixed *container)
182 return GTK_TYPE_WIDGET;
185 static void
186 emacs_fixed_init (EmacsFixed *fixed)
188 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED,
189 EmacsFixedPrivate);
190 fixed->priv->f = 0;
194 * emacs_fixed_new:
196 * Creates a new #EmacsFixed.
198 * Returns: a new #EmacsFixed.
200 GtkWidget*
201 emacs_fixed_new (struct frame *f)
203 EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL);
204 EmacsFixedPrivate *priv = fixed->priv;
205 priv->f = f;
206 return GTK_WIDGET (fixed);
209 static void
210 emacs_fixed_get_preferred_width (GtkWidget *widget,
211 gint *minimum,
212 gint *natural)
214 EmacsFixed *fixed = EMACS_FIXED (widget);
215 EmacsFixedPrivate *priv = fixed->priv;
216 int w = priv->f->output_data.x->size_hints.min_width;
217 if (minimum) *minimum = w;
218 if (natural) *natural = w;
221 static void
222 emacs_fixed_get_preferred_height (GtkWidget *widget,
223 gint *minimum,
224 gint *natural)
226 EmacsFixed *fixed = EMACS_FIXED (widget);
227 EmacsFixedPrivate *priv = fixed->priv;
228 int h = priv->f->output_data.x->size_hints.min_height;
229 if (minimum) *minimum = h;
230 if (natural) *natural = h;
234 /* Override the X function so we can intercept Gtk+ 3 calls.
235 Use our values for min_width/height so that KDE don't freak out
236 (Bug#8919), and so users can resize our frames as they wish. */
238 void
239 XSetWMSizeHints(Display* d,
240 Window w,
241 XSizeHints* hints,
242 Atom prop)
244 struct x_display_info *dpyinfo = x_display_info_for_display (d);
245 struct frame *f = x_top_window_to_frame (dpyinfo, w);
246 long data[18];
247 data[0] = hints->flags;
248 data[1] = hints->x;
249 data[2] = hints->y;
250 data[3] = hints->width;
251 data[4] = hints->height;
252 data[5] = hints->min_width;
253 data[6] = hints->min_height;
254 data[7] = hints->max_width;
255 data[8] = hints->max_height;
256 data[9] = hints->width_inc;
257 data[10] = hints->height_inc;
258 data[11] = hints->min_aspect.x;
259 data[12] = hints->min_aspect.y;
260 data[13] = hints->max_aspect.x;
261 data[14] = hints->max_aspect.y;
262 data[15] = hints->base_width;
263 data[16] = hints->base_height;
264 data[17] = hints->win_gravity;
266 if ((hints->flags & PMinSize) && f)
268 int w = f->output_data.x->size_hints.min_width;
269 int h = f->output_data.x->size_hints.min_height;
270 data[5] = w;
271 data[6] = h;
274 XChangeProperty (d, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace,
275 (unsigned char *) data, 18);
278 /* Override this X11 function.
279 This function is in the same X11 file as the one above. So we must
280 provide it also. */
282 void
283 XSetWMNormalHints (Display *d, Window w, XSizeHints *hints)
285 XSetWMSizeHints (d, w, hints, XA_WM_NORMAL_HINTS);