5 /* This is a callback function. The data arguments are ignored
6 * in this example. More on callbacks below. */
7 void hello( GtkWidget *widget,
10 g_print ("Hello World\n");
13 gint delete_event( GtkWidget *widget,
17 /* If you return FALSE in the "delete_event" signal handler,
18 * GTK will emit the "destroy" signal. Returning TRUE means
19 * you don't want the window to be destroyed.
20 * This is useful for popping up 'are you sure you want to quit?'
23 g_print ("delete event occurred\n");
25 /* Change TRUE to FALSE and the main window will be destroyed with
26 * a "delete_event". */
31 /* Another callback */
32 void destroy( GtkWidget *widget,
41 /* GtkWidget is the storage type for widgets */
45 /* This is called in all GTK applications. Arguments are parsed
46 * from the command line and are returned to the application. */
47 gtk_init (&argc, &argv);
49 /* create a new window */
50 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
52 /* When the window is given the "delete_event" signal (this is given
53 * by the window manager, usually by the "close" option, or on the
54 * titlebar), we ask it to call the delete_event () function
55 * as defined above. The data passed to the callback
56 * function is NULL and is ignored in the callback function. */
57 g_signal_connect (G_OBJECT (window), "delete_event",
58 G_CALLBACK (delete_event), NULL);
60 /* Here we connect the "destroy" event to a signal handler.
61 * This event occurs when we call gtk_widget_destroy() on the window,
62 * or if we return FALSE in the "delete_event" callback. */
63 g_signal_connect (G_OBJECT (window), "destroy",
64 G_CALLBACK (destroy), NULL);
66 /* Sets the border width of the window. */
67 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
69 /* Creates a new button with the label "Hello World". */
70 button = gtk_button_new_with_label ("Hello World");
72 /* When the button receives the "clicked" signal, it will call the
73 * function hello() passing it NULL as its argument. The hello()
74 * function is defined above. */
75 g_signal_connect (G_OBJECT (button), "clicked",
76 G_CALLBACK (hello), NULL);
78 /* This will cause the window to be destroyed by calling
79 * gtk_widget_destroy(window) when "clicked". Again, the destroy
80 * signal could come from here, or the window manager. */
81 g_signal_connect_swapped (G_OBJECT (button), "clicked",
82 G_CALLBACK (gtk_widget_destroy),
85 /* This packs the button into the window (a gtk container). */
86 gtk_container_add (GTK_CONTAINER (window), button);
88 /* The final step is to display this newly created widget. */
89 gtk_widget_show (button);
92 gtk_widget_show (window);
94 /* All GTK applications must have a gtk_main(). Control ends here
95 * and waits for an event to occur (like a key press or