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