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/>. */
23 #include "emacsgtkfixed.h"
33 struct _EmacsFixedPrivate
39 static void emacs_fixed_get_preferred_width (GtkWidget
*widget
,
42 static void emacs_fixed_get_preferred_height (GtkWidget
*widget
,
45 G_DEFINE_TYPE (EmacsFixed
, emacs_fixed
, GTK_TYPE_FIXED
)
48 /* void aloc_callback(GtkWidget* child, GtkWidget* fixed){ */
49 /* GtkAllocation child_allocation; */
50 /* GtkRequisition child_requisition; */
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)); */
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 */
68 struct GtkFixedPrivateL
73 static void emacs_fixed_gtk_widget_size_allocate (GtkWidget
*widget
,
74 GtkAllocation
*allocation
){
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
,
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, */
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
;
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
),
119 for (children
= priv
->children
;
121 children
= children
->next
)
123 child
= children
->data
;
125 if (!gtk_widget_get_visible (child
->widget
))
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));
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
);
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
;
174 widget_class
->size_allocate
= emacs_fixed_gtk_widget_size_allocate
;
176 g_type_class_add_private (klass
, sizeof (EmacsFixedPrivate
));
180 emacs_fixed_child_type (GtkFixed
*container
)
182 return GTK_TYPE_WIDGET
;
186 emacs_fixed_init (EmacsFixed
*fixed
)
188 fixed
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (fixed
, EMACS_TYPE_FIXED
,
196 * Creates a new #EmacsFixed.
198 * Returns: a new #EmacsFixed.
201 emacs_fixed_new (struct frame
*f
)
203 EmacsFixed
*fixed
= g_object_new (EMACS_TYPE_FIXED
, NULL
);
204 EmacsFixedPrivate
*priv
= fixed
->priv
;
206 return GTK_WIDGET (fixed
);
210 emacs_fixed_get_preferred_width (GtkWidget
*widget
,
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
;
222 emacs_fixed_get_preferred_height (GtkWidget
*widget
,
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. */
239 XSetWMSizeHints(Display
* d
,
244 struct x_display_info
*dpyinfo
= x_display_info_for_display (d
);
245 struct frame
*f
= x_top_window_to_frame (dpyinfo
, w
);
247 data
[0] = hints
->flags
;
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
;
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
283 XSetWMNormalHints (Display
*d
, Window w
, XSizeHints
*hints
)
285 XSetWMSizeHints (d
, w
, hints
, XA_WM_NORMAL_HINTS
);