6
static gboolean delete_event( GtkWidget *widget,
14
/* Make a new hbox filled with button-labels. Arguments for the
15
* variables we're interested are passed in to this function.
16
* We do not show the box, but do show everything inside. */
17
static GtkWidget *make_box( gboolean homogeneous,
27
/* Create a new hbox with the appropriate homogeneous
28
* and spacing settings */
29
box = gtk_hbox_new (homogeneous, spacing);
31
/* Create a series of buttons with the appropriate settings */
32
button = gtk_button_new_with_label ("gtk_box_pack");
33
gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
34
gtk_widget_show (button);
36
button = gtk_button_new_with_label ("(box,");
37
gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
38
gtk_widget_show (button);
40
button = gtk_button_new_with_label ("button,");
41
gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
42
gtk_widget_show (button);
44
/* Create a button with the label depending on the value of
47
button = gtk_button_new_with_label ("TRUE,");
49
button = gtk_button_new_with_label ("FALSE,");
51
gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
52
gtk_widget_show (button);
54
/* This is the same as the button creation for "expand"
55
* above, but uses the shorthand form. */
56
button = gtk_button_new_with_label (fill ? "TRUE," : "FALSE,");
57
gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
58
gtk_widget_show (button);
60
sprintf (padstr, "%d);", padding);
62
button = gtk_button_new_with_label (padstr);
63
gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
64
gtk_widget_show (button);
81
/* Our init, don't forget this! :) */
82
gtk_init (&argc, &argv);
85
fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n");
86
/* This just does cleanup in GTK and exits with an exit status of 1. */
90
which = atoi (argv[1]);
92
/* Create our window */
93
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
95
/* You should always remember to connect the delete_event signal
96
* to the main window. This is very important for proper intuitive
98
g_signal_connect (G_OBJECT (window), "delete_event",
99
G_CALLBACK (delete_event), NULL);
100
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
102
/* We create a vertical box (vbox) to pack the horizontal boxes into.
103
* This allows us to stack the horizontal boxes filled with buttons one
104
* on top of the other in this vbox. */
105
box1 = gtk_vbox_new (FALSE, 0);
107
/* which example to show. These correspond to the pictures above. */
110
/* create a new label. */
111
label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");
113
/* Align the label to the left side. We'll discuss this function and
114
* others in the section on Widget Attributes. */
115
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
117
/* Pack the label into the vertical box (vbox box1). Remember that
118
* widgets added to a vbox will be packed one on top of the other in
120
gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
123
gtk_widget_show (label);
125
/* Call our make box function - homogeneous = FALSE, spacing = 0,
126
* expand = FALSE, fill = FALSE, padding = 0 */
127
box2 = make_box (FALSE, 0, FALSE, FALSE, 0);
128
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
129
gtk_widget_show (box2);
131
/* Call our make box function - homogeneous = FALSE, spacing = 0,
132
* expand = TRUE, fill = FALSE, padding = 0 */
133
box2 = make_box (FALSE, 0, TRUE, FALSE, 0);
134
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
135
gtk_widget_show (box2);
137
/* Args are: homogeneous, spacing, expand, fill, padding */
138
box2 = make_box (FALSE, 0, TRUE, TRUE, 0);
139
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
140
gtk_widget_show (box2);
142
/* Creates a separator, we'll learn more about these later,
143
* but they are quite simple. */
144
separator = gtk_hseparator_new ();
146
/* Pack the separator into the vbox. Remember each of these
147
* widgets is being packed into a vbox, so they'll be stacked
149
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
150
gtk_widget_show (separator);
152
/* Create another new label, and show it. */
153
label = gtk_label_new ("gtk_hbox_new (TRUE, 0);");
154
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
155
gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
156
gtk_widget_show (label);
158
/* Args are: homogeneous, spacing, expand, fill, padding */
159
box2 = make_box (TRUE, 0, TRUE, FALSE, 0);
160
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
161
gtk_widget_show (box2);
163
/* Args are: homogeneous, spacing, expand, fill, padding */
164
box2 = make_box (TRUE, 0, TRUE, TRUE, 0);
165
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
166
gtk_widget_show (box2);
168
/* Another new separator. */
169
separator = gtk_hseparator_new ();
170
/* The last 3 arguments to gtk_box_pack_start are:
171
* expand, fill, padding. */
172
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
173
gtk_widget_show (separator);
179
/* Create a new label, remember box1 is a vbox as created
180
* near the beginning of main() */
181
label = gtk_label_new ("gtk_hbox_new (FALSE, 10);");
182
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
183
gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
184
gtk_widget_show (label);
186
/* Args are: homogeneous, spacing, expand, fill, padding */
187
box2 = make_box (FALSE, 10, TRUE, FALSE, 0);
188
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
189
gtk_widget_show (box2);
191
/* Args are: homogeneous, spacing, expand, fill, padding */
192
box2 = make_box (FALSE, 10, TRUE, TRUE, 0);
193
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
194
gtk_widget_show (box2);
196
separator = gtk_hseparator_new ();
197
/* The last 3 arguments to gtk_box_pack_start are:
198
* expand, fill, padding. */
199
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
200
gtk_widget_show (separator);
202
label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");
203
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
204
gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
205
gtk_widget_show (label);
207
/* Args are: homogeneous, spacing, expand, fill, padding */
208
box2 = make_box (FALSE, 0, TRUE, FALSE, 10);
209
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
210
gtk_widget_show (box2);
212
/* Args are: homogeneous, spacing, expand, fill, padding */
213
box2 = make_box (FALSE, 0, TRUE, TRUE, 10);
214
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
215
gtk_widget_show (box2);
217
separator = gtk_hseparator_new ();
218
/* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */
219
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
220
gtk_widget_show (separator);
225
/* This demonstrates the ability to use gtk_box_pack_end() to
226
* right justify widgets. First, we create a new box as before. */
227
box2 = make_box (FALSE, 0, FALSE, FALSE, 0);
229
/* Create the label that will be put at the end. */
230
label = gtk_label_new ("end");
231
/* Pack it using gtk_box_pack_end(), so it is put on the right
232
* side of the hbox created in the make_box() call. */
233
gtk_box_pack_end (GTK_BOX (box2), label, FALSE, FALSE, 0);
234
/* Show the label. */
235
gtk_widget_show (label);
237
/* Pack box2 into box1 (the vbox remember ? :) */
238
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
239
gtk_widget_show (box2);
241
/* A separator for the bottom. */
242
separator = gtk_hseparator_new ();
243
/* This explicitly sets the separator to 400 pixels wide by 5 pixels
244
* high. This is so the hbox we created will also be 400 pixels wide,
245
* and the "end" label will be separated from the other labels in the
246
* hbox. Otherwise, all the widgets in the hbox would be packed as
247
* close together as possible. */
248
gtk_widget_set_size_request (separator, 400, 5);
249
/* pack the separator into the vbox (box1) created near the start
251
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
252
gtk_widget_show (separator);
255
/* Create another new hbox.. remember we can use as many as we need! */
256
quitbox = gtk_hbox_new (FALSE, 0);
258
/* Our quit button. */
259
button = gtk_button_new_with_label ("Quit");
261
/* Setup the signal to terminate the program when the button is clicked */
262
g_signal_connect_swapped (G_OBJECT (button), "clicked",
263
G_CALLBACK (gtk_main_quit),
265
/* Pack the button into the quitbox.
266
* The last 3 arguments to gtk_box_pack_start are:
267
* expand, fill, padding. */
268
gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);
269
/* pack the quitbox into the vbox (box1) */
270
gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0);
272
/* Pack the vbox (box1) which now contains all our widgets, into the
274
gtk_container_add (GTK_CONTAINER (window), box1);
276
/* And show everything left */
277
gtk_widget_show (button);
278
gtk_widget_show (quitbox);
280
gtk_widget_show (box1);
281
/* Showing the window last so everything pops up at once. */
282
gtk_widget_show (window);
284
/* And of course, our main function. */
287
/* Control returns here when gtk_main_quit() is called, but not when