]> Pileus Git - ~andy/gtk/blob - examples/radiobuttons/radiobuttons.c
More work on #71430.
[~andy/gtk] / examples / radiobuttons / radiobuttons.c
1
2 #include <glib.h>
3 #include <gtk/gtk.h>
4
5 gint 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 (GTK_OBJECT (window), "delete_event",
28                         GTK_SIGNAL_FUNC(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_vbox_new (FALSE, 0);
35     gtk_container_add (GTK_CONTAINER (window), box1);
36     gtk_widget_show (box1);
37
38     box2 = gtk_vbox_new (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(
54                  gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
55                  "button3");
56     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
57     gtk_widget_show (button);
58
59     separator = gtk_hseparator_new ();
60     gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
61     gtk_widget_show (separator);
62
63     box2 = gtk_vbox_new (FALSE, 10);
64     gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
65     gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
66     gtk_widget_show (box2);
67
68     button = gtk_button_new_with_label ("close");
69     g_signal_connect_swapped (GTK_OBJECT (button), "clicked",
70                                GTK_SIGNAL_FUNC(close_application),
71                                GTK_OBJECT (window));
72     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
73     GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
74     gtk_widget_grab_default (button);
75     gtk_widget_show (button);
76     gtk_widget_show (window);
77      
78     gtk_main();
79
80     return 0;
81 }