]> Pileus Git - ~andy/gtk/blob - tests/gtkoffscreenbox.c
API: Change offscreen windows to use a cairo_surface_t
[~andy/gtk] / tests / gtkoffscreenbox.c
1 /*
2  * gtkoffscreenbox.c
3  */
4
5 #include "config.h"
6
7 #include <math.h>
8 #include <gtk/gtk.h>
9
10 #include "gtkoffscreenbox.h"
11
12 static void        gtk_offscreen_box_realize       (GtkWidget       *widget);
13 static void        gtk_offscreen_box_unrealize     (GtkWidget       *widget);
14 static void        gtk_offscreen_box_size_request  (GtkWidget       *widget,
15                                                     GtkRequisition  *requisition);
16 static void        gtk_offscreen_box_size_allocate (GtkWidget       *widget,
17                                                     GtkAllocation   *allocation);
18 static gboolean    gtk_offscreen_box_damage        (GtkWidget       *widget,
19                                                     GdkEventExpose  *event);
20 static gboolean    gtk_offscreen_box_expose        (GtkWidget       *widget,
21                                                     GdkEventExpose  *offscreen);
22
23 static void        gtk_offscreen_box_add           (GtkContainer    *container,
24                                                     GtkWidget       *child);
25 static void        gtk_offscreen_box_remove        (GtkContainer    *container,
26                                                     GtkWidget       *widget);
27 static void        gtk_offscreen_box_forall        (GtkContainer    *container,
28                                                     gboolean         include_internals,
29                                                     GtkCallback      callback,
30                                                     gpointer         callback_data);
31 static GType       gtk_offscreen_box_child_type    (GtkContainer    *container);
32
33 #define CHILD1_SIZE_SCALE 1.0
34 #define CHILD2_SIZE_SCALE 1.0
35
36 G_DEFINE_TYPE (GtkOffscreenBox, gtk_offscreen_box, GTK_TYPE_CONTAINER);
37
38 static void
39 to_child_2 (GtkOffscreenBox *offscreen_box,
40             double widget_x, double widget_y,
41             double *x_out, double *y_out)
42 {
43   GtkAllocation child_area;
44   double x, y, xr, yr;
45   double cos_angle, sin_angle;
46
47   x = widget_x;
48   y = widget_y;
49
50   gtk_widget_get_allocation (offscreen_box->child1, &child_area);
51   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
52     y -= child_area.height;
53
54   gtk_widget_get_allocation (offscreen_box->child2, &child_area);
55
56   x -= child_area.width / 2;
57   y -= child_area.height / 2;
58
59   cos_angle = cos (-offscreen_box->angle);
60   sin_angle = sin (-offscreen_box->angle);
61
62   xr = x * cos_angle - y * sin_angle;
63   yr = x * sin_angle + y * cos_angle;
64   x = xr;
65   y = yr;
66
67   x += child_area.width / 2;
68   y += child_area.height / 2;
69
70   *x_out = x;
71   *y_out = y;
72 }
73
74 static void
75 to_parent_2 (GtkOffscreenBox *offscreen_box,
76              double offscreen_x, double offscreen_y,
77              double *x_out, double *y_out)
78 {
79   GtkAllocation child_area;
80   double x, y, xr, yr;
81   double cos_angle, sin_angle;
82
83   gtk_widget_get_allocation (offscreen_box->child2, &child_area);
84
85   x = offscreen_x;
86   y = offscreen_y;
87
88   x -= child_area.width / 2;
89   y -= child_area.height / 2;
90
91   cos_angle = cos (offscreen_box->angle);
92   sin_angle = sin (offscreen_box->angle);
93
94   xr = x * cos_angle - y * sin_angle;
95   yr = x * sin_angle + y * cos_angle;
96   x = xr;
97   y = yr;
98
99   x += child_area.width / 2;
100   y += child_area.height / 2;
101
102   gtk_widget_get_allocation (offscreen_box->child1, &child_area);
103   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
104     y += child_area.height;
105
106   *x_out = x;
107   *y_out = y;
108 }
109
110 static void
111 gtk_offscreen_box_class_init (GtkOffscreenBoxClass *klass)
112 {
113   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
114   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
115
116   widget_class->realize = gtk_offscreen_box_realize;
117   widget_class->unrealize = gtk_offscreen_box_unrealize;
118   widget_class->size_request = gtk_offscreen_box_size_request;
119   widget_class->size_allocate = gtk_offscreen_box_size_allocate;
120   widget_class->expose_event = gtk_offscreen_box_expose;
121
122   g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
123                                    GTK_TYPE_OFFSCREEN_BOX,
124                                    g_cclosure_new (G_CALLBACK (gtk_offscreen_box_damage),
125                                                    NULL, NULL));
126
127   container_class->add = gtk_offscreen_box_add;
128   container_class->remove = gtk_offscreen_box_remove;
129   container_class->forall = gtk_offscreen_box_forall;
130   container_class->child_type = gtk_offscreen_box_child_type;
131 }
132
133 static void
134 gtk_offscreen_box_init (GtkOffscreenBox *offscreen_box)
135 {
136   gtk_widget_set_has_window (GTK_WIDGET (offscreen_box), TRUE);
137 }
138
139 GtkWidget *
140 gtk_offscreen_box_new (void)
141 {
142   return g_object_new (GTK_TYPE_OFFSCREEN_BOX, NULL);
143 }
144
145 static GdkWindow *
146 pick_offscreen_child (GdkWindow *offscreen_window,
147                       double widget_x, double widget_y,
148                       GtkOffscreenBox *offscreen_box)
149 {
150  GtkAllocation child_area;
151  double x, y;
152
153  /* First check for child 2 */
154  if (offscreen_box->child2 &&
155      gtk_widget_get_visible (offscreen_box->child2))
156     {
157       to_child_2 (offscreen_box,
158                   widget_x, widget_y,
159                   &x, &y);
160
161       gtk_widget_get_allocation (offscreen_box->child2, &child_area);
162
163       if (x >= 0 && x < child_area.width &&
164           y >= 0 && y < child_area.height)
165         return offscreen_box->offscreen_window2;
166     }
167
168  if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
169    {
170      x = widget_x;
171      y = widget_y;
172
173      gtk_widget_get_allocation (offscreen_box->child1, &child_area);
174
175      if (x >= 0 && x < child_area.width &&
176          y >= 0 && y < child_area.height)
177        return offscreen_box->offscreen_window1;
178    }
179
180   return NULL;
181 }
182
183 static void
184 offscreen_window_to_parent1 (GdkWindow       *offscreen_window,
185                              double           offscreen_x,
186                              double           offscreen_y,
187                              double          *parent_x,
188                              double          *parent_y,
189                              GtkOffscreenBox *offscreen_box)
190 {
191   *parent_x = offscreen_x;
192   *parent_y = offscreen_y;
193 }
194
195 static void
196 offscreen_window_from_parent1 (GdkWindow       *window,
197                                double           parent_x,
198                                double           parent_y,
199                                double          *offscreen_x,
200                                double          *offscreen_y,
201                                GtkOffscreenBox *offscreen_box)
202 {
203   *offscreen_x = parent_x;
204   *offscreen_y = parent_y;
205 }
206
207 static void
208 offscreen_window_to_parent2 (GdkWindow       *offscreen_window,
209                              double           offscreen_x,
210                              double           offscreen_y,
211                              double          *parent_x,
212                              double          *parent_y,
213                              GtkOffscreenBox *offscreen_box)
214 {
215   to_parent_2 (offscreen_box,
216               offscreen_x, offscreen_y,
217               parent_x, parent_y);
218 }
219
220 static void
221 offscreen_window_from_parent2 (GdkWindow       *window,
222                                double           parent_x,
223                                double           parent_y,
224                                double          *offscreen_x,
225                                double          *offscreen_y,
226                                GtkOffscreenBox *offscreen_box)
227 {
228   to_child_2 (offscreen_box,
229               parent_x, parent_y,
230               offscreen_x, offscreen_y);
231 }
232
233 static void
234 gtk_offscreen_box_realize (GtkWidget *widget)
235 {
236   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
237   GtkAllocation allocation, child_area;
238   GtkStyle *style;
239   GdkWindow *window;
240   GdkWindowAttr attributes;
241   gint attributes_mask;
242   guint border_width;
243   GtkRequisition child_requisition;
244   int start_y = 0;
245
246   gtk_widget_set_realized (widget, TRUE);
247
248   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
249
250   gtk_widget_get_allocation (widget, &allocation);
251
252   attributes.x = allocation.x + border_width;
253   attributes.y = allocation.y + border_width;
254   attributes.width = allocation.width - 2 * border_width;
255   attributes.height = allocation.height - 2 * border_width;
256   attributes.window_type = GDK_WINDOW_CHILD;
257   attributes.event_mask = gtk_widget_get_events (widget)
258                         | GDK_EXPOSURE_MASK
259                         | GDK_POINTER_MOTION_MASK
260                         | GDK_BUTTON_PRESS_MASK
261                         | GDK_BUTTON_RELEASE_MASK
262                         | GDK_SCROLL_MASK
263                         | GDK_ENTER_NOTIFY_MASK
264                         | GDK_LEAVE_NOTIFY_MASK;
265
266   attributes.visual = gtk_widget_get_visual (widget);
267   attributes.colormap = gtk_widget_get_colormap (widget);
268   attributes.wclass = GDK_INPUT_OUTPUT;
269
270   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
271
272   window = gdk_window_new (gtk_widget_get_parent_window (widget),
273                            &attributes, attributes_mask);
274   gtk_widget_set_window (widget, window);
275   gdk_window_set_user_data (window, widget);
276
277   g_signal_connect (window, "pick-embedded-child",
278                     G_CALLBACK (pick_offscreen_child), offscreen_box);
279
280   attributes.window_type = GDK_WINDOW_OFFSCREEN;
281
282   /* Child 1 */
283   attributes.x = attributes.y = 0;
284   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
285     {
286       gtk_widget_get_allocation (offscreen_box->child1, &child_area);
287
288       attributes.width = child_area.width;
289       attributes.height = child_area.height;
290       start_y += child_area.height;
291     }
292   offscreen_box->offscreen_window1 = gdk_window_new (gtk_widget_get_root_window (widget),
293                                                      &attributes, attributes_mask);
294   gdk_window_set_user_data (offscreen_box->offscreen_window1, widget);
295   if (offscreen_box->child1)
296     gtk_widget_set_parent_window (offscreen_box->child1, offscreen_box->offscreen_window1);
297
298   gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window1,
299                                      window);
300
301   g_signal_connect (offscreen_box->offscreen_window1, "to-embedder",
302                     G_CALLBACK (offscreen_window_to_parent1), offscreen_box);
303   g_signal_connect (offscreen_box->offscreen_window1, "from-embedder",
304                     G_CALLBACK (offscreen_window_from_parent1), offscreen_box);
305
306   /* Child 2 */
307   attributes.y = start_y;
308   child_requisition.width = child_requisition.height = 0;
309   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
310     {
311       gtk_widget_get_allocation (offscreen_box->child2, &child_area);
312
313       attributes.width = child_area.width;
314       attributes.height = child_area.height;
315     }
316   offscreen_box->offscreen_window2 = gdk_window_new (gtk_widget_get_root_window (widget),
317                                                      &attributes, attributes_mask);
318   gdk_window_set_user_data (offscreen_box->offscreen_window2, widget);
319   if (offscreen_box->child2)
320     gtk_widget_set_parent_window (offscreen_box->child2, offscreen_box->offscreen_window2);
321   gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window2,
322                                      window);
323   g_signal_connect (offscreen_box->offscreen_window2, "to-embedder",
324                     G_CALLBACK (offscreen_window_to_parent2), offscreen_box);
325   g_signal_connect (offscreen_box->offscreen_window2, "from-embedder",
326                     G_CALLBACK (offscreen_window_from_parent2), offscreen_box);
327
328   gtk_widget_style_attach (widget);
329   style = gtk_widget_get_style (widget);
330   gtk_style_set_background (style, window, GTK_STATE_NORMAL);
331   gtk_style_set_background (style, offscreen_box->offscreen_window1, GTK_STATE_NORMAL);
332   gtk_style_set_background (style, offscreen_box->offscreen_window2, GTK_STATE_NORMAL);
333
334   gdk_window_show (offscreen_box->offscreen_window1);
335   gdk_window_show (offscreen_box->offscreen_window2);
336 }
337
338 static void
339 gtk_offscreen_box_unrealize (GtkWidget *widget)
340 {
341   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
342
343   gdk_window_set_user_data (offscreen_box->offscreen_window1, NULL);
344   gdk_window_destroy (offscreen_box->offscreen_window1);
345   offscreen_box->offscreen_window1 = NULL;
346
347   gdk_window_set_user_data (offscreen_box->offscreen_window2, NULL);
348   gdk_window_destroy (offscreen_box->offscreen_window2);
349   offscreen_box->offscreen_window2 = NULL;
350
351   GTK_WIDGET_CLASS (gtk_offscreen_box_parent_class)->unrealize (widget);
352 }
353
354 static GType
355 gtk_offscreen_box_child_type (GtkContainer *container)
356 {
357   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
358
359   if (offscreen_box->child1 && offscreen_box->child2)
360     return G_TYPE_NONE;
361
362   return GTK_TYPE_WIDGET;
363 }
364
365 static void
366 gtk_offscreen_box_add (GtkContainer *container,
367                        GtkWidget    *widget)
368 {
369   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
370
371   if (!offscreen_box->child1)
372     gtk_offscreen_box_add1 (offscreen_box, widget);
373   else if (!offscreen_box->child2)
374     gtk_offscreen_box_add2 (offscreen_box, widget);
375   else
376     g_warning ("GtkOffscreenBox cannot have more than 2 children\n");
377 }
378
379 void
380 gtk_offscreen_box_add1 (GtkOffscreenBox *offscreen_box,
381                         GtkWidget       *child)
382 {
383   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
384   g_return_if_fail (GTK_IS_WIDGET (child));
385
386   if (offscreen_box->child1 == NULL)
387     {
388       gtk_widget_set_parent_window (child, offscreen_box->offscreen_window1);
389       gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
390       offscreen_box->child1 = child;
391     }
392 }
393
394 void
395 gtk_offscreen_box_add2 (GtkOffscreenBox  *offscreen_box,
396                         GtkWidget    *child)
397 {
398   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
399   g_return_if_fail (GTK_IS_WIDGET (child));
400
401   if (offscreen_box->child2 == NULL)
402     {
403       gtk_widget_set_parent_window (child, offscreen_box->offscreen_window2);
404       gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
405       offscreen_box->child2 = child;
406     }
407 }
408
409 static void
410 gtk_offscreen_box_remove (GtkContainer *container,
411                           GtkWidget    *widget)
412 {
413   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
414   gboolean was_visible;
415
416   was_visible = gtk_widget_get_visible (widget);
417
418   if (offscreen_box->child1 == widget)
419     {
420       gtk_widget_unparent (widget);
421
422       offscreen_box->child1 = NULL;
423
424       if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
425         gtk_widget_queue_resize (GTK_WIDGET (container));
426     }
427   else if (offscreen_box->child2 == widget)
428     {
429       gtk_widget_unparent (widget);
430
431       offscreen_box->child2 = NULL;
432
433       if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
434         gtk_widget_queue_resize (GTK_WIDGET (container));
435     }
436 }
437
438 static void
439 gtk_offscreen_box_forall (GtkContainer *container,
440                           gboolean      include_internals,
441                           GtkCallback   callback,
442                           gpointer      callback_data)
443 {
444   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
445
446   g_return_if_fail (callback != NULL);
447
448   if (offscreen_box->child1)
449     (*callback) (offscreen_box->child1, callback_data);
450   if (offscreen_box->child2)
451     (*callback) (offscreen_box->child2, callback_data);
452 }
453
454 void
455 gtk_offscreen_box_set_angle (GtkOffscreenBox  *offscreen_box,
456                              gdouble           angle)
457 {
458   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
459
460   offscreen_box->angle = angle;
461   gtk_widget_queue_draw (GTK_WIDGET (offscreen_box));
462
463   /* TODO: Really needs to resent pointer events if over the rotated window */
464 }
465
466
467 static void
468 gtk_offscreen_box_size_request (GtkWidget      *widget,
469                                 GtkRequisition *requisition)
470 {
471   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
472   int w, h;
473   guint border_width;
474
475   w = 0;
476   h = 0;
477
478   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
479     {
480       GtkRequisition child_requisition;
481
482       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
483                                  &child_requisition, NULL);
484
485       w = MAX (w, CHILD1_SIZE_SCALE * child_requisition.width);
486       h += CHILD1_SIZE_SCALE * child_requisition.height;
487     }
488
489   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
490     {
491       GtkRequisition child_requisition;
492
493       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
494                                  &child_requisition, NULL);
495
496       w = MAX (w, CHILD2_SIZE_SCALE * child_requisition.width);
497       h += CHILD2_SIZE_SCALE * child_requisition.height;
498     }
499
500   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
501   requisition->width = border_width * 2 + w;
502   requisition->height = border_width * 2 + h;
503 }
504
505 static void
506 gtk_offscreen_box_size_allocate (GtkWidget     *widget,
507                                  GtkAllocation *allocation)
508 {
509   GtkOffscreenBox *offscreen_box;
510   gint start_y;
511   guint border_width;
512
513   offscreen_box = GTK_OFFSCREEN_BOX (widget);
514
515   gtk_widget_set_allocation (widget, allocation);
516
517   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
518
519   if (gtk_widget_get_realized (widget))
520     gdk_window_move_resize (gtk_widget_get_window (widget),
521                             allocation->x + border_width,
522                             allocation->y + border_width,
523                             allocation->width - border_width * 2,
524                             allocation->height - border_width * 2);
525
526   start_y = 0;
527
528   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
529     {
530       GtkRequisition child_requisition;
531       GtkAllocation child_allocation;
532
533       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
534                                  &child_requisition, NULL);
535       child_allocation.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
536       child_allocation.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
537       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
538       child_allocation.height = child_requisition.height;
539
540       start_y += CHILD1_SIZE_SCALE * child_requisition.height;
541
542       if (gtk_widget_get_realized (widget))
543         gdk_window_move_resize (offscreen_box->offscreen_window1,
544                                 child_allocation.x,
545                                 child_allocation.y,
546                                 child_allocation.width,
547                                 child_allocation.height);
548
549       child_allocation.x = child_allocation.y = 0;
550       gtk_widget_size_allocate (offscreen_box->child1, &child_allocation);
551     }
552
553   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
554     {
555       GtkRequisition child_requisition;
556       GtkAllocation child_allocation;
557
558       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
559                                  &child_requisition, NULL);
560       child_allocation.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
561       child_allocation.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
562       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
563       child_allocation.height = child_requisition.height;
564
565       start_y += CHILD2_SIZE_SCALE * child_requisition.height;
566
567       if (gtk_widget_get_realized (widget))
568         gdk_window_move_resize (offscreen_box->offscreen_window2,
569                                 child_allocation.x,
570                                 child_allocation.y,
571                                 child_allocation.width,
572                                 child_allocation.height);
573
574       child_allocation.x = child_allocation.y = 0;
575       gtk_widget_size_allocate (offscreen_box->child2, &child_allocation);
576     }
577 }
578
579 static gboolean
580 gtk_offscreen_box_damage (GtkWidget      *widget,
581                           GdkEventExpose *event)
582 {
583   gdk_window_invalidate_rect (gtk_widget_get_window (widget),
584                               NULL, FALSE);
585
586   return TRUE;
587 }
588
589 static gboolean
590 gtk_offscreen_box_expose (GtkWidget      *widget,
591                           GdkEventExpose *event)
592 {
593   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
594   GdkWindow *window;
595
596   if (gtk_widget_is_drawable (widget))
597     {
598       window = gtk_widget_get_window (widget);
599       if (event->window == window)
600         {
601           cairo_surface_t *surface;
602           GtkAllocation child_area;
603           cairo_t *cr;
604           int start_y = 0;
605
606           if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
607             {
608               surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1);
609               gtk_widget_get_allocation (offscreen_box->child1, &child_area);
610
611               cr = gdk_cairo_create (window);
612
613               cairo_set_source_surface (cr, surface, 0, 0);
614               cairo_paint (cr);
615
616               cairo_destroy (cr);
617
618               start_y += child_area.height;
619             }
620
621           if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
622             {
623               gint w, h;
624
625               surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
626               gtk_widget_get_allocation (offscreen_box->child2, &child_area);
627
628               cr = gdk_cairo_create (window);
629
630               /* transform */
631               cairo_translate (cr, 0, start_y);
632               cairo_translate (cr, child_area.width / 2, child_area.height / 2);
633               cairo_rotate (cr, offscreen_box->angle);
634               cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
635
636               /* clip */
637               gdk_drawable_get_size (offscreen_box->offscreen_window2, &w, &h);
638               cairo_rectangle (cr, 0, 0, w, h);
639               cairo_clip (cr);
640
641               /* paint */
642               cairo_set_source_surface (cr, surface, 0, 0);
643               cairo_paint (cr);
644
645               cairo_destroy (cr);
646             }
647         }
648       else if (event->window == offscreen_box->offscreen_window1)
649         {
650           gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
651                               GTK_STATE_NORMAL, GTK_SHADOW_NONE,
652                               &event->area, widget, "blah",
653                               0, 0, -1, -1);
654
655           if (offscreen_box->child1)
656             gtk_container_propagate_expose (GTK_CONTAINER (widget),
657                                             offscreen_box->child1,
658                                             event);
659         }
660       else if (event->window == offscreen_box->offscreen_window2)
661         {
662           gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
663                               GTK_STATE_NORMAL, GTK_SHADOW_NONE,
664                               &event->area, widget, "blah",
665                               0, 0, -1, -1);
666
667           if (offscreen_box->child2)
668             gtk_container_propagate_expose (GTK_CONTAINER (widget),
669                                             offscreen_box->child2,
670                                             event);
671         }
672     }
673
674   return FALSE;
675 }