gtkoffscreenbox.c 21.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*
 * gtkoffscreenbox.c
 */

#include "config.h"

#include <math.h>
#include <gtk/gtk.h>

#include "gtkoffscreenbox.h"

static void        gtk_offscreen_box_realize       (GtkWidget       *widget);
static void        gtk_offscreen_box_unrealize     (GtkWidget       *widget);
static void        gtk_offscreen_box_size_request  (GtkWidget       *widget,
                                                    GtkRequisition  *requisition);
static void        gtk_offscreen_box_size_allocate (GtkWidget       *widget,
                                                    GtkAllocation   *allocation);
static gboolean    gtk_offscreen_box_damage        (GtkWidget       *widget,
                                                    GdkEventExpose  *event);
static gboolean    gtk_offscreen_box_expose        (GtkWidget       *widget,
                                                    GdkEventExpose  *offscreen);

static void        gtk_offscreen_box_add           (GtkContainer    *container,
                                                    GtkWidget       *child);
static void        gtk_offscreen_box_remove        (GtkContainer    *container,
                                                    GtkWidget       *widget);
static void        gtk_offscreen_box_forall        (GtkContainer    *container,
                                                    gboolean         include_internals,
                                                    GtkCallback      callback,
                                                    gpointer         callback_data);
static GType       gtk_offscreen_box_child_type    (GtkContainer    *container);

#define CHILD1_SIZE_SCALE 1.0
#define CHILD2_SIZE_SCALE 1.0

G_DEFINE_TYPE (GtkOffscreenBox, gtk_offscreen_box, GTK_TYPE_CONTAINER);

38 39 40 41 42 43 44 45 46 47 48 49
static void
to_child_2 (GtkOffscreenBox *offscreen_box,
	    double widget_x, double widget_y,
	    double *x_out, double *y_out)
{
  GtkAllocation child_area;
  double x, y, xr, yr;
  double cos_angle, sin_angle;

  x = widget_x;
  y = widget_y;

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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

  x -= child_area.width / 2;
  y -= child_area.height / 2;

  cos_angle = cos (-offscreen_box->angle);
  sin_angle = sin (-offscreen_box->angle);

  xr = x * cos_angle - y * sin_angle;
  yr = x * sin_angle + y * cos_angle;
  x = xr;
  y = yr;

  x += child_area.width / 2;
  y += child_area.height / 2;

  *x_out = x;
  *y_out = y;
}

static void
to_parent_2 (GtkOffscreenBox *offscreen_box,
	     double offscreen_x, double offscreen_y,
	     double *x_out, double *y_out)
{
  GtkAllocation child_area;
  double x, y, xr, yr;
  double cos_angle, sin_angle;

83
  gtk_widget_get_allocation (offscreen_box->child2, &child_area);
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

  x = offscreen_x;
  y = offscreen_y;

  x -= child_area.width / 2;
  y -= child_area.height / 2;

  cos_angle = cos (offscreen_box->angle);
  sin_angle = sin (offscreen_box->angle);

  xr = x * cos_angle - y * sin_angle;
  yr = x * sin_angle + y * cos_angle;
  x = xr;
  y = yr;

  x += child_area.width / 2;
  y += child_area.height / 2;

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 107 108 109

  *x_out = x;
  *y_out = y;
}

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
static void
gtk_offscreen_box_class_init (GtkOffscreenBoxClass *klass)
{
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);

  widget_class->realize = gtk_offscreen_box_realize;
  widget_class->unrealize = gtk_offscreen_box_unrealize;
  widget_class->size_request = gtk_offscreen_box_size_request;
  widget_class->size_allocate = gtk_offscreen_box_size_allocate;
  widget_class->expose_event = gtk_offscreen_box_expose;

  g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
                                   GTK_TYPE_OFFSCREEN_BOX,
                                   g_cclosure_new (G_CALLBACK (gtk_offscreen_box_damage),
                                                   NULL, NULL));

  container_class->add = gtk_offscreen_box_add;
  container_class->remove = gtk_offscreen_box_remove;
  container_class->forall = gtk_offscreen_box_forall;
  container_class->child_type = gtk_offscreen_box_child_type;
}

static void
gtk_offscreen_box_init (GtkOffscreenBox *offscreen_box)
{
136
  gtk_widget_set_has_window (GTK_WIDGET (offscreen_box), TRUE);
137 138 139 140 141 142 143 144
}

GtkWidget *
gtk_offscreen_box_new (void)
{
  return g_object_new (GTK_TYPE_OFFSCREEN_BOX, NULL);
}

145 146 147 148 149 150 151 152 153 154
static GdkWindow *
pick_offscreen_child (GdkWindow *offscreen_window,
		      double widget_x, double widget_y,
		      GtkOffscreenBox *offscreen_box)
{
 GtkAllocation child_area;
 double x, y;

 /* First check for child 2 */
 if (offscreen_box->child2 &&
155
     gtk_widget_get_visible (offscreen_box->child2))
156 157 158 159 160
    {
      to_child_2 (offscreen_box,
		  widget_x, widget_y,
		  &x, &y);

161
      gtk_widget_get_allocation (offscreen_box->child2, &child_area);
162 163 164 165 166 167

      if (x >= 0 && x < child_area.width &&
	  y >= 0 && y < child_area.height)
	return offscreen_box->offscreen_window2;
    }

168
 if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
169 170 171 172
   {
     x = widget_x;
     y = widget_y;

173
     gtk_widget_get_allocation (offscreen_box->child1, &child_area);
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232

     if (x >= 0 && x < child_area.width &&
	 y >= 0 && y < child_area.height)
       return offscreen_box->offscreen_window1;
   }

  return NULL;
}

static void
offscreen_window_to_parent1 (GdkWindow       *offscreen_window,
			     double           offscreen_x,
			     double           offscreen_y,
			     double          *parent_x,
			     double          *parent_y,
			     GtkOffscreenBox *offscreen_box)
{
  *parent_x = offscreen_x;
  *parent_y = offscreen_y;
}

static void
offscreen_window_from_parent1 (GdkWindow       *window,
			       double           parent_x,
			       double           parent_y,
			       double          *offscreen_x,
			       double          *offscreen_y,
			       GtkOffscreenBox *offscreen_box)
{
  *offscreen_x = parent_x;
  *offscreen_y = parent_y;
}

static void
offscreen_window_to_parent2 (GdkWindow       *offscreen_window,
			     double           offscreen_x,
			     double           offscreen_y,
			     double          *parent_x,
			     double          *parent_y,
			     GtkOffscreenBox *offscreen_box)
{
  to_parent_2 (offscreen_box,
	      offscreen_x, offscreen_y,
	      parent_x, parent_y);
}

static void
offscreen_window_from_parent2 (GdkWindow       *window,
			       double           parent_x,
			       double           parent_y,
			       double          *offscreen_x,
			       double          *offscreen_y,
			       GtkOffscreenBox *offscreen_box)
{
  to_child_2 (offscreen_box,
	      parent_x, parent_y,
	      offscreen_x, offscreen_y);
}

233 234 235 236
static void
gtk_offscreen_box_realize (GtkWidget *widget)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
237 238 239
  GtkAllocation allocation, child_area;
  GtkStyle *style;
  GdkWindow *window;
240 241
  GdkWindowAttr attributes;
  gint attributes_mask;
242
  guint border_width;
243 244 245
  GtkRequisition child_requisition;
  int start_y = 0;

246
  gtk_widget_set_realized (widget, TRUE);
247

248
  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
249

250 251 252 253 254 255
  gtk_widget_get_allocation (widget, &allocation);

  attributes.x = allocation.x + border_width;
  attributes.y = allocation.y + border_width;
  attributes.width = allocation.width - 2 * border_width;
  attributes.height = allocation.height - 2 * border_width;
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.event_mask = gtk_widget_get_events (widget)
			| GDK_EXPOSURE_MASK
			| GDK_POINTER_MOTION_MASK
			| GDK_BUTTON_PRESS_MASK
			| GDK_BUTTON_RELEASE_MASK
			| GDK_SCROLL_MASK
			| GDK_ENTER_NOTIFY_MASK
			| GDK_LEAVE_NOTIFY_MASK;

  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.wclass = GDK_INPUT_OUTPUT;

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

272 273 274 275
  window = gdk_window_new (gtk_widget_get_parent_window (widget),
                           &attributes, attributes_mask);
  gtk_widget_set_window (widget, window);
  gdk_window_set_user_data (window, widget);
276

277
  g_signal_connect (window, "pick-embedded-child",
278 279
		    G_CALLBACK (pick_offscreen_child), offscreen_box);

280
  attributes.window_type = GDK_WINDOW_OFFSCREEN;
281

282 283
  /* Child 1 */
  attributes.x = attributes.y = 0;
284
  if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
285
    {
286 287 288 289 290
      gtk_widget_get_allocation (offscreen_box->child1, &child_area);

      attributes.width = child_area.width;
      attributes.height = child_area.height;
      start_y += child_area.height;
291
    }
292
  offscreen_box->offscreen_window1 = gdk_window_new (gtk_widget_get_root_window (widget),
293 294 295 296 297
						     &attributes, attributes_mask);
  gdk_window_set_user_data (offscreen_box->offscreen_window1, widget);
  if (offscreen_box->child1)
    gtk_widget_set_parent_window (offscreen_box->child1, offscreen_box->offscreen_window1);

298
  gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window1,
299 300
				     window);

301
  g_signal_connect (offscreen_box->offscreen_window1, "to-embedder",
302
		    G_CALLBACK (offscreen_window_to_parent1), offscreen_box);
303
  g_signal_connect (offscreen_box->offscreen_window1, "from-embedder",
304 305
		    G_CALLBACK (offscreen_window_from_parent1), offscreen_box);

306 307 308
  /* Child 2 */
  attributes.y = start_y;
  child_requisition.width = child_requisition.height = 0;
309
  if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
310
    {
311 312 313 314
      gtk_widget_get_allocation (offscreen_box->child2, &child_area);

      attributes.width = child_area.width;
      attributes.height = child_area.height;
315
    }
316
  offscreen_box->offscreen_window2 = gdk_window_new (gtk_widget_get_root_window (widget),
317 318 319 320
						     &attributes, attributes_mask);
  gdk_window_set_user_data (offscreen_box->offscreen_window2, widget);
  if (offscreen_box->child2)
    gtk_widget_set_parent_window (offscreen_box->child2, offscreen_box->offscreen_window2);
321
  gdk_offscreen_window_set_embedder (offscreen_box->offscreen_window2,
322
				     window);
323
  g_signal_connect (offscreen_box->offscreen_window2, "to-embedder",
324
		    G_CALLBACK (offscreen_window_to_parent2), offscreen_box);
325
  g_signal_connect (offscreen_box->offscreen_window2, "from-embedder",
326
		    G_CALLBACK (offscreen_window_from_parent2), offscreen_box);
327

328 329 330 331 332
  gtk_widget_style_attach (widget);
  style = gtk_widget_get_style (widget);
  gtk_style_set_background (style, window, GTK_STATE_NORMAL);
  gtk_style_set_background (style, offscreen_box->offscreen_window1, GTK_STATE_NORMAL);
  gtk_style_set_background (style, offscreen_box->offscreen_window2, GTK_STATE_NORMAL);
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415

  gdk_window_show (offscreen_box->offscreen_window1);
  gdk_window_show (offscreen_box->offscreen_window2);
}

static void
gtk_offscreen_box_unrealize (GtkWidget *widget)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);

  gdk_window_set_user_data (offscreen_box->offscreen_window1, NULL);
  gdk_window_destroy (offscreen_box->offscreen_window1);
  offscreen_box->offscreen_window1 = NULL;

  gdk_window_set_user_data (offscreen_box->offscreen_window2, NULL);
  gdk_window_destroy (offscreen_box->offscreen_window2);
  offscreen_box->offscreen_window2 = NULL;

  GTK_WIDGET_CLASS (gtk_offscreen_box_parent_class)->unrealize (widget);
}

static GType
gtk_offscreen_box_child_type (GtkContainer *container)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);

  if (offscreen_box->child1 && offscreen_box->child2)
    return G_TYPE_NONE;

  return GTK_TYPE_WIDGET;
}

static void
gtk_offscreen_box_add (GtkContainer *container,
		       GtkWidget    *widget)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);

  if (!offscreen_box->child1)
    gtk_offscreen_box_add1 (offscreen_box, widget);
  else if (!offscreen_box->child2)
    gtk_offscreen_box_add2 (offscreen_box, widget);
  else
    g_warning ("GtkOffscreenBox cannot have more than 2 children\n");
}

void
gtk_offscreen_box_add1 (GtkOffscreenBox *offscreen_box,
			GtkWidget       *child)
{
  g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
  g_return_if_fail (GTK_IS_WIDGET (child));

  if (offscreen_box->child1 == NULL)
    {
      gtk_widget_set_parent_window (child, offscreen_box->offscreen_window1);
      gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
      offscreen_box->child1 = child;
    }
}

void
gtk_offscreen_box_add2 (GtkOffscreenBox  *offscreen_box,
			GtkWidget    *child)
{
  g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));
  g_return_if_fail (GTK_IS_WIDGET (child));

  if (offscreen_box->child2 == NULL)
    {
      gtk_widget_set_parent_window (child, offscreen_box->offscreen_window2);
      gtk_widget_set_parent (child, GTK_WIDGET (offscreen_box));
      offscreen_box->child2 = child;
    }
}

static void
gtk_offscreen_box_remove (GtkContainer *container,
			  GtkWidget    *widget)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);
  gboolean was_visible;

416
  was_visible = gtk_widget_get_visible (widget);
417 418 419 420 421 422 423

  if (offscreen_box->child1 == widget)
    {
      gtk_widget_unparent (widget);

      offscreen_box->child1 = NULL;

424
      if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
425 426 427 428 429 430 431 432
	gtk_widget_queue_resize (GTK_WIDGET (container));
    }
  else if (offscreen_box->child2 == widget)
    {
      gtk_widget_unparent (widget);

      offscreen_box->child2 = NULL;

433
      if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
	gtk_widget_queue_resize (GTK_WIDGET (container));
    }
}

static void
gtk_offscreen_box_forall (GtkContainer *container,
			  gboolean      include_internals,
			  GtkCallback   callback,
			  gpointer      callback_data)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (container);

  g_return_if_fail (callback != NULL);

  if (offscreen_box->child1)
    (*callback) (offscreen_box->child1, callback_data);
  if (offscreen_box->child2)
    (*callback) (offscreen_box->child2, callback_data);
}

void
gtk_offscreen_box_set_angle (GtkOffscreenBox  *offscreen_box,
			     gdouble           angle)
{
  g_return_if_fail (GTK_IS_OFFSCREEN_BOX (offscreen_box));

  offscreen_box->angle = angle;
  gtk_widget_queue_draw (GTK_WIDGET (offscreen_box));

  /* TODO: Really needs to resent pointer events if over the rotated window */
}


static void
gtk_offscreen_box_size_request (GtkWidget      *widget,
				GtkRequisition *requisition)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
  int w, h;
473
  guint border_width;
474 475 476 477

  w = 0;
  h = 0;

478
  if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
479 480 481
    {
      GtkRequisition child_requisition;

482 483
      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
                                 &child_requisition, NULL);
484 485 486 487 488

      w = MAX (w, CHILD1_SIZE_SCALE * child_requisition.width);
      h += CHILD1_SIZE_SCALE * child_requisition.height;
    }

489
  if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
490 491 492
    {
      GtkRequisition child_requisition;

493 494
      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
                                 &child_requisition, NULL);
495 496 497 498 499

      w = MAX (w, CHILD2_SIZE_SCALE * child_requisition.width);
      h += CHILD2_SIZE_SCALE * child_requisition.height;
    }

500 501 502
  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
  requisition->width = border_width * 2 + w;
  requisition->height = border_width * 2 + h;
503 504 505 506 507 508 509 510
}

static void
gtk_offscreen_box_size_allocate (GtkWidget     *widget,
				 GtkAllocation *allocation)
{
  GtkOffscreenBox *offscreen_box;
  gint start_y;
511
  guint border_width;
512 513 514

  offscreen_box = GTK_OFFSCREEN_BOX (widget);

515 516
  gtk_widget_set_allocation (widget, allocation);

517
  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
518

519
  if (gtk_widget_get_realized (widget))
520
    gdk_window_move_resize (gtk_widget_get_window (widget),
521 522 523 524 525 526 527
                            allocation->x + border_width,
                            allocation->y + border_width,
                            allocation->width - border_width * 2,
                            allocation->height - border_width * 2);

  start_y = 0;

528
  if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
529 530 531 532
    {
      GtkRequisition child_requisition;
      GtkAllocation child_allocation;

533 534
      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child1),
                                 &child_requisition, NULL);
535 536
      child_allocation.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
      child_allocation.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
537
      child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
538 539 540 541
      child_allocation.height = child_requisition.height;

      start_y += CHILD1_SIZE_SCALE * child_requisition.height;

542
      if (gtk_widget_get_realized (widget))
543 544 545 546 547 548 549 550 551 552
	gdk_window_move_resize (offscreen_box->offscreen_window1,
				child_allocation.x,
                                child_allocation.y,
				child_allocation.width,
                                child_allocation.height);

      child_allocation.x = child_allocation.y = 0;
      gtk_widget_size_allocate (offscreen_box->child1, &child_allocation);
    }

553
  if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
554 555 556 557
    {
      GtkRequisition child_requisition;
      GtkAllocation child_allocation;

558 559
      gtk_size_request_get_size (GTK_SIZE_REQUEST (offscreen_box->child2),
                                 &child_requisition, NULL);
560 561
      child_allocation.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
      child_allocation.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
562
      child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
563 564 565 566
      child_allocation.height = child_requisition.height;

      start_y += CHILD2_SIZE_SCALE * child_requisition.height;

567
      if (gtk_widget_get_realized (widget))
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
	gdk_window_move_resize (offscreen_box->offscreen_window2,
				child_allocation.x,
                                child_allocation.y,
				child_allocation.width,
                                child_allocation.height);

      child_allocation.x = child_allocation.y = 0;
      gtk_widget_size_allocate (offscreen_box->child2, &child_allocation);
    }
}

static gboolean
gtk_offscreen_box_damage (GtkWidget      *widget,
                          GdkEventExpose *event)
{
583 584
  gdk_window_invalidate_rect (gtk_widget_get_window (widget),
                              NULL, FALSE);
585 586 587 588 589 590 591 592 593

  return TRUE;
}

static gboolean
gtk_offscreen_box_expose (GtkWidget      *widget,
			  GdkEventExpose *event)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
594
  GdkWindow *window;
595

596
  if (gtk_widget_is_drawable (widget))
597
    {
598 599
      window = gtk_widget_get_window (widget);
      if (event->window == window)
600
	{
601
          cairo_surface_t *surface;
602 603 604 605
          GtkAllocation child_area;
          cairo_t *cr;
	  int start_y = 0;

606
	  if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
607
	    {
608
	      surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1);
609
              gtk_widget_get_allocation (offscreen_box->child1, &child_area);
610

611
	      cr = gdk_cairo_create (window);
612

613
              cairo_set_source_surface (cr, surface, 0, 0);
614 615 616 617 618 619 620
              cairo_paint (cr);

              cairo_destroy (cr);

              start_y += child_area.height;
	    }

621
	  if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
622 623 624
	    {
              gint w, h;

625
	      surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
626
              gtk_widget_get_allocation (offscreen_box->child2, &child_area);
627

628
	      cr = gdk_cairo_create (window);
629 630 631 632 633 634 635 636

              /* transform */
	      cairo_translate (cr, 0, start_y);
	      cairo_translate (cr, child_area.width / 2, child_area.height / 2);
	      cairo_rotate (cr, offscreen_box->angle);
	      cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);

              /* clip */
637
              gdk_drawable_get_size (offscreen_box->offscreen_window2, &w, &h);
638 639 640 641
              cairo_rectangle (cr, 0, 0, w, h);
              cairo_clip (cr);

              /* paint */
642
	      cairo_set_source_surface (cr, surface, 0, 0);
643 644 645 646 647 648 649
	      cairo_paint (cr);

              cairo_destroy (cr);
	    }
	}
      else if (event->window == offscreen_box->offscreen_window1)
	{
650
	  gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
651 652 653 654 655 656 657 658 659 660 661
			      GTK_STATE_NORMAL, GTK_SHADOW_NONE,
			      &event->area, widget, "blah",
			      0, 0, -1, -1);

	  if (offscreen_box->child1)
	    gtk_container_propagate_expose (GTK_CONTAINER (widget),
					    offscreen_box->child1,
                                            event);
	}
      else if (event->window == offscreen_box->offscreen_window2)
	{
662
	  gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
663 664 665 666 667 668 669 670 671 672 673 674 675
			      GTK_STATE_NORMAL, GTK_SHADOW_NONE,
			      &event->area, widget, "blah",
			      0, 0, -1, -1);

	  if (offscreen_box->child2)
	    gtk_container_propagate_expose (GTK_CONTAINER (widget),
					    offscreen_box->child2,
                                            event);
	}
    }

  return FALSE;
}