]> Pileus Git - ~andy/gtk/blob - tests/gtkoffscreenbox.c
tests: Get rid of gdk_drawable_get_size() usage in offscreenbox
[~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_draw          (GtkWidget       *widget,
21                                                     cairo_t         *cr);
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->draw = gtk_offscreen_box_draw;
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.wclass = GDK_INPUT_OUTPUT;
268
269   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
270
271   window = gdk_window_new (gtk_widget_get_parent_window (widget),
272                            &attributes, attributes_mask);
273   gtk_widget_set_window (widget, window);
274   gdk_window_set_user_data (window, widget);
275
276   g_signal_connect (window, "pick-embedded-child",
277                     G_CALLBACK (pick_offscreen_child), offscreen_box);
278
279   attributes.window_type = GDK_WINDOW_OFFSCREEN;
280
281   /* Child 1 */
282   attributes.x = attributes.y = 0;
283   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
284     {
285       gtk_widget_get_allocation (offscreen_box->child1, &child_area);
286
287       attributes.width = child_area.width;
288       attributes.height = child_area.height;
289       start_y += child_area.height;
290     }
291   offscreen_box->offscreen_window1 = gdk_window_new (gtk_widget_get_root_window (widget),
292                                                      &attributes, attributes_mask);
293   gdk_window_set_user_data (offscreen_box->offscreen_window1, widget);
294   if (offscreen_box->child1)
295     gtk_widget_set_parent_window (offscreen_box->child1, offscreen_box->offscreen_window1);
296
297   gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window1,
298                                      window);
299
300   g_signal_connect (offscreen_box->offscreen_window1, "to-embedder",
301                     G_CALLBACK (offscreen_window_to_parent1), offscreen_box);
302   g_signal_connect (offscreen_box->offscreen_window1, "from-embedder",
303                     G_CALLBACK (offscreen_window_from_parent1), offscreen_box);
304
305   /* Child 2 */
306   attributes.y = start_y;
307   child_requisition.width = child_requisition.height = 0;
308   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
309     {
310       gtk_widget_get_allocation (offscreen_box->child2, &child_area);
311
312       attributes.width = child_area.width;
313       attributes.height = child_area.height;
314     }
315   offscreen_box->offscreen_window2 = gdk_window_new (gtk_widget_get_root_window (widget),
316                                                      &attributes, attributes_mask);
317   gdk_window_set_user_data (offscreen_box->offscreen_window2, widget);
318   if (offscreen_box->child2)
319     gtk_widget_set_parent_window (offscreen_box->child2, offscreen_box->offscreen_window2);
320   gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window2,
321                                      window);
322   g_signal_connect (offscreen_box->offscreen_window2, "to-embedder",
323                     G_CALLBACK (offscreen_window_to_parent2), offscreen_box);
324   g_signal_connect (offscreen_box->offscreen_window2, "from-embedder",
325                     G_CALLBACK (offscreen_window_from_parent2), offscreen_box);
326
327   gtk_widget_style_attach (widget);
328   style = gtk_widget_get_style (widget);
329   gtk_style_set_background (style, window, GTK_STATE_NORMAL);
330   gtk_style_set_background (style, offscreen_box->offscreen_window1, GTK_STATE_NORMAL);
331   gtk_style_set_background (style, offscreen_box->offscreen_window2, GTK_STATE_NORMAL);
332
333   gdk_window_show (offscreen_box->offscreen_window1);
334   gdk_window_show (offscreen_box->offscreen_window2);
335 }
336
337 static void
338 gtk_offscreen_box_unrealize (GtkWidget *widget)
339 {
340   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
341
342   gdk_window_set_user_data (offscreen_box->offscreen_window1, NULL);
343   gdk_window_destroy (offscreen_box->offscreen_window1);
344   offscreen_box->offscreen_window1 = NULL;
345
346   gdk_window_set_user_data (offscreen_box->offscreen_window2, NULL);
347   gdk_window_destroy (offscreen_box->offscreen_window2);
348   offscreen_box->offscreen_window2 = NULL;
349
350   GTK_WIDGET_CLASS (gtk_offscreen_box_parent_class)->unrealize (widget);
351 }
352
353 static GType
354 gtk_offscreen_box_child_type (GtkContainer *container)
355 {
356   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
357
358   if (offscreen_box->child1 && offscreen_box->child2)
359     return G_TYPE_NONE;
360
361   return GTK_TYPE_WIDGET;
362 }
363
364 static void
365 gtk_offscreen_box_add (GtkContainer *container,
366                        GtkWidget    *widget)
367 {
368   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
369
370   if (!offscreen_box->child1)
371     gtk_offscreen_box_add1 (offscreen_box, widget);
372   else if (!offscreen_box->child2)
373     gtk_offscreen_box_add2 (offscreen_box, widget);
374   else
375     g_warning ("GtkOffscreenBox cannot have more than 2 children\n");
376 }
377
378 void
379 gtk_offscreen_box_add1 (GtkOffscreenBox *offscreen_box,
380                         GtkWidget       *child)
381 {
382   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
383   g_return_if_fail (GTK_IS_WIDGET (child));
384
385   if (offscreen_box->child1 == NULL)
386     {
387       gtk_widget_set_parent_window (child, offscreen_box->offscreen_window1);
388       gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
389       offscreen_box->child1 = child;
390     }
391 }
392
393 void
394 gtk_offscreen_box_add2 (GtkOffscreenBox  *offscreen_box,
395                         GtkWidget    *child)
396 {
397   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
398   g_return_if_fail (GTK_IS_WIDGET (child));
399
400   if (offscreen_box->child2 == NULL)
401     {
402       gtk_widget_set_parent_window (child, offscreen_box->offscreen_window2);
403       gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
404       offscreen_box->child2 = child;
405     }
406 }
407
408 static void
409 gtk_offscreen_box_remove (GtkContainer *container,
410                           GtkWidget    *widget)
411 {
412   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
413   gboolean was_visible;
414
415   was_visible = gtk_widget_get_visible (widget);
416
417   if (offscreen_box->child1 == widget)
418     {
419       gtk_widget_unparent (widget);
420
421       offscreen_box->child1 = NULL;
422
423       if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
424         gtk_widget_queue_resize (GTK_WIDGET (container));
425     }
426   else if (offscreen_box->child2 == widget)
427     {
428       gtk_widget_unparent (widget);
429
430       offscreen_box->child2 = NULL;
431
432       if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
433         gtk_widget_queue_resize (GTK_WIDGET (container));
434     }
435 }
436
437 static void
438 gtk_offscreen_box_forall (GtkContainer *container,
439                           gboolean      include_internals,
440                           GtkCallback   callback,
441                           gpointer      callback_data)
442 {
443   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
444
445   g_return_if_fail (callback != NULL);
446
447   if (offscreen_box->child1)
448     (*callback) (offscreen_box->child1, callback_data);
449   if (offscreen_box->child2)
450     (*callback) (offscreen_box->child2, callback_data);
451 }
452
453 void
454 gtk_offscreen_box_set_angle (GtkOffscreenBox  *offscreen_box,
455                              gdouble           angle)
456 {
457   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
458
459   offscreen_box->angle = angle;
460   gtk_widget_queue_draw (GTK_WIDGET (offscreen_box));
461
462   /* TODO: Really needs to resent pointer events if over the rotated window */
463 }
464
465
466 static void
467 gtk_offscreen_box_size_request (GtkWidget      *widget,
468                                 GtkRequisition *requisition)
469 {
470   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
471   int w, h;
472   guint border_width;
473
474   w = 0;
475   h = 0;
476
477   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
478     {
479       GtkRequisition child_requisition;
480
481       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
482                                  &child_requisition, NULL);
483
484       w = MAX (w, CHILD1_SIZE_SCALE * child_requisition.width);
485       h += CHILD1_SIZE_SCALE * child_requisition.height;
486     }
487
488   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
489     {
490       GtkRequisition child_requisition;
491
492       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
493                                  &child_requisition, NULL);
494
495       w = MAX (w, CHILD2_SIZE_SCALE * child_requisition.width);
496       h += CHILD2_SIZE_SCALE * child_requisition.height;
497     }
498
499   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
500   requisition->width = border_width * 2 + w;
501   requisition->height = border_width * 2 + h;
502 }
503
504 static void
505 gtk_offscreen_box_size_allocate (GtkWidget     *widget,
506                                  GtkAllocation *allocation)
507 {
508   GtkOffscreenBox *offscreen_box;
509   gint start_y;
510   guint border_width;
511
512   offscreen_box = GTK_OFFSCREEN_BOX (widget);
513
514   gtk_widget_set_allocation (widget, allocation);
515
516   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
517
518   if (gtk_widget_get_realized (widget))
519     gdk_window_move_resize (gtk_widget_get_window (widget),
520                             allocation->x + border_width,
521                             allocation->y + border_width,
522                             allocation->width - border_width * 2,
523                             allocation->height - border_width * 2);
524
525   start_y = 0;
526
527   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
528     {
529       GtkRequisition child_requisition;
530       GtkAllocation child_allocation;
531
532       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
533                                  &child_requisition, NULL);
534       child_allocation.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
535       child_allocation.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
536       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
537       child_allocation.height = child_requisition.height;
538
539       start_y += CHILD1_SIZE_SCALE * child_requisition.height;
540
541       if (gtk_widget_get_realized (widget))
542         gdk_window_move_resize (offscreen_box->offscreen_window1,
543                                 child_allocation.x,
544                                 child_allocation.y,
545                                 child_allocation.width,
546                                 child_allocation.height);
547
548       child_allocation.x = child_allocation.y = 0;
549       gtk_widget_size_allocate (offscreen_box->child1, &child_allocation);
550     }
551
552   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
553     {
554       GtkRequisition child_requisition;
555       GtkAllocation child_allocation;
556
557       gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
558                                  &child_requisition, NULL);
559       child_allocation.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
560       child_allocation.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
561       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
562       child_allocation.height = child_requisition.height;
563
564       start_y += CHILD2_SIZE_SCALE * child_requisition.height;
565
566       if (gtk_widget_get_realized (widget))
567         gdk_window_move_resize (offscreen_box->offscreen_window2,
568                                 child_allocation.x,
569                                 child_allocation.y,
570                                 child_allocation.width,
571                                 child_allocation.height);
572
573       child_allocation.x = child_allocation.y = 0;
574       gtk_widget_size_allocate (offscreen_box->child2, &child_allocation);
575     }
576 }
577
578 static gboolean
579 gtk_offscreen_box_damage (GtkWidget      *widget,
580                           GdkEventExpose *event)
581 {
582   gdk_window_invalidate_rect (gtk_widget_get_window (widget),
583                               NULL, FALSE);
584
585   return TRUE;
586 }
587
588 static gboolean
589 gtk_offscreen_box_draw (GtkWidget *widget,
590                         cairo_t   *cr)
591 {
592   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
593   GdkWindow *window;
594
595   window = gtk_widget_get_window (widget);
596   if (gtk_cairo_should_draw_window (cr, window))
597     {
598       cairo_surface_t *surface;
599       GtkAllocation child_area;
600
601       if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
602         {
603           surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1);
604
605           cairo_set_source_surface (cr, surface, 0, 0);
606           cairo_paint (cr);
607
608           gtk_widget_get_allocation (offscreen_box->child1, &child_area);
609           cairo_translate (cr, 0, child_area.height);
610         }
611
612       if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
613         {
614           surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
615           gtk_widget_get_allocation (offscreen_box->child2, &child_area);
616
617           /* transform */
618           cairo_translate (cr, child_area.width / 2, child_area.height / 2);
619           cairo_rotate (cr, offscreen_box->angle);
620           cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
621
622           /* paint */
623           cairo_set_source_surface (cr, surface, 0, 0);
624           cairo_paint (cr);
625         }
626     }
627   else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window1))
628     {
629       gtk_paint_flat_box (gtk_widget_get_style (widget), cr,
630                           GTK_STATE_NORMAL, GTK_SHADOW_NONE,
631                           widget, "blah",
632                           0, 0,
633                           gdk_window_get_width (offscreen_box->offscreen_window1),
634                           gdk_window_get_height (offscreen_box->offscreen_window1));
635
636       if (offscreen_box->child1)
637         gtk_container_propagate_draw (GTK_CONTAINER (widget),
638                                       offscreen_box->child1,
639                                       cr);
640     }
641   else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window2))
642     {
643       gtk_paint_flat_box (gtk_widget_get_style (widget), cr,
644                           GTK_STATE_NORMAL, GTK_SHADOW_NONE,
645                           widget, "blah",
646                           0, 0,
647                           gdk_window_get_width (offscreen_box->offscreen_window2),
648                           gdk_window_get_height (offscreen_box->offscreen_window2));
649
650       if (offscreen_box->child2)
651         gtk_container_propagate_draw (GTK_CONTAINER (widget),
652                                       offscreen_box->child2,
653                                       cr);
654     }
655
656   return FALSE;
657 }