2 * http://library.gnome.org/devel/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD
7 /* This is a callback function. The data arguments are ignored
8 * in this example. More on callbacks below. */
9 static void hello( GtkWidget *widget,
12 g_print ("Hello World\n");
15 static gboolean delete_event( GtkWidget *widget,
19 /* If you return FALSE in the "delete_event" signal handler,
20 * GTK will emit the "destroy" signal. Returning TRUE means
21 * you don't want the window to be destroyed.
22 * This is useful for popping up 'are you sure you want to quit?'
25 g_print ("delete event occurred\n");
27 /* Change TRUE to FALSE and the main window will be destroyed with
28 * a "delete_event". */
33 /* Another callback */
34 static void destroy( GtkWidget *widget,
43 /* GtkWidget is the storage type for widgets */
47 /* This is called in all GTK applications. Arguments are parsed
48 * from the command line and are returned to the application. */
49 gtk_init (&argc, &argv);
51 /* create a new window */
52 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
54 /* When the window is given the "delete_event" signal (this is given
55 * by the window manager, usually by the "close" option, or on the
56 * titlebar), we ask it to call the delete_event () function
57 * as defined above. The data passed to the callback
58 * function is NULL and is ignored in the callback function. */
59 g_signal_connect (G_OBJECT (window), "delete_event",
60 G_CALLBACK (delete_event), NULL);
62 /* Here we connect the "destroy" event to a signal handler.
63 * This event occurs when we call gtk_widget_destroy() on the window,
64 * or if we return FALSE in the "delete_event" callback. */
65 g_signal_connect (G_OBJECT (window), "destroy",
66 G_CALLBACK (destroy), NULL);
68 /* Sets the border width of the window. */
69 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
71 /* Creates a new button with the label "Hello World". */
72 button = gtk_button_new_with_label ("Hello World");
74 /* When the button receives the "clicked" signal, it will call the
75 * function hello() passing it NULL as its argument. The hello()
76 * function is defined above. */
77 g_signal_connect (G_OBJECT (button), "clicked",
78 G_CALLBACK (hello), NULL);
80 /* This will cause the window to be destroyed by calling
81 * gtk_widget_destroy(window) when "clicked". Again, the destroy
82 * signal could come from here, or the window manager. */
83 g_signal_connect_swapped (G_OBJECT (button), "clicked",
84 G_CALLBACK (gtk_widget_destroy),
87 /* This packs the button into the window (a gtk container). */
88 gtk_container_add (GTK_CONTAINER (window), button);
90 /* The final step is to display this newly created widget. */
91 gtk_widget_show (button);
94 gtk_widget_show (window);
96 /* All GTK applications must have a gtk_main(). Control ends here
97 * and waits for an event to occur (like a key press or