]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/win_gtk.c
WinCE warning fixes.
[wxWidgets.git] / src / gtk / win_gtk.c
1 /* ///////////////////////////////////////////////////////////////////////////
2 // Name: 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/setup.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 #ifndef __WXGTK20__
27
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
31
32 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
33 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
34
35 #endif
36
37 typedef struct _GtkPizzaAdjData GtkPizzaAdjData;
38
39 struct _GtkPizzaAdjData
40 {
41 gint dx;
42 gint dy;
43 };
44
45 static void gtk_pizza_class_init (GtkPizzaClass *klass);
46 static void gtk_pizza_init (GtkPizza *pizza);
47
48 static void gtk_pizza_realize (GtkWidget *widget);
49 static void gtk_pizza_unrealize (GtkWidget *widget);
50
51 static void gtk_pizza_map (GtkWidget *widget);
52
53 static void gtk_pizza_size_request (GtkWidget *widget,
54 GtkRequisition *requisition);
55 static void gtk_pizza_size_allocate (GtkWidget *widget,
56 GtkAllocation *allocation);
57 #ifndef __WXGTK20__
58 static void gtk_pizza_draw (GtkWidget *widget,
59 GdkRectangle *area);
60 #endif /* __WXGTK20__ */
61 static gint gtk_pizza_expose (GtkWidget *widget,
62 GdkEventExpose *event);
63 static void gtk_pizza_style_set (GtkWidget *widget,
64 GtkStyle *previous_style);
65 static void gtk_pizza_add (GtkContainer *container,
66 GtkWidget *widget);
67 static void gtk_pizza_remove (GtkContainer *container,
68 GtkWidget *widget);
69 static void gtk_pizza_forall (GtkContainer *container,
70 gboolean include_internals,
71 GtkCallback callback,
72 gpointer callback_data);
73
74 static void gtk_pizza_allocate_child (GtkPizza *pizza,
75 GtkPizzaChild *child);
76 static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
77 gpointer cb_data);
78
79 #ifndef __WXGTK20__
80 static void gtk_pizza_position_child (GtkPizza *pizza,
81 GtkPizzaChild *child);
82 static void gtk_pizza_position_children (GtkPizza *pizza);
83
84 static GdkFilterReturn gtk_pizza_filter (GdkXEvent *gdk_xevent,
85 GdkEvent *event,
86 gpointer data);
87 static GdkFilterReturn gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
88 GdkEvent *event,
89 gpointer data);
90 #endif /* __WXGTK20__ */
91
92 static GtkType gtk_pizza_child_type (GtkContainer *container);
93
94 static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
95 GtkAdjustment *hadj,
96 GtkAdjustment *vadj);
97
98
99 #ifdef __WXGTK20__
100 GtkContainerClass *pizza_parent_class = NULL;
101 #else
102 static GtkContainerClass *pizza_parent_class = NULL;
103 #endif
104
105 static gboolean gravity_works;
106
107 guint
108 gtk_pizza_get_type ()
109 {
110 static guint pizza_type = 0;
111
112 if (!pizza_type)
113 {
114
115 #ifdef __WXGTK20__
116 static const GTypeInfo pizza_info =
117 {
118 sizeof (GtkPizzaClass),
119 NULL, /* base_init */
120 NULL, /* base_finalize */
121 (GClassInitFunc) gtk_pizza_class_init,
122 NULL, /* class_finalize */
123 NULL, /* class_data */
124 sizeof (GtkPizza),
125 16, /* n_preallocs */
126 (GInstanceInitFunc) gtk_pizza_init,
127 };
128 pizza_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkPizza", &pizza_info, 0);
129 #else
130 GtkTypeInfo pizza_info =
131 {
132 "GtkPizza",
133 sizeof (GtkPizza),
134 sizeof (GtkPizzaClass),
135 (GtkClassInitFunc) gtk_pizza_class_init,
136 (GtkObjectInitFunc) gtk_pizza_init,
137 /* reserved_1 */ NULL,
138 /* reserved_2 */ NULL,
139 (GtkClassInitFunc) NULL,
140 };
141 pizza_type = gtk_type_unique (gtk_container_get_type (), &pizza_info);
142 #endif
143 }
144
145 return pizza_type;
146 }
147
148 static void
149 gtk_pizza_class_init (GtkPizzaClass *klass)
150 {
151 GtkObjectClass *object_class;
152 GtkWidgetClass *widget_class;
153 GtkContainerClass *container_class;
154
155 object_class = (GtkObjectClass*) klass;
156 widget_class = (GtkWidgetClass*) klass;
157 container_class = (GtkContainerClass*) klass;
158 pizza_parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
159
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;
165 #ifndef __WXGTK20__
166 widget_class->draw = gtk_pizza_draw;
167 #endif
168 widget_class->expose_event = gtk_pizza_expose;
169 widget_class->style_set = gtk_pizza_style_set;
170
171 container_class->add = gtk_pizza_add;
172 container_class->remove = gtk_pizza_remove;
173 container_class->forall = gtk_pizza_forall;
174
175 container_class->child_type = gtk_pizza_child_type;
176
177 klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments;
178
179 widget_class->set_scroll_adjustments_signal =
180 gtk_signal_new ("set_scroll_adjustments",
181 GTK_RUN_LAST,
182 #ifdef __WXGTK20__
183 GTK_CLASS_TYPE(object_class),
184 #else
185 object_class->type,
186 #endif
187 GTK_SIGNAL_OFFSET (GtkPizzaClass, set_scroll_adjustments),
188 gtk_marshal_NONE__POINTER_POINTER,
189 GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
190 }
191
192 static GtkType
193 gtk_pizza_child_type (GtkContainer *container)
194 {
195 return GTK_TYPE_WIDGET;
196 }
197
198 static void
199 gtk_pizza_init (GtkPizza *pizza)
200 {
201 GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
202
203 pizza->shadow_type = GTK_MYSHADOW_NONE;
204
205 pizza->children = NULL;
206
207 pizza->width = 20;
208 pizza->height = 20;
209
210 pizza->bin_window = NULL;
211
212 pizza->xoffset = 0;
213 pizza->yoffset = 0;
214
215 pizza->configure_serial = 0;
216 pizza->scroll_x = 0;
217 pizza->scroll_y = 0;
218 pizza->visibility = GDK_VISIBILITY_PARTIAL;
219
220 pizza->clear_on_draw = TRUE;
221 pizza->use_filter = TRUE;
222 pizza->external_expose = FALSE;
223 }
224
225 GtkWidget*
226 gtk_pizza_new ()
227 {
228 GtkPizza *pizza;
229
230 pizza = gtk_type_new (gtk_pizza_get_type ());
231
232 return GTK_WIDGET (pizza);
233 }
234
235 static void
236 gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
237 GtkAdjustment *hadj,
238 GtkAdjustment *vadj)
239 {
240 /* We handle scrolling in the wxScrolledWindow, not here. */
241 }
242
243 void
244 gtk_pizza_set_shadow_type (GtkPizza *pizza,
245 GtkMyShadowType type)
246 {
247 g_return_if_fail (pizza != NULL);
248 g_return_if_fail (GTK_IS_PIZZA (pizza));
249
250 if ((GtkMyShadowType) pizza->shadow_type != type)
251 {
252 pizza->shadow_type = type;
253
254 if (GTK_WIDGET_VISIBLE (pizza))
255 {
256 gtk_widget_size_allocate (GTK_WIDGET (pizza), &(GTK_WIDGET (pizza)->allocation));
257 gtk_widget_queue_draw (GTK_WIDGET (pizza));
258 }
259 }
260 }
261
262 void
263 gtk_pizza_set_clear (GtkPizza *pizza,
264 gboolean clear)
265 {
266 g_return_if_fail (pizza != NULL);
267 g_return_if_fail (GTK_IS_PIZZA (pizza));
268
269 pizza->clear_on_draw = clear;
270 }
271
272 void
273 gtk_pizza_set_filter (GtkPizza *pizza,
274 gboolean use)
275 {
276 g_return_if_fail (pizza != NULL);
277 g_return_if_fail (GTK_IS_PIZZA (pizza));
278
279 pizza->use_filter = use;
280 }
281
282 void
283 gtk_pizza_set_external (GtkPizza *pizza,
284 gboolean expose)
285 {
286 g_return_if_fail (pizza != NULL);
287 g_return_if_fail (GTK_IS_PIZZA (pizza));
288
289 pizza->external_expose = expose;
290 }
291
292 void
293 gtk_pizza_put (GtkPizza *pizza,
294 GtkWidget *widget,
295 gint x,
296 gint y,
297 gint width,
298 gint height)
299 {
300 GtkPizzaChild *child_info;
301
302 g_return_if_fail (pizza != NULL);
303 g_return_if_fail (GTK_IS_PIZZA (pizza));
304 g_return_if_fail (widget != NULL);
305
306 child_info = g_new (GtkPizzaChild, 1);
307
308 child_info->widget = widget;
309 child_info->x = x;
310 child_info->y = y;
311 child_info->width = width;
312 child_info->height = height;
313
314 pizza->children = g_list_append (pizza->children, child_info);
315
316 if (GTK_WIDGET_REALIZED (pizza))
317 gtk_widget_set_parent_window (widget, pizza->bin_window);
318
319 gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
320
321 #ifndef __WXGTK20__ /* FIXME? */
322 if (!IS_ONSCREEN (x, y))
323 GTK_PRIVATE_SET_FLAG (widget, GTK_IS_OFFSCREEN);
324 #endif
325
326 gtk_widget_set_usize (widget, width, height);
327 }
328
329 void
330 gtk_pizza_move (GtkPizza *pizza,
331 GtkWidget *widget,
332 gint x,
333 gint y)
334 {
335 GtkPizzaChild *child;
336 GList *children;
337
338 g_return_if_fail (pizza != NULL);
339 g_return_if_fail (GTK_IS_PIZZA (pizza));
340 g_return_if_fail (widget != NULL);
341
342 children = pizza->children;
343 while (children)
344 {
345 child = children->data;
346 children = children->next;
347
348 if (child->widget == widget)
349 {
350 if ((child->x == x) && (child->y == y))
351 break;
352
353 child->x = x;
354 child->y = y;
355
356 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
357 gtk_widget_queue_resize (widget);
358 break;
359 }
360 }
361 }
362
363 void
364 gtk_pizza_resize (GtkPizza *pizza,
365 GtkWidget *widget,
366 gint width,
367 gint height)
368 {
369 GtkPizzaChild *child;
370 GList *children;
371
372 g_return_if_fail (pizza != NULL);
373 g_return_if_fail (GTK_IS_PIZZA (pizza));
374 g_return_if_fail (widget != NULL);
375
376 children = pizza->children;
377 while (children)
378 {
379 child = children->data;
380 children = children->next;
381
382 if (child->widget == widget)
383 {
384 if ((child->width == width) && (child->height == height))
385 break;
386
387 child->width = width;
388 child->height = height;
389
390 gtk_widget_set_usize (widget, width, height);
391
392 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
393 gtk_widget_queue_resize (widget);
394 break;
395 }
396 }
397 }
398
399 void
400 gtk_pizza_set_size (GtkPizza *pizza,
401 GtkWidget *widget,
402 gint x,
403 gint y,
404 gint width,
405 gint height)
406 {
407 GtkPizzaChild *child;
408 GList *children;
409
410 g_return_if_fail (pizza != NULL);
411 g_return_if_fail (GTK_IS_PIZZA (pizza));
412 g_return_if_fail (widget != NULL);
413
414 children = pizza->children;
415 while (children)
416 {
417 child = children->data;
418 children = children->next;
419
420 if (child->widget == widget)
421 {
422 if ((child->x == x) &&
423 (child->y == y) &&
424 (child->width == width) &&
425 (child->height == height)) return;
426
427 child->x = x;
428 child->y = y;
429 child->width = width;
430 child->height = height;
431
432 gtk_widget_set_usize (widget, width, height);
433
434 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
435 gtk_widget_queue_resize (widget);
436
437 return;
438 }
439 }
440 }
441
442 gint
443 gtk_pizza_child_resized (GtkPizza *pizza,
444 GtkWidget *widget)
445 {
446 GtkPizzaChild *child;
447 GList *children;
448
449 g_return_val_if_fail (pizza != NULL, FALSE);
450 g_return_val_if_fail (GTK_IS_PIZZA (pizza), FALSE);
451 g_return_val_if_fail (widget != NULL, FALSE);
452
453 children = pizza->children;
454 while (children)
455 {
456 child = children->data;
457 children = children->next;
458
459 if (child->widget == widget)
460 {
461 return ((child->width == widget->allocation.width) &&
462 (child->height == widget->allocation.height));
463 }
464 }
465
466 return FALSE;
467 }
468
469 static void
470 gtk_pizza_map (GtkWidget *widget)
471 {
472 GtkPizza *pizza;
473 GtkPizzaChild *child;
474 GList *children;
475
476 g_return_if_fail (widget != NULL);
477 g_return_if_fail (GTK_IS_PIZZA (widget));
478
479 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
480 pizza = GTK_PIZZA (widget);
481
482 children = pizza->children;
483 while (children)
484 {
485 child = children->data;
486 children = children->next;
487
488 if ( GTK_WIDGET_VISIBLE (child->widget) &&
489 !GTK_WIDGET_MAPPED (child->widget) &&
490 #ifdef __WXGTK20__
491 TRUE)
492 #else
493 !GTK_WIDGET_IS_OFFSCREEN (child->widget))
494 #endif
495 {
496 gtk_widget_map (child->widget);
497 }
498 }
499
500 gdk_window_show (widget->window);
501 gdk_window_show (pizza->bin_window);
502 }
503
504 static void
505 gtk_pizza_realize (GtkWidget *widget)
506 {
507 GtkPizza *pizza;
508 GdkWindowAttr attributes;
509 gint attributes_mask;
510 GtkPizzaChild *child;
511 GList *children;
512
513 g_return_if_fail (widget != NULL);
514 g_return_if_fail (GTK_IS_PIZZA (widget));
515
516 pizza = GTK_PIZZA (widget);
517 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
518
519 attributes.window_type = GDK_WINDOW_CHILD;
520
521 attributes.x = widget->allocation.x;
522 attributes.y = widget->allocation.y;
523 attributes.width = widget->allocation.width;
524 attributes.height = widget->allocation.height;
525
526 #ifndef __WXUNIVERSAL__
527 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
528 {
529 /* no border, no changes to sizes */
530 }
531 else if (pizza->shadow_type == GTK_MYSHADOW_THIN)
532 {
533 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
534 attributes.x += 1;
535 attributes.y += 1;
536 attributes.width -= 2;
537 attributes.height -= 2;
538 }
539 else
540 {
541 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
542 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
543 attributes.x += 2;
544 attributes.y += 2;
545 attributes.width -= 4;
546 attributes.height -= 4;
547 }
548 #endif /* __WXUNIVERSAL__ */
549
550 /* minimal size */
551 if (attributes.width < 2) attributes.width = 2;
552 if (attributes.height < 2) attributes.height = 2;
553
554 attributes.wclass = GDK_INPUT_OUTPUT;
555 attributes.visual = gtk_widget_get_visual (widget);
556 attributes.colormap = gtk_widget_get_colormap (widget);
557 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
558 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
559
560 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget),
561 &attributes, attributes_mask);
562 gdk_window_set_user_data (widget->window, widget);
563
564 attributes.x = 0;
565 attributes.y = 0;
566
567 attributes.event_mask = gtk_widget_get_events (widget);
568 attributes.event_mask |= GDK_EXPOSURE_MASK |
569 #ifdef __WXGTK20__
570 GDK_SCROLL_MASK |
571 #endif
572 GDK_POINTER_MOTION_MASK |
573 GDK_POINTER_MOTION_HINT_MASK |
574 GDK_BUTTON_MOTION_MASK |
575 GDK_BUTTON1_MOTION_MASK |
576 GDK_BUTTON2_MOTION_MASK |
577 GDK_BUTTON3_MOTION_MASK |
578 GDK_BUTTON_PRESS_MASK |
579 GDK_BUTTON_RELEASE_MASK |
580 GDK_KEY_PRESS_MASK |
581 GDK_KEY_RELEASE_MASK |
582 GDK_ENTER_NOTIFY_MASK |
583 GDK_LEAVE_NOTIFY_MASK |
584 GDK_FOCUS_CHANGE_MASK;
585
586 pizza->bin_window = gdk_window_new(widget->window,
587 &attributes, attributes_mask);
588 gdk_window_set_user_data (pizza->bin_window, widget);
589
590 widget->style = gtk_style_attach (widget->style, widget->window);
591 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
592 gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL );
593
594 /*
595 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
596 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
597 */
598
599 #ifndef __WXGTK20__
600 /* add filters for intercepting visibility and expose events */
601 gdk_window_add_filter (widget->window, gtk_pizza_main_filter, pizza);
602 gdk_window_add_filter (pizza->bin_window, gtk_pizza_filter, pizza);
603 #endif
604
605 /* we NEED gravity or we'll give up */
606 gravity_works = gdk_window_set_static_gravities (pizza->bin_window, TRUE);
607
608 /* cannot be done before realisation */
609 children = pizza->children;
610 while (children)
611 {
612 child = children->data;
613 children = children->next;
614
615 gtk_widget_set_parent_window (child->widget, pizza->bin_window);
616 }
617 }
618
619 static void
620 gtk_pizza_unrealize (GtkWidget *widget)
621 {
622 GtkPizza *pizza;
623
624 g_return_if_fail (widget != NULL);
625 g_return_if_fail (GTK_IS_PIZZA (widget));
626
627 pizza = GTK_PIZZA (widget);
628
629 gdk_window_set_user_data (pizza->bin_window, NULL);
630 gdk_window_destroy (pizza->bin_window);
631 pizza->bin_window = NULL;
632
633 if (GTK_WIDGET_CLASS (pizza_parent_class)->unrealize)
634 (* GTK_WIDGET_CLASS (pizza_parent_class)->unrealize) (widget);
635 }
636
637 static void
638 gtk_pizza_size_request (GtkWidget *widget,
639 GtkRequisition *requisition)
640 {
641 GtkPizza *pizza;
642 GtkPizzaChild *child;
643 GList *children;
644 GtkRequisition child_requisition;
645
646 g_return_if_fail (widget != NULL);
647 g_return_if_fail (GTK_IS_PIZZA (widget));
648 g_return_if_fail (requisition != NULL);
649
650 pizza = GTK_PIZZA (widget);
651
652 children = pizza->children;
653 while (children)
654 {
655 child = children->data;
656 children = children->next;
657
658 if (GTK_WIDGET_VISIBLE (child->widget))
659 {
660 gtk_widget_size_request (child->widget, &child_requisition);
661 }
662 }
663
664 /* request very little, I'm not sure if requesting nothing
665 will always have positive effects on stability... */
666 requisition->width = 2;
667 requisition->height = 2;
668 }
669
670 static void
671 gtk_pizza_size_allocate (GtkWidget *widget,
672 GtkAllocation *allocation)
673 {
674 GtkPizza *pizza;
675 gint border;
676 gint x,y,w,h;
677 GtkPizzaChild *child;
678 GList *children;
679
680 g_return_if_fail (widget != NULL);
681 g_return_if_fail (GTK_IS_PIZZA(widget));
682 g_return_if_fail (allocation != NULL);
683
684 pizza = GTK_PIZZA (widget);
685
686 widget->allocation = *allocation;
687
688 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
689 border = 0;
690 else
691 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
692 border = 1;
693 else
694 border = 2;
695
696 x = allocation->x + border;
697 y = allocation->y + border;
698 w = allocation->width - border*2;
699 h = allocation->height - border*2;
700
701 if (GTK_WIDGET_REALIZED (widget))
702 {
703 gdk_window_move_resize( widget->window, x, y, w, h );
704 gdk_window_move_resize( pizza->bin_window, 0, 0, w, h );
705 }
706
707 children = pizza->children;
708 while (children)
709 {
710 child = children->data;
711 children = children->next;
712
713 #ifndef __WXGTK20__
714 gtk_pizza_position_child (pizza, child);
715 #endif
716 gtk_pizza_allocate_child (pizza, child);
717 }
718 }
719
720 #ifndef __WXGTK20__
721
722 static void
723 gtk_pizza_draw (GtkWidget *widget,
724 GdkRectangle *area)
725 {
726 GtkPizza *pizza;
727 GtkPizzaChild *child;
728 GdkRectangle child_area;
729 GList *children;
730
731 g_return_if_fail (widget != NULL);
732 g_return_if_fail (GTK_IS_PIZZA (widget));
733
734 pizza = GTK_PIZZA (widget);
735
736 /* Sometimes, We handle all expose events in window.cpp now. */
737 if (pizza->external_expose)
738 return;
739
740 children = pizza->children;
741 if ( !(GTK_WIDGET_APP_PAINTABLE (widget)) &&
742 (pizza->clear_on_draw))
743 {
744 gdk_window_clear_area( pizza->bin_window,
745 area->x, area->y, area->width, area->height);
746 }
747
748 while (children)
749 {
750 child = children->data;
751 children = children->next;
752
753 if (gtk_widget_intersect (child->widget, area, &child_area))
754 gtk_widget_draw (child->widget, &child_area);
755 }
756 }
757
758 #endif /* __WXGTK20__ */
759
760 static gint
761 gtk_pizza_expose (GtkWidget *widget,
762 GdkEventExpose *event)
763 {
764 GtkPizza *pizza;
765 #ifndef __WXGTK20__
766 GtkPizzaChild *child;
767 GdkEventExpose child_event;
768 GList *children;
769 #endif
770
771 g_return_val_if_fail (widget != NULL, FALSE);
772 g_return_val_if_fail (GTK_IS_PIZZA (widget), FALSE);
773 g_return_val_if_fail (event != NULL, FALSE);
774
775 pizza = GTK_PIZZA (widget);
776
777 if (event->window != pizza->bin_window)
778 return FALSE;
779
780 /* We handle all expose events in window.cpp now. */
781 if (pizza->external_expose)
782 return FALSE;
783
784 #ifdef __WXGTK20__
785
786 (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, event);
787
788 return FALSE;
789
790 #else
791
792 children = pizza->children;
793 while (children)
794 {
795 child = children->data;
796 children = children->next;
797
798 child_event = *event;
799
800 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
801 GTK_WIDGET_DRAWABLE (child->widget) &&
802 gtk_widget_intersect (child->widget, &event->area, &child_event.area))
803 {
804 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
805 }
806 }
807
808 return TRUE;
809
810 #endif
811 }
812
813 static void
814 gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style)
815 {
816 if (GTK_WIDGET_REALIZED(widget))
817 {
818 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
819 gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL );
820 }
821
822 (* GTK_WIDGET_CLASS (pizza_parent_class)->style_set) (widget, previous_style);
823 }
824
825 static void
826 gtk_pizza_add (GtkContainer *container,
827 GtkWidget *widget)
828 {
829 g_return_if_fail (container != NULL);
830 g_return_if_fail (GTK_IS_PIZZA (container));
831 g_return_if_fail (widget != NULL);
832
833 gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 );
834 }
835
836 static void
837 gtk_pizza_remove (GtkContainer *container,
838 GtkWidget *widget)
839 {
840 GtkPizza *pizza;
841 GtkPizzaChild *child;
842 GList *children;
843
844 g_return_if_fail (container != NULL);
845 g_return_if_fail (GTK_IS_PIZZA (container));
846 g_return_if_fail (widget != NULL);
847
848 pizza = GTK_PIZZA (container);
849
850 children = pizza->children;
851 while (children)
852 {
853 child = children->data;
854
855 if (child->widget == widget)
856 {
857 gtk_widget_unparent (widget);
858
859 /* security checks */
860 g_return_if_fail (GTK_IS_WIDGET (widget));
861
862 pizza->children = g_list_remove_link (pizza->children, children);
863 g_list_free (children);
864 g_free (child);
865
866 /* security checks */
867 g_return_if_fail (GTK_IS_WIDGET (widget));
868
869 #ifndef __WXGTK20__
870 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IS_OFFSCREEN);
871 #endif
872
873 break;
874 }
875
876 children = children->next;
877 }
878 }
879
880 static void
881 gtk_pizza_forall (GtkContainer *container,
882 gboolean include_internals,
883 GtkCallback callback,
884 gpointer callback_data)
885 {
886 GtkPizza *pizza;
887 GtkPizzaChild *child;
888 GList *children;
889
890 g_return_if_fail (container != NULL);
891 g_return_if_fail (GTK_IS_PIZZA (container));
892 g_return_if_fail (callback != (GtkCallback)NULL);
893
894 pizza = GTK_PIZZA (container);
895
896 children = pizza->children;
897 while (children)
898 {
899 child = children->data;
900 children = children->next;
901
902 (* callback) (child->widget, callback_data);
903 }
904 }
905
906 static void
907 gtk_pizza_allocate_child (GtkPizza *pizza,
908 GtkPizzaChild *child)
909 {
910 GtkAllocation allocation;
911 GtkRequisition requisition;
912
913 allocation.x = child->x - pizza->xoffset;
914 allocation.y = child->y - pizza->yoffset;
915 gtk_widget_get_child_requisition (child->widget, &requisition);
916 allocation.width = requisition.width;
917 allocation.height = requisition.height;
918
919 gtk_widget_size_allocate (child->widget, &allocation);
920 }
921
922 static void
923 gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
924 gpointer cb_data)
925 {
926 GtkPizzaAdjData *data = cb_data;
927
928 widget->allocation.x += data->dx;
929 widget->allocation.y += data->dy;
930
931 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
932 {
933 gtk_container_forall (GTK_CONTAINER (widget),
934 gtk_pizza_adjust_allocations_recurse,
935 cb_data);
936 }
937 }
938
939 static void
940 gtk_pizza_adjust_allocations (GtkPizza *pizza,
941 gint dx,
942 gint dy)
943 {
944 GList *tmp_list;
945 GtkPizzaAdjData data;
946
947 data.dx = dx;
948 data.dy = dy;
949
950 tmp_list = pizza->children;
951 while (tmp_list)
952 {
953 GtkPizzaChild *child = tmp_list->data;
954 tmp_list = tmp_list->next;
955
956 child->widget->allocation.x += dx;
957 child->widget->allocation.y += dy;
958
959 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
960 GTK_IS_CONTAINER (child->widget))
961 {
962 gtk_container_forall (GTK_CONTAINER (child->widget),
963 gtk_pizza_adjust_allocations_recurse,
964 &data);
965 }
966 }
967 }
968
969 #ifndef __WXGTK20__
970 static void
971 gtk_pizza_position_child (GtkPizza *pizza,
972 GtkPizzaChild *child)
973 {
974 gint x;
975 gint y;
976
977 x = child->x - pizza->xoffset;
978 y = child->y - pizza->yoffset;
979
980 if (IS_ONSCREEN (x,y))
981 {
982 if (GTK_WIDGET_MAPPED (pizza) &&
983 GTK_WIDGET_VISIBLE (child->widget))
984 {
985 if (!GTK_WIDGET_MAPPED (child->widget))
986 gtk_widget_map (child->widget);
987 }
988
989 if (GTK_WIDGET_IS_OFFSCREEN (child->widget))
990 GTK_PRIVATE_UNSET_FLAG (child->widget, GTK_IS_OFFSCREEN);
991 }
992 else
993 {
994 if (!GTK_WIDGET_IS_OFFSCREEN (child->widget))
995 GTK_PRIVATE_SET_FLAG (child->widget, GTK_IS_OFFSCREEN);
996
997 if (GTK_WIDGET_MAPPED (child->widget))
998 gtk_widget_unmap (child->widget);
999 }
1000 }
1001
1002 static void
1003 gtk_pizza_position_children (GtkPizza *pizza)
1004 {
1005 GList *tmp_list;
1006
1007 tmp_list = pizza->children;
1008 while (tmp_list)
1009 {
1010 GtkPizzaChild *child = tmp_list->data;
1011 tmp_list = tmp_list->next;
1012
1013 gtk_pizza_position_child (pizza, child);
1014 }
1015 }
1016
1017 /* This function is used to find events to process while scrolling */
1018 static Bool
1019 gtk_pizza_expose_predicate (Display *display,
1020 XEvent *xevent,
1021 XPointer arg)
1022 {
1023 if ((xevent->type == Expose) ||
1024 ((xevent->xany.window == *(Window *)arg) &&
1025 (xevent->type == ConfigureNotify)))
1026 return True;
1027 else
1028 return False;
1029 }
1030 #endif /* __WXGTK20__ */
1031
1032 /* This is the main routine to do the scrolling. Scrolling is
1033 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1034 * a few modifications.
1035 *
1036 * The main improvement is that we keep track of whether we
1037 * are obscured or not. If not, we ignore the generated expose
1038 * events and instead do the exposes ourself, without having
1039 * to wait for a roundtrip to the server. This also provides
1040 * a limited form of expose-event compression, since we do
1041 * the affected area as one big chunk.
1042 */
1043
1044 void
1045 gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
1046 {
1047 #ifdef __WXGTK20__
1048 pizza->xoffset += dx;
1049 pizza->yoffset += dy;
1050
1051 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
1052
1053 if (pizza->bin_window)
1054 gdk_window_scroll( pizza->bin_window, -dx, -dy );
1055 #else
1056 GtkWidget *widget;
1057 XEvent xevent;
1058 XID win;
1059
1060 gint x,y,w,h,border;
1061
1062 widget = GTK_WIDGET (pizza);
1063
1064 pizza->xoffset += dx;
1065 pizza->yoffset += dy;
1066
1067 if (!GTK_WIDGET_MAPPED (pizza))
1068 {
1069 gtk_pizza_position_children (pizza);
1070 return;
1071 }
1072
1073 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
1074
1075 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
1076 border = 0;
1077 else
1078 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
1079 border = 1;
1080 else
1081 border = 2;
1082
1083 x = 0;
1084 y = 0;
1085 w = widget->allocation.width - 2*border;
1086 h = widget->allocation.height - 2*border;
1087
1088 if (dx > 0)
1089 {
1090 if (gravity_works)
1091 {
1092 gdk_window_resize (pizza->bin_window,
1093 w + dx,
1094 h);
1095 gdk_window_move (pizza->bin_window, x-dx, y);
1096 gdk_window_move_resize (pizza->bin_window, x, y, w, h );
1097 }
1098 else
1099 {
1100 /* FIXME */
1101 }
1102 }
1103 else if (dx < 0)
1104 {
1105 if (gravity_works)
1106 {
1107 gdk_window_move_resize (pizza->bin_window,
1108 x + dx,
1109 y,
1110 w - dx,
1111 h);
1112 gdk_window_move (pizza->bin_window, x, y);
1113 gdk_window_resize (pizza->bin_window, w, h );
1114 }
1115 else
1116 {
1117 /* FIXME */
1118 }
1119 }
1120
1121 if (dy > 0)
1122 {
1123 if (gravity_works)
1124 {
1125 gdk_window_resize (pizza->bin_window, w, h + dy);
1126 gdk_window_move (pizza->bin_window, x, y-dy);
1127 gdk_window_move_resize (pizza->bin_window,
1128 x, y, w, h );
1129 }
1130 else
1131 {
1132 /* FIXME */
1133 }
1134 }
1135 else if (dy < 0)
1136 {
1137 if (gravity_works)
1138 {
1139 gdk_window_move_resize (pizza->bin_window,
1140 x, y+dy, w, h - dy );
1141 gdk_window_move (pizza->bin_window, x, y);
1142 gdk_window_resize (pizza->bin_window, w, h );
1143 }
1144 else
1145 {
1146 /* FIXME */
1147 }
1148 }
1149
1150 gtk_pizza_position_children (pizza);
1151
1152 gdk_flush();
1153
1154 win = GDK_WINDOW_XWINDOW (pizza->bin_window);
1155 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza->bin_window),
1156 &xevent,
1157 gtk_pizza_expose_predicate,
1158 (XPointer)&win))
1159 {
1160 GdkEvent event;
1161 GtkWidget *event_widget;
1162
1163 if ((xevent.xany.window == GDK_WINDOW_XWINDOW (pizza->bin_window)) )
1164 gtk_pizza_filter (&xevent, &event, pizza);
1165
1166 if (xevent.type == Expose)
1167 {
1168 event.expose.window = gdk_window_lookup (xevent.xany.window);
1169 gdk_window_get_user_data (event.expose.window,
1170 (gpointer *)&event_widget);
1171
1172 if (event_widget)
1173 {
1174 event.expose.type = GDK_EXPOSE;
1175 event.expose.area.x = xevent.xexpose.x;
1176 event.expose.area.y = xevent.xexpose.y;
1177 event.expose.area.width = xevent.xexpose.width;
1178 event.expose.area.height = xevent.xexpose.height;
1179 event.expose.count = xevent.xexpose.count;
1180
1181 gdk_window_ref (event.expose.window);
1182 gtk_widget_event (event_widget, &event);
1183 gdk_window_unref (event.expose.window);
1184 }
1185 }
1186 }
1187 #endif /* __WXGTK20__ */
1188 }
1189
1190
1191 #ifndef __WXGTK20__
1192 /* The main event filter. Actually, we probably don't really need
1193 * to install this as a filter at all, since we are calling it
1194 * directly above in the expose-handling hack. But in case scrollbars
1195 * are fixed up in some manner...
1196 *
1197 * This routine identifies expose events that are generated when
1198 * we've temporarily moved the bin_window_origin, and translates
1199 * them or discards them, depending on whether we are obscured
1200 * or not.
1201 */
1202 static GdkFilterReturn
1203 gtk_pizza_filter (GdkXEvent *gdk_xevent,
1204 GdkEvent *event,
1205 gpointer data)
1206 {
1207 XEvent *xevent;
1208 GtkPizza *pizza;
1209
1210 xevent = (XEvent *)gdk_xevent;
1211
1212 pizza = GTK_PIZZA (data);
1213
1214 if (!pizza->use_filter)
1215 return GDK_FILTER_CONTINUE;
1216
1217 switch (xevent->type)
1218 {
1219 case Expose:
1220 if (xevent->xexpose.serial == pizza->configure_serial)
1221 {
1222 xevent->xexpose.x += pizza->scroll_x;
1223 xevent->xexpose.y += pizza->scroll_y;
1224 }
1225 break;
1226
1227 case ConfigureNotify:
1228 {
1229 pizza->configure_serial = xevent->xconfigure.serial;
1230 pizza->scroll_x = xevent->xconfigure.x;
1231 pizza->scroll_y = xevent->xconfigure.y;
1232 }
1233 break;
1234 }
1235
1236 return GDK_FILTER_CONTINUE;
1237 }
1238
1239 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1240 * there is no corresponding event in GTK, so we have
1241 * to get the events from a filter
1242 */
1243 static GdkFilterReturn
1244 gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
1245 GdkEvent *event,
1246 gpointer data)
1247 {
1248 XEvent *xevent;
1249 GtkPizza *pizza;
1250
1251 xevent = (XEvent *)gdk_xevent;
1252 pizza = GTK_PIZZA (data);
1253
1254 if (!pizza->use_filter)
1255 return GDK_FILTER_CONTINUE;
1256
1257 if (xevent->type == VisibilityNotify)
1258 {
1259 switch (xevent->xvisibility.state)
1260 {
1261 case VisibilityFullyObscured:
1262 pizza->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1263 break;
1264
1265 case VisibilityPartiallyObscured:
1266 pizza->visibility = GDK_VISIBILITY_PARTIAL;
1267 break;
1268
1269 case VisibilityUnobscured:
1270 pizza->visibility = GDK_VISIBILITY_UNOBSCURED;
1271 break;
1272 }
1273
1274 return GDK_FILTER_REMOVE;
1275 }
1276
1277 return GDK_FILTER_CONTINUE;
1278 }
1279 #endif /* __WXGTK20__ */
1280
1281
1282 #ifdef __cplusplus
1283 }
1284 #endif /* __cplusplus */
1285