GtkNotebook: Maintain invariants during tab dnd
authorMatthias Clasen <mclasen@redhat.com>
Sat, 23 Jun 2012 13:59:10 +0000 (09:59 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 23 Jun 2012 14:04:14 +0000 (10:04 -0400)
It turns out that we can end up removing a notebook child while
the tab is still 'detached'. Child removal causes
gtk_notebook_remove_tab_label() to be called on the tab label,
but that function did not deal with the eventuality that the tab
label may be a child of the dnd window.

http://bugzilla.gnome.org/show_bug.cgi?id=677943

gtk/gtknotebook.c

index a7f05d5c7e2a0903da61b28da5c26ccdd7d8aa23..214af5668dd814d20bccdcdabde7a3999ce4d06c 100644 (file)
@@ -3150,11 +3150,8 @@ hide_drag_window (GtkNotebook        *notebook,
     {
       g_object_ref (page->tab_label);
 
-      if (GTK_IS_WINDOW (parent))
-        {
-          /* parent widget is the drag window */
-          gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
-        }
+      if (GTK_IS_WINDOW (parent)) /* parent widget is the drag window */
+        gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
       else
         gtk_widget_unparent (page->tab_label);
 
@@ -4932,7 +4929,17 @@ gtk_notebook_remove_tab_label (GtkNotebook     *notebook,
       page->mnemonic_activate_signal = 0;
 
       gtk_widget_set_state_flags (page->tab_label, 0, TRUE);
-      gtk_widget_unparent (page->tab_label);
+      if (gtk_widget_get_window (page->tab_label) != gtk_widget_get_window (GTK_WIDGET (notebook)) ||
+          !NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
+        {
+          GtkWidget *parent;
+
+          parent = gtk_widget_get_parent (page->tab_label);
+          if (GTK_IS_WINDOW (parent))
+            gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
+          else
+            gtk_widget_unparent (page->tab_label);
+        }
       page->tab_label = NULL;
     }
 }