]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkhandlebox.c
dnd-quartz: gtk_widget_render_icon() => gtk_widget_render_icon_pixbuf()
[~andy/gtk] / gtk / gtkhandlebox.c
index 22ec0539439370dade25f8e3178d31af8cca2c7c..1e02e84f87a7f93e6df6da9b282bac31ca7d6dd7 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include "config.h"
 #include <stdlib.h>
 #include "gtkhandlebox.h"
+#include "gtkinvisible.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
-#include "gtksignal.h"
 #include "gtkwindow.h"
+#include "gtkprivate.h"
 #include "gtkintl.h"
 
+
+
+struct _GtkHandleBoxPrivate
+{
+  /* Properties */
+  GtkPositionType handle_position;
+  GtkPositionType snap_edge;
+  GtkShadowType   shadow_type;
+  gboolean        child_detached;
+  /* Properties */
+
+  GtkAllocation   attach_allocation;
+  GtkAllocation   float_allocation;
+
+  GdkDevice      *grab_device;
+
+  GdkWindow      *bin_window;     /* parent window for children */
+  GdkWindow      *float_window;
+
+  /* Variables used during a drag
+   */
+  gint            orig_x;
+  gint            orig_y;
+
+  guint           float_window_mapped : 1;
+  guint           in_drag : 1;
+  guint           shrink_on_detach : 1;
+};
+
 enum {
   PROP_0,
-  PROP_SHADOW,
   PROP_SHADOW_TYPE,
   PROP_HANDLE_POSITION,
-  PROP_SNAP_EDGE
+  PROP_SNAP_EDGE,
+  PROP_SNAP_EDGE_SET,
+  PROP_CHILD_DETACHED
 };
 
 #define DRAG_HANDLE_SIZE 10
@@ -92,139 +124,117 @@ enum {
  *          <--------bin_window-------------------->
  */
 
-static void gtk_handle_box_class_init     (GtkHandleBoxClass *klass);
-static void gtk_handle_box_init           (GtkHandleBox      *handle_box);
-static void gtk_handle_box_set_property   (GObject      *object,
-                                          guint         param_id,
-                                          const GValue *value,
-                                          GParamSpec   *pspec);
-static void gtk_handle_box_get_property   (GObject     *object,
-                                          guint        param_id,
-                                          GValue      *value,
-                                          GParamSpec  *pspec);
-static void gtk_handle_box_destroy        (GtkObject         *object);
-static void gtk_handle_box_map            (GtkWidget         *widget);
-static void gtk_handle_box_unmap          (GtkWidget         *widget);
-static void gtk_handle_box_realize        (GtkWidget         *widget);
-static void gtk_handle_box_unrealize      (GtkWidget         *widget);
-static void gtk_handle_box_style_set      (GtkWidget         *widget,
-                                          GtkStyle          *previous_style);
-static void gtk_handle_box_size_request   (GtkWidget         *widget,
-                                          GtkRequisition    *requisition);
-static void gtk_handle_box_size_allocate  (GtkWidget         *widget,
-                                          GtkAllocation     *real_allocation);
-static void gtk_handle_box_add            (GtkContainer      *container,
-                                          GtkWidget         *widget);
-static void gtk_handle_box_remove         (GtkContainer      *container,
-                                          GtkWidget         *widget);
-static void gtk_handle_box_draw_ghost     (GtkHandleBox      *hb);
-static void gtk_handle_box_paint          (GtkWidget         *widget,
-                                          GdkEventExpose    *event,
-                                          GdkRectangle      *area);
-static gint gtk_handle_box_expose         (GtkWidget         *widget,
-                                          GdkEventExpose    *event);
-static gint gtk_handle_box_button_changed (GtkWidget         *widget,
-                                          GdkEventButton    *event);
-static gint gtk_handle_box_motion         (GtkWidget         *widget,
-                                          GdkEventMotion    *event);
-static gint gtk_handle_box_delete_event   (GtkWidget         *widget,
-                                          GdkEventAny       *event);
-static void gtk_handle_box_reattach       (GtkHandleBox      *hb);
-
-
-static GtkBinClass *parent_class;
-static guint        handle_box_signals[SIGNAL_LAST] = { 0 };
-
-
-GtkType
-gtk_handle_box_get_type (void)
-{
-  static GtkType handle_box_type = 0;
-
-  if (!handle_box_type)
-    {
-      static const GtkTypeInfo handle_box_info =
-      {
-       "GtkHandleBox",
-       sizeof (GtkHandleBox),
-       sizeof (GtkHandleBoxClass),
-       (GtkClassInitFunc) gtk_handle_box_class_init,
-       (GtkObjectInitFunc) gtk_handle_box_init,
-       /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
-      };
-
-      handle_box_type = gtk_type_unique (GTK_TYPE_BIN, &handle_box_info);
-    }
-
-  return handle_box_type;
-}
+static void     gtk_handle_box_set_property  (GObject        *object,
+                                              guint           param_id,
+                                              const GValue   *value,
+                                              GParamSpec     *pspec);
+static void     gtk_handle_box_get_property  (GObject        *object,
+                                              guint           param_id,
+                                              GValue         *value,
+                                              GParamSpec     *pspec);
+static void     gtk_handle_box_map           (GtkWidget      *widget);
+static void     gtk_handle_box_unmap         (GtkWidget      *widget);
+static void     gtk_handle_box_realize       (GtkWidget      *widget);
+static void     gtk_handle_box_unrealize     (GtkWidget      *widget);
+static void     gtk_handle_box_style_set     (GtkWidget      *widget,
+                                              GtkStyle       *previous_style);
+static void     gtk_handle_box_size_request  (GtkWidget      *widget,
+                                              GtkRequisition *requisition);
+static void     gtk_handle_box_get_preferred_width (GtkWidget *widget,
+                                                   gint      *minimum,
+                                                   gint      *natural);
+static void     gtk_handle_box_get_preferred_height (GtkWidget *widget,
+                                                   gint      *minimum,
+                                                   gint      *natural);
+static void     gtk_handle_box_size_allocate (GtkWidget      *widget,
+                                              GtkAllocation  *real_allocation);
+static void     gtk_handle_box_add           (GtkContainer   *container,
+                                              GtkWidget      *widget);
+static void     gtk_handle_box_remove        (GtkContainer   *container,
+                                              GtkWidget      *widget);
+static gboolean gtk_handle_box_draw          (GtkWidget      *widget,
+                                              cairo_t        *cr);
+static gboolean gtk_handle_box_button_press  (GtkWidget      *widget,
+                                              GdkEventButton *event);
+static gboolean gtk_handle_box_motion        (GtkWidget      *widget,
+                                              GdkEventMotion *event);
+static gboolean gtk_handle_box_delete_event  (GtkWidget      *widget,
+                                              GdkEventAny    *event);
+static void     gtk_handle_box_reattach      (GtkHandleBox   *hb);
+static void     gtk_handle_box_end_drag      (GtkHandleBox   *hb,
+                                              guint32         time);
+
+static guint handle_box_signals[SIGNAL_LAST] = { 0 };
+
+G_DEFINE_TYPE (GtkHandleBox, gtk_handle_box, GTK_TYPE_BIN)
 
 static void
 gtk_handle_box_class_init (GtkHandleBoxClass *class)
 {
   GObjectClass *gobject_class;
-  GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
   GtkContainerClass *container_class;
 
   gobject_class = (GObjectClass *) class;
-  object_class = (GtkObjectClass *) class;
   widget_class = (GtkWidgetClass *) class;
   container_class = (GtkContainerClass *) class;
 
-  parent_class = gtk_type_class (GTK_TYPE_BIN);
-
   gobject_class->set_property = gtk_handle_box_set_property;
   gobject_class->get_property = gtk_handle_box_get_property;
   
-  g_object_class_install_property (gobject_class,
-                                   PROP_SHADOW,
-                                   g_param_spec_enum ("shadow", NULL,
-                                                      _("Deprecated property, use shadow_type instead"),
-                                                     GTK_TYPE_SHADOW_TYPE,
-                                                     GTK_SHADOW_ETCHED_OUT,
-                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
   g_object_class_install_property (gobject_class,
                                    PROP_SHADOW_TYPE,
-                                   g_param_spec_enum ("shadow_type",
-                                                      _("Shadow type"),
-                                                      _("Appearance of the shadow that surrounds the container"),
+                                   g_param_spec_enum ("shadow-type",
+                                                      P_("Shadow type"),
+                                                      P_("Appearance of the shadow that surrounds the container"),
                                                      GTK_TYPE_SHADOW_TYPE,
-                                                     GTK_SHADOW_ETCHED_OUT,
-                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                     GTK_SHADOW_OUT,
+                                                      GTK_PARAM_READWRITE));
   
   g_object_class_install_property (gobject_class,
                                    PROP_HANDLE_POSITION,
-                                   g_param_spec_enum ("handle_position",
-                                                      _("Handle position"),
-                                                      _("Position of the handle relative to the child widget"),
+                                   g_param_spec_enum ("handle-position",
+                                                      P_("Handle position"),
+                                                      P_("Position of the handle relative to the child widget"),
                                                      GTK_TYPE_POSITION_TYPE,
                                                      GTK_POS_LEFT,
-                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                      GTK_PARAM_READWRITE));
   
   g_object_class_install_property (gobject_class,
                                    PROP_SNAP_EDGE,
-                                   g_param_spec_enum ("snap_edge",
-                                                      _("Snap edge"),
-                                                      _("Side of the handlebox that's lined up with the docking point to dock the handlebox"),
+                                   g_param_spec_enum ("snap-edge",
+                                                      P_("Snap edge"),
+                                                      P_("Side of the handlebox that's lined up with the docking point to dock the handlebox"),
                                                      GTK_TYPE_POSITION_TYPE,
                                                      GTK_POS_TOP,
-                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
-  object_class->destroy = gtk_handle_box_destroy;
+                                                      GTK_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_SNAP_EDGE_SET,
+                                   g_param_spec_boolean ("snap-edge-set",
+                                                        P_("Snap edge set"),
+                                                        P_("Whether to use the value from the snap_edge property or a value derived from handle_position"),
+                                                        FALSE,
+                                                        GTK_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_CHILD_DETACHED,
+                                   g_param_spec_boolean ("child-detached",
+                                                        P_("Child Detached"),
+                                                        P_("A boolean value indicating whether the handlebox's child is attached or detached."),
+                                                        FALSE,
+                                                        GTK_PARAM_READABLE));
 
   widget_class->map = gtk_handle_box_map;
   widget_class->unmap = gtk_handle_box_unmap;
   widget_class->realize = gtk_handle_box_realize;
   widget_class->unrealize = gtk_handle_box_unrealize;
   widget_class->style_set = gtk_handle_box_style_set;
-  widget_class->size_request = gtk_handle_box_size_request;
+  widget_class->get_preferred_width = gtk_handle_box_get_preferred_width;
+  widget_class->get_preferred_height = gtk_handle_box_get_preferred_height;
   widget_class->size_allocate = gtk_handle_box_size_allocate;
-  widget_class->expose_event = gtk_handle_box_expose;
-  widget_class->button_press_event = gtk_handle_box_button_changed;
-  widget_class->button_release_event = gtk_handle_box_button_changed;
-  widget_class->motion_notify_event = gtk_handle_box_motion;
+  widget_class->draw = gtk_handle_box_draw;
+  widget_class->button_press_event = gtk_handle_box_button_press;
   widget_class->delete_event = gtk_handle_box_delete_event;
 
   container_class->add = gtk_handle_box_add;
@@ -234,37 +244,48 @@ gtk_handle_box_class_init (GtkHandleBoxClass *class)
   class->child_detached = NULL;
 
   handle_box_signals[SIGNAL_CHILD_ATTACHED] =
-    gtk_signal_new ("child_attached",
-                   GTK_RUN_FIRST,
-                   GTK_CLASS_TYPE (object_class),
-                   GTK_SIGNAL_OFFSET (GtkHandleBoxClass, child_attached),
-                   _gtk_marshal_VOID__OBJECT,
-                   GTK_TYPE_NONE, 1,
-                   GTK_TYPE_WIDGET);
+    g_signal_new (I_("child-attached"),
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_FIRST,
+                 G_STRUCT_OFFSET (GtkHandleBoxClass, child_attached),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__OBJECT,
+                 G_TYPE_NONE, 1,
+                 GTK_TYPE_WIDGET);
   handle_box_signals[SIGNAL_CHILD_DETACHED] =
-    gtk_signal_new ("child_detached",
-                   GTK_RUN_FIRST,
-                   GTK_CLASS_TYPE (object_class),
-                   GTK_SIGNAL_OFFSET (GtkHandleBoxClass, child_detached),
-                   _gtk_marshal_VOID__OBJECT,
-                   GTK_TYPE_NONE, 1,
-                   GTK_TYPE_WIDGET);
+    g_signal_new (I_("child-detached"),
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_FIRST,
+                 G_STRUCT_OFFSET (GtkHandleBoxClass, child_detached),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__OBJECT,
+                 G_TYPE_NONE, 1,
+                 GTK_TYPE_WIDGET);
+
+  g_type_class_add_private (gobject_class, sizeof (GtkHandleBoxPrivate));
 }
 
 static void
 gtk_handle_box_init (GtkHandleBox *handle_box)
 {
-  GTK_WIDGET_UNSET_FLAGS (handle_box, GTK_NO_WINDOW);
-
-  handle_box->bin_window = NULL;
-  handle_box->float_window = NULL;
-  handle_box->shadow_type = GTK_SHADOW_OUT;
-  handle_box->handle_position = GTK_POS_LEFT;
-  handle_box->float_window_mapped = FALSE;
-  handle_box->child_detached = FALSE;
-  handle_box->in_drag = FALSE;
-  handle_box->shrink_on_detach = TRUE;
-  handle_box->snap_edge = -1;
+  GtkHandleBoxPrivate *priv;
+
+  handle_box->priv = G_TYPE_INSTANCE_GET_PRIVATE (handle_box,
+                                                  GTK_TYPE_HANDLE_BOX,
+                                                  GtkHandleBoxPrivate);
+  priv = handle_box->priv;
+
+  gtk_widget_set_has_window (GTK_WIDGET (handle_box), TRUE);
+
+  priv->bin_window = NULL;
+  priv->float_window = NULL;
+  priv->shadow_type = GTK_SHADOW_OUT;
+  priv->handle_position = GTK_POS_LEFT;
+  priv->float_window_mapped = FALSE;
+  priv->child_detached = FALSE;
+  priv->in_drag = FALSE;
+  priv->shrink_on_detach = TRUE;
+  priv->snap_edge = -1;
 }
 
 static void 
@@ -277,7 +298,6 @@ gtk_handle_box_set_property (GObject         *object,
 
   switch (prop_id)
     {
-    case PROP_SHADOW:
     case PROP_SHADOW_TYPE:
       gtk_handle_box_set_shadow_type (handle_box, g_value_get_enum (value));
       break;
@@ -287,6 +307,10 @@ gtk_handle_box_set_property (GObject         *object,
     case PROP_SNAP_EDGE:
       gtk_handle_box_set_snap_edge (handle_box, g_value_get_enum (value));
       break;
+    case PROP_SNAP_EDGE_SET:
+      if (!g_value_get_boolean (value))
+       gtk_handle_box_set_snap_edge (handle_box, (GtkPositionType)-1);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -300,18 +324,26 @@ gtk_handle_box_get_property (GObject         *object,
                             GParamSpec      *pspec)
 {
   GtkHandleBox *handle_box = GTK_HANDLE_BOX (object);
-  
+  GtkHandleBoxPrivate *priv = handle_box->priv;
+
   switch (prop_id)
     {
-    case PROP_SHADOW:
     case PROP_SHADOW_TYPE:
-      g_value_set_enum (value, handle_box->shadow_type);
+      g_value_set_enum (value, priv->shadow_type);
       break;
     case PROP_HANDLE_POSITION:
-      g_value_set_enum (value, handle_box->handle_position);
+      g_value_set_enum (value, priv->handle_position);
       break;
     case PROP_SNAP_EDGE:
-      g_value_set_enum (value, handle_box->snap_edge);
+      g_value_set_enum (value,
+                       (priv->snap_edge == -1 ?
+                        GTK_POS_TOP : priv->snap_edge));
+      break;
+    case PROP_SNAP_EDGE_SET:
+      g_value_set_boolean (value, priv->snap_edge != -1);
+      break;
+    case PROP_CHILD_DETACHED:
+      g_value_set_boolean (value, priv->child_detached);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -322,88 +354,89 @@ gtk_handle_box_get_property (GObject         *object,
 GtkWidget*
 gtk_handle_box_new (void)
 {
-  return GTK_WIDGET (gtk_type_new (gtk_handle_box_get_type ()));
-}
-
-static void
-gtk_handle_box_destroy (GtkObject *object)
-{
-  if (GTK_OBJECT_CLASS (parent_class)->destroy)
-    (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+  return g_object_new (GTK_TYPE_HANDLE_BOX, NULL);
 }
 
 static void
 gtk_handle_box_map (GtkWidget *widget)
 {
-  GtkBin *bin;
-  GtkHandleBox *hb;
-
-  GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
+  GtkBin *bin = GTK_BIN (widget);
+  GtkWidget *child;
 
-  bin = GTK_BIN (widget);
-  hb = GTK_HANDLE_BOX (widget);
+  gtk_widget_set_mapped (widget, TRUE);
 
-  if (bin->child &&
-      GTK_WIDGET_VISIBLE (bin->child) &&
-      !GTK_WIDGET_MAPPED (bin->child))
-    gtk_widget_map (bin->child);
+  child = gtk_bin_get_child (bin);
+  if (child != NULL &&
+      gtk_widget_get_visible (child) &&
+      !gtk_widget_get_mapped (child))
+    gtk_widget_map (child);
 
-  if (hb->child_detached && !hb->float_window_mapped)
+  if (priv->child_detached && !priv->float_window_mapped)
     {
-      gdk_window_show (hb->float_window);
-      hb->float_window_mapped = TRUE;
+      gdk_window_show (priv->float_window);
+      priv->float_window_mapped = TRUE;
     }
 
-  gdk_window_show (hb->bin_window);
-  gdk_window_show (widget->window);
+  gdk_window_show (priv->bin_window);
+  gdk_window_show (gtk_widget_get_window (widget));
 }
 
 static void
 gtk_handle_box_unmap (GtkWidget *widget)
 {
-  GtkHandleBox *hb;
-
-  GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
 
-  hb = GTK_HANDLE_BOX (widget);
+  gtk_widget_set_mapped (widget, FALSE);
 
-  gdk_window_hide (widget->window);
-  if (hb->float_window_mapped)
+  gdk_window_hide (gtk_widget_get_window (widget));
+  if (priv->float_window_mapped)
     {
-      gdk_window_hide (hb->float_window);
-      hb->float_window_mapped = FALSE;
+      gdk_window_hide (priv->float_window);
+      priv->float_window_mapped = FALSE;
     }
 }
 
 static void
 gtk_handle_box_realize (GtkWidget *widget)
 {
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
+  GtkAllocation allocation;
+  GtkRequisition requisition;
+  GtkStateType state;
+  GtkStyle *style;
+  GtkWidget *child;
+  GdkWindow *window;
   GdkWindowAttr attributes;
   gint attributes_mask;
-  GtkHandleBox *hb;
 
-  hb = GTK_HANDLE_BOX (widget);
+  gtk_widget_set_realized (widget, TRUE);
 
-  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+  gtk_widget_get_allocation (widget, &allocation);
 
-  attributes.x = widget->allocation.x;
-  attributes.y = widget->allocation.y;
-  attributes.width = widget->allocation.width;
-  attributes.height = widget->allocation.height;
+  attributes.x = allocation.x;
+  attributes.y = allocation.y;
+  attributes.width = allocation.width;
+  attributes.height = allocation.height;
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.wclass = GDK_INPUT_OUTPUT;
   attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
   attributes.event_mask = (gtk_widget_get_events (widget)
                           | GDK_EXPOSURE_MASK);
-  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);
+  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+  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);
 
   attributes.x = 0;
   attributes.y = 0;
-  attributes.width = widget->allocation.width;
-  attributes.height = widget->allocation.height;
+  attributes.width = allocation.width;
+  attributes.height = allocation.height;
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.event_mask = (gtk_widget_get_events (widget) |
                           GDK_EXPOSURE_MASK |
@@ -411,54 +444,61 @@ gtk_handle_box_realize (GtkWidget *widget)
                           GDK_POINTER_MOTION_HINT_MASK |
                           GDK_BUTTON_PRESS_MASK |
                            GDK_BUTTON_RELEASE_MASK);
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-  hb->bin_window = gdk_window_new (widget->window, &attributes, attributes_mask);
-  gdk_window_set_user_data (hb->bin_window, widget);
-  if (GTK_BIN (hb)->child)
-    gtk_widget_set_parent_window (GTK_BIN (hb)->child, hb->bin_window);
+  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+  priv->bin_window = gdk_window_new (window,
+                                     &attributes, attributes_mask);
+  gdk_window_set_user_data (priv->bin_window, widget);
+
+  child = gtk_bin_get_child (GTK_BIN (hb));
+  if (child)
+    gtk_widget_set_parent_window (child, priv->bin_window);
   
+  gtk_widget_get_preferred_size (widget, &requisition, NULL);
+
   attributes.x = 0;
   attributes.y = 0;
-  attributes.width = widget->requisition.width;
-  attributes.height = widget->requisition.height;
+  attributes.width = requisition.width;
+  attributes.height = requisition.height;
   attributes.window_type = GDK_WINDOW_TOPLEVEL;
   attributes.wclass = GDK_INPUT_OUTPUT;
   attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
   attributes.event_mask = (gtk_widget_get_events (widget) |
                           GDK_KEY_PRESS_MASK |
                           GDK_ENTER_NOTIFY_MASK |
                           GDK_LEAVE_NOTIFY_MASK |
                           GDK_FOCUS_CHANGE_MASK |
                           GDK_STRUCTURE_MASK);
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-  hb->float_window = gdk_window_new (gtk_widget_get_root_window (widget),
+  attributes.type_hint = GDK_WINDOW_TYPE_HINT_TOOLBAR;
+  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_TYPE_HINT;
+  priv->float_window = gdk_window_new (gtk_widget_get_root_window (widget),
                                     &attributes, attributes_mask);
-  gdk_window_set_user_data (hb->float_window, widget);
-  gdk_window_set_decorations (hb->float_window, 0);
-  gdk_window_set_type_hint (hb->float_window, GDK_WINDOW_TYPE_HINT_TOOLBAR);
-  
-  widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, widget->window, GTK_WIDGET_STATE (hb));
-  gtk_style_set_background (widget->style, hb->bin_window, GTK_WIDGET_STATE (hb));
-  gtk_style_set_background (widget->style, hb->float_window, GTK_WIDGET_STATE (hb));
-  gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+  gdk_window_set_user_data (priv->float_window, widget);
+  gdk_window_set_decorations (priv->float_window, 0);
+  gdk_window_set_type_hint (priv->float_window, GDK_WINDOW_TYPE_HINT_TOOLBAR);
+
+  gtk_widget_style_attach (widget);
+  style = gtk_widget_get_style (widget);
+  state = gtk_widget_get_state (widget);
+  gtk_style_set_background (style, window, state);
+  gtk_style_set_background (style, priv->bin_window, state);
+  gtk_style_set_background (style, priv->float_window, state);
 }
 
 static void
 gtk_handle_box_unrealize (GtkWidget *widget)
 {
   GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
 
-  gdk_window_set_user_data (hb->bin_window, NULL);
-  gdk_window_destroy (hb->bin_window);
-  hb->bin_window = NULL;
-  gdk_window_set_user_data (hb->float_window, NULL);
-  gdk_window_destroy (hb->float_window);
-  hb->float_window = NULL;
+  gdk_window_set_user_data (priv->bin_window, NULL);
+  gdk_window_destroy (priv->bin_window);
+  priv->bin_window = NULL;
+  gdk_window_set_user_data (priv->float_window, NULL);
+  gdk_window_destroy (priv->float_window);
+  priv->float_window = NULL;
 
-  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
-    (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+  GTK_WIDGET_CLASS (gtk_handle_box_parent_class)->unrealize (widget);
 }
 
 static void
@@ -466,30 +506,65 @@ gtk_handle_box_style_set (GtkWidget *widget,
                          GtkStyle  *previous_style)
 {
   GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
+
+  if (gtk_widget_get_realized (widget) &&
+      gtk_widget_get_has_window (widget))
+    {
+      GtkStateType state;
+      GtkStyle *style;
+
+      style = gtk_widget_get_style (widget);
+      state = gtk_widget_get_state (widget);
+
+      gtk_style_set_background (style, gtk_widget_get_window (widget), state);
+      gtk_style_set_background (style, priv->bin_window, state);
+      gtk_style_set_background (style, priv->float_window, state);
+    }
+}
+
+static int
+effective_handle_position (GtkHandleBox *hb)
+{
+  GtkHandleBoxPrivate *priv = hb->priv;
+  int handle_position;
 
-  if (GTK_WIDGET_REALIZED (widget) &&
-      !GTK_WIDGET_NO_WINDOW (widget))
+  if (gtk_widget_get_direction (GTK_WIDGET (hb)) == GTK_TEXT_DIR_LTR)
+    handle_position = priv->handle_position;
+  else
     {
-      gtk_style_set_background (widget->style, widget->window,
-                               widget->state);
-      gtk_style_set_background (widget->style, hb->bin_window, widget->state);
-      gtk_style_set_background (widget->style, hb->float_window, widget->state);
+      switch (priv->handle_position)
+       {
+       case GTK_POS_LEFT:
+         handle_position = GTK_POS_RIGHT;
+         break;
+       case GTK_POS_RIGHT:
+         handle_position = GTK_POS_LEFT;
+         break;
+       default:
+         handle_position = priv->handle_position;
+         break;
+       }
     }
+
+  return handle_position;
 }
 
 static void
 gtk_handle_box_size_request (GtkWidget      *widget,
                             GtkRequisition *requisition)
 {
-  GtkBin *bin;
-  GtkHandleBox *hb;
+  GtkBin *bin = GTK_BIN (widget);
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
   GtkRequisition child_requisition;
+  GtkWidget *child;
+  gint handle_position;
 
-  bin = GTK_BIN (widget);
-  hb = GTK_HANDLE_BOX (widget);
+  handle_position = effective_handle_position (hb);
 
-  if (hb->handle_position == GTK_POS_LEFT ||
-      hb->handle_position == GTK_POS_RIGHT)
+  if (handle_position == GTK_POS_LEFT ||
+      handle_position == GTK_POS_RIGHT)
     {
       requisition->width = DRAG_HANDLE_SIZE;
       requisition->height = 0;
@@ -500,43 +575,49 @@ gtk_handle_box_size_request (GtkWidget      *widget,
       requisition->height = DRAG_HANDLE_SIZE;
     }
 
+  child = gtk_bin_get_child (bin);
   /* if our child is not visible, we still request its size, since we
-   * won't have any usefull hint for our size otherwise.
+   * won't have any useful hint for our size otherwise.
    */
-  if (bin->child)
-    gtk_widget_size_request (bin->child, &child_requisition);
+  if (child)
+    {
+      gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+    }
   else
     {
       child_requisition.width = 0;
       child_requisition.height = 0;
     }      
 
-  if (hb->child_detached)
+  if (priv->child_detached)
     {
       /* FIXME: This doesn't work currently */
-      if (!hb->shrink_on_detach)
+      if (!priv->shrink_on_detach)
        {
-         if (hb->handle_position == GTK_POS_LEFT ||
-             hb->handle_position == GTK_POS_RIGHT)
+         if (handle_position == GTK_POS_LEFT ||
+             handle_position == GTK_POS_RIGHT)
            requisition->height += child_requisition.height;
          else
            requisition->width += child_requisition.width;
        }
       else
        {
-         if (hb->handle_position == GTK_POS_LEFT ||
-             hb->handle_position == GTK_POS_RIGHT)
-           requisition->height += widget->style->ythickness;
+         if (handle_position == GTK_POS_LEFT ||
+             handle_position == GTK_POS_RIGHT)
+           requisition->height += gtk_widget_get_style (widget)->ythickness;
          else
-           requisition->width += widget->style->xthickness;
+           requisition->width += gtk_widget_get_style (widget)->xthickness;
        }
     }
   else
     {
-      requisition->width += GTK_CONTAINER (widget)->border_width * 2;
-      requisition->height += GTK_CONTAINER (widget)->border_width * 2;
+      guint border_width;
+
+      border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+      requisition->width += border_width * 2;
+      requisition->height += border_width * 2;
       
-      if (bin->child)
+      if (child)
        {
          requisition->width += child_requisition.width;
          requisition->height += child_requisition.height;
@@ -549,52 +630,78 @@ gtk_handle_box_size_request (GtkWidget      *widget,
     }
 }
 
+static void
+gtk_handle_box_get_preferred_width (GtkWidget *widget,
+                                    gint      *minimum,
+                                    gint      *natural)
+{
+  GtkRequisition requisition;
+
+  gtk_handle_box_size_request (widget, &requisition);
+
+  *minimum = *natural = requisition.width;
+}
+
+static void
+gtk_handle_box_get_preferred_height (GtkWidget *widget,
+                                    gint      *minimum,
+                                    gint      *natural)
+{
+  GtkRequisition requisition;
+
+  gtk_handle_box_size_request (widget, &requisition);
+
+  *minimum = *natural = requisition.height;
+}
+
+
 static void
 gtk_handle_box_size_allocate (GtkWidget     *widget,
                              GtkAllocation *allocation)
 {
-  GtkBin *bin;
-  GtkHandleBox *hb;
+  GtkBin *bin = GTK_BIN (widget);
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
   GtkRequisition child_requisition;
-  
-  bin = GTK_BIN (widget);
-  hb = GTK_HANDLE_BOX (widget);
-  
-  if (bin->child)
-    gtk_widget_get_child_requisition (bin->child, &child_requisition);
+  GtkWidget *child;
+  gint handle_position;
+
+  handle_position = effective_handle_position (hb);
+
+  child = gtk_bin_get_child (bin);
+
+  if (child)
+    {
+      gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+    }
   else
     {
       child_requisition.width = 0;
       child_requisition.height = 0;
-    }      
-      
-  widget->allocation = *allocation;
+    }
 
-  if (GTK_WIDGET_REALIZED (hb))
-    gdk_window_move_resize (widget->window,
-                           widget->allocation.x,
-                           widget->allocation.y,
-                           widget->allocation.width,
-                           widget->allocation.height);
+  gtk_widget_set_allocation (widget, allocation);
 
+  if (gtk_widget_get_realized (widget))
+    gdk_window_move_resize (gtk_widget_get_window (widget),
+                            allocation->x, allocation->y,
+                            allocation->width, allocation->height);
 
-  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+  if (child != NULL && gtk_widget_get_visible (child))
     {
-      GtkWidget *child;
       GtkAllocation child_allocation;
       guint border_width;
 
-      child = bin->child;
-      border_width = GTK_CONTAINER (widget)->border_width;
+      border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
 
       child_allocation.x = border_width;
       child_allocation.y = border_width;
-      if (hb->handle_position == GTK_POS_LEFT)
+      if (handle_position == GTK_POS_LEFT)
        child_allocation.x += DRAG_HANDLE_SIZE;
-      else if (hb->handle_position == GTK_POS_TOP)
+      else if (handle_position == GTK_POS_TOP)
        child_allocation.y += DRAG_HANDLE_SIZE;
 
-      if (hb->child_detached)
+      if (priv->child_detached)
        {
          guint float_width;
          guint float_height;
@@ -605,18 +712,18 @@ gtk_handle_box_size_allocate (GtkWidget     *widget,
          float_width = child_allocation.width + 2 * border_width;
          float_height = child_allocation.height + 2 * border_width;
          
-         if (hb->handle_position == GTK_POS_LEFT ||
-             hb->handle_position == GTK_POS_RIGHT)
+         if (handle_position == GTK_POS_LEFT ||
+             handle_position == GTK_POS_RIGHT)
            float_width += DRAG_HANDLE_SIZE;
          else
            float_height += DRAG_HANDLE_SIZE;
 
-         if (GTK_WIDGET_REALIZED (hb))
+         if (gtk_widget_get_realized (widget))
            {
-             gdk_window_resize (hb->float_window,
+             gdk_window_resize (priv->float_window,
                                 float_width,
                                 float_height);
-             gdk_window_move_resize (hb->bin_window,
+             gdk_window_move_resize (priv->bin_window,
                                      0,
                                      0,
                                      float_width,
@@ -625,101 +732,109 @@ gtk_handle_box_size_allocate (GtkWidget     *widget,
        }
       else
        {
-         child_allocation.width = MAX (1, (gint)widget->allocation.width - 2 * border_width);
-         child_allocation.height = MAX (1, (gint)widget->allocation.height - 2 * border_width);
+         child_allocation.width = MAX (1, (gint) allocation->width - 2 * border_width);
+         child_allocation.height = MAX (1, (gint) allocation->height - 2 * border_width);
 
-         if (hb->handle_position == GTK_POS_LEFT ||
-             hb->handle_position == GTK_POS_RIGHT)
+         if (handle_position == GTK_POS_LEFT ||
+             handle_position == GTK_POS_RIGHT)
            child_allocation.width -= DRAG_HANDLE_SIZE;
          else
            child_allocation.height -= DRAG_HANDLE_SIZE;
          
-         if (GTK_WIDGET_REALIZED (hb))
-           gdk_window_move_resize (hb->bin_window,
+         if (gtk_widget_get_realized (widget))
+           gdk_window_move_resize (priv->bin_window,
                                    0,
                                    0,
-                                   widget->allocation.width,
-                                   widget->allocation.height);
+                                   allocation->width,
+                                   allocation->height);
        }
 
-      gtk_widget_size_allocate (bin->child, &child_allocation);
+      gtk_widget_size_allocate (child, &child_allocation);
     }
 }
 
 static void
-gtk_handle_box_draw_ghost (GtkHandleBox *hb)
+gtk_handle_box_draw_ghost (GtkHandleBox *hb,
+                           cairo_t      *cr)
 {
-  GtkWidget *widget;
+  GtkWidget *widget = GTK_WIDGET (hb);
+  GtkStateType state;
+  GtkStyle *style;
+  GdkWindow *window;
   guint x;
   guint y;
   guint width;
   guint height;
+  gint allocation_width;
+  gint allocation_height;
+  gint handle_position;
 
-  widget = GTK_WIDGET (hb);
+  handle_position = effective_handle_position (hb);
+  allocation_width = gtk_widget_get_allocated_width (widget);
+  allocation_height = gtk_widget_get_allocated_height (widget);
 
-  if (hb->handle_position == GTK_POS_LEFT ||
-      hb->handle_position == GTK_POS_RIGHT)
+  if (handle_position == GTK_POS_LEFT ||
+      handle_position == GTK_POS_RIGHT)
     {
-      x = hb->handle_position == GTK_POS_LEFT ? 0 : widget->allocation.width - DRAG_HANDLE_SIZE;
+      x = handle_position == GTK_POS_LEFT ? 0 : allocation_width - DRAG_HANDLE_SIZE;
       y = 0;
       width = DRAG_HANDLE_SIZE;
-      height = widget->allocation.height;
+      height = allocation_height;
     }
   else
     {
       x = 0;
-      y = hb->handle_position == GTK_POS_TOP ? 0 : widget->allocation.height - DRAG_HANDLE_SIZE;
-      width = widget->allocation.width;
+      y = handle_position == GTK_POS_TOP ? 0 : allocation_height - DRAG_HANDLE_SIZE;
+      width = allocation_width;
       height = DRAG_HANDLE_SIZE;
     }
-  gtk_paint_shadow (widget->style,
-                   widget->window,
-                   GTK_WIDGET_STATE (widget),
+
+  style = gtk_widget_get_style (widget);
+  window = gtk_widget_get_window (widget);
+  state = gtk_widget_get_state (widget);
+
+  gtk_paint_shadow (style,
+                   cr,
+                   state,
                    GTK_SHADOW_ETCHED_IN,
-                   NULL, widget, "handle",
+                   widget, "handle",
                    x,
                    y,
                    width,
                    height);
-   if (hb->handle_position == GTK_POS_LEFT ||
-       hb->handle_position == GTK_POS_RIGHT)
-     gtk_paint_hline (widget->style,
-                     widget->window,
-                     GTK_WIDGET_STATE (widget),
-                     NULL, widget, "handlebox",
-                     hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
-                     hb->handle_position == GTK_POS_LEFT ? widget->allocation.width : widget->allocation.width - DRAG_HANDLE_SIZE,
-                     widget->allocation.height / 2);
+   if (handle_position == GTK_POS_LEFT ||
+       handle_position == GTK_POS_RIGHT)
+     gtk_paint_hline (style,
+                     cr,
+                     state,
+                     widget, "handlebox",
+                     handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
+                     handle_position == GTK_POS_LEFT ? allocation_width : allocation_width - DRAG_HANDLE_SIZE,
+                     allocation_height / 2);
    else
-     gtk_paint_vline (widget->style,
-                     widget->window,
-                     GTK_WIDGET_STATE (widget),
-                     NULL, widget, "handlebox",
-                     hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
-                     hb->handle_position == GTK_POS_TOP ? widget->allocation.height : widget->allocation.height - DRAG_HANDLE_SIZE,
-                     widget->allocation.width / 2);
-}
-
-static void
-draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow,
-                    GdkRectangle *clip)
-{
-   gtk_paint_handle (widget->style, window, GTK_STATE_NORMAL, shadow,
-                    clip, widget, "handlebox",
-                    rect->x, rect->y, rect->width, rect->height, 
-                    GTK_ORIENTATION_VERTICAL);
+     gtk_paint_vline (style,
+                     cr,
+                     state,
+                     widget, "handlebox",
+                     handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
+                     handle_position == GTK_POS_TOP ? allocation_height : allocation_height - DRAG_HANDLE_SIZE,
+                     allocation_width / 2);
 }
 
 void
 gtk_handle_box_set_shadow_type (GtkHandleBox  *handle_box,
                                GtkShadowType  type)
 {
+  GtkHandleBoxPrivate *priv;
+
   g_return_if_fail (GTK_IS_HANDLE_BOX (handle_box));
 
-  if ((GtkShadowType) handle_box->shadow_type != type)
+  priv = handle_box->priv;
+
+  if ((GtkShadowType) priv->shadow_type != type)
     {
-      handle_box->shadow_type = type;
-      g_object_notify (G_OBJECT (handle_box), "shadow_type");
+      priv->shadow_type = type;
+      g_object_notify (G_OBJECT (handle_box), "shadow-type");
       gtk_widget_queue_resize (GTK_WIDGET (handle_box));
     }
 }
@@ -738,19 +853,23 @@ gtk_handle_box_get_shadow_type (GtkHandleBox *handle_box)
 {
   g_return_val_if_fail (GTK_IS_HANDLE_BOX (handle_box), GTK_SHADOW_ETCHED_OUT);
 
-  return handle_box->shadow_type;
+  return handle_box->priv->shadow_type;
 }
 
 void        
 gtk_handle_box_set_handle_position  (GtkHandleBox    *handle_box,
                                     GtkPositionType  position)
 {
+  GtkHandleBoxPrivate *priv;
+
   g_return_if_fail (GTK_IS_HANDLE_BOX (handle_box));
 
-  if ((GtkPositionType) handle_box->handle_position != position)
+  priv = handle_box->priv;
+
+  if ((GtkPositionType) priv->handle_position != position)
     {
-      handle_box->handle_position = position;
-      g_object_notify (G_OBJECT (handle_box), "handle_position");
+      priv->handle_position = position;
+      g_object_notify (G_OBJECT (handle_box), "handle-position");
       gtk_widget_queue_resize (GTK_WIDGET (handle_box));
     }
 }
@@ -769,19 +888,27 @@ gtk_handle_box_get_handle_position (GtkHandleBox *handle_box)
 {
   g_return_val_if_fail (GTK_IS_HANDLE_BOX (handle_box), GTK_POS_LEFT);
 
-  return handle_box->handle_position;
+  return handle_box->priv->handle_position;
 }
 
 void        
 gtk_handle_box_set_snap_edge        (GtkHandleBox    *handle_box,
                                     GtkPositionType  edge)
 {
+  GtkHandleBoxPrivate *priv;
+
   g_return_if_fail (GTK_IS_HANDLE_BOX (handle_box));
 
-  if (handle_box->snap_edge != edge)
+  priv = handle_box->priv;
+
+  if (priv->snap_edge != edge)
     {
-      handle_box->snap_edge = edge;
-      g_object_notify (G_OBJECT (handle_box), "snap_edge");
+      priv->snap_edge = edge;
+
+      g_object_freeze_notify (G_OBJECT (handle_box));
+      g_object_notify (G_OBJECT (handle_box), "snap-edge");
+      g_object_notify (G_OBJECT (handle_box), "snap-edge-set");
+      g_object_thaw_notify (G_OBJECT (handle_box));
     }
 }
 
@@ -800,127 +927,169 @@ gtk_handle_box_get_snap_edge (GtkHandleBox *handle_box)
 {
   g_return_val_if_fail (GTK_IS_HANDLE_BOX (handle_box), (GtkPositionType)-1);
 
-  return handle_box->snap_edge;
+  return handle_box->priv->snap_edge;
+}
+
+/**
+ * gtk_handle_box_get_child_detached:
+ * @handle_box: a #GtkHandleBox
+ *
+ * Whether the handlebox's child is currently detached.
+ *
+ * Return value: %TRUE if the child is currently detached, otherwise %FALSE
+ *
+ * Since: 2.14
+ **/
+gboolean
+gtk_handle_box_get_child_detached (GtkHandleBox *handle_box)
+{
+  g_return_val_if_fail (GTK_IS_HANDLE_BOX (handle_box), FALSE);
+
+  return handle_box->priv->child_detached;
 }
 
 static void
 gtk_handle_box_paint (GtkWidget      *widget,
-                     GdkEventExpose *event,
-                     GdkRectangle   *area)
+                      cairo_t        *cr)
 {
-  GtkBin *bin;
-  GtkHandleBox *hb;
-  guint width;
-  guint height;
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
+  GtkBin *bin = GTK_BIN (widget);
+  GtkWidget *child;
+  gint width, height;
   GdkRectangle rect;
-  GdkRectangle dest;
+  gint handle_position;
+  GtkOrientation handle_orientation;
 
-  bin = GTK_BIN (widget);
-  hb = GTK_HANDLE_BOX (widget);
+  handle_position = effective_handle_position (hb);
 
-  gdk_window_get_size (hb->bin_window, &width, &height);
-  
-  if (!event)
-    gtk_paint_box (widget->style,
-                  hb->bin_window,
-                  GTK_WIDGET_STATE (widget),
-                  hb->shadow_type,
-                  area, widget, "handlebox_bin",
-                  0, 0, -1, -1);
-  else
-   gtk_paint_box (widget->style,
-                 hb->bin_window,
-                 GTK_WIDGET_STATE (widget),
-                 hb->shadow_type,
-                 &event->area, widget, "handlebox_bin",
-                 0, 0, -1, -1);
-
-/* We currently draw the handle _above_ the relief of the handlebox.
- * it could also be drawn on the same level...
-
-                hb->handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
-                hb->handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
-                width,
-                height);*/
-
-  switch (hb->handle_position)
+  width = gdk_window_get_width (priv->bin_window);
+  height = gdk_window_get_height (priv->bin_window);
+
+  gtk_paint_box (gtk_widget_get_style (widget),
+                 cr,
+                 gtk_widget_get_state (widget),
+                 priv->shadow_type,
+                 widget, "handlebox_bin",
+                 0, 0, width, height);
+
+  switch (handle_position)
     {
     case GTK_POS_LEFT:
       rect.x = 0;
       rect.y = 0; 
       rect.width = DRAG_HANDLE_SIZE;
       rect.height = height;
+      handle_orientation = GTK_ORIENTATION_VERTICAL;
       break;
     case GTK_POS_RIGHT:
       rect.x = width - DRAG_HANDLE_SIZE; 
       rect.y = 0;
       rect.width = DRAG_HANDLE_SIZE;
       rect.height = height;
+      handle_orientation = GTK_ORIENTATION_VERTICAL;
       break;
     case GTK_POS_TOP:
       rect.x = 0;
       rect.y = 0; 
       rect.width = width;
       rect.height = DRAG_HANDLE_SIZE;
+      handle_orientation = GTK_ORIENTATION_HORIZONTAL;
       break;
     case GTK_POS_BOTTOM:
       rect.x = 0;
       rect.y = height - DRAG_HANDLE_SIZE;
       rect.width = width;
       rect.height = DRAG_HANDLE_SIZE;
+      handle_orientation = GTK_ORIENTATION_HORIZONTAL;
+      break;
+    default: 
+      g_assert_not_reached ();
       break;
     }
 
-  if (gdk_rectangle_intersect (event ? &event->area : area, &rect, &dest))
-    draw_textured_frame (widget, hb->bin_window, &rect,
-                        GTK_SHADOW_OUT,
-                        event ? &event->area : area);
+  gtk_paint_handle (gtk_widget_get_style (widget), cr,
+                    GTK_STATE_NORMAL, GTK_SHADOW_OUT,
+                    widget, "handlebox",
+                    rect.x, rect.y, rect.width, rect.height, 
+                    handle_orientation);
 
-  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
-    {
-      GdkRectangle child_area;
+  child = gtk_bin_get_child (bin);
+  if (child != NULL && gtk_widget_get_visible (child))
+    GTK_WIDGET_CLASS (gtk_handle_box_parent_class)->draw (widget, cr);
+}
 
-      if (!event) /* we were called from draw() */
-       {
-         if (gtk_widget_intersect (bin->child, area, &child_area))
-           gtk_widget_draw (bin->child, &child_area);
-       }
-      else /* we were called from expose() */
-       (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+static gboolean
+gtk_handle_box_draw (GtkWidget *widget,
+                    cairo_t   *cr)
+{
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
+
+  if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
+    {
+      if (priv->child_detached)
+        gtk_handle_box_draw_ghost (hb, cr);
     }
+  else if (gtk_cairo_should_draw_window (cr, priv->bin_window))
+    gtk_handle_box_paint (widget, cr);
+  
+  return FALSE;
 }
 
-static gint
-gtk_handle_box_expose (GtkWidget      *widget,
-                      GdkEventExpose *event)
+static GtkWidget *
+gtk_handle_box_get_invisible (void)
 {
-  GtkHandleBox *hb;
+  static GtkWidget *handle_box_invisible = NULL;
 
-  if (GTK_WIDGET_DRAWABLE (widget))
+  if (!handle_box_invisible)
     {
-      hb = GTK_HANDLE_BOX (widget);
+      handle_box_invisible = gtk_invisible_new ();
+      gtk_widget_show (handle_box_invisible);
+    }
+  
+  return handle_box_invisible;
+}
 
-      if (event->window == widget->window)
+static gboolean
+gtk_handle_box_grab_event (GtkWidget    *widget,
+                          GdkEvent     *event,
+                          GtkHandleBox *hb)
+{
+  GtkHandleBoxPrivate *priv = hb->priv;
+
+  switch (event->type)
+    {
+    case GDK_BUTTON_RELEASE:
+      if (priv->in_drag)               /* sanity check */
        {
-         if (hb->child_detached)
-           gtk_handle_box_draw_ghost (hb);
+         gtk_handle_box_end_drag (hb, event->button.time);
+         return TRUE;
        }
-      else
-       gtk_handle_box_paint (widget, event, NULL);
+      break;
+
+    case GDK_MOTION_NOTIFY:
+      return gtk_handle_box_motion (GTK_WIDGET (hb), (GdkEventMotion *)event);
+      break;
+
+    default:
+      break;
     }
-  
+
   return FALSE;
 }
 
-static gint
-gtk_handle_box_button_changed (GtkWidget      *widget,
-                              GdkEventButton *event)
+static gboolean
+gtk_handle_box_button_press (GtkWidget      *widget,
+                             GdkEventButton *event)
 {
-  GtkHandleBox *hb;
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
   gboolean event_handled;
   GdkCursor *fleur;
+  gint handle_position;
 
-  hb = GTK_HANDLE_BOX (widget);
+  handle_position = effective_handle_position (hb);
 
   event_handled = FALSE;
   if ((event->button == 1) && 
@@ -929,14 +1098,20 @@ gtk_handle_box_button_changed (GtkWidget      *widget,
       GtkWidget *child;
       gboolean in_handle;
       
-      if (event->window != hb->bin_window)
+      if (event->window != priv->bin_window)
        return FALSE;
 
-      child = GTK_BIN (hb)->child;
+      child = gtk_bin_get_child (GTK_BIN (hb));
 
       if (child)
        {
-         switch (hb->handle_position)
+          GtkAllocation child_allocation;
+          guint border_width;
+
+          gtk_widget_get_allocation (child, &child_allocation);
+          border_width = gtk_container_get_border_width (GTK_CONTAINER (hb));
+
+         switch (handle_position)
            {
            case GTK_POS_LEFT:
              in_handle = event->x < DRAG_HANDLE_SIZE;
@@ -945,10 +1120,10 @@ gtk_handle_box_button_changed (GtkWidget      *widget,
              in_handle = event->y < DRAG_HANDLE_SIZE;
              break;
            case GTK_POS_RIGHT:
-             in_handle = event->x > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.width;
+             in_handle = event->x > 2 * border_width + child_allocation.width;
              break;
            case GTK_POS_BOTTOM:
-             in_handle = event->y > 2 * GTK_CONTAINER (hb)->border_width + child->allocation.height;
+             in_handle = event->y > 2 * border_width + child_allocation.height;
              break;
            default:
              in_handle = FALSE;
@@ -965,118 +1140,149 @@ gtk_handle_box_button_changed (GtkWidget      *widget,
        {
          if (event->type == GDK_BUTTON_PRESS) /* Start a drag */
            {
-             gint desk_x, desk_y;
+             GtkWidget *invisible = gtk_handle_box_get_invisible ();
+              GdkWindow *window;
              gint root_x, root_y;
-             gint width, height;
-             
-             gdk_window_get_deskrelative_origin (hb->bin_window, &desk_x, &desk_y);
-             gdk_window_get_origin (hb->bin_window, &root_x, &root_y);
-             gdk_window_get_size (hb->bin_window, &width, &height);
-             
-             hb->float_allocation.x = root_x - event->x_root;
-             hb->float_allocation.y = root_y - event->y_root;
-             hb->float_allocation.width = width;
-             hb->float_allocation.height = height;
-             
-             hb->deskoff_x = desk_x - root_x;
-             hb->deskoff_y = desk_y - root_y;
-             
-             gdk_window_get_origin (widget->window, &root_x, &root_y);
-             gdk_window_get_size (widget->window, &width, &height);
-             
-             hb->attach_allocation.x = root_x;
-             hb->attach_allocation.y = root_y;
-             hb->attach_allocation.width = width;
-             hb->attach_allocation.height = height;
-
-             hb->in_drag = TRUE;
+
+              gtk_invisible_set_screen (GTK_INVISIBLE (invisible),
+                                        gtk_widget_get_screen (GTK_WIDGET (hb)));
+             gdk_window_get_origin (priv->bin_window, &root_x, &root_y);
+
+             priv->orig_x = event->x_root;
+             priv->orig_y = event->y_root;
+
+             priv->float_allocation.x = root_x - event->x_root;
+             priv->float_allocation.y = root_y - event->y_root;
+             priv->float_allocation.width = gdk_window_get_width (priv->bin_window);
+             priv->float_allocation.height = gdk_window_get_height (priv->bin_window);
+
+              window = gtk_widget_get_window (widget);
+             if (gdk_window_is_viewable (window))
+               {
+                 gdk_window_get_origin (window, &root_x, &root_y);
+
+                 priv->attach_allocation.x = root_x;
+                 priv->attach_allocation.y = root_y;
+                 priv->attach_allocation.width = gdk_window_get_width (window);
+                 priv->attach_allocation.height = gdk_window_get_height (window);
+               }
+             else
+               {
+                 priv->attach_allocation.x = -1;
+                 priv->attach_allocation.y = -1;
+                 priv->attach_allocation.width = 0;
+                 priv->attach_allocation.height = 0;
+               }
+             priv->in_drag = TRUE;
+              priv->grab_device = event->device;
              fleur = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
                                                  GDK_FLEUR);
-             if (gdk_pointer_grab (widget->window,
-                                   FALSE,
-                                   (GDK_BUTTON1_MOTION_MASK |
-                                    GDK_POINTER_MOTION_HINT_MASK |
-                                    GDK_BUTTON_RELEASE_MASK),
-                                   NULL,
-                                   fleur,
-                                   GDK_CURRENT_TIME) != 0)
+             if (gdk_device_grab (event->device,
+                                   gtk_widget_get_window (invisible),
+                                   GDK_OWNERSHIP_WINDOW,
+                                   FALSE,
+                                   (GDK_BUTTON1_MOTION_MASK |
+                                    GDK_POINTER_MOTION_HINT_MASK |
+                                    GDK_BUTTON_RELEASE_MASK),
+                                   fleur,
+                                   event->time) != GDK_GRAB_SUCCESS)
+               {
+                 priv->in_drag = FALSE;
+                  priv->grab_device = NULL;
+               }
+             else
                {
-                 hb->in_drag = FALSE;
+                  gtk_device_grab_add (invisible, priv->grab_device, TRUE);
+                 g_signal_connect (invisible, "event",
+                                   G_CALLBACK (gtk_handle_box_grab_event), hb);
                }
-             
-             gdk_cursor_destroy (fleur);
+
+             gdk_cursor_unref (fleur);
              event_handled = TRUE;
            }
-         else if (hb->child_detached) /* Double click */
+         else if (priv->child_detached) /* Double click */
            {
              gtk_handle_box_reattach (hb);
            }
        }
     }
-  else if (event->type == GDK_BUTTON_RELEASE &&
-          hb->in_drag)
-    {
-      if (event->window != widget->window)
-       return FALSE;
-      
-      gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                 GDK_CURRENT_TIME);
-      hb->in_drag = FALSE;
-      event_handled = TRUE;
-    }
   
   return event_handled;
 }
 
-static gint
+static gboolean
 gtk_handle_box_motion (GtkWidget      *widget,
                       GdkEventMotion *event)
 {
-  GtkHandleBox *hb;
+  GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
+  GtkWidget *child;
   gint new_x, new_y;
   gint snap_edge;
   gboolean is_snapped = FALSE;
+  gint handle_position;
+  GdkGeometry geometry;
+  GdkScreen *screen, *pointer_screen;
 
-  hb = GTK_HANDLE_BOX (widget);
-  if (!hb->in_drag)
+  if (!priv->in_drag)
     return FALSE;
+  handle_position = effective_handle_position (hb);
 
-  if (!hb->in_drag || (event->window != widget->window))
-    return FALSE;
-  
   /* Calculate the attachment point on the float, if the float
    * were detached
    */
   new_x = 0;
   new_y = 0;
-  gdk_window_get_pointer (gtk_widget_get_root_window (widget), 
-                         &new_x, &new_y, NULL);
-  new_x += hb->float_allocation.x;
-  new_y += hb->float_allocation.y;
+  screen = gtk_widget_get_screen (widget);
+  gdk_display_get_device_state (gdk_screen_get_display (screen),
+                                event->device,
+                                &pointer_screen,
+                                &new_x, &new_y, NULL);
+  if (pointer_screen != screen)
+    {
+      new_x = priv->orig_x;
+      new_y = priv->orig_y;
+    }
+
+  new_x += priv->float_allocation.x;
+  new_y += priv->float_allocation.y;
 
-  snap_edge = hb->snap_edge;
+  snap_edge = priv->snap_edge;
   if (snap_edge == -1)
-    snap_edge = (hb->handle_position == GTK_POS_LEFT ||
-                 hb->handle_position == GTK_POS_RIGHT) ?
+    snap_edge = (handle_position == GTK_POS_LEFT ||
+                handle_position == GTK_POS_RIGHT) ?
       GTK_POS_TOP : GTK_POS_LEFT;
 
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
+    switch (snap_edge) 
+      {
+      case GTK_POS_LEFT:
+       snap_edge = GTK_POS_RIGHT;
+       break;
+      case GTK_POS_RIGHT:
+       snap_edge = GTK_POS_LEFT;
+       break;
+      default:
+       break;
+      }
+
   /* First, check if the snapped edge is aligned
    */
   switch (snap_edge)
     {
     case GTK_POS_TOP:
-      is_snapped = abs (hb->attach_allocation.y - new_y) < TOLERANCE;
+      is_snapped = abs (priv->attach_allocation.y - new_y) < TOLERANCE;
       break;
     case GTK_POS_BOTTOM:
-      is_snapped = abs (hb->attach_allocation.y + (gint)hb->attach_allocation.height -
-                       new_y - (gint)hb->float_allocation.height) < TOLERANCE;
+      is_snapped = abs (priv->attach_allocation.y + (gint)priv->attach_allocation.height -
+                       new_y - (gint)priv->float_allocation.height) < TOLERANCE;
       break;
     case GTK_POS_LEFT:
-      is_snapped = abs (hb->attach_allocation.x - new_x) < TOLERANCE;
+      is_snapped = abs (priv->attach_allocation.x - new_x) < TOLERANCE;
       break;
     case GTK_POS_RIGHT:
-      is_snapped = abs (hb->attach_allocation.x + (gint)hb->attach_allocation.width -
-                       new_x - (gint)hb->float_allocation.width) < TOLERANCE;
+      is_snapped = abs (priv->attach_allocation.x + (gint)priv->attach_allocation.width -
+                       new_x - (gint)priv->float_allocation.width) < TOLERANCE;
       break;
     }
 
@@ -1094,17 +1300,17 @@ gtk_handle_box_motion (GtkWidget      *widget,
        {
        case GTK_POS_TOP:
        case GTK_POS_BOTTOM:
-         attach_pos1 = hb->attach_allocation.x;
-         attach_pos2 = hb->attach_allocation.x + hb->attach_allocation.width;
+         attach_pos1 = priv->attach_allocation.x;
+         attach_pos2 = priv->attach_allocation.x + priv->attach_allocation.width;
          float_pos1 = new_x;
-         float_pos2 = new_x + hb->float_allocation.width;
+         float_pos2 = new_x + priv->float_allocation.width;
          break;
        case GTK_POS_LEFT:
        case GTK_POS_RIGHT:
-         attach_pos1 = hb->attach_allocation.y;
-         attach_pos2 = hb->attach_allocation.y + hb->attach_allocation.height;
+         attach_pos1 = priv->attach_allocation.y;
+         attach_pos2 = priv->attach_allocation.y + priv->attach_allocation.height;
          float_pos1 = new_y;
-         float_pos2 = new_y + hb->float_allocation.height;
+         float_pos2 = new_y + priv->float_allocation.height;
          break;
        }
 
@@ -1114,17 +1320,20 @@ gtk_handle_box_motion (GtkWidget      *widget,
                    (float_pos2 + TOLERANCE > attach_pos2));
     }
 
+  child = gtk_bin_get_child (GTK_BIN (hb));
+
   if (is_snapped)
     {
-      if (hb->child_detached)
+      if (priv->child_detached)
        {
-         hb->child_detached = FALSE;
-         gdk_window_hide (hb->float_window);
-         gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
-         hb->float_window_mapped = FALSE;
-         gtk_signal_emit (GTK_OBJECT (hb),
-                          handle_box_signals[SIGNAL_CHILD_ATTACHED],
-                          GTK_BIN (hb)->child);
+         priv->child_detached = FALSE;
+         gdk_window_hide (priv->float_window);
+         gdk_window_reparent (priv->bin_window, gtk_widget_get_window (widget), 0, 0);
+         priv->float_window_mapped = FALSE;
+         g_signal_emit (hb,
+                        handle_box_signals[SIGNAL_CHILD_ATTACHED],
+                        0,
+                        child);
          
          gtk_widget_queue_resize (widget);
        }
@@ -1133,74 +1342,75 @@ gtk_handle_box_motion (GtkWidget      *widget,
     {
       gint width, height;
 
-      gdk_window_get_size (hb->float_window, &width, &height);
-      new_x += hb->deskoff_x;
-      new_y += hb->deskoff_y;
+      width = gdk_window_get_width (priv->float_window);
+      height = gdk_window_get_height (priv->float_window);
 
-      switch (hb->handle_position)
+      switch (handle_position)
        {
        case GTK_POS_LEFT:
-         new_y += ((gint)hb->float_allocation.height - height) / 2;
+         new_y += ((gint)priv->float_allocation.height - height) / 2;
          break;
        case GTK_POS_RIGHT:
-         new_x += (gint)hb->float_allocation.width - width;
-         new_y += ((gint)hb->float_allocation.height - height) / 2;
+         new_x += (gint)priv->float_allocation.width - width;
+         new_y += ((gint)priv->float_allocation.height - height) / 2;
          break;
        case GTK_POS_TOP:
-         new_x += ((gint)hb->float_allocation.width - width) / 2;
+         new_x += ((gint)priv->float_allocation.width - width) / 2;
          break;
        case GTK_POS_BOTTOM:
-         new_x += ((gint)hb->float_allocation.width - width) / 2;
-         new_y += (gint)hb->float_allocation.height - height;
+         new_x += ((gint)priv->float_allocation.width - width) / 2;
+         new_y += (gint)priv->float_allocation.height - height;
          break;
        }
 
-      if (hb->child_detached)
+      if (priv->child_detached)
        {
-         gdk_window_move (hb->float_window, new_x, new_y);
-         gdk_window_raise (hb->float_window);
+         gdk_window_move (priv->float_window, new_x, new_y);
+         gdk_window_raise (priv->float_window);
        }
       else
        {
-         gint width;
-         gint height;
+          guint border_width;
          GtkRequisition child_requisition;
 
-         hb->child_detached = TRUE;
+         priv->child_detached = TRUE;
 
-         if (GTK_BIN (hb)->child)
-           gtk_widget_get_child_requisition (GTK_BIN (hb)->child, &child_requisition);
+         if (child)
+            {
+              gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+            }
          else
            {
              child_requisition.width = 0;
              child_requisition.height = 0;
            }      
 
-         width = child_requisition.width + 2 * GTK_CONTAINER (hb)->border_width;
-         height = child_requisition.height + 2 * GTK_CONTAINER (hb)->border_width;
+          border_width = gtk_container_get_border_width (GTK_CONTAINER (hb));
+         width = child_requisition.width + 2 * border_width;
+         height = child_requisition.height + 2 * border_width;
 
-         if (hb->handle_position == GTK_POS_LEFT || hb->handle_position == GTK_POS_RIGHT)
+         if (handle_position == GTK_POS_LEFT || handle_position == GTK_POS_RIGHT)
            width += DRAG_HANDLE_SIZE;
          else
            height += DRAG_HANDLE_SIZE;
          
-         gdk_window_move_resize (hb->float_window, new_x, new_y, width, height);
-         gdk_window_reparent (hb->bin_window, hb->float_window, 0, 0);
-         gdk_window_set_hints (hb->float_window, new_x, new_y, 0, 0, 0, 0, GDK_HINT_POS);
-         gdk_window_show (hb->float_window);
-         hb->float_window_mapped = TRUE;
+         gdk_window_move_resize (priv->float_window, new_x, new_y, width, height);
+         gdk_window_reparent (priv->bin_window, priv->float_window, 0, 0);
+         gdk_window_set_geometry_hints (priv->float_window, &geometry, GDK_HINT_POS);
+         gdk_window_show (priv->float_window);
+         priv->float_window_mapped = TRUE;
 #if    0
-         /* this extra move is neccessary if we use decorations, or our
+         /* this extra move is necessary if we use decorations, or our
           * window manager insists on decorations.
           */
          gdk_display_sync (gtk_widget_get_display (widget));
-         gdk_window_move (hb->float_window, new_x, new_y);
+         gdk_window_move (priv->float_window, new_x, new_y);
          gdk_display_sync (gtk_widget_get_display (widget));
 #endif /* 0 */
-         gtk_signal_emit (GTK_OBJECT (hb),
-                          handle_box_signals[SIGNAL_CHILD_DETACHED],
-                          GTK_BIN (hb)->child);
-         gtk_handle_box_draw_ghost (hb);
+         g_signal_emit (hb,
+                        handle_box_signals[SIGNAL_CHILD_DETACHED],
+                        0,
+                        child);
          
          gtk_widget_queue_resize (widget);
        }
@@ -1213,15 +1423,17 @@ static void
 gtk_handle_box_add (GtkContainer *container,
                    GtkWidget    *widget)
 {
-  gtk_widget_set_parent_window (widget, GTK_HANDLE_BOX (container)->bin_window);
-  GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
+  GtkHandleBoxPrivate *priv = GTK_HANDLE_BOX (container)->priv;
+
+  gtk_widget_set_parent_window (widget, priv->bin_window);
+  GTK_CONTAINER_CLASS (gtk_handle_box_parent_class)->add (container, widget);
 }
 
 static void
 gtk_handle_box_remove (GtkContainer *container,
                       GtkWidget    *widget)
 {
-  GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
+  GTK_CONTAINER_CLASS (gtk_handle_box_parent_class)->remove (container, widget);
 
   gtk_handle_box_reattach (GTK_HANDLE_BOX (container));
 }
@@ -1231,8 +1443,9 @@ gtk_handle_box_delete_event (GtkWidget *widget,
                             GdkEventAny  *event)
 {
   GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
+  GtkHandleBoxPrivate *priv = hb->priv;
 
-  if (event->window == hb->float_window)
+  if (event->window == priv->float_window)
     {
       gtk_handle_box_reattach (hb);
       
@@ -1245,30 +1458,49 @@ gtk_handle_box_delete_event (GtkWidget *widget,
 static void
 gtk_handle_box_reattach (GtkHandleBox *hb)
 {
+  GtkHandleBoxPrivate *priv = hb->priv;
+  GtkWidget *child;
   GtkWidget *widget = GTK_WIDGET (hb);
   
-  if (hb->child_detached)
+  if (priv->child_detached)
     {
-      hb->child_detached = FALSE;
-      if (GTK_WIDGET_REALIZED (hb))
+      priv->child_detached = FALSE;
+      if (gtk_widget_get_realized (widget))
        {
-         gdk_window_hide (hb->float_window);
-         gdk_window_reparent (hb->bin_window, widget->window, 0, 0);
+         gdk_window_hide (priv->float_window);
+          gdk_window_reparent (priv->bin_window, gtk_widget_get_window (widget),
+                               0, 0);
 
-         if (GTK_BIN (hb)->child)
-           gtk_signal_emit (GTK_OBJECT (hb),
-                            handle_box_signals[SIGNAL_CHILD_ATTACHED],
-                            GTK_BIN (hb)->child);
+          child = gtk_bin_get_child (GTK_BIN (hb));
+         if (child)
+           g_signal_emit (hb,
+                          handle_box_signals[SIGNAL_CHILD_ATTACHED],
+                          0,
+                          child);
 
        }
-      hb->float_window_mapped = FALSE;
-    }
-  if (hb->in_drag)
-    {
-      gdk_display_pointer_ungrab (gtk_widget_get_display (GTK_WIDGET (hb)),
-                                 GDK_CURRENT_TIME);
-      hb->in_drag = FALSE;
+      priv->float_window_mapped = FALSE;
     }
+  if (priv->in_drag)
+    gtk_handle_box_end_drag (hb, GDK_CURRENT_TIME);
 
   gtk_widget_queue_resize (GTK_WIDGET (hb));
 }
+
+static void
+gtk_handle_box_end_drag (GtkHandleBox *hb,
+                        guint32       time)
+{
+  GtkHandleBoxPrivate *priv = hb->priv;
+  GtkWidget *invisible = gtk_handle_box_get_invisible ();
+
+  priv->in_drag = FALSE;
+
+  gtk_device_grab_remove (invisible, priv->grab_device);
+  gdk_device_ungrab (priv->grab_device, time);
+  g_signal_handlers_disconnect_by_func (invisible,
+                                       G_CALLBACK (gtk_handle_box_grab_event),
+                                       hb);
+
+  priv->grab_device = NULL;
+}