]> Pileus Git - ~andy/gtk/blob - examples/radiobuttons/radiobuttons.c
threads example from Erik Mouw. New question on GtkLabel background
[~andy/gtk] / examples / radiobuttons / radiobuttons.c
1 /* example-start radiobuttons radiobuttons.c */
2
3 #include <gtk/gtk.h>
4 #include <glib.h>
5
6 gint close_application( GtkWidget *widget,
7                         GdkEvent  *event,
8                         gpointer   data )
9 {
10   gtk_main_quit();
11   return(FALSE);
12 }
13
14 int main( int   argc,
15           char *argv[] )
16 {
17     GtkWidget *window = NULL;
18     GtkWidget *box1;
19     GtkWidget *box2;
20     GtkWidget *button;
21     GtkWidget *separator;
22     GSList *group;
23   
24     gtk_init(&argc,&argv);    
25       
26     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
27   
28     gtk_signal_connect (GTK_OBJECT (window), "delete_event",
29                         GTK_SIGNAL_FUNC(close_application),
30                         NULL);
31
32     gtk_window_set_title (GTK_WINDOW (window), "radio buttons");
33     gtk_container_set_border_width (GTK_CONTAINER (window), 0);
34
35     box1 = gtk_vbox_new (FALSE, 0);
36     gtk_container_add (GTK_CONTAINER (window), box1);
37     gtk_widget_show (box1);
38
39     box2 = gtk_vbox_new (FALSE, 10);
40     gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
41     gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
42     gtk_widget_show (box2);
43
44     button = gtk_radio_button_new_with_label (NULL, "button1");
45     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
46     gtk_widget_show (button);
47
48     group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
49     button = gtk_radio_button_new_with_label(group, "button2");
50     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
51     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
52     gtk_widget_show (button);
53
54     button = gtk_radio_button_new_with_label(
55                  gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
56                  "button3");
57     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
58     gtk_widget_show (button);
59
60     separator = gtk_hseparator_new ();
61     gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
62     gtk_widget_show (separator);
63
64     box2 = gtk_vbox_new (FALSE, 10);
65     gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
66     gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
67     gtk_widget_show (box2);
68
69     button = gtk_button_new_with_label ("close");
70     gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
71                                GTK_SIGNAL_FUNC(close_application),
72                                GTK_OBJECT (window));
73     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
74     GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
75     gtk_widget_grab_default (button);
76     gtk_widget_show (button);
77     gtk_widget_show (window);
78      
79     gtk_main();
80
81     return(0);
82 }
83 /* example-end */