1/* Button Boxes
2 *
3 * The Button Box widgets are used to arrange buttons with padding.
4 */
5
6#include <glib/gi18n.h>
7#include <gtk/gtk.h>
8
9static GtkWidget *
10create_bbox (gint horizontal,
11 char *title,
12 gint spacing,
13 gint layout)
14{
15 GtkWidget *frame;
16 GtkWidget *bbox;
17 GtkWidget *button;
18
19 frame = gtk_frame_new (title);
20
21 if (horizontal)
22 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
23 else
24 bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
25
26 gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
27 gtk_container_add (GTK_CONTAINER (frame), bbox);
28
29 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
30 gtk_box_set_spacing (GTK_BOX (bbox), spacing);
31
32 button = gtk_button_new_with_label (_("OK"));
33 gtk_container_add (GTK_CONTAINER (bbox), button);
34
35 button = gtk_button_new_with_label (_("Cancel"));
36 gtk_container_add (GTK_CONTAINER (bbox), button);
37
38 button = gtk_button_new_with_label (_("Help"));
39 gtk_container_add (GTK_CONTAINER (bbox), button);
40
41 return frame;
42}
43
44GtkWidget *
45do_button_box (GtkWidget *do_widget)
46{
47 static GtkWidget *window = NULL;
48 GtkWidget *main_vbox;
49 GtkWidget *vbox;
50 GtkWidget *hbox;
51 GtkWidget *frame_horz;
52 GtkWidget *frame_vert;
53
54 if (!window)
55 {
56 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
57 gtk_window_set_screen (GTK_WINDOW (window),
58 gtk_widget_get_screen (do_widget));
59 gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
60
61 g_signal_connect (window, "destroy",
62 G_CALLBACK (gtk_widget_destroyed),
63 &window);
64
65 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
66
67 main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
68 gtk_container_add (GTK_CONTAINER (window), main_vbox);
69
70 frame_horz = gtk_frame_new ("Horizontal Button Boxes");
71 gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
72
73 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
74 gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
75 gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
76
77 gtk_box_pack_start (GTK_BOX (vbox),
78 create_bbox (TRUE, "Spread", 40, GTK_BUTTONBOX_SPREAD),
79 TRUE, TRUE, 0);
80
81 gtk_box_pack_start (GTK_BOX (vbox),
82 create_bbox (TRUE, "Edge", 40, GTK_BUTTONBOX_EDGE),
83 TRUE, TRUE, 5);
84
85 gtk_box_pack_start (GTK_BOX (vbox),
86 create_bbox (TRUE, "Start", 40, GTK_BUTTONBOX_START),
87 TRUE, TRUE, 5);
88
89 gtk_box_pack_start (GTK_BOX (vbox),
90 create_bbox (TRUE, "End", 40, GTK_BUTTONBOX_END),
91 TRUE, TRUE, 5);
92
93 gtk_box_pack_start (GTK_BOX (vbox),
94 create_bbox (TRUE, "Center", 40, GTK_BUTTONBOX_CENTER),
95 TRUE, TRUE, 5);
96
97 gtk_box_pack_start (GTK_BOX (vbox),
98 create_bbox (TRUE, "Expand", 0, GTK_BUTTONBOX_EXPAND),
99 TRUE, TRUE, 5);
100
101 frame_vert = gtk_frame_new ("Vertical Button Boxes");
102 gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
103
104 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
105 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
106 gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
107
108 gtk_box_pack_start (GTK_BOX (hbox),
109 create_bbox (FALSE, "Spread", 10, GTK_BUTTONBOX_SPREAD),
110 TRUE, TRUE, 0);
111
112 gtk_box_pack_start (GTK_BOX (hbox),
113 create_bbox (FALSE, "Edge", 10, GTK_BUTTONBOX_EDGE),
114 TRUE, TRUE, 5);
115
116 gtk_box_pack_start (GTK_BOX (hbox),
117 create_bbox (FALSE, "Start", 10, GTK_BUTTONBOX_START),
118 TRUE, TRUE, 5);
119
120 gtk_box_pack_start (GTK_BOX (hbox),
121 create_bbox (FALSE, "End", 10, GTK_BUTTONBOX_END),
122 TRUE, TRUE, 5);
123 gtk_box_pack_start (GTK_BOX (hbox),
124 create_bbox (FALSE, "Center", 10, GTK_BUTTONBOX_CENTER),
125 TRUE, TRUE, 5);
126 gtk_box_pack_start (GTK_BOX (hbox),
127 create_bbox (FALSE, "Expand", 0, GTK_BUTTONBOX_EXPAND),
128 TRUE, TRUE, 5);
129 }
130
131 if (!gtk_widget_get_visible (window))
132 gtk_widget_show_all (window);
133 else
134 gtk_widget_destroy (window);
135
136 return window;
137}
138