]> Pileus Git - ~andy/gtk/blob - tests/gtkoffscreenbox.c
Forgotten files
[~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   gtk_widget_style_attach (widget);
349   context = gtk_widget_get_style_context (widget);
350   gtk_style_context_set_background (context, window);
351   gtk_style_context_set_background (context, offscreen_box->offscreen_window1);
352   gtk_style_context_set_background (context, offscreen_box->offscreen_window2);
353
354   gdk_window_show (offscreen_box->offscreen_window1);
355   gdk_window_show (offscreen_box->offscreen_window2);
356 }
357
358 static void
359 gtk_offscreen_box_unrealize (GtkWidget *widget)
360 {
361   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
362
363   gdk_window_set_user_data (offscreen_box->offscreen_window1, NULL);
364   gdk_window_destroy (offscreen_box->offscreen_window1);
365   offscreen_box->offscreen_window1 = NULL;
366
367   gdk_window_set_user_data (offscreen_box->offscreen_window2, NULL);
368   gdk_window_destroy (offscreen_box->offscreen_window2);
369   offscreen_box->offscreen_window2 = NULL;
370
371   GTK_WIDGET_CLASS (gtk_offscreen_box_parent_class)->unrealize (widget);
372 }
373
374 static GType
375 gtk_offscreen_box_child_type (GtkContainer *container)
376 {
377   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
378
379   if (offscreen_box->child1 && offscreen_box->child2)
380     return G_TYPE_NONE;
381
382   return GTK_TYPE_WIDGET;
383 }
384
385 static void
386 gtk_offscreen_box_add (GtkContainer *container,
387                        GtkWidget    *widget)
388 {
389   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
390
391   if (!offscreen_box->child1)
392     gtk_offscreen_box_add1 (offscreen_box, widget);
393   else if (!offscreen_box->child2)
394     gtk_offscreen_box_add2 (offscreen_box, widget);
395   else
396     g_warning ("GtkOffscreenBox cannot have more than 2 children\n");
397 }
398
399 void
400 gtk_offscreen_box_add1 (GtkOffscreenBox *offscreen_box,
401                         GtkWidget       *child)
402 {
403   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
404   g_return_if_fail (GTK_IS_WIDGET (child));
405
406   if (offscreen_box->child1 == NULL)
407     {
408       gtk_widget_set_parent_window (child, offscreen_box->offscreen_window1);
409       gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
410       offscreen_box->child1 = child;
411     }
412 }
413
414 void
415 gtk_offscreen_box_add2 (GtkOffscreenBox  *offscreen_box,
416                         GtkWidget    *child)
417 {
418   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
419   g_return_if_fail (GTK_IS_WIDGET (child));
420
421   if (offscreen_box->child2 == NULL)
422     {
423       gtk_widget_set_parent_window (child, offscreen_box->offscreen_window2);
424       gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
425       offscreen_box->child2 = child;
426     }
427 }
428
429 static void
430 gtk_offscreen_box_remove (GtkContainer *container,
431                           GtkWidget    *widget)
432 {
433   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
434   gboolean was_visible;
435
436   was_visible = gtk_widget_get_visible (widget);
437
438   if (offscreen_box->child1 == widget)
439     {
440       gtk_widget_unparent (widget);
441
442       offscreen_box->child1 = NULL;
443
444       if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
445         gtk_widget_queue_resize (GTK_WIDGET (container));
446     }
447   else if (offscreen_box->child2 == widget)
448     {
449       gtk_widget_unparent (widget);
450
451       offscreen_box->child2 = NULL;
452
453       if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
454         gtk_widget_queue_resize (GTK_WIDGET (container));
455     }
456 }
457
458 static void
459 gtk_offscreen_box_forall (GtkContainer *container,
460                           gboolean      include_internals,
461                           GtkCallback   callback,
462                           gpointer      callback_data)
463 {
464   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
465
466   g_return_if_fail (callback != NULL);
467
468   if (offscreen_box->child1)
469     (*callback) (offscreen_box->child1, callback_data);
470   if (offscreen_box->child2)
471     (*callback) (offscreen_box->child2, callback_data);
472 }
473
474 void
475 gtk_offscreen_box_set_angle (GtkOffscreenBox  *offscreen_box,
476                              gdouble           angle)
477 {
478   g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
479
480   offscreen_box->angle = angle;
481   gtk_widget_queue_draw (GTK_WIDGET (offscreen_box));
482
483   /* TODO: Really needs to resent pointer events if over the rotated window */
484 }
485
486
487 static void
488 gtk_offscreen_box_size_request (GtkWidget      *widget,
489                                 GtkRequisition *requisition)
490 {
491   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
492   int w, h;
493   guint border_width;
494
495   w = 0;
496   h = 0;
497
498   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
499     {
500       GtkRequisition child_requisition;
501
502       gtk_widget_get_preferred_size ( (offscreen_box->child1),
503                                  &child_requisition, NULL);
504
505       w = MAX (w, CHILD1_SIZE_SCALE * child_requisition.width);
506       h += CHILD1_SIZE_SCALE * child_requisition.height;
507     }
508
509   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
510     {
511       GtkRequisition child_requisition;
512
513       gtk_widget_get_preferred_size ( (offscreen_box->child2),
514                                  &child_requisition, NULL);
515
516       w = MAX (w, CHILD2_SIZE_SCALE * child_requisition.width);
517       h += CHILD2_SIZE_SCALE * child_requisition.height;
518     }
519
520   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
521   requisition->width = border_width * 2 + w;
522   requisition->height = border_width * 2 + h;
523 }
524
525 static void
526 gtk_offscreen_box_get_preferred_width (GtkWidget *widget,
527                                        gint      *minimum,
528                                        gint      *natural)
529 {
530   GtkRequisition requisition;
531
532   gtk_offscreen_box_size_request (widget, &requisition);
533
534   *minimum = *natural = requisition.width;
535 }
536
537 static void
538 gtk_offscreen_box_get_preferred_height (GtkWidget *widget,
539                                         gint      *minimum,
540                                         gint      *natural)
541 {
542   GtkRequisition requisition;
543
544   gtk_offscreen_box_size_request (widget, &requisition);
545
546   *minimum = *natural = requisition.height;
547 }
548
549 static void
550 gtk_offscreen_box_size_allocate (GtkWidget     *widget,
551                                  GtkAllocation *allocation)
552 {
553   GtkOffscreenBox *offscreen_box;
554   gint start_y;
555   guint border_width;
556
557   offscreen_box = GTK_OFFSCREEN_BOX (widget);
558
559   gtk_widget_set_allocation (widget, allocation);
560
561   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
562
563   if (gtk_widget_get_realized (widget))
564     gdk_window_move_resize (gtk_widget_get_window (widget),
565                             allocation->x + border_width,
566                             allocation->y + border_width,
567                             allocation->width - border_width * 2,
568                             allocation->height - border_width * 2);
569
570   start_y = 0;
571
572   if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
573     {
574       GtkRequisition child_requisition;
575       GtkAllocation child_allocation;
576
577       gtk_widget_get_preferred_size (offscreen_box->child1,
578                                      &child_requisition, NULL);
579       child_allocation.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
580       child_allocation.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
581       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
582       child_allocation.height = child_requisition.height;
583
584       start_y += CHILD1_SIZE_SCALE * child_requisition.height;
585
586       if (gtk_widget_get_realized (widget))
587         gdk_window_move_resize (offscreen_box->offscreen_window1,
588                                 child_allocation.x,
589                                 child_allocation.y,
590                                 child_allocation.width,
591                                 child_allocation.height);
592
593       child_allocation.x = child_allocation.y = 0;
594       gtk_widget_size_allocate (offscreen_box->child1, &child_allocation);
595     }
596
597   if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
598     {
599       GtkRequisition child_requisition;
600       GtkAllocation child_allocation;
601
602       gtk_widget_get_preferred_size (offscreen_box->child2,
603                                      &child_requisition, NULL);
604       child_allocation.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
605       child_allocation.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
606       child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
607       child_allocation.height = child_requisition.height;
608
609       start_y += CHILD2_SIZE_SCALE * child_requisition.height;
610
611       if (gtk_widget_get_realized (widget))
612         gdk_window_move_resize (offscreen_box->offscreen_window2,
613                                 child_allocation.x,
614                                 child_allocation.y,
615                                 child_allocation.width,
616                                 child_allocation.height);
617
618       child_allocation.x = child_allocation.y = 0;
619       gtk_widget_size_allocate (offscreen_box->child2, &child_allocation);
620     }
621 }
622
623 static gboolean
624 gtk_offscreen_box_damage (GtkWidget      *widget,
625                           GdkEventExpose *event)
626 {
627   gdk_window_invalidate_rect (gtk_widget_get_window (widget),
628                               NULL, FALSE);
629
630   return TRUE;
631 }
632
633 static gboolean
634 gtk_offscreen_box_draw (GtkWidget *widget,
635                         cairo_t   *cr)
636 {
637   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
638   GdkWindow *window;
639
640   window = gtk_widget_get_window (widget);
641   if (gtk_cairo_should_draw_window (cr, window))
642     {
643       cairo_surface_t *surface;
644       GtkAllocation child_area;
645
646       if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
647         {
648           surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1);
649
650           cairo_set_source_surface (cr, surface, 0, 0);
651           cairo_paint (cr);
652
653           gtk_widget_get_allocation (offscreen_box->child1, &child_area);
654           cairo_translate (cr, 0, child_area.height);
655         }
656
657       if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
658         {
659           surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
660
661           gtk_widget_get_allocation (offscreen_box->child2, &child_area);
662
663           /* transform */
664           cairo_translate (cr, child_area.width / 2, child_area.height / 2);
665           cairo_rotate (cr, offscreen_box->angle);
666           cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
667
668           /* paint */
669           cairo_set_source_surface (cr, surface, 0, 0);
670           cairo_paint (cr);
671         }
672     }
673   else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window1))
674     {
675       gtk_render_background (gtk_widget_get_style_context (widget), cr,
676                              0, 0,
677
678                              gdk_window_get_width (offscreen_box->offscreen_window1),
679                              gdk_window_get_height (offscreen_box->offscreen_window1));
680
681       if (offscreen_box->child1)
682         gtk_container_propagate_draw (GTK_CONTAINER (widget),
683                                       offscreen_box->child1,
684                                       cr);
685     }
686   else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window2))
687     {
688       gtk_render_background (gtk_widget_get_style_context (widget), cr,
689                              0, 0,
690                              gdk_window_get_width (offscreen_box->offscreen_window2),
691                              gdk_window_get_height (offscreen_box->offscreen_window2));
692
693       if (offscreen_box->child2)
694         gtk_container_propagate_draw (GTK_CONTAINER (widget),
695                                       offscreen_box->child2,
696                                       cr);
697     }
698
699   return FALSE;
700 }