]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/win_gtk.c
use WXDLLIMPEXP_ADV on the base class too
[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);
3fc6e5fa
RR
74static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
75 gpointer cb_data);
ed673c6a 76
da048e3d 77static GtkType gtk_pizza_child_type (GtkContainer *container);
c801d85f 78
b6fa52db 79static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
bf3dab48
VZ
80 GtkAdjustment *hadj,
81 GtkAdjustment *vadj);
c801d85f 82
c764029c 83static GtkWidgetClass* pizza_parent_class;
034be888 84
e1ff9329 85GtkType
da048e3d 86gtk_pizza_get_type ()
c801d85f 87{
e1ff9329 88 static GtkType pizza_type = 0;
c801d85f 89
da048e3d 90 if (!pizza_type)
c801d85f 91 {
67d78217
RR
92 static const GTypeInfo pizza_info =
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)
114static void
115g_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 150static void
da048e3d 151gtk_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 192static GtkType
da048e3d 193gtk_pizza_child_type (GtkContainer *container)
38c7b3d3 194{
053f9cc1 195 return GTK_TYPE_WIDGET;
c801d85f
KB
196}
197
198static void
da048e3d 199gtk_pizza_init (GtkPizza *pizza)
c801d85f 200{
da048e3d 201 GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
bf3dab48 202
da048e3d 203 pizza->children = NULL;
bf3dab48 204
da048e3d 205 pizza->bin_window = NULL;
3dd9b88a 206
a31bb944
RR
207 pizza->m_xoffset = 0;
208 pizza->m_yoffset = 0;
c801d85f
KB
209}
210
211GtkWidget*
da048e3d 212gtk_pizza_new ()
c801d85f 213{
da048e3d 214 GtkPizza *pizza;
c801d85f 215
efc8ab7c 216 pizza = g_object_new (gtk_pizza_get_type (), NULL);
bf3dab48 217
da048e3d 218 return GTK_WIDGET (pizza);
c801d85f
KB
219}
220
a31bb944
RR
221gint gtk_pizza_get_xoffset (GtkPizza *pizza)
222{
223 g_return_val_if_fail ( (pizza != NULL), -1 );
224 g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 );
225
226 return pizza->m_xoffset;
227}
228
229gint gtk_pizza_get_yoffset (GtkPizza *pizza)
230{
231 g_return_val_if_fail ( (pizza != NULL), -1 );
232 g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 );
233
234 return pizza->m_yoffset;
235}
236
237void gtk_pizza_set_xoffset (GtkPizza *pizza, gint xoffset)
238{
239 g_return_if_fail (pizza != NULL);
240 g_return_if_fail (GTK_IS_PIZZA (pizza));
241
242 pizza->m_xoffset = xoffset;
243 // do something
244}
245
246void gtk_pizza_set_yoffset (GtkPizza *pizza, gint yoffset)
247{
248 g_return_if_fail (pizza != NULL);
249 g_return_if_fail (GTK_IS_PIZZA (pizza));
250
251 pizza->m_xoffset = yoffset;
252 // do something
253}
254
428f4657
RR
255gint gtk_pizza_get_rtl_offset (GtkPizza *pizza)
256{
39b5648e 257 gint border;
428f4657
RR
258
259 g_return_val_if_fail ( (pizza != NULL), 0 );
260 g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), 0 );
261
262 if (!pizza->bin_window) return 0;
263
af05af4d 264 border = pizza->container.border_width;
39b5648e 265
55dc8e18 266 return GTK_WIDGET(pizza)->allocation.width - border*2;
428f4657
RR
267}
268
269
bf3dab48 270static void
da048e3d 271gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
bf3dab48
VZ
272 GtkAdjustment *hadj,
273 GtkAdjustment *vadj)
034be888 274{
ed673c6a 275 /* We handle scrolling in the wxScrolledWindow, not here. */
034be888
RR
276}
277
c801d85f 278void
b6fa52db
RR
279gtk_pizza_put (GtkPizza *pizza,
280 GtkWidget *widget,
281 gint x,
282 gint y,
283 gint width,
284 gint height)
c801d85f 285{
da048e3d 286 GtkPizzaChild *child_info;
053f9cc1 287
da048e3d
RR
288 g_return_if_fail (pizza != NULL);
289 g_return_if_fail (GTK_IS_PIZZA (pizza));
053f9cc1
RR
290 g_return_if_fail (widget != NULL);
291
da048e3d 292 child_info = g_new (GtkPizzaChild, 1);
bf3dab48 293
053f9cc1
RR
294 child_info->widget = widget;
295 child_info->x = x;
296 child_info->y = y;
bf3dab48
VZ
297
298 pizza->children = g_list_append (pizza->children, child_info);
ed673c6a 299
da048e3d 300 if (GTK_WIDGET_REALIZED (pizza))
8db7faf2 301 gtk_widget_set_parent_window (widget, pizza->bin_window);
bf3dab48 302
2b5f62a0
VZ
303 gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
304
d218e518 305 gtk_widget_set_size_request( widget, width, height );
8db7faf2
RR
306 if (GTK_WIDGET_REALIZED (pizza))
307 gtk_pizza_allocate_child (pizza, child_info);
c801d85f
KB
308}
309
fdd3ed7a 310void
b6fa52db
RR
311gtk_pizza_set_size (GtkPizza *pizza,
312 GtkWidget *widget,
313 gint x,
314 gint y,
315 gint width,
316 gint height)
fdd3ed7a 317{
da048e3d 318 GtkPizzaChild *child;
053f9cc1 319 GList *children;
fdd3ed7a 320
da048e3d
RR
321 g_return_if_fail (pizza != NULL);
322 g_return_if_fail (GTK_IS_PIZZA (pizza));
053f9cc1 323 g_return_if_fail (widget != NULL);
fdd3ed7a 324
aaf53059 325#ifndef WX_WARN_ILLEGAL_SETSIZE
6b71411a 326 /* this really shouldn't happen -- but it does, a lot, right now and we
aaf53059
MR
327 can't pass negative values to gtk_widget_set_size_request() without getting
328 a warning printed out, so filter them out here */
6b71411a
VZ
329 if ( width < 0 )
330 width = 0;
331 if ( height < 0 )
332 height = 0;
aaf53059 333#endif
6b71411a 334
da048e3d 335 children = pizza->children;
053f9cc1 336 while (children)
c801d85f 337 {
053f9cc1
RR
338 child = children->data;
339 children = children->next;
c801d85f 340
053f9cc1 341 if (child->widget == widget)
c801d85f 342 {
db71eb06 343 child->x = x;
053f9cc1 344 child->y = y;
91641d04 345
370dc79c 346 gtk_widget_set_size_request (widget, width, height);
bf3dab48 347
6d693bb4 348 return;
c801d85f
KB
349 }
350 }
351}
352
353static void
da048e3d 354gtk_pizza_map (GtkWidget *widget)
c801d85f 355{
da048e3d
RR
356 GtkPizza *pizza;
357 GtkPizzaChild *child;
053f9cc1 358 GList *children;
c801d85f 359
053f9cc1 360 g_return_if_fail (widget != NULL);
da048e3d 361 g_return_if_fail (GTK_IS_PIZZA (widget));
c801d85f 362
053f9cc1 363 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
da048e3d 364 pizza = GTK_PIZZA (widget);
c801d85f 365
da048e3d 366 children = pizza->children;
053f9cc1 367 while (children)
c801d85f 368 {
053f9cc1
RR
369 child = children->data;
370 children = children->next;
c801d85f 371
bf3dab48 372 if ( GTK_WIDGET_VISIBLE (child->widget) &&
efc8ab7c 373 !GTK_WIDGET_MAPPED (child->widget) )
bf3dab48
VZ
374 {
375 gtk_widget_map (child->widget);
376 }
c801d85f 377 }
bf3dab48 378
053f9cc1 379 gdk_window_show (widget->window);
da048e3d 380 gdk_window_show (pizza->bin_window);
c801d85f
KB
381}
382
c801d85f 383static void
da048e3d 384gtk_pizza_realize (GtkWidget *widget)
c801d85f 385{
da048e3d 386 GtkPizza *pizza;
053f9cc1
RR
387 GdkWindowAttr attributes;
388 gint attributes_mask;
da048e3d 389 GtkPizzaChild *child;
ed673c6a 390 GList *children;
af05af4d 391 int border;
c801d85f 392
053f9cc1 393 g_return_if_fail (widget != NULL);
da048e3d 394 g_return_if_fail (GTK_IS_PIZZA (widget));
c801d85f 395
da048e3d 396 pizza = GTK_PIZZA (widget);
053f9cc1 397 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
c801d85f 398
053f9cc1 399 attributes.window_type = GDK_WINDOW_CHILD;
bf3dab48 400
053f9cc1
RR
401 attributes.x = widget->allocation.x;
402 attributes.y = widget->allocation.y;
403 attributes.width = widget->allocation.width;
404 attributes.height = widget->allocation.height;
405
af05af4d
PC
406 border = pizza->container.border_width;
407 attributes.x += border;
408 attributes.y += border;
409 attributes.width -= 2 * border;
410 attributes.height -= 2 * border;
bf3dab48 411
ed673c6a 412 /* minimal size */
053f9cc1
RR
413 if (attributes.width < 2) attributes.width = 2;
414 if (attributes.height < 2) attributes.height = 2;
bf3dab48 415
053f9cc1
RR
416 attributes.wclass = GDK_INPUT_OUTPUT;
417 attributes.visual = gtk_widget_get_visual (widget);
418 attributes.colormap = gtk_widget_get_colormap (widget);
3dd9b88a 419 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
ed673c6a 420 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
bf3dab48 421
c916e13b 422 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget),
bf3dab48 423 &attributes, attributes_mask);
ed673c6a
RR
424 gdk_window_set_user_data (widget->window, widget);
425
426 attributes.x = 0;
427 attributes.y = 0;
bf3dab48 428
053f9cc1 429 attributes.event_mask = gtk_widget_get_events (widget);
3dd9b88a 430 attributes.event_mask |= GDK_EXPOSURE_MASK |
67d78217 431 GDK_SCROLL_MASK |
3dd9b88a
VZ
432 GDK_POINTER_MOTION_MASK |
433 GDK_POINTER_MOTION_HINT_MASK |
434 GDK_BUTTON_MOTION_MASK |
435 GDK_BUTTON1_MOTION_MASK |
436 GDK_BUTTON2_MOTION_MASK |
437 GDK_BUTTON3_MOTION_MASK |
438 GDK_BUTTON_PRESS_MASK |
439 GDK_BUTTON_RELEASE_MASK |
440 GDK_KEY_PRESS_MASK |
441 GDK_KEY_RELEASE_MASK |
442 GDK_ENTER_NOTIFY_MASK |
443 GDK_LEAVE_NOTIFY_MASK |
444 GDK_FOCUS_CHANGE_MASK;
053f9cc1 445
c916e13b 446 pizza->bin_window = gdk_window_new(widget->window,
bf3dab48 447 &attributes, attributes_mask);
da048e3d 448 gdk_window_set_user_data (pizza->bin_window, widget);
bf3dab48 449
053f9cc1
RR
450 widget->style = gtk_style_attach (widget->style, widget->window);
451 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
b6fa52db 452 gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL );
17a1ebd1 453
33611ebb
RR
454/*
455 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
456 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
457*/
bf3dab48 458
ed673c6a 459 /* cannot be done before realisation */
da048e3d 460 children = pizza->children;
ed673c6a
RR
461 while (children)
462 {
463 child = children->data;
464 children = children->next;
465
da048e3d 466 gtk_widget_set_parent_window (child->widget, pizza->bin_window);
ed673c6a
RR
467 }
468}
469
bf3dab48 470static void
da048e3d 471gtk_pizza_unrealize (GtkWidget *widget)
ed673c6a 472{
d5ab387d 473 GtkPizza *pizza;
ed673c6a 474
d5ab387d
RR
475 g_return_if_fail (widget != NULL);
476 g_return_if_fail (GTK_IS_PIZZA (widget));
ed673c6a 477
d5ab387d 478 pizza = GTK_PIZZA (widget);
ed673c6a 479
d5ab387d
RR
480 gdk_window_set_user_data (pizza->bin_window, NULL);
481 gdk_window_destroy (pizza->bin_window);
482 pizza->bin_window = NULL;
ed673c6a 483
c764029c
PC
484 if (pizza_parent_class->unrealize)
485 pizza_parent_class->unrealize(widget);
c801d85f
KB
486}
487
488static void
da048e3d 489gtk_pizza_size_request (GtkWidget *widget,
b6fa52db 490 GtkRequisition *requisition)
c801d85f 491{
da048e3d
RR
492 GtkPizza *pizza;
493 GtkPizzaChild *child;
053f9cc1
RR
494 GList *children;
495 GtkRequisition child_requisition;
bf3dab48 496
053f9cc1 497 g_return_if_fail (widget != NULL);
da048e3d 498 g_return_if_fail (GTK_IS_PIZZA (widget));
053f9cc1 499 g_return_if_fail (requisition != NULL);
c801d85f 500
da048e3d 501 pizza = GTK_PIZZA (widget);
bf3dab48 502
da048e3d 503 children = pizza->children;
053f9cc1 504 while (children)
c801d85f 505 {
053f9cc1
RR
506 child = children->data;
507 children = children->next;
c801d85f 508
053f9cc1 509 if (GTK_WIDGET_VISIBLE (child->widget))
bf3dab48 510 {
053f9cc1 511 gtk_widget_size_request (child->widget, &child_requisition);
bf3dab48 512 }
c801d85f 513 }
bf3dab48 514
053f9cc1
RR
515 /* request very little, I'm not sure if requesting nothing
516 will always have positive effects on stability... */
517 requisition->width = 2;
518 requisition->height = 2;
c801d85f
KB
519}
520
521static void
da048e3d 522gtk_pizza_size_allocate (GtkWidget *widget,
b6fa52db 523 GtkAllocation *allocation)
c801d85f 524{
da048e3d 525 GtkPizza *pizza;
053f9cc1 526 gint border;
ed673c6a 527 gint x,y,w,h;
da048e3d 528 GtkPizzaChild *child;
ed673c6a 529 GList *children;
db71eb06 530 gboolean only_resize;
c801d85f 531
053f9cc1 532 g_return_if_fail (widget != NULL);
da048e3d 533 g_return_if_fail (GTK_IS_PIZZA(widget));
053f9cc1 534 g_return_if_fail (allocation != NULL);
c801d85f 535
da048e3d 536 pizza = GTK_PIZZA (widget);
bf3dab48 537
db71eb06
RR
538 only_resize = ((widget->allocation.x == allocation->x) &&
539 (widget->allocation.y == allocation->y));
227e5e99 540 widget->allocation = *allocation;
bf3dab48 541
af05af4d 542 border = pizza->container.border_width;
8db7faf2 543
ed673c6a
RR
544 x = allocation->x + border;
545 y = allocation->y + border;
546 w = allocation->width - border*2;
547 h = allocation->height - border*2;
69346023
PC
548 if (w < 0)
549 w = 0;
550 if (h < 0)
551 h = 0;
034be888 552
053f9cc1
RR
553 if (GTK_WIDGET_REALIZED (widget))
554 {
db71eb06
RR
555 if (only_resize)
556 gdk_window_resize( widget->window, w, h );
557 else
558 gdk_window_move_resize( widget->window, x, y, w, h );
02ae785a
PC
559
560 gdk_window_resize( pizza->bin_window, w, h );
053f9cc1 561 }
bf3dab48 562
da048e3d 563 children = pizza->children;
6d693bb4
RR
564 while (children)
565 {
566 child = children->data;
567 children = children->next;
bf3dab48 568
da048e3d 569 gtk_pizza_allocate_child (pizza, child);
6d693bb4 570 }
c801d85f
KB
571}
572
22aff579
VS
573static void
574gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style)
575{
576 if (GTK_WIDGET_REALIZED(widget))
577 {
578 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
579 gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL );
580 }
581
c764029c 582 pizza_parent_class->style_set(widget, previous_style);
22aff579
VS
583}
584
c801d85f 585static void
da048e3d 586gtk_pizza_add (GtkContainer *container,
bf3dab48 587 GtkWidget *widget)
c801d85f 588{
ed673c6a 589 g_return_if_fail (container != NULL);
da048e3d 590 g_return_if_fail (GTK_IS_PIZZA (container));
ed673c6a 591 g_return_if_fail (widget != NULL);
c801d85f 592
da048e3d 593 gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 );
c801d85f
KB
594}
595
596static void
da048e3d 597gtk_pizza_remove (GtkContainer *container,
b6fa52db 598 GtkWidget *widget)
c801d85f 599{
da048e3d
RR
600 GtkPizza *pizza;
601 GtkPizzaChild *child;
ed673c6a 602 GList *children;
c801d85f 603
ed673c6a 604 g_return_if_fail (container != NULL);
da048e3d 605 g_return_if_fail (GTK_IS_PIZZA (container));
ed673c6a 606 g_return_if_fail (widget != NULL);
c801d85f 607
da048e3d 608 pizza = GTK_PIZZA (container);
c801d85f 609
da048e3d 610 children = pizza->children;
ed673c6a 611 while (children)
c801d85f 612 {
ed673c6a 613 child = children->data;
c801d85f 614
ed673c6a 615 if (child->widget == widget)
bf3dab48
VZ
616 {
617 gtk_widget_unparent (widget);
c801d85f 618
ed673c6a
RR
619 /* security checks */
620 g_return_if_fail (GTK_IS_WIDGET (widget));
bf3dab48
VZ
621
622 pizza->children = g_list_remove_link (pizza->children, children);
623 g_list_free (children);
624 g_free (child);
c801d85f 625
ed673c6a 626 /* security checks */
bf3dab48
VZ
627 g_return_if_fail (GTK_IS_WIDGET (widget));
628
bf3dab48
VZ
629 break;
630 }
c801d85f 631
ed673c6a 632 children = children->next;
c801d85f
KB
633 }
634}
635
636static void
da048e3d 637gtk_pizza_forall (GtkContainer *container,
b6fa52db
RR
638 gboolean include_internals,
639 GtkCallback callback,
640 gpointer callback_data)
c801d85f 641{
da048e3d
RR
642 GtkPizza *pizza;
643 GtkPizzaChild *child;
6d693bb4 644 GList *children;
c801d85f 645
6d693bb4 646 g_return_if_fail (container != NULL);
da048e3d 647 g_return_if_fail (GTK_IS_PIZZA (container));
90350682 648 g_return_if_fail (callback != (GtkCallback)NULL);
c801d85f 649
da048e3d 650 pizza = GTK_PIZZA (container);
c801d85f 651
da048e3d 652 children = pizza->children;
6d693bb4 653 while (children)
c801d85f 654 {
6d693bb4
RR
655 child = children->data;
656 children = children->next;
c801d85f 657
6d693bb4 658 (* callback) (child->widget, callback_data);
c801d85f
KB
659 }
660}
661
67d78217
RR
662static void
663gtk_pizza_allocate_child (GtkPizza *pizza,
664 GtkPizzaChild *child)
665{
666 GtkAllocation allocation;
667 GtkRequisition requisition;
c801d85f 668
a31bb944
RR
669 allocation.x = child->x - pizza->m_xoffset;
670 allocation.y = child->y - pizza->m_yoffset;
67d78217
RR
671 gtk_widget_get_child_requisition (child->widget, &requisition);
672 allocation.width = requisition.width;
673 allocation.height = requisition.height;
674
db71eb06
RR
675 if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL)
676 {
677 /* reverse horizontal placement */
39b5648e
RR
678 gint offset,border;
679
680 offset = GTK_WIDGET(pizza)->allocation.width;
af05af4d 681 border = pizza->container.border_width;
39b5648e
RR
682 offset -= border*2;
683
34445cc7 684 allocation.x = offset - child->x - allocation.width + pizza->m_xoffset;
db71eb06
RR
685 }
686
67d78217
RR
687 gtk_widget_size_allocate (child->widget, &allocation);
688}
ed673c6a 689
ed673c6a 690static void
da048e3d 691gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
bf3dab48 692 gpointer cb_data)
ed673c6a 693{
da048e3d 694 GtkPizzaAdjData *data = cb_data;
ed673c6a 695
6d693bb4
RR
696 widget->allocation.x += data->dx;
697 widget->allocation.y += data->dy;
ed673c6a 698
6d693bb4
RR
699 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
700 {
bf3dab48
VZ
701 gtk_container_forall (GTK_CONTAINER (widget),
702 gtk_pizza_adjust_allocations_recurse,
703 cb_data);
6d693bb4 704 }
ed673c6a
RR
705}
706
707static void
da048e3d 708gtk_pizza_adjust_allocations (GtkPizza *pizza,
bf3dab48
VZ
709 gint dx,
710 gint dy)
ed673c6a 711{
0e09f76e
RR
712 GList *tmp_list;
713 GtkPizzaAdjData data;
ed673c6a 714
0e09f76e
RR
715 data.dx = dx;
716 data.dy = dy;
ed673c6a 717
0e09f76e
RR
718 tmp_list = pizza->children;
719 while (tmp_list)
ed673c6a 720 {
0e09f76e
RR
721 GtkPizzaChild *child = tmp_list->data;
722 tmp_list = tmp_list->next;
bf3dab48 723
0e09f76e
RR
724 child->widget->allocation.x += dx;
725 child->widget->allocation.y += dy;
ed673c6a 726
0e09f76e
RR
727 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
728 GTK_IS_CONTAINER (child->widget))
729 {
730 gtk_container_forall (GTK_CONTAINER (child->widget),
731 gtk_pizza_adjust_allocations_recurse,
732 &data);
733 }
ed673c6a
RR
734 }
735}
bf3dab48 736
ed673c6a 737void
da048e3d 738gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
ed673c6a 739{
a31bb944
RR
740 pizza->m_xoffset += dx;
741 pizza->m_yoffset += dy;
3fc6e5fa
RR
742
743 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
744
745 if (pizza->bin_window)
746 gdk_window_scroll( pizza->bin_window, -dx, -dy );
ed673c6a
RR
747}
748
c801d85f
KB
749#ifdef __cplusplus
750}
751#endif /* __cplusplus */