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