Updated .hgignore file.
[fedora-mingw.git] / gtk2 / test1.c
1 /* Hello, world from
2  * http://library.gnome.org/devel/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD
3  */
4
5 #include <gtk/gtk.h>
6
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,
10                    gpointer   data )
11 {
12     g_print ("Hello World\n");
13 }
14
15 static gboolean delete_event( GtkWidget *widget,
16                               GdkEvent  *event,
17                               gpointer   data )
18 {
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?'
23      * type dialogs. */
24
25     g_print ("delete event occurred\n");
26
27     /* Change TRUE to FALSE and the main window will be destroyed with
28      * a "delete_event". */
29
30     return TRUE;
31 }
32
33 /* Another callback */
34 static void destroy( GtkWidget *widget,
35                      gpointer   data )
36 {
37     gtk_main_quit ();
38 }
39
40 int main( int   argc,
41           char *argv[] )
42 {
43     /* GtkWidget is the storage type for widgets */
44     GtkWidget *window;
45     GtkWidget *button;
46     
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);
50     
51     /* create a new window */
52     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
53     
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);
61     
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);
67     
68     /* Sets the border width of the window. */
69     gtk_container_set_border_width (GTK_CONTAINER (window), 10);
70     
71     /* Creates a new button with the label "Hello World". */
72     button = gtk_button_new_with_label ("Hello World");
73     
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);
79     
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),
85                               G_OBJECT (window));
86     
87     /* This packs the button into the window (a gtk container). */
88     gtk_container_add (GTK_CONTAINER (window), button);
89     
90     /* The final step is to display this newly created widget. */
91     gtk_widget_show (button);
92     
93     /* and the window */
94     gtk_widget_show (window);
95     
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
98      * mouse event). */
99     gtk_main ();
100     
101     return 0;
102 }