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