]> Pileus Git - ~andy/gtk/blob - gtk/testgtk.c
6869f309651eb7f80a3a1fbda65f3ae12f5e8fd7
[~andy/gtk] / gtk / testgtk.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "gtk.h"
21 #include "../gdk/gdk.h"
22 #include "../gdk/gdkx.h"
23
24 void
25 destroy_window (GtkWidget  *widget,
26                 GtkWidget **window)
27 {
28   *window = NULL;
29 }
30
31 void
32 destroy_tooltips (GtkWidget *widget, GtkWindow **window)
33 {
34   GtkTooltips *tt = gtk_object_get_data (GTK_OBJECT (*window), "tooltips");
35   gtk_object_unref (GTK_OBJECT (tt));
36   
37   *window = NULL;
38 }
39
40 void
41 button_window (GtkWidget *widget,
42                GtkWidget *button)
43 {
44   if (!GTK_WIDGET_VISIBLE (button))
45     gtk_widget_show (button);
46   else
47     gtk_widget_hide (button);
48 }
49
50 void
51 create_buttons ()
52 {
53   static GtkWidget *window = NULL;
54   GtkWidget *box1;
55   GtkWidget *box2;
56   GtkWidget *table;
57   GtkWidget *button[10];
58   GtkWidget *separator;
59
60   if (!window)
61     {
62       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
63
64       gtk_signal_connect (GTK_OBJECT (window), "destroy",
65                           GTK_SIGNAL_FUNC (destroy_window),
66                           &window);
67       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
68                           GTK_SIGNAL_FUNC (gtk_true),
69                           &window);
70
71       gtk_window_set_title (GTK_WINDOW (window), "buttons");
72       gtk_container_border_width (GTK_CONTAINER (window), 0);
73
74       box1 = gtk_vbox_new (FALSE, 0);
75       gtk_container_add (GTK_CONTAINER (window), box1);
76       gtk_widget_show (box1);
77
78
79       table = gtk_table_new (3, 3, FALSE);
80       gtk_table_set_row_spacings (GTK_TABLE (table), 5);
81       gtk_table_set_col_spacings (GTK_TABLE (table), 5);
82       gtk_container_border_width (GTK_CONTAINER (table), 10);
83       gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
84       gtk_widget_show (table);
85
86
87       button[0] = gtk_button_new_with_label ("button1");
88       button[1] = gtk_button_new_with_label ("button2");
89       button[2] = gtk_button_new_with_label ("button3");
90       button[3] = gtk_button_new_with_label ("button4");
91       button[4] = gtk_button_new_with_label ("button5");
92       button[5] = gtk_button_new_with_label ("button6");
93       button[6] = gtk_button_new_with_label ("button7");
94       button[7] = gtk_button_new_with_label ("button8");
95       button[8] = gtk_button_new_with_label ("button9");
96
97       gtk_signal_connect (GTK_OBJECT (button[0]), "clicked",
98                           GTK_SIGNAL_FUNC(button_window),
99                           button[1]);
100
101       gtk_table_attach (GTK_TABLE (table), button[0], 0, 1, 0, 1,
102                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
103       gtk_widget_show (button[0]);
104
105       gtk_signal_connect (GTK_OBJECT (button[1]), "clicked",
106                           GTK_SIGNAL_FUNC(button_window),
107                           button[2]);
108
109       gtk_table_attach (GTK_TABLE (table), button[1], 1, 2, 1, 2,
110                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
111       gtk_widget_show (button[1]);
112
113       gtk_signal_connect (GTK_OBJECT (button[2]), "clicked",
114                           GTK_SIGNAL_FUNC(button_window),
115                           button[3]);
116       gtk_table_attach (GTK_TABLE (table), button[2], 2, 3, 2, 3,
117                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
118       gtk_widget_show (button[2]);
119
120       gtk_signal_connect (GTK_OBJECT (button[3]), "clicked",
121                           GTK_SIGNAL_FUNC(button_window),
122                           button[4]);
123       gtk_table_attach (GTK_TABLE (table), button[3], 0, 1, 2, 3,
124                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
125       gtk_widget_show (button[3]);
126
127       gtk_signal_connect (GTK_OBJECT (button[4]), "clicked",
128                           GTK_SIGNAL_FUNC(button_window),
129                           button[5]);
130       gtk_table_attach (GTK_TABLE (table), button[4], 2, 3, 0, 1,
131                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
132       gtk_widget_show (button[4]);
133
134       gtk_signal_connect (GTK_OBJECT (button[5]), "clicked",
135                           GTK_SIGNAL_FUNC(button_window),
136                           button[6]);
137       gtk_table_attach (GTK_TABLE (table), button[5], 1, 2, 2, 3,
138                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
139       gtk_widget_show (button[5]);
140
141       gtk_signal_connect (GTK_OBJECT (button[6]), "clicked",
142                           GTK_SIGNAL_FUNC(button_window),
143                           button[7]);
144       gtk_table_attach (GTK_TABLE (table), button[6], 1, 2, 0, 1,
145                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
146       gtk_widget_show (button[6]);
147
148       gtk_signal_connect (GTK_OBJECT (button[7]), "clicked",
149                           GTK_SIGNAL_FUNC(button_window),
150                           button[8]);
151       gtk_table_attach (GTK_TABLE (table), button[7], 2, 3, 1, 2,
152                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
153       gtk_widget_show (button[7]);
154
155       gtk_signal_connect (GTK_OBJECT (button[8]), "clicked",
156                           GTK_SIGNAL_FUNC(button_window),
157                           button[0]);
158       gtk_table_attach (GTK_TABLE (table), button[8], 0, 1, 1, 2,
159                         GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
160       gtk_widget_show (button[8]);
161
162
163       separator = gtk_hseparator_new ();
164       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
165       gtk_widget_show (separator);
166
167
168       box2 = gtk_vbox_new (FALSE, 10);
169       gtk_container_border_width (GTK_CONTAINER (box2), 10);
170       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
171       gtk_widget_show (box2);
172
173
174       button[9] = gtk_button_new_with_label ("close");
175       gtk_signal_connect_object (GTK_OBJECT (button[9]), "clicked",
176                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
177                                  GTK_OBJECT (window));
178       gtk_box_pack_start (GTK_BOX (box2), button[9], TRUE, TRUE, 0);
179       GTK_WIDGET_SET_FLAGS (button[9], GTK_CAN_DEFAULT);
180       gtk_widget_grab_default (button[9]);
181       gtk_widget_show (button[9]);
182     }
183
184   if (!GTK_WIDGET_VISIBLE (window))
185     gtk_widget_show (window);
186   else
187     gtk_widget_destroy (window);
188 }
189
190 void
191 create_toggle_buttons ()
192 {
193   static GtkWidget *window = NULL;
194   GtkWidget *box1;
195   GtkWidget *box2;
196   GtkWidget *button;
197   GtkWidget *separator;
198
199   if (!window)
200     {
201       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
202
203       gtk_signal_connect (GTK_OBJECT (window), "destroy",
204                           GTK_SIGNAL_FUNC(destroy_window),
205                           &window);
206       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
207                           GTK_SIGNAL_FUNC(destroy_window),
208                           &window);
209
210       gtk_window_set_title (GTK_WINDOW (window), "toggle buttons");
211       gtk_container_border_width (GTK_CONTAINER (window), 0);
212
213
214       box1 = gtk_vbox_new (FALSE, 0);
215       gtk_container_add (GTK_CONTAINER (window), box1);
216       gtk_widget_show (box1);
217
218
219       box2 = gtk_vbox_new (FALSE, 10);
220       gtk_container_border_width (GTK_CONTAINER (box2), 10);
221       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
222       gtk_widget_show (box2);
223
224
225       button = gtk_toggle_button_new_with_label ("button1");
226       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
227       gtk_widget_show (button);
228
229       button = gtk_toggle_button_new_with_label ("button2");
230       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
231       gtk_widget_show (button);
232
233       button = gtk_toggle_button_new_with_label ("button3");
234       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
235       gtk_widget_show (button);
236
237
238       separator = gtk_hseparator_new ();
239       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
240       gtk_widget_show (separator);
241
242
243       box2 = gtk_vbox_new (FALSE, 10);
244       gtk_container_border_width (GTK_CONTAINER (box2), 10);
245       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
246       gtk_widget_show (box2);
247
248
249       button = gtk_button_new_with_label ("close");
250       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
251                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
252                                  GTK_OBJECT (window));
253       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
254       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
255       gtk_widget_grab_default (button);
256       gtk_widget_show (button);
257     }
258
259   if (!GTK_WIDGET_VISIBLE (window))
260     gtk_widget_show (window);
261   else
262     gtk_widget_destroy (window);
263 }
264
265 void
266 create_check_buttons ()
267 {
268   static GtkWidget *window = NULL;
269   GtkWidget *box1;
270   GtkWidget *box2;
271   GtkWidget *button;
272   GtkWidget *separator;
273
274   if (!window)
275     {
276       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
277
278       gtk_signal_connect (GTK_OBJECT (window), "destroy",
279                           GTK_SIGNAL_FUNC(destroy_window),
280                           &window);
281       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
282                           GTK_SIGNAL_FUNC(destroy_window),
283                           &window);
284
285       gtk_window_set_title (GTK_WINDOW (window), "check buttons");
286       gtk_container_border_width (GTK_CONTAINER (window), 0);
287
288
289       box1 = gtk_vbox_new (FALSE, 0);
290       gtk_container_add (GTK_CONTAINER (window), box1);
291       gtk_widget_show (box1);
292
293
294       box2 = gtk_vbox_new (FALSE, 10);
295       gtk_container_border_width (GTK_CONTAINER (box2), 10);
296       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
297       gtk_widget_show (box2);
298
299
300       button = gtk_check_button_new_with_label ("button1");
301       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
302       gtk_widget_show (button);
303
304       button = gtk_check_button_new_with_label ("button2");
305       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
306       gtk_widget_show (button);
307
308       button = gtk_check_button_new_with_label ("button3");
309       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
310       gtk_widget_show (button);
311
312
313       separator = gtk_hseparator_new ();
314       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
315       gtk_widget_show (separator);
316
317
318       box2 = gtk_vbox_new (FALSE, 10);
319       gtk_container_border_width (GTK_CONTAINER (box2), 10);
320       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
321       gtk_widget_show (box2);
322
323
324       button = gtk_button_new_with_label ("close");
325       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
326                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
327                                  GTK_OBJECT (window));
328       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
329       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
330       gtk_widget_grab_default (button);
331       gtk_widget_show (button);
332     }
333
334   if (!GTK_WIDGET_VISIBLE (window))
335     gtk_widget_show (window);
336   else
337     gtk_widget_destroy (window);
338 }
339
340 void
341 create_radio_buttons ()
342 {
343   static GtkWidget *window = NULL;
344   GtkWidget *box1;
345   GtkWidget *box2;
346   GtkWidget *button;
347   GtkWidget *separator;
348
349   if (!window)
350     {
351       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
352
353       gtk_signal_connect (GTK_OBJECT (window), "destroy",
354                           GTK_SIGNAL_FUNC(destroy_window),
355                           &window);
356       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
357                           GTK_SIGNAL_FUNC(destroy_window),
358                           &window);
359
360       gtk_window_set_title (GTK_WINDOW (window), "radio buttons");
361       gtk_container_border_width (GTK_CONTAINER (window), 0);
362
363
364       box1 = gtk_vbox_new (FALSE, 0);
365       gtk_container_add (GTK_CONTAINER (window), box1);
366       gtk_widget_show (box1);
367
368
369       box2 = gtk_vbox_new (FALSE, 10);
370       gtk_container_border_width (GTK_CONTAINER (box2), 10);
371       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
372       gtk_widget_show (box2);
373
374
375       button = gtk_radio_button_new_with_label (NULL, "button1");
376       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
377       gtk_widget_show (button);
378
379       button = gtk_radio_button_new_with_label (
380                  gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
381                  "button2");
382       gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
383       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
384       gtk_widget_show (button);
385
386       button = gtk_radio_button_new_with_label (
387                  gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
388                  "button3");
389       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
390       gtk_widget_show (button);
391
392
393       separator = gtk_hseparator_new ();
394       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
395       gtk_widget_show (separator);
396
397
398       box2 = gtk_vbox_new (FALSE, 10);
399       gtk_container_border_width (GTK_CONTAINER (box2), 10);
400       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
401       gtk_widget_show (box2);
402
403
404       button = gtk_button_new_with_label ("close");
405       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
406                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
407                                  GTK_OBJECT (window));
408       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
409       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
410       gtk_widget_grab_default (button);
411       gtk_widget_show (button);
412     }
413
414   if (!GTK_WIDGET_VISIBLE (window))
415     gtk_widget_show (window);
416   else
417     gtk_widget_destroy (window);
418 }
419
420 void
421 bbox_widget_destroy (GtkWidget* widget, GtkWidget* todestroy)
422 {
423 }
424
425 void
426 create_bbox_window (gint  horizontal,
427                     char* title, 
428                     gint  pos, 
429                     gint  spacing,
430                     gint  child_w, 
431                     gint  child_h, 
432                     gint  layout)
433 {
434   GtkWidget* window;
435   GtkWidget* box1;
436   GtkWidget* bbox;
437   GtkWidget* button;
438         
439   /* create a new window */
440   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
441   gtk_window_set_title (GTK_WINDOW (window), title);
442
443   gtk_signal_connect (GTK_OBJECT (window), "destroy",
444                       GTK_SIGNAL_FUNC(bbox_widget_destroy), window);
445   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
446                       GTK_SIGNAL_FUNC(bbox_widget_destroy), window);
447   
448   if (horizontal)
449   {
450     gtk_widget_set_usize (window, 550, 60);
451     gtk_widget_set_uposition (window, 150, pos);
452     box1 = gtk_vbox_new (FALSE, 0);
453   }
454   else
455   {
456     gtk_widget_set_usize (window, 150, 400);
457     gtk_widget_set_uposition (window, pos, 200);
458     box1 = gtk_vbox_new (FALSE, 0);
459   }
460   
461   gtk_container_add (GTK_CONTAINER (window), box1);
462   gtk_widget_show (box1);
463   
464   if (horizontal)
465     bbox = gtk_hbutton_box_new();
466   else
467     bbox = gtk_vbutton_box_new();
468   gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
469   gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), spacing);
470   gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h);
471   gtk_widget_show (bbox);
472   
473   gtk_container_border_width (GTK_CONTAINER(box1), 25);
474   gtk_box_pack_start (GTK_BOX (box1), bbox, TRUE, TRUE, 0);
475   
476   button = gtk_button_new_with_label ("OK");
477   gtk_container_add (GTK_CONTAINER(bbox), button);
478
479   gtk_signal_connect (GTK_OBJECT (button), "clicked",
480                       GTK_SIGNAL_FUNC(bbox_widget_destroy), window);
481
482   gtk_widget_show (button);
483   
484   button = gtk_button_new_with_label ("Cancel");
485   gtk_container_add (GTK_CONTAINER(bbox), button);
486   gtk_widget_show (button);
487   
488   button = gtk_button_new_with_label ("Help");
489   gtk_container_add (GTK_CONTAINER(bbox), button);
490   gtk_widget_show (button);
491   
492   gtk_widget_show (window);
493 }
494
495 void
496 test_hbbox ()
497 {
498   create_bbox_window (TRUE, "Spread", 50, 40, 85, 28, GTK_BUTTONBOX_SPREAD);
499   create_bbox_window (TRUE, "Edge", 200, 40, 85, 25, GTK_BUTTONBOX_EDGE);
500   create_bbox_window (TRUE, "Start", 350, 40, 85, 25, GTK_BUTTONBOX_START);
501   create_bbox_window (TRUE, "End", 500, 15, 30, 25, GTK_BUTTONBOX_END);
502 }
503
504 void
505 test_vbbox ()
506 {
507   create_bbox_window (FALSE, "Spread", 50, 40, 85, 25, GTK_BUTTONBOX_SPREAD);
508   create_bbox_window (FALSE, "Edge", 250, 40, 85, 28, GTK_BUTTONBOX_EDGE);
509   create_bbox_window (FALSE, "Start", 450, 40, 85, 25, GTK_BUTTONBOX_START);
510   create_bbox_window (FALSE, "End", 650, 15, 30, 25, GTK_BUTTONBOX_END);
511
512
513 void
514 create_button_box ()
515 {
516   static GtkWidget* window = NULL;
517   GtkWidget* bbox;
518   GtkWidget* button;
519         
520   if (!window)
521   {
522     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
523     gtk_window_set_title (GTK_WINDOW (window),
524                           "Button Box Test");
525     
526     gtk_signal_connect (GTK_OBJECT (window), "destroy",
527                         GTK_SIGNAL_FUNC(destroy_window), &window);
528     gtk_signal_connect (GTK_OBJECT (window), "delete_event",
529                         GTK_SIGNAL_FUNC(destroy_window), &window);
530     
531     gtk_container_border_width (GTK_CONTAINER (window), 20);
532     
533     /* 
534      *these 15 lines are a nice and easy example for GtkHButtonBox 
535      */
536     bbox = gtk_hbutton_box_new ();
537     gtk_container_add (GTK_CONTAINER (window), bbox);
538     gtk_widget_show (bbox);
539     
540     button = gtk_button_new_with_label ("Horizontal");
541     gtk_signal_connect (GTK_OBJECT (button), "clicked",
542                         GTK_SIGNAL_FUNC(test_hbbox), 0);
543     gtk_container_add (GTK_CONTAINER (bbox), button);
544     gtk_widget_show (button);
545     
546     button = gtk_button_new_with_label ("Vertical");
547     gtk_signal_connect (GTK_OBJECT (button), "clicked",
548                         GTK_SIGNAL_FUNC(test_vbbox), 0);
549     gtk_container_add (GTK_CONTAINER (bbox), button);
550     gtk_widget_show (button);
551   }
552
553   if (!GTK_WIDGET_VISIBLE (window))
554     gtk_widget_show (window);
555   else
556     gtk_widget_destroy (window);
557 }
558
559 GtkWidget *
560 new_pixmap (char      *filename,
561             GdkWindow *window,
562             GdkColor  *background)
563 {
564   GtkWidget *wpixmap;
565   GdkPixmap *pixmap;
566   GdkBitmap *mask;
567
568   pixmap = gdk_pixmap_create_from_xpm (window, &mask,
569                                        background,
570                                        "test.xpm");
571   wpixmap = gtk_pixmap_new (pixmap, mask);
572
573   return wpixmap;
574 }
575
576 void
577 set_toolbar_horizontal (GtkWidget *widget,
578                         gpointer   data)
579 {
580   gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_HORIZONTAL);
581 }
582
583 void
584 set_toolbar_vertical (GtkWidget *widget,
585                       gpointer   data)
586 {
587   gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_VERTICAL);
588 }
589
590 void
591 set_toolbar_icons (GtkWidget *widget,
592                    gpointer   data)
593 {
594   gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_ICONS);
595 }
596
597 void
598 set_toolbar_text (GtkWidget *widget,
599                   gpointer   data)
600 {
601   gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_TEXT);
602 }
603
604 void
605 set_toolbar_both (GtkWidget *widget,
606                   gpointer   data)
607 {
608   gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH);
609 }
610
611 void
612 set_toolbar_small_space (GtkWidget *widget,
613                          gpointer   data)
614 {
615   gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 5);
616 }
617
618 void
619 set_toolbar_big_space (GtkWidget *widget,
620                        gpointer   data)
621 {
622   gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 10);
623 }
624
625 void
626 set_toolbar_enable (GtkWidget *widget,
627                     gpointer   data)
628 {
629   gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), TRUE);
630 }
631
632 void
633 set_toolbar_disable (GtkWidget *widget,
634                      gpointer   data)
635 {
636   gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), FALSE);
637 }
638
639 void
640 create_toolbar (void)
641 {
642   static GtkWidget *window = NULL;
643   GtkWidget *toolbar;
644   GtkWidget *entry;
645
646   if (!window)
647     {
648       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
649       gtk_window_set_title (GTK_WINDOW (window), "Toolbar test");
650       gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, TRUE);
651
652       gtk_signal_connect (GTK_OBJECT (window), "destroy",
653                           GTK_SIGNAL_FUNC (destroy_window),
654                           &window);
655       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
656                           GTK_SIGNAL_FUNC (destroy_window),
657                           &window);
658
659       gtk_container_border_width (GTK_CONTAINER (window), 0);
660       gtk_widget_realize (window);
661
662       toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
663
664       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
665                                "Horizontal", "Horizontal toolbar layout",
666                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
667                                (GtkSignalFunc) set_toolbar_horizontal, toolbar);
668       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
669                                "Vertical", "Vertical toolbar layout",
670                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
671                                (GtkSignalFunc) set_toolbar_vertical, toolbar);
672
673       gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));
674
675       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
676                                "Icons", "Only show toolbar icons",
677                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
678                                (GtkSignalFunc) set_toolbar_icons, toolbar);
679       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
680                                "Text", "Only show toolbar text",
681                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
682                                (GtkSignalFunc) set_toolbar_text, toolbar);
683       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
684                                "Both", "Show toolbar icons and text",
685                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
686                                (GtkSignalFunc) set_toolbar_both, toolbar);
687
688       gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
689
690       entry = gtk_entry_new ();
691       gtk_widget_show(entry);
692       gtk_toolbar_append_widget (GTK_TOOLBAR (toolbar), entry, NULL);
693
694       gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
695
696       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
697                                "Small", "Use small spaces",
698                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
699                                (GtkSignalFunc) set_toolbar_small_space, toolbar);
700       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
701                                "Big", "Use big spaces",
702                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
703                                (GtkSignalFunc) set_toolbar_big_space, toolbar);
704
705       gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
706
707       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
708                                "Enable", "Enable tooltips",
709                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
710                                (GtkSignalFunc) set_toolbar_enable, toolbar);
711       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
712                                "Disable", "Disable tooltips",
713                                new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
714                                (GtkSignalFunc) set_toolbar_disable, toolbar);
715
716       gtk_container_add (GTK_CONTAINER (window), toolbar);
717       gtk_widget_show (toolbar);
718     }
719
720   if (!GTK_WIDGET_VISIBLE (window))
721     gtk_widget_show (window);
722   else
723     gtk_widget_destroy (window);
724 }
725
726 GtkWidget *
727 make_toolbar (GtkWidget *window)
728 {
729   GtkWidget *toolbar;
730
731   if (!GTK_WIDGET_REALIZED (window))
732     gtk_widget_realize (window);
733
734   toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
735
736   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
737                            "Horizontal", "Horizontal toolbar layout",
738                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
739                            (GtkSignalFunc) set_toolbar_horizontal, toolbar);
740   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
741                            "Vertical", "Vertical toolbar layout",
742                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
743                            (GtkSignalFunc) set_toolbar_vertical, toolbar);
744
745   gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));
746
747   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
748                            "Icons", "Only show toolbar icons",
749                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
750                            (GtkSignalFunc) set_toolbar_icons, toolbar);
751   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
752                            "Text", "Only show toolbar text",
753                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
754                            (GtkSignalFunc) set_toolbar_text, toolbar);
755   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
756                            "Both", "Show toolbar icons and text",
757                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
758                            (GtkSignalFunc) set_toolbar_both, toolbar);
759
760   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
761
762   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
763                            "Small", "Use small spaces",
764                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
765                            (GtkSignalFunc) set_toolbar_small_space, toolbar);
766   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
767                            "Big", "Use big spaces",
768                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
769                            (GtkSignalFunc) set_toolbar_big_space, toolbar);
770
771   gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
772
773   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
774                            "Enable", "Enable tooltips",
775                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
776                            (GtkSignalFunc) set_toolbar_enable, toolbar);
777   gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
778                            "Disable", "Disable tooltips",
779                            new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
780                            (GtkSignalFunc) set_toolbar_disable, toolbar);
781
782   return toolbar;
783 }
784
785 void
786 create_handle_box ()
787 {
788   static GtkWidget* window = NULL;
789   GtkWidget *hbox;
790   GtkWidget *toolbar;
791         
792   if (!window)
793   {
794     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
795     gtk_window_set_title (GTK_WINDOW (window),
796                           "Handle Box Test");
797     
798     gtk_signal_connect (GTK_OBJECT (window), "destroy",
799                         GTK_SIGNAL_FUNC(destroy_window), &window);
800     gtk_signal_connect (GTK_OBJECT (window), "delete_event",
801                         GTK_SIGNAL_FUNC(destroy_window), &window);
802     
803     gtk_container_border_width (GTK_CONTAINER (window), 20);
804     
805     hbox = gtk_handle_box_new ();
806     gtk_container_add (GTK_CONTAINER (window), hbox);
807     gtk_widget_show (hbox);
808
809     toolbar = make_toolbar (window);
810     gtk_container_add (GTK_CONTAINER (hbox), toolbar);
811     gtk_widget_show (toolbar);
812   }
813
814   if (!GTK_WIDGET_VISIBLE (window))
815     gtk_widget_show (window);
816   else
817     gtk_widget_destroy (window);
818 }
819
820
821 void
822 reparent_label (GtkWidget *widget,
823                 GtkWidget *new_parent)
824 {
825   GtkWidget *label;
826
827   label = gtk_object_get_user_data (GTK_OBJECT (widget));
828
829   gtk_widget_reparent (label, new_parent);
830 }
831
832 void
833 create_reparent ()
834 {
835   static GtkWidget *window = NULL;
836   GtkWidget *box1;
837   GtkWidget *box2;
838   GtkWidget *box3;
839   GtkWidget *frame;
840   GtkWidget *button;
841   GtkWidget *label;
842   GtkWidget *separator;
843
844   if (!window)
845     {
846       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
847
848       gtk_signal_connect (GTK_OBJECT (window), "destroy",
849                           GTK_SIGNAL_FUNC(destroy_window),
850                           &window);
851       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
852                           GTK_SIGNAL_FUNC(destroy_window),
853                           &window);
854
855       gtk_window_set_title (GTK_WINDOW (window), "buttons");
856       gtk_container_border_width (GTK_CONTAINER (window), 0);
857
858
859       box1 = gtk_vbox_new (FALSE, 0);
860       gtk_container_add (GTK_CONTAINER (window), box1);
861       gtk_widget_show (box1);
862
863
864       box2 = gtk_hbox_new (FALSE, 5);
865       gtk_container_border_width (GTK_CONTAINER (box2), 10);
866       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
867       gtk_widget_show (box2);
868
869
870       label = gtk_label_new ("Hello World");
871
872       frame = gtk_frame_new ("Frame 1");
873       gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0);
874       gtk_widget_show (frame);
875
876       box3 = gtk_vbox_new (FALSE, 5);
877       gtk_container_border_width (GTK_CONTAINER (box3), 5);
878       gtk_container_add (GTK_CONTAINER (frame), box3);
879       gtk_widget_show (box3);
880
881       button = gtk_button_new_with_label ("switch");
882       gtk_signal_connect (GTK_OBJECT (button), "clicked",
883                           GTK_SIGNAL_FUNC(reparent_label),
884                           box3);
885       gtk_object_set_user_data (GTK_OBJECT (button), label);
886       gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0);
887       gtk_widget_show (button);
888
889       gtk_box_pack_start (GTK_BOX (box3), label, FALSE, TRUE, 0);
890       gtk_widget_show (label);
891
892
893       frame = gtk_frame_new ("Frame 2");
894       gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0);
895       gtk_widget_show (frame);
896
897       box3 = gtk_vbox_new (FALSE, 5);
898       gtk_container_border_width (GTK_CONTAINER (box3), 5);
899       gtk_container_add (GTK_CONTAINER (frame), box3);
900       gtk_widget_show (box3);
901
902       button = gtk_button_new_with_label ("switch");
903       gtk_signal_connect (GTK_OBJECT (button), "clicked",
904                           GTK_SIGNAL_FUNC(reparent_label),
905                           box3);
906       gtk_object_set_user_data (GTK_OBJECT (button), label);
907       gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0);
908       gtk_widget_show (button);
909
910
911       separator = gtk_hseparator_new ();
912       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
913       gtk_widget_show (separator);
914
915
916       box2 = gtk_vbox_new (FALSE, 10);
917       gtk_container_border_width (GTK_CONTAINER (box2), 10);
918       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
919       gtk_widget_show (box2);
920
921
922       button = gtk_button_new_with_label ("close");
923       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
924                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
925                                  GTK_OBJECT (window));
926       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
927       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
928       gtk_widget_grab_default (button);
929       gtk_widget_show (button);
930     }
931
932   if (!GTK_WIDGET_VISIBLE (window))
933     gtk_widget_show (window);
934   else
935     gtk_widget_destroy (window);
936 }
937
938 void
939 create_pixmap ()
940 {
941   static GtkWidget *window = NULL;
942   GtkWidget *box1;
943   GtkWidget *box2;
944   GtkWidget *box3;
945   GtkWidget *button;
946   GtkWidget *label;
947   GtkWidget *separator;
948   GtkWidget *pixmapwid;
949   GdkPixmap *pixmap;
950   GdkBitmap *mask;
951   GtkStyle *style;
952
953   if (!window)
954     {
955       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
956
957       gtk_signal_connect (GTK_OBJECT (window), "destroy",
958                           GTK_SIGNAL_FUNC(destroy_window),
959                           &window);
960       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
961                           GTK_SIGNAL_FUNC(destroy_window),
962                           &window);
963
964       gtk_window_set_title (GTK_WINDOW (window), "pixmap");
965       gtk_container_border_width (GTK_CONTAINER (window), 0);
966       gtk_widget_realize(window);
967
968       box1 = gtk_vbox_new (FALSE, 0);
969       gtk_container_add (GTK_CONTAINER (window), box1);
970       gtk_widget_show (box1);
971
972       box2 = gtk_vbox_new (FALSE, 10);
973       gtk_container_border_width (GTK_CONTAINER (box2), 10);
974       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
975       gtk_widget_show (box2);
976
977       button = gtk_button_new ();
978       gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0);
979       gtk_widget_show (button);
980
981       style=gtk_widget_get_style(button);
982
983       pixmap = gdk_pixmap_create_from_xpm (window->window, &mask, 
984                                            &style->bg[GTK_STATE_NORMAL],
985                                            "test.xpm");
986       pixmapwid = gtk_pixmap_new (pixmap, mask);
987
988       label = gtk_label_new ("Pixmap\ntest");
989       box3 = gtk_hbox_new (FALSE, 0);
990       gtk_container_border_width (GTK_CONTAINER (box3), 2);
991       gtk_container_add (GTK_CONTAINER (box3), pixmapwid);
992       gtk_container_add (GTK_CONTAINER (box3), label);
993       gtk_container_add (GTK_CONTAINER (button), box3);
994       gtk_widget_show (pixmapwid);
995       gtk_widget_show (label);
996       gtk_widget_show (box3);
997
998       separator = gtk_hseparator_new ();
999       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1000       gtk_widget_show (separator);
1001
1002
1003       box2 = gtk_vbox_new (FALSE, 10);
1004       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1005       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1006       gtk_widget_show (box2);
1007
1008
1009       button = gtk_button_new_with_label ("close");
1010       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1011                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1012                                  GTK_OBJECT (window));
1013       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1014       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1015       gtk_widget_grab_default (button);
1016       gtk_widget_show (button);
1017     }
1018
1019   if (!GTK_WIDGET_VISIBLE (window))
1020     gtk_widget_show (window);
1021   else
1022     gtk_widget_destroy (window);
1023 }
1024
1025 void
1026 create_tooltips ()
1027 {
1028   static GtkWidget *window = NULL;
1029   GtkWidget *box1;
1030   GtkWidget *box2;
1031   GtkWidget *button;
1032   GtkWidget *separator;
1033   GtkTooltips *tooltips;
1034
1035   if (!window)
1036     {
1037       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1038
1039       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1040                           GTK_SIGNAL_FUNC (destroy_tooltips),
1041                           &window);
1042       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1043                           GTK_SIGNAL_FUNC (gtk_true),
1044                           &window);
1045
1046       gtk_window_set_title (GTK_WINDOW (window), "tooltips");
1047       gtk_container_border_width (GTK_CONTAINER (window), 0);
1048
1049       tooltips=gtk_tooltips_new();
1050       gtk_object_set_data (GTK_OBJECT (window), "tooltips", tooltips);
1051       
1052       box1 = gtk_vbox_new (FALSE, 0);
1053       gtk_container_add (GTK_CONTAINER (window), box1);
1054       gtk_widget_show (box1);
1055
1056
1057       box2 = gtk_vbox_new (FALSE, 10);
1058       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1059       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1060       gtk_widget_show (box2);
1061
1062
1063       button = gtk_toggle_button_new_with_label ("button1");
1064       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1065       gtk_widget_show (button);
1066
1067       gtk_tooltips_set_tips(tooltips,button,"This is button 1");
1068
1069       button = gtk_toggle_button_new_with_label ("button2");
1070       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1071       gtk_widget_show (button);
1072
1073       gtk_tooltips_set_tips(tooltips,button,"This is button 2");
1074
1075       button = gtk_toggle_button_new_with_label ("button3");
1076       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1077       gtk_widget_show (button);
1078
1079       gtk_tooltips_set_tips (tooltips, button, "This is button 3. This is also a really long tooltip which probably won't fit on a single line and will therefore need to be wrapped. Hopefully the wrapping will work correctly.");
1080
1081       separator = gtk_hseparator_new ();
1082       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1083       gtk_widget_show (separator);
1084
1085
1086       box2 = gtk_vbox_new (FALSE, 10);
1087       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1088       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1089       gtk_widget_show (box2);
1090
1091
1092       button = gtk_button_new_with_label ("close");
1093       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1094                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1095                                  GTK_OBJECT (window));
1096       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1097       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1098       gtk_widget_grab_default (button);
1099       gtk_widget_show (button);
1100
1101       gtk_tooltips_set_tips (tooltips, button, "Push this button to close window");
1102     }
1103
1104   if (!GTK_WIDGET_VISIBLE (window))
1105     gtk_widget_show (window);
1106   else
1107     gtk_widget_destroy (window);
1108 }
1109
1110 GtkWidget*
1111 create_menu (int depth)
1112 {
1113   GtkWidget *menu;
1114   GtkWidget *submenu;
1115   GtkWidget *menuitem;
1116   GSList *group;
1117   char buf[32];
1118   int i, j;
1119
1120   if (depth < 1)
1121     return NULL;
1122
1123   menu = gtk_menu_new ();
1124   submenu = NULL;
1125   group = NULL;
1126
1127   for (i = 0, j = 1; i < 5; i++, j++)
1128     {
1129       sprintf (buf, "item %2d - %d", depth, j);
1130       menuitem = gtk_radio_menu_item_new_with_label (group, buf);
1131       group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
1132       if (depth % 2)
1133         gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
1134       gtk_menu_append (GTK_MENU (menu), menuitem);
1135       gtk_widget_show (menuitem);
1136
1137       if (depth > 0)
1138         {
1139           if (!submenu)
1140             submenu = create_menu (depth - 1);
1141           gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
1142         }
1143     }
1144
1145   return menu;
1146 }
1147
1148 void
1149 create_menus ()
1150 {
1151   static GtkWidget *window = NULL;
1152   GtkWidget *box1;
1153   GtkWidget *box2;
1154   GtkWidget *button;
1155   GtkWidget *menu;
1156   GtkWidget *menubar;
1157   GtkWidget *menuitem;
1158   GtkWidget *optionmenu;
1159   GtkWidget *separator;
1160
1161   if (!window)
1162     {
1163       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1164
1165       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1166                           GTK_SIGNAL_FUNC(destroy_window),
1167                           &window);
1168       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1169                           GTK_SIGNAL_FUNC(destroy_window),
1170                           &window);
1171
1172       gtk_window_set_title (GTK_WINDOW (window), "menus");
1173       gtk_container_border_width (GTK_CONTAINER (window), 0);
1174
1175
1176       box1 = gtk_vbox_new (FALSE, 0);
1177       gtk_container_add (GTK_CONTAINER (window), box1);
1178       gtk_widget_show (box1);
1179
1180
1181       menubar = gtk_menu_bar_new ();
1182       gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0);
1183       gtk_widget_show (menubar);
1184
1185       menu = create_menu (2);
1186
1187       menuitem = gtk_menu_item_new_with_label ("test\nline2");
1188       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
1189       gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
1190       gtk_widget_show (menuitem);
1191
1192       menuitem = gtk_menu_item_new_with_label ("foo");
1193       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
1194       gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
1195       gtk_widget_show (menuitem);
1196
1197       menuitem = gtk_menu_item_new_with_label ("bar");
1198       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
1199       gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem));
1200       gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
1201       gtk_widget_show (menuitem);
1202
1203
1204       box2 = gtk_vbox_new (FALSE, 10);
1205       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1206       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1207       gtk_widget_show (box2);
1208
1209
1210       optionmenu = gtk_option_menu_new ();
1211       gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), create_menu (1));
1212       gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 4);
1213       gtk_box_pack_start (GTK_BOX (box2), optionmenu, TRUE, TRUE, 0);
1214       gtk_widget_show (optionmenu);
1215
1216
1217       separator = gtk_hseparator_new ();
1218       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1219       gtk_widget_show (separator);
1220
1221
1222       box2 = gtk_vbox_new (FALSE, 10);
1223       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1224       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1225       gtk_widget_show (box2);
1226
1227
1228       button = gtk_button_new_with_label ("close");
1229       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1230                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1231                                  GTK_OBJECT (window));
1232       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1233       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1234       gtk_widget_grab_default (button);
1235       gtk_widget_show (button);
1236     }
1237
1238   if (!GTK_WIDGET_VISIBLE (window))
1239     gtk_widget_show (window);
1240   else
1241     gtk_widget_destroy (window);
1242 }
1243
1244 /*
1245  * GtkScrolledWindow
1246  */
1247 void
1248 create_scrolled_windows ()
1249 {
1250   static GtkWidget *window;
1251   GtkWidget *scrolled_window;
1252   GtkWidget *table;
1253   GtkWidget *button;
1254   char buffer[32];
1255   int i, j;
1256
1257   if (!window)
1258     {
1259       window = gtk_dialog_new ();
1260
1261       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1262                           GTK_SIGNAL_FUNC(destroy_window),
1263                           &window);
1264       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1265                           GTK_SIGNAL_FUNC(destroy_window),
1266                           &window);
1267
1268       gtk_window_set_title (GTK_WINDOW (window), "dialog");
1269       gtk_container_border_width (GTK_CONTAINER (window), 0);
1270
1271
1272       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1273       gtk_container_border_width (GTK_CONTAINER (scrolled_window), 10);
1274       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1275                                       GTK_POLICY_AUTOMATIC,
1276                                       GTK_POLICY_AUTOMATIC);
1277       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
1278                           scrolled_window, TRUE, TRUE, 0);
1279       gtk_widget_show (scrolled_window);
1280
1281       table = gtk_table_new (20, 20, FALSE);
1282       gtk_table_set_row_spacings (GTK_TABLE (table), 10);
1283       gtk_table_set_col_spacings (GTK_TABLE (table), 10);
1284       gtk_container_add (GTK_CONTAINER (scrolled_window), table);
1285       gtk_widget_show (table);
1286
1287       for (i = 0; i < 20; i++)
1288         for (j = 0; j < 20; j++)
1289           {
1290             sprintf (buffer, "button (%d,%d)\n", i, j);
1291             button = gtk_toggle_button_new_with_label (buffer);
1292             gtk_table_attach_defaults (GTK_TABLE (table), button,
1293                                        i, i+1, j, j+1);
1294             gtk_widget_show (button);
1295           }
1296
1297
1298       button = gtk_button_new_with_label ("close");
1299       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1300                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1301                                  GTK_OBJECT (window));
1302       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1303       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
1304                           button, TRUE, TRUE, 0);
1305       gtk_widget_grab_default (button);
1306       gtk_widget_show (button);
1307     }
1308
1309   if (!GTK_WIDGET_VISIBLE (window))
1310     gtk_widget_show (window);
1311   else
1312     gtk_widget_destroy (window);
1313 }
1314
1315 /*
1316  * GtkEntry
1317  */
1318
1319 void entry_toggle_editable (GtkWidget *checkbutton,
1320                             GtkWidget *entry)
1321 {
1322    gtk_entry_set_editable(GTK_ENTRY(entry),
1323                           GTK_TOGGLE_BUTTON(checkbutton)->active);
1324 }
1325
1326 void
1327 create_entry ()
1328 {
1329   static GtkWidget *window = NULL;
1330   GtkWidget *box1;
1331   GtkWidget *box2;
1332   GtkWidget *editable_check;
1333   GtkWidget *entry, *cb;
1334   GtkWidget *button;
1335   GtkWidget *separator;
1336   GList *cbitems = NULL;
1337
1338   if (!window)
1339     {
1340       cbitems = g_list_append(cbitems, "item1");
1341       cbitems = g_list_append(cbitems, "item2");
1342       cbitems = g_list_append(cbitems, "and item3");
1343       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1344
1345       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1346                           GTK_SIGNAL_FUNC(destroy_window),
1347                           &window);
1348       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1349                           GTK_SIGNAL_FUNC(destroy_window),
1350                           &window);
1351
1352       gtk_window_set_title (GTK_WINDOW (window), "entry");
1353       gtk_container_border_width (GTK_CONTAINER (window), 0);
1354
1355
1356       box1 = gtk_vbox_new (FALSE, 0);
1357       gtk_container_add (GTK_CONTAINER (window), box1);
1358       gtk_widget_show (box1);
1359
1360
1361       box2 = gtk_vbox_new (FALSE, 10);
1362       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1363       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1364       gtk_widget_show (box2);
1365
1366       entry = gtk_entry_new ();
1367       gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
1368       gtk_entry_select_region (GTK_ENTRY (entry), 
1369                                0, GTK_ENTRY(entry)->text_length);
1370       gtk_box_pack_start (GTK_BOX (box2), entry, TRUE, TRUE, 0);
1371       gtk_widget_show (entry);
1372
1373       cb = gtk_combo_new ();
1374       gtk_combo_set_popdown_strings (GTK_COMBO (cb), cbitems);
1375       gtk_entry_set_text (GTK_ENTRY (GTK_COMBO(cb)->entry), "hello world");
1376       gtk_entry_select_region (GTK_ENTRY (GTK_COMBO(cb)->entry),
1377                                0, GTK_ENTRY(entry)->text_length);
1378       gtk_box_pack_start (GTK_BOX (box2), cb, TRUE, TRUE, 0);
1379       gtk_widget_show (cb);
1380
1381       editable_check = gtk_check_button_new_with_label("Editable");
1382       gtk_box_pack_start (GTK_BOX (box2), editable_check, TRUE, TRUE, 0);
1383       gtk_signal_connect (GTK_OBJECT(editable_check), "toggled",
1384                           GTK_SIGNAL_FUNC(entry_toggle_editable), entry);
1385       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(editable_check), TRUE);
1386       gtk_widget_show (editable_check);
1387
1388       separator = gtk_hseparator_new ();
1389       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1390       gtk_widget_show (separator);
1391
1392
1393       box2 = gtk_vbox_new (FALSE, 10);
1394       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1395       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1396       gtk_widget_show (box2);
1397
1398
1399       button = gtk_button_new_with_label ("close");
1400       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1401                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1402                                  GTK_OBJECT (window));
1403       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1404       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1405       gtk_widget_grab_default (button);
1406       gtk_widget_show (button);
1407     }
1408
1409   if (!GTK_WIDGET_VISIBLE (window))
1410     gtk_widget_show (window);
1411   /*  else
1412     gtk_widget_destroy (window); */
1413 }
1414
1415 /*
1416  * GtkList
1417  */
1418 void
1419 list_add (GtkWidget *widget,
1420           GtkWidget *list)
1421 {
1422   static int i = 1;
1423   gchar buffer[64];
1424   GtkWidget *list_item;
1425
1426   sprintf (buffer, "added item %d", i++);
1427   list_item = gtk_list_item_new_with_label (buffer);
1428   gtk_widget_show (list_item);
1429   gtk_container_add (GTK_CONTAINER (list), list_item);
1430 }
1431
1432 void
1433 list_remove (GtkWidget *widget,
1434              GtkWidget *list)
1435 {
1436   GList *tmp_list;
1437   GList *clear_list;
1438
1439   tmp_list = GTK_LIST (list)->selection;
1440   clear_list = NULL;
1441
1442   while (tmp_list)
1443     {
1444       clear_list = g_list_prepend (clear_list, tmp_list->data);
1445       tmp_list = tmp_list->next;
1446     }
1447
1448   clear_list = g_list_reverse (clear_list);
1449
1450   gtk_list_remove_items (GTK_LIST (list), clear_list);
1451
1452   g_list_free (clear_list);
1453 }
1454
1455 void
1456 create_list ()
1457 {
1458   static GtkWidget *window = NULL;
1459   static char *list_items[] =
1460   {
1461     "hello",
1462     "world",
1463     "blah",
1464     "foo",
1465     "bar",
1466     "argh",
1467     "spencer",
1468     "is a",
1469     "wussy",
1470     "programmer",
1471   };
1472   static int nlist_items = sizeof (list_items) / sizeof (list_items[0]);
1473
1474   GtkWidget *box1;
1475   GtkWidget *box2;
1476   GtkWidget *scrolled_win;
1477   GtkWidget *list;
1478   GtkWidget *list_item;
1479   GtkWidget *button;
1480   GtkWidget *separator;
1481   int i;
1482
1483   if (!window)
1484     {
1485       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1486
1487       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1488                           GTK_SIGNAL_FUNC(destroy_window),
1489                           &window);
1490       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1491                           GTK_SIGNAL_FUNC(destroy_window),
1492                           &window);
1493
1494       gtk_window_set_title (GTK_WINDOW (window), "list");
1495       gtk_container_border_width (GTK_CONTAINER (window), 0);
1496
1497
1498       box1 = gtk_vbox_new (FALSE, 0);
1499       gtk_container_add (GTK_CONTAINER (window), box1);
1500       gtk_widget_show (box1);
1501
1502
1503       box2 = gtk_vbox_new (FALSE, 10);
1504       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1505       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1506       gtk_widget_show (box2);
1507
1508
1509       scrolled_win = gtk_scrolled_window_new (NULL, NULL);
1510       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
1511                                       GTK_POLICY_AUTOMATIC, 
1512                                       GTK_POLICY_AUTOMATIC);
1513       gtk_box_pack_start (GTK_BOX (box2), scrolled_win, TRUE, TRUE, 0);
1514       gtk_widget_show (scrolled_win);
1515
1516       list = gtk_list_new ();
1517       gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_MULTIPLE);
1518       gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_BROWSE);
1519       gtk_container_add (GTK_CONTAINER (scrolled_win), list);
1520       gtk_widget_show (list);
1521
1522       for (i = 0; i < nlist_items; i++)
1523         {
1524           list_item = gtk_list_item_new_with_label (list_items[i]);
1525           gtk_container_add (GTK_CONTAINER (list), list_item);
1526           gtk_widget_show (list_item);
1527         }
1528
1529       button = gtk_button_new_with_label ("add");
1530       GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_FOCUS);
1531       gtk_signal_connect (GTK_OBJECT (button), "clicked",
1532                           GTK_SIGNAL_FUNC(list_add),
1533                           list);
1534       gtk_box_pack_start (GTK_BOX (box2), button, FALSE, TRUE, 0);
1535       gtk_widget_show (button);
1536
1537       button = gtk_button_new_with_label ("remove");
1538       GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_FOCUS);
1539       gtk_signal_connect (GTK_OBJECT (button), "clicked",
1540                           GTK_SIGNAL_FUNC(list_remove),
1541                           list);
1542       gtk_box_pack_start (GTK_BOX (box2), button, FALSE, TRUE, 0);
1543       gtk_widget_show (button);
1544
1545
1546       separator = gtk_hseparator_new ();
1547       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1548       gtk_widget_show (separator);
1549
1550
1551       box2 = gtk_vbox_new (FALSE, 10);
1552       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1553       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1554       gtk_widget_show (box2);
1555
1556
1557       button = gtk_button_new_with_label ("close");
1558       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1559                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1560                                  GTK_OBJECT (window));
1561       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1562       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1563       gtk_widget_grab_default (button);
1564       gtk_widget_show (button);
1565     }
1566
1567   if (!GTK_WIDGET_VISIBLE (window))
1568     gtk_widget_show (window);
1569   else
1570     gtk_widget_destroy (window);
1571 }
1572
1573 /*
1574  * GtkCList
1575  */
1576 #define TESTGTK_CLIST_COLUMNS 7
1577 static gint clist_rows = 0;
1578 static gint clist_selected_row = 0;
1579
1580 void
1581 add1000_clist (GtkWidget *widget, gpointer data)
1582 {
1583   gint i;
1584   char text[TESTGTK_CLIST_COLUMNS][50];
1585   char *texts[TESTGTK_CLIST_COLUMNS];
1586
1587   for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
1588     {
1589       texts[i] = text[i];
1590       sprintf (text[i], "Column %d", i);
1591     }
1592   
1593   sprintf (text[1], "Right");
1594   sprintf (text[2], "Center");
1595   
1596   gtk_clist_freeze (GTK_CLIST (data));
1597   for (i = 0; i < 1000; i++)
1598     {
1599       sprintf (text[0], "Row %d", clist_rows++);
1600       gtk_clist_append (GTK_CLIST (data), texts);
1601     }
1602   gtk_clist_thaw (GTK_CLIST (data));
1603
1604 }
1605
1606 void
1607 add10000_clist (GtkWidget *widget, gpointer data)
1608 {
1609   gint i;
1610   char text[TESTGTK_CLIST_COLUMNS][50];
1611   char *texts[TESTGTK_CLIST_COLUMNS];
1612
1613   for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
1614     {
1615       texts[i] = text[i];
1616       sprintf (text[i], "Column %d", i);
1617     }
1618   
1619   sprintf (text[1], "Right");
1620   sprintf (text[2], "Center");
1621   
1622   gtk_clist_freeze (GTK_CLIST (data));
1623   for (i = 0; i < 10000; i++)
1624     {
1625       sprintf (text[0], "Row %d", clist_rows++);
1626       gtk_clist_append (GTK_CLIST (data), texts);
1627     }
1628   gtk_clist_thaw (GTK_CLIST (data));
1629
1630 }
1631
1632 void
1633 clear_clist (GtkWidget *widget, gpointer data)
1634 {
1635   gtk_clist_clear (GTK_CLIST (data));
1636   clist_rows = 0;
1637 }
1638
1639 void
1640 remove_row_clist (GtkWidget *widget, gpointer data)
1641 {
1642   gtk_clist_remove (GTK_CLIST (data), clist_selected_row);
1643   clist_rows--;
1644 }
1645
1646 void
1647 show_titles_clist (GtkWidget *widget, gpointer data)
1648 {
1649   gtk_clist_column_titles_show (GTK_CLIST (data));
1650 }
1651
1652 void
1653 hide_titles_clist (GtkWidget *widget, gpointer data)
1654 {
1655   gtk_clist_column_titles_hide (GTK_CLIST (data));
1656 }
1657
1658 void
1659 select_clist (GtkWidget *widget,
1660               gint row, 
1661               gint column, 
1662               GdkEventButton *bevent)
1663 {
1664   gint button = 0;
1665
1666   if (bevent)
1667     button = bevent->button;
1668
1669   g_print ("GtkCList Selection: row %d column %d button %d\n", 
1670            row, column, button);
1671
1672   clist_selected_row = row;
1673 }
1674
1675 void
1676 list_selection_clist (GtkWidget *widget, gpointer data)
1677 {
1678   GList *list;
1679   GtkCListRow *clist_row;
1680   GtkCList *clist;
1681
1682 }
1683
1684 void
1685 create_clist ()
1686 {
1687   gint i;
1688   static GtkWidget *window = NULL;
1689
1690   static char *titles[] =
1691   {
1692     "Title 0",
1693     "Title 1",
1694     "Title 2",
1695     "Title 3",
1696     "Title 4",
1697     "Title 5",
1698     "Title 6"
1699   };
1700
1701   char text[TESTGTK_CLIST_COLUMNS][50];
1702   char *texts[TESTGTK_CLIST_COLUMNS];
1703
1704   GtkWidget *box1;
1705   GtkWidget *box2;
1706   GtkWidget *clist;
1707   GtkWidget *button;
1708   GtkWidget *separator;
1709
1710
1711   if (!window)
1712     {
1713       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1714
1715       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1716                           GTK_SIGNAL_FUNC(destroy_window),
1717                           &window);
1718       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1719                           GTK_SIGNAL_FUNC(destroy_window),
1720                           &window);
1721
1722       gtk_window_set_title (GTK_WINDOW (window), "clist");
1723       gtk_container_border_width (GTK_CONTAINER (window), 0);
1724
1725
1726       box1 = gtk_vbox_new (FALSE, 0);
1727       gtk_container_add (GTK_CONTAINER (window), box1);
1728       gtk_widget_show (box1);
1729
1730
1731       box2 = gtk_hbox_new (FALSE, 10);
1732       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1733       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
1734       gtk_widget_show (box2);
1735
1736       /* create GtkCList here so we have a pointer to throw at the 
1737        * button callbacks -- more is done with it later */
1738       clist = gtk_clist_new_with_titles (TESTGTK_CLIST_COLUMNS, titles);
1739
1740       /* control buttons */
1741       button = gtk_button_new_with_label ("Add 1,000 Rows");
1742       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1743
1744       gtk_signal_connect (GTK_OBJECT (button),
1745                           "clicked",
1746                           (GtkSignalFunc) add1000_clist,
1747                           (gpointer) clist);
1748
1749       gtk_widget_show (button);
1750
1751
1752       button = gtk_button_new_with_label ("Add 10,000 Rows");
1753       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1754
1755       gtk_signal_connect (GTK_OBJECT (button),
1756                           "clicked",
1757                           (GtkSignalFunc) add10000_clist,
1758                           (gpointer) clist);
1759
1760       gtk_widget_show (button);
1761
1762       button = gtk_button_new_with_label ("Clear List");
1763       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1764
1765       gtk_signal_connect (GTK_OBJECT (button),
1766                           "clicked",
1767                           (GtkSignalFunc) clear_clist,
1768                           (gpointer) clist);
1769
1770       gtk_widget_show (button);
1771
1772       button = gtk_button_new_with_label ("Remove Row");
1773       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1774
1775       gtk_signal_connect (GTK_OBJECT (button),
1776                           "clicked",
1777                           (GtkSignalFunc) remove_row_clist,
1778                           (gpointer) clist);
1779
1780       gtk_widget_show (button);
1781
1782       /* second layer of buttons */
1783       box2 = gtk_hbox_new (FALSE, 10);
1784       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1785       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
1786       gtk_widget_show (box2);
1787
1788       button = gtk_button_new_with_label ("Show Title Buttons");
1789       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1790
1791       gtk_signal_connect (GTK_OBJECT (button),
1792                           "clicked",
1793                           (GtkSignalFunc) show_titles_clist,
1794                           (gpointer) clist);
1795
1796       gtk_widget_show (button);
1797
1798       button = gtk_button_new_with_label ("Hide Title Buttons");
1799       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1800
1801       gtk_signal_connect (GTK_OBJECT (button),
1802                           "clicked",
1803                           (GtkSignalFunc) hide_titles_clist,
1804                           (gpointer) clist);
1805
1806       gtk_widget_show (button);
1807
1808       /* vbox for the list itself */
1809       box2 = gtk_vbox_new (FALSE, 10);
1810       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1811       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1812       gtk_widget_show (box2);
1813
1814       /* 
1815        * the rest of the clist configuration
1816        */
1817       gtk_clist_set_row_height (GTK_CLIST (clist), 20);
1818       
1819       gtk_signal_connect (GTK_OBJECT (clist), 
1820                           "select_row",
1821                           (GtkSignalFunc) select_clist, 
1822                           NULL);
1823
1824       gtk_clist_set_column_width (GTK_CLIST (clist), 0, 100);
1825
1826       for (i = 1; i < TESTGTK_CLIST_COLUMNS; i++)
1827         gtk_clist_set_column_width (GTK_CLIST (clist), i, 80);
1828
1829       gtk_clist_set_selection_mode (GTK_CLIST (clist), GTK_SELECTION_BROWSE);
1830
1831       gtk_clist_set_policy (GTK_CLIST (clist), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1832
1833       gtk_clist_set_column_justification (GTK_CLIST (clist), 1, GTK_JUSTIFY_RIGHT);
1834       gtk_clist_set_column_justification (GTK_CLIST (clist), 2, GTK_JUSTIFY_CENTER);
1835       
1836       for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
1837         {
1838           texts[i] = text[i];
1839           sprintf (text[i], "Column %d", i);
1840         }
1841
1842       sprintf (text[1], "Right");
1843       sprintf (text[2], "Center");
1844
1845       for (i = 0; i < 100; i++)
1846         {
1847           sprintf (text[0], "Row %d", clist_rows++);
1848           gtk_clist_append (GTK_CLIST (clist), texts);
1849         }
1850
1851       gtk_container_border_width (GTK_CONTAINER (clist), 5);
1852       gtk_box_pack_start (GTK_BOX (box2), clist, TRUE, TRUE, 0);
1853       gtk_widget_show (clist);
1854
1855
1856       separator = gtk_hseparator_new ();
1857       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1858       gtk_widget_show (separator);
1859
1860       box2 = gtk_vbox_new (FALSE, 10);
1861       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1862       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1863       gtk_widget_show (box2);
1864
1865       button = gtk_button_new_with_label ("close");
1866       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1867                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1868                                  GTK_OBJECT (window));
1869
1870       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1871       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1872       gtk_widget_grab_default (button);
1873
1874       gtk_widget_show (button);
1875     }
1876
1877   if (!GTK_WIDGET_VISIBLE (window))
1878     gtk_widget_show (window);
1879   else
1880     gtk_widget_destroy (window);
1881
1882 }
1883
1884 /*
1885  * GtkColorSelect
1886  */
1887 void
1888 color_selection_ok (GtkWidget               *w,
1889                     GtkColorSelectionDialog *cs)
1890 {
1891   GtkColorSelection *colorsel;
1892   gdouble color[4];
1893
1894   colorsel=GTK_COLOR_SELECTION(cs->colorsel);
1895
1896   gtk_color_selection_get_color(colorsel,color);
1897   gtk_color_selection_set_color(colorsel,color);
1898 }
1899
1900 void
1901 color_selection_changed (GtkWidget *w,
1902                          GtkColorSelectionDialog *cs)
1903 {
1904   GtkColorSelection *colorsel;
1905   gdouble color[4];
1906
1907   colorsel=GTK_COLOR_SELECTION(cs->colorsel);
1908   gtk_color_selection_get_color(colorsel,color);
1909 }
1910
1911 void
1912 create_color_selection ()
1913 {
1914   static GtkWidget *window = NULL;
1915
1916   if (!window)
1917     {
1918       gtk_preview_set_install_cmap (TRUE);
1919       gtk_widget_push_visual (gtk_preview_get_visual ());
1920       gtk_widget_push_colormap (gtk_preview_get_cmap ());
1921
1922       window = gtk_color_selection_dialog_new ("color selection dialog");
1923
1924       gtk_color_selection_set_opacity (
1925         GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (window)->colorsel),
1926         TRUE);
1927
1928       gtk_color_selection_set_update_policy(
1929         GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (window)->colorsel),
1930         GTK_UPDATE_CONTINUOUS);
1931
1932       gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
1933
1934       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1935                           GTK_SIGNAL_FUNC(destroy_window),
1936                           &window);
1937       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1938                           GTK_SIGNAL_FUNC(destroy_window),
1939                           &window);
1940
1941       gtk_signal_connect (
1942         GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->colorsel),
1943         "color_changed",
1944         GTK_SIGNAL_FUNC(color_selection_changed),
1945         window);
1946
1947       gtk_signal_connect (
1948         GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->ok_button),
1949         "clicked",
1950         GTK_SIGNAL_FUNC(color_selection_ok),
1951         window);
1952
1953       gtk_signal_connect_object (
1954         GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->cancel_button),
1955         "clicked",
1956         GTK_SIGNAL_FUNC(gtk_widget_destroy),
1957         GTK_OBJECT (window));
1958
1959       gtk_widget_pop_colormap ();
1960       gtk_widget_pop_visual ();
1961     }
1962
1963   if (!GTK_WIDGET_VISIBLE (window))
1964     gtk_widget_show (window);
1965   else
1966     gtk_widget_destroy (window);
1967 }
1968
1969
1970 void
1971 file_selection_ok (GtkWidget        *w,
1972                    GtkFileSelection *fs)
1973 {
1974   g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
1975 }
1976
1977 void
1978 create_file_selection ()
1979 {
1980   static GtkWidget *window = NULL;
1981
1982   if (!window)
1983     {
1984       window = gtk_file_selection_new ("file selection dialog");
1985       gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
1986
1987       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1988                           GTK_SIGNAL_FUNC(destroy_window),
1989                           &window);
1990       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1991                           GTK_SIGNAL_FUNC(destroy_window),
1992                           &window);
1993
1994       gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (window)->ok_button),
1995                           "clicked", GTK_SIGNAL_FUNC(file_selection_ok),
1996                           window);
1997       gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (window)->cancel_button),
1998                                  "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
1999                                  GTK_OBJECT (window));
2000     }
2001
2002   if (!GTK_WIDGET_VISIBLE (window))
2003     gtk_widget_show (window);
2004   else
2005     gtk_widget_destroy (window);
2006 }
2007
2008
2009 /*
2010  * GtkDialog
2011  */
2012 static GtkWidget *dialog_window = NULL;
2013
2014 void
2015 label_toggle (GtkWidget  *widget,
2016               GtkWidget **label)
2017 {
2018   if (!(*label))
2019     {
2020       *label = gtk_label_new ("Dialog Test");
2021       gtk_signal_connect (GTK_OBJECT (*label),
2022                           "destroy",
2023                           GTK_SIGNAL_FUNC (gtk_widget_destroyed),
2024                           label);
2025       gtk_misc_set_padding (GTK_MISC (*label), 10, 10);
2026       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox), 
2027                           *label, TRUE, TRUE, 0);
2028       gtk_widget_show (*label);
2029     }
2030   else
2031     gtk_widget_destroy (*label);
2032 }
2033
2034 void
2035 create_dialog ()
2036 {
2037   static GtkWidget *label;
2038   GtkWidget *button;
2039
2040   if (!dialog_window)
2041     {
2042       dialog_window = gtk_dialog_new ();
2043
2044       gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy",
2045                           GTK_SIGNAL_FUNC(destroy_window),
2046                           &dialog_window);
2047       gtk_signal_connect (GTK_OBJECT (dialog_window), "delete_event",
2048                           GTK_SIGNAL_FUNC(destroy_window),
2049                           &dialog_window);
2050
2051       gtk_window_set_title (GTK_WINDOW (dialog_window), "dialog");
2052       gtk_container_border_width (GTK_CONTAINER (dialog_window), 0);
2053
2054       button = gtk_button_new_with_label ("OK");
2055       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2056       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area), 
2057                           button, TRUE, TRUE, 0);
2058       gtk_widget_grab_default (button);
2059       gtk_widget_show (button);
2060
2061       button = gtk_button_new_with_label ("Toggle");
2062       gtk_signal_connect (GTK_OBJECT (button), "clicked",
2063                           GTK_SIGNAL_FUNC (label_toggle),
2064                           &label);
2065       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2066       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area),
2067                           button, TRUE, TRUE, 0);
2068       gtk_widget_show (button);
2069
2070       label = NULL;
2071     }
2072
2073   if (!GTK_WIDGET_VISIBLE (dialog_window))
2074     gtk_widget_show (dialog_window);
2075   else
2076     gtk_widget_destroy (dialog_window);
2077 }
2078
2079
2080 /*
2081  * GtkRange
2082  */
2083 void
2084 create_range_controls ()
2085 {
2086   static GtkWidget *window = NULL;
2087   GtkWidget *box1;
2088   GtkWidget *box2;
2089   GtkWidget *button;
2090   GtkWidget *scrollbar;
2091   GtkWidget *scale;
2092   GtkWidget *separator;
2093   GtkObject *adjustment;
2094
2095   if (!window)
2096     {
2097       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2098
2099       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2100                           GTK_SIGNAL_FUNC(destroy_window),
2101                           &window);
2102       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2103                           GTK_SIGNAL_FUNC(destroy_window),
2104                           &window);
2105
2106       gtk_window_set_title (GTK_WINDOW (window), "range controls");
2107       gtk_container_border_width (GTK_CONTAINER (window), 0);
2108
2109
2110       box1 = gtk_vbox_new (FALSE, 0);
2111       gtk_container_add (GTK_CONTAINER (window), box1);
2112       gtk_widget_show (box1);
2113
2114
2115       box2 = gtk_vbox_new (FALSE, 10);
2116       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2117       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2118       gtk_widget_show (box2);
2119
2120
2121       adjustment = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
2122
2123       scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
2124       gtk_widget_set_usize (GTK_WIDGET (scale), 150, 30);
2125       gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
2126       gtk_scale_set_digits (GTK_SCALE (scale), 1);
2127       gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
2128       gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
2129       gtk_widget_show (scale);
2130
2131       scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (adjustment));
2132       gtk_range_set_update_policy (GTK_RANGE (scrollbar), 
2133                                    GTK_UPDATE_CONTINUOUS);
2134       gtk_box_pack_start (GTK_BOX (box2), scrollbar, TRUE, TRUE, 0);
2135       gtk_widget_show (scrollbar);
2136
2137
2138       separator = gtk_hseparator_new ();
2139       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2140       gtk_widget_show (separator);
2141
2142
2143       box2 = gtk_vbox_new (FALSE, 10);
2144       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2145       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2146       gtk_widget_show (box2);
2147
2148
2149       button = gtk_button_new_with_label ("close");
2150       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2151                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2152                                  GTK_OBJECT (window));
2153       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2154       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2155       gtk_widget_grab_default (button);
2156       gtk_widget_show (button);
2157     }
2158
2159   if (!GTK_WIDGET_VISIBLE (window))
2160     gtk_widget_show (window);
2161   else
2162     gtk_widget_destroy (window);
2163 }
2164
2165
2166 /*
2167  * GtkRulers
2168  */
2169 void
2170 create_rulers ()
2171 {
2172   static GtkWidget *window = NULL;
2173   GtkWidget *table;
2174   GtkWidget *ruler;
2175
2176   if (!window)
2177     {
2178       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2179
2180       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2181                           GTK_SIGNAL_FUNC(destroy_window),
2182                           &window);
2183       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2184                           GTK_SIGNAL_FUNC(destroy_window),
2185                           &window);
2186
2187       gtk_window_set_title (GTK_WINDOW (window), "rulers");
2188       gtk_widget_set_usize (window, 300, 300);
2189       gtk_widget_set_events (window, 
2190                              GDK_POINTER_MOTION_MASK 
2191                              | GDK_POINTER_MOTION_HINT_MASK);
2192       gtk_container_border_width (GTK_CONTAINER (window), 0);
2193
2194       table = gtk_table_new (2, 2, FALSE);
2195       gtk_container_add (GTK_CONTAINER (window), table);
2196       gtk_widget_show (table);
2197
2198       ruler = gtk_hruler_new ();
2199       gtk_ruler_set_range (GTK_RULER (ruler), 5, 15, 0, 20);
2200
2201       gtk_signal_connect_object (
2202         GTK_OBJECT (window), 
2203         "motion_notify_event",
2204         GTK_SIGNAL_FUNC(
2205           GTK_WIDGET_CLASS (GTK_OBJECT (ruler)->klass)->motion_notify_event),
2206         GTK_OBJECT (ruler));
2207
2208       gtk_table_attach (GTK_TABLE (table), ruler, 1, 2, 0, 1,
2209                         GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
2210       gtk_widget_show (ruler);
2211
2212
2213       ruler = gtk_vruler_new ();
2214       gtk_ruler_set_range (GTK_RULER (ruler), 5, 15, 0, 20);
2215
2216       gtk_signal_connect_object (
2217         GTK_OBJECT (window), 
2218         "motion_notify_event",
2219         GTK_SIGNAL_FUNC (GTK_WIDGET_CLASS (GTK_OBJECT (ruler)->klass)->motion_notify_event),
2220         GTK_OBJECT (ruler));
2221
2222       gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 2,
2223                         GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2224       gtk_widget_show (ruler);
2225     }
2226
2227   if (!GTK_WIDGET_VISIBLE (window))
2228     gtk_widget_show (window);
2229   else
2230     gtk_widget_destroy (window);
2231 }
2232
2233
2234 /*
2235  * GtkText
2236  */
2237 void
2238 create_text ()
2239 {
2240   static GtkWidget *window = NULL;
2241   GtkWidget *box1;
2242   GtkWidget *box2;
2243   GtkWidget *button;
2244   GtkWidget *separator;
2245   GtkWidget *table;
2246   GtkWidget *hscrollbar;
2247   GtkWidget *vscrollbar;
2248   GtkWidget *text;
2249
2250   if (!window)
2251     {
2252       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2253       gtk_widget_set_name (window, "text window");
2254
2255       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2256                           GTK_SIGNAL_FUNC(destroy_window),
2257                           &window);
2258       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2259                           GTK_SIGNAL_FUNC(destroy_window),
2260                           &window);
2261
2262       gtk_window_set_title (GTK_WINDOW (window), "test");
2263       gtk_container_border_width (GTK_CONTAINER (window), 0);
2264
2265
2266       box1 = gtk_vbox_new (FALSE, 0);
2267       gtk_container_add (GTK_CONTAINER (window), box1);
2268       gtk_widget_show (box1);
2269
2270
2271       box2 = gtk_vbox_new (FALSE, 10);
2272       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2273       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2274       gtk_widget_show (box2);
2275
2276
2277       table = gtk_table_new (2, 2, FALSE);
2278       gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
2279       gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
2280       gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
2281       gtk_widget_show (table);
2282
2283       text = gtk_text_new (NULL, NULL);
2284       gtk_text_set_editable (GTK_TEXT (text), TRUE);
2285       gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
2286       gtk_widget_show (text);
2287
2288       hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
2289       gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
2290                         GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
2291       gtk_widget_show (hscrollbar);
2292
2293       vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
2294       gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
2295                         GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2296       gtk_widget_show (vscrollbar);
2297
2298       gtk_text_freeze (GTK_TEXT (text));
2299
2300       gtk_widget_realize (text);
2301
2302       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2303                        "spencer blah blah blah\n", -1);
2304       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2305                        "kimball\n", -1);
2306       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2307                        "is\n", -1);
2308       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2309                        "a\n", -1);
2310       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2311                        "wuss.\n", -1);
2312       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2313                        "but\n", -1);
2314       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
2315                        "josephine\n", -1);
2316       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2317                        "(his\n", -1);
2318       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2319                        "girlfriend\n", -1);
2320       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2321                        "is\n", -1);
2322       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2323                        "not).\n", -1);
2324       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2325                        "why?\n", -1);
2326       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2327                        "because\n", -1);
2328       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2329                        "spencer\n", -1);
2330       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2331                        "puked\n", -1);
2332       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2333                        "last\n", -1);
2334       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2335                        "night\n", -1);
2336       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2337                        "but\n", -1);
2338       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2339                        "josephine\n", -1);
2340       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2341                        "did\n", -1);
2342       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2343                        "not", -1);
2344
2345       gtk_text_thaw (GTK_TEXT (text));
2346
2347       separator = gtk_hseparator_new ();
2348       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2349       gtk_widget_show (separator);
2350
2351
2352       box2 = gtk_vbox_new (FALSE, 10);
2353       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2354       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2355       gtk_widget_show (box2);
2356
2357
2358       button = gtk_button_new_with_label ("close");
2359       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2360                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2361                                  GTK_OBJECT (window));
2362       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2363       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2364       gtk_widget_grab_default (button);
2365       gtk_widget_show (button);
2366     }
2367
2368   if (!GTK_WIDGET_VISIBLE (window))
2369     gtk_widget_show (window);
2370   else
2371     gtk_widget_destroy (window);
2372 }
2373
2374
2375 /*
2376  * GtkNotebook
2377  */
2378 void
2379 rotate_notebook (GtkButton   *button,
2380                  GtkNotebook *notebook)
2381 {
2382   gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos + 1) % 4);
2383 }
2384
2385 void
2386 create_notebook ()
2387 {
2388   static GtkWidget *window = NULL;
2389   GtkWidget *box1;
2390   GtkWidget *box2;
2391   GtkWidget *button;
2392   GtkWidget *separator;
2393   GtkWidget *notebook;
2394   GtkWidget *frame;
2395   GtkWidget *label;
2396   char buffer[32];
2397   int i;
2398
2399   if (!window)
2400     {
2401       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2402
2403       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2404                           GTK_SIGNAL_FUNC(destroy_window),
2405                           &window);
2406       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2407                           GTK_SIGNAL_FUNC(destroy_window),
2408                           &window);
2409
2410       gtk_window_set_title (GTK_WINDOW (window), "notebook");
2411       gtk_container_border_width (GTK_CONTAINER (window), 0);
2412
2413
2414       box1 = gtk_vbox_new (FALSE, 0);
2415       gtk_container_add (GTK_CONTAINER (window), box1);
2416       gtk_widget_show (box1);
2417
2418
2419       box2 = gtk_vbox_new (FALSE, 10);
2420       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2421       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2422       gtk_widget_show (box2);
2423
2424
2425       notebook = gtk_notebook_new ();
2426       gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
2427       gtk_box_pack_start (GTK_BOX (box2), notebook, TRUE, TRUE, 0);
2428       gtk_widget_show (notebook);
2429
2430
2431       for (i = 0; i < 5; i++)
2432         {
2433           sprintf (buffer, "Page %d", i+1);
2434
2435           frame = gtk_frame_new (buffer);
2436           gtk_container_border_width (GTK_CONTAINER (frame), 10);
2437           gtk_widget_set_usize (frame, 200, 150);
2438           gtk_widget_show (frame);
2439
2440           label = gtk_label_new (buffer);
2441           gtk_container_add (GTK_CONTAINER (frame), label);
2442           gtk_widget_show (label);
2443
2444           label = gtk_label_new (buffer);
2445           gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
2446         }
2447
2448
2449       separator = gtk_hseparator_new ();
2450       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2451       gtk_widget_show (separator);
2452
2453
2454       box2 = gtk_hbox_new (FALSE, 10);
2455       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2456       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2457       gtk_widget_show (box2);
2458
2459
2460       button = gtk_button_new_with_label ("close");
2461       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2462                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2463                                  GTK_OBJECT (window));
2464       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2465       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2466       gtk_widget_grab_default (button);
2467       gtk_widget_show (button);
2468
2469       button = gtk_button_new_with_label ("next");
2470       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2471                                  GTK_SIGNAL_FUNC(gtk_notebook_next_page),
2472                                  GTK_OBJECT (notebook));
2473       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2474       gtk_widget_show (button);
2475
2476       button = gtk_button_new_with_label ("prev");
2477       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2478                                  GTK_SIGNAL_FUNC(gtk_notebook_prev_page),
2479                                  GTK_OBJECT (notebook));
2480       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2481       gtk_widget_show (button);
2482
2483       button = gtk_button_new_with_label ("rotate");
2484       gtk_signal_connect (GTK_OBJECT (button), "clicked",
2485                           GTK_SIGNAL_FUNC(rotate_notebook),
2486                           notebook);
2487       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2488       gtk_widget_show (button);
2489     }
2490
2491   if (!GTK_WIDGET_VISIBLE (window))
2492     gtk_widget_show (window);
2493   else
2494     gtk_widget_destroy (window);
2495 }
2496
2497
2498 /*
2499  * GtkPanes
2500  */
2501 void
2502 create_panes ()
2503 {
2504   static GtkWidget *window = NULL;
2505   GtkWidget *frame;
2506   GtkWidget *hpaned;
2507   GtkWidget *vpaned;
2508
2509   if (!window)
2510     {
2511       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2512
2513       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2514                           GTK_SIGNAL_FUNC(destroy_window),
2515                           &window);
2516       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2517                           GTK_SIGNAL_FUNC(destroy_window),
2518                           &window);
2519
2520       gtk_window_set_title (GTK_WINDOW (window), "Panes");
2521       gtk_container_border_width (GTK_CONTAINER (window), 0);
2522
2523       vpaned = gtk_vpaned_new ();
2524       gtk_container_add (GTK_CONTAINER (window), vpaned);
2525       gtk_container_border_width (GTK_CONTAINER(vpaned), 5);
2526       gtk_widget_show (vpaned);
2527
2528       hpaned = gtk_hpaned_new ();
2529       gtk_paned_add1 (GTK_PANED (vpaned), hpaned);
2530
2531       frame = gtk_frame_new (NULL);
2532       gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
2533       gtk_widget_set_usize (frame, 60, 60);
2534       gtk_paned_add1 (GTK_PANED (hpaned), frame);
2535       gtk_widget_show (frame);
2536
2537       frame = gtk_frame_new (NULL);
2538       gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
2539       gtk_widget_set_usize (frame, 80, 60);
2540       gtk_paned_add2 (GTK_PANED (hpaned), frame);
2541       gtk_widget_show (frame);
2542
2543       gtk_widget_show (hpaned);
2544
2545       frame = gtk_frame_new (NULL);
2546       gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
2547       gtk_widget_set_usize (frame, 60, 80);
2548       gtk_paned_add2 (GTK_PANED (vpaned), frame);
2549       gtk_widget_show (frame);
2550     }
2551
2552   if (!GTK_WIDGET_VISIBLE (window))
2553     gtk_widget_show (window);
2554   else
2555     gtk_widget_destroy (window);
2556 }
2557
2558
2559 /*
2560  * Drag -N- Drop
2561  */
2562
2563 gboolean
2564 dnd_drop_destroy_popup (GtkWidget *widget, GtkWindow **window)
2565 {
2566   if(GTK_IS_BUTTON(widget)) /* I.e. they clicked the close button */
2567     gtk_widget_destroy(GTK_WIDGET(*window));
2568   else {
2569     gtk_grab_remove(GTK_WIDGET(*window));
2570     *window = NULL;
2571   }
2572   return TRUE;
2573 }
2574
2575 void
2576 dnd_drop (GtkWidget *button, GdkEvent *event)
2577 {
2578   static GtkWidget *window = NULL;
2579   GtkWidget *vbox, *lbl, *btn;
2580   gchar *msg;
2581
2582   window = gtk_window_new(GTK_WINDOW_DIALOG);
2583   gtk_container_border_width (GTK_CONTAINER(window), 10);
2584
2585   gtk_signal_connect (GTK_OBJECT (window), "destroy",
2586                       GTK_SIGNAL_FUNC(dnd_drop_destroy_popup),
2587                       &window);
2588   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2589                       GTK_SIGNAL_FUNC(dnd_drop_destroy_popup),
2590                       &window);
2591
2592   vbox = gtk_vbox_new(FALSE, 5);
2593
2594   /* Display message that we got from drop source */
2595   msg = g_malloc(strlen(event->dropdataavailable.data)
2596                  + strlen(event->dropdataavailable.data_type) + 100);
2597   sprintf(msg, "Drop data of type %s was:\n\n%s",
2598           event->dropdataavailable.data_type,
2599           (char *)event->dropdataavailable.data);
2600   lbl = gtk_label_new(msg);
2601   gtk_label_set_justify(GTK_LABEL(lbl), GTK_JUSTIFY_FILL);
2602   g_free(msg);
2603   gtk_widget_show(lbl);
2604   gtk_box_pack_start_defaults(GTK_BOX(vbox), lbl);
2605
2606   /* Provide an obvious way out of this heinousness */
2607   btn = gtk_button_new_with_label("Continue with life in\nspite of this oppression");
2608   gtk_signal_connect (GTK_OBJECT (btn), "clicked",
2609                       GTK_SIGNAL_FUNC(dnd_drop_destroy_popup),
2610                       &window);
2611   gtk_widget_show(btn);
2612   gtk_box_pack_start_defaults(GTK_BOX(vbox), btn);
2613
2614   gtk_container_add(GTK_CONTAINER(window), vbox);
2615
2616   gtk_widget_show(vbox);
2617   gtk_grab_add(window);
2618   gtk_widget_show(window);
2619 }
2620
2621 void
2622 dnd_drag_request (GtkWidget *button, GdkEvent *event)
2623 {
2624 #define DND_STRING "Bill Gates demands royalties for\nyour use of his innovation."
2625   gtk_widget_dnd_data_set (button, event, DND_STRING, strlen(DND_STRING) + 1);
2626 }
2627
2628 void
2629 create_dnd ()
2630 {
2631   static GtkWidget *window = NULL;
2632   GtkWidget *box1;
2633   GtkWidget *box2;
2634   GtkWidget *box3;
2635   GtkWidget *frame;
2636   GtkWidget *button;
2637   GtkWidget *separator;
2638
2639   /* For clarity... */
2640   char *possible_drag_types[] = {"text/plain"};
2641   char *accepted_drop_types[] = {"text/plain"};
2642
2643   if (!window)
2644     {
2645       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2646
2647       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2648                           GTK_SIGNAL_FUNC(destroy_window),
2649                           &window);
2650       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2651                           GTK_SIGNAL_FUNC(destroy_window),
2652                           &window);
2653
2654       gtk_window_set_title (GTK_WINDOW (window), "Drag -N- Drop");
2655       gtk_container_border_width (GTK_CONTAINER (window), 0);
2656
2657       box1 = gtk_vbox_new (FALSE, 0);
2658       gtk_container_add (GTK_CONTAINER (window), box1);
2659       gtk_widget_show (box1);
2660
2661       box2 = gtk_hbox_new (FALSE, 5);
2662       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2663       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2664       gtk_widget_show (box2);
2665
2666       frame = gtk_frame_new ("Drag");
2667       gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0);
2668       gtk_widget_show (frame);
2669
2670       box3 = gtk_vbox_new (FALSE, 5);
2671       gtk_container_border_width (GTK_CONTAINER (box3), 5);
2672       gtk_container_add (GTK_CONTAINER (frame), box3);
2673       gtk_widget_show (box3);
2674
2675       /*
2676        * FROM Button
2677        */
2678       button = gtk_button_new_with_label ("Drag me!");
2679       gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0);
2680       gtk_widget_show (button);
2681
2682       /*
2683        * currently, the widget has to be realized to
2684        * set dnd on it, this needs to change
2685        */
2686       gtk_widget_realize (button);
2687       gtk_signal_connect (GTK_OBJECT (button),
2688                           "drag_request_event",
2689                           GTK_SIGNAL_FUNC(dnd_drag_request),
2690                           button);
2691       
2692       gtk_widget_dnd_drag_set (button, TRUE, possible_drag_types, 1);
2693
2694
2695       frame = gtk_frame_new ("Drop");
2696       gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0);
2697       gtk_widget_show (frame);
2698
2699       box3 = gtk_vbox_new (FALSE, 5);
2700       gtk_container_border_width (GTK_CONTAINER (box3), 5);
2701       gtk_container_add (GTK_CONTAINER (frame), box3);
2702       gtk_widget_show (box3);
2703
2704
2705       /*
2706        * TO Button
2707        */
2708       button = gtk_button_new_with_label ("To");
2709       gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0);
2710       gtk_widget_show (button);
2711
2712       gtk_widget_realize (button);
2713       gtk_signal_connect (GTK_OBJECT (button), 
2714                           "drop_data_available_event",
2715                           GTK_SIGNAL_FUNC(dnd_drop),
2716                           button);
2717
2718       gtk_widget_dnd_drop_set (button, TRUE, accepted_drop_types, 1, FALSE);
2719
2720
2721       separator = gtk_hseparator_new ();
2722       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2723       gtk_widget_show (separator);
2724
2725
2726       box2 = gtk_vbox_new (FALSE, 10);
2727       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2728       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2729       gtk_widget_show (box2);
2730
2731
2732       button = gtk_button_new_with_label ("close");
2733
2734       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2735                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2736                                  GTK_OBJECT (window));
2737
2738       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2739       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2740       gtk_widget_grab_default (button);
2741       gtk_widget_show (button);
2742     }
2743
2744   if (!GTK_WIDGET_VISIBLE (window))
2745     gtk_widget_show (window);
2746   else
2747     gtk_widget_destroy (window);
2748 }
2749
2750 /*
2751  * Shaped Windows
2752  */
2753 static GdkWindow *root_win = NULL;
2754 static GtkWidget *modeller = NULL;
2755 static GtkWidget *sheets = NULL;
2756 static GtkWidget *rings = NULL;
2757
2758 typedef struct _cursoroffset {gint x,y;} CursorOffset;
2759
2760 static void
2761 shape_pressed (GtkWidget *widget, GdkEventButton *event)
2762 {
2763   CursorOffset *p;
2764
2765   /* ignore double and triple click */
2766   if (event->type != GDK_BUTTON_PRESS)
2767     return;
2768
2769   p = gtk_object_get_user_data (GTK_OBJECT(widget));
2770   p->x = (int) event->x;
2771   p->y = (int) event->y;
2772
2773   gtk_grab_add (widget);
2774   gdk_pointer_grab (widget->window, TRUE,
2775                     GDK_BUTTON_RELEASE_MASK |
2776                     GDK_BUTTON_MOTION_MASK,
2777                     NULL, NULL, 0);
2778 }
2779
2780
2781 static void
2782 shape_released (GtkWidget *widget)
2783 {
2784   gtk_grab_remove (widget);
2785   gdk_pointer_ungrab (0);
2786 }
2787
2788 static void
2789 shape_motion (GtkWidget      *widget, 
2790               GdkEventMotion *event)
2791 {
2792   gint xp, yp;
2793   CursorOffset * p;
2794   GdkModifierType mask;
2795
2796   p = gtk_object_get_user_data (GTK_OBJECT (widget));
2797
2798   gdk_window_get_pointer (root_win, &xp, &yp, &mask);
2799   gtk_widget_set_uposition (widget, xp  - p->x, yp  - p->y);
2800 }
2801
2802 GtkWidget *
2803 shape_create_icon (char     *xpm_file,
2804                    gint      x,
2805                    gint      y,
2806                    gint      px,
2807                    gint      py,
2808                    gint      window_type)
2809 {
2810   GtkWidget *window;
2811   GtkWidget *pixmap;
2812   GtkWidget *fixed;
2813   CursorOffset* icon_pos;
2814   GdkGC* gc;
2815   GdkBitmap *gdk_pixmap_mask;
2816   GdkPixmap *gdk_pixmap;
2817   GtkStyle *style;
2818
2819   style = gtk_widget_get_default_style ();
2820   gc = style->black_gc; 
2821
2822   /*
2823    * GDK_WINDOW_TOPLEVEL works also, giving you a title border
2824    */
2825   window = gtk_window_new (window_type);
2826   
2827   fixed = gtk_fixed_new ();
2828   gtk_widget_set_usize (fixed, 100,100);
2829   gtk_container_add (GTK_CONTAINER (window), fixed);
2830   gtk_widget_show (fixed);
2831   
2832   gdk_pixmap = gdk_pixmap_create_from_xpm (window->window, &gdk_pixmap_mask, 
2833                                            &style->bg[GTK_STATE_NORMAL],
2834                                            xpm_file);
2835
2836   pixmap = gtk_pixmap_new (gdk_pixmap, gdk_pixmap_mask);
2837   gtk_fixed_put (GTK_FIXED (fixed), pixmap, px,py);
2838   gtk_widget_show (pixmap);
2839   
2840   gtk_widget_shape_combine_mask (window, gdk_pixmap_mask, px,py);
2841
2842   gtk_widget_set_events (window, 
2843                          gtk_widget_get_events (window) |
2844                          GDK_BUTTON_MOTION_MASK |
2845                          GDK_BUTTON_PRESS_MASK);
2846
2847   gtk_signal_connect (GTK_OBJECT (window), "button_press_event",
2848                       GTK_SIGNAL_FUNC (shape_pressed),NULL);
2849   gtk_signal_connect (GTK_OBJECT (window), "button_release_event",
2850                       GTK_SIGNAL_FUNC (shape_released),NULL);
2851   gtk_signal_connect (GTK_OBJECT (window), "motion_notify_event",
2852                       GTK_SIGNAL_FUNC (shape_motion),NULL);
2853
2854   icon_pos = g_new (CursorOffset, 1);
2855   gtk_object_set_user_data(GTK_OBJECT(window), icon_pos);
2856
2857   gtk_widget_set_uposition (window, x, y);
2858   gtk_widget_show (window);
2859
2860   return window;
2861 }
2862
2863 void 
2864 create_shapes ()
2865 {
2866   root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
2867
2868   if (!modeller)
2869     {
2870       modeller = shape_create_icon ("Modeller.xpm",
2871                                     440, 140, 0,0, GTK_WINDOW_POPUP);
2872
2873       gtk_signal_connect (GTK_OBJECT (modeller), "destroy",
2874                           GTK_SIGNAL_FUNC(destroy_window),
2875                           &modeller);
2876       gtk_signal_connect (GTK_OBJECT (modeller), "delete_event",
2877                           GTK_SIGNAL_FUNC(destroy_window),
2878                           &modeller);
2879     }
2880   else
2881     gtk_widget_destroy (modeller);
2882
2883   if (!sheets)
2884     {
2885       sheets = shape_create_icon ("FilesQueue.xpm",
2886                                   580, 170, 0,0, GTK_WINDOW_POPUP);
2887
2888       gtk_signal_connect (GTK_OBJECT (sheets), "destroy",
2889                           GTK_SIGNAL_FUNC(destroy_window),
2890                           &sheets);
2891       gtk_signal_connect (GTK_OBJECT (sheets), "delete_event",
2892                           GTK_SIGNAL_FUNC(destroy_window),
2893                           &sheets);
2894
2895     }
2896   else
2897     gtk_widget_destroy (sheets);
2898
2899   if (!rings)
2900     {
2901       rings = shape_create_icon ("3DRings.xpm",
2902                                  460, 270, 25,25, GTK_WINDOW_TOPLEVEL);
2903
2904       gtk_signal_connect (GTK_OBJECT (rings), "destroy",
2905                           GTK_SIGNAL_FUNC(destroy_window),
2906                           &rings);
2907       gtk_signal_connect (GTK_OBJECT (rings), "delete_event",
2908                           GTK_SIGNAL_FUNC(destroy_window),
2909                           &rings);
2910     }
2911   else
2912     gtk_widget_destroy (rings);
2913 }
2914
2915
2916 /*
2917  * Progress Bar
2918  */
2919 static int progress_timer = 0;
2920
2921 gint
2922 progress_timeout (gpointer data)
2923 {
2924   gfloat new_val;
2925
2926   new_val = GTK_PROGRESS_BAR (data)->percentage;
2927   if (new_val >= 1.0)
2928     new_val = 0.0;
2929   new_val += 0.02;
2930
2931   gtk_progress_bar_update (GTK_PROGRESS_BAR (data), new_val);
2932
2933   return TRUE;
2934 }
2935
2936 void
2937 destroy_progress (GtkWidget  *widget,
2938                   GtkWidget **window)
2939 {
2940   destroy_window (widget, window);
2941   gtk_timeout_remove (progress_timer);
2942   progress_timer = 0;
2943 }
2944
2945 void
2946 create_progress_bar ()
2947 {
2948   static GtkWidget *window = NULL;
2949   GtkWidget *button;
2950   GtkWidget *vbox;
2951   GtkWidget *pbar;
2952   GtkWidget *label;
2953
2954   if (!window)
2955     {
2956       window = gtk_dialog_new ();
2957
2958       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2959                           GTK_SIGNAL_FUNC(destroy_progress),
2960                           &window);
2961       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2962                           GTK_SIGNAL_FUNC(destroy_progress),
2963                           &window);
2964
2965       gtk_window_set_title (GTK_WINDOW (window), "dialog");
2966       gtk_container_border_width (GTK_CONTAINER (window), 0);
2967
2968
2969       vbox = gtk_vbox_new (FALSE, 5);
2970       gtk_container_border_width (GTK_CONTAINER (vbox), 10);
2971       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
2972                           vbox, TRUE, TRUE, 0);
2973       gtk_widget_show (vbox);
2974
2975       label = gtk_label_new ("progress...");
2976       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2977       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
2978       gtk_widget_show (label);
2979
2980       pbar = gtk_progress_bar_new ();
2981       gtk_widget_set_usize (pbar, 200, 20);
2982       gtk_box_pack_start (GTK_BOX (vbox), pbar, TRUE, TRUE, 0);
2983       gtk_widget_show (pbar);
2984
2985       progress_timer = gtk_timeout_add (100, progress_timeout, pbar);
2986
2987       button = gtk_button_new_with_label ("close");
2988       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2989                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2990                                  GTK_OBJECT (window));
2991       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2992       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
2993                           button, TRUE, TRUE, 0);
2994       gtk_widget_grab_default (button);
2995       gtk_widget_show (button);
2996     }
2997
2998   if (!GTK_WIDGET_VISIBLE (window))
2999     gtk_widget_show (window);
3000   else
3001     gtk_widget_destroy (window);
3002 }
3003
3004
3005 /*
3006  * Color Preview
3007  */
3008 static int color_idle = 0;
3009
3010 gint
3011 color_idle_func (GtkWidget *preview)
3012 {
3013   static int count = 1;
3014   guchar buf[768];
3015   int i, j, k;
3016
3017   for (i = 0; i < 256; i++)
3018     {
3019       for (j = 0, k = 0; j < 256; j++)
3020         {
3021           buf[k+0] = i + count;
3022           buf[k+1] = 0;
3023           buf[k+2] = j + count;
3024           k += 3;
3025         }
3026
3027       gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3028     }
3029
3030   count += 1;
3031
3032   gtk_widget_draw (preview, NULL);
3033
3034   return TRUE;
3035 }
3036
3037 void
3038 color_preview_destroy (GtkWidget  *widget,
3039                        GtkWidget **window)
3040 {
3041   gtk_idle_remove (color_idle);
3042   color_idle = 0;
3043
3044   destroy_window (widget, window);
3045 }
3046
3047 void
3048 create_color_preview ()
3049 {
3050   static GtkWidget *window = NULL;
3051   GtkWidget *preview;
3052   guchar buf[768];
3053   int i, j, k;
3054
3055   if (!window)
3056     {
3057       gtk_widget_push_visual (gtk_preview_get_visual ());
3058       gtk_widget_push_colormap (gtk_preview_get_cmap ());
3059
3060       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3061
3062       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3063                           GTK_SIGNAL_FUNC(color_preview_destroy),
3064                           &window);
3065       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3066                           GTK_SIGNAL_FUNC(color_preview_destroy),
3067                           &window);
3068
3069       gtk_window_set_title (GTK_WINDOW (window), "test");
3070       gtk_container_border_width (GTK_CONTAINER (window), 10);
3071
3072       preview = gtk_preview_new (GTK_PREVIEW_COLOR);
3073       gtk_preview_size (GTK_PREVIEW (preview), 256, 256);
3074       gtk_container_add (GTK_CONTAINER (window), preview);
3075       gtk_widget_show (preview);
3076
3077       for (i = 0; i < 256; i++)
3078         {
3079           for (j = 0, k = 0; j < 256; j++)
3080             {
3081               buf[k+0] = i;
3082               buf[k+1] = 0;
3083               buf[k+2] = j;
3084               k += 3;
3085             }
3086
3087           gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3088         }
3089
3090       color_idle = gtk_idle_add ((GtkFunction) color_idle_func, preview);
3091
3092       gtk_widget_pop_colormap ();
3093       gtk_widget_pop_visual ();
3094     }
3095
3096   if (!GTK_WIDGET_VISIBLE (window))
3097     gtk_widget_show (window);
3098   else
3099     gtk_widget_destroy (window);
3100 }
3101
3102
3103 /*
3104  * Gray Preview
3105  */
3106 static int gray_idle = 0;
3107
3108 gint
3109 gray_idle_func (GtkWidget *preview)
3110 {
3111   static int count = 1;
3112   guchar buf[256];
3113   int i, j;
3114
3115   for (i = 0; i < 256; i++)
3116     {
3117       for (j = 0; j < 256; j++)
3118         buf[j] = i + j + count;
3119
3120       gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3121     }
3122
3123   count += 1;
3124
3125   gtk_widget_draw (preview, NULL);
3126
3127   return TRUE;
3128 }
3129
3130 void
3131 gray_preview_destroy (GtkWidget  *widget,
3132                       GtkWidget **window)
3133 {
3134   gtk_idle_remove (gray_idle);
3135   gray_idle = 0;
3136
3137   destroy_window (widget, window);
3138 }
3139
3140 void
3141 create_gray_preview ()
3142 {
3143   static GtkWidget *window = NULL;
3144   GtkWidget *preview;
3145   guchar buf[256];
3146   int i, j;
3147
3148   if (!window)
3149     {
3150       gtk_widget_push_visual (gtk_preview_get_visual ());
3151       gtk_widget_push_colormap (gtk_preview_get_cmap ());
3152
3153       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3154
3155       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3156                           GTK_SIGNAL_FUNC(gray_preview_destroy),
3157                           &window);
3158       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3159                           GTK_SIGNAL_FUNC(gray_preview_destroy),
3160                           &window);
3161
3162       gtk_window_set_title (GTK_WINDOW (window), "test");
3163       gtk_container_border_width (GTK_CONTAINER (window), 10);
3164
3165       preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
3166       gtk_preview_size (GTK_PREVIEW (preview), 256, 256);
3167       gtk_container_add (GTK_CONTAINER (window), preview);
3168       gtk_widget_show (preview);
3169
3170       for (i = 0; i < 256; i++)
3171         {
3172           for (j = 0; j < 256; j++)
3173             buf[j] = i + j;
3174
3175           gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3176         }
3177
3178       gray_idle = gtk_idle_add ((GtkFunction) gray_idle_func, preview);
3179
3180       gtk_widget_pop_colormap ();
3181       gtk_widget_pop_visual ();
3182     }
3183
3184   if (!GTK_WIDGET_VISIBLE (window))
3185     gtk_widget_show (window);
3186   else
3187     gtk_widget_destroy (window);
3188 }
3189
3190
3191 /*
3192  * Selection Test
3193  */
3194 void
3195 selection_test_received (GtkWidget *list, GtkSelectionData *data)
3196 {
3197   GdkAtom *atoms;
3198   GtkWidget *list_item;
3199   GList *item_list;
3200   int i, l;
3201
3202   if (data->length < 0)
3203     {
3204       g_print ("Selection retrieval failed\n");
3205       return;
3206     }
3207   if (data->type != GDK_SELECTION_TYPE_ATOM)
3208     {
3209       g_print ("Selection \"TARGETS\" was not returned as atoms!\n");
3210       return;
3211     }
3212
3213   /* Clear out any current list items */
3214
3215   gtk_list_clear_items (GTK_LIST(list), 0, -1);
3216
3217   /* Add new items to list */
3218
3219   atoms = (GdkAtom *)data->data;
3220
3221   item_list = NULL;
3222   l = data->length / sizeof (GdkAtom);
3223   for (i = 0; i < l; i++)
3224     {
3225       char *name;
3226       name = gdk_atom_name (atoms[i]);
3227       if (name != NULL)
3228         {
3229           list_item = gtk_list_item_new_with_label (name);
3230           g_free (name);
3231         }
3232       else
3233         list_item = gtk_list_item_new_with_label ("(bad atom)");
3234
3235       gtk_widget_show (list_item);
3236       item_list = g_list_append (item_list, list_item);
3237     }
3238
3239   gtk_list_append_items (GTK_LIST (list), item_list);
3240
3241   return;
3242 }
3243
3244 void
3245 selection_test_get_targets (GtkWidget *widget, GtkWidget *list)
3246 {
3247   static GdkAtom targets_atom = GDK_NONE;
3248
3249   if (targets_atom == GDK_NONE)
3250     targets_atom = gdk_atom_intern ("TARGETS", FALSE);
3251
3252   gtk_selection_convert (list, GDK_SELECTION_PRIMARY, targets_atom,
3253                          GDK_CURRENT_TIME);
3254 }
3255
3256 void
3257 create_selection_test ()
3258 {
3259   static GtkWidget *window = NULL;
3260   GtkWidget *button;
3261   GtkWidget *vbox;
3262   GtkWidget *scrolled_win;
3263   GtkWidget *list;
3264   GtkWidget *label;
3265
3266   if (!window)
3267     {
3268       window = gtk_dialog_new ();
3269
3270       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3271                           GTK_SIGNAL_FUNC(destroy_window),
3272                           &window);
3273       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3274                           GTK_SIGNAL_FUNC(destroy_window),
3275                           &window);
3276
3277       gtk_window_set_title (GTK_WINDOW (window), "Selection Test");
3278       gtk_container_border_width (GTK_CONTAINER (window), 0);
3279
3280       /* Create the list */
3281
3282       vbox = gtk_vbox_new (FALSE, 5);
3283       gtk_container_border_width (GTK_CONTAINER (vbox), 10);
3284       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox,
3285                           TRUE, TRUE, 0);
3286       gtk_widget_show (vbox);
3287
3288       label = gtk_label_new ("Gets available targets for current selection");
3289       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
3290       gtk_widget_show (label);
3291
3292       scrolled_win = gtk_scrolled_window_new (NULL, NULL);
3293       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
3294                                       GTK_POLICY_AUTOMATIC, 
3295                                       GTK_POLICY_AUTOMATIC);
3296       gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
3297       gtk_widget_set_usize (scrolled_win, 100, 200);
3298       gtk_widget_show (scrolled_win);
3299
3300       list = gtk_list_new ();
3301       gtk_container_add (GTK_CONTAINER (scrolled_win), list);
3302
3303       gtk_signal_connect (GTK_OBJECT(list), "selection_received",
3304                           GTK_SIGNAL_FUNC (selection_test_received), NULL);
3305       gtk_widget_show (list);
3306
3307       /* .. And create some buttons */
3308       button = gtk_button_new_with_label ("Get Targets");
3309       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
3310                           button, TRUE, TRUE, 0);
3311
3312       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3313                           GTK_SIGNAL_FUNC (selection_test_get_targets), list);
3314       gtk_widget_show (button);
3315
3316       button = gtk_button_new_with_label ("Quit");
3317       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
3318                           button, TRUE, TRUE, 0);
3319
3320       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3321                                  GTK_SIGNAL_FUNC (gtk_widget_destroy),
3322                                  GTK_OBJECT (window));
3323       gtk_widget_show (button);
3324     }
3325
3326   if (!GTK_WIDGET_VISIBLE (window))
3327     gtk_widget_show (window);
3328   else
3329     gtk_widget_destroy (window);
3330 }
3331
3332
3333 /*
3334  * Gamma Curve
3335  */
3336 void
3337 create_gamma_curve ()
3338 {
3339   static GtkWidget *window = NULL, *curve;
3340   static int count = 0;
3341   gfloat vec[256];
3342   gint max;
3343   gint i;
3344
3345   if (!window)
3346     {
3347       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3348       gtk_window_set_title (GTK_WINDOW (window), "test");
3349       gtk_container_border_width (GTK_CONTAINER (window), 10);
3350
3351       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3352                           GTK_SIGNAL_FUNC(destroy_window),
3353                           &window);
3354       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3355                           GTK_SIGNAL_FUNC(destroy_window),
3356                           &window);
3357
3358       curve = gtk_gamma_curve_new ();
3359       gtk_container_add (GTK_CONTAINER (window), curve);
3360       gtk_widget_show (curve);
3361     }
3362
3363   max = 127 + (count % 2)*128;
3364   gtk_curve_set_range (GTK_CURVE (GTK_GAMMA_CURVE (curve)->curve),
3365                        0, max, 0, max);
3366   for (i = 0; i < max; ++i)
3367     vec[i] = (127 / sqrt (max)) * sqrt (i);
3368   gtk_curve_set_vector (GTK_CURVE (GTK_GAMMA_CURVE (curve)->curve),
3369                         max, vec);
3370
3371   if (!GTK_WIDGET_VISIBLE (window))
3372     gtk_widget_show (window);
3373   else if (count % 4 == 3)
3374     {
3375       gtk_widget_destroy (window);
3376       window = NULL;
3377     }
3378
3379   ++count;
3380 }
3381
3382 static int scroll_test_pos = 0.0;
3383 static GdkGC *scroll_test_gc = NULL;
3384
3385 static gint
3386 scroll_test_expose (GtkWidget *widget, GdkEventExpose *event,
3387                     GtkAdjustment *adj)
3388 {
3389   gint i,j;
3390   gint imin, imax, jmin, jmax;
3391   
3392   imin = (event->area.x) / 10;
3393   imax = (event->area.x + event->area.width + 9) / 10;
3394
3395   jmin = ((int)adj->value + event->area.y) / 10;
3396   jmax = ((int)adj->value + event->area.y + event->area.height + 9) / 10;
3397
3398   gdk_window_clear_area (widget->window,
3399                          event->area.x, event->area.y,
3400                          event->area.width, event->area.height);
3401
3402   for (i=imin; i<imax; i++)
3403     for (j=jmin; j<jmax; j++)
3404       if ((i+j) % 2)
3405         gdk_draw_rectangle (widget->window, 
3406                             widget->style->black_gc,
3407                             TRUE,
3408                             10*i, 10*j - (int)adj->value, 1+i%10, 1+j%10);
3409
3410   return TRUE;
3411 }
3412
3413 static void
3414 scroll_test_configure (GtkWidget *widget, GdkEventConfigure *event,
3415                        GtkAdjustment *adj)
3416 {
3417   adj->page_increment = 0.9 * widget->allocation.height;
3418   adj->page_size = widget->allocation.height;
3419
3420   gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed");
3421 }
3422
3423 static void
3424 scroll_test_adjustment_changed (GtkAdjustment *adj, GtkWidget *widget)
3425 {
3426   gint source_min = (int)adj->value - scroll_test_pos;
3427   gint source_max = source_min + widget->allocation.height;
3428   gint dest_min = 0;
3429   gint dest_max = widget->allocation.height;
3430   GdkRectangle rect;
3431   GdkEvent *event;
3432
3433   scroll_test_pos = adj->value;
3434
3435   if (!GTK_WIDGET_DRAWABLE (widget))
3436     return;
3437
3438   if (source_min < 0)
3439     {
3440       rect.x = 0; 
3441       rect.y = 0;
3442       rect.width = widget->allocation.width;
3443       rect.height = -source_min;
3444       if (rect.height > widget->allocation.height)
3445         rect.height = widget->allocation.height;
3446
3447       source_min = 0;
3448       dest_min = rect.height;
3449     }
3450   else
3451     {
3452       rect.x = 0;
3453       rect.y = 2*widget->allocation.height - source_max;
3454       if (rect.y < 0)
3455         rect.y = 0;
3456       rect.width = widget->allocation.width;
3457       rect.height = widget->allocation.height - rect.y;
3458
3459       source_max = widget->allocation.height;
3460       dest_max = rect.y;
3461     }
3462
3463   if (source_min != source_max)
3464     {
3465       if (scroll_test_gc == NULL)
3466         {
3467           scroll_test_gc = gdk_gc_new (widget->window);
3468           gdk_gc_set_exposures (scroll_test_gc, TRUE);
3469         }
3470
3471       gdk_draw_pixmap (widget->window,
3472                        scroll_test_gc,
3473                        widget->window,
3474                        0, source_min,
3475                        0, dest_min,
3476                        widget->allocation.width,
3477                        source_max - source_min);
3478
3479       /* Make sure graphics expose events are processed before scrolling
3480        * again */
3481       
3482       while ((event = gdk_event_get_graphics_expose (widget->window)) != NULL)
3483         {
3484           gtk_widget_event (widget, event);
3485           if (event->expose.count == 0)
3486             {
3487               gdk_event_free (event);
3488               break;
3489             }
3490           gdk_event_free (event);
3491         }
3492     }
3493
3494
3495   if (rect.height != 0)
3496     gtk_widget_draw (widget, &rect);
3497 }
3498
3499
3500 void
3501 create_scroll_test ()
3502 {
3503   static GtkWidget *window = NULL;
3504   GtkWidget *hbox;
3505   GtkWidget *drawing_area;
3506   GtkWidget *scrollbar;
3507   GtkWidget *button;
3508   GtkAdjustment *adj;
3509   
3510   if (!window)
3511     {
3512       window = gtk_dialog_new ();
3513
3514       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3515                           GTK_SIGNAL_FUNC(destroy_window),
3516                           &window);
3517       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3518                           GTK_SIGNAL_FUNC(destroy_window),
3519                           &window);
3520
3521       gtk_window_set_title (GTK_WINDOW (window), "Scroll Test");
3522       gtk_container_border_width (GTK_CONTAINER (window), 0);
3523
3524       hbox = gtk_hbox_new (FALSE, 0);
3525       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), hbox,
3526                           TRUE, TRUE, 0);
3527       gtk_widget_show (hbox);
3528
3529       drawing_area = gtk_drawing_area_new ();
3530       gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200);
3531       gtk_box_pack_start (GTK_BOX (hbox), drawing_area, TRUE, TRUE, 0);
3532       gtk_widget_show (drawing_area);
3533
3534       gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK);
3535
3536       adj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 1000.0, 1.0, 180.0, 200.0));
3537       scroll_test_pos = 0.0;
3538
3539       scrollbar = gtk_vscrollbar_new (adj);
3540       gtk_box_pack_start (GTK_BOX (hbox), scrollbar, FALSE, FALSE, 0);
3541       gtk_widget_show (scrollbar);
3542
3543       gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
3544                           GTK_SIGNAL_FUNC (scroll_test_expose), adj);
3545       gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event",
3546                           GTK_SIGNAL_FUNC (scroll_test_configure), adj);
3547
3548       
3549       gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
3550                           GTK_SIGNAL_FUNC (scroll_test_adjustment_changed),
3551                           drawing_area);
3552       
3553       /* .. And create some buttons */
3554
3555       button = gtk_button_new_with_label ("Quit");
3556       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
3557                           button, TRUE, TRUE, 0);
3558
3559       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3560                                  GTK_SIGNAL_FUNC (gtk_widget_destroy),
3561                                  GTK_OBJECT (window));
3562       gtk_widget_show (button);
3563     }
3564
3565   if (!GTK_WIDGET_VISIBLE (window))
3566     gtk_widget_show (window);
3567   else
3568     gtk_widget_destroy (window);
3569 }
3570
3571 /*
3572  * Timeout Test
3573  */
3574 static int timer = 0;
3575
3576 void
3577 timeout_test (GtkWidget *label)
3578 {
3579   static int count = 0;
3580   static char buffer[32];
3581
3582   sprintf (buffer, "count: %d", ++count);
3583   gtk_label_set (GTK_LABEL (label), buffer);
3584 }
3585
3586 void
3587 start_timeout_test (GtkWidget *widget,
3588                     GtkWidget *label)
3589 {
3590   if (!timer)
3591     {
3592       timer = gtk_timeout_add (100, (GtkFunction) timeout_test, label);
3593     }
3594 }
3595
3596 void
3597 stop_timeout_test (GtkWidget *widget,
3598                    gpointer   data)
3599 {
3600   if (timer)
3601     {
3602       gtk_timeout_remove (timer);
3603       timer = 0;
3604     }
3605 }
3606
3607 void
3608 destroy_timeout_test (GtkWidget  *widget,
3609                       GtkWidget **window)
3610 {
3611   destroy_window (widget, window);
3612   stop_timeout_test (NULL, NULL);
3613 }
3614
3615 void
3616 create_timeout_test ()
3617 {
3618   static GtkWidget *window = NULL;
3619   GtkWidget *button;
3620   GtkWidget *label;
3621
3622   if (!window)
3623     {
3624       window = gtk_dialog_new ();
3625
3626       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3627                           GTK_SIGNAL_FUNC(destroy_timeout_test),
3628                           &window);
3629       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3630                           GTK_SIGNAL_FUNC(destroy_timeout_test),
3631                           &window);
3632
3633       gtk_window_set_title (GTK_WINDOW (window), "Timeout Test");
3634       gtk_container_border_width (GTK_CONTAINER (window), 0);
3635
3636       label = gtk_label_new ("count: 0");
3637       gtk_misc_set_padding (GTK_MISC (label), 10, 10);
3638       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
3639                           label, TRUE, TRUE, 0);
3640       gtk_widget_show (label);
3641
3642       button = gtk_button_new_with_label ("close");
3643       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3644                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
3645                                  GTK_OBJECT (window));
3646       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3647       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3648                           button, TRUE, TRUE, 0);
3649       gtk_widget_grab_default (button);
3650       gtk_widget_show (button);
3651
3652       button = gtk_button_new_with_label ("start");
3653       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3654                           GTK_SIGNAL_FUNC(start_timeout_test),
3655                           label);
3656       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3657       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3658                           button, TRUE, TRUE, 0);
3659       gtk_widget_show (button);
3660
3661       button = gtk_button_new_with_label ("stop");
3662       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3663                           GTK_SIGNAL_FUNC(stop_timeout_test),
3664                           NULL);
3665       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3666       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3667                           button, TRUE, TRUE, 0);
3668       gtk_widget_show (button);
3669     }
3670
3671   if (!GTK_WIDGET_VISIBLE (window))
3672     gtk_widget_show (window);
3673   else
3674     gtk_widget_destroy (window);
3675 }
3676
3677
3678 /*
3679  * Idle Test
3680  */
3681 static int idle = 0;
3682
3683 gint
3684 idle_test (GtkWidget *label)
3685 {
3686   static int count = 0;
3687   static char buffer[32];
3688
3689   sprintf (buffer, "count: %d", ++count);
3690   gtk_label_set (GTK_LABEL (label), buffer);
3691
3692   return TRUE;
3693 }
3694
3695 void
3696 start_idle_test (GtkWidget *widget,
3697                  GtkWidget *label)
3698 {
3699   if (!idle)
3700     {
3701       idle = gtk_idle_add ((GtkFunction) idle_test, label);
3702     }
3703 }
3704
3705 void
3706 stop_idle_test (GtkWidget *widget,
3707                 gpointer   data)
3708 {
3709   if (idle)
3710     {
3711       gtk_idle_remove (idle);
3712       idle = 0;
3713     }
3714 }
3715
3716 void
3717 destroy_idle_test (GtkWidget  *widget,
3718                    GtkWidget **window)
3719 {
3720   destroy_window (widget, window);
3721   stop_idle_test (NULL, NULL);
3722 }
3723
3724 void
3725 create_idle_test ()
3726 {
3727   static GtkWidget *window = NULL;
3728   GtkWidget *button;
3729   GtkWidget *label;
3730
3731   if (!window)
3732     {
3733       window = gtk_dialog_new ();
3734
3735       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3736                           GTK_SIGNAL_FUNC(destroy_idle_test),
3737                           &window);
3738       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3739                           GTK_SIGNAL_FUNC(destroy_idle_test),
3740                           &window);
3741
3742       gtk_window_set_title (GTK_WINDOW (window), "Idle Test");
3743       gtk_container_border_width (GTK_CONTAINER (window), 0);
3744
3745       label = gtk_label_new ("count: 0");
3746       gtk_misc_set_padding (GTK_MISC (label), 10, 10);
3747       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
3748                           label, TRUE, TRUE, 0);
3749       gtk_widget_show (label);
3750
3751       button = gtk_button_new_with_label ("close");
3752       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3753                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
3754                                  GTK_OBJECT (window));
3755       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3756       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3757                           button, TRUE, TRUE, 0);
3758       gtk_widget_grab_default (button);
3759       gtk_widget_show (button);
3760
3761       button = gtk_button_new_with_label ("start");
3762       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3763                           GTK_SIGNAL_FUNC(start_idle_test),
3764                           label);
3765       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3766       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3767                           button, TRUE, TRUE, 0);
3768       gtk_widget_show (button);
3769
3770       button = gtk_button_new_with_label ("stop");
3771       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3772                           GTK_SIGNAL_FUNC(stop_idle_test),
3773                           NULL);
3774       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3775       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3776                           button, TRUE, TRUE, 0);
3777       gtk_widget_show (button);
3778     }
3779
3780   if (!GTK_WIDGET_VISIBLE (window))
3781     gtk_widget_show (window);
3782   else
3783     gtk_widget_destroy (window);
3784 }
3785
3786 void
3787 test_destroy (GtkWidget  *widget,
3788               GtkWidget **window)
3789 {
3790   destroy_window (widget, window);
3791   gtk_main_quit ();
3792 }
3793
3794 /*
3795  * Basic Test
3796  */
3797 void
3798 create_test ()
3799 {
3800   static GtkWidget *window = NULL;
3801
3802   if (!window)
3803     {
3804       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3805
3806       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3807                           GTK_SIGNAL_FUNC(test_destroy),
3808                           &window);
3809       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3810                           GTK_SIGNAL_FUNC(test_destroy),
3811                           &window);
3812
3813
3814       gtk_window_set_title (GTK_WINDOW (window), "test");
3815       gtk_container_border_width (GTK_CONTAINER (window), 0);
3816     }
3817
3818   if (!GTK_WIDGET_VISIBLE (window))
3819     {
3820       gtk_widget_show (window);
3821
3822       g_print ("create_test: start\n");
3823       gtk_main ();
3824       g_print ("create_test: done\n");
3825     }
3826   else
3827     gtk_widget_destroy (window);
3828 }
3829
3830
3831 /*
3832  * Main Window and Exit
3833  */
3834 void
3835 do_exit (GtkWidget *widget, GtkWidget *window)
3836 {
3837   gtk_widget_destroy (window);
3838   gtk_main_quit ();
3839 }
3840
3841 void
3842 create_main_window ()
3843 {
3844   struct {
3845     char *label;
3846     void (*func) ();
3847   } buttons[] =
3848     {
3849       { "buttons", create_buttons },
3850       { "toggle buttons", create_toggle_buttons },
3851       { "check buttons", create_check_buttons },
3852       { "radio buttons", create_radio_buttons },
3853       { "button box", create_button_box },
3854       { "toolbar", create_toolbar },
3855       { "handle box", create_handle_box },
3856       { "reparent", create_reparent },
3857       { "pixmap", create_pixmap },
3858       { "tooltips", create_tooltips },
3859       { "menus", create_menus },
3860       { "scrolled windows", create_scrolled_windows },
3861       { "drawing areas", NULL },
3862       { "entry", create_entry },
3863       { "list", create_list },
3864       { "clist", create_clist},
3865       { "color selection", create_color_selection },
3866       { "file selection", create_file_selection },
3867       { "dialog", create_dialog },
3868       { "miscellaneous", NULL },
3869       { "range controls", create_range_controls },
3870       { "rulers", create_rulers },
3871       { "text", create_text },
3872       { "notebook", create_notebook },
3873       { "panes", create_panes },
3874       { "shapes", create_shapes },
3875       { "dnd", create_dnd },
3876       { "progress bar", create_progress_bar },
3877       { "preview color", create_color_preview },
3878       { "preview gray", create_gray_preview },
3879       { "gamma curve", create_gamma_curve },
3880       { "test scrolling", create_scroll_test },
3881       { "test selection", create_selection_test },
3882       { "test timeout", create_timeout_test },
3883       { "test idle", create_idle_test },
3884       { "test", create_test },
3885     };
3886   int nbuttons = sizeof (buttons) / sizeof (buttons[0]);
3887   GtkWidget *window;
3888   GtkWidget *box1;
3889   GtkWidget *box2;
3890   GtkWidget *scrolled_window;
3891   GtkWidget *button;
3892   GtkWidget *separator;
3893   int i;
3894
3895   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3896   gtk_widget_set_name (window, "main window");
3897   gtk_widget_set_usize (window, 200, 400);
3898   gtk_widget_set_uposition (window, 20, 20);
3899
3900   gtk_signal_connect (GTK_OBJECT (window), "destroy",
3901                       GTK_SIGNAL_FUNC(gtk_main_quit),
3902                       NULL);
3903   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3904                       GTK_SIGNAL_FUNC(gtk_main_quit),
3905                       NULL);
3906
3907   box1 = gtk_vbox_new (FALSE, 0);
3908   gtk_container_add (GTK_CONTAINER (window), box1);
3909   gtk_widget_show (box1);
3910
3911   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
3912   gtk_container_border_width (GTK_CONTAINER (scrolled_window), 10);
3913   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
3914                                   GTK_POLICY_AUTOMATIC, 
3915                                   GTK_POLICY_AUTOMATIC);
3916   gtk_box_pack_start (GTK_BOX (box1), scrolled_window, TRUE, TRUE, 0);
3917   gtk_widget_show (scrolled_window);
3918
3919   box2 = gtk_vbox_new (FALSE, 0);
3920   gtk_container_border_width (GTK_CONTAINER (box2), 10);
3921   gtk_container_add (GTK_CONTAINER (scrolled_window), box2);
3922   gtk_widget_show (box2);
3923
3924   for (i = 0; i < nbuttons; i++)
3925     {
3926       button = gtk_button_new_with_label (buttons[i].label);
3927       if (buttons[i].func)
3928         gtk_signal_connect (GTK_OBJECT (button), 
3929                             "clicked", 
3930                             GTK_SIGNAL_FUNC(buttons[i].func),
3931                             NULL);
3932       else
3933         gtk_widget_set_sensitive (button, FALSE);
3934       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
3935       gtk_widget_show (button);
3936     }
3937
3938   separator = gtk_hseparator_new ();
3939   gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
3940   gtk_widget_show (separator);
3941
3942   box2 = gtk_vbox_new (FALSE, 10);
3943   gtk_container_border_width (GTK_CONTAINER (box2), 10);
3944   gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
3945   gtk_widget_show (box2);
3946
3947   button = gtk_button_new_with_label ("close");
3948   gtk_signal_connect (GTK_OBJECT (button), "clicked",
3949                       GTK_SIGNAL_FUNC (do_exit),
3950                       window);
3951   gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
3952   GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3953   gtk_widget_grab_default (button);
3954   gtk_widget_show (button);
3955
3956   gtk_widget_show (window);
3957 }
3958
3959 int
3960 main (int argc, char *argv[])
3961 {
3962   gtk_set_locale ();
3963
3964   gtk_init (&argc, &argv);
3965   gtk_rc_parse ("testgtkrc");
3966
3967   create_main_window ();
3968
3969   gtk_main ();
3970
3971   return 0;
3972 }