Index: tests/Makefile.am
===================================================================
RCS file: /cvs/gnome/gtk+/tests/Makefile.am,v
retrieving revision 1.47
diff -u -p -r1.47 Makefile.am
--- tests/Makefile.am	11 Feb 2005 07:15:10 -0000	1.47
+++ tests/Makefile.am	13 Oct 2005 20:59:04 -0000
@@ -46,6 +47,7 @@ noinst_PROGRAMS =			\
 	testmenubars			\
 	testmultidisplay		\
 	testmultiscreen			\
+	testoffscreen			\
 	testrgb				\
 	testselection			\
 	$(testsocket_programs)		\
@@ -135,6 +138,7 @@ testsocket_child_LDADD = $(LDADDS)
 testspinbutton_LDADD = $(LDADDS)
 testtextbuffer_LDADD = $(LDADDS)
 testtoolbar_LDADD = $(LDADDS)
+testoffscreen_LDADD = $(LDADDS)
 stresstest_toolbar_LDADD = $(LDADDS)
 testtreeedit_LDADD = $(LDADDS)
 testtreemodel_LDADD = $(LDADDS)
@@ -197,6 +201,11 @@ testspinbutton_SOURCES =    	\
 
 testmerge_SOURCES = 		\
 	testmerge.c
+
+testoffscreen_SOURCES = 		\
+	gtkoffscreenbox.h	\
+	gtkoffscreenbox.c	\
+	testoffscreen.c
 
 testactions_SOURCES = 		\
 	testactions.c
Index: tests/gtkoffscreenbox.c
===================================================================
RCS file: tests/gtkoffscreenbox.c
diff -N tests/gtkoffscreenbox.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/gtkoffscreenbox.c	13 Oct 2005 20:59:04 -0000
@@ -0,0 +1,699 @@
+#include <config.h>
+#include "gtkoffscreenbox.h"
+#include <x11/gdkx.h>
+#include <cairo-xlib.h>
+#include <math.h>
+
+static void       gtk_offscreen_box_class_init            (GtkOffscreenBoxClass *klass);
+static void       gtk_offscreen_box_init                  (GtkOffscreenBox      *offscreen_box);
+static void       gtk_offscreen_box_realize               (GtkWidget            *widget);
+static void       gtk_offscreen_box_unrealize             (GtkWidget            *widget);
+static void       gtk_offscreen_box_map                   (GtkWidget            *widget);
+static void       gtk_offscreen_box_unmap                 (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 gint       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);
+static gboolean   gtk_offscreen_box_damage_event          (GtkWidget            *widget,
+							   GdkEventExpose       *event);
+static void       window_to_parent_coordinate             (GdkWindow            *window,
+							   double                x,
+							   double                y,
+							   double               *parent_x,
+							   double               *parent_y,
+							   GtkOffscreenBox      *offscreen_box);
+static void       parent_to_window_coordinate             (GdkWindow            *window,
+							   double                x,
+							   double                y,
+							   double               *win_x,
+							   double               *win_y,
+							   GtkOffscreenBox      *offscreen_box);
+static GdkWindow *find_offscreen_child                    (GdkWindow            *window,
+							   double                x,
+							   double                y,
+							   GtkOffscreenBox      *offscreen_box);
+  
+static GtkContainerClass *parent_class = NULL;
+
+#define CHILD1_SIZE_SCALE 1.1
+#define CHILD2_SIZE_SCALE 1.7
+
+GType
+gtk_offscreen_box_get_type (void)
+{
+  static GType offscreen_box_type = 0;
+
+  if (!offscreen_box_type)
+    {
+      static const GTypeInfo offscreen_box_info =
+      {
+	sizeof (GtkOffscreenBoxClass),
+	NULL,		/* base_init */
+	NULL,		/* base_finalize */
+	(GClassInitFunc) gtk_offscreen_box_class_init,
+	NULL,		/* class_finalize */
+	NULL,		/* class_data */
+	sizeof (GtkOffscreenBox),
+	0,		/* n_preallocs */
+	(GInstanceInitFunc) gtk_offscreen_box_init,
+      };
+
+      offscreen_box_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkOffscreenBox",
+						   &offscreen_box_info, 0);
+    }
+
+  return offscreen_box_type;
+}
+
+static void
+gtk_offscreen_box_class_init (GtkOffscreenBoxClass *class)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+  GtkContainerClass *container_class;
+
+  parent_class = g_type_class_peek_parent (class);
+  container_class = (GtkContainerClass*) class;
+
+  widget_class->realize = gtk_offscreen_box_realize;
+  widget_class->unrealize = gtk_offscreen_box_unrealize;
+  widget_class->map = gtk_offscreen_box_map;
+  widget_class->unmap = gtk_offscreen_box_unmap;
+  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;
+  widget_class->damage_event = gtk_offscreen_box_damage_event;
+
+  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)
+{
+  GTK_WIDGET_UNSET_FLAGS (offscreen_box, GTK_NO_WINDOW);
+ 
+}
+
+GtkWidget*
+gtk_offscreen_box_new (void)
+{
+  return g_object_new (GTK_TYPE_OFFSCREEN_BOX, NULL);
+}
+
+static void
+gtk_offscreen_box_realize (GtkWidget *widget)
+{
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+  gint border_width;
+  GtkOffscreenBox *offscreen_box;
+  GtkRequisition child_requisition;
+  int start_y;
+
+  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+  offscreen_box = GTK_OFFSCREEN_BOX (widget);
+  border_width = GTK_CONTAINER (widget)->border_width;
+  
+  attributes.x = widget->allocation.x + border_width;
+  attributes.y = widget->allocation.y + border_width;
+  attributes.width = widget->allocation.width - 2*border_width;
+  attributes.height = widget->allocation.height - 2*border_width;
+  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;
+  
+  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+				   &attributes, attributes_mask);
+  gdk_window_set_user_data (widget->window, widget);
+
+  start_y = 0;
+
+  /* Child 1 */
+  child_requisition.width = child_requisition.height = 0;
+  if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+    {
+      gtk_widget_get_child_requisition (offscreen_box->child1, &child_requisition);
+    }
+
+  attributes.x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
+  attributes.y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
+  attributes.width = child_requisition.width;
+  attributes.height = child_requisition.height;
+
+  start_y += CHILD1_SIZE_SCALE * child_requisition.height;
+  
+  offscreen_box->offscreen_window1 = gdk_window_new_offscreen (widget->window,
+							       &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);
+
+  /* Child 2 */
+  child_requisition.width = child_requisition.height = 0;
+  if (offscreen_box->child2 && GTK_WIDGET_VISIBLE (offscreen_box->child2))
+    {
+      gtk_widget_get_child_requisition (offscreen_box->child2, &child_requisition);
+    }
+
+  attributes.x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
+  attributes.y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
+  attributes.width = child_requisition.width;
+  attributes.height = child_requisition.height;
+
+  start_y += CHILD2_SIZE_SCALE * child_requisition.height;
+  
+  offscreen_box->offscreen_window2 = gdk_window_new_offscreen (widget->window,
+							       &attributes, attributes_mask);
+  gdk_window_set_user_data (offscreen_box->offscreen_window2, widget);
+  g_signal_connect_object (offscreen_box->offscreen_window2, "parent_to_window_coordinate",
+			   G_CALLBACK (parent_to_window_coordinate), widget, 0);
+  g_signal_connect_object (offscreen_box->offscreen_window2, "window_to_parent_coordinate",
+			   G_CALLBACK (window_to_parent_coordinate), widget, 0);
+
+  g_signal_connect_object (widget->window, "find_offscreen_child",
+			   G_CALLBACK (find_offscreen_child), widget, 0);
+
+  if (offscreen_box->child2)
+    gtk_widget_set_parent_window (offscreen_box->child2,
+				  offscreen_box->offscreen_window2);
+
+  
+  widget->style = gtk_style_attach (widget->style, widget->window);
+  
+  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+  gtk_style_set_background (widget->style, offscreen_box->offscreen_window1, GTK_STATE_NORMAL);
+  gtk_style_set_background (widget->style, offscreen_box->offscreen_window2, GTK_STATE_NORMAL);
+
+  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;
+
+  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;
+  
+  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
+    (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+}
+
+static GType
+gtk_offscreen_box_child_type (GtkContainer *container)
+{
+  if (!GTK_OFFSCREEN_BOX (container)->child1 || !GTK_OFFSCREEN_BOX (container)->child2)
+    return GTK_TYPE_WIDGET;
+  else
+    return G_TYPE_NONE;
+}
+
+static void
+gtk_offscreen_box_add (GtkContainer *container,
+		       GtkWidget    *widget)
+{
+  GtkOffscreenBox *offscreen_box;
+
+  g_return_if_fail (GTK_IS_OFFSCREEN_BOX (container));
+
+  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_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_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;
+  gboolean was_visible;
+
+  
+  offscreen_box = GTK_OFFSCREEN_BOX (container);
+  was_visible = GTK_WIDGET_VISIBLE (widget);
+
+  if (offscreen_box->child1 == widget)
+    {
+      gtk_widget_unparent (widget);
+
+      offscreen_box->child1 = NULL;
+
+      if (was_visible && GTK_WIDGET_VISIBLE (container))
+	gtk_widget_queue_resize (GTK_WIDGET (container));
+    }
+  else if (offscreen_box->child2 == widget)
+    {
+      gtk_widget_unparent (widget);
+
+      offscreen_box->child2 = NULL;
+
+      if (was_visible && GTK_WIDGET_VISIBLE (container))
+	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;
+
+  g_return_if_fail (callback != NULL);
+
+  offscreen_box = GTK_OFFSCREEN_BOX (container);
+
+  if (offscreen_box->child1)
+    (*callback) (offscreen_box->child1, callback_data);
+  if (offscreen_box->child2)
+    (*callback) (offscreen_box->child2, callback_data);
+}
+
+static void
+gtk_offscreen_box_map (GtkWidget *widget)
+{
+  (* GTK_WIDGET_CLASS (parent_class)->map) (widget);
+}
+
+static void
+gtk_offscreen_box_unmap (GtkWidget *widget)
+{
+  (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget);
+}
+
+void
+gtk_offscreen_box_set_angle (GtkOffscreenBox  *offscreen_box,
+			     double 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;
+
+  w = 0;
+  h = 0;
+  
+  if (offscreen_box->child1 &&
+      GTK_WIDGET_VISIBLE (offscreen_box->child1))
+    {
+      GtkRequisition child_requisition;
+      
+      gtk_widget_size_request (offscreen_box->child1, &child_requisition);
+
+      w = MAX (w, CHILD1_SIZE_SCALE * child_requisition.width);
+      h += CHILD1_SIZE_SCALE * child_requisition.height;
+    }
+
+  if (offscreen_box->child2 &&
+      GTK_WIDGET_VISIBLE (offscreen_box->child2))
+    {
+      GtkRequisition child_requisition;
+      
+      gtk_widget_size_request (offscreen_box->child2, &child_requisition);
+
+      w = MAX (w, CHILD2_SIZE_SCALE * child_requisition.width);
+      h += CHILD2_SIZE_SCALE * child_requisition.height;
+    }
+  
+  requisition->width = GTK_CONTAINER (widget)->border_width * 2 + w;
+  requisition->height = GTK_CONTAINER (widget)->border_width * 2 + h;
+}
+
+static void
+gtk_offscreen_box_size_allocate (GtkWidget     *widget,
+				 GtkAllocation *allocation)
+{
+  GtkOffscreenBox *offscreen_box;
+  GtkAllocation child_allocation;
+  GtkRequisition child_requisition;
+  gint border_width;
+  gint start_y;
+  
+  widget->allocation = *allocation;
+  offscreen_box = GTK_OFFSCREEN_BOX (widget);
+  
+  border_width = GTK_CONTAINER (widget)->border_width;
+  
+  
+  if (GTK_WIDGET_REALIZED (widget))
+    {
+      gdk_window_move_resize (widget->window,
+			      allocation->x + border_width,
+			      allocation->y + border_width,
+			      allocation->width - border_width * 2,
+			      allocation->height - border_width * 2);
+      
+    }
+
+  start_y = 0;
+  
+  if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+    {
+      gtk_widget_get_child_requisition (offscreen_box->child1, &child_requisition);
+
+      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;
+      child_allocation.width = child_requisition.width;
+      child_allocation.height = child_requisition.height;
+
+      start_y += CHILD1_SIZE_SCALE * child_requisition.height;
+      
+      if (GTK_WIDGET_REALIZED (widget))
+	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);
+    }
+  
+  if (offscreen_box->child2 && GTK_WIDGET_VISIBLE (offscreen_box->child2))
+    {
+      gtk_widget_get_child_requisition (offscreen_box->child2, &child_requisition);
+
+      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;
+      child_allocation.width = child_requisition.width;
+      child_allocation.height = child_requisition.height;
+
+      start_y += CHILD2_SIZE_SCALE * child_requisition.height;
+      
+      if (GTK_WIDGET_REALIZED (widget))
+	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_event (GtkWidget *widget,
+					 GdkEventExpose *event)
+{
+  gdk_window_invalidate_rect (widget->window, NULL, FALSE);
+  return TRUE;
+}
+
+static gint
+gtk_offscreen_box_expose (GtkWidget      *widget,
+			  GdkEventExpose *event)
+{
+  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
+  GtkRequisition child_requisition;
+
+  
+  if (GTK_WIDGET_DRAWABLE (widget))
+    {
+      if (event->window == widget->window)
+	{
+	  GdkPixmap *pixmap;
+	  GdkGC *gc;
+	  int x, y, width, height, start_y;
+
+	  start_y = 0;
+
+	  if (offscreen_box->child1 && GTK_WIDGET_VISIBLE (offscreen_box->child1))
+	    {
+	      gtk_widget_get_child_requisition (offscreen_box->child1, &child_requisition);
+	  
+	      x = child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2;
+	      y = start_y + child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2;
+	      width = child_requisition.width;
+	      height = child_requisition.height;
+
+	      start_y += CHILD1_SIZE_SCALE * child_requisition.height;
+
+	      pixmap = gdk_window_get_offscreen_pixmap (offscreen_box->offscreen_window1);
+
+	      gc = gdk_gc_new (pixmap);
+
+	      gdk_draw_drawable (widget->window, gc, pixmap,
+				 0, 0,
+				 x, y,
+				 -1, -1);
+	  
+	      g_object_unref (gc);
+	    }
+	  
+	  if (offscreen_box->child2 && GTK_WIDGET_VISIBLE (offscreen_box->child2))
+	    {
+	      cairo_t *cr;
+	      
+	      gtk_widget_get_child_requisition (offscreen_box->child2, &child_requisition);
+	  
+	      x = child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2;
+	      y = start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2;
+	      width = child_requisition.width;
+	      height = child_requisition.height;
+
+	      start_y += CHILD2_SIZE_SCALE * child_requisition.height;
+
+	      pixmap = gdk_window_get_offscreen_pixmap (offscreen_box->offscreen_window2);
+
+	      cr = gdk_cairo_create (widget->window);
+	      cairo_translate (cr, x, y);
+	      cairo_translate (cr, width/2, height/2);
+	      cairo_rotate (cr, offscreen_box->angle);
+	      cairo_translate (cr, -width/2, -height/2);
+	      gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+	      cairo_paint (cr);
+	    }
+
+
+	}
+      else if (event->window == offscreen_box->offscreen_window1)
+	{
+	  gtk_paint_flat_box (widget->style, event->window, 
+			      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)
+	{
+	  gtk_paint_flat_box (widget->style, event->window, 
+			      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;
+}
+
+static gboolean
+parent_to_child1 (GtkOffscreenBox *offscreen_box,
+		  double x, double y, double *child_x, double *child_y)
+{
+  GtkRequisition child_requisition;
+  
+  gtk_widget_size_request (offscreen_box->child1, &child_requisition);
+  
+  *child_x = x - (child_requisition.width * (CHILD1_SIZE_SCALE - 1.0) / 2);
+  *child_y = y - (child_requisition.height * (CHILD1_SIZE_SCALE - 1.0) / 2);
+
+  return (*child_x >= 0 && *child_x < child_requisition.width &&
+	  *child_y >= 0 && *child_y < child_requisition.height);
+}
+
+static void
+parent_to_window_coordinate (GdkWindow *window,
+			     double x, double y,
+			     double *win_x, double *win_y,
+			     GtkOffscreenBox *offscreen_box)
+{
+  GtkRequisition child_requisition;
+  double pos_x, pos_y, rot_x, rot_y, start_y;
+  double angle;
+
+  start_y = 0;
+
+  if (offscreen_box->child1)
+    {
+      gtk_widget_size_request (offscreen_box->child1, &child_requisition);
+      start_y = child_requisition.height * CHILD1_SIZE_SCALE;
+    }
+  
+  gtk_widget_size_request (offscreen_box->child2, &child_requisition);
+  
+  pos_x = x - (child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2);
+  pos_y = y - (start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2);
+
+  pos_x -= child_requisition.width/2;
+  pos_y -= child_requisition.height/2;
+
+  angle = -offscreen_box->angle;
+  rot_x = pos_x*cos (angle) - pos_y * sin(angle);
+  rot_y = pos_x*sin (angle) + pos_y * cos(angle);
+  
+  *win_x = rot_x + child_requisition.width/2;
+  *win_y = rot_y + child_requisition.height/2;
+}
+
+static void
+window_to_parent_coordinate (GdkWindow *window,
+			     double x, double y,
+			     double *parent_x, double *parent_y,
+			     GtkOffscreenBox *offscreen_box)
+{
+  GtkRequisition child_requisition;
+  double pos_x, pos_y, rot_x, rot_y, start_y;
+  double angle;
+
+  gtk_widget_size_request (offscreen_box->child1, &child_requisition);
+  start_y = child_requisition.height * CHILD1_SIZE_SCALE;
+  
+  gtk_widget_size_request (offscreen_box->child2, &child_requisition);
+
+  pos_x = x - child_requisition.width/2;
+  pos_y = y - child_requisition.height/2;
+
+  angle = offscreen_box->angle;
+  rot_x = pos_x*cos (angle) - pos_y * sin(angle);
+  rot_y = pos_x*sin (angle) + pos_y * cos(angle);
+  
+  rot_x += child_requisition.width/2;
+  rot_y += child_requisition.height/2;
+
+  *parent_x = rot_x + (child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2);
+  *parent_y = rot_y + (start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2);
+}
+
+static gboolean
+parent_to_child2 (GtkOffscreenBox *offscreen_box,
+		  double x, double y, double *child_x, double *child_y)
+{
+  GtkRequisition child_requisition;
+  double pos_x, pos_y, rot_x, rot_y, start_y;
+  double angle;
+
+  start_y = 0;
+  if (offscreen_box->child1)
+    {
+      gtk_widget_size_request (offscreen_box->child1, &child_requisition);
+      start_y += child_requisition.height * CHILD1_SIZE_SCALE;
+    }
+  
+  gtk_widget_size_request (offscreen_box->child2, &child_requisition);
+  
+  pos_x = x - (child_requisition.width * (CHILD2_SIZE_SCALE - 1.0) / 2);
+  pos_y = y - (start_y + child_requisition.height * (CHILD2_SIZE_SCALE - 1.0) / 2);
+
+  pos_x -= child_requisition.width/2;
+  pos_y -= child_requisition.height/2;
+
+  angle = -offscreen_box->angle;
+  rot_x = pos_x*cos (angle) - pos_y * sin(angle);
+  rot_y = pos_x*sin (angle) + pos_y * cos(angle);
+  
+  *child_x = rot_x + child_requisition.width/2;
+  *child_y = rot_y + child_requisition.height/2;
+
+  return (*child_x >= 0 && *child_x < child_requisition.width &&
+	  *child_y >= 0 && *child_y < child_requisition.height);
+}
+
+static GdkWindow *
+find_offscreen_child (GdkWindow *window, double x, double y,
+		      GtkOffscreenBox *offscreen_box)
+{
+  double ox, oy;
+  
+  /* Child2 is drawn last, pick first */
+  if (offscreen_box->child2 &&
+      parent_to_child2 (offscreen_box, x, y, &ox, &oy))
+    return offscreen_box->offscreen_window2;
+  
+  if (offscreen_box->child1 &&
+      parent_to_child1 (offscreen_box, x, y, &ox, &oy))
+    return offscreen_box->offscreen_window1;
+
+  return NULL;
+}
Index: tests/gtkoffscreenbox.h
===================================================================
RCS file: tests/gtkoffscreenbox.h
diff -N tests/gtkoffscreenbox.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/gtkoffscreenbox.h	13 Oct 2005 20:59:04 -0000
@@ -0,0 +1,53 @@
+#ifndef __GTK_OFFSCREEN_BOX_H__
+#define __GTK_OFFSCREEN_BOX_H__
+
+
+#include <gdk/gdk.h>
+#include <gtk/gtkbin.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_OFFSCREEN_BOX              (gtk_offscreen_box_get_type ())
+#define GTK_OFFSCREEN_BOX(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_OFFSCREEN_BOX, GtkOffscreenBox))
+#define GTK_OFFSCREEN_BOX_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OFFSCREEN_BOX, GtkOffscreenBoxClass))
+#define GTK_IS_OFFSCREEN_BOX(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_OFFSCREEN_BOX))
+#define GTK_IS_OFFSCREEN_BOX_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OFFSCREEN_BOX))
+#define GTK_OFFSCREEN_BOX_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_OFFSCREEN_BOX, GtkOffscreenBoxClass))
+
+typedef struct _GtkOffscreenBox	  GtkOffscreenBox;
+typedef struct _GtkOffscreenBoxClass  GtkOffscreenBoxClass;
+
+struct _GtkOffscreenBox
+{
+  GtkContainer container;
+  
+  GtkWidget *child1;
+  GtkWidget *child2;
+  
+  GdkWindow *offscreen_window1;
+  GdkWindow *offscreen_window2;
+
+  GdkWindow *last_pointer_event_window;
+  gdouble angle;
+};
+
+struct _GtkOffscreenBoxClass
+{
+  GtkBinClass parent_class;
+};
+
+GType	   gtk_offscreen_box_get_type           (void) G_GNUC_CONST;
+GtkWidget* gtk_offscreen_box_new       (void);
+void       gtk_offscreen_box_add1      (GtkOffscreenBox *offscreen,
+					GtkWidget       *child);
+void       gtk_offscreen_box_add2      (GtkOffscreenBox *offscreen,
+					GtkWidget       *child);
+void       gtk_offscreen_box_set_angle (GtkOffscreenBox *offscreen,
+					double           angle);
+
+
+
+G_END_DECLS
+
+#endif /* __GTK_OFFSCREEN_BOX_H__ */
Index: tests/testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testgtk.c,v
retrieving revision 1.354
diff -u -p -r1.354 testgtk.c
--- tests/testgtk.c	15 Jun 2005 19:25:49 -0000	1.354
+++ tests/testgtk.c	13 Oct 2005 20:59:04 -0000
@@ -11900,6 +11900,7 @@ query_properties (GtkButton *button,
   data->in_query = TRUE;
 }
 
+
 static void
 create_properties (GtkWidget *widget)
 {
@@ -11949,6 +11950,155 @@ create_properties (GtkWidget *widget)
   
 }
 
+struct SnapshotData {
+  GtkWidget *toplevel_button;
+  GtkWidget **window;
+  GdkCursor *cursor;
+  gboolean in_query;
+  gboolean is_toplevel;
+  gint handler;
+};
+
+static void
+destroy_snapshot_data (GtkWidget             *widget,
+		       struct SnapshotData *data)
+{
+  if (*data->window)
+    *data->window = NULL;
+  
+  if (data->cursor)
+    {
+      gdk_cursor_unref (data->cursor);
+      data->cursor = NULL;
+    }
+
+  if (data->handler)
+    {
+      g_signal_handler_disconnect (widget, data->handler);
+      data->handler = 0;
+    }
+
+  g_free (data);
+}
+
+static gint
+snapshot_widget_event (GtkWidget	       *widget,
+		       GdkEvent	       *event,
+		       struct SnapshotData *data)
+{
+  GtkWidget *res_widget = NULL;
+
+  if (!data->in_query)
+    return FALSE;
+  
+  if (event->type == GDK_BUTTON_RELEASE)
+    {
+      gtk_grab_remove (widget);
+      gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
+				  GDK_CURRENT_TIME);
+      
+      res_widget = find_widget_at_pointer (gtk_widget_get_display (widget));
+      if (data->is_toplevel && res_widget)
+	res_widget = gtk_widget_get_toplevel (res_widget);
+      if (res_widget)
+	{
+	  GdkPixmap *pixmap;
+	  GtkWidget *window, *image;
+
+	  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+	  pixmap = gtk_widget_get_snapshot (res_widget);
+	  image = gtk_image_new_from_pixmap (pixmap, NULL);
+	  gtk_container_add (GTK_CONTAINER (window), image);
+	  
+	  gtk_widget_show_all (window);
+	}
+
+      data->in_query = FALSE;
+    }
+  return FALSE;
+}
+
+
+static void
+snapshot_widget (GtkButton *button,
+		 struct SnapshotData *data)
+{
+  gint failure;
+
+  g_signal_connect (button, "event",
+		    G_CALLBACK (snapshot_widget_event), data);
+
+  data->is_toplevel = GTK_WIDGET (button) == data->toplevel_button;
+  
+  if (!data->cursor)
+    data->cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (button)),
+					       GDK_TARGET);
+  
+  failure = gdk_pointer_grab (GTK_WIDGET (button)->window,
+			      TRUE,
+			      GDK_BUTTON_RELEASE_MASK,
+			      NULL,
+			      data->cursor,
+			      GDK_CURRENT_TIME);
+
+  gtk_grab_add (GTK_WIDGET (button));
+
+  data->in_query = TRUE;
+}
+
+static void
+create_snapshot (GtkWidget *widget)
+{
+  static GtkWidget *window = NULL;
+  GtkWidget *button;
+  GtkWidget *vbox;
+  struct SnapshotData *data;
+
+  data = g_new (struct SnapshotData, 1);
+  data->window = &window;
+  data->in_query = FALSE;
+  data->cursor = NULL;
+  data->handler = 0;
+
+  if (!window)
+    {
+      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+      gtk_window_set_screen (GTK_WINDOW (window),
+			     gtk_widget_get_screen (widget));      
+
+      data->handler = g_signal_connect (window, "destroy",
+					G_CALLBACK (destroy_snapshot_data),
+					data);
+
+      gtk_window_set_title (GTK_WINDOW (window), "test snapshot");
+      gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+
+      vbox = gtk_vbox_new (FALSE, 1);
+      gtk_container_add (GTK_CONTAINER (window), vbox);
+            
+      button = gtk_button_new_with_label ("Snapshot widget");
+      gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+      g_signal_connect (button, "clicked",
+			G_CALLBACK (snapshot_widget),
+			data);
+      
+      button = gtk_button_new_with_label ("Snapshot toplevel");
+      data->toplevel_button = button;
+      gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+      g_signal_connect (button, "clicked",
+			G_CALLBACK (snapshot_widget),
+			data);
+    }
+
+  if (!GTK_WIDGET_VISIBLE (window))
+    gtk_widget_show_all (window);
+  else
+    gtk_widget_destroy (window);
+  
+}
+
+
 
 /*
  * Color Preview
@@ -13148,6 +13298,80 @@ create_styles (GtkWidget *widget)
     gtk_widget_destroy (window);
 }
 
+
+/* GtkExpander */
+
+static void
+create_expander (GtkWidget *widget)
+{
+  static GtkWidget *window = NULL;
+  GtkWidget *box1, *box2, *button, *expander, *frame, *entry;
+
+  if (!window)
+    {
+      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_screen (GTK_WINDOW (window),
+			     gtk_widget_get_screen (widget));
+
+      g_signal_connect (window, "destroy",
+			G_CALLBACK (gtk_widget_destroyed),
+			&window);
+
+      gtk_window_set_title (GTK_WINDOW (window), "GtkExpander");
+      gtk_container_set_border_width (GTK_CONTAINER (window), 4);
+
+      frame = gtk_frame_new ("Frame");
+      gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
+      gtk_container_add (GTK_CONTAINER (window), frame);
+      
+      box1 = gtk_vbox_new (FALSE, 0);
+      gtk_container_set_border_width (GTK_CONTAINER (box1), 4);
+      gtk_container_add (GTK_CONTAINER (frame), box1);
+
+      button = gtk_toggle_button_new_with_label ("button1");
+      gtk_box_pack_start (GTK_BOX (box1), button, FALSE, FALSE, 0);
+      
+      button = gtk_toggle_button_new_with_label ("button2");
+      gtk_box_pack_start (GTK_BOX (box1), button, FALSE, FALSE, 0);
+
+      expander = gtk_expander_new ("expand me!");
+      gtk_box_pack_start (GTK_BOX (box1), expander, FALSE, FALSE, 0);
+
+      box2 = gtk_vbox_new (FALSE, 0);
+
+      button = gtk_toggle_button_new_with_label ("button3");
+      gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0);
+
+      button = gtk_toggle_button_new_with_label ("button4 - really long.......");
+      gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0);
+
+      entry = gtk_entry_new ();
+      gtk_box_pack_start (GTK_BOX (box2), entry, FALSE, FALSE, 0);
+      
+      button = gtk_toggle_button_new_with_label ("button5");
+      gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0);
+
+      gtk_container_add (GTK_CONTAINER (expander), box2);
+
+      button = gtk_toggle_button_new_with_label ("button6");
+      gtk_box_pack_start (GTK_BOX (box1), button, FALSE, FALSE, 0);
+      
+      button = gtk_toggle_button_new_with_label ("button7");
+      gtk_box_pack_start (GTK_BOX (box1), button, FALSE, FALSE, 0);
+      
+      entry = gtk_entry_new ();
+      gtk_box_pack_start (GTK_BOX (box1), entry, FALSE, FALSE, 0);
+
+    }
+
+  if (!GTK_WIDGET_VISIBLE (window))
+    gtk_widget_show_all (window);
+  else
+    gtk_widget_destroy (window);
+}
+
+
+
 /*
  * Main Window and Exit
  */
@@ -13184,6 +13408,7 @@ struct {
   { "entry", create_entry },
   { "event box", create_event_box },
   { "event watcher", create_event_watcher },
+  { "expander", create_expander },
   { "file selection", create_file_selection },
   { "flipping", create_flipping },
   { "focus", create_focus },
@@ -13221,6 +13446,7 @@ struct {
   { "scrolled windows", create_scrolled_windows },
   { "shapes", create_shapes },
   { "size groups", create_size_groups },
+  { "snapshot", create_snapshot },
   { "spinbutton", create_spins },
   { "statusbar", create_statusbar },
   { "styles", create_styles },
@@ -13256,7 +13482,7 @@ create_main_window (void)
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_name (window, "main window");
-  gtk_widget_set_uposition (window, 20, 20);
+  gtk_widget_set_uposition (window, 50, 20);
   gtk_window_set_default_size (GTK_WINDOW (window), -1, 400);
 
   geometry.min_width = -1;
Index: tests/testoffscreen.c
===================================================================
RCS file: tests/testoffscreen.c
diff -N tests/testoffscreen.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/testoffscreen.c	13 Oct 2005 20:59:04 -0000
@@ -0,0 +1,291 @@
+#undef GTK_DISABLE_DEPRECATED
+
+#include <math.h>
+#include <gtk/gtk.h>
+#include "gtkoffscreenbox.h"
+
+
+static void
+combo_changed_cb (GtkWidget *combo,
+		  gpointer   data)
+{
+  GtkWidget *label = GTK_WIDGET (data);
+  gint active;
+
+  active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+  
+  gtk_label_set_ellipsize (GTK_LABEL (label), (PangoEllipsizeMode)active);
+}
+
+gboolean
+layout_expose_handler (GtkWidget *widget, GdkEventExpose *event)
+{
+  GtkLayout *layout;
+
+  gint i,j;
+  gint imin, imax, jmin, jmax;
+
+  layout = GTK_LAYOUT (widget);
+
+  if (event->window != layout->bin_window)
+    return FALSE;
+  
+  imin = (event->area.x) / 10;
+  imax = (event->area.x + event->area.width + 9) / 10;
+
+  jmin = (event->area.y) / 10;
+  jmax = (event->area.y + event->area.height + 9) / 10;
+
+  for (i=imin; i<imax; i++)
+    for (j=jmin; j<jmax; j++)
+      if ((i+j) % 2)
+	gdk_draw_rectangle (layout->bin_window,
+			    widget->style->black_gc,
+			    TRUE,
+			    10*i, 10*j, 
+			    1+i%10, 1+j%10);
+  
+  return FALSE;
+}
+
+static gboolean
+scroll_layout (gpointer data)
+{
+  GtkWidget *layout = data;
+  GtkAdjustment *adj;
+  
+  adj = gtk_layout_get_hadjustment (GTK_LAYOUT (layout));
+  gtk_adjustment_set_value (adj,
+			    gtk_adjustment_get_value (adj) + 5.0);
+  return TRUE;
+}
+
+static guint layout_timeout;
+
+void create_layout (GtkWidget *vbox)
+{
+  GtkWidget *layout;
+  GtkWidget *scrolledwindow;
+  GtkWidget *button;
+  gchar buf[16];
+  gint i, j;
+      
+
+  scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
+				       GTK_SHADOW_IN);
+  gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (scrolledwindow),
+				     GTK_CORNER_TOP_RIGHT);
+  
+  gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
+  
+  layout = gtk_layout_new (NULL, NULL);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow), layout);
+  
+  /* We set step sizes here since GtkLayout does not set
+   * them itself.
+   */
+  GTK_LAYOUT (layout)->hadjustment->step_increment = 10.0;
+  GTK_LAYOUT (layout)->vadjustment->step_increment = 10.0;
+  
+  gtk_widget_set_events (layout, GDK_EXPOSURE_MASK);
+  g_signal_connect (layout, "expose_event",
+		    G_CALLBACK (layout_expose_handler), NULL);
+  
+  gtk_layout_set_size (GTK_LAYOUT (layout), 1600, 128000);
+  
+  for (i=0 ; i < 16 ; i++)
+    for (j=0 ; j < 16 ; j++)
+      {
+	sprintf(buf, "Button %d, %d", i, j);
+	if ((i + j) % 2)
+	  button = gtk_button_new_with_label (buf);
+	else
+	  button = gtk_label_new (buf);
+	
+	gtk_layout_put (GTK_LAYOUT (layout), button,
+			j*100, i*100);
+      }
+  
+  for (i=16; i < 1280; i++)
+    {
+      sprintf(buf, "Button %d, %d", i, 0);
+      if (i % 2)
+	button = gtk_button_new_with_label (buf);
+      else
+	button = gtk_label_new (buf);
+      
+      gtk_layout_put (GTK_LAYOUT (layout), button,
+		      0, i*100);
+    }
+
+  layout_timeout = g_timeout_add (1000, scroll_layout, layout);
+}
+
+GtkWidget *
+create_widgets (void)
+{
+  GtkWidget *vbox, *hbox, *label, *combo, *entry, *button, *cb;
+  GtkWidget *sw, *text_view;
+  GList *cbitems = NULL;
+  
+  vbox = gtk_vbox_new (0, FALSE);
+  
+  hbox = gtk_hbox_new (0, FALSE);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+  
+  label = gtk_label_new ("This label may be ellipsized\nto make it fit.");
+  gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+  combo = gtk_combo_box_new_text ();
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "NONE");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "START");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "MIDDLE");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "END");
+  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+  g_signal_connect (combo, "changed", G_CALLBACK (combo_changed_cb), label);
+  
+  entry = gtk_entry_new ();
+  gtk_entry_set_text (GTK_ENTRY (entry), "an entry - lots of text.... lots of text.... lots of text.... lots of text.... ");
+  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+  
+  label = gtk_label_new ("Label after entry.");
+  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+  gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+
+  button = gtk_button_new_with_label ("Button");
+  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+
+  button = gtk_check_button_new_with_mnemonic ("_Check button");
+  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  cb = gtk_combo_new ();
+  cbitems = g_list_append(cbitems, "item0");
+  cbitems = g_list_append(cbitems, "item1 item1");
+  cbitems = g_list_append(cbitems, "item2 item2 item2");
+  gtk_combo_set_popdown_strings (GTK_COMBO (cb), cbitems);
+  gtk_entry_set_text (GTK_ENTRY (GTK_COMBO(cb)->entry), "hello world \n\n\n foo");
+  gtk_editable_select_region (GTK_EDITABLE (GTK_COMBO(cb)->entry),
+			      0, -1);
+  gtk_box_pack_start (GTK_BOX (vbox), cb, TRUE, TRUE, 0);
+
+  sw = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+				  GTK_POLICY_AUTOMATIC,
+				  GTK_POLICY_AUTOMATIC);
+  text_view = gtk_text_view_new ();
+  gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
+  gtk_container_add (GTK_CONTAINER (sw), text_view);
+  
+  create_layout (vbox);
+  
+  return vbox;
+}
+
+
+static void
+scale_changed (GtkRange     *range,
+	       GtkOffscreenBox *offscreen_box)
+{
+  gtk_offscreen_box_set_angle (offscreen_box,
+			       gtk_range_get_value (range));
+
+}
+
+static void
+remove_clicked (GtkButton *button, GtkWidget *widget)
+{
+  static gboolean destroyed = FALSE;
+
+  if (destroyed)
+    return;
+
+  destroyed = TRUE;
+  gtk_widget_destroy (widget);
+  g_source_remove (layout_timeout);
+}
+
+int
+main (int argc, char *argv[])
+{
+  GtkWidget *window, *widget, *scale, *vbox, *button, *widget2, *entry;
+  GtkWidget *offscreen = NULL, *offscreen2;
+  gboolean use_offscreen;
+
+  gtk_init (&argc, &argv);
+
+  use_offscreen = argc == 1;
+  
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_default_size (GTK_WINDOW (window), 300,300);
+  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+
+  vbox = gtk_vbox_new (0, FALSE);
+  gtk_container_add (GTK_CONTAINER (window), vbox);
+
+  scale = gtk_hscale_new_with_range (0, 
+				     M_PI * 2,
+				     0.01);
+  gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
+
+  button = gtk_button_new_with_label ("Remove child 2");
+  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+  
+  if (use_offscreen)
+    {
+      offscreen = gtk_offscreen_box_new ();
+      g_signal_connect (G_OBJECT (scale), "value_changed", G_CALLBACK (scale_changed), offscreen);
+    }
+  else
+    offscreen = gtk_vpaned_new ();
+  
+  gtk_box_pack_start (GTK_BOX (vbox), offscreen, TRUE, TRUE, 0);
+
+  widget = create_widgets ();
+  if (use_offscreen)
+    gtk_offscreen_box_add1 (GTK_OFFSCREEN_BOX (offscreen),
+			    widget);
+  else
+    gtk_paned_add1 (GTK_PANED (offscreen), widget);
+  
+  widget = create_widgets ();
+  if (1)
+    {
+      widget2 = gtk_button_new_with_label ("Offscreen in offscreen");
+      offscreen2 = gtk_offscreen_box_new ();
+      gtk_offscreen_box_add2 (GTK_OFFSCREEN_BOX (offscreen2),
+			      widget2);
+      g_signal_connect (G_OBJECT (scale), "value_changed", G_CALLBACK (scale_changed), offscreen2);
+      gtk_box_pack_start (GTK_BOX (widget), offscreen2, FALSE, FALSE, 0);
+    }
+      
+  if (use_offscreen)
+    gtk_offscreen_box_add2 (GTK_OFFSCREEN_BOX (offscreen),
+			    widget);
+  else
+    gtk_paned_add2 (GTK_PANED (offscreen), widget);
+
+  gtk_widget_show_all (window);
+
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (remove_clicked), widget);
+
+  /* redirect */
+  if (0)
+    {
+      GtkWidget *redirect_win;
+      
+      redirect_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_default_size (GTK_WINDOW (redirect_win), 400,400);
+      gtk_widget_show (redirect_win);
+      gtk_widget_realize (redirect_win);
+      gtk_widget_realize (window);
+      gdk_window_redirect_to_drawable (window->window,
+				       GDK_DRAWABLE (redirect_win->window),
+				       0, 0, 0, 0, -1, -1);
+    }
+  
+  gtk_main ();
+
+  return 0;
+}
