From: Matthias Clasen Date: Sun, 6 Aug 2006 04:10:11 +0000 (+0000) Subject: Don't allow dragging a notebook tab to one of its children. (#348626, X-Git-Url: http://pileus.org/git/?p=~andy%2Fgtk;a=commitdiff_plain;h=ab299968d072556544aa53ce6c7ecbb32f3ca4ac Don't allow dragging a notebook tab to one of its children. (#348626, 2006-08-06 Matthias Clasen * gtk/gtknotebook.c (gtk_notebook_drag_motion): Don't allow dragging a notebook tab to one of its children. (#348626, Benjamin Otte) --- diff --git a/ChangeLog b/ChangeLog index 7005b23b8..592b00c3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-08-06 Matthias Clasen + + * gtk/gtknotebook.c (gtk_notebook_drag_motion): Don't allow + dragging a notebook tab to one of its children. (#348626, + Benjamin Otte) + + * tests/testnotebookdnd.c: Test more corner cases. + 2006-08-05 Matthias Clasen * docs/tutorial/gtk-tut.sgml: Remove outdated lists of diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 7005b23b8..592b00c3d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2006-08-06 Matthias Clasen + + * gtk/gtknotebook.c (gtk_notebook_drag_motion): Don't allow + dragging a notebook tab to one of its children. (#348626, + Benjamin Otte) + + * tests/testnotebookdnd.c: Test more corner cases. + 2006-08-05 Matthias Clasen * docs/tutorial/gtk-tut.sgml: Remove outdated lists of diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 4bcc88a3a..4ce749ffb 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -3159,7 +3159,9 @@ gtk_notebook_drag_motion (GtkWidget *widget, if (widget_group != -1 && source_widget_group != -1 && - 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; diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c index 796ec4709..233d9003e 100644 --- a/tests/testnotebookdnd.c +++ b/tests/testnotebookdnd.c @@ -34,10 +34,10 @@ enum { }; gchar *tabs1 [] = { - "a", - "b", - "c", - "d", + "aaaaaaaaaa", + "bbbbbbbbbb", + "cccccccccc", + "dddddddddd", NULL }; @@ -46,7 +46,7 @@ gchar *tabs2 [] = { "2", "3", "4", - "5", + "55555", NULL }; @@ -184,6 +184,47 @@ create_notebook (gchar **labels, return notebook; } +static GtkWidget* +create_notebook_with_notebooks (gchar **labels, + gint group_id, + gint packing, + GtkPositionType pos) +{ + GtkWidget *notebook, *title, *page; + gint count = 0; + + notebook = gtk_notebook_new (); + + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos); + gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); + gtk_container_set_border_width (GTK_CONTAINER (notebook), 6); + gtk_notebook_set_group_id (GTK_NOTEBOOK (notebook), group_id); + + while (*labels) + { + page = create_notebook (labels, group_id, packing, pos); + + title = gtk_label_new (*labels); + + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title); + gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE); + gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE); + + if (packing == PACK_END || + (packing == PACK_ALTERNATE && count % 2 == 1)) + gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL); + + count++; + labels++; + } + + g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered", + G_CALLBACK (on_page_reordered), NULL); + g_signal_connect_after (G_OBJECT (notebook), "drag-begin", + G_CALLBACK (on_notebook_drag_begin), NULL); + return notebook; +} + static GtkWidget* create_trash_button (void) { @@ -215,7 +256,7 @@ main (gint argc, gchar *argv[]) gtk_notebook_set_window_creation_hook (window_creation_function, NULL, NULL); gtk_table_attach_defaults (GTK_TABLE (table), - create_notebook (tabs1, GROUP_A, PACK_START, GTK_POS_TOP), + create_notebook (tabs1, GROUP_A, PACK_ALTERNATE, GTK_POS_TOP), 0, 1, 0, 1); gtk_table_attach_defaults (GTK_TABLE (table), @@ -227,7 +268,7 @@ main (gint argc, gchar *argv[]) 1, 2, 0, 1); gtk_table_attach_defaults (GTK_TABLE (table), - create_notebook (tabs4, GROUP_A, PACK_ALTERNATE, GTK_POS_RIGHT), + create_notebook_with_notebooks (tabs4, GROUP_A, PACK_ALTERNATE, GTK_POS_RIGHT), 1, 2, 1, 2); gtk_table_attach (GTK_TABLE (table),