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