futile allocation hacks
[emacs.git] / src / emacsgtkfixed.c
blob9b10957f583336475e9b7546069cd638e648b085
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 #include "xwidget.h"
31 struct _EmacsFixedPrivate
33 struct frame *f;
37 static void emacs_fixed_get_preferred_width (GtkWidget *widget,
38 gint *minimum,
39 gint *natural);
40 static void emacs_fixed_get_preferred_height (GtkWidget *widget,
41 gint *minimum,
42 gint *natural);
43 G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
45 /* void aloc_callback(GtkWidget* child, GtkWidget* fixed){ */
46 /* GtkAllocation child_allocation; */
47 /* GtkRequisition child_requisition; */
49 /* //TODO */
50 /* // if child is an xwidget, find its clipping area and modify allocation */
52 /* struct xwidget_view* xv = (struct xwidget_viev*) g_object_get_data (G_OBJECT (child), XG_XWIDGET_VIEW); */
53 /* printf("aloc callback %d %s\n", xv, gtk_widget_get_name(child)); */
54 /* if(xv){ */
55 /* printf(" allocation modification for xw\n"); */
56 /* gtk_widget_get_allocation(child, &child_allocation); */
57 /* child_allocation.width = xv->clip_right; */
58 /* child_allocation.height = xv->clip_bottom - xv->clip_top; */
59 /* gtk_widget_size_allocate (child, &child_allocation); */
60 /* //TODO find a way to remove this feeble workaround */
61 /* } */
63 /* } */
65 struct GtkFixedPrivateL
67 GList *children;
70 static void emacs_fixed_gtk_widget_size_allocate (GtkWidget *widget,
71 GtkAllocation *allocation){
72 //for xwidgets
75 //TODO 1st call base class method
76 EmacsFixedClass *klass;
77 GtkWidgetClass *parent_class;
78 struct GtkFixedPrivateL* priv;
80 printf(" emacs_fixed_gtk_widget_size_allocate\n");
81 klass = EMACS_FIXED_GET_CLASS (widget);
82 parent_class = g_type_class_peek_parent (klass);
83 parent_class->size_allocate (widget, allocation);
85 priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
86 GTK_TYPE_FIXED,
87 struct GtkFixedPrivateL);
88 //fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, GTK_TYPE_FIXED, GtkFixedPrivate);
89 //then modify allocations
90 /* gtk_container_foreach (widget, */
91 /* aloc_callback, */
92 /* widget); */
94 //begin copy paste extravaganza!!!
96 //GtkFixed *fixed = GTK_FIXED (widget);
97 //GtkFixedPrivate *priv = fixed->priv;
98 GtkFixedChild *child;
99 GtkAllocation child_allocation;
100 GtkRequisition child_requisition;
101 GList *children;
104 gtk_widget_set_allocation (widget, allocation);
106 if (gtk_widget_get_has_window (widget))
108 if (gtk_widget_get_realized (widget))
109 gdk_window_move_resize (gtk_widget_get_window (widget),
110 allocation->x,
111 allocation->y,
112 allocation->width,
113 allocation->height);
116 for (children = priv->children;
117 children;
118 children = children->next)
120 child = children->data;
122 if (!gtk_widget_get_visible (child->widget))
123 continue;
125 gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
126 child_allocation.x = child->x;
127 child_allocation.y = child->y;
129 if (!gtk_widget_get_has_window (widget))
131 child_allocation.x += allocation->x;
132 child_allocation.y += allocation->y;
135 child_allocation.width = child_requisition.width;
136 child_allocation.height = child_requisition.height;
140 struct xwidget_view* xv = (struct xwidget_viev*) g_object_get_data (G_OBJECT (child->widget), XG_XWIDGET_VIEW);
141 //printf("aloc callback %d %s\n", xv, gtk_widget_get_name(child));
142 if(xv){
143 //gtk_widget_get_allocation(child, &child_allocation);
144 child_allocation.width = xv->clip_right;
145 child_allocation.height = xv->clip_bottom - xv->clip_top;
146 //gtk_widget_size_allocate (child, &child_allocation);
147 //TODO find a way to remove this feeble workaround
148 printf(" allocation internal modification for xw %d %d,%d\n",xv, child_allocation.width, child_allocation.height);
151 gtk_widget_size_allocate (child->widget, &child_allocation);
159 static void
160 emacs_fixed_class_init (EmacsFixedClass *klass)
162 GtkWidgetClass *widget_class;
163 GtkFixedClass *fixed_class;
165 widget_class = (GtkWidgetClass*) klass;
166 fixed_class = (GtkFixedClass*) klass;
168 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
169 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
170 widget_class->size_allocate = emacs_fixed_gtk_widget_size_allocate;
171 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
174 static GType
175 emacs_fixed_child_type (GtkFixed *container)
177 return GTK_TYPE_WIDGET;
180 static void
181 emacs_fixed_init (EmacsFixed *fixed)
183 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED,
184 EmacsFixedPrivate);
185 fixed->priv->f = 0;
189 * emacs_fixed_new:
191 * Creates a new #EmacsFixed.
193 * Returns: a new #EmacsFixed.
195 GtkWidget*
196 emacs_fixed_new (struct frame *f)
198 EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL);
199 EmacsFixedPrivate *priv = fixed->priv;
200 priv->f = f;
201 return GTK_WIDGET (fixed);
204 static void
205 emacs_fixed_get_preferred_width (GtkWidget *widget,
206 gint *minimum,
207 gint *natural)
209 EmacsFixed *fixed = EMACS_FIXED (widget);
210 EmacsFixedPrivate *priv = fixed->priv;
211 int w = priv->f->output_data.x->size_hints.min_width;
212 if (minimum) *minimum = w;
213 if (natural) *natural = w;
216 static void
217 emacs_fixed_get_preferred_height (GtkWidget *widget,
218 gint *minimum,
219 gint *natural)
221 EmacsFixed *fixed = EMACS_FIXED (widget);
222 EmacsFixedPrivate *priv = fixed->priv;
223 int h = priv->f->output_data.x->size_hints.min_height;
224 if (minimum) *minimum = h;
225 if (natural) *natural = h;
229 /* Override the X function so we can intercept Gtk+ 3 calls.
230 Use our values for min_width/height so that KDE don't freak out
231 (Bug#8919), and so users can resize our frames as they wish. */
233 void
234 XSetWMSizeHints(Display* d,
235 Window w,
236 XSizeHints* hints,
237 Atom prop)
239 struct x_display_info *dpyinfo = x_display_info_for_display (d);
240 struct frame *f = x_top_window_to_frame (dpyinfo, w);
241 long data[18];
242 data[0] = hints->flags;
243 data[1] = hints->x;
244 data[2] = hints->y;
245 data[3] = hints->width;
246 data[4] = hints->height;
247 data[5] = hints->min_width;
248 data[6] = hints->min_height;
249 data[7] = hints->max_width;
250 data[8] = hints->max_height;
251 data[9] = hints->width_inc;
252 data[10] = hints->height_inc;
253 data[11] = hints->min_aspect.x;
254 data[12] = hints->min_aspect.y;
255 data[13] = hints->max_aspect.x;
256 data[14] = hints->max_aspect.y;
257 data[15] = hints->base_width;
258 data[16] = hints->base_height;
259 data[17] = hints->win_gravity;
261 if ((hints->flags & PMinSize) && f)
263 int w = f->output_data.x->size_hints.min_width;
264 int h = f->output_data.x->size_hints.min_height;
265 data[5] = w;
266 data[6] = h;
269 XChangeProperty (d, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace,
270 (unsigned char *) data, 18);
273 /* Override this X11 function.
274 This function is in the same X11 file as the one above. So we must
275 provide it also. */
277 void
278 XSetWMNormalHints (Display *d, Window w, XSizeHints *hints)
280 XSetWMSizeHints (d, w, hints, XA_WM_NORMAL_HINTS);