]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/win_gtk.c
more properties
[wxWidgets.git] / src / gtk / win_gtk.c
1 /* ///////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/win_gtk.c
3 // Purpose: Native GTK+ widget for wxWidgets, based on GtkLayout and
4 // GtkFixed. It makes use of the gravity window property and
5 // therefore does not work with GTK 1.0.
6 // Author: Robert Roebling
7 // Id: $Id$
8 // Copyright: (c) 1998 Robert Roebling
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////// */
11
12 #ifdef VMS
13 #define XCheckIfEvent XCHECKIFEVENT
14 #endif
15
16 #include "wx/platform.h"
17 #include "wx/gtk/win_gtk.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif /* __cplusplus */
22
23 typedef struct _GtkPizzaAdjData GtkPizzaAdjData;
24
25 struct _GtkPizzaAdjData
26 {
27 gint dx;
28 gint dy;
29 };
30
31 static void gtk_pizza_class_init (GtkPizzaClass *klass);
32 static void gtk_pizza_init (GtkPizza *pizza);
33
34 static void gtk_pizza_realize (GtkWidget *widget);
35 static void gtk_pizza_unrealize (GtkWidget *widget);
36
37 static void gtk_pizza_map (GtkWidget *widget);
38
39 static void gtk_pizza_size_request (GtkWidget *widget,
40 GtkRequisition *requisition);
41 static void gtk_pizza_size_allocate (GtkWidget *widget,
42 GtkAllocation *allocation);
43 static gint gtk_pizza_expose (GtkWidget *widget,
44 GdkEventExpose *event);
45 static void gtk_pizza_style_set (GtkWidget *widget,
46 GtkStyle *previous_style);
47 static void gtk_pizza_add (GtkContainer *container,
48 GtkWidget *widget);
49 static void gtk_pizza_remove (GtkContainer *container,
50 GtkWidget *widget);
51 static void gtk_pizza_forall (GtkContainer *container,
52 gboolean include_internals,
53 GtkCallback callback,
54 gpointer callback_data);
55
56 static void gtk_pizza_allocate_child (GtkPizza *pizza,
57 GtkPizzaChild *child);
58 static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
59 gpointer cb_data);
60
61 static GtkType gtk_pizza_child_type (GtkContainer *container);
62
63 static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
64 GtkAdjustment *hadj,
65 GtkAdjustment *vadj);
66
67 /* static */
68 GtkContainerClass *pizza_parent_class = NULL;
69
70 GtkType
71 gtk_pizza_get_type ()
72 {
73 static GtkType pizza_type = 0;
74
75 if (!pizza_type)
76 {
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 };
89 pizza_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkPizza", &pizza_info, (GTypeFlags)0);
90 }
91
92 return pizza_type;
93 }
94
95 /* Marshaller needed for set_scroll_adjustments signal,
96 generated with GLib-2.4.6 glib-genmarshal */
97 #define g_marshal_value_peek_object(v) g_value_get_object (v)
98 static void
99 g_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 }
133
134 static void
135 gtk_pizza_class_init (GtkPizzaClass *klass)
136 {
137 GtkObjectClass *object_class;
138 GtkWidgetClass *widget_class;
139 GtkContainerClass *container_class;
140
141 object_class = (GtkObjectClass*) klass;
142 widget_class = (GtkWidgetClass*) klass;
143 container_class = (GtkContainerClass*) klass;
144 pizza_parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
145
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;
151 widget_class->expose_event = gtk_pizza_expose;
152 widget_class->style_set = gtk_pizza_style_set;
153
154 container_class->add = gtk_pizza_add;
155 container_class->remove = gtk_pizza_remove;
156 container_class->forall = gtk_pizza_forall;
157
158 container_class->child_type = gtk_pizza_child_type;
159
160 klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments;
161
162 widget_class->set_scroll_adjustments_signal =
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);
175 }
176
177 static GtkType
178 gtk_pizza_child_type (GtkContainer *container)
179 {
180 return GTK_TYPE_WIDGET;
181 }
182
183 static void
184 gtk_pizza_init (GtkPizza *pizza)
185 {
186 GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
187
188 pizza->shadow_type = GTK_MYSHADOW_NONE;
189
190 pizza->children = NULL;
191
192 pizza->bin_window = NULL;
193
194 pizza->m_xoffset = 0;
195 pizza->m_yoffset = 0;
196
197 pizza->m_width = -1;
198
199 pizza->external_expose = FALSE;
200 }
201
202 GtkWidget*
203 gtk_pizza_new ()
204 {
205 GtkPizza *pizza;
206
207 pizza = g_object_new (gtk_pizza_get_type (), NULL);
208
209 return GTK_WIDGET (pizza);
210 }
211
212 gint gtk_pizza_get_xoffset (GtkPizza *pizza)
213 {
214 g_return_val_if_fail ( (pizza != NULL), -1 );
215 g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 );
216
217 return pizza->m_xoffset;
218 }
219
220 gint gtk_pizza_get_yoffset (GtkPizza *pizza)
221 {
222 g_return_val_if_fail ( (pizza != NULL), -1 );
223 g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 );
224
225 return pizza->m_yoffset;
226 }
227
228 void gtk_pizza_set_xoffset (GtkPizza *pizza, gint xoffset)
229 {
230 g_return_if_fail (pizza != NULL);
231 g_return_if_fail (GTK_IS_PIZZA (pizza));
232
233 pizza->m_xoffset = xoffset;
234 // do something
235 }
236
237 void gtk_pizza_set_yoffset (GtkPizza *pizza, gint yoffset)
238 {
239 g_return_if_fail (pizza != NULL);
240 g_return_if_fail (GTK_IS_PIZZA (pizza));
241
242 pizza->m_xoffset = yoffset;
243 // do something
244 }
245
246 gint gtk_pizza_get_rtl_offset (GtkPizza *pizza)
247 {
248 gint width;
249
250 g_return_val_if_fail ( (pizza != NULL), 0 );
251 g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), 0 );
252
253 if (!pizza->bin_window) return 0;
254
255 gdk_window_get_geometry( pizza->bin_window, NULL, NULL, &width, NULL, NULL );
256
257 return width;
258 }
259
260
261 static void
262 gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
263 GtkAdjustment *hadj,
264 GtkAdjustment *vadj)
265 {
266 /* We handle scrolling in the wxScrolledWindow, not here. */
267 }
268
269 void
270 gtk_pizza_set_shadow_type (GtkPizza *pizza,
271 GtkMyShadowType type)
272 {
273 g_return_if_fail (pizza != NULL);
274 g_return_if_fail (GTK_IS_PIZZA (pizza));
275
276 if (pizza->shadow_type != type)
277 {
278 pizza->shadow_type = type;
279
280 if (GTK_WIDGET_VISIBLE (pizza))
281 {
282 gtk_widget_size_allocate (GTK_WIDGET (pizza), &(GTK_WIDGET (pizza)->allocation));
283 gtk_widget_queue_draw (GTK_WIDGET (pizza));
284 }
285 }
286 }
287
288 void
289 gtk_pizza_set_external (GtkPizza *pizza,
290 gboolean expose)
291 {
292 g_return_if_fail (pizza != NULL);
293 g_return_if_fail (GTK_IS_PIZZA (pizza));
294
295 pizza->external_expose = expose;
296 }
297
298 void
299 gtk_pizza_put (GtkPizza *pizza,
300 GtkWidget *widget,
301 gint x,
302 gint y,
303 gint width,
304 gint height)
305 {
306 GtkPizzaChild *child_info;
307
308 g_return_if_fail (pizza != NULL);
309 g_return_if_fail (GTK_IS_PIZZA (pizza));
310 g_return_if_fail (widget != NULL);
311
312 if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL)
313 {
314 // reverse horizontal placement
315 x = pizza->m_width - x - width;
316 }
317
318 child_info = g_new (GtkPizzaChild, 1);
319
320 child_info->widget = widget;
321 child_info->x = x;
322 child_info->y = y;
323 child_info->width = width;
324 child_info->height = height;
325
326 if (GTK_IS_PIZZA(widget))
327 GTK_PIZZA(widget)->m_width = width;
328
329 pizza->children = g_list_append (pizza->children, child_info);
330
331 if (GTK_WIDGET_REALIZED (pizza))
332 gtk_widget_set_parent_window (widget, pizza->bin_window);
333
334 gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
335
336 gtk_widget_set_size_request (widget, width, height);
337 }
338
339 void
340 gtk_pizza_set_size (GtkPizza *pizza,
341 GtkWidget *widget,
342 gint x,
343 gint y,
344 gint width,
345 gint height)
346 {
347 GtkPizzaChild *child;
348 GList *children;
349
350 g_return_if_fail (pizza != NULL);
351 g_return_if_fail (GTK_IS_PIZZA (pizza));
352 g_return_if_fail (widget != NULL);
353
354 #ifndef WX_WARN_ILLEGAL_SETSIZE
355 /* this really shouldn't happen -- but it does, a lot, right now and we
356 can't pass negative values to gtk_widget_set_size_request() without getting
357 a warning printed out, so filter them out here */
358 if ( width < 0 )
359 width = 0;
360 if ( height < 0 )
361 height = 0;
362 #endif
363
364 children = pizza->children;
365 while (children)
366 {
367 child = children->data;
368 children = children->next;
369
370 if (child->widget == widget)
371 {
372 gint new_x = x;
373 if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL)
374 {
375 // reverse horizontal placement
376 new_x = pizza->m_width - new_x - width;
377 }
378
379 if ((child->x == new_x) &&
380 (child->y == y) &&
381 (child->width == width) &&
382 (child->height == height)) return;
383
384 child->x = new_x;
385 child->y = y;
386 child->width = width;
387 child->height = height;
388
389 if (GTK_IS_PIZZA(widget))
390 GTK_PIZZA(widget)->m_width = width;
391
392 gtk_widget_set_size_request (widget, width, height);
393
394 return;
395 }
396 }
397 }
398
399 static void
400 gtk_pizza_map (GtkWidget *widget)
401 {
402 GtkPizza *pizza;
403 GtkPizzaChild *child;
404 GList *children;
405
406 g_return_if_fail (widget != NULL);
407 g_return_if_fail (GTK_IS_PIZZA (widget));
408
409 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
410 pizza = GTK_PIZZA (widget);
411
412 children = pizza->children;
413 while (children)
414 {
415 child = children->data;
416 children = children->next;
417
418 if ( GTK_WIDGET_VISIBLE (child->widget) &&
419 !GTK_WIDGET_MAPPED (child->widget) )
420 {
421 gtk_widget_map (child->widget);
422 }
423 }
424
425 gdk_window_show (widget->window);
426 gdk_window_show (pizza->bin_window);
427 }
428
429 static void
430 gtk_pizza_realize (GtkWidget *widget)
431 {
432 GtkPizza *pizza;
433 GdkWindowAttr attributes;
434 gint attributes_mask;
435 GtkPizzaChild *child;
436 GList *children;
437
438 g_return_if_fail (widget != NULL);
439 g_return_if_fail (GTK_IS_PIZZA (widget));
440
441 pizza = GTK_PIZZA (widget);
442 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
443
444 attributes.window_type = GDK_WINDOW_CHILD;
445
446 attributes.x = widget->allocation.x;
447 attributes.y = widget->allocation.y;
448 attributes.width = widget->allocation.width;
449 attributes.height = widget->allocation.height;
450
451 #ifndef __WXUNIVERSAL__
452 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
453 {
454 /* no border, no changes to sizes */
455 }
456 else if (pizza->shadow_type == GTK_MYSHADOW_THIN)
457 {
458 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
459 attributes.x += 1;
460 attributes.y += 1;
461 attributes.width -= 2;
462 attributes.height -= 2;
463 }
464 else
465 {
466 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
467 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
468 attributes.x += 2;
469 attributes.y += 2;
470 attributes.width -= 4;
471 attributes.height -= 4;
472 }
473 #endif /* __WXUNIVERSAL__ */
474
475 /* minimal size */
476 if (attributes.width < 2) attributes.width = 2;
477 if (attributes.height < 2) attributes.height = 2;
478
479 attributes.wclass = GDK_INPUT_OUTPUT;
480 attributes.visual = gtk_widget_get_visual (widget);
481 attributes.colormap = gtk_widget_get_colormap (widget);
482 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
483 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
484
485 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget),
486 &attributes, attributes_mask);
487 gdk_window_set_user_data (widget->window, widget);
488
489 attributes.x = 0;
490 attributes.y = 0;
491
492 attributes.event_mask = gtk_widget_get_events (widget);
493 attributes.event_mask |= GDK_EXPOSURE_MASK |
494 GDK_SCROLL_MASK |
495 GDK_POINTER_MOTION_MASK |
496 GDK_POINTER_MOTION_HINT_MASK |
497 GDK_BUTTON_MOTION_MASK |
498 GDK_BUTTON1_MOTION_MASK |
499 GDK_BUTTON2_MOTION_MASK |
500 GDK_BUTTON3_MOTION_MASK |
501 GDK_BUTTON_PRESS_MASK |
502 GDK_BUTTON_RELEASE_MASK |
503 GDK_KEY_PRESS_MASK |
504 GDK_KEY_RELEASE_MASK |
505 GDK_ENTER_NOTIFY_MASK |
506 GDK_LEAVE_NOTIFY_MASK |
507 GDK_FOCUS_CHANGE_MASK;
508
509 pizza->bin_window = gdk_window_new(widget->window,
510 &attributes, attributes_mask);
511 gdk_window_set_user_data (pizza->bin_window, widget);
512
513 widget->style = gtk_style_attach (widget->style, widget->window);
514 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
515 gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL );
516
517 /*
518 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
519 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
520 */
521
522 /* cannot be done before realisation */
523 children = pizza->children;
524 while (children)
525 {
526 child = children->data;
527 children = children->next;
528
529 gtk_widget_set_parent_window (child->widget, pizza->bin_window);
530 }
531 }
532
533 static void
534 gtk_pizza_unrealize (GtkWidget *widget)
535 {
536 GtkPizza *pizza;
537
538 g_return_if_fail (widget != NULL);
539 g_return_if_fail (GTK_IS_PIZZA (widget));
540
541 pizza = GTK_PIZZA (widget);
542
543 gdk_window_set_user_data (pizza->bin_window, NULL);
544 gdk_window_destroy (pizza->bin_window);
545 pizza->bin_window = NULL;
546
547 if (GTK_WIDGET_CLASS (pizza_parent_class)->unrealize)
548 (* GTK_WIDGET_CLASS (pizza_parent_class)->unrealize) (widget);
549 }
550
551 static void
552 gtk_pizza_size_request (GtkWidget *widget,
553 GtkRequisition *requisition)
554 {
555 GtkPizza *pizza;
556 GtkPizzaChild *child;
557 GList *children;
558 GtkRequisition child_requisition;
559
560 g_return_if_fail (widget != NULL);
561 g_return_if_fail (GTK_IS_PIZZA (widget));
562 g_return_if_fail (requisition != NULL);
563
564 pizza = GTK_PIZZA (widget);
565
566 children = pizza->children;
567 while (children)
568 {
569 child = children->data;
570 children = children->next;
571
572 if (GTK_WIDGET_VISIBLE (child->widget))
573 {
574 gtk_widget_size_request (child->widget, &child_requisition);
575 }
576 }
577
578 /* request very little, I'm not sure if requesting nothing
579 will always have positive effects on stability... */
580 requisition->width = 2;
581 requisition->height = 2;
582 }
583
584 static void
585 gtk_pizza_size_allocate (GtkWidget *widget,
586 GtkAllocation *allocation)
587 {
588 GtkPizza *pizza;
589 gint border;
590 gint x,y,w,h;
591 GtkPizzaChild *child;
592 GList *children;
593
594 g_return_if_fail (widget != NULL);
595 g_return_if_fail (GTK_IS_PIZZA(widget));
596 g_return_if_fail (allocation != NULL);
597
598 pizza = GTK_PIZZA (widget);
599
600 widget->allocation = *allocation;
601
602 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
603 border = 0;
604 else
605 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
606 border = 1;
607 else
608 border = 2;
609
610 x = allocation->x + border;
611 y = allocation->y + border;
612 w = allocation->width - border*2;
613 h = allocation->height - border*2;
614 if (w < 0)
615 w = 0;
616 if (h < 0)
617 h = 0;
618
619 if (GTK_WIDGET_REALIZED (widget))
620 {
621 gdk_window_move_resize( widget->window, x, y, w, h );
622 gdk_window_move_resize( pizza->bin_window, 0, 0, w, h );
623 }
624
625 children = pizza->children;
626 while (children)
627 {
628 child = children->data;
629 children = children->next;
630
631 gtk_pizza_allocate_child (pizza, child);
632 }
633 }
634
635 static gint
636 gtk_pizza_expose (GtkWidget *widget,
637 GdkEventExpose *event)
638 {
639 GtkPizza *pizza;
640
641 g_return_val_if_fail (widget != NULL, FALSE);
642 g_return_val_if_fail (GTK_IS_PIZZA (widget), FALSE);
643 g_return_val_if_fail (event != NULL, FALSE);
644
645 pizza = GTK_PIZZA (widget);
646
647 if (event->window != pizza->bin_window)
648 return FALSE;
649
650 /* We handle all expose events in window.cpp now. */
651 if (pizza->external_expose)
652 return FALSE;
653
654 (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, event);
655
656 return FALSE;
657 }
658
659 static void
660 gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style)
661 {
662 if (GTK_WIDGET_REALIZED(widget))
663 {
664 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
665 gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL );
666 }
667
668 (* GTK_WIDGET_CLASS (pizza_parent_class)->style_set) (widget, previous_style);
669 }
670
671 static void
672 gtk_pizza_add (GtkContainer *container,
673 GtkWidget *widget)
674 {
675 g_return_if_fail (container != NULL);
676 g_return_if_fail (GTK_IS_PIZZA (container));
677 g_return_if_fail (widget != NULL);
678
679 gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 );
680 }
681
682 static void
683 gtk_pizza_remove (GtkContainer *container,
684 GtkWidget *widget)
685 {
686 GtkPizza *pizza;
687 GtkPizzaChild *child;
688 GList *children;
689
690 g_return_if_fail (container != NULL);
691 g_return_if_fail (GTK_IS_PIZZA (container));
692 g_return_if_fail (widget != NULL);
693
694 pizza = GTK_PIZZA (container);
695
696 children = pizza->children;
697 while (children)
698 {
699 child = children->data;
700
701 if (child->widget == widget)
702 {
703 gtk_widget_unparent (widget);
704
705 /* security checks */
706 g_return_if_fail (GTK_IS_WIDGET (widget));
707
708 pizza->children = g_list_remove_link (pizza->children, children);
709 g_list_free (children);
710 g_free (child);
711
712 /* security checks */
713 g_return_if_fail (GTK_IS_WIDGET (widget));
714
715 break;
716 }
717
718 children = children->next;
719 }
720 }
721
722 static void
723 gtk_pizza_forall (GtkContainer *container,
724 gboolean include_internals,
725 GtkCallback callback,
726 gpointer callback_data)
727 {
728 GtkPizza *pizza;
729 GtkPizzaChild *child;
730 GList *children;
731
732 g_return_if_fail (container != NULL);
733 g_return_if_fail (GTK_IS_PIZZA (container));
734 g_return_if_fail (callback != (GtkCallback)NULL);
735
736 pizza = GTK_PIZZA (container);
737
738 children = pizza->children;
739 while (children)
740 {
741 child = children->data;
742 children = children->next;
743
744 (* callback) (child->widget, callback_data);
745 }
746 }
747
748 static void
749 gtk_pizza_allocate_child (GtkPizza *pizza,
750 GtkPizzaChild *child)
751 {
752 GtkAllocation allocation;
753 GtkRequisition requisition;
754
755 allocation.x = child->x - pizza->m_xoffset;
756 allocation.y = child->y - pizza->m_yoffset;
757 gtk_widget_get_child_requisition (child->widget, &requisition);
758 allocation.width = requisition.width;
759 allocation.height = requisition.height;
760
761 gtk_widget_size_allocate (child->widget, &allocation);
762 }
763
764 static void
765 gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
766 gpointer cb_data)
767 {
768 GtkPizzaAdjData *data = cb_data;
769
770 widget->allocation.x += data->dx;
771 widget->allocation.y += data->dy;
772
773 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
774 {
775 gtk_container_forall (GTK_CONTAINER (widget),
776 gtk_pizza_adjust_allocations_recurse,
777 cb_data);
778 }
779 }
780
781 static void
782 gtk_pizza_adjust_allocations (GtkPizza *pizza,
783 gint dx,
784 gint dy)
785 {
786 GList *tmp_list;
787 GtkPizzaAdjData data;
788
789 data.dx = dx;
790 data.dy = dy;
791
792 tmp_list = pizza->children;
793 while (tmp_list)
794 {
795 GtkPizzaChild *child = tmp_list->data;
796 tmp_list = tmp_list->next;
797
798 child->widget->allocation.x += dx;
799 child->widget->allocation.y += dy;
800
801 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
802 GTK_IS_CONTAINER (child->widget))
803 {
804 gtk_container_forall (GTK_CONTAINER (child->widget),
805 gtk_pizza_adjust_allocations_recurse,
806 &data);
807 }
808 }
809 }
810
811 void
812 gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
813 {
814 pizza->m_xoffset += dx;
815 pizza->m_yoffset += dy;
816
817 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
818
819 if (pizza->bin_window)
820 gdk_window_scroll( pizza->bin_window, -dx, -dy );
821 }
822
823 #ifdef __cplusplus
824 }
825 #endif /* __cplusplus */