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