diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-12-24 12:35:56 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2011-01-06 14:39:40 +0900 |
commit | 387d745e0eec26bebf3f50a7eb970aaaa99b2a6e (patch) | |
tree | ebaecb805865d5fd4246a9c685d23a436d0c04e5 /tests | |
parent | 2dfa855bc4d32ebdb2c2c0c53670094f06e79271 (diff) | |
download | gtk+-387d745e0eec26bebf3f50a7eb970aaaa99b2a6e.tar.gz |
Added buttons to notebook tabs in testtoplevelembed
Now you can remove and reembed the toplevels (deleting the
toplevels put them back in the notebook).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testtoplevelembed.c | 85 |
1 files changed, 62 insertions, 23 deletions
diff --git a/tests/testtoplevelembed.c b/tests/testtoplevelembed.c index 3bcac96178..3540ed49cf 100644 --- a/tests/testtoplevelembed.c +++ b/tests/testtoplevelembed.c @@ -1,16 +1,63 @@ #include "config.h" #include <gtk/gtk.h> +GtkWidget *notebook; +static void +remove_notebook_page (GtkWidget *button, + GtkWidget *toplevel) +{ + gtk_container_remove (GTK_CONTAINER (notebook), toplevel); + + gtk_widget_hide (toplevel); + gtk_widget_show (toplevel); +} + +GtkWidget * +create_tab_label (GtkWidget *toplevel) +{ + GtkWidget *box = gtk_hbox_new (FALSE, 2); + GtkWidget *label = gtk_label_new (G_OBJECT_TYPE_NAME (toplevel)); + GtkWidget *button = gtk_button_new (); + GtkWidget *image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_SMALL_TOOLBAR); + + gtk_container_add (GTK_CONTAINER (button), image); + gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (box), button, FALSE, TRUE, 0); + + g_signal_connect (button, "clicked", + G_CALLBACK (remove_notebook_page), toplevel); + + gtk_widget_show_all (box); + return box; +} + +static void +toplevel_delete_event (GtkWidget *toplevel, + GdkEvent *event, + gpointer none) +{ + GdkWindow *gdk_win; + GtkWidget *label = create_tab_label (toplevel); + + gdk_win = gtk_widget_get_window (notebook); + g_assert (gdk_win); + + gtk_widget_hide (toplevel); + gtk_widget_unrealize (toplevel); + + gtk_widget_set_parent_window (toplevel, gdk_win); + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), toplevel, label); + + gtk_widget_show (toplevel); +} + gint main (gint argc, gchar **argv) { GtkWidget *window; - GtkWidget *notebook; GtkWidget *widget; - GtkWidget *label; - GdkWindow *gdk_win; gtk_init (&argc, &argv); @@ -22,43 +69,35 @@ main (gint argc, gchar **argv) gtk_container_add (GTK_CONTAINER (window), notebook); gtk_widget_realize (notebook); - gdk_win = gtk_widget_get_window (notebook); - g_assert (gdk_win); widget = gtk_about_dialog_new (); - label = gtk_label_new ("GtkAboutDialog"); - gtk_widget_set_parent_window (widget, gdk_win); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label); + toplevel_delete_event (widget, NULL, NULL); + g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); widget = gtk_file_chooser_dialog_new ("the chooser", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL); - label = gtk_label_new ("GtkFileChooser"); - gtk_widget_set_parent_window (widget, gdk_win); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label); + toplevel_delete_event (widget, NULL, NULL); + g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); widget = gtk_color_selection_dialog_new ("the colorsel"); - label = gtk_label_new ("GtkColorSelDialog"); - gtk_widget_set_parent_window (widget, gdk_win); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label); + toplevel_delete_event (widget, NULL, NULL); + g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); widget = gtk_font_selection_dialog_new ("the fontsel"); - label = gtk_label_new ("GtkFontSelectionDialog"); - gtk_widget_set_parent_window (widget, gdk_win); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label); + toplevel_delete_event (widget, NULL, NULL); + g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); widget = gtk_recent_chooser_dialog_new ("the recent chooser", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - label = gtk_label_new ("GtkRecentChooserDialog"); - gtk_widget_set_parent_window (widget, gdk_win); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label); + toplevel_delete_event (widget, NULL, NULL); + g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); widget = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Do you have any questions ?"); - label = gtk_label_new ("GtkMessageDialog"); - gtk_widget_set_parent_window (widget, gdk_win); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label); + toplevel_delete_event (widget, NULL, NULL); + g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL); gtk_widget_show_all (window); gtk_main (); |