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