]> Pileus Git - ~andy/gtk/blob - examples/radiobuttons/radiobuttons.c
Use gtk_box_new() instead gtk_[v|h]box_new()
[~andy/gtk] / examples / radiobuttons / radiobuttons.c
1
2 #include <glib.h>
3 #include <gtk/gtk.h>
4
5 static gboolean close_application( GtkWidget *widget,
6                                    GdkEvent  *event,
7                                    gpointer   data )
8 {
9   gtk_main_quit ();
10   return FALSE;
11 }
12
13 int main( int   argc,
14           char *argv[] )
15 {
16     GtkWidget *window = NULL;
17     GtkWidget *box1;
18     GtkWidget *box2;
19     GtkWidget *button;
20     GtkWidget *separator;
21     GSList *group;
22
23     gtk_init (&argc, &argv);
24
25     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
26
27     g_signal_connect (window, "delete-event",
28                       G_CALLBACK (close_application),
29                       NULL);
30
31     gtk_window_set_title (GTK_WINDOW (window), "radio buttons");
32     gtk_container_set_border_width (GTK_CONTAINER (window), 0);
33
34     box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
35     gtk_container_add (GTK_CONTAINER (window), box1);
36     gtk_widget_show (box1);
37
38     box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 10);
39     gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
40     gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
41     gtk_widget_show (box2);
42
43     button = gtk_radio_button_new_with_label (NULL, "button1");
44     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
45     gtk_widget_show (button);
46
47     group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
48     button = gtk_radio_button_new_with_label (group, "button2");
49     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
50     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
51     gtk_widget_show (button);
52
53     button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button),
54                                                           "button3");
55     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
56     gtk_widget_show (button);
57
58     separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
59     gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
60     gtk_widget_show (separator);
61
62     box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 10);
63     gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
64     gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
65     gtk_widget_show (box2);
66
67     button = gtk_button_new_with_label ("close");
68     g_signal_connect_swapped (button, "clicked",
69                               G_CALLBACK (close_application),
70                               window);
71     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
72     gtk_widget_set_can_default (button, TRUE);
73     gtk_widget_grab_default (button);
74     gtk_widget_show (button);
75     gtk_widget_show (window);
76
77     gtk_main ();
78
79     return 0;
80 }