]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtknotebook.c
Clarify the docs. Pointed out by Wolfgang Oertl
[~andy/gtk] / gtk / gtknotebook.c
index 12a85bc74b875527e4269a1b9a6f30315c76acaf..b623e15ea31821fffe8f2018359806ee2b6fa7b3 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <gdk/gdkkeysyms.h>
+
+#undef GTK_DISABLE_DEPRECATED
+
 #include "gtknotebook.h"
 #include "gtkmain.h"
 #include "gtkmenu.h"
 #include "gtkmenuitem.h"
 #include "gtklabel.h"
-#include <gdk/gdkkeysyms.h>
-#include <stdio.h>
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
 #include "gtkbindings.h"
 #include "gtkprivate.h"
-#include "gtkalias.h"
 #include "gtkdnd.h"
+#include "gtkbuildable.h"
+
+#include "gtkalias.h"
 
 #define SCROLL_DELAY_FACTOR   5
 #define SCROLL_THRESHOLD      12
 #define DND_THRESHOLD_MULTIPLIER 4
+#define FRAMES_PER_SECOND     45
+#define MSECS_BETWEEN_UPDATES (1000 / FRAMES_PER_SECOND)
 
 enum {
   SWITCH_PAGE,
@@ -54,6 +64,7 @@ enum {
   PAGE_REORDERED,
   PAGE_REMOVED,
   PAGE_ADDED,
+  CREATE_WINDOW,
   LAST_SIGNAL
 };
 
@@ -100,6 +111,7 @@ enum {
   PROP_PAGE,
   PROP_ENABLE_POPUP,
   PROP_GROUP_ID,
+  PROP_GROUP,
   PROP_HOMOGENEOUS
 };
 
@@ -154,13 +166,20 @@ typedef struct _GtkNotebookPrivate GtkNotebookPrivate;
 
 struct _GtkNotebookPrivate
 {
-  gint  group_id;
+  gpointer group;
   gint  mouse_x;
   gint  mouse_y;
   gint  pressed_button;
   guint dnd_timer;
   guint switch_tab_timer;
 
+  gint  drag_begin_x;
+  gint  drag_begin_y;
+
+  gint  drag_offset_x;
+  gint  drag_offset_y;
+
+  GtkWidget *dnd_window;
   GtkTargetList *source_targets;
   GtkNotebookDragOperation operation;
   GdkWindow *drag_window;
@@ -168,17 +187,15 @@ struct _GtkNotebookPrivate
   gint drag_window_y;
   GtkNotebookPage *detached_tab;
 
-  gboolean during_detach : 1;
-  gboolean has_scrolled  : 1;
-};
+  guint32 timestamp;
 
-static const GtkTargetEntry notebook_source_targets [] = {
-  { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
-  { "application/x-rootwindow-drop", 0, 1 }
+  guint during_reorder : 1;
+  guint during_detach  : 1;
+  guint has_scrolled   : 1;
 };
 
-static const GtkTargetEntry notebook_dest_targets[] = {
-  { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 }
+static const GtkTargetEntry notebook_targets [] = {
+  { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
 };
 
 #ifdef G_DISABLE_CHECKS
@@ -194,13 +211,15 @@ static gboolean gtk_notebook_select_page         (GtkNotebook      *notebook,
                                                  gboolean          move_focus);
 static gboolean gtk_notebook_focus_tab           (GtkNotebook      *notebook,
                                                  GtkNotebookTab    type);
-static void     gtk_notebook_change_current_page (GtkNotebook      *notebook,
+static gboolean gtk_notebook_change_current_page (GtkNotebook      *notebook,
                                                  gint              offset);
 static void     gtk_notebook_move_focus_out      (GtkNotebook      *notebook,
                                                  GtkDirectionType  direction_type);
-static void     gtk_notebook_reorder_tab         (GtkNotebook      *notebook,
+static gboolean gtk_notebook_reorder_tab         (GtkNotebook      *notebook,
                                                  GtkDirectionType  direction_type,
                                                  gboolean          move_to_last);
+static void     gtk_notebook_remove_tab_label    (GtkNotebook      *notebook,
+                                                 GtkNotebookPage  *page);
 
 /*** GtkObject Methods ***/
 static void gtk_notebook_destroy             (GtkObject        *object);
@@ -231,8 +250,6 @@ static gint gtk_notebook_button_press        (GtkWidget        *widget,
 static gint gtk_notebook_button_release      (GtkWidget        *widget,
                                              GdkEventButton   *event);
 static gboolean gtk_notebook_popup_menu      (GtkWidget        *widget);
-static gint gtk_notebook_enter_notify        (GtkWidget        *widget,
-                                             GdkEventCrossing *event);
 static gint gtk_notebook_leave_notify        (GtkWidget        *widget,
                                              GdkEventCrossing *event);
 static gint gtk_notebook_motion_notify       (GtkWidget        *widget,
@@ -245,7 +262,8 @@ static void gtk_notebook_grab_notify         (GtkWidget          *widget,
                                              gboolean            was_grabbed);
 static void gtk_notebook_state_changed       (GtkWidget          *widget,
                                              GtkStateType        previous_state);
-static void gtk_notebook_draw_focus          (GtkWidget        *widget);
+static void gtk_notebook_draw_focus          (GtkWidget        *widget,
+                                             GdkEventExpose   *event);
 static gint gtk_notebook_focus               (GtkWidget        *widget,
                                              GtkDirectionType  direction);
 static void gtk_notebook_style_set           (GtkWidget        *widget,
@@ -254,6 +272,12 @@ static void gtk_notebook_style_set           (GtkWidget        *widget,
 /*** Drag and drop Methods ***/
 static void gtk_notebook_drag_begin          (GtkWidget        *widget,
                                              GdkDragContext   *context);
+static void gtk_notebook_drag_end            (GtkWidget        *widget,
+                                             GdkDragContext   *context);
+static gboolean gtk_notebook_drag_failed     (GtkWidget        *widget,
+                                             GdkDragContext   *context,
+                                             GtkDragResult     result,
+                                             gpointer          data);
 static gboolean gtk_notebook_drag_motion     (GtkWidget        *widget,
                                              GdkDragContext   *context,
                                              gint              x,
@@ -310,6 +334,11 @@ static gint gtk_notebook_real_insert_page    (GtkNotebook      *notebook,
                                              GtkWidget        *menu_label,
                                              gint              position);
 
+static GtkNotebook *gtk_notebook_create_window (GtkNotebook    *notebook,
+                                                GtkWidget      *page,
+                                                gint            x,
+                                                gint            y);
+
 /*** GtkNotebook Private Functions ***/
 static void gtk_notebook_redraw_tabs         (GtkNotebook      *notebook);
 static void gtk_notebook_redraw_arrows       (GtkNotebook      *notebook);
@@ -329,6 +358,8 @@ static GList * gtk_notebook_search_page      (GtkNotebook      *notebook,
                                              GList            *list,
                                              gint              direction,
                                              gboolean          find_visible);
+static void  gtk_notebook_child_reordered    (GtkNotebook      *notebook,
+                                             GtkNotebookPage  *page);
 
 /*** GtkNotebook Drawing Functions ***/
 static void gtk_notebook_paint               (GtkWidget        *widget,
@@ -356,8 +387,7 @@ static void gtk_notebook_real_switch_page    (GtkNotebook      *notebook,
 
 /*** GtkNotebook Page Switch Functions ***/
 static void gtk_notebook_switch_page         (GtkNotebook      *notebook,
-                                             GtkNotebookPage  *page,
-                                             gint              page_num);
+                                             GtkNotebookPage  *page);
 static gint gtk_notebook_page_select         (GtkNotebook      *notebook,
                                              gboolean          move_focus);
 static void gtk_notebook_switch_focus_tab    (GtkNotebook      *notebook,
@@ -393,14 +423,28 @@ static gboolean focus_child_in (GtkNotebook      *notebook,
                                GtkDirectionType  direction);
 
 static void stop_scrolling (GtkNotebook *notebook);
+static void do_detach_tab  (GtkNotebook *from,
+                           GtkNotebook *to,
+                           GtkWidget   *child,
+                           gint         x,
+                           gint         y);
 
+/* GtkBuildable */
+static void gtk_notebook_buildable_init           (GtkBuildableIface *iface);
+static void gtk_notebook_buildable_add_child      (GtkBuildable *buildable,
+                                                  GtkBuilder   *builder,
+                                                  GObject      *child,
+                                                  const gchar  *type);
 
 static GtkNotebookWindowCreationFunc window_creation_hook = NULL;
 static gpointer window_creation_hook_data;
+static GDestroyNotify window_creation_hook_destroy = NULL;
 
 static guint notebook_signals[LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER)
+G_DEFINE_TYPE_WITH_CODE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_notebook_buildable_init))
 
 static void
 add_tab_bindings (GtkBindingSet    *binding_set,
@@ -448,6 +492,22 @@ add_reorder_bindings (GtkBindingSet    *binding_set,
                                G_TYPE_BOOLEAN, move_to_last);
 }
 
+static gboolean
+gtk_object_handled_accumulator (GSignalInvocationHint *ihint,
+                                GValue                *return_accu,
+                                const GValue          *handler_return,
+                                gpointer               dummy)
+{
+  gboolean continue_emission;
+  GObject *object;
+
+  object = g_value_get_object (handler_return);
+  g_value_set_object (return_accu, object);
+  continue_emission = !object;
+
+  return continue_emission;
+}
+
 static void
 gtk_notebook_class_init (GtkNotebookClass *class)
 {
@@ -472,7 +532,6 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->button_press_event = gtk_notebook_button_press;
   widget_class->button_release_event = gtk_notebook_button_release;
   widget_class->popup_menu = gtk_notebook_popup_menu;
-  widget_class->enter_notify_event = gtk_notebook_enter_notify;
   widget_class->leave_notify_event = gtk_notebook_leave_notify;
   widget_class->motion_notify_event = gtk_notebook_motion_notify;
   widget_class->grab_notify = gtk_notebook_grab_notify;
@@ -482,6 +541,7 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->focus = gtk_notebook_focus;
   widget_class->style_set = gtk_notebook_style_set;
   widget_class->drag_begin = gtk_notebook_drag_begin;
+  widget_class->drag_end = gtk_notebook_drag_end;
   widget_class->drag_motion = gtk_notebook_drag_motion;
   widget_class->drag_leave = gtk_notebook_drag_leave;
   widget_class->drag_drop = gtk_notebook_drag_drop;
@@ -504,15 +564,16 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   class->change_current_page = gtk_notebook_change_current_page;
   class->move_focus_out = gtk_notebook_move_focus_out;
   class->reorder_tab = gtk_notebook_reorder_tab;
+  class->create_window = gtk_notebook_create_window;
   
   g_object_class_install_property (gobject_class,
                                   PROP_PAGE,
                                   g_param_spec_int ("page",
                                                     P_("Page"),
                                                     P_("The index of the current page"),
-                                                    0,
+                                                    -1,
                                                     G_MAXINT,
-                                                    0,
+                                                    -1,
                                                     GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_TAB_POS,
@@ -594,6 +655,20 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                                                     -1,
                                                     GTK_PARAM_READWRITE));
 
+  /**
+   * GtkNotebook:group:
+   *  
+   * Group for tabs drag and drop.
+   *
+   * Since: 2.12
+   */    
+  g_object_class_install_property (gobject_class,
+                                  PROP_GROUP,
+                                  g_param_spec_pointer ("group",
+                                                        P_("Group"),
+                                                        P_("Group for tabs drag and drop"),
+                                                        GTK_PARAM_READWRITE));
+
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_TAB_LABEL,
                                              g_param_spec_string ("tab-label", 
@@ -620,7 +695,7 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                                              g_param_spec_boolean ("tab-expand", 
                                                                    P_("Tab expand"), 
                                                                    P_("Whether to expand the child's tab or not"),
-                                                                   TRUE,
+                                                                   FALSE,
                                                                    GTK_PARAM_READWRITE));
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_TAB_FILL,
@@ -749,7 +824,7 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   /**
    * GtkNotebook:arrow-spacing:
    *
-   * The "arrow-size" property defines the spacing between the scroll
+   * The "arrow-spacing" property defines the spacing between the scroll
    * arrows and the tabs.
    *
    * Since: 2.10
@@ -797,8 +872,8 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                   G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
                   NULL, NULL,
-                  _gtk_marshal_VOID__INT,
-                  G_TYPE_NONE, 1,
+                  _gtk_marshal_BOOLEAN__INT,
+                  G_TYPE_BOOLEAN, 1,
                   G_TYPE_INT);
   notebook_signals[MOVE_FOCUS_OUT] =
     g_signal_new (I_("move_focus_out"),
@@ -815,8 +890,8 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                   G_STRUCT_OFFSET (GtkNotebookClass, reorder_tab),
                   NULL, NULL,
-                  _gtk_marshal_VOID__ENUM_BOOLEAN,
-                  G_TYPE_NONE, 2,
+                  _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
+                  G_TYPE_BOOLEAN, 2,
                   GTK_TYPE_DIRECTION_TYPE,
                  G_TYPE_BOOLEAN);
   /**
@@ -880,6 +955,39 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                  GTK_TYPE_WIDGET,
                  G_TYPE_UINT);
 
+  /**
+   * GtkNotebook::create-window:
+   * @notebook: the #GtkNotebook emitting the signal
+   * @page: the tab of @notebook that is being detached
+   * @x: the X coordinate where the drop happens
+   * @y: the Y coordinate where the drop happens
+   *
+   * The ::create-window signal is emitted when a detachable
+   * tab is dropped on the root window. 
+   *
+   * A handler for this signal can create a window containing 
+   * a notebook where the tab will be attached. It is also 
+   * responsible for moving/resizing the window and adding the 
+   * necessary properties to the notebook (e.g. the 
+   * #GtkNotebook:group-id ).
+   *
+   * The default handler uses the global window creation hook,
+   * if one has been set with gtk_notebook_set_window_creation_hook().
+   *
+   * Returns: a #GtkNotebook that @page should be added to, or %NULL.
+   *
+   * Since: 2.12
+   */
+  notebook_signals[CREATE_WINDOW] = 
+    g_signal_new (I_("create_window"),
+                  G_TYPE_FROM_CLASS (gobject_class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GtkNotebookClass, create_window),
+                  gtk_object_handled_accumulator, NULL,
+                  _gtk_marshal_OBJECT__OBJECT_INT_INT,
+                  GTK_TYPE_NOTEBOOK, 3,
+                  GTK_TYPE_WIDGET, G_TYPE_INT, G_TYPE_INT);
   binding_set = gtk_binding_set_by_class (class);
   gtk_binding_entry_add_signal (binding_set,
                                 GDK_space, 0,
@@ -982,30 +1090,62 @@ gtk_notebook_init (GtkNotebook *notebook)
   notebook->has_after_previous  = 0;
   notebook->has_after_next      = 1;
 
-  priv->group_id = -1;
+  priv->group = NULL;
   priv->pressed_button = -1;
   priv->dnd_timer = 0;
   priv->switch_tab_timer = 0;
-  priv->source_targets = gtk_target_list_new (notebook_source_targets,
-                                             G_N_ELEMENTS (notebook_source_targets));
+  priv->source_targets = gtk_target_list_new (notebook_targets,
+                                             G_N_ELEMENTS (notebook_targets));
   priv->operation = DRAG_OPERATION_NONE;
   priv->detached_tab = NULL;
   priv->during_detach = FALSE;
   priv->has_scrolled = FALSE;
 
-  gtk_drag_dest_set (GTK_WIDGET (notebook),
-                    GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
-                    notebook_dest_targets, G_N_ELEMENTS (notebook_dest_targets),
+  gtk_drag_dest_set (GTK_WIDGET (notebook), 0,
+                    notebook_targets, G_N_ELEMENTS (notebook_targets),
                      GDK_ACTION_MOVE);
 
+  g_signal_connect (G_OBJECT (notebook), "drag-failed",
+                   G_CALLBACK (gtk_notebook_drag_failed), NULL);
+
   gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
 }
 
+static void
+gtk_notebook_buildable_init (GtkBuildableIface *iface)
+{
+  iface->add_child = gtk_notebook_buildable_add_child;
+}
+
+static void
+gtk_notebook_buildable_add_child (GtkBuildable  *buildable,
+                                 GtkBuilder    *builder,
+                                 GObject       *child,
+                                 const gchar   *type)
+{
+  GtkNotebook *notebook = GTK_NOTEBOOK (buildable);
+
+  if (type && strcmp (type, "tab") == 0)
+    {
+      GtkWidget * page;
+
+      page = gtk_notebook_get_nth_page (notebook, -1);
+      /* To set the tab label widget, we must have already a child
+       * inside the tab container. */
+      g_assert (page != NULL);
+      gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child));
+    }
+  else if (!type)
+    gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL);
+  else
+    GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type);
+}
+
 static gboolean
 gtk_notebook_select_page (GtkNotebook *notebook,
                           gboolean     move_focus)
 {
-  if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
+  if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && notebook->show_tabs)
     {
       gtk_notebook_page_select (notebook, move_focus);
       return TRUE;
@@ -1020,7 +1160,7 @@ gtk_notebook_focus_tab (GtkNotebook       *notebook,
 {
   GList *list;
 
-  if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
+  if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && notebook->show_tabs)
     {
       switch (type)
        {
@@ -1042,25 +1182,49 @@ gtk_notebook_focus_tab (GtkNotebook       *notebook,
     return FALSE;
 }
 
-static void
+static gboolean
 gtk_notebook_change_current_page (GtkNotebook *notebook,
                                  gint         offset)
 {
   GList *current = NULL;
 
+  if (!notebook->show_tabs)
+    return FALSE;
+
   if (notebook->cur_page)
     current = g_list_find (notebook->children, notebook->cur_page);
 
   while (offset != 0)
     {
-      current = gtk_notebook_search_page (notebook, current, offset < 0 ? STEP_PREV : STEP_NEXT, TRUE);
+      current = gtk_notebook_search_page (notebook, current,
+                                          offset < 0 ? STEP_PREV : STEP_NEXT,
+                                          TRUE);
+
+      if (!current)
+        {
+          gboolean wrap_around;
+
+          g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
+                        "gtk-keynav-wrap-around", &wrap_around,
+                        NULL);
+
+          if (wrap_around)
+            current = gtk_notebook_search_page (notebook, NULL,
+                                                offset < 0 ? STEP_PREV : STEP_NEXT,
+                                                TRUE);
+          else
+            break;
+        }
+
       offset += offset < 0 ? 1 : -1;
     }
 
   if (current)
-    gtk_notebook_switch_page (notebook, current->data, -1);
+    gtk_notebook_switch_page (notebook, current->data);
   else
-    gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (notebook)));
+    gtk_widget_error_bell (GTK_WIDGET (notebook));
+
+  return TRUE;
 }
 
 static GtkDirectionType
@@ -1208,7 +1372,7 @@ reorder_tab (GtkNotebook *notebook, GList *position, GList *tab)
   return g_list_position (notebook->children, tab);
 }
 
-static void
+static gboolean
 gtk_notebook_reorder_tab (GtkNotebook      *notebook,
                          GtkDirectionType  direction_type,
                          gboolean          move_to_last)
@@ -1218,13 +1382,16 @@ gtk_notebook_reorder_tab (GtkNotebook      *notebook,
   GList *last, *child;
   gint page_num;
 
+  if (!gtk_widget_is_focus (GTK_WIDGET (notebook)) || !notebook->show_tabs)
+    return FALSE;
+
   if (!notebook->cur_page ||
       !notebook->cur_page->reorderable)
-    return;
+    return FALSE;
 
   if (effective_direction != GTK_DIR_LEFT &&
       effective_direction != GTK_DIR_RIGHT)
-    return;
+    return FALSE;
 
   if (move_to_last)
     {
@@ -1247,7 +1414,7 @@ gtk_notebook_reorder_tab (GtkNotebook      *notebook,
                                      TRUE);
 
   if (!child || child->data == notebook->cur_page)
-    return;
+    return FALSE;
 
   page = child->data;
 
@@ -1265,7 +1432,11 @@ gtk_notebook_reorder_tab (GtkNotebook      *notebook,
                     0,
                     ((GtkNotebookPage *) notebook->focus_tab->data)->child,
                     page_num);
+
+      return TRUE;
     }
+
+  return FALSE;
 }
 
 /**
@@ -1292,7 +1463,7 @@ gtk_notebook_destroy (GtkObject *object)
 {
   GtkNotebook *notebook = GTK_NOTEBOOK (object);
   GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
-  
+
   if (notebook->menu)
     gtk_notebook_popup_disable (notebook);
 
@@ -1359,7 +1530,11 @@ gtk_notebook_set_property (GObject         *object,
     case PROP_GROUP_ID:
       gtk_notebook_set_group_id (notebook, g_value_get_int (value));
       break;
+    case PROP_GROUP:
+      gtk_notebook_set_group (notebook, g_value_get_pointer (value));
+      break;
     default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
     }
 }
@@ -1406,7 +1581,10 @@ gtk_notebook_get_property (GObject         *object,
       g_value_set_uint (value, notebook->tab_vborder);
       break;
     case PROP_GROUP_ID:
-      g_value_set_int (value, priv->group_id);
+      g_value_set_int (value, gtk_notebook_get_group_id (notebook));
+      break;
+    case PROP_GROUP:
+      g_value_set_pointer (value, priv->group);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1426,7 +1604,6 @@ gtk_notebook_get_property (GObject         *object,
  * gtk_notebook_button_press
  * gtk_notebook_button_release
  * gtk_notebook_popup_menu
- * gtk_notebook_enter_notify
  * gtk_notebook_leave_notify
  * gtk_notebook_motion_notify
  * gtk_notebook_focus_in
@@ -1434,6 +1611,8 @@ gtk_notebook_get_property (GObject         *object,
  * gtk_notebook_draw_focus
  * gtk_notebook_style_set
  * gtk_notebook_drag_begin
+ * gtk_notebook_drag_end
+ * gtk_notebook_drag_failed
  * gtk_notebook_drag_motion
  * gtk_notebook_drag_drop
  * gtk_notebook_drag_data_get
@@ -1506,8 +1685,6 @@ gtk_notebook_map (GtkWidget *widget)
   GtkNotebookPage *page;
   GList *children;
 
-  g_return_if_fail (GTK_IS_NOTEBOOK (widget));
-
   GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
 
   notebook = GTK_NOTEBOOK (widget);
@@ -1542,8 +1719,6 @@ gtk_notebook_map (GtkWidget *widget)
 static void
 gtk_notebook_unmap (GtkWidget *widget)
 {
-  g_return_if_fail (GTK_IS_NOTEBOOK (widget));
-
   stop_scrolling (GTK_NOTEBOOK (widget));
   
   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
@@ -1561,8 +1736,6 @@ gtk_notebook_realize (GtkWidget *widget)
   gint attributes_mask;
   GdkRectangle event_window_pos;
 
-  g_return_if_fail (GTK_IS_NOTEBOOK (widget));
-
   notebook = GTK_NOTEBOOK (widget);
   GTK_WIDGET_SET_FLAGS (notebook, GTK_REALIZED);
 
@@ -1580,7 +1753,7 @@ gtk_notebook_realize (GtkWidget *widget)
   attributes.event_mask = gtk_widget_get_events (widget);
   attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
                            GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
-                           GDK_BUTTON1_MOTION_MASK |
+                           GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK |
                            GDK_SCROLL_MASK);
   attributes_mask = GDK_WA_X | GDK_WA_Y;
 
@@ -1597,8 +1770,6 @@ gtk_notebook_unrealize (GtkWidget *widget)
   GtkNotebook *notebook;
   GtkNotebookPrivate *priv;
 
-  g_return_if_fail (GTK_IS_NOTEBOOK (widget));
-
   notebook = GTK_NOTEBOOK (widget);
   priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
 
@@ -1635,7 +1806,7 @@ gtk_notebook_size_request (GtkWidget      *widget,
   gint scroll_arrow_vlength;
 
   gtk_widget_style_get (widget,
-                       "focus-line-width", &focus_width,
+                        "focus-line-width", &focus_width,
                        "tab-overlap", &tab_overlap,
                        "tab-curvature", &tab_curvature,
                         "arrow-spacing", &arrow_spacing,
@@ -1812,7 +1983,7 @@ gtk_notebook_size_request (GtkWidget      *widget,
 
                  if (notebook->scrollable && vis_pages > 1 && 
                      widget->requisition.height < tab_height)
-                   tab_height = tab_max + scroll_arrow_vlength + arrow_spacing;
+                   tab_height = tab_max + (2 * scroll_arrow_vlength + arrow_spacing);
 
                  widget->requisition.width += tab_width;
 
@@ -1860,7 +2031,7 @@ gtk_notebook_size_request (GtkWidget      *widget,
              page = children->data;
              if (GTK_WIDGET_VISIBLE (page->child))
                {
-                 gtk_notebook_switch_page (notebook, page, -1);
+                 gtk_notebook_switch_page (notebook, page);
                  break;
                }
            }
@@ -1877,7 +2048,7 @@ gtk_notebook_size_request (GtkWidget      *widget,
       if (children)
        {
          notebook->first_tab = children;
-         gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children),-1);
+         gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children));
        }
     }
 }
@@ -1969,10 +2140,6 @@ gtk_notebook_expose (GtkWidget      *widget,
 {
   GtkNotebook *notebook;
   GtkNotebookPrivate *priv;
-  GdkRectangle child_area;
-
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
 
   notebook = GTK_NOTEBOOK (widget);
   priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
@@ -1986,19 +2153,33 @@ gtk_notebook_expose (GtkWidget      *widget,
       gtk_notebook_draw_tab (notebook,
                             notebook->cur_page,
                             &area);
+      gtk_notebook_draw_focus (widget, event);
+      gtk_container_propagate_expose (GTK_CONTAINER (notebook),
+                                     notebook->cur_page->tab_label, event);
     }
   else if (GTK_WIDGET_DRAWABLE (widget))
     {
       gtk_notebook_paint (widget, &event->area);
       if (notebook->show_tabs)
        {
-         if (notebook->cur_page && 
-             gtk_widget_intersect (notebook->cur_page->tab_label, 
-                                   &event->area, &child_area))
-           gtk_notebook_draw_focus (widget);
+         GtkNotebookPage *page;
+         GList *pages;
+
+         gtk_notebook_draw_focus (widget, event);
+         pages = notebook->children;
+
+         while (pages)
+           {
+             page = GTK_NOTEBOOK_PAGE (pages);
+             pages = pages->next;
+
+             if (page->tab_label->window == event->window &&
+                 GTK_WIDGET_DRAWABLE (page->tab_label))
+               gtk_container_propagate_expose (GTK_CONTAINER (notebook),
+                                               page->tab_label, event);
+           }
        }
 
-      
       if (notebook->cur_page)
        gtk_container_propagate_expose (GTK_CONTAINER (notebook),
                                        notebook->cur_page->child,
@@ -2154,6 +2335,8 @@ gtk_notebook_do_arrow (GtkNotebook     *notebook,
        dir = ARROW_IS_LEFT (arrow) ? GTK_DIR_UP : GTK_DIR_DOWN;
       else
        dir = ARROW_IS_LEFT (arrow) ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
+
+      gtk_widget_grab_focus (widget);
       gtk_widget_child_focus (widget, dir);
     }
 }
@@ -2242,7 +2425,7 @@ gtk_notebook_scroll (GtkWidget      *widget,
   originator = gtk_get_event_widget ((GdkEvent *)event);
 
   /* ignore scroll events from the content of the page */
-  if (!originator || gtk_widget_is_ancestor (originator, child))
+  if (!originator || gtk_widget_is_ancestor (originator, child) || originator == child)
     return FALSE;
   
   switch (event->direction)
@@ -2325,21 +2508,29 @@ gtk_notebook_button_press (GtkWidget      *widget,
       page = tab->data;
       page_changed = page != notebook->cur_page;
       was_focus = gtk_widget_is_focus (widget);
-         
+
       gtk_notebook_switch_focus_tab (notebook, tab);
       gtk_widget_grab_focus (widget);
-         
+
       if (page_changed && !was_focus)
        gtk_widget_child_focus (page->child, GTK_DIR_TAB_FORWARD);
-         
+
       /* save press to possibly begin a drag */
       if (page->reorderable || page->detachable)
        {
          priv->during_detach = FALSE;
+         priv->during_reorder = FALSE;
          priv->pressed_button = event->button;
 
-         priv->mouse_x = x - widget->allocation.x;
-         priv->mouse_y = y - widget->allocation.y;
+         gdk_window_get_pointer (widget->window,
+                                 &priv->mouse_x,
+                                 &priv->mouse_y,
+                                 NULL);
+
+         priv->drag_begin_x = priv->mouse_x;
+         priv->drag_begin_y = priv->mouse_y;
+         priv->drag_offset_x = priv->drag_begin_x - page->allocation.x;
+         priv->drag_offset_y = priv->drag_begin_y - page->allocation.y;
        }
     }
 
@@ -2424,8 +2615,8 @@ get_drop_position (GtkNotebook *notebook,
   gint x, y;
 
   priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
-  x = priv->mouse_x + GTK_WIDGET (notebook)->allocation.x;
-  y = priv->mouse_y + GTK_WIDGET (notebook)->allocation.y;
+  x = priv->mouse_x;
+  y = priv->mouse_y;
 
   is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
   children = notebook->children;
@@ -2545,7 +2736,6 @@ hide_drag_window (GtkNotebook        *notebook,
       else
        gtk_widget_unparent (page->tab_label);
 
-      gtk_widget_set_parent_window (page->tab_label, widget->window);
       gtk_widget_set_parent (page->tab_label, widget);
       g_object_unref (page->tab_label);
     }
@@ -2555,44 +2745,43 @@ hide_drag_window (GtkNotebook        *notebook,
     gdk_window_hide (priv->drag_window);
 }
 
-static gint
-gtk_notebook_button_release (GtkWidget      *widget,
-                            GdkEventButton *event)
+static void
+gtk_notebook_stop_reorder (GtkNotebook *notebook)
 {
-  GtkNotebook *notebook;
   GtkNotebookPrivate *priv;
   GtkNotebookPage *page;
-  GList *element;
-  gint old_page_num, page_num;
 
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
+  priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
 
-  if (event->type != GDK_BUTTON_RELEASE)
-    return FALSE;
+  if (priv->operation == DRAG_OPERATION_DETACH)
+    page = priv->detached_tab;
+  else
+    page = notebook->cur_page;
 
-  notebook = GTK_NOTEBOOK (widget);
-  priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
-  page = notebook->cur_page;
+  if (!page || !page->tab_label)
+    return;
 
-  if (page->reorderable &&
-      event->button == priv->pressed_button)
-    {
-      priv->pressed_button = -1;
+  priv->pressed_button = -1;
 
-      if (!priv->during_detach)
+  if (page->reorderable || page->detachable)
+    {
+      if (priv->during_reorder)
        {
+         gint old_page_num, page_num;
+         GList *element;
+
          element = get_drop_position (notebook, page->pack);
          old_page_num = g_list_position (notebook->children, notebook->focus_tab);
          page_num = reorder_tab (notebook, element, notebook->focus_tab);
-
-         if (priv->has_scrolled ||
-             old_page_num != page_num)
+          gtk_notebook_child_reordered (notebook, page);
+          
+         if (priv->has_scrolled || old_page_num != page_num)
            g_signal_emit (notebook,
                           notebook_signals[PAGE_REORDERED], 0,
                           page->child, page_num);
 
          priv->has_scrolled = FALSE;
+          priv->during_reorder = FALSE; 
        }
 
       hide_drag_window (notebook, priv, page);
@@ -2606,43 +2795,35 @@ gtk_notebook_button_release (GtkWidget      *widget,
          priv->dnd_timer = 0;
        }
     }
-
-  if (event->button == notebook->button)
-    {
-      stop_scrolling (notebook);
-      return TRUE;
-    }
-  else
-    return FALSE;
 }
 
 static gint
-gtk_notebook_enter_notify (GtkWidget        *widget,
-                          GdkEventCrossing *event)
+gtk_notebook_button_release (GtkWidget      *widget,
+                            GdkEventButton *event)
 {
   GtkNotebook *notebook;
-  GtkNotebookArrow arrow;
-  gint x, y;
+  GtkNotebookPrivate *priv;
+  GtkNotebookPage *page;
 
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
+  if (event->type != GDK_BUTTON_RELEASE)
+    return FALSE;
 
   notebook = GTK_NOTEBOOK (widget);
+  priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
+  page = notebook->cur_page;
 
-  if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
-    return FALSE;
-
-  arrow = gtk_notebook_get_arrow (notebook, x, y);
+  if (!priv->during_detach &&
+      page->reorderable &&
+      event->button == priv->pressed_button)
+    gtk_notebook_stop_reorder (notebook);
 
-  if (arrow != notebook->in_child)
+  if (event->button == notebook->button)
     {
-      notebook->in_child = arrow;
-      gtk_notebook_redraw_arrows (notebook);
-
+      stop_scrolling (notebook);
       return TRUE;
     }
-
-  return TRUE;
+  else
+    return FALSE;
 }
 
 static gint
@@ -2678,20 +2859,26 @@ get_pointer_position (GtkNotebook *notebook)
   if (notebook->tab_pos == GTK_POS_TOP ||
       notebook->tab_pos == GTK_POS_BOTTOM)
     {
+      gint x;
+
       is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
+      x = priv->mouse_x - widget->allocation.x;
 
-      if (priv->mouse_x > widget->allocation.width - 2 * container->border_width - SCROLL_THRESHOLD)
+      if (x > widget->allocation.width - 2 * container->border_width - SCROLL_THRESHOLD)
        return (is_rtl) ? POINTER_BEFORE : POINTER_AFTER;
-      else if (priv->mouse_x < SCROLL_THRESHOLD + container->border_width)
+      else if (x < SCROLL_THRESHOLD + container->border_width)
        return (is_rtl) ? POINTER_AFTER : POINTER_BEFORE;
       else
        return POINTER_BETWEEN;
     }
   else
     {
-      if (priv->mouse_y > widget->allocation.height - 2 * container->border_width - SCROLL_THRESHOLD)
+      gint y;
+
+      y = priv->mouse_y - widget->allocation.y;
+      if (y > widget->allocation.height - 2 * container->border_width - SCROLL_THRESHOLD)
        return POINTER_AFTER;
-      else if (priv->mouse_y < SCROLL_THRESHOLD + container->border_width)
+      else if (y < SCROLL_THRESHOLD + container->border_width)
        return POINTER_BEFORE;
       else
        return POINTER_BETWEEN;
@@ -2768,26 +2955,44 @@ gtk_notebook_motion_notify (GtkWidget      *widget,
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
   GtkNotebookPage *page;
+  GtkNotebookArrow arrow;
   GtkNotebookPointerPosition pointer_position;
   GtkSettings *settings;
   guint timeout;
 
-  if (priv->pressed_button == -1)
+  page = notebook->cur_page;
+
+  if (!page)
     return FALSE;
 
-  if (!notebook->cur_page)
+  if (!(event->state & GDK_BUTTON1_MASK) &&
+      priv->pressed_button != -1)
+    {
+      gtk_notebook_stop_reorder (notebook);
+      stop_scrolling (notebook);
+    }
+
+  if (event->time < priv->timestamp + MSECS_BETWEEN_UPDATES)
     return FALSE;
 
-  page = notebook->cur_page;
+  priv->timestamp = event->time;
+  gdk_window_get_pointer (widget->window,
+                         &priv->mouse_x,
+                         &priv->mouse_y,
+                         NULL);
 
-  get_widget_coordinates (widget, (GdkEvent*) event, &priv->mouse_x, &priv->mouse_y);
-  priv->mouse_x -= widget->allocation.x;
-  priv->mouse_y -= widget->allocation.y;
+  arrow = gtk_notebook_get_arrow (notebook, priv->mouse_x, priv->mouse_y);
+  if (arrow != notebook->in_child)
+    {
+      notebook->in_child = arrow;
+      gtk_notebook_redraw_arrows (notebook);
+    }
+
+  if (priv->pressed_button == -1)
+    return FALSE;
 
   if (page->detachable &&
-      check_threshold (notebook,
-                      priv->mouse_x + widget->allocation.x,
-                      priv->mouse_y + widget->allocation.y))
+      check_threshold (notebook, priv->mouse_x, priv->mouse_y))
     {
       priv->detached_tab = notebook->cur_page;
       priv->during_detach = TRUE;
@@ -2797,8 +3002,11 @@ gtk_notebook_motion_notify (GtkWidget      *widget,
       return TRUE;
     }
 
-  if (page->reorderable)
+  if (page->reorderable &&
+      (priv->during_reorder ||
+       gtk_drag_check_threshold (widget, priv->drag_begin_x, priv->drag_begin_y, priv->mouse_x, priv->mouse_y)))
     {
+      priv->during_reorder = TRUE;
       pointer_position = get_pointer_position (notebook);
 
       if (event->window == priv->drag_window &&
@@ -2812,8 +3020,8 @@ gtk_notebook_motion_notify (GtkWidget      *widget,
              settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
              g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
 
-             priv->dnd_timer = g_timeout_add (timeout * SCROLL_DELAY_FACTOR,
-                                              (GSourceFunc) scroll_notebook_timer, 
+             priv->dnd_timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
+                                              scroll_notebook_timer, 
                                               (gpointer) notebook);
            }
        }
@@ -2832,8 +3040,8 @@ gtk_notebook_motion_notify (GtkWidget      *widget,
          /* the drag operation is beginning, create the window */
          if (priv->operation != DRAG_OPERATION_REORDER)
            {
-             show_drag_window (notebook, priv, page);
              priv->operation = DRAG_OPERATION_REORDER;
+             show_drag_window (notebook, priv, page);
            }
 
          gtk_notebook_pages_allocate (notebook);
@@ -2852,8 +3060,13 @@ static void
 gtk_notebook_grab_notify (GtkWidget *widget,
                          gboolean   was_grabbed)
 {
+  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+
   if (!was_grabbed)
-    stop_scrolling (GTK_NOTEBOOK (widget));
+    {
+      gtk_notebook_stop_reorder (notebook);
+      stop_scrolling (notebook);
+    }
 }
 
 static void
@@ -2885,27 +3098,35 @@ gtk_notebook_focus_out (GtkWidget     *widget,
 }
 
 static void
-gtk_notebook_draw_focus (GtkWidget *widget)
+gtk_notebook_draw_focus (GtkWidget      *widget,
+                        GdkEventExpose *event)
 {
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
 
-  if (GTK_WIDGET_DRAWABLE (widget) && notebook->show_tabs &&
-      notebook->focus_tab)
+  if (GTK_WIDGET_HAS_FOCUS (widget) && GTK_WIDGET_DRAWABLE (widget) &&
+      notebook->show_tabs && notebook->cur_page &&
+      notebook->cur_page->tab_label->window == event->window)
     {
       GtkNotebookPage *page;
-      GdkRectangle area;
-      gint focus_width;
-      
-      gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
 
-      page = notebook->focus_tab->data;
+      page = notebook->cur_page;
 
-      area.x = page->tab_label->allocation.x - focus_width;
-      area.y = page->tab_label->allocation.y - focus_width;
-      area.width = page->tab_label->allocation.width + 2 * focus_width;
-      area.height = page->tab_label->allocation.height + 2 * focus_width;
+      if (gtk_widget_intersect (page->tab_label, &event->area, NULL))
+        {
+          GdkRectangle area;
+          gint focus_width;
 
-      gtk_notebook_draw_tab (GTK_NOTEBOOK (widget), page, &area);
+          gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
+
+          area.x = page->tab_label->allocation.x - focus_width;
+          area.y = page->tab_label->allocation.y - focus_width;
+          area.width = page->tab_label->allocation.width + 2 * focus_width;
+          area.height = page->tab_label->allocation.height + 2 * focus_width;
+
+         gtk_paint_focus (widget->style, event->window, 
+                           GTK_WIDGET_STATE (widget), NULL, widget, "tab",
+                          area.x, area.y, area.width, area.height);
+        }
     }
 }
 
@@ -2969,8 +3190,7 @@ gtk_notebook_drag_begin (GtkWidget        *widget,
 {
   GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
   GtkNotebook *notebook = (GtkNotebook*) widget;
-  GtkWidget *tab_label, *window;
-  gint width, height;
+  GtkWidget *tab_label;
 
   if (priv->dnd_timer)
     {
@@ -2978,25 +3198,87 @@ gtk_notebook_drag_begin (GtkWidget        *widget,
       priv->dnd_timer = 0;
     }
 
+  priv->operation = DRAG_OPERATION_DETACH;
+  gtk_notebook_pages_allocate (notebook);
+
   tab_label = priv->detached_tab->tab_label;
-  gdk_drawable_get_size (priv->drag_window, &width, &height);
 
   hide_drag_window (notebook, priv, notebook->cur_page);
   g_object_ref (tab_label);
   gtk_widget_unparent (tab_label);
 
-  window = gtk_window_new (GTK_WINDOW_POPUP);
-  gtk_container_add (GTK_CONTAINER (window), tab_label);
-  gtk_widget_set_size_request (window, width, height);
+  priv->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);
+  gtk_container_add (GTK_CONTAINER (priv->dnd_window), tab_label);
+  gtk_widget_set_size_request (priv->dnd_window,
+                              priv->detached_tab->allocation.width,
+                              priv->detached_tab->allocation.height);
   g_object_unref (tab_label);
 
-  g_signal_connect (G_OBJECT (window), "expose-event",
+  g_signal_connect (G_OBJECT (priv->dnd_window), "expose-event",
                    G_CALLBACK (on_drag_icon_expose), notebook);
 
-  gtk_drag_set_icon_widget (context, window, -2, -2);
+  gtk_drag_set_icon_widget (context, priv->dnd_window, -2, -2);
+}
 
-  priv->operation = DRAG_OPERATION_DETACH;
-  gtk_notebook_pages_allocate (notebook);
+static void
+gtk_notebook_drag_end (GtkWidget      *widget,
+                      GdkDragContext *context)
+{
+  GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
+
+  gtk_notebook_stop_reorder (GTK_NOTEBOOK (widget));
+
+  if (priv->detached_tab)
+    gtk_notebook_switch_page (GTK_NOTEBOOK (widget), priv->detached_tab);
+
+  GTK_BIN (priv->dnd_window)->child = NULL;
+  gtk_widget_destroy (priv->dnd_window);
+  priv->dnd_window = NULL;
+
+  priv->operation = DRAG_OPERATION_NONE;
+}
+
+static GtkNotebook *
+gtk_notebook_create_window (GtkNotebook *notebook,
+                            GtkWidget   *page,
+                            gint         x,
+                            gint         y)
+{
+  if (window_creation_hook)
+    return (* window_creation_hook) (notebook, page, x, y, window_creation_hook_data);
+
+  return NULL;
+}
+
+static gboolean
+gtk_notebook_drag_failed (GtkWidget      *widget,
+                         GdkDragContext *context,
+                         GtkDragResult   result,
+                         gpointer        data)
+{
+  if (result == GTK_DRAG_RESULT_NO_TARGET)
+    {
+      GtkNotebookPrivate *priv;
+      GtkNotebook *notebook, *dest_notebook = NULL;
+      GdkDisplay *display;
+      gint x, y;
+
+      notebook = GTK_NOTEBOOK (widget);
+      priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
+
+      display = gtk_widget_get_display (widget);
+      gdk_display_get_pointer (display, NULL, &x, &y, NULL);
+
+      g_signal_emit (notebook, notebook_signals[CREATE_WINDOW], 0,
+                     priv->detached_tab->child, x, y, &dest_notebook);
+
+      if (dest_notebook)
+       do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
+
+      return TRUE;
+    }
+
+  return FALSE;
 }
 
 static gboolean
@@ -3049,6 +3331,7 @@ gtk_notebook_drag_motion (GtkWidget      *widget,
     {
       notebook->click_child = arrow;
       gtk_notebook_set_scroll_timer (notebook);
+      gdk_drag_status (context, 0, time);
       return TRUE;
     }
 
@@ -3058,35 +3341,35 @@ gtk_notebook_drag_motion (GtkWidget      *widget,
 
   if (target == tab_target)
     {
-      gint widget_group, source_widget_group;
+      gpointer widget_group, source_widget_group;
       GtkWidget *source_widget;
 
       source_widget = gtk_drag_get_source_widget (context);
       g_assert (source_widget);
 
-      widget_group = gtk_notebook_get_group_id (notebook);
-      source_widget_group = gtk_notebook_get_group_id (GTK_NOTEBOOK (source_widget));
+      widget_group = gtk_notebook_get_group (notebook);
+      source_widget_group = gtk_notebook_get_group (GTK_NOTEBOOK (source_widget));
 
-      if (widget_group != -1 &&
-         source_widget_group != -1 &&
-         widget_group == source_widget_group)
+      if (widget_group && source_widget_group &&
+         widget_group == source_widget_group &&
+         !(widget == GTK_NOTEBOOK (source_widget)->cur_page->child || 
+           gtk_widget_is_ancestor (widget, GTK_NOTEBOOK (source_widget)->cur_page->child)))
        {
          gdk_drag_status (context, GDK_ACTION_MOVE, time);
          return TRUE;
        }
+      else
+       {
+         /* it's a tab, but doesn't share
+          * ID with this notebook */
+         gdk_drag_status (context, 0, time);
+       }
     }
 
   priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
   x += widget->allocation.x;
   y += widget->allocation.y;
 
-  if (target == tab_target)
-    {
-      /* it's a tab, but doesn't share
-       * ID with this notebook */
-      gdk_drag_status (context, 0, time);
-    }
-
   if (gtk_notebook_get_event_window_position (notebook, &position) &&
       x >= position.x && x <= position.x + position.width &&
       y >= position.y && y <= position.y + position.height)
@@ -3099,8 +3382,8 @@ gtk_notebook_drag_motion (GtkWidget      *widget,
           settings = gtk_widget_get_settings (widget);
 
           g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
-         priv->switch_tab_timer = g_timeout_add (timeout,
-                                                 (GSourceFunc) gtk_notebook_switch_tab_timeout,
+         priv->switch_tab_timer = gdk_threads_add_timeout (timeout,
+                                                 gtk_notebook_switch_tab_timeout,
                                                  widget);
        }
     }
@@ -3113,7 +3396,7 @@ gtk_notebook_drag_motion (GtkWidget      *widget,
        }
     }
 
-  return TRUE;
+  return (target == tab_target) ? TRUE : FALSE;
 }
 
 static void
@@ -3141,14 +3424,18 @@ gtk_notebook_drag_drop (GtkWidget        *widget,
                        gint              y,
                        guint             time)
 {
-  GdkAtom target;
+  GdkAtom target, tab_target;
 
   target = gtk_drag_dest_find_target (widget, context, NULL);
+  tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
 
-  if (target == GDK_NONE)
-    gtk_drag_finish (context, FALSE, FALSE, time);
+  if (target == tab_target)
+    {
+      gtk_drag_get_data (widget, context, target, time);
+      return TRUE;
+    }
 
-  return TRUE;
+  return FALSE;
 }
 
 static void
@@ -3189,8 +3476,8 @@ do_detach_tab (GtkNotebook     *from,
   gtk_container_remove (GTK_CONTAINER (from), child);
 
   priv = GTK_NOTEBOOK_GET_PRIVATE (to);
-  priv->mouse_x = x;
-  priv->mouse_y = y;
+  priv->mouse_x = x + GTK_WIDGET (to)->allocation.x;
+  priv->mouse_y = y + GTK_WIDGET (to)->allocation.y;
 
   element = get_drop_position (to, tab_pack);
   page_num = g_list_position (to->children, element);
@@ -3222,40 +3509,18 @@ gtk_notebook_drag_data_get (GtkWidget        *widget,
                            guint             info,
                            guint             time)
 {
-  GtkNotebook *dest_notebook, *notebook;
   GtkNotebookPrivate *priv;
 
-  if (data->target != gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB") &&
-      (data->target != gdk_atom_intern_static_string ("application/x-rootwindow-drop") ||
-       !window_creation_hook))
-    return;
-
-  notebook = GTK_NOTEBOOK (widget);
-  priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
-
   if (data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
     {
+      priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
+
       gtk_selection_data_set (data,
                              data->target,
                              8,
                              (void*) &priv->detached_tab->child,
                              sizeof (gpointer));
     }
-  else
-    {
-      GdkDisplay *display;
-      gint x, y;
-
-      display = gtk_widget_get_display (widget);
-      gdk_display_get_pointer (display, NULL, &x, &y, NULL);
-
-      dest_notebook = (* window_creation_hook) (notebook,
-                                               priv->detached_tab->child,
-                                               x, y,
-                                               window_creation_hook_data);
-      if (dest_notebook)
-       do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
-    }
 }
 
 static void
@@ -3395,7 +3660,7 @@ gtk_notebook_get_child_property (GtkContainer    *container,
     case CHILD_PROP_TAB_LABEL:
       label = gtk_notebook_get_tab_label (notebook, child);
 
-      if (label && GTK_IS_LABEL (label))
+      if (GTK_IS_LABEL (label))
        g_value_set_string (value, GTK_LABEL (label)->label);
       else
        g_value_set_string (value, NULL);
@@ -3403,7 +3668,7 @@ gtk_notebook_get_child_property (GtkContainer    *container,
     case CHILD_PROP_MENU_LABEL:
       label = gtk_notebook_get_menu_label (notebook, child);
 
-      if (label && GTK_IS_LABEL (label))
+      if (GTK_IS_LABEL (label))
        g_value_set_string (value, GTK_LABEL (label)->label);
       else
        g_value_set_string (value, NULL);
@@ -3444,8 +3709,6 @@ static void
 gtk_notebook_add (GtkContainer *container,
                  GtkWidget    *widget)
 {
-  g_return_if_fail (GTK_IS_NOTEBOOK (container));
-
   gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget, 
                                 NULL, NULL, -1);
 }
@@ -3459,9 +3722,6 @@ gtk_notebook_remove (GtkContainer *container,
   GList *children;
   gint page_num = 0;
 
-  g_return_if_fail (GTK_IS_NOTEBOOK (container));
-  g_return_if_fail (widget != NULL);
-
   notebook = GTK_NOTEBOOK (container);
 
   children = notebook->children;
@@ -3518,11 +3778,24 @@ focus_tabs_move (GtkNotebook     *notebook,
 
   new_page = gtk_notebook_search_page (notebook, notebook->focus_tab,
                                       search_direction, TRUE);
+  if (!new_page)
+    {
+      gboolean wrap_around;
+
+      g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
+                    "gtk-keynav-wrap-around", &wrap_around,
+                    NULL);
+
+      if (wrap_around)
+        new_page = gtk_notebook_search_page (notebook, NULL,
+                                             search_direction, TRUE);
+    }
+
   if (new_page)
     gtk_notebook_switch_focus_tab (notebook, new_page);
   else
-    gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (notebook)));
-  
+    gtk_widget_error_bell (GTK_WIDGET (notebook));
+
   return TRUE;
 }
 
@@ -3550,8 +3823,6 @@ gtk_notebook_focus (GtkWidget        *widget,
   gboolean widget_is_focus;
   GtkContainer *container;
 
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
-
   container = GTK_CONTAINER (widget);
   notebook = GTK_NOTEBOOK (container);
 
@@ -3705,9 +3976,6 @@ gtk_notebook_forall (GtkContainer *container,
   GtkNotebook *notebook;
   GList *children;
 
-  g_return_if_fail (GTK_IS_NOTEBOOK (container));
-  g_return_if_fail (callback != NULL);
-
   notebook = GTK_NOTEBOOK (container);
 
   children = notebook->children;
@@ -3759,7 +4027,7 @@ page_visible_cb (GtkWidget  *page,
         }
 
       if (next)
-        gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next), -1);
+        gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next));
     }
 }
 
@@ -3773,28 +4041,11 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
   GtkNotebookPage *page;
   gint nchildren;
 
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
-  g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
-  g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
-  g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
-
   gtk_widget_freeze_child_notify (child);
-  
-  page = g_new (GtkNotebookPage, 1);
+
+  page = g_slice_new0 (GtkNotebookPage);
   page->child = child;
-  page->last_focus_child = NULL;
-  page->requisition.width = 0;
-  page->requisition.height = 0;
-  page->allocation.x = 0;
-  page->allocation.y = 0;
-  page->allocation.width = 0;
-  page->allocation.height = 0;
-  page->default_menu = FALSE;
-  page->default_tab = FALSE;
-  page->mnemonic_activate_signal = 0;
-  page->reorderable = FALSE;
-  page->detachable = FALSE;
-   
+
   nchildren = g_list_length (notebook->children);
   if ((position < 0) || (position > nchildren))
     position = nchildren;
@@ -3805,7 +4056,7 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
     {
       page->default_tab = TRUE;
       if (notebook->show_tabs)
-       tab_label = gtk_label_new ("");
+       tab_label = gtk_label_new (NULL);
     }
   page->tab_label = tab_label;
   page->menu_label = menu_label;
@@ -3816,9 +4067,7 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
   if (!menu_label)
     page->default_menu = TRUE;
   else  
-    {
-      g_object_ref_sink (page->menu_label);
-    }
+    g_object_ref_sink (page->menu_label);
 
   if (notebook->menu)
     gtk_notebook_menu_item_create (notebook,
@@ -3834,8 +4083,9 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
     notebook->first_tab = notebook->children;
 
   /* child visible will be turned on by switch_page below */
-  gtk_widget_set_child_visible (child, FALSE);
-  
+  if (notebook->cur_page != page)
+    gtk_widget_set_child_visible (child, FALSE);
+
   if (tab_label)
     {
       if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
@@ -3861,8 +4111,9 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
 
   if (!notebook->cur_page)
     {
-      gtk_notebook_switch_page (notebook, page, 0);
-      gtk_notebook_switch_focus_tab (notebook, NULL);
+      gtk_notebook_switch_page (notebook, page);
+      /* focus_tab is set in the switch_page method */
+      gtk_notebook_switch_focus_tab (notebook, notebook->focus_tab);
     }
 
   gtk_notebook_update_tab_states (notebook);
@@ -3875,7 +4126,8 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
   gtk_widget_child_notify (child, "position");
   gtk_widget_thaw_child_notify (child);
 
-  return position;
+  /* The page-added handler might have reordered the pages, re-get the position */
+  return gtk_notebook_page_num (notebook, child);
 }
 
 /* Private GtkNotebook Functions:
@@ -3947,68 +4199,6 @@ gtk_notebook_redraw_tabs (GtkNotebook *notebook)
   gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
 }
 
-static void
-gtk_notebook_redraw_tabs_union (GtkNotebook *notebook)
-{
-  GtkWidget *widget;
-  GtkNotebookPage *page;
-  GdkRectangle redraw_rect;
-  gint border;
-  gint tab_pos = get_effective_tab_pos (notebook);
-
-  widget = GTK_WIDGET (notebook);
-  border = GTK_CONTAINER (notebook)->border_width;
-
-  if (!GTK_WIDGET_MAPPED (notebook) || !notebook->first_tab)
-    return;
-
-  page = GTK_NOTEBOOK_PAGE (notebook->first_tab);
-
-  redraw_rect.x = border;
-  redraw_rect.y = border;
-
-  switch (tab_pos)
-    {
-    case GTK_POS_TOP:
-      redraw_rect.x = border;
-      redraw_rect.y = page->allocation.height + border;
-      break;
-    case GTK_POS_BOTTOM:
-      redraw_rect.x = border;
-      redraw_rect.y = widget->allocation.height - border -
-       page->allocation.height - widget->style->ythickness;
-      break;
-    case GTK_POS_RIGHT:
-      redraw_rect.x = widget->allocation.width - border -
-       page->allocation.width - widget->style->xthickness;
-      redraw_rect.y = border;
-      break;
-    case GTK_POS_LEFT:
-      redraw_rect.x = page->allocation.width + border;
-      redraw_rect.y = border;
-      break;
-    }
-
-  switch (tab_pos)
-    {
-    case GTK_POS_TOP:
-    case GTK_POS_BOTTOM:
-      redraw_rect.width = widget->allocation.width - 2 * border;
-      redraw_rect.height = widget->style->ythickness;
-      break;
-    case GTK_POS_RIGHT:
-    case GTK_POS_LEFT:
-      redraw_rect.width = widget->style->xthickness;
-      redraw_rect.height = widget->allocation.height - 2 * border;
-      break;
-    }
-
-  redraw_rect.x += widget->allocation.x;
-  redraw_rect.y += widget->allocation.y;
-
-  gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
-}
-
 static void
 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
 {
@@ -4035,13 +4225,11 @@ gtk_notebook_redraw_arrows (GtkNotebook *notebook)
     }
 }
 
-static gint
+static gboolean
 gtk_notebook_timer (GtkNotebook *notebook)
 {
   gboolean retval = FALSE;
 
-  GDK_THREADS_ENTER ();
-
   if (notebook->timer)
     {
       gtk_notebook_do_arrow (notebook, notebook->click_child);
@@ -4055,7 +4243,7 @@ gtk_notebook_timer (GtkNotebook *notebook)
           g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
 
          notebook->need_timer = FALSE;
-         notebook->timer = g_timeout_add (timeout * SCROLL_DELAY_FACTOR,
+         notebook->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
                                           (GSourceFunc) gtk_notebook_timer,
                                           (gpointer) notebook);
        }
@@ -4063,8 +4251,6 @@ gtk_notebook_timer (GtkNotebook *notebook)
        retval = TRUE;
     }
 
-  GDK_THREADS_LEAVE ();
-
   return retval;
 }
 
@@ -4080,7 +4266,7 @@ gtk_notebook_set_scroll_timer (GtkNotebook *notebook)
 
       g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
 
-      notebook->timer = g_timeout_add (timeout,
+      notebook->timer = gdk_threads_add_timeout (timeout,
                                       (GSourceFunc) gtk_notebook_timer,
                                       (gpointer) notebook);
       notebook->need_timer = TRUE;
@@ -4132,25 +4318,33 @@ static void
 gtk_notebook_real_remove (GtkNotebook *notebook,
                          GList       *list)
 {
+  GtkNotebookPrivate *priv;
   GtkNotebookPage *page;
   GList * next_list;
   gint need_resize = FALSE;
+  GtkWidget *tab_label;
 
   gboolean destroying;
 
+  priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
   destroying = GTK_OBJECT_FLAGS (notebook) & GTK_IN_DESTRUCTION;
   
-  next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
+  next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
   if (!next_list)
-    next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
+    next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
+
+  notebook->children = g_list_remove_link (notebook->children, list);
 
   if (notebook->cur_page == list->data)
     { 
       notebook->cur_page = NULL;
       if (next_list && !destroying)
-       gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list), -1);
+       gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list));
     }
 
+  if (priv->detached_tab == list->data)
+    priv->detached_tab = NULL;
+
   if (list == notebook->first_tab)
     notebook->first_tab = next_list;
   if (list == notebook->focus_tab && !destroying)
@@ -4165,8 +4359,16 @@ gtk_notebook_real_remove (GtkNotebook *notebook,
 
   gtk_widget_unparent (page->child);
 
-  gtk_notebook_remove_tab_label (notebook, page);
-  
+  tab_label = page->tab_label;
+  if (tab_label)
+    {
+      g_object_ref (tab_label);
+      gtk_notebook_remove_tab_label (notebook, page);
+      if (destroying)
+        gtk_widget_destroy (tab_label);
+      g_object_unref (tab_label);
+    } 
+
   if (notebook->menu)
     {
       gtk_container_remove (GTK_CONTAINER (notebook->menu), 
@@ -4176,7 +4378,6 @@ gtk_notebook_real_remove (GtkNotebook *notebook,
   if (!page->default_menu)
     g_object_unref (page->menu_label);
   
-  notebook->children = g_list_remove_link (notebook->children, list);
   g_list_free (list);
 
   if (page->last_focus_child)
@@ -4185,7 +4386,7 @@ gtk_notebook_real_remove (GtkNotebook *notebook,
       page->last_focus_child = NULL;
     }
   
-  g_free (page);
+  g_slice_free (GtkNotebookPage, page);
 
   gtk_notebook_update_labels (notebook);
   if (need_resize)
@@ -4200,6 +4401,9 @@ gtk_notebook_update_labels (GtkNotebook *notebook)
   gchar string[32];
   gint page_num = 1;
 
+  if (!notebook->show_tabs && !notebook->menu)
+    return;
+
   for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
        list;
        list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
@@ -4229,9 +4433,9 @@ gtk_notebook_update_labels (GtkNotebook *notebook)
        }
       if (notebook->menu && page->default_menu)
        {
-         if (page->tab_label && GTK_IS_LABEL (page->tab_label))
+         if (GTK_IS_LABEL (page->tab_label))
            gtk_label_set_text (GTK_LABEL (page->menu_label),
-                          GTK_LABEL (page->tab_label)->label);
+                                GTK_LABEL (page->tab_label)->label);
          else
            gtk_label_set_text (GTK_LABEL (page->menu_label), string);
        }
@@ -4245,9 +4449,6 @@ gtk_notebook_real_page_position (GtkNotebook *notebook,
   GList *work;
   gint count_start;
 
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
-  g_return_val_if_fail (list != NULL, -1);
-
   for (work = notebook->children, count_start = 0;
        work && work != list; work = work->next)
     if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
@@ -4272,8 +4473,6 @@ gtk_notebook_search_page (GtkNotebook *notebook,
   GList *old_list = NULL;
   gint flag = 0;
 
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
-
   switch (direction)
     {
     case STEP_PREV:
@@ -4352,9 +4551,6 @@ gtk_notebook_paint (GtkWidget    *widget,
   gboolean is_rtl;
   gint tab_pos;
    
-  g_return_if_fail (GTK_IS_NOTEBOOK (widget));
-  g_return_if_fail (area != NULL);
-
   if (!GTK_WIDGET_DRAWABLE (widget))
     return;
 
@@ -4384,8 +4580,7 @@ gtk_notebook_paint (GtkWidget    *widget,
   if (!notebook->first_tab)
     notebook->first_tab = notebook->children;
 
-  if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) ||
-      !GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
+  if (!GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
     page = GTK_NOTEBOOK_PAGE (notebook->first_tab);
   else
     page = notebook->cur_page;
@@ -4409,10 +4604,8 @@ gtk_notebook_paint (GtkWidget    *widget,
   if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) ||
       !GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
     {
-      gtk_paint_box (widget->style, widget->window,
-                    GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-                    area, widget, "notebook",
-                    x, y, width, height);
+      gap_x = 0;
+      gap_width = 0;
     }
   else
     {
@@ -4439,13 +4632,12 @@ gtk_notebook_paint (GtkWidget    *widget,
          step = STEP_PREV;
          break;
        }
-
-      gtk_paint_box_gap (widget->style, widget->window,
-                        GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-                        area, widget, "notebook",
-                        x, y, width, height,
-                        tab_pos, gap_x, gap_width);
     }
+  gtk_paint_box_gap (widget->style, widget->window,
+                    GTK_STATE_NORMAL, GTK_SHADOW_OUT,
+                    area, widget, "notebook",
+                    x, y, width, height,
+                    tab_pos, gap_x, gap_width);
 
   showarrow = FALSE;
   children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
@@ -4489,10 +4681,6 @@ gtk_notebook_draw_tab (GtkNotebook     *notebook,
   GdkWindow *window;
   GtkWidget *widget;
   
-  g_return_if_fail (notebook != NULL);
-  g_return_if_fail (page != NULL);
-  g_return_if_fail (area != NULL);
-
   if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
       !GTK_WIDGET_MAPPED (page->tab_label) ||
       (page->allocation.width == 0) || (page->allocation.height == 0))
@@ -4526,37 +4714,6 @@ gtk_notebook_draw_tab (GtkNotebook     *notebook,
                           page_area.x, page_area.y,
                           page_area.width, page_area.height,
                           gap_side);
-
-      if ((GTK_WIDGET_HAS_FOCUS (widget)) &&
-         notebook->focus_tab && (notebook->focus_tab->data == page))
-       {
-          gint focus_width;
-
-         gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
-
-         gtk_paint_focus (widget->style, window, GTK_WIDGET_STATE (widget),
-                          area, widget, "tab",
-                          page->tab_label->allocation.x - focus_width,
-                          page->tab_label->allocation.y - focus_width,
-                          page->tab_label->allocation.width + 2 * focus_width,
-                          page->tab_label->allocation.height + 2 * focus_width);
-       }
-
-      if (gtk_widget_intersect (page->tab_label, area, &child_area) &&
-          GTK_WIDGET_DRAWABLE (page->tab_label))
-        {
-          GdkEvent *expose_event = gdk_event_new (GDK_EXPOSE);
-
-          /* This is a lame hack since all this code needs rewriting anyhow */
-          expose_event->expose.window = g_object_ref (page->tab_label->window);
-          expose_event->expose.area = child_area;
-          expose_event->expose.region = gdk_region_rectangle (&child_area);
-          expose_event->expose.send_event = TRUE;
-          expose_event->expose.count = 0;
-
-         gtk_widget_send_expose (page->tab_label, expose_event);
-         gdk_event_free (expose_event);
-       }
     }
 }
 
@@ -4571,20 +4728,20 @@ gtk_notebook_draw_arrow (GtkNotebook      *notebook,
   GtkArrowType arrow;
   gboolean is_rtl, left;
 
-  gtk_notebook_get_arrow_rect (notebook, &arrow_rect, nbarrow);
-
-  widget = GTK_WIDGET (notebook);
-
-  is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
-  left = (ARROW_IS_LEFT (nbarrow) && !is_rtl) ||
-         (!ARROW_IS_LEFT (nbarrow) && is_rtl); 
-
   if (GTK_WIDGET_DRAWABLE (notebook))
     {
       gint scroll_arrow_hlength;
       gint scroll_arrow_vlength;
       gint arrow_size;
 
+      gtk_notebook_get_arrow_rect (notebook, &arrow_rect, nbarrow);
+
+      widget = GTK_WIDGET (notebook);
+
+      is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
+      left = (ARROW_IS_LEFT (nbarrow) && !is_rtl) ||
+             (!ARROW_IS_LEFT (nbarrow) && is_rtl); 
+
       gtk_widget_style_get (widget,
                             "scroll-arrow-hlength", &scroll_arrow_hlength,
                             "scroll-arrow-vlength", &scroll_arrow_vlength,
@@ -4607,7 +4764,7 @@ gtk_notebook_draw_arrow (GtkNotebook      *notebook,
 
       if (notebook->focus_tab &&
          !gtk_notebook_search_page (notebook, notebook->focus_tab,
-                                     left? STEP_PREV : STEP_NEXT, TRUE))
+                                    left ? STEP_PREV : STEP_NEXT, TRUE))
        {
          shadow_type = GTK_SHADOW_ETCHED_IN;
          state_type = GTK_STATE_INSENSITIVE;
@@ -4624,7 +4781,7 @@ gtk_notebook_draw_arrow (GtkNotebook      *notebook,
           arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT);
           arrow_size = scroll_arrow_hlength;
         }
-      
+     
       gtk_paint_arrow (widget->style, widget->window, state_type, 
                       shadow_type, NULL, widget, "notebook",
                       arrow, TRUE, arrow_rect.x, arrow_rect.y, 
@@ -4650,7 +4807,6 @@ gtk_notebook_tab_space (GtkNotebook *notebook,
 {
   GtkNotebookPrivate *priv;
   GtkWidget *widget;
-  GtkNotebookPage *page;
   GList *children;
   gint tab_pos = get_effective_tab_pos (notebook);
   gint tab_overlap;
@@ -4677,6 +4833,8 @@ gtk_notebook_tab_space (GtkNotebook *notebook,
 
       while (children)
        {
+          GtkNotebookPage *page;
+
          page = children->data;
          children = children->next;
 
@@ -4692,6 +4850,8 @@ gtk_notebook_tab_space (GtkNotebook *notebook,
 
       while (children)
        {
+          GtkNotebookPage *page;
+
          page = children->data;
          children = children->next;
 
@@ -4715,7 +4875,6 @@ gtk_notebook_tab_space (GtkNotebook *notebook,
          if (*tab_space > *max - *min - tab_overlap)
            {
              *show_arrows = TRUE;
-             page = notebook->focus_tab->data;
 
              /* take arrows into account */
              *tab_space = widget->allocation.width - tab_overlap -
@@ -4751,7 +4910,6 @@ gtk_notebook_tab_space (GtkNotebook *notebook,
          if (*tab_space > *max - *min - tab_overlap)
            {
              *show_arrows = TRUE;
-             page = notebook->focus_tab->data;
 
              /* take arrows into account */
              *tab_space = widget->allocation.height -
@@ -4807,7 +4965,7 @@ gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
                                  &(notebook->focus_tab),
                                  remaining_space, STEP_NEXT);
        }
-      
+
       if (*remaining_space <= 0)
        {
          /* show 1 tab */
@@ -4851,9 +5009,7 @@ gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
                                    &(notebook->first_tab), remaining_space,
                                    STEP_PREV);
 
-         page = notebook->focus_tab->data;
-         if (*remaining_space <= 0 &&
-             !gtk_widget_get_child_visible(page->tab_label))
+         if (*remaining_space < 0)
            {
              notebook->first_tab =
                gtk_notebook_search_page (notebook, notebook->first_tab,
@@ -4885,16 +5041,21 @@ gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
                {
                  *last_child = NULL;
                  children = NULL;
+
                  gtk_notebook_calc_tabs (notebook,
                                          gtk_notebook_search_page (notebook,
                                                                    notebook->first_tab,
                                                                    STEP_PREV,
                                                                    TRUE),
                                          &children, remaining_space, STEP_PREV);
-                 notebook->first_tab = gtk_notebook_search_page(notebook,
-                                                                children,
-                                                                STEP_NEXT,
-                                                                TRUE);
+
+                 if (*remaining_space == 0)
+                   notebook->first_tab = children;
+                 else
+                   notebook->first_tab = gtk_notebook_search_page(notebook,
+                                                                  children,
+                                                                  STEP_NEXT,
+                                                                  TRUE);
                }
            }
        }
@@ -5013,6 +5174,7 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook  *notebook,
   gboolean allocate_at_bottom;
   gint tab_overlap, tab_pos, tab_extra_space;
   gint left_x, right_x, top_y, bottom_y, anchor;
+  gint xthickness, ythickness;
   gboolean gap_left, packing_changed;
   GtkAllocation child_allocation = { 0, };
   gboolean allocation_changed = FALSE;
@@ -5028,6 +5190,9 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook  *notebook,
   child_allocation.x = widget->allocation.x + container->border_width;
   child_allocation.y = widget->allocation.y + container->border_width;
 
+  xthickness = widget->style->xthickness;
+  ythickness = widget->style->ythickness;
+
   switch (tab_pos)
     {
     case GTK_POS_BOTTOM:
@@ -5051,9 +5216,9 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook  *notebook,
       break;
     }
 
-  left_x   = CLAMP (widget->allocation.x + priv->mouse_x - notebook->cur_page->allocation.width / 2,
+  left_x   = CLAMP (priv->mouse_x - priv->drag_offset_x,
                    min, max - notebook->cur_page->allocation.width);
-  top_y    = CLAMP (widget->allocation.y + priv->mouse_y - notebook->cur_page->allocation.height / 2,
+  top_y    = CLAMP (priv->mouse_y - priv->drag_offset_y,
                    min, max - notebook->cur_page->allocation.height);
   right_x  = left_x + notebook->cur_page->allocation.width;
   bottom_y = top_y + notebook->cur_page->allocation.height;
@@ -5207,14 +5372,33 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook  *notebook,
 
       page->allocation = child_allocation;
 
-      if (priv->operation == DRAG_OPERATION_REORDER &&
-         page == notebook->cur_page)
+      if ((page == priv->detached_tab && priv->operation == DRAG_OPERATION_DETACH) ||
+         (page == notebook->cur_page && priv->operation == DRAG_OPERATION_REORDER))
        {
          /* needs to be allocated at 0,0
           * to be shown in the drag window */
          page->allocation.x = 0;
          page->allocation.y = 0;
        }
+      
+      if (page != notebook->cur_page)
+       {
+         switch (tab_pos)
+           {
+           case GTK_POS_TOP:
+             page->allocation.y += ythickness;
+             /* fall through */
+           case GTK_POS_BOTTOM:
+             page->allocation.height = MAX (1, page->allocation.height - ythickness);
+             break;
+           case GTK_POS_LEFT:
+             page->allocation.x += xthickness;
+             /* fall through */
+           case GTK_POS_RIGHT:
+             page->allocation.width = MAX (1, page->allocation.width - xthickness);
+             break;
+           }
+       }
 
       /* calculate whether to leave a gap based on reorder operation or not */
       switch (tab_pos)
@@ -5318,7 +5502,6 @@ gtk_notebook_pages_allocate (GtkNotebook *notebook)
   gboolean showarrow = FALSE;
   gint tab_space, min, max, remaining_space;
   gint expanded_tabs, operation;
-  gboolean changed;
 
   if (!notebook->show_tabs || !notebook->children || !notebook->cur_page)
     return;
@@ -5334,15 +5517,15 @@ gtk_notebook_pages_allocate (GtkNotebook *notebook)
                                     &expanded_tabs, &remaining_space);
 
   children = notebook->first_tab;
-  changed = gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
-                                                   showarrow, STEP_NEXT,
-                                                   &remaining_space, &expanded_tabs, min, max);
+  gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
+                                         showarrow, STEP_NEXT,
+                                         &remaining_space, &expanded_tabs, min, max);
   if (children && children != last_child)
     {
       children = notebook->children;
-      changed |= gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
-                                                        showarrow, STEP_PREV,
-                                                        &remaining_space, &expanded_tabs, min, max);
+      gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
+                                             showarrow, STEP_PREV,
+                                             &remaining_space, &expanded_tabs, min, max);
     }
 
   children = notebook->children;
@@ -5358,10 +5541,7 @@ gtk_notebook_pages_allocate (GtkNotebook *notebook)
   if (!notebook->first_tab)
     notebook->first_tab = notebook->children;
 
-  if (changed || operation != DRAG_OPERATION_REORDER)
-    gtk_notebook_redraw_tabs (notebook);
-  else if (!changed)
-    gtk_notebook_redraw_tabs_union (notebook);
+  gtk_notebook_redraw_tabs (notebook);
 }
 
 static void
@@ -5457,8 +5637,10 @@ gtk_notebook_calc_tabs (GtkNotebook  *notebook,
   GtkNotebookPage *page = NULL;
   GList *children;
   GList *last_list = NULL;
+  GList *last_calculated_child = NULL;
   gboolean pack;
   gint tab_pos = get_effective_tab_pos (notebook);
+  guint real_direction;
 
   if (!start)
     return;
@@ -5466,7 +5648,9 @@ gtk_notebook_calc_tabs (GtkNotebook  *notebook,
   children = start;
   pack = GTK_NOTEBOOK_PAGE (start)->pack;
   if (pack == GTK_PACK_END)
-    direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
+    real_direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
+  else
+    real_direction = direction;
 
   while (1)
     {
@@ -5489,14 +5673,20 @@ gtk_notebook_calc_tabs (GtkNotebook  *notebook,
                            {
                              *tab_space = - (*tab_space +
                                              page->requisition.width);
+
+                             if (*tab_space == 0 && direction == STEP_PREV)
+                               children = last_calculated_child;
+
                              *end = children;
                            }
                          return;
                        }
+
+                     last_calculated_child = children;
                    }
                  last_list = children;
                }
-             if (direction == STEP_NEXT)
+             if (real_direction == STEP_NEXT)
                children = children->next;
              else
                children = children->prev;
@@ -5519,24 +5709,30 @@ gtk_notebook_calc_tabs (GtkNotebook  *notebook,
                            {
                              *tab_space = - (*tab_space +
                                              page->requisition.height);
+
+                             if (*tab_space == 0 && direction == STEP_PREV)
+                               children = last_calculated_child;
+
                              *end = children;
                            }
                          return;
                        }
+
+                     last_calculated_child = children;
                    }
                  last_list = children;
                }
-             if (direction == STEP_NEXT)
+             if (real_direction == STEP_NEXT)
                children = children->next;
              else
                children = children->prev;
            }
          break;
        }
-      if (direction == STEP_PREV)
+      if (real_direction == STEP_PREV)
        return;
       pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
-      direction = STEP_PREV;
+      real_direction = STEP_PREV;
       children = last_list;
     }
 }
@@ -5569,15 +5765,12 @@ gtk_notebook_real_switch_page (GtkNotebook     *notebook,
                               GtkNotebookPage *page,
                               guint            page_num)
 {
-  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-  g_return_if_fail (page != NULL);
-
   if (notebook->cur_page == page || !GTK_WIDGET_VISIBLE (page->child))
     return;
 
   if (notebook->cur_page)
     gtk_widget_set_child_visible (notebook->cur_page->child, FALSE);
-  
+
   notebook->cur_page = page;
 
   if (!notebook->focus_tab ||
@@ -5615,17 +5808,14 @@ gtk_notebook_real_switch_page (GtkNotebook     *notebook,
  */
 static void
 gtk_notebook_switch_page (GtkNotebook     *notebook,
-                         GtkNotebookPage *page,
-                         gint             page_num)
+                         GtkNotebookPage *page)
 { 
-  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-  g_return_if_fail (page != NULL);
+  guint page_num;
+
   if (notebook->cur_page == page)
     return;
 
-  if (page_num < 0)
-    page_num = g_list_index (notebook->children, page);
+  page_num = g_list_index (notebook->children, page);
 
   g_signal_emit (notebook,
                 notebook_signals[SWITCH_PAGE],
@@ -5642,13 +5832,11 @@ gtk_notebook_page_select (GtkNotebook *notebook,
   GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
   gint tab_pos = get_effective_tab_pos (notebook);
 
-  g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
-
   if (!notebook->focus_tab)
     return FALSE;
 
   page = notebook->focus_tab->data;
-  gtk_notebook_switch_page (notebook, page, -1);
+  gtk_notebook_switch_page (notebook, page);
 
   if (move_focus)
     {
@@ -5681,8 +5869,6 @@ gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
   GList *old_child;
   GtkNotebookPage *page;
 
-  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-
   if (notebook->focus_tab == new_child)
     return;
 
@@ -5700,9 +5886,8 @@ gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
     gtk_notebook_redraw_tabs (notebook);
   else
     gtk_notebook_pages_allocate (notebook);
-  
-  gtk_notebook_switch_page (notebook, page,
-                           g_list_index (notebook->children, page));
+
+  gtk_notebook_switch_page (notebook, page);
 }
 
 static void
@@ -5713,9 +5898,6 @@ gtk_notebook_menu_switch_page (GtkWidget       *widget,
   GList *children;
   guint page_num;
 
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (page != NULL);
-
   notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget
                           (GTK_MENU (widget->parent)));
 
@@ -5753,7 +5935,7 @@ gtk_notebook_menu_item_create (GtkNotebook *notebook,
   page = list->data;
   if (page->default_menu)
     {
-      if (page->tab_label && GTK_IS_LABEL (page->tab_label))
+      if (GTK_IS_LABEL (page->tab_label))
        page->menu_label = gtk_label_new (GTK_LABEL (page->tab_label)->label);
       else
        page->menu_label = gtk_label_new ("");
@@ -5785,8 +5967,6 @@ gtk_notebook_menu_detacher (GtkWidget *widget,
 {
   GtkNotebook *notebook;
 
-  g_return_if_fail (GTK_IS_NOTEBOOK (widget));
-
   notebook = GTK_NOTEBOOK (widget);
   g_return_if_fail (notebook->menu == (GtkWidget*) menu);
 
@@ -5804,8 +5984,6 @@ static void
 gtk_notebook_set_homogeneous_tabs_internal (GtkNotebook *notebook,
                                            gboolean     homogeneous)
 {
-  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-
   if (homogeneous == notebook->homogeneous)
     return;
 
@@ -5819,8 +5997,6 @@ static void
 gtk_notebook_set_tab_border_internal (GtkNotebook *notebook,
                                      guint        border_width)
 {
-  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-
   notebook->tab_hborder = border_width;
   notebook->tab_vborder = border_width;
 
@@ -5837,8 +6013,6 @@ static void
 gtk_notebook_set_tab_hborder_internal (GtkNotebook *notebook,
                                       guint        tab_hborder)
 {
-  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-
   if (notebook->tab_hborder == tab_hborder)
     return;
 
@@ -5854,8 +6028,6 @@ static void
 gtk_notebook_set_tab_vborder_internal (GtkNotebook *notebook,
                                       guint        tab_vborder)
 {
-  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-
   if (notebook->tab_vborder == tab_vborder)
     return;
 
@@ -6041,7 +6213,7 @@ gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
       GtkNotebookPage *page = list->data;
 
       gtk_widget_grab_focus (GTK_WIDGET (notebook));   /* Do this first to avoid focusing new page */
-      gtk_notebook_switch_page (notebook, page,  -1);
+      gtk_notebook_switch_page (notebook, page);
       focus_tabs_in (notebook);
     }
 
@@ -6147,7 +6319,7 @@ gtk_notebook_get_current_page (GtkNotebook *notebook)
 /**
  * gtk_notebook_get_nth_page:
  * @notebook: a #GtkNotebook
- * @page_num: the index of a page in the noteobok, or -1
+ * @page_num: the index of a page in the notebook, or -1
  *            to get the last page.
  * 
  * Returns the child widget contained in page number @page_num.
@@ -6240,8 +6412,13 @@ gtk_notebook_page_num (GtkNotebook      *notebook,
  *            than the number of pages in the notebook, nothing
  *            will be done.
  *                
- * Switches to the page number @page_num.
- **/
+ * Switches to the page number @page_num. 
+ *
+ * Note that due to historical reasons, GtkNotebook refuses
+ * to switch to a page unless the child widget is visible. 
+ * Therefore, it is recommended to show child widgets before
+ * adding them to a notebook. 
+ */
 void
 gtk_notebook_set_current_page (GtkNotebook *notebook,
                               gint         page_num)
@@ -6250,15 +6427,12 @@ gtk_notebook_set_current_page (GtkNotebook *notebook,
 
   g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
 
-  if (page_num >= 0)
-    list = g_list_nth (notebook->children, page_num);
-  else
-    list = g_list_last (notebook->children);
-
-  page_num = g_list_index (notebook->children, list);
+  if (page_num < 0)
+    page_num = g_list_length (notebook->children) - 1;
 
+  list = g_list_nth (notebook->children, page_num);
   if (list)
-    gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), page_num);
+    gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
 }
 
 /**
@@ -6283,7 +6457,7 @@ gtk_notebook_next_page (GtkNotebook *notebook)
   if (!list)
     return;
 
-  gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
+  gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
 }
 
 /**
@@ -6308,7 +6482,7 @@ gtk_notebook_prev_page (GtkNotebook *notebook)
   if (!list)
     return;
 
-  gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
+  gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
 }
 
 /* Public GtkNotebook/Tab Style Functions
@@ -6797,10 +6971,10 @@ gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
  * Retrieves the text of the tab label for the page containing
  *    @child.
  *
- * Returns value: the text of the tab label, or %NULL if the
- *                tab label widget is not a #GtkLabel. The
- *                string is owned by the widget and must not
- *                be freed.
+ * Return value: the text of the tab label, or %NULL if the
+ *               tab label widget is not a #GtkLabel. The
+ *               string is owned by the widget and must not
+ *               be freed.
  **/
 G_CONST_RETURN gchar *
 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
@@ -6813,7 +6987,7 @@ gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
 
   tab_label = gtk_notebook_get_tab_label (notebook, child);
 
-  if (tab_label && GTK_IS_LABEL (tab_label))
+  if (GTK_IS_LABEL (tab_label))
     return gtk_label_get_text (GTK_LABEL (tab_label));
   else
     return NULL;
@@ -6915,7 +7089,10 @@ gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
   g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
 
   if (menu_text)
-    menu_label = gtk_label_new (menu_text);
+    {
+      menu_label = gtk_label_new (menu_text);
+      gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5);
+    }
   gtk_notebook_set_menu_label (notebook, child, menu_label);
   gtk_widget_child_notify (child, "menu-label");
 }
@@ -6928,11 +7105,11 @@ gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
  * Retrieves the text of the menu label for the page containing
  *    @child.
  *
- * Returns value: the text of the tab label, or %NULL if the
- *                widget does not have a menu label other than
- *                the default menu label, or the menu label widget
- *                is not a #GtkLabel. The string is owned by
- *                the widget and must not be freed.
+ * Return value: the text of the tab label, or %NULL if the
+ *               widget does not have a menu label other than
+ *               the default menu label, or the menu label widget
+ *               is not a #GtkLabel. The string is owned by
+ *               the widget and must not be freed.
  **/
 G_CONST_RETURN gchar *
 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
@@ -6945,7 +7122,7 @@ gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
  
   menu_label = gtk_notebook_get_menu_label (notebook, child);
 
-  if (menu_label && GTK_IS_LABEL (menu_label))
+  if (GTK_IS_LABEL (menu_label))
     return gtk_label_get_text (GTK_LABEL (menu_label));
   else
     return NULL;
@@ -7128,8 +7305,9 @@ gtk_notebook_reorder_child (GtkNotebook *notebook,
 
 /**
  * gtk_notebook_set_window_creation_hook:
- * @func: the #GtkNotebookWindowCreationFunc, or NULL
- * @data: user data for @func.
+ * @func: the #GtkNotebookWindowCreationFunc, or %NULL
+ * @data: user data for @func
+ * @destroy: Destroy notifier for @data, or %NULL
  *
  * Installs a global function used to create a window
  * when a detached tab is dropped in an empty area.
@@ -7138,10 +7316,15 @@ gtk_notebook_reorder_child (GtkNotebook *notebook,
  **/
 void
 gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc  func,
-                                      gpointer                       data)
+                                      gpointer                       data,
+                                       GDestroyNotify                 destroy)
 {
+  if (window_creation_hook_destroy)
+    window_creation_hook_destroy (window_creation_hook_data);
+
   window_creation_hook = func;
   window_creation_hook_data = data;
+  window_creation_hook_destroy = destroy;
 }
 
 /**
@@ -7155,10 +7338,36 @@ gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc  func,
  * not be able to exchange tabs with any other notebook.
  * 
  * Since: 2.10
- **/
+ * Deprecated: 2.12: use gtk_notebook_set_group() instead.
+ */
 void
 gtk_notebook_set_group_id (GtkNotebook *notebook,
                           gint         group_id)
+{
+  gpointer group;
+
+  g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
+
+  /* add 1 to get rid of the -1/NULL difference */
+  group = GINT_TO_POINTER (group_id + 1);
+  gtk_notebook_set_group (notebook, group);
+}
+
+/**
+ * gtk_notebook_set_group:
+ * @notebook: a #GtkNotebook
+ * @group: a pointer to identify the notebook group, or %NULL to unset it
+ *
+ * Sets a group identificator pointer for @notebook, notebooks sharing
+ * the same group identificator pointer will be able to exchange tabs
+ * via drag and drop. A notebook with a %NULL group identificator will
+ * not be able to exchange tabs with any other notebook.
+ * 
+ * Since: 2.12
+ */
+void
+gtk_notebook_set_group (GtkNotebook *notebook,
+                       gpointer     group)
 {
   GtkNotebookPrivate *priv;
 
@@ -7166,10 +7375,11 @@ gtk_notebook_set_group_id (GtkNotebook *notebook,
 
   priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
 
-  if (priv->group_id != group_id)
+  if (priv->group != group)
     {
-      priv->group_id = group_id;
+      priv->group = group;
       g_object_notify (G_OBJECT (notebook), "group-id");
+      g_object_notify (G_OBJECT (notebook), "group");
     }
 }
 
@@ -7182,7 +7392,8 @@ gtk_notebook_set_group_id (GtkNotebook *notebook,
  * Return Value: the group identificator, or -1 if none is set.
  *
  * Since: 2.10
- **/
+ * Deprecated: 2.12: use gtk_notebook_get_group() instead.
+ */
 gint
 gtk_notebook_get_group_id (GtkNotebook *notebook)
 {
@@ -7191,7 +7402,30 @@ gtk_notebook_get_group_id (GtkNotebook *notebook)
   g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
 
   priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
-  return priv->group_id;
+
+  /* substract 1 to get rid of the -1/NULL difference */
+  return GPOINTER_TO_INT (priv->group) - 1;
+}
+
+/**
+ * gtk_notebook_get_group:
+ * @notebook: a #GtkNotebook
+ * 
+ * Gets the current group identificator pointer for @notebook.
+ * 
+ * Return Value: the group identificator, or %NULL if none is set.
+ *
+ * Since: 2.12
+ **/
+gpointer
+gtk_notebook_get_group (GtkNotebook *notebook)
+{
+  GtkNotebookPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
+
+  priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
+  return priv->group;
 }
 
 /**
@@ -7298,8 +7532,7 @@ gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
  * destination and accept the target "GTK_NOTEBOOK_TAB". The notebook
  * will fill the selection with a GtkWidget** pointing to the child
  * widget that corresponds to the dropped tab.
- *
- * <informalexample><programlisting>
+ * |[
  *  static void
  *  on_drop_zone_drag_data_received (GtkWidget        *widget,
  *                                   GdkDragContext   *context,
@@ -7319,7 +7552,7 @@ gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
  *    process_widget (*child);
  *    gtk_container_remove (GTK_CONTAINER (notebook), *child);
  *  }
- * </programlisting></informalexample>
+ * ]|
  *
  * If you want a notebook to accept drags from other widgets,
  * you will have to set your own DnD code to do it.