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