]> Pileus Git - ~andy/gtk/blob - examples/buttons/buttons.c
Use gtk_box_new() instead gtk_[v|h]box_new()
[~andy/gtk] / examples / buttons / buttons.c
1
2 #include <stdlib.h>
3 #include <gtk/gtk.h>
4
5 /* Create a new hbox with an image and a label packed into it
6  * and return the box. */
7
8 static GtkWidget *xpm_label_box( gchar     *xpm_filename,
9                                  gchar     *label_text )
10 {
11     GtkWidget *box;
12     GtkWidget *label;
13     GtkWidget *image;
14
15     /* Create box for image and label */
16     box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 0);
17     gtk_container_set_border_width (GTK_CONTAINER (box), 2);
18
19     /* Now on to the image stuff */
20     image = gtk_image_new_from_file (xpm_filename);
21
22     /* Create a label for the button */
23     label = gtk_label_new (label_text);
24
25     /* Pack the image and label into the box */
26     gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 3);
27     gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 3);
28
29     gtk_widget_show (image);
30     gtk_widget_show (label);
31
32     return box;
33 }
34
35 /* Our usual callback function */
36 static void callback( GtkWidget *widget,
37                       gpointer   data )
38 {
39     g_print ("Hello again - %s was pressed\n", (char *) data);
40 }
41
42 int main( int   argc,
43           char *argv[] )
44 {
45     /* GtkWidget is the storage type for widgets */
46     GtkWidget *window;
47     GtkWidget *button;
48     GtkWidget *box;
49
50     gtk_init (&argc, &argv);
51
52     /* Create a new window */
53     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
54
55     gtk_window_set_title (GTK_WINDOW (window), "Pixmap'd Buttons!");
56
57     /* It's a good idea to do this for all windows. */
58     g_signal_connect (G_OBJECT (window), "destroy",
59                       G_CALLBACK (gtk_main_quit), NULL);
60
61     g_signal_connect (G_OBJECT (window), "delete-event",
62                       G_CALLBACK (gtk_main_quit), NULL);
63
64     /* Sets the border width of the window. */
65     gtk_container_set_border_width (GTK_CONTAINER (window), 10);
66
67     /* Create a new button */
68     button = gtk_button_new ();
69
70     /* Connect the "clicked" signal of the button to our callback */
71     g_signal_connect (G_OBJECT (button), "clicked",
72                       G_CALLBACK (callback), (gpointer) "cool button");
73
74     /* This calls our box creating function */
75     box = xpm_label_box ("info.xpm", "cool button");
76
77     /* Pack and show all our widgets */
78     gtk_widget_show (box);
79
80     gtk_container_add (GTK_CONTAINER (button), box);
81
82     gtk_widget_show (button);
83
84     gtk_container_add (GTK_CONTAINER (window), button);
85
86     gtk_widget_show (window);
87
88     /* Rest in gtk_main and wait for the fun to begin! */
89     gtk_main ();
90
91     return 0;
92 }