2010-12-24 01:29:21 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2010-12-24 03:35:56 +00:00
|
|
|
GtkWidget *notebook;
|
2010-12-24 01:29:21 +00:00
|
|
|
|
|
|
|
|
2010-12-24 03:35:56 +00:00
|
|
|
static void
|
|
|
|
remove_notebook_page (GtkWidget *button,
|
|
|
|
GtkWidget *toplevel)
|
|
|
|
{
|
|
|
|
gtk_container_remove (GTK_CONTAINER (notebook), toplevel);
|
2011-01-03 15:55:04 +00:00
|
|
|
gtk_widget_show (toplevel);
|
2010-12-24 03:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
create_tab_label (GtkWidget *toplevel)
|
|
|
|
{
|
2011-04-22 13:38:40 +00:00
|
|
|
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2010-12-24 03:35:56 +00:00
|
|
|
GtkWidget *label = gtk_label_new (G_OBJECT_TYPE_NAME (toplevel));
|
|
|
|
GtkWidget *button = gtk_button_new ();
|
2013-06-24 21:31:22 +00:00
|
|
|
GtkWidget *image = gtk_image_new_from_icon_name ("window-close", GTK_ICON_SIZE_MENU);
|
2010-12-24 03:35:56 +00:00
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), image);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), label);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), button);
|
2010-12-24 03:35:56 +00:00
|
|
|
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (remove_notebook_page), toplevel);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-12-24 01:29:21 +00:00
|
|
|
gint
|
|
|
|
main (gint argc, gchar **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2010-12-24 01:29:21 +00:00
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Toplevel widget embedding example");
|
|
|
|
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
|
|
|
|
|
|
|
|
notebook = gtk_notebook_new ();
|
2010-12-26 10:25:06 +00:00
|
|
|
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
|
2010-12-24 01:29:21 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), notebook);
|
|
|
|
|
|
|
|
gtk_widget_realize (notebook);
|
|
|
|
|
|
|
|
widget = gtk_about_dialog_new ();
|
2010-12-24 03:35:56 +00:00
|
|
|
toplevel_delete_event (widget, NULL, NULL);
|
|
|
|
g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL);
|
2010-12-24 01:29:21 +00:00
|
|
|
|
|
|
|
widget = gtk_file_chooser_dialog_new ("the chooser", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
|
2010-12-24 03:35:56 +00:00
|
|
|
toplevel_delete_event (widget, NULL, NULL);
|
|
|
|
g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL);
|
2010-12-24 01:29:21 +00:00
|
|
|
|
2012-02-09 21:24:24 +00:00
|
|
|
widget = gtk_color_chooser_dialog_new ("the colorsel", NULL);
|
2010-12-24 03:35:56 +00:00
|
|
|
toplevel_delete_event (widget, NULL, NULL);
|
|
|
|
g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL);
|
2010-12-24 01:29:21 +00:00
|
|
|
|
2011-08-16 14:42:54 +00:00
|
|
|
widget = gtk_font_chooser_dialog_new ("the fontsel", NULL);
|
2010-12-24 03:35:56 +00:00
|
|
|
toplevel_delete_event (widget, NULL, NULL);
|
|
|
|
g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL);
|
2010-12-24 01:29:21 +00:00
|
|
|
|
|
|
|
widget = gtk_recent_chooser_dialog_new ("the recent chooser", NULL,
|
2013-06-24 21:31:22 +00:00
|
|
|
"_Cancel", GTK_RESPONSE_CANCEL,
|
|
|
|
"_Open", GTK_RESPONSE_ACCEPT,
|
2010-12-24 01:29:21 +00:00
|
|
|
NULL);
|
2010-12-24 03:35:56 +00:00
|
|
|
toplevel_delete_event (widget, NULL, NULL);
|
|
|
|
g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL);
|
2010-12-24 01:29:21 +00:00
|
|
|
|
|
|
|
widget = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
|
|
|
|
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
|
|
|
|
"Do you have any questions ?");
|
2010-12-24 03:35:56 +00:00
|
|
|
toplevel_delete_event (widget, NULL, NULL);
|
|
|
|
g_signal_connect (widget, "delete-event", G_CALLBACK (toplevel_delete_event), NULL);
|
2010-12-24 01:29:21 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2010-12-24 01:29:21 +00:00
|
|
|
gtk_main ();
|
2013-01-08 11:23:52 +00:00
|
|
|
|
|
|
|
return 0;
|
2010-12-24 01:29:21 +00:00
|
|
|
}
|