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