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