]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkpaned.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkpaned.c
index 6962059dd7d206a5e4db8608b04b943687b7bd65..7c5ec381f3f0ab9eb0633692b53f4ce2009445dc 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
 #include "gtkorientable.h"
 #include "gtkwindow.h"
 #include "gtktypebuiltins.h"
+#include "gtkorientableprivate.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
-
+#include "a11y/gtkpanedaccessible.h"
 
 /**
  * SECTION:gtkpaned
- * @Short_description: Base class for widgets with two adjustable panes
+ * @Short_description: A widget with two adjustable panes
  * @Title: GtkPaned
  *
- * #GtkPaned is the base class for widgets with two panes, arranged either
- * horizontally (#GtkHPaned) or vertically (#GtkVPaned). Child widgets are
+ * #GtkPaned has two panes, arranged either
+ * horizontally or vertically. The division between
+ * the two panes is adjustable by the user by dragging
+ * a handle.
+ *
+ * Child widgets are
  * added to the panes of the widget with gtk_paned_pack1() and
  * gtk_paned_pack2(). The division between the two children is set by default
  * from the size requests of the children, but it can be adjusted by the
  * </example>
  */
 
+enum {
+  CHILD1,
+  CHILD2
+};
+
 struct _GtkPanedPrivate
 {
-  GtkOrientation  orientation;
   GtkPaned       *first_paned;
   GtkWidget      *child1;
   GtkWidget      *child2;
+  GdkWindow      *child1_window;
+  GdkWindow      *child2_window;
   GtkWidget      *last_child1_focus;
   GtkWidget      *last_child2_focus;
   GtkWidget      *saved_focus;
+  GtkOrientation  orientation;
 
   GdkCursorType  cursor_type;
   GdkDevice     *grab_device;
@@ -111,6 +121,8 @@ struct _GtkPanedPrivate
   gint          min_position;
   gint          original_position;
 
+  guint32       grab_time;
+
   guint         handle_prelit : 1;
   guint         in_drag       : 1;
   guint         in_recursion  : 1;
@@ -119,8 +131,6 @@ struct _GtkPanedPrivate
   guint         child2_resize : 1;
   guint         child2_shrink : 1;
   guint         position_set  : 1;
-
-  guint32       grab_time;
 };
 
 enum {
@@ -174,6 +184,16 @@ static void     gtk_paned_get_preferred_width   (GtkWidget        *widget,
 static void     gtk_paned_get_preferred_height  (GtkWidget        *widget,
                                                  gint             *minimum,
                                                  gint             *natural);
+static void     gtk_paned_get_preferred_width_for_height
+                                                (GtkWidget        *widget,
+                                                 gint              height,
+                                                 gint             *minimum,
+                                                 gint             *natural);
+static void     gtk_paned_get_preferred_height_for_width
+                                                (GtkWidget        *widget,
+                                                 gint              width,
+                                                 gint             *minimum,
+                                                 gint              *natural);
 
 static void     gtk_paned_size_allocate         (GtkWidget        *widget,
                                                  GtkAllocation    *allocation);
@@ -284,6 +304,8 @@ gtk_paned_class_init (GtkPanedClass *class)
 
   widget_class->get_preferred_width = gtk_paned_get_preferred_width;
   widget_class->get_preferred_height = gtk_paned_get_preferred_height;
+  widget_class->get_preferred_width_for_height = gtk_paned_get_preferred_width_for_height;
+  widget_class->get_preferred_height_for_width = gtk_paned_get_preferred_height_for_width;
   widget_class->size_allocate = gtk_paned_size_allocate;
   widget_class->realize = gtk_paned_realize;
   widget_class->unrealize = gtk_paned_unrealize;
@@ -630,6 +652,7 @@ gtk_paned_class_init (GtkPanedClass *class)
   add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
 
   g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_PANED_ACCESSIBLE);
 }
 
 static GType
@@ -648,7 +671,6 @@ static void
 gtk_paned_init (GtkPaned *paned)
 {
   GtkPanedPrivate *priv;
-  GtkStyleContext *context;
 
   gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
   gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
@@ -667,7 +689,6 @@ gtk_paned_init (GtkPaned *paned)
   priv->child1 = NULL;
   priv->child2 = NULL;
   priv->handle = NULL;
-  priv->cursor_type = GDK_CROSS;
 
   priv->handle_pos.width = 5;
   priv->handle_pos.height = 5;
@@ -685,9 +706,6 @@ gtk_paned_init (GtkPaned *paned)
   priv->handle_pos.y = -1;
 
   priv->drag_pos = -1;
-
-  context = gtk_widget_get_style_context (GTK_WIDGET (paned));
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
 }
 
 static void
@@ -703,6 +721,7 @@ gtk_paned_set_property (GObject        *object,
     {
     case PROP_ORIENTATION:
       priv->orientation = g_value_get_enum (value);
+      _gtk_orientable_set_style_classes (GTK_ORIENTABLE (paned));
 
       if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
         priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
@@ -850,9 +869,29 @@ gtk_paned_finalize (GObject *object)
   G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
 }
 
+static void
+get_preferred_size_for_size (GtkWidget      *widget,
+                             GtkOrientation  orientation,
+                             gint            size,
+                             gint           *minimum,
+                             gint           *natural)
+{
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    if (size < 0)
+      gtk_widget_get_preferred_width (widget, minimum, natural);
+    else
+      gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
+  else
+    if (size < 0)
+      gtk_widget_get_preferred_height (widget, minimum, natural);
+    else
+      gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
+}
+
 static void
 gtk_paned_get_preferred_size (GtkWidget      *widget,
                               GtkOrientation  orientation,
+                              gint            size,
                               gint           *minimum,
                               gint           *natural)
 {
@@ -864,25 +903,22 @@ gtk_paned_get_preferred_size (GtkWidget      *widget,
 
   if (priv->child1 && gtk_widget_get_visible (priv->child1))
     {
-      if (orientation == GTK_ORIENTATION_HORIZONTAL)
-        gtk_widget_get_preferred_width (priv->child1, &child_min, &child_nat);
+      get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
+      if (priv->child1_shrink && priv->orientation == orientation)
+        *minimum = 0;
       else
-        gtk_widget_get_preferred_height (priv->child1, &child_min, &child_nat);
-
-      *minimum = child_min;
+        *minimum = child_min;
       *natural = child_nat;
     }
 
   if (priv->child2 && gtk_widget_get_visible (priv->child2))
     {
-      if (orientation == GTK_ORIENTATION_HORIZONTAL)
-        gtk_widget_get_preferred_width (priv->child2, &child_min, &child_nat);
-      else
-        gtk_widget_get_preferred_height (priv->child2, &child_min, &child_nat);
+      get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
 
       if (priv->orientation == orientation)
         {
-          *minimum += child_min;
+          if (!priv->child2_shrink)
+            *minimum += child_min;
           *natural += child_nat;
         }
       else
@@ -912,7 +948,7 @@ gtk_paned_get_preferred_width (GtkWidget *widget,
                                gint      *minimum,
                                gint      *natural)
 {
-  gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
+  gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
 }
 
 static void
@@ -920,7 +956,25 @@ gtk_paned_get_preferred_height (GtkWidget *widget,
                                 gint      *minimum,
                                 gint      *natural)
 {
-  gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum, natural);
+  gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
+}
+
+static void
+gtk_paned_get_preferred_width_for_height (GtkWidget *widget,
+                                          gint       height,
+                                          gint      *minimum,
+                                          gint      *natural)
+{
+  gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
+}
+
+static void
+gtk_paned_get_preferred_height_for_width (GtkWidget *widget,
+                                          gint       width,
+                                          gint      *minimum,
+                                          gint      *natural)
+{
+  gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
 }
 
 static void
@@ -937,82 +991,170 @@ flip_child (GtkWidget     *widget,
   child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
 }
 
+static void
+gtk_paned_set_child_visible (GtkPaned  *paned,
+                             guint      id,
+                             gboolean   visible)
+{
+  GtkPanedPrivate *priv = paned->priv;
+  GtkWidget *child;
+
+  child = id == CHILD1 ? priv->child1 : priv->child2;
+
+  if (child == NULL)
+    return;
+
+  gtk_widget_set_child_visible (child, visible);
+
+  if (gtk_widget_get_mapped (GTK_WIDGET (paned)))
+    {
+      GdkWindow *window = id == CHILD1 ? priv->child1_window : priv->child2_window;
+
+      if (visible != gdk_window_is_visible (window))
+        {
+          if (visible)
+            gdk_window_show (window);
+          else
+            gdk_window_hide (window);
+        }
+    }
+}
+
+static void
+gtk_paned_child_allocate (GtkWidget           *child,
+                          GdkWindow           *child_window, /* can be NULL */
+                          const GtkAllocation *window_allocation,
+                          GtkAllocation       *child_allocation)
+{
+  if (child_window)
+    gdk_window_move_resize (child_window,
+                            window_allocation->x, window_allocation->y,
+                            window_allocation->width, window_allocation->height);
+
+  gtk_widget_size_allocate (child, child_allocation);
+}
+
 static void
 gtk_paned_size_allocate (GtkWidget     *widget,
                          GtkAllocation *allocation)
 {
   GtkPaned *paned = GTK_PANED (widget);
   GtkPanedPrivate *priv = paned->priv;
-  GtkAllocation widget_allocation;
 
   gtk_widget_set_allocation (widget, allocation);
 
   if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
       priv->child2 && gtk_widget_get_visible (priv->child2))
     {
-      GtkRequisition child1_requisition;
-      GtkRequisition child2_requisition;
-      GtkAllocation child1_allocation;
-      GtkAllocation child2_allocation;
+      GtkAllocation child1_allocation, window1_allocation;
+      GtkAllocation child2_allocation, window2_allocation;
       GtkAllocation priv_child1_allocation;
       GdkRectangle old_handle_pos;
       gint handle_size;
 
       gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
 
-      gtk_widget_get_preferred_size (priv->child1, &child1_requisition, NULL);
-      gtk_widget_get_preferred_size (priv->child2, &child2_requisition, NULL);
-
       old_handle_pos = priv->handle_pos;
 
-      gtk_widget_get_allocation (widget, &widget_allocation);
-
       if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
         {
+          gint child1_width, child2_width;
+
+          gtk_widget_get_preferred_width_for_height (priv->child1,
+                                                     allocation->height,
+                                                     &child1_width, NULL);
+          gtk_widget_get_preferred_width_for_height (priv->child2,
+                                                     allocation->height,
+                                                     &child2_width, NULL);
+
           gtk_paned_calc_position (paned,
-                                   MAX (1, widget_allocation.width - handle_size),
-                                   child1_requisition.width,
-                                   child2_requisition.width);
+                                   MAX (1, allocation->width - handle_size),
+                                   child1_width,
+                                   child2_width);
 
-          priv->handle_pos.x = widget_allocation.x + priv->child1_size;
-          priv->handle_pos.y = widget_allocation.y;
+          priv->handle_pos.x = allocation->x + priv->child1_size;
+          priv->handle_pos.y = allocation->y;
           priv->handle_pos.width = handle_size;
-          priv->handle_pos.height = widget_allocation.height;
+          priv->handle_pos.height = allocation->height;
 
-          child1_allocation.height = child2_allocation.height = allocation->height;
-          child1_allocation.width = MAX (1, priv->child1_size);
-          child1_allocation.x = widget_allocation.x;
-          child1_allocation.y = child2_allocation.y = widget_allocation.y;
+          window1_allocation.height = window2_allocation.height = allocation->height;
+          window1_allocation.width = MAX (1, priv->child1_size);
+          window1_allocation.x = allocation->x;
+          window1_allocation.y = window2_allocation.y = allocation->y;
 
-          child2_allocation.x = child1_allocation.x + priv->child1_size + priv->handle_pos.width;
-          child2_allocation.width = MAX (1, widget_allocation.x + widget_allocation.width - child2_allocation.x);
+          window2_allocation.x = window1_allocation.x + priv->child1_size + priv->handle_pos.width;
+          window2_allocation.width = MAX (1, allocation->x + allocation->width - window2_allocation.x);
 
           if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
             {
-              flip_child (widget, &(child2_allocation));
-              flip_child (widget, &(child1_allocation));
+              flip_child (widget, &(window2_allocation));
+              flip_child (widget, &(window1_allocation));
               flip_child (widget, &(priv->handle_pos));
             }
+
+          child1_allocation.x = child1_allocation.y = 0;
+          child1_allocation.width = window1_allocation.width;
+          child1_allocation.height = window1_allocation.height;
+          if (child1_width > child1_allocation.width)
+            {
+              if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR)
+                child1_allocation.x -= child1_width - child1_allocation.width;
+              child1_allocation.width = child1_width;
+            }
+
+          child2_allocation.x = child2_allocation.y = 0;
+          child2_allocation.width = window2_allocation.width;
+          child2_allocation.height = window2_allocation.height;
+          if (child2_width > child2_allocation.width)
+            {
+              if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
+                child2_allocation.x -= child2_width - child2_allocation.width;
+              child2_allocation.width = child2_width;
+            }
         }
       else
         {
+          gint child1_height, child2_height;
+
+          gtk_widget_get_preferred_height_for_width (priv->child1,
+                                                     allocation->width,
+                                                     &child1_height, NULL);
+          gtk_widget_get_preferred_height_for_width (priv->child2,
+                                                     allocation->width,
+                                                     &child2_height, NULL);
+
           gtk_paned_calc_position (paned,
-                                   MAX (1, widget_allocation.height - handle_size),
-                                   child1_requisition.height,
-                                   child2_requisition.height);
+                                   MAX (1, allocation->height - handle_size),
+                                   child1_height,
+                                   child2_height);
 
-          priv->handle_pos.x = widget_allocation.x;
-          priv->handle_pos.y = widget_allocation.y + priv->child1_size;
-          priv->handle_pos.width = widget_allocation.width;
+          priv->handle_pos.x = allocation->x;
+          priv->handle_pos.y = allocation->y + priv->child1_size;
+          priv->handle_pos.width = allocation->width;
           priv->handle_pos.height = handle_size;
 
-          child1_allocation.width = child2_allocation.width = allocation->width;
-          child1_allocation.height = MAX (1, priv->child1_size);
-          child1_allocation.x = child2_allocation.x = widget_allocation.x;
-          child1_allocation.y = widget_allocation.y;
+          window1_allocation.width = window2_allocation.width = allocation->width;
+          window1_allocation.height = MAX (1, priv->child1_size);
+          window1_allocation.x = window2_allocation.x = allocation->x;
+          window1_allocation.y = allocation->y;
 
-          child2_allocation.y = child1_allocation.y + priv->child1_size + priv->handle_pos.height;
-          child2_allocation.height = MAX (1, widget_allocation.y + widget_allocation.height - child2_allocation.y);
+          window2_allocation.y = window1_allocation.y + priv->child1_size + priv->handle_pos.height;
+          window2_allocation.height = MAX (1, allocation->y + allocation->height - window2_allocation.y);
+
+          child1_allocation.x = child1_allocation.y = 0;
+          child1_allocation.width = window1_allocation.width;
+          child1_allocation.height = window1_allocation.height;
+          if (child1_height > child1_allocation.height)
+            {
+              child1_allocation.y -= child1_height - child1_allocation.height;
+              child1_allocation.height = child1_height;
+            }
+
+          child2_allocation.x = child2_allocation.y = 0;
+          child2_allocation.width = window2_allocation.width;
+          child2_allocation.height = window2_allocation.height;
+          if (child2_height > child2_allocation.height)
+            child2_allocation.height = child2_height;
         }
 
       if (gtk_widget_get_mapped (widget) &&
@@ -1062,41 +1204,131 @@ gtk_paned_size_allocate (GtkWidget     *widget,
            (priv->orientation == GTK_ORIENTATION_VERTICAL &&
             priv_child1_allocation.height < child1_allocation.height)))
        {
-         gtk_widget_size_allocate (priv->child2, &child2_allocation);
-         gtk_widget_size_allocate (priv->child1, &child1_allocation);
+          gtk_paned_child_allocate (priv->child2,
+                                    priv->child2_window,
+                                    &window2_allocation,
+                                    &child2_allocation);
+          gtk_paned_child_allocate (priv->child1,
+                                    priv->child1_window,
+                                    &window1_allocation,
+                                    &child1_allocation);
        }
       else
        {
-         gtk_widget_size_allocate (priv->child1, &child1_allocation);
-         gtk_widget_size_allocate (priv->child2, &child2_allocation);
+          gtk_paned_child_allocate (priv->child1,
+                                    priv->child1_window,
+                                    &window1_allocation,
+                                    &child1_allocation);
+          gtk_paned_child_allocate (priv->child2,
+                                    priv->child2_window,
+                                    &window2_allocation,
+                                    &child2_allocation);
        }
     }
   else
     {
-      GtkAllocation child_allocation;
+      GtkAllocation window_allocation, child_allocation;
 
       if (gtk_widget_get_realized (widget))
        gdk_window_hide (priv->handle);
 
-      if (priv->child1)
-       gtk_widget_set_child_visible (priv->child1, TRUE);
-      if (priv->child2)
-       gtk_widget_set_child_visible (priv->child2, TRUE);
-
-      gtk_widget_get_allocation (widget, &widget_allocation);
-
-      child_allocation.x = widget_allocation.x;
-      child_allocation.y = widget_allocation.y;
+      window_allocation.x = allocation->x;
+      window_allocation.y = allocation->y;
+      window_allocation.width = allocation->width;
+      window_allocation.height = allocation->height;
+      child_allocation.x = child_allocation.y = 0;
       child_allocation.width = allocation->width;
       child_allocation.height = allocation->height;
 
       if (priv->child1 && gtk_widget_get_visible (priv->child1))
-       gtk_widget_size_allocate (priv->child1, &child_allocation);
+        {
+          gtk_paned_set_child_visible (paned, 0, TRUE);
+          if (priv->child2)
+            gtk_paned_set_child_visible (paned, 1, FALSE);
+
+          gtk_paned_child_allocate (priv->child1,
+                                    priv->child1_window,
+                                    &window_allocation,
+                                    &child_allocation);
+        }
       else if (priv->child2 && gtk_widget_get_visible (priv->child2))
-       gtk_widget_size_allocate (priv->child2, &child_allocation);
+        {
+          gtk_paned_set_child_visible (paned, 1, TRUE);
+          if (priv->child1)
+            gtk_paned_set_child_visible (paned, 0, FALSE);
+
+          gtk_paned_child_allocate (priv->child2,
+                                    priv->child2_window,
+                                    &window_allocation,
+                                    &child_allocation);
+        }
+      else
+        {
+          if (priv->child1)
+            gtk_paned_set_child_visible (paned, 0, FALSE);
+          if (priv->child2)
+            gtk_paned_set_child_visible (paned, 1, FALSE);
+        }
     }
 }
 
+static GdkWindow *
+gtk_paned_create_child_window (GtkPaned  *paned,
+                               GtkWidget *child) /* may be NULL */
+{
+  GtkWidget *widget = GTK_WIDGET (paned);
+  GtkPanedPrivate *priv = paned->priv;
+  GdkWindow *window;
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+
+  attributes.window_type = GDK_WINDOW_CHILD;
+  attributes.wclass = GDK_INPUT_OUTPUT;
+  attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+  if (child)
+    {
+      GtkAllocation allocation;
+      int handle_size;
+
+      gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+      gtk_widget_get_allocation (widget, &allocation);
+      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
+          child == priv->child2 && priv->child1 &&
+          gtk_widget_get_visible (priv->child1))
+        attributes.x = priv->handle_pos.x + handle_size;
+      else
+        attributes.x = allocation.x;
+      if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
+          child == priv->child2 && priv->child1 &&
+          gtk_widget_get_visible (priv->child1))
+        attributes.y = priv->handle_pos.y + handle_size;
+      else
+        attributes.y = allocation.y;
+
+      gtk_widget_get_allocation (child, &allocation);
+      attributes.width = allocation.width;
+      attributes.height = allocation.height;
+      attributes_mask = GDK_WA_X | GDK_WA_Y;
+    }
+  else
+    {
+      attributes.width = 1;
+      attributes.height = 1;
+      attributes_mask = 0;
+    }
+
+  window = gdk_window_new (gtk_widget_get_window (widget),
+                           &attributes, attributes_mask);
+  gtk_widget_register_window (widget, window);
+  gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
+
+  if (child)
+    gtk_widget_set_parent_window (child, window);
+
+  return window;
+}
+
 static void
 gtk_paned_realize (GtkWidget *widget)
 {
@@ -1123,8 +1355,7 @@ gtk_paned_realize (GtkWidget *widget)
                            GDK_BUTTON_RELEASE_MASK |
                            GDK_ENTER_NOTIFY_MASK |
                            GDK_LEAVE_NOTIFY_MASK |
-                           GDK_POINTER_MOTION_MASK |
-                           GDK_POINTER_MOTION_HINT_MASK);
+                           GDK_POINTER_MOTION_MASK);
   attributes_mask = GDK_WA_X | GDK_WA_Y;
   if (gtk_widget_is_sensitive (widget))
     {
@@ -1135,13 +1366,12 @@ gtk_paned_realize (GtkWidget *widget)
 
   priv->handle = gdk_window_new (window,
                                  &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->handle, paned);
+  gtk_widget_register_window (widget, priv->handle);
   if (attributes_mask & GDK_WA_CURSOR)
     g_object_unref (attributes.cursor);
 
-  if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
-      priv->child2 && gtk_widget_get_visible (priv->child2))
-    gdk_window_show (priv->handle);
+  priv->child1_window = gtk_paned_create_child_window (paned, priv->child1);
+  priv->child2_window = gtk_paned_create_child_window (paned, priv->child2);
 }
 
 static void
@@ -1150,9 +1380,21 @@ gtk_paned_unrealize (GtkWidget *widget)
   GtkPaned *paned = GTK_PANED (widget);
   GtkPanedPrivate *priv = paned->priv;
 
+  if (priv->child2)
+    gtk_widget_set_parent_window (priv->child2, NULL);
+  gtk_widget_unregister_window (widget, priv->child2_window);
+  gdk_window_destroy (priv->child2_window);
+  priv->child2_window = NULL;
+
+  if (priv->child1)
+    gtk_widget_set_parent_window (priv->child1, NULL);
+  gtk_widget_unregister_window (widget, priv->child1_window);
+  gdk_window_destroy (priv->child1_window);
+  priv->child1_window = NULL;
+
   if (priv->handle)
     {
-      gdk_window_set_user_data (priv->handle, NULL);
+      gtk_widget_unregister_window (widget, priv->handle);
       gdk_window_destroy (priv->handle);
       priv->handle = NULL;
     }
@@ -1171,7 +1413,14 @@ gtk_paned_map (GtkWidget *widget)
   GtkPaned *paned = GTK_PANED (widget);
   GtkPanedPrivate *priv = paned->priv;
 
-  gdk_window_show (priv->handle);
+  if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
+      priv->child2 && gtk_widget_get_visible (priv->child2))
+    gdk_window_show (priv->handle);
+
+  if (priv->child1 && gtk_widget_get_visible (priv->child1) && gtk_widget_get_child_visible (priv->child1))
+    gdk_window_show (priv->child1_window);
+  if (priv->child2 && gtk_widget_get_visible (priv->child2) && gtk_widget_get_child_visible (priv->child2))
+    gdk_window_show (priv->child2_window);
 
   GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
 }
@@ -1183,6 +1432,11 @@ gtk_paned_unmap (GtkWidget *widget)
   GtkPanedPrivate *priv = paned->priv;
 
   gdk_window_hide (priv->handle);
+  
+  if (gdk_window_is_visible (priv->child1_window))
+    gdk_window_hide (priv->child1_window);
+  if (gdk_window_is_visible (priv->child2_window))
+    gdk_window_hide (priv->child2_window);
 
   GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
 }
@@ -1194,7 +1448,31 @@ gtk_paned_draw (GtkWidget *widget,
   GtkPaned *paned = GTK_PANED (widget);
   GtkPanedPrivate *priv = paned->priv;
 
-  if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
+  if (gtk_cairo_should_draw_window (cr, priv->child1_window))
+    {
+      cairo_save (cr);
+      gtk_cairo_transform_to_window (cr, widget, priv->child1_window);
+      gtk_render_background (gtk_widget_get_style_context (widget),
+                             cr,
+                             0, 0,
+                             gdk_window_get_width (priv->child1_window),
+                             gdk_window_get_height (priv->child1_window));
+      cairo_restore (cr);
+    }
+
+  if (gtk_cairo_should_draw_window (cr, priv->child2_window))
+    {
+      cairo_save (cr);
+      gtk_cairo_transform_to_window (cr, widget, priv->child2_window);
+      gtk_render_background (gtk_widget_get_style_context (widget),
+                             cr,
+                             0, 0,
+                             gdk_window_get_width (priv->child2_window),
+                             gdk_window_get_height (priv->child2_window));
+      cairo_restore (cr);
+    }
+
+  if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)) &&
       priv->child1 && gtk_widget_get_visible (priv->child1) &&
       priv->child2 && gtk_widget_get_visible (priv->child2))
     {
@@ -1213,6 +1491,7 @@ gtk_paned_draw (GtkWidget *widget,
 
       gtk_style_context_save (context);
       gtk_style_context_set_state (context, state);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
       gtk_render_handle (context, cr,
                          priv->handle_pos.x - allocation.x,
                          priv->handle_pos.y - allocation.y,
@@ -1243,7 +1522,10 @@ is_rtl (GtkPaned *paned)
 }
 
 static void
-update_drag (GtkPaned *paned)
+update_drag (GtkPaned         *paned,
+             /* relative to priv->handle */
+             int               xpos,
+             int               ypos)
 {
   GtkPanedPrivate *priv = paned->priv;
   GtkAllocation allocation;
@@ -1251,11 +1533,18 @@ update_drag (GtkPaned *paned)
   gint pos;
   gint handle_size;
   gint size;
+  gint x, y;
 
+  gdk_window_get_position (priv->handle, &x, &y);
+  gtk_widget_get_allocation (widget, &allocation);
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-    gtk_widget_get_pointer (widget, &pos, NULL);
+    {
+      pos = xpos + x - allocation.x;
+    }
   else
-    gtk_widget_get_pointer (widget, NULL, &pos);
+    {
+      pos = ypos + y - allocation.y;
+    }
 
   pos -= priv->drag_pos;
 
@@ -1265,7 +1554,6 @@ update_drag (GtkPaned *paned)
                            "handle-size", &handle_size,
                            NULL);
 
-      gtk_widget_get_allocation (widget, &allocation);
       size = allocation.width - pos - handle_size;
     }
   else
@@ -1287,7 +1575,7 @@ gtk_paned_enter (GtkWidget        *widget,
   GtkPanedPrivate *priv = paned->priv;
 
   if (priv->in_drag)
-    update_drag (paned);
+    update_drag (paned, event->x, event->y);
   else
     {
       priv->handle_prelit = TRUE;
@@ -1309,7 +1597,7 @@ gtk_paned_leave (GtkWidget        *widget,
   GtkPanedPrivate *priv = paned->priv;
 
   if (priv->in_drag)
-    update_drag (paned);
+    update_drag (paned, event->x, event->y);
   else
     {
       priv->handle_prelit = FALSE;
@@ -1349,15 +1637,14 @@ gtk_paned_button_press (GtkWidget      *widget,
   GtkPanedPrivate *priv = paned->priv;
 
   if (!priv->in_drag &&
-      (event->window == priv->handle) && (event->button == 1))
+      (event->window == priv->handle) && (event->button == GDK_BUTTON_PRIMARY))
     {
       /* We need a server grab here, not gtk_grab_add(), since
        * we don't want to pass events on to the widget's children */
       if (gdk_device_grab (event->device,
                            priv->handle,
                            GDK_OWNERSHIP_WINDOW, FALSE,
-                           GDK_POINTER_MOTION_HINT_MASK
-                           | GDK_BUTTON1_MOTION_MASK
+                           GDK_BUTTON1_MOTION_MASK
                            | GDK_BUTTON_RELEASE_MASK
                            | GDK_ENTER_NOTIFY_MASK
                            | GDK_LEAVE_NOTIFY_MASK,
@@ -1452,7 +1739,7 @@ gtk_paned_button_release (GtkWidget      *widget,
   GtkPaned *paned = GTK_PANED (widget);
   GtkPanedPrivate *priv = paned->priv;
 
-  if (priv->in_drag && (event->button == 1))
+  if (priv->in_drag && (event->button == GDK_BUTTON_PRIMARY))
     {
       stop_drag (paned);
 
@@ -1471,7 +1758,7 @@ gtk_paned_motion (GtkWidget      *widget,
 
   if (priv->in_drag)
     {
-      update_drag (paned);
+      update_drag (paned, event->x, event->y);
       return TRUE;
     }
   
@@ -1556,6 +1843,7 @@ gtk_paned_pack1 (GtkPaned  *paned,
       priv->child1_resize = resize;
       priv->child1_shrink = shrink;
 
+      gtk_widget_set_parent_window (child, priv->child1_window);
       gtk_widget_set_parent (child, GTK_WIDGET (paned));
     }
 }
@@ -1588,6 +1876,7 @@ gtk_paned_pack2 (GtkPaned  *paned,
       priv->child2_resize = resize;
       priv->child2_shrink = shrink;
 
+      gtk_widget_set_parent_window (child, priv->child2_window);
       gtk_widget_set_parent (child, GTK_WIDGET (paned));
     }
 }
@@ -1625,6 +1914,9 @@ gtk_paned_remove (GtkContainer *container,
 
   if (priv->child1 == widget)
     {
+      if (priv->child1_window && gdk_window_is_visible (priv->child1_window))
+        gdk_window_hide (priv->child1_window);
+
       gtk_widget_unparent (widget);
 
       priv->child1 = NULL;
@@ -1634,6 +1926,9 @@ gtk_paned_remove (GtkContainer *container,
     }
   else if (priv->child2 == widget)
     {
+      if (priv->child2_window && gdk_window_is_visible (priv->child2_window))
+        gdk_window_hide (priv->child2_window);
+
       gtk_widget_unparent (widget);
 
       priv->child2 = NULL;
@@ -1824,10 +2119,10 @@ gtk_paned_calc_position (GtkPaned *paned,
                              priv->max_position);
 
   if (priv->child1)
-    gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0);
+    gtk_paned_set_child_visible (paned, 0, priv->child1_size != 0);
   
   if (priv->child2)
-    gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation); 
+    gtk_paned_set_child_visible (paned, 1, priv->child1_size != allocation); 
 
   g_object_freeze_notify (G_OBJECT (paned));
   if (priv->child1_size != old_position)