]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/win_gtk.c
added support for <bg> tag for toolbars in XRC
[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 #include "gtk/gtksignal.h"
19 #include "gtk/gtkprivate.h"
20 #include "gdk/gdkx.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif /* __cplusplus */
25
26 typedef struct _GtkPizzaAdjData GtkPizzaAdjData;
27
28 struct _GtkPizzaAdjData
29 {
30 gint dx;
31 gint dy;
32 };
33
34 static void gtk_pizza_class_init (GtkPizzaClass *klass);
35 static void gtk_pizza_init (GtkPizza *pizza);
36
37 static void gtk_pizza_realize (GtkWidget *widget);
38 static void gtk_pizza_unrealize (GtkWidget *widget);
39
40 static void gtk_pizza_map (GtkWidget *widget);
41
42 static void gtk_pizza_size_request (GtkWidget *widget,
43 GtkRequisition *requisition);
44 static void gtk_pizza_size_allocate (GtkWidget *widget,
45 GtkAllocation *allocation);
46 static gint gtk_pizza_expose (GtkWidget *widget,
47 GdkEventExpose *event);
48 static void gtk_pizza_style_set (GtkWidget *widget,
49 GtkStyle *previous_style);
50 static void gtk_pizza_add (GtkContainer *container,
51 GtkWidget *widget);
52 static void gtk_pizza_remove (GtkContainer *container,
53 GtkWidget *widget);
54 static void gtk_pizza_forall (GtkContainer *container,
55 gboolean include_internals,
56 GtkCallback callback,
57 gpointer callback_data);
58
59 static void gtk_pizza_allocate_child (GtkPizza *pizza,
60 GtkPizzaChild *child);
61 static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
62 gpointer cb_data);
63
64 static GtkType gtk_pizza_child_type (GtkContainer *container);
65
66 static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
67 GtkAdjustment *hadj,
68 GtkAdjustment *vadj);
69
70 /* static */
71 GtkContainerClass *pizza_parent_class = NULL;
72
73 GtkType
74 gtk_pizza_get_type ()
75 {
76 static GtkType pizza_type = 0;
77
78 if (!pizza_type)
79 {
80 static const GTypeInfo pizza_info =
81 {
82 sizeof (GtkPizzaClass),
83 NULL, /* base_init */
84 NULL, /* base_finalize */
85 (GClassInitFunc) gtk_pizza_class_init,
86 NULL, /* class_finalize */
87 NULL, /* class_data */
88 sizeof (GtkPizza),
89 16, /* n_preallocs */
90 (GInstanceInitFunc) gtk_pizza_init,
91 };
92 pizza_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkPizza", &pizza_info, (GTypeFlags)0);
93 }
94
95 return pizza_type;
96 }
97
98 /* Marshaller needed for set_scroll_adjustments signal,
99 generated with GLib-2.4.6 glib-genmarshal */
100 #define g_marshal_value_peek_object(v) g_value_get_object (v)
101 static void
102 g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
103 GValue *return_value,
104 guint n_param_values,
105 const GValue *param_values,
106 gpointer invocation_hint,
107 gpointer marshal_data)
108 {
109 typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1,
110 gpointer arg_1,
111 gpointer arg_2,
112 gpointer data2);
113 register GMarshalFunc_VOID__OBJECT_OBJECT callback;
114 register GCClosure *cc = (GCClosure*) closure;
115 register gpointer data1, data2;
116
117 g_return_if_fail (n_param_values == 3);
118
119 if (G_CCLOSURE_SWAP_DATA (closure))
120 {
121 data1 = closure->data;
122 data2 = g_value_peek_pointer (param_values + 0);
123 }
124 else
125 {
126 data1 = g_value_peek_pointer (param_values + 0);
127 data2 = closure->data;
128 }
129 callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
130
131 callback (data1,
132 g_marshal_value_peek_object (param_values + 1),
133 g_marshal_value_peek_object (param_values + 2),
134 data2);
135 }
136
137 static void
138 gtk_pizza_class_init (GtkPizzaClass *klass)
139 {
140 GtkObjectClass *object_class;
141 GtkWidgetClass *widget_class;
142 GtkContainerClass *container_class;
143
144 object_class = (GtkObjectClass*) klass;
145 widget_class = (GtkWidgetClass*) klass;
146 container_class = (GtkContainerClass*) klass;
147 pizza_parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
148
149 widget_class->map = gtk_pizza_map;
150 widget_class->realize = gtk_pizza_realize;
151 widget_class->unrealize = gtk_pizza_unrealize;
152 widget_class->size_request = gtk_pizza_size_request;
153 widget_class->size_allocate = gtk_pizza_size_allocate;
154 widget_class->expose_event = gtk_pizza_expose;
155 widget_class->style_set = gtk_pizza_style_set;
156
157 container_class->add = gtk_pizza_add;
158 container_class->remove = gtk_pizza_remove;
159 container_class->forall = gtk_pizza_forall;
160
161 container_class->child_type = gtk_pizza_child_type;
162
163 klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments;
164
165 widget_class->set_scroll_adjustments_signal =
166 g_signal_new(
167 "set_scroll_adjustments",
168 G_TYPE_FROM_CLASS(object_class),
169 G_SIGNAL_RUN_LAST,
170 G_STRUCT_OFFSET(GtkPizzaClass, set_scroll_adjustments),
171 NULL,
172 NULL,
173 g_cclosure_user_marshal_VOID__OBJECT_OBJECT,
174 G_TYPE_NONE,
175 2,
176 GTK_TYPE_ADJUSTMENT,
177 GTK_TYPE_ADJUSTMENT);
178 }
179
180 static GtkType
181 gtk_pizza_child_type (GtkContainer *container)
182 {
183 return GTK_TYPE_WIDGET;
184 }
185
186 static void
187 gtk_pizza_init (GtkPizza *pizza)
188 {
189 GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
190
191 pizza->shadow_type = GTK_MYSHADOW_NONE;
192
193 pizza->children = NULL;
194
195 pizza->width = 20;
196 pizza->height = 20;
197
198 pizza->bin_window = NULL;
199
200 pizza->xoffset = 0;
201 pizza->yoffset = 0;
202
203 pizza->configure_serial = 0;
204 pizza->scroll_x = 0;
205 pizza->scroll_y = 0;
206 pizza->visibility = GDK_VISIBILITY_PARTIAL;
207
208 pizza->clear_on_draw = TRUE;
209 pizza->use_filter = TRUE;
210 pizza->external_expose = FALSE;
211 }
212
213 GtkWidget*
214 gtk_pizza_new ()
215 {
216 GtkPizza *pizza;
217
218 pizza = gtk_type_new (gtk_pizza_get_type ());
219
220 return GTK_WIDGET (pizza);
221 }
222
223 static void
224 gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
225 GtkAdjustment *hadj,
226 GtkAdjustment *vadj)
227 {
228 /* We handle scrolling in the wxScrolledWindow, not here. */
229 }
230
231 void
232 gtk_pizza_set_shadow_type (GtkPizza *pizza,
233 GtkMyShadowType type)
234 {
235 g_return_if_fail (pizza != NULL);
236 g_return_if_fail (GTK_IS_PIZZA (pizza));
237
238 if ((GtkMyShadowType) pizza->shadow_type != type)
239 {
240 pizza->shadow_type = type;
241
242 if (GTK_WIDGET_VISIBLE (pizza))
243 {
244 gtk_widget_size_allocate (GTK_WIDGET (pizza), &(GTK_WIDGET (pizza)->allocation));
245 gtk_widget_queue_draw (GTK_WIDGET (pizza));
246 }
247 }
248 }
249
250 void
251 gtk_pizza_set_clear (GtkPizza *pizza,
252 gboolean clear)
253 {
254 g_return_if_fail (pizza != NULL);
255 g_return_if_fail (GTK_IS_PIZZA (pizza));
256
257 pizza->clear_on_draw = clear;
258 }
259
260 void
261 gtk_pizza_set_filter (GtkPizza *pizza,
262 gboolean use)
263 {
264 g_return_if_fail (pizza != NULL);
265 g_return_if_fail (GTK_IS_PIZZA (pizza));
266
267 pizza->use_filter = use;
268 }
269
270 void
271 gtk_pizza_set_external (GtkPizza *pizza,
272 gboolean expose)
273 {
274 g_return_if_fail (pizza != NULL);
275 g_return_if_fail (GTK_IS_PIZZA (pizza));
276
277 pizza->external_expose = expose;
278 }
279
280 void
281 gtk_pizza_put (GtkPizza *pizza,
282 GtkWidget *widget,
283 gint x,
284 gint y,
285 gint width,
286 gint height)
287 {
288 GtkPizzaChild *child_info;
289
290 g_return_if_fail (pizza != NULL);
291 g_return_if_fail (GTK_IS_PIZZA (pizza));
292 g_return_if_fail (widget != NULL);
293
294 child_info = g_new (GtkPizzaChild, 1);
295
296 child_info->widget = widget;
297 child_info->x = x;
298 child_info->y = y;
299 child_info->width = width;
300 child_info->height = height;
301
302 pizza->children = g_list_append (pizza->children, child_info);
303
304 if (GTK_WIDGET_REALIZED (pizza))
305 gtk_widget_set_parent_window (widget, pizza->bin_window);
306
307 gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
308
309 gtk_widget_set_size_request (widget, width, height);
310 }
311
312 void
313 gtk_pizza_move (GtkPizza *pizza,
314 GtkWidget *widget,
315 gint x,
316 gint y)
317 {
318 GtkPizzaChild *child;
319 GList *children;
320
321 g_return_if_fail (pizza != NULL);
322 g_return_if_fail (GTK_IS_PIZZA (pizza));
323 g_return_if_fail (widget != NULL);
324
325 children = pizza->children;
326 while (children)
327 {
328 child = children->data;
329 children = children->next;
330
331 if (child->widget == widget)
332 {
333 if ((child->x == x) && (child->y == y))
334 break;
335
336 child->x = x;
337 child->y = y;
338
339 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
340 gtk_widget_queue_resize (widget);
341 break;
342 }
343 }
344 }
345
346 void
347 gtk_pizza_resize (GtkPizza *pizza,
348 GtkWidget *widget,
349 gint width,
350 gint height)
351 {
352 GtkPizzaChild *child;
353 GList *children;
354
355 g_return_if_fail (pizza != NULL);
356 g_return_if_fail (GTK_IS_PIZZA (pizza));
357 g_return_if_fail (widget != NULL);
358
359 children = pizza->children;
360 while (children)
361 {
362 child = children->data;
363 children = children->next;
364
365 if (child->widget == widget)
366 {
367 if ((child->width == width) && (child->height == height))
368 break;
369
370 child->width = width;
371 child->height = height;
372
373 gtk_widget_set_size_request (widget, width, height);
374
375 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
376 gtk_widget_queue_resize (widget);
377 break;
378 }
379 }
380 }
381
382 void
383 gtk_pizza_set_size (GtkPizza *pizza,
384 GtkWidget *widget,
385 gint x,
386 gint y,
387 gint width,
388 gint height)
389 {
390 GtkPizzaChild *child;
391 GList *children;
392
393 g_return_if_fail (pizza != NULL);
394 g_return_if_fail (GTK_IS_PIZZA (pizza));
395 g_return_if_fail (widget != NULL);
396
397 children = pizza->children;
398 while (children)
399 {
400 child = children->data;
401 children = children->next;
402
403 if (child->widget == widget)
404 {
405 if ((child->x == x) &&
406 (child->y == y) &&
407 (child->width == width) &&
408 (child->height == height)) return;
409
410 child->x = x;
411 child->y = y;
412 child->width = width;
413 child->height = height;
414
415 gtk_widget_set_size_request (widget, width, height);
416
417 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
418 gtk_widget_queue_resize (widget);
419
420 return;
421 }
422 }
423 }
424
425 gint
426 gtk_pizza_child_resized (GtkPizza *pizza,
427 GtkWidget *widget)
428 {
429 GtkPizzaChild *child;
430 GList *children;
431
432 g_return_val_if_fail (pizza != NULL, FALSE);
433 g_return_val_if_fail (GTK_IS_PIZZA (pizza), FALSE);
434 g_return_val_if_fail (widget != NULL, FALSE);
435
436 children = pizza->children;
437 while (children)
438 {
439 child = children->data;
440 children = children->next;
441
442 if (child->widget == widget)
443 {
444 return ((child->width == widget->allocation.width) &&
445 (child->height == widget->allocation.height));
446 }
447 }
448
449 return FALSE;
450 }
451
452 static void
453 gtk_pizza_map (GtkWidget *widget)
454 {
455 GtkPizza *pizza;
456 GtkPizzaChild *child;
457 GList *children;
458
459 g_return_if_fail (widget != NULL);
460 g_return_if_fail (GTK_IS_PIZZA (widget));
461
462 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
463 pizza = GTK_PIZZA (widget);
464
465 children = pizza->children;
466 while (children)
467 {
468 child = children->data;
469 children = children->next;
470
471 if ( GTK_WIDGET_VISIBLE (child->widget) &&
472 !GTK_WIDGET_MAPPED (child->widget) &&
473 TRUE)
474 {
475 gtk_widget_map (child->widget);
476 }
477 }
478
479 gdk_window_show (widget->window);
480 gdk_window_show (pizza->bin_window);
481 }
482
483 static void
484 gtk_pizza_realize (GtkWidget *widget)
485 {
486 GtkPizza *pizza;
487 GdkWindowAttr attributes;
488 gint attributes_mask;
489 GtkPizzaChild *child;
490 GList *children;
491
492 g_return_if_fail (widget != NULL);
493 g_return_if_fail (GTK_IS_PIZZA (widget));
494
495 pizza = GTK_PIZZA (widget);
496 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
497
498 attributes.window_type = GDK_WINDOW_CHILD;
499
500 attributes.x = widget->allocation.x;
501 attributes.y = widget->allocation.y;
502 attributes.width = widget->allocation.width;
503 attributes.height = widget->allocation.height;
504
505 #ifndef __WXUNIVERSAL__
506 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
507 {
508 /* no border, no changes to sizes */
509 }
510 else if (pizza->shadow_type == GTK_MYSHADOW_THIN)
511 {
512 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
513 attributes.x += 1;
514 attributes.y += 1;
515 attributes.width -= 2;
516 attributes.height -= 2;
517 }
518 else
519 {
520 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
521 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
522 attributes.x += 2;
523 attributes.y += 2;
524 attributes.width -= 4;
525 attributes.height -= 4;
526 }
527 #endif /* __WXUNIVERSAL__ */
528
529 /* minimal size */
530 if (attributes.width < 2) attributes.width = 2;
531 if (attributes.height < 2) attributes.height = 2;
532
533 attributes.wclass = GDK_INPUT_OUTPUT;
534 attributes.visual = gtk_widget_get_visual (widget);
535 attributes.colormap = gtk_widget_get_colormap (widget);
536 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
537 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
538
539 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget),
540 &attributes, attributes_mask);
541 gdk_window_set_user_data (widget->window, widget);
542
543 attributes.x = 0;
544 attributes.y = 0;
545
546 attributes.event_mask = gtk_widget_get_events (widget);
547 attributes.event_mask |= GDK_EXPOSURE_MASK |
548 GDK_SCROLL_MASK |
549 GDK_POINTER_MOTION_MASK |
550 GDK_POINTER_MOTION_HINT_MASK |
551 GDK_BUTTON_MOTION_MASK |
552 GDK_BUTTON1_MOTION_MASK |
553 GDK_BUTTON2_MOTION_MASK |
554 GDK_BUTTON3_MOTION_MASK |
555 GDK_BUTTON_PRESS_MASK |
556 GDK_BUTTON_RELEASE_MASK |
557 GDK_KEY_PRESS_MASK |
558 GDK_KEY_RELEASE_MASK |
559 GDK_ENTER_NOTIFY_MASK |
560 GDK_LEAVE_NOTIFY_MASK |
561 GDK_FOCUS_CHANGE_MASK;
562
563 pizza->bin_window = gdk_window_new(widget->window,
564 &attributes, attributes_mask);
565 gdk_window_set_user_data (pizza->bin_window, widget);
566
567 widget->style = gtk_style_attach (widget->style, widget->window);
568 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
569 gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL );
570
571 /*
572 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
573 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
574 */
575
576 /* cannot be done before realisation */
577 children = pizza->children;
578 while (children)
579 {
580 child = children->data;
581 children = children->next;
582
583 gtk_widget_set_parent_window (child->widget, pizza->bin_window);
584 }
585 }
586
587 static void
588 gtk_pizza_unrealize (GtkWidget *widget)
589 {
590 GtkPizza *pizza;
591
592 g_return_if_fail (widget != NULL);
593 g_return_if_fail (GTK_IS_PIZZA (widget));
594
595 pizza = GTK_PIZZA (widget);
596
597 gdk_window_set_user_data (pizza->bin_window, NULL);
598 gdk_window_destroy (pizza->bin_window);
599 pizza->bin_window = NULL;
600
601 if (GTK_WIDGET_CLASS (pizza_parent_class)->unrealize)
602 (* GTK_WIDGET_CLASS (pizza_parent_class)->unrealize) (widget);
603 }
604
605 static void
606 gtk_pizza_size_request (GtkWidget *widget,
607 GtkRequisition *requisition)
608 {
609 GtkPizza *pizza;
610 GtkPizzaChild *child;
611 GList *children;
612 GtkRequisition child_requisition;
613
614 g_return_if_fail (widget != NULL);
615 g_return_if_fail (GTK_IS_PIZZA (widget));
616 g_return_if_fail (requisition != NULL);
617
618 pizza = GTK_PIZZA (widget);
619
620 children = pizza->children;
621 while (children)
622 {
623 child = children->data;
624 children = children->next;
625
626 if (GTK_WIDGET_VISIBLE (child->widget))
627 {
628 gtk_widget_size_request (child->widget, &child_requisition);
629 }
630 }
631
632 /* request very little, I'm not sure if requesting nothing
633 will always have positive effects on stability... */
634 requisition->width = 2;
635 requisition->height = 2;
636 }
637
638 static void
639 gtk_pizza_size_allocate (GtkWidget *widget,
640 GtkAllocation *allocation)
641 {
642 GtkPizza *pizza;
643 gint border;
644 gint x,y,w,h;
645 GtkPizzaChild *child;
646 GList *children;
647
648 g_return_if_fail (widget != NULL);
649 g_return_if_fail (GTK_IS_PIZZA(widget));
650 g_return_if_fail (allocation != NULL);
651
652 pizza = GTK_PIZZA (widget);
653
654 widget->allocation = *allocation;
655
656 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
657 border = 0;
658 else
659 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
660 border = 1;
661 else
662 border = 2;
663
664 x = allocation->x + border;
665 y = allocation->y + border;
666 w = allocation->width - border*2;
667 h = allocation->height - border*2;
668
669 if (GTK_WIDGET_REALIZED (widget))
670 {
671 gdk_window_move_resize( widget->window, x, y, w, h );
672 gdk_window_move_resize( pizza->bin_window, 0, 0, w, h );
673 }
674
675 children = pizza->children;
676 while (children)
677 {
678 child = children->data;
679 children = children->next;
680
681 gtk_pizza_allocate_child (pizza, child);
682 }
683 }
684
685 static gint
686 gtk_pizza_expose (GtkWidget *widget,
687 GdkEventExpose *event)
688 {
689 GtkPizza *pizza;
690
691 g_return_val_if_fail (widget != NULL, FALSE);
692 g_return_val_if_fail (GTK_IS_PIZZA (widget), FALSE);
693 g_return_val_if_fail (event != NULL, FALSE);
694
695 pizza = GTK_PIZZA (widget);
696
697 if (event->window != pizza->bin_window)
698 return FALSE;
699
700 /* We handle all expose events in window.cpp now. */
701 if (pizza->external_expose)
702 return FALSE;
703
704 (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, event);
705
706 return FALSE;
707 }
708
709 static void
710 gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style)
711 {
712 if (GTK_WIDGET_REALIZED(widget))
713 {
714 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
715 gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL );
716 }
717
718 (* GTK_WIDGET_CLASS (pizza_parent_class)->style_set) (widget, previous_style);
719 }
720
721 static void
722 gtk_pizza_add (GtkContainer *container,
723 GtkWidget *widget)
724 {
725 g_return_if_fail (container != NULL);
726 g_return_if_fail (GTK_IS_PIZZA (container));
727 g_return_if_fail (widget != NULL);
728
729 gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 );
730 }
731
732 static void
733 gtk_pizza_remove (GtkContainer *container,
734 GtkWidget *widget)
735 {
736 GtkPizza *pizza;
737 GtkPizzaChild *child;
738 GList *children;
739
740 g_return_if_fail (container != NULL);
741 g_return_if_fail (GTK_IS_PIZZA (container));
742 g_return_if_fail (widget != NULL);
743
744 pizza = GTK_PIZZA (container);
745
746 children = pizza->children;
747 while (children)
748 {
749 child = children->data;
750
751 if (child->widget == widget)
752 {
753 gtk_widget_unparent (widget);
754
755 /* security checks */
756 g_return_if_fail (GTK_IS_WIDGET (widget));
757
758 pizza->children = g_list_remove_link (pizza->children, children);
759 g_list_free (children);
760 g_free (child);
761
762 /* security checks */
763 g_return_if_fail (GTK_IS_WIDGET (widget));
764
765 break;
766 }
767
768 children = children->next;
769 }
770 }
771
772 static void
773 gtk_pizza_forall (GtkContainer *container,
774 gboolean include_internals,
775 GtkCallback callback,
776 gpointer callback_data)
777 {
778 GtkPizza *pizza;
779 GtkPizzaChild *child;
780 GList *children;
781
782 g_return_if_fail (container != NULL);
783 g_return_if_fail (GTK_IS_PIZZA (container));
784 g_return_if_fail (callback != (GtkCallback)NULL);
785
786 pizza = GTK_PIZZA (container);
787
788 children = pizza->children;
789 while (children)
790 {
791 child = children->data;
792 children = children->next;
793
794 (* callback) (child->widget, callback_data);
795 }
796 }
797
798 static void
799 gtk_pizza_allocate_child (GtkPizza *pizza,
800 GtkPizzaChild *child)
801 {
802 GtkAllocation allocation;
803 GtkRequisition requisition;
804
805 allocation.x = child->x - pizza->xoffset;
806 allocation.y = child->y - pizza->yoffset;
807 gtk_widget_get_child_requisition (child->widget, &requisition);
808 allocation.width = requisition.width;
809 allocation.height = requisition.height;
810
811 gtk_widget_size_allocate (child->widget, &allocation);
812 }
813
814 static void
815 gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
816 gpointer cb_data)
817 {
818 GtkPizzaAdjData *data = cb_data;
819
820 widget->allocation.x += data->dx;
821 widget->allocation.y += data->dy;
822
823 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
824 {
825 gtk_container_forall (GTK_CONTAINER (widget),
826 gtk_pizza_adjust_allocations_recurse,
827 cb_data);
828 }
829 }
830
831 static void
832 gtk_pizza_adjust_allocations (GtkPizza *pizza,
833 gint dx,
834 gint dy)
835 {
836 GList *tmp_list;
837 GtkPizzaAdjData data;
838
839 data.dx = dx;
840 data.dy = dy;
841
842 tmp_list = pizza->children;
843 while (tmp_list)
844 {
845 GtkPizzaChild *child = tmp_list->data;
846 tmp_list = tmp_list->next;
847
848 child->widget->allocation.x += dx;
849 child->widget->allocation.y += dy;
850
851 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
852 GTK_IS_CONTAINER (child->widget))
853 {
854 gtk_container_forall (GTK_CONTAINER (child->widget),
855 gtk_pizza_adjust_allocations_recurse,
856 &data);
857 }
858 }
859 }
860
861
862 /* This is the main routine to do the scrolling. Scrolling is
863 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
864 * a few modifications.
865 *
866 * The main improvement is that we keep track of whether we
867 * are obscured or not. If not, we ignore the generated expose
868 * events and instead do the exposes ourself, without having
869 * to wait for a roundtrip to the server. This also provides
870 * a limited form of expose-event compression, since we do
871 * the affected area as one big chunk.
872 */
873
874 void
875 gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
876 {
877 pizza->xoffset += dx;
878 pizza->yoffset += dy;
879
880 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
881
882 if (pizza->bin_window)
883 gdk_window_scroll( pizza->bin_window, -dx, -dy );
884 }
885
886 #ifdef __cplusplus
887 }
888 #endif /* __cplusplus */