summaryrefslogtreecommitdiff
path: root/tests/testwrapbox.c
blob: 0cc2916cad83998b00dbb23e7f048c4eaeefe5eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/* testwrapbox.c
 * Copyright (C) 2010 Openismus GmbH
 *
 * Author:
 *      Tristan Van Berkom <tristan.van.berkom@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <gtk/gtk.h>

enum {
  SIMPLE_ITEMS = 0,
  WRAPPY_ITEMS,
  STOCK_ITEMS
};

#define INITIAL_ALLOCATION_MODE GTK_WRAP_ALLOCATE_HOMOGENEOUS
#define INITIAL_SPREADING       GTK_WRAP_BOX_SPREAD_BEGIN
#define INITIAL_MINIMUM_LENGTH  3
#define INITIAL_HSPACING        2
#define INITIAL_VSPACING        2

static GtkWrapBox *the_wrapbox       = NULL;
static gint           items_type       = SIMPLE_ITEMS;
static GtkOrientation text_orientation = GTK_ORIENTATION_HORIZONTAL;
static gboolean       items_xexpand    = TRUE;
static gboolean       items_yexpand    = TRUE;
static gboolean       items_xfill      = TRUE;
static gboolean       items_yfill      = TRUE;
static gint           items_xpad       = 0;
static gint           items_ypad       = 0;


static void
populate_wrapbox_simple (GtkWrapBox *wrapbox)
{
  GtkWidget *widget, *frame;
  gint i;

  for (i = 0; i < 30; i++)
    {
      gchar *text = g_strdup_printf ("Item %02d", i);

      widget = gtk_label_new (text);
      frame  = gtk_frame_new (NULL);
      gtk_widget_show (widget);
      gtk_widget_show (frame);

      gtk_container_add (GTK_CONTAINER (frame), widget);

      if (text_orientation == GTK_ORIENTATION_VERTICAL)
	gtk_label_set_angle (GTK_LABEL (widget), 90);

      gtk_wrap_box_insert_child (GTK_WRAP_BOX (wrapbox), frame, -1,
				    items_xpad, items_ypad, 
				    items_xexpand, items_yexpand, items_xfill, items_yfill);
      
      g_free (text);
    }
}

static void
populate_wrapbox_wrappy (GtkWrapBox *wrapbox)
{
  GtkWidget *widget, *frame;
  gint i;

  const gchar *strings[] = {
    "These are", "some wrappy label", "texts", "of various", "lengths.",
    "They should always be", "shown", "consecutively. Except it's",
    "hard to say", "where exactly the", "label", "will wrap", "and where exactly",
    "the actual", "container", "will wrap.", "This label is really really really long !", 
    "Let's add some more", "labels to the",
    "mix. Just to", "make sure we", "got something to work", "with here."
  };

  for (i = 0; i < G_N_ELEMENTS (strings); i++)
    {
      widget = gtk_label_new (strings[i]);
      frame  = gtk_frame_new (NULL);
      gtk_widget_show (widget);
      gtk_widget_show (frame);

      if (text_orientation == GTK_ORIENTATION_VERTICAL)
	gtk_label_set_angle (GTK_LABEL (widget), 90);

      gtk_container_add (GTK_CONTAINER (frame), widget);

      gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
      gtk_label_set_line_wrap_mode (GTK_LABEL (widget), PANGO_WRAP_WORD);
      gtk_label_set_width_chars (GTK_LABEL (widget), 10);

      gtk_wrap_box_insert_child (GTK_WRAP_BOX (wrapbox), frame, -1,
				    items_xpad, items_ypad, 
				    items_xexpand, items_yexpand, items_xfill, items_yfill);
    }
}


static void
populate_wrapbox_stock (GtkWrapBox *wrapbox)
{
  GtkWidget *widget;
  static GSList *stock_ids = NULL;
  GSList *l;
  gint i;

  if (!stock_ids)
    stock_ids = gtk_stock_list_ids ();

  for (i = 0, l = stock_ids; i < 30 && l != NULL; i++, l = l->next)
    {
      gchar *stock_id = l->data;

      widget = gtk_button_new_from_stock (stock_id);
      gtk_widget_show (widget);

      gtk_wrap_box_insert_child (GTK_WRAP_BOX (wrapbox), widget, -1,
				    items_xpad, items_ypad, 
				    items_xexpand, items_yexpand, items_xfill, items_yfill);
    }
}

static void 
populate_items (GtkWrapBox *wrapbox)
{
  GList *children, *l;
  
  /* Remove all children first */
  children = gtk_container_get_children (GTK_CONTAINER (wrapbox));
  for (l = children; l; l = l->next)
    {
      GtkWidget *child = l->data;

      gtk_container_remove (GTK_CONTAINER (wrapbox), child);
    }
  g_list_free (children);

  if (items_type == SIMPLE_ITEMS)
    populate_wrapbox_simple (wrapbox);
  else if (items_type == WRAPPY_ITEMS)
    populate_wrapbox_wrappy (wrapbox);
  else if (items_type == STOCK_ITEMS)
    populate_wrapbox_stock (wrapbox);
}


static void
mode_changed (GtkComboBox   *box,
	      GtkWrapBox    *wrapbox)
{
  GtkWrapAllocationMode mode = gtk_combo_box_get_active (box);
  
  gtk_wrap_box_set_allocation_mode (wrapbox, mode);
}

static void
spreading_changed (GtkComboBox   *box,
		   GtkWrapBox    *wrapbox)
{
  GtkWrapBoxSpreading spreading = gtk_combo_box_get_active (box);
  
  gtk_wrap_box_set_spreading (wrapbox, spreading);
}

static void
orientation_changed (GtkComboBox   *box,
		     GtkWrapBox *wrapbox)
{
  GtkOrientation orientation = gtk_combo_box_get_active (box);

  gtk_orientable_set_orientation (GTK_ORIENTABLE (wrapbox), orientation);
}

static void
line_length_changed (GtkSpinButton *spin,
		     GtkWrapBox *wrapbox)
{
  gint length = gtk_spin_button_get_value_as_int (spin);
  
  gtk_wrap_box_set_minimum_line_children (wrapbox, length);
}

static void
spacing_changed (GtkSpinButton *button,
		 gpointer       data)
{
  GtkOrientation orientation = GPOINTER_TO_INT (data);
  gint           state = gtk_spin_button_get_value_as_int (button);

  if (orientation == GTK_ORIENTATION_HORIZONTAL)
    gtk_wrap_box_set_horizontal_spacing (the_wrapbox, state);
  else
    gtk_wrap_box_set_vertical_spacing (the_wrapbox, state);
}


static void
items_changed (GtkComboBox   *box,
	       GtkWrapBox *wrapbox)
{
  items_type = gtk_combo_box_get_active (box);

  populate_items (wrapbox);
}

static void
text_orientation_changed (GtkComboBox   *box,
			  GtkWrapBox *wrapbox)
{
  text_orientation = gtk_combo_box_get_active (box);
  
  populate_items (wrapbox);
}

static void
child_option_toggled (GtkToggleButton *button,
		      gboolean        *state)
{
  *state = gtk_toggle_button_get_active (button);

  populate_items (the_wrapbox);
}

static void
child_padding_changed (GtkSpinButton *button,
		       gint          *state)
{
  *state = gtk_spin_button_get_value_as_int (button);

  populate_items (the_wrapbox);
}

static GtkWidget *
create_window (void)
{
  GtkWidget *window, *hbox, *vbox, *frame, *wrapbox_cntl, *items_cntl;
  GtkWidget *wrapbox, *widget, *expander, *swindow;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  hbox   = gtk_hbox_new (FALSE, 2);
  vbox   = gtk_vbox_new (FALSE, 6);

  gtk_container_set_border_width (GTK_CONTAINER (window), 8);

  gtk_widget_show (vbox);
  gtk_widget_show (hbox);
  gtk_container_add (GTK_CONTAINER (window), hbox);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);

  frame = gtk_frame_new ("Wrap Box");
  gtk_widget_show (frame);
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);

  swindow = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (swindow);
  gtk_container_add (GTK_CONTAINER (frame), swindow);

  wrapbox = gtk_wrap_box_new (INITIAL_ALLOCATION_MODE, INITIAL_SPREADING, 
			      INITIAL_HSPACING, INITIAL_VSPACING);
  the_wrapbox = (GtkWrapBox *)wrapbox;
  gtk_wrap_box_set_minimum_line_children (GTK_WRAP_BOX (wrapbox), INITIAL_MINIMUM_LENGTH);
  gtk_widget_show (wrapbox);
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swindow), wrapbox);

  /* Add Wrapbox test control frame */
  expander = gtk_expander_new ("Wrap Box controls");
  gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
  wrapbox_cntl = gtk_vbox_new (FALSE, 2);
  gtk_widget_show (wrapbox_cntl);
  gtk_widget_show (expander);
  gtk_container_add (GTK_CONTAINER (expander), wrapbox_cntl);
  gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 0);

  /* Add Allocation mode control */
  widget = gtk_combo_box_new_text ();
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Wrap Freely");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Align items");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Homogeneous");
  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), INITIAL_ALLOCATION_MODE);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the wrapbox allocation mode");
  gtk_box_pack_start (GTK_BOX (wrapbox_cntl), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (mode_changed), wrapbox);

  /* Add Spreading control */
  widget = gtk_combo_box_new_text ();
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Spread Begin");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Spread End");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Spread Even");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Spread Expand");
  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), INITIAL_SPREADING);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the wrapbox spread mode");
  gtk_box_pack_start (GTK_BOX (wrapbox_cntl), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (spreading_changed), wrapbox);

  /* Add Orientation control */
  widget = gtk_combo_box_new_text ();
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Horizontal");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Vertical");
  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the wrapbox orientation");
  gtk_box_pack_start (GTK_BOX (wrapbox_cntl), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (orientation_changed), wrapbox);

  /* Add minimum line length in items control */
  widget = gtk_spin_button_new_with_range (1, 10, 1);
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), INITIAL_MINIMUM_LENGTH);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the minimum amount of items per line before wrapping");
  gtk_box_pack_start (GTK_BOX (wrapbox_cntl), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (line_length_changed), wrapbox);
  g_signal_connect (G_OBJECT (widget), "value-changed",
		    G_CALLBACK (line_length_changed), wrapbox);

  /* Add horizontal/vertical spacing controls */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox);

  widget = gtk_label_new ("H Spacing");
  gtk_widget_show (widget);
  gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);

  widget = gtk_spin_button_new_with_range (0, 30, 1);
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), INITIAL_HSPACING);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the horizontal spacing between children");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_HORIZONTAL));
  g_signal_connect (G_OBJECT (widget), "value-changed",
		    G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_HORIZONTAL));

  gtk_box_pack_start (GTK_BOX (wrapbox_cntl), hbox, FALSE, FALSE, 0);

  hbox = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox);

  widget = gtk_label_new ("V Spacing");
  gtk_widget_show (widget);
  gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);

  widget = gtk_spin_button_new_with_range (0, 30, 1);
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), INITIAL_VSPACING);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the vertical spacing between children");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_VERTICAL));
  g_signal_connect (G_OBJECT (widget), "value-changed",
		    G_CALLBACK (spacing_changed), GINT_TO_POINTER (GTK_ORIENTATION_VERTICAL));

  gtk_box_pack_start (GTK_BOX (wrapbox_cntl), hbox, FALSE, FALSE, 0);


  /* Add test items control frame */
  expander = gtk_expander_new ("Test item controls");
  gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
  items_cntl = gtk_vbox_new (FALSE, 2);
  gtk_widget_show (items_cntl);
  gtk_widget_show (expander);
  gtk_container_add (GTK_CONTAINER (expander), items_cntl);
  gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 0);

  /* Add Items control */
  widget = gtk_combo_box_new_text ();
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Simple");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Wrappy");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Stock");
  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the item set to use");
  gtk_box_pack_start (GTK_BOX (items_cntl), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (items_changed), wrapbox);


  /* Add Text Orientation control */
  widget = gtk_combo_box_new_text ();
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Horizontal");
  gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "Vertical");
  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the item's text orientation (cant be done for stock buttons)");
  gtk_box_pack_start (GTK_BOX (items_cntl), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (text_orientation_changed), wrapbox);


  /* Add expand/fill options */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox);

  widget = gtk_check_button_new_with_label ("X Expand");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set whether the items expand horizontally");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "toggled",
		    G_CALLBACK (child_option_toggled), &items_xexpand);


  widget = gtk_check_button_new_with_label ("X Fill");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set whether the items fill their allotted size horizontally");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "toggled",
		    G_CALLBACK (child_option_toggled), &items_xfill);

  gtk_box_pack_start (GTK_BOX (items_cntl), hbox, FALSE, FALSE, 0);


  hbox = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox);

  widget = gtk_check_button_new_with_label ("Y Expand");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set whether the items expand vertically");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "toggled",
		    G_CALLBACK (child_option_toggled), &items_yexpand);


  widget = gtk_check_button_new_with_label ("Y Fill");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set whether the items fill their allotted size vertically");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "toggled",
		    G_CALLBACK (child_option_toggled), &items_yfill);

  gtk_box_pack_start (GTK_BOX (items_cntl), hbox, FALSE, FALSE, 0);


  /* Add x/y padding options */
  hbox = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox);

  widget = gtk_label_new ("X Padding");
  gtk_widget_show (widget);
  gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);

  widget = gtk_spin_button_new_with_range (0, 30, 1);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the horizontal padding values for children");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (child_padding_changed), &items_xpad);
  g_signal_connect (G_OBJECT (widget), "value-changed",
		    G_CALLBACK (child_padding_changed), &items_xpad);

  gtk_box_pack_start (GTK_BOX (items_cntl), hbox, FALSE, FALSE, 0);


  hbox = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox);

  widget = gtk_label_new ("Y Padding");
  gtk_widget_show (widget);
  gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);

  widget = gtk_spin_button_new_with_range (0, 30, 1);
  gtk_widget_show (widget);

  gtk_widget_set_tooltip_text (widget, "Set the vertical padding values for children");
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (widget), "changed",
		    G_CALLBACK (child_padding_changed), &items_ypad);
  g_signal_connect (G_OBJECT (widget), "value-changed",
		    G_CALLBACK (child_padding_changed), &items_ypad);

  gtk_box_pack_start (GTK_BOX (items_cntl), hbox, FALSE, FALSE, 0);

  populate_items (GTK_WRAP_BOX (wrapbox));

  return window;
}



int
main (int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init (&argc, &argv);

  window = create_window ();

  g_signal_connect (window, "delete-event",
                    G_CALLBACK (gtk_main_quit), window);

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}