diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2006-03-22 16:11:48 +0000 |
---|---|---|
committer | Carlos Garnacho <carlosg@src.gnome.org> | 2006-03-22 16:11:48 +0000 |
commit | f77c0fb15ec8ee8010564dff83838d892176607d (patch) | |
tree | 1e334ea0a454108b472a3553aeaa349ef40cb3c6 /tests/testnotebookdnd.c | |
parent | 0047b0b98ddfa0b21097ef2dd787393cf2ed5e31 (diff) | |
download | gtk+-f77c0fb15ec8ee8010564dff83838d892176607d.tar.gz |
send a GtkWidget** instead of a GtkNotebookPage* when doing tabs DnD, this
2006-03-22 Carlos Garnacho <carlosg@gnome.org>
* gtk/gtknotebook.c: send a GtkWidget** instead of a GtkNotebookPage*
when doing tabs DnD, this allows DnD interaction with other widgets,
added some docs for this too.
* tests/testnotebookdnd.c: add some code to test it.
Diffstat (limited to 'tests/testnotebookdnd.c')
-rw-r--r-- | tests/testnotebookdnd.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c index 4c48af5649..f47d93a6f2 100644 --- a/tests/testnotebookdnd.c +++ b/tests/testnotebookdnd.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */ /* * GTK - The GIMP Toolkit * Copyright (C) 2006 Carlos Garnacho Parro <carlosg@gnome.org> @@ -64,6 +65,10 @@ gchar *tabs4 [] = { NULL }; +static const GtkTargetEntry button_targets[] = { + { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 }, +}; + static GtkNotebook* window_creation_function (GtkNotebook *source_notebook, GtkWidget *child, @@ -94,6 +99,46 @@ on_page_reordered (GtkNotebook *notebook, GtkWidget *child, guint page_num, gpoi g_print ("page %d reordered\n", page_num); } +static void +on_notebook_drag_begin (GtkWidget *widget, + GdkDragContext *context, + gpointer data) +{ + GdkPixbuf *pixbuf; + guint page_num; + + page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget)); + + pixbuf = gtk_widget_render_icon (widget, + (page_num % 2) ? GTK_STOCK_HELP : GTK_STOCK_STOP, + GTK_ICON_SIZE_DND, NULL); + + gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0); + g_object_unref (pixbuf); +} + +static void +on_button_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *data, + guint info, + guint time, + gpointer user_data) +{ + GtkWidget *source, *tab_label; + GtkWidget **child; + + source = gtk_drag_get_source_widget (context); + child = (void*) data->data; + + tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child); + g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label))); + + gtk_container_remove (GTK_CONTAINER (source), *child); +} + static GtkWidget* create_notebook (gchar **labels, gint group_id, @@ -131,10 +176,29 @@ create_notebook (gchar **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) +{ + GtkWidget *button; + + button = gtk_button_new_from_stock (GTK_STOCK_DELETE); + + gtk_drag_dest_set (button, + GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, + button_targets, + G_N_ELEMENTS (button_targets), + GDK_ACTION_MOVE); + + g_signal_connect_after (G_OBJECT (button), "drag-data-received", + G_CALLBACK (on_button_drag_data_received), NULL); + return button; +} + gint main (gint argc, gchar *argv[]) { @@ -143,7 +207,7 @@ main (gint argc, gchar *argv[]) gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - table = gtk_table_new (2, 2, TRUE); + table = gtk_table_new (3, 2, FALSE); gtk_notebook_set_window_creation_hook (window_creation_function, NULL); @@ -163,6 +227,10 @@ main (gint argc, gchar *argv[]) create_notebook (tabs4, GROUP_A, PACK_ALTERNATE, GTK_POS_RIGHT), 1, 2, 1, 2); + gtk_table_attach (GTK_TABLE (table), + create_trash_button (), 1, 2, 2, 3, + GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); + gtk_container_add (GTK_CONTAINER (window), table); gtk_window_set_default_size (GTK_WINDOW (window), 400, 400); gtk_widget_show_all (window); |