]>
Commit | Line | Data |
---|---|---|
c67daf87 | 1 | /* /////////////////////////////////////////////////////////////////////////// |
0ba6a836 | 2 | // Name: src/gtk/win_gtk.c |
77ffb593 | 3 | // Purpose: Native GTK+ widget for wxWidgets, based on GtkLayout and |
ed673c6a RR |
4 | // GtkFixed. It makes use of the gravity window property and |
5 | // therefore does not work with GTK 1.0. | |
c801d85f | 6 | // Author: Robert Roebling |
c67d8618 | 7 | // Id: $Id$ |
01111366 | 8 | // Copyright: (c) 1998 Robert Roebling |
77ffb593 | 9 | // Licence: wxWidgets licence |
c67daf87 | 10 | /////////////////////////////////////////////////////////////////////////// */ |
c801d85f | 11 | |
d02af7bb JJ |
12 | #ifdef VMS |
13 | #define XCheckIfEvent XCHECKIFEVENT | |
3fa056ab | 14 | #endif |
27df579a | 15 | |
79918119 | 16 | #include "wx/platform.h" |
27df579a | 17 | #include "wx/gtk/win_gtk.h" |
38c7b3d3 | 18 | |
c801d85f KB |
19 | #ifdef __cplusplus |
20 | extern "C" { | |
21 | #endif /* __cplusplus */ | |
22 | ||
91641d04 PC |
23 | typedef struct _GtkPizzaChild GtkPizzaChild; |
24 | typedef struct _GtkPizzaClass GtkPizzaClass; | |
da048e3d | 25 | typedef struct _GtkPizzaAdjData GtkPizzaAdjData; |
ed673c6a | 26 | |
91641d04 PC |
27 | struct _GtkPizzaClass |
28 | { | |
29 | GtkContainerClass parent_class; | |
30 | ||
31 | void (*set_scroll_adjustments) (GtkPizza *pizza, | |
32 | GtkAdjustment *hadjustment, | |
33 | GtkAdjustment *vadjustment); | |
34 | }; | |
35 | ||
36 | struct _GtkPizzaChild | |
37 | { | |
38 | GtkWidget *widget; | |
39 | gint x; | |
40 | gint y; | |
41 | }; | |
42 | ||
bf3dab48 | 43 | struct _GtkPizzaAdjData |
ed673c6a RR |
44 | { |
45 | gint dx; | |
46 | gint dy; | |
47 | }; | |
48 | ||
b6fa52db RR |
49 | static void gtk_pizza_class_init (GtkPizzaClass *klass); |
50 | static void gtk_pizza_init (GtkPizza *pizza); | |
ed673c6a | 51 | |
b6fa52db RR |
52 | static void gtk_pizza_realize (GtkWidget *widget); |
53 | static void gtk_pizza_unrealize (GtkWidget *widget); | |
ed673c6a | 54 | |
b6fa52db | 55 | static void gtk_pizza_map (GtkWidget *widget); |
ed673c6a | 56 | |
da048e3d | 57 | static void gtk_pizza_size_request (GtkWidget *widget, |
bf3dab48 | 58 | GtkRequisition *requisition); |
da048e3d | 59 | static void gtk_pizza_size_allocate (GtkWidget *widget, |
bf3dab48 | 60 | GtkAllocation *allocation); |
22aff579 VS |
61 | static void gtk_pizza_style_set (GtkWidget *widget, |
62 | GtkStyle *previous_style); | |
da048e3d | 63 | static void gtk_pizza_add (GtkContainer *container, |
bf3dab48 | 64 | GtkWidget *widget); |
da048e3d | 65 | static void gtk_pizza_remove (GtkContainer *container, |
bf3dab48 | 66 | GtkWidget *widget); |
b6fa52db RR |
67 | static void gtk_pizza_forall (GtkContainer *container, |
68 | gboolean include_internals, | |
69 | GtkCallback callback, | |
70 | gpointer callback_data); | |
17a1ebd1 | 71 | |
67d78217 RR |
72 | static void gtk_pizza_allocate_child (GtkPizza *pizza, |
73 | GtkPizzaChild *child); | |
3fc6e5fa RR |
74 | static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget, |
75 | gpointer cb_data); | |
ed673c6a | 76 | |
da048e3d | 77 | static GtkType gtk_pizza_child_type (GtkContainer *container); |
c801d85f | 78 | |
b6fa52db | 79 | static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza, |
bf3dab48 VZ |
80 | GtkAdjustment *hadj, |
81 | GtkAdjustment *vadj); | |
c801d85f | 82 | |
c764029c | 83 | static GtkWidgetClass* pizza_parent_class; |
034be888 | 84 | |
e1ff9329 | 85 | GtkType |
da048e3d | 86 | gtk_pizza_get_type () |
c801d85f | 87 | { |
e1ff9329 | 88 | static GtkType pizza_type = 0; |
c801d85f | 89 | |
da048e3d | 90 | if (!pizza_type) |
c801d85f | 91 | { |
de4a74e2 | 92 | const GTypeInfo pizza_info = |
67d78217 RR |
93 | { |
94 | sizeof (GtkPizzaClass), | |
95 | NULL, /* base_init */ | |
96 | NULL, /* base_finalize */ | |
97 | (GClassInitFunc) gtk_pizza_class_init, | |
98 | NULL, /* class_finalize */ | |
99 | NULL, /* class_data */ | |
100 | sizeof (GtkPizza), | |
101 | 16, /* n_preallocs */ | |
102 | (GInstanceInitFunc) gtk_pizza_init, | |
4eb8ef2d | 103 | NULL |
67d78217 | 104 | }; |
17a1ebd1 | 105 | pizza_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkPizza", &pizza_info, (GTypeFlags)0); |
c801d85f | 106 | } |
bf3dab48 | 107 | |
da048e3d | 108 | return pizza_type; |
c801d85f KB |
109 | } |
110 | ||
02a525b3 VZ |
111 | /* Marshaller needed for set_scroll_adjustments signal, |
112 | generated with GLib-2.4.6 glib-genmarshal */ | |
143318dd RR |
113 | #define g_marshal_value_peek_object(v) g_value_get_object (v) |
114 | static void | |
115 | g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure *closure, | |
116 | GValue *return_value, | |
117 | guint n_param_values, | |
118 | const GValue *param_values, | |
119 | gpointer invocation_hint, | |
120 | gpointer marshal_data) | |
121 | { | |
122 | typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1, | |
123 | gpointer arg_1, | |
124 | gpointer arg_2, | |
125 | gpointer data2); | |
126 | register GMarshalFunc_VOID__OBJECT_OBJECT callback; | |
127 | register GCClosure *cc = (GCClosure*) closure; | |
128 | register gpointer data1, data2; | |
129 | ||
130 | g_return_if_fail (n_param_values == 3); | |
131 | ||
132 | if (G_CCLOSURE_SWAP_DATA (closure)) | |
133 | { | |
134 | data1 = closure->data; | |
135 | data2 = g_value_peek_pointer (param_values + 0); | |
136 | } | |
137 | else | |
138 | { | |
139 | data1 = g_value_peek_pointer (param_values + 0); | |
140 | data2 = closure->data; | |
141 | } | |
142 | callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback); | |
143 | ||
144 | callback (data1, | |
145 | g_marshal_value_peek_object (param_values + 1), | |
146 | g_marshal_value_peek_object (param_values + 2), | |
147 | data2); | |
148 | } | |
143318dd | 149 | |
c801d85f | 150 | static void |
da048e3d | 151 | gtk_pizza_class_init (GtkPizzaClass *klass) |
c801d85f | 152 | { |
053f9cc1 RR |
153 | GtkObjectClass *object_class; |
154 | GtkWidgetClass *widget_class; | |
155 | GtkContainerClass *container_class; | |
c801d85f | 156 | |
053f9cc1 RR |
157 | object_class = (GtkObjectClass*) klass; |
158 | widget_class = (GtkWidgetClass*) klass; | |
159 | container_class = (GtkContainerClass*) klass; | |
67d78217 | 160 | pizza_parent_class = gtk_type_class (GTK_TYPE_CONTAINER); |
c801d85f | 161 | |
da048e3d RR |
162 | widget_class->map = gtk_pizza_map; |
163 | widget_class->realize = gtk_pizza_realize; | |
164 | widget_class->unrealize = gtk_pizza_unrealize; | |
165 | widget_class->size_request = gtk_pizza_size_request; | |
166 | widget_class->size_allocate = gtk_pizza_size_allocate; | |
22aff579 | 167 | widget_class->style_set = gtk_pizza_style_set; |
053f9cc1 | 168 | |
da048e3d RR |
169 | container_class->add = gtk_pizza_add; |
170 | container_class->remove = gtk_pizza_remove; | |
171 | container_class->forall = gtk_pizza_forall; | |
38c7b3d3 | 172 | |
da048e3d | 173 | container_class->child_type = gtk_pizza_child_type; |
034be888 | 174 | |
da048e3d | 175 | klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments; |
034be888 | 176 | |
053f9cc1 | 177 | widget_class->set_scroll_adjustments_signal = |
143318dd RR |
178 | g_signal_new( |
179 | "set_scroll_adjustments", | |
180 | G_TYPE_FROM_CLASS(object_class), | |
181 | G_SIGNAL_RUN_LAST, | |
182 | G_STRUCT_OFFSET(GtkPizzaClass, set_scroll_adjustments), | |
183 | NULL, | |
184 | NULL, | |
185 | g_cclosure_user_marshal_VOID__OBJECT_OBJECT, | |
186 | G_TYPE_NONE, | |
187 | 2, | |
188 | GTK_TYPE_ADJUSTMENT, | |
189 | GTK_TYPE_ADJUSTMENT); | |
38c7b3d3 RR |
190 | } |
191 | ||
38c7b3d3 | 192 | static GtkType |
da048e3d | 193 | gtk_pizza_child_type (GtkContainer *container) |
38c7b3d3 | 194 | { |
053f9cc1 | 195 | return GTK_TYPE_WIDGET; |
c801d85f KB |
196 | } |
197 | ||
198 | static void | |
da048e3d | 199 | gtk_pizza_init (GtkPizza *pizza) |
c801d85f | 200 | { |
28e88942 | 201 | GTK_WIDGET_SET_FLAGS (pizza, GTK_CAN_FOCUS); |
da048e3d | 202 | GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW); |
bf3dab48 | 203 | |
da048e3d | 204 | pizza->children = NULL; |
bf3dab48 | 205 | |
da048e3d | 206 | pizza->bin_window = NULL; |
3dd9b88a | 207 | |
a31bb944 RR |
208 | pizza->m_xoffset = 0; |
209 | pizza->m_yoffset = 0; | |
c801d85f KB |
210 | } |
211 | ||
212 | GtkWidget* | |
da048e3d | 213 | gtk_pizza_new () |
c801d85f | 214 | { |
da048e3d | 215 | GtkPizza *pizza; |
c801d85f | 216 | |
efc8ab7c | 217 | pizza = g_object_new (gtk_pizza_get_type (), NULL); |
3e09bcfd RR |
218 | |
219 | pizza->m_noscroll = FALSE; | |
220 | ||
221 | return GTK_WIDGET (pizza); | |
222 | } | |
223 | ||
224 | GtkWidget* | |
225 | gtk_pizza_new_no_scroll () | |
226 | { | |
227 | GtkPizza *pizza; | |
228 | ||
229 | pizza = g_object_new (gtk_pizza_get_type (), NULL); | |
230 | ||
231 | pizza->m_noscroll = TRUE; | |
bf3dab48 | 232 | |
da048e3d | 233 | return GTK_WIDGET (pizza); |
c801d85f KB |
234 | } |
235 | ||
a31bb944 RR |
236 | gint gtk_pizza_get_xoffset (GtkPizza *pizza) |
237 | { | |
238 | g_return_val_if_fail ( (pizza != NULL), -1 ); | |
239 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); | |
240 | ||
241 | return pizza->m_xoffset; | |
242 | } | |
243 | ||
244 | gint gtk_pizza_get_yoffset (GtkPizza *pizza) | |
245 | { | |
246 | g_return_val_if_fail ( (pizza != NULL), -1 ); | |
247 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); | |
248 | ||
249 | return pizza->m_yoffset; | |
250 | } | |
251 | ||
252 | void gtk_pizza_set_xoffset (GtkPizza *pizza, gint xoffset) | |
253 | { | |
254 | g_return_if_fail (pizza != NULL); | |
255 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
256 | ||
257 | pizza->m_xoffset = xoffset; | |
258 | // do something | |
259 | } | |
260 | ||
261 | void gtk_pizza_set_yoffset (GtkPizza *pizza, gint yoffset) | |
262 | { | |
263 | g_return_if_fail (pizza != NULL); | |
264 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
265 | ||
266 | pizza->m_xoffset = yoffset; | |
267 | // do something | |
268 | } | |
269 | ||
428f4657 RR |
270 | gint gtk_pizza_get_rtl_offset (GtkPizza *pizza) |
271 | { | |
39b5648e | 272 | gint border; |
428f4657 RR |
273 | |
274 | g_return_val_if_fail ( (pizza != NULL), 0 ); | |
275 | g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), 0 ); | |
f4322df6 | 276 | |
428f4657 | 277 | if (!pizza->bin_window) return 0; |
f4322df6 | 278 | |
af05af4d | 279 | border = pizza->container.border_width; |
f4322df6 | 280 | |
55dc8e18 | 281 | return GTK_WIDGET(pizza)->allocation.width - border*2; |
428f4657 RR |
282 | } |
283 | ||
284 | ||
bf3dab48 | 285 | static void |
da048e3d | 286 | gtk_pizza_scroll_set_adjustments (GtkPizza *pizza, |
bf3dab48 VZ |
287 | GtkAdjustment *hadj, |
288 | GtkAdjustment *vadj) | |
034be888 | 289 | { |
ed673c6a | 290 | /* We handle scrolling in the wxScrolledWindow, not here. */ |
034be888 RR |
291 | } |
292 | ||
c801d85f | 293 | void |
b6fa52db RR |
294 | gtk_pizza_put (GtkPizza *pizza, |
295 | GtkWidget *widget, | |
296 | gint x, | |
297 | gint y, | |
298 | gint width, | |
299 | gint height) | |
c801d85f | 300 | { |
da048e3d | 301 | GtkPizzaChild *child_info; |
053f9cc1 | 302 | |
da048e3d RR |
303 | g_return_if_fail (pizza != NULL); |
304 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
053f9cc1 RR |
305 | g_return_if_fail (widget != NULL); |
306 | ||
da048e3d | 307 | child_info = g_new (GtkPizzaChild, 1); |
bf3dab48 | 308 | |
053f9cc1 RR |
309 | child_info->widget = widget; |
310 | child_info->x = x; | |
311 | child_info->y = y; | |
bf3dab48 VZ |
312 | |
313 | pizza->children = g_list_append (pizza->children, child_info); | |
ed673c6a | 314 | |
da048e3d | 315 | if (GTK_WIDGET_REALIZED (pizza)) |
8db7faf2 | 316 | gtk_widget_set_parent_window (widget, pizza->bin_window); |
bf3dab48 | 317 | |
2b5f62a0 VZ |
318 | gtk_widget_set_parent (widget, GTK_WIDGET (pizza)); |
319 | ||
d218e518 | 320 | gtk_widget_set_size_request( widget, width, height ); |
8db7faf2 RR |
321 | if (GTK_WIDGET_REALIZED (pizza)) |
322 | gtk_pizza_allocate_child (pizza, child_info); | |
c801d85f KB |
323 | } |
324 | ||
fdd3ed7a | 325 | void |
b6fa52db RR |
326 | gtk_pizza_set_size (GtkPizza *pizza, |
327 | GtkWidget *widget, | |
328 | gint x, | |
329 | gint y, | |
330 | gint width, | |
331 | gint height) | |
fdd3ed7a | 332 | { |
da048e3d | 333 | GtkPizzaChild *child; |
053f9cc1 | 334 | GList *children; |
fdd3ed7a | 335 | |
da048e3d RR |
336 | g_return_if_fail (pizza != NULL); |
337 | g_return_if_fail (GTK_IS_PIZZA (pizza)); | |
053f9cc1 | 338 | g_return_if_fail (widget != NULL); |
fdd3ed7a | 339 | |
aaf53059 | 340 | #ifndef WX_WARN_ILLEGAL_SETSIZE |
6b71411a | 341 | /* this really shouldn't happen -- but it does, a lot, right now and we |
aaf53059 MR |
342 | can't pass negative values to gtk_widget_set_size_request() without getting |
343 | a warning printed out, so filter them out here */ | |
6b71411a VZ |
344 | if ( width < 0 ) |
345 | width = 0; | |
346 | if ( height < 0 ) | |
347 | height = 0; | |
aaf53059 | 348 | #endif |
6b71411a | 349 | |
da048e3d | 350 | children = pizza->children; |
053f9cc1 | 351 | while (children) |
c801d85f | 352 | { |
053f9cc1 RR |
353 | child = children->data; |
354 | children = children->next; | |
c801d85f | 355 | |
053f9cc1 | 356 | if (child->widget == widget) |
c801d85f | 357 | { |
bc9e85a3 PC |
358 | if (child->x != x || child->y != y) |
359 | { | |
360 | child->x = x; | |
361 | child->y = y; | |
362 | gtk_widget_queue_resize(widget); | |
363 | } | |
91641d04 | 364 | |
370dc79c | 365 | gtk_widget_set_size_request (widget, width, height); |
bf3dab48 | 366 | |
6d693bb4 | 367 | return; |
c801d85f KB |
368 | } |
369 | } | |
370 | } | |
371 | ||
372 | static void | |
da048e3d | 373 | gtk_pizza_map (GtkWidget *widget) |
c801d85f | 374 | { |
da048e3d RR |
375 | GtkPizza *pizza; |
376 | GtkPizzaChild *child; | |
053f9cc1 | 377 | GList *children; |
c801d85f | 378 | |
053f9cc1 | 379 | g_return_if_fail (widget != NULL); |
da048e3d | 380 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
c801d85f | 381 | |
053f9cc1 | 382 | GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); |
da048e3d | 383 | pizza = GTK_PIZZA (widget); |
c801d85f | 384 | |
da048e3d | 385 | children = pizza->children; |
053f9cc1 | 386 | while (children) |
c801d85f | 387 | { |
053f9cc1 RR |
388 | child = children->data; |
389 | children = children->next; | |
c801d85f | 390 | |
bf3dab48 | 391 | if ( GTK_WIDGET_VISIBLE (child->widget) && |
efc8ab7c | 392 | !GTK_WIDGET_MAPPED (child->widget) ) |
bf3dab48 VZ |
393 | { |
394 | gtk_widget_map (child->widget); | |
395 | } | |
c801d85f | 396 | } |
bf3dab48 | 397 | |
053f9cc1 | 398 | gdk_window_show (widget->window); |
da048e3d | 399 | gdk_window_show (pizza->bin_window); |
c801d85f KB |
400 | } |
401 | ||
c801d85f | 402 | static void |
da048e3d | 403 | gtk_pizza_realize (GtkWidget *widget) |
c801d85f | 404 | { |
da048e3d | 405 | GtkPizza *pizza; |
053f9cc1 RR |
406 | GdkWindowAttr attributes; |
407 | gint attributes_mask; | |
da048e3d | 408 | GtkPizzaChild *child; |
ed673c6a | 409 | GList *children; |
af05af4d | 410 | int border; |
c801d85f | 411 | |
053f9cc1 | 412 | g_return_if_fail (widget != NULL); |
da048e3d | 413 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
c801d85f | 414 | |
da048e3d | 415 | pizza = GTK_PIZZA (widget); |
053f9cc1 | 416 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); |
c801d85f | 417 | |
053f9cc1 | 418 | attributes.window_type = GDK_WINDOW_CHILD; |
bf3dab48 | 419 | |
053f9cc1 RR |
420 | attributes.x = widget->allocation.x; |
421 | attributes.y = widget->allocation.y; | |
422 | attributes.width = widget->allocation.width; | |
423 | attributes.height = widget->allocation.height; | |
424 | ||
af05af4d PC |
425 | border = pizza->container.border_width; |
426 | attributes.x += border; | |
427 | attributes.y += border; | |
428 | attributes.width -= 2 * border; | |
429 | attributes.height -= 2 * border; | |
bf3dab48 | 430 | |
ed673c6a | 431 | /* minimal size */ |
053f9cc1 RR |
432 | if (attributes.width < 2) attributes.width = 2; |
433 | if (attributes.height < 2) attributes.height = 2; | |
bf3dab48 | 434 | |
053f9cc1 RR |
435 | attributes.wclass = GDK_INPUT_OUTPUT; |
436 | attributes.visual = gtk_widget_get_visual (widget); | |
437 | attributes.colormap = gtk_widget_get_colormap (widget); | |
3dd9b88a | 438 | attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; |
ed673c6a | 439 | attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; |
bf3dab48 | 440 | |
c916e13b | 441 | widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), |
bf3dab48 | 442 | &attributes, attributes_mask); |
ed673c6a RR |
443 | gdk_window_set_user_data (widget->window, widget); |
444 | ||
445 | attributes.x = 0; | |
446 | attributes.y = 0; | |
bf3dab48 | 447 | |
053f9cc1 | 448 | attributes.event_mask = gtk_widget_get_events (widget); |
3dd9b88a | 449 | attributes.event_mask |= GDK_EXPOSURE_MASK | |
67d78217 | 450 | GDK_SCROLL_MASK | |
3dd9b88a VZ |
451 | GDK_POINTER_MOTION_MASK | |
452 | GDK_POINTER_MOTION_HINT_MASK | | |
453 | GDK_BUTTON_MOTION_MASK | | |
454 | GDK_BUTTON1_MOTION_MASK | | |
455 | GDK_BUTTON2_MOTION_MASK | | |
456 | GDK_BUTTON3_MOTION_MASK | | |
457 | GDK_BUTTON_PRESS_MASK | | |
458 | GDK_BUTTON_RELEASE_MASK | | |
459 | GDK_KEY_PRESS_MASK | | |
460 | GDK_KEY_RELEASE_MASK | | |
461 | GDK_ENTER_NOTIFY_MASK | | |
462 | GDK_LEAVE_NOTIFY_MASK | | |
463 | GDK_FOCUS_CHANGE_MASK; | |
053f9cc1 | 464 | |
c916e13b | 465 | pizza->bin_window = gdk_window_new(widget->window, |
bf3dab48 | 466 | &attributes, attributes_mask); |
da048e3d | 467 | gdk_window_set_user_data (pizza->bin_window, widget); |
bf3dab48 | 468 | |
053f9cc1 RR |
469 | widget->style = gtk_style_attach (widget->style, widget->window); |
470 | gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); | |
b6fa52db | 471 | gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL ); |
17a1ebd1 | 472 | |
33611ebb RR |
473 | /* |
474 | gdk_window_set_back_pixmap( widget->window, NULL, FALSE ); | |
475 | gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE ); | |
476 | */ | |
bf3dab48 | 477 | |
ed673c6a | 478 | /* cannot be done before realisation */ |
da048e3d | 479 | children = pizza->children; |
ed673c6a RR |
480 | while (children) |
481 | { | |
482 | child = children->data; | |
483 | children = children->next; | |
484 | ||
da048e3d | 485 | gtk_widget_set_parent_window (child->widget, pizza->bin_window); |
ed673c6a RR |
486 | } |
487 | } | |
488 | ||
bf3dab48 | 489 | static void |
da048e3d | 490 | gtk_pizza_unrealize (GtkWidget *widget) |
ed673c6a | 491 | { |
d5ab387d | 492 | GtkPizza *pizza; |
ed673c6a | 493 | |
d5ab387d RR |
494 | g_return_if_fail (widget != NULL); |
495 | g_return_if_fail (GTK_IS_PIZZA (widget)); | |
ed673c6a | 496 | |
d5ab387d | 497 | pizza = GTK_PIZZA (widget); |
ed673c6a | 498 | |
d5ab387d RR |
499 | gdk_window_set_user_data (pizza->bin_window, NULL); |
500 | gdk_window_destroy (pizza->bin_window); | |
501 | pizza->bin_window = NULL; | |
ed673c6a | 502 | |
c764029c PC |
503 | if (pizza_parent_class->unrealize) |
504 | pizza_parent_class->unrealize(widget); | |
c801d85f KB |
505 | } |
506 | ||
507 | static void | |
da048e3d | 508 | gtk_pizza_size_request (GtkWidget *widget, |
b6fa52db | 509 | GtkRequisition *requisition) |
c801d85f | 510 | { |
da048e3d RR |
511 | GtkPizza *pizza; |
512 | GtkPizzaChild *child; | |
053f9cc1 RR |
513 | GList *children; |
514 | GtkRequisition child_requisition; | |
bf3dab48 | 515 | |
053f9cc1 | 516 | g_return_if_fail (widget != NULL); |
da048e3d | 517 | g_return_if_fail (GTK_IS_PIZZA (widget)); |
053f9cc1 | 518 | g_return_if_fail (requisition != NULL); |
c801d85f | 519 | |
da048e3d | 520 | pizza = GTK_PIZZA (widget); |
bf3dab48 | 521 | |
da048e3d | 522 | children = pizza->children; |
053f9cc1 | 523 | while (children) |
c801d85f | 524 | { |
053f9cc1 RR |
525 | child = children->data; |
526 | children = children->next; | |
c801d85f | 527 | |
053f9cc1 | 528 | if (GTK_WIDGET_VISIBLE (child->widget)) |
bf3dab48 | 529 | { |
053f9cc1 | 530 | gtk_widget_size_request (child->widget, &child_requisition); |
bf3dab48 | 531 | } |
c801d85f | 532 | } |
bf3dab48 | 533 | |
053f9cc1 RR |
534 | /* request very little, I'm not sure if requesting nothing |
535 | will always have positive effects on stability... */ | |
536 | requisition->width = 2; | |
537 | requisition->height = 2; | |
c801d85f KB |
538 | } |
539 | ||
540 | static void | |
da048e3d | 541 | gtk_pizza_size_allocate (GtkWidget *widget, |
b6fa52db | 542 | GtkAllocation *allocation) |
c801d85f | 543 | { |
da048e3d | 544 | GtkPizza *pizza; |
053f9cc1 | 545 | gint border; |
ed673c6a | 546 | gint x,y,w,h; |
da048e3d | 547 | GtkPizzaChild *child; |
ed673c6a | 548 | GList *children; |
db71eb06 | 549 | gboolean only_resize; |
c801d85f | 550 | |
053f9cc1 | 551 | g_return_if_fail (widget != NULL); |
da048e3d | 552 | g_return_if_fail (GTK_IS_PIZZA(widget)); |
053f9cc1 | 553 | g_return_if_fail (allocation != NULL); |
c801d85f | 554 | |
da048e3d | 555 | pizza = GTK_PIZZA (widget); |
bf3dab48 | 556 | |
db71eb06 RR |
557 | only_resize = ((widget->allocation.x == allocation->x) && |
558 | (widget->allocation.y == allocation->y)); | |
227e5e99 | 559 | widget->allocation = *allocation; |
bf3dab48 | 560 | |
af05af4d | 561 | border = pizza->container.border_width; |
f4322df6 | 562 | |
ed673c6a RR |
563 | x = allocation->x + border; |
564 | y = allocation->y + border; | |
565 | w = allocation->width - border*2; | |
566 | h = allocation->height - border*2; | |
69346023 PC |
567 | if (w < 0) |
568 | w = 0; | |
569 | if (h < 0) | |
570 | h = 0; | |
034be888 | 571 | |
3e09bcfd RR |
572 | if (!GTK_WIDGET_REALIZED (widget)) |
573 | return; | |
574 | ||
575 | if (pizza->m_noscroll) | |
576 | { | |
577 | if (only_resize) | |
578 | gdk_window_resize( widget->window, allocation->width, allocation->height ); | |
579 | else | |
580 | gdk_window_move_resize( widget->window, allocation->x, allocation->y, | |
581 | allocation->width, allocation->height ); | |
582 | ||
583 | gdk_window_move_resize( pizza->bin_window, border, border, w, h ); | |
584 | } | |
585 | else | |
053f9cc1 | 586 | { |
db71eb06 RR |
587 | if (only_resize) |
588 | gdk_window_resize( widget->window, w, h ); | |
589 | else | |
590 | gdk_window_move_resize( widget->window, x, y, w, h ); | |
02ae785a PC |
591 | |
592 | gdk_window_resize( pizza->bin_window, w, h ); | |
053f9cc1 | 593 | } |
bf3dab48 | 594 | |
da048e3d | 595 | children = pizza->children; |
6d693bb4 RR |
596 | while (children) |
597 | { | |
598 | child = children->data; | |
599 | children = children->next; | |
bf3dab48 | 600 | |
da048e3d | 601 | gtk_pizza_allocate_child (pizza, child); |
6d693bb4 | 602 | } |
c801d85f KB |
603 | } |
604 | ||
22aff579 VS |
605 | static void |
606 | gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style) | |
607 | { | |
608 | if (GTK_WIDGET_REALIZED(widget)) | |
609 | { | |
610 | gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); | |
611 | gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL ); | |
612 | } | |
613 | ||
c764029c | 614 | pizza_parent_class->style_set(widget, previous_style); |
22aff579 VS |
615 | } |
616 | ||
c801d85f | 617 | static void |
da048e3d | 618 | gtk_pizza_add (GtkContainer *container, |
bf3dab48 | 619 | GtkWidget *widget) |
c801d85f | 620 | { |
ed673c6a | 621 | g_return_if_fail (container != NULL); |
da048e3d | 622 | g_return_if_fail (GTK_IS_PIZZA (container)); |
ed673c6a | 623 | g_return_if_fail (widget != NULL); |
c801d85f | 624 | |
da048e3d | 625 | gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 ); |
c801d85f KB |
626 | } |
627 | ||
628 | static void | |
da048e3d | 629 | gtk_pizza_remove (GtkContainer *container, |
b6fa52db | 630 | GtkWidget *widget) |
c801d85f | 631 | { |
da048e3d RR |
632 | GtkPizza *pizza; |
633 | GtkPizzaChild *child; | |
ed673c6a | 634 | GList *children; |
c801d85f | 635 | |
ed673c6a | 636 | g_return_if_fail (container != NULL); |
da048e3d | 637 | g_return_if_fail (GTK_IS_PIZZA (container)); |
ed673c6a | 638 | g_return_if_fail (widget != NULL); |
c801d85f | 639 | |
da048e3d | 640 | pizza = GTK_PIZZA (container); |
c801d85f | 641 | |
da048e3d | 642 | children = pizza->children; |
ed673c6a | 643 | while (children) |
c801d85f | 644 | { |
ed673c6a | 645 | child = children->data; |
c801d85f | 646 | |
ed673c6a | 647 | if (child->widget == widget) |
bf3dab48 VZ |
648 | { |
649 | gtk_widget_unparent (widget); | |
c801d85f | 650 | |
ed673c6a RR |
651 | /* security checks */ |
652 | g_return_if_fail (GTK_IS_WIDGET (widget)); | |
bf3dab48 VZ |
653 | |
654 | pizza->children = g_list_remove_link (pizza->children, children); | |
655 | g_list_free (children); | |
656 | g_free (child); | |
c801d85f | 657 | |
ed673c6a | 658 | /* security checks */ |
bf3dab48 VZ |
659 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
660 | ||
bf3dab48 VZ |
661 | break; |
662 | } | |
c801d85f | 663 | |
ed673c6a | 664 | children = children->next; |
c801d85f KB |
665 | } |
666 | } | |
667 | ||
668 | static void | |
da048e3d | 669 | gtk_pizza_forall (GtkContainer *container, |
b6fa52db RR |
670 | gboolean include_internals, |
671 | GtkCallback callback, | |
672 | gpointer callback_data) | |
c801d85f | 673 | { |
da048e3d RR |
674 | GtkPizza *pizza; |
675 | GtkPizzaChild *child; | |
6d693bb4 | 676 | GList *children; |
c801d85f | 677 | |
6d693bb4 | 678 | g_return_if_fail (container != NULL); |
da048e3d | 679 | g_return_if_fail (GTK_IS_PIZZA (container)); |
90350682 | 680 | g_return_if_fail (callback != (GtkCallback)NULL); |
c801d85f | 681 | |
da048e3d | 682 | pizza = GTK_PIZZA (container); |
c801d85f | 683 | |
da048e3d | 684 | children = pizza->children; |
6d693bb4 | 685 | while (children) |
c801d85f | 686 | { |
6d693bb4 RR |
687 | child = children->data; |
688 | children = children->next; | |
c801d85f | 689 | |
6d693bb4 | 690 | (* callback) (child->widget, callback_data); |
c801d85f KB |
691 | } |
692 | } | |
693 | ||
67d78217 RR |
694 | static void |
695 | gtk_pizza_allocate_child (GtkPizza *pizza, | |
696 | GtkPizzaChild *child) | |
697 | { | |
698 | GtkAllocation allocation; | |
699 | GtkRequisition requisition; | |
c801d85f | 700 | |
a31bb944 RR |
701 | allocation.x = child->x - pizza->m_xoffset; |
702 | allocation.y = child->y - pizza->m_yoffset; | |
67d78217 RR |
703 | gtk_widget_get_child_requisition (child->widget, &requisition); |
704 | allocation.width = requisition.width; | |
705 | allocation.height = requisition.height; | |
706 | ||
db71eb06 RR |
707 | if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL) |
708 | { | |
709 | /* reverse horizontal placement */ | |
f4322df6 VZ |
710 | gint offset,border; |
711 | ||
39b5648e | 712 | offset = GTK_WIDGET(pizza)->allocation.width; |
af05af4d | 713 | border = pizza->container.border_width; |
39b5648e | 714 | offset -= border*2; |
f4322df6 VZ |
715 | |
716 | allocation.x = offset - child->x - allocation.width + pizza->m_xoffset; | |
db71eb06 | 717 | } |
f4322df6 | 718 | |
67d78217 RR |
719 | gtk_widget_size_allocate (child->widget, &allocation); |
720 | } | |
ed673c6a | 721 | |
ed673c6a | 722 | static void |
da048e3d | 723 | gtk_pizza_adjust_allocations_recurse (GtkWidget *widget, |
bf3dab48 | 724 | gpointer cb_data) |
ed673c6a | 725 | { |
da048e3d | 726 | GtkPizzaAdjData *data = cb_data; |
ed673c6a | 727 | |
6d693bb4 RR |
728 | widget->allocation.x += data->dx; |
729 | widget->allocation.y += data->dy; | |
ed673c6a | 730 | |
6d693bb4 RR |
731 | if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget)) |
732 | { | |
bf3dab48 VZ |
733 | gtk_container_forall (GTK_CONTAINER (widget), |
734 | gtk_pizza_adjust_allocations_recurse, | |
735 | cb_data); | |
6d693bb4 | 736 | } |
ed673c6a RR |
737 | } |
738 | ||
739 | static void | |
da048e3d | 740 | gtk_pizza_adjust_allocations (GtkPizza *pizza, |
bf3dab48 VZ |
741 | gint dx, |
742 | gint dy) | |
ed673c6a | 743 | { |
0e09f76e RR |
744 | GList *tmp_list; |
745 | GtkPizzaAdjData data; | |
ed673c6a | 746 | |
0e09f76e RR |
747 | data.dx = dx; |
748 | data.dy = dy; | |
ed673c6a | 749 | |
0e09f76e RR |
750 | tmp_list = pizza->children; |
751 | while (tmp_list) | |
ed673c6a | 752 | { |
0e09f76e RR |
753 | GtkPizzaChild *child = tmp_list->data; |
754 | tmp_list = tmp_list->next; | |
bf3dab48 | 755 | |
0e09f76e RR |
756 | child->widget->allocation.x += dx; |
757 | child->widget->allocation.y += dy; | |
ed673c6a | 758 | |
0e09f76e RR |
759 | if (GTK_WIDGET_NO_WINDOW (child->widget) && |
760 | GTK_IS_CONTAINER (child->widget)) | |
761 | { | |
762 | gtk_container_forall (GTK_CONTAINER (child->widget), | |
763 | gtk_pizza_adjust_allocations_recurse, | |
764 | &data); | |
765 | } | |
ed673c6a RR |
766 | } |
767 | } | |
bf3dab48 | 768 | |
ed673c6a | 769 | void |
da048e3d | 770 | gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy) |
ed673c6a | 771 | { |
a31bb944 RR |
772 | pizza->m_xoffset += dx; |
773 | pizza->m_yoffset += dy; | |
3fc6e5fa RR |
774 | |
775 | gtk_pizza_adjust_allocations (pizza, -dx, -dy); | |
776 | ||
777 | if (pizza->bin_window) | |
778 | gdk_window_scroll( pizza->bin_window, -dx, -dy ); | |
ed673c6a RR |
779 | } |
780 | ||
c801d85f KB |
781 | #ifdef __cplusplus |
782 | } | |
783 | #endif /* __cplusplus */ |