]> Pileus Git - ~andy/gtk/blob - gtk/testgtk.c
don't add the same menu to different menuitems/ optionmenus.
[~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 *menuitem;
1115   GSList *group;
1116   char buf[32];
1117   int i, j;
1118
1119   if (depth < 1)
1120     return NULL;
1121
1122   menu = gtk_menu_new ();
1123   group = NULL;
1124
1125   for (i = 0, j = 1; i < 5; i++, j++)
1126     {
1127       sprintf (buf, "item %2d - %d", depth, j);
1128       menuitem = gtk_radio_menu_item_new_with_label (group, buf);
1129       group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
1130       if (depth % 2)
1131         gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
1132       gtk_menu_append (GTK_MENU (menu), menuitem);
1133       gtk_widget_show (menuitem);
1134
1135       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1));
1136     }
1137
1138   return menu;
1139 }
1140
1141 void
1142 create_menus ()
1143 {
1144   static GtkWidget *window = NULL;
1145   GtkWidget *box1;
1146   GtkWidget *box2;
1147   GtkWidget *button;
1148   GtkWidget *menu;
1149   GtkWidget *menubar;
1150   GtkWidget *menuitem;
1151   GtkWidget *optionmenu;
1152   GtkWidget *separator;
1153
1154   if (!window)
1155     {
1156       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1157
1158       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1159                           GTK_SIGNAL_FUNC(destroy_window),
1160                           &window);
1161       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1162                           GTK_SIGNAL_FUNC(destroy_window),
1163                           &window);
1164
1165       gtk_window_set_title (GTK_WINDOW (window), "menus");
1166       gtk_container_border_width (GTK_CONTAINER (window), 0);
1167
1168
1169       box1 = gtk_vbox_new (FALSE, 0);
1170       gtk_container_add (GTK_CONTAINER (window), box1);
1171       gtk_widget_show (box1);
1172
1173
1174       menubar = gtk_menu_bar_new ();
1175       gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0);
1176       gtk_widget_show (menubar);
1177
1178       menu = create_menu (2);
1179
1180       menuitem = gtk_menu_item_new_with_label ("test\nline2");
1181       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
1182       gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
1183       gtk_widget_show (menuitem);
1184
1185       menuitem = gtk_menu_item_new_with_label ("foo");
1186       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3));
1187       gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
1188       gtk_widget_show (menuitem);
1189
1190       menuitem = gtk_menu_item_new_with_label ("bar");
1191       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4));
1192       gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem));
1193       gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
1194       gtk_widget_show (menuitem);
1195
1196
1197       box2 = gtk_vbox_new (FALSE, 10);
1198       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1199       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1200       gtk_widget_show (box2);
1201
1202
1203       optionmenu = gtk_option_menu_new ();
1204       gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), create_menu (1));
1205       gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 4);
1206       gtk_box_pack_start (GTK_BOX (box2), optionmenu, TRUE, TRUE, 0);
1207       gtk_widget_show (optionmenu);
1208
1209
1210       separator = gtk_hseparator_new ();
1211       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1212       gtk_widget_show (separator);
1213
1214
1215       box2 = gtk_vbox_new (FALSE, 10);
1216       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1217       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1218       gtk_widget_show (box2);
1219
1220
1221       button = gtk_button_new_with_label ("close");
1222       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1223                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1224                                  GTK_OBJECT (window));
1225       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1226       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1227       gtk_widget_grab_default (button);
1228       gtk_widget_show (button);
1229     }
1230
1231   if (!GTK_WIDGET_VISIBLE (window))
1232     gtk_widget_show (window);
1233   else
1234     gtk_widget_destroy (window);
1235 }
1236
1237 /*
1238  * GtkScrolledWindow
1239  */
1240 void
1241 create_scrolled_windows ()
1242 {
1243   static GtkWidget *window;
1244   GtkWidget *scrolled_window;
1245   GtkWidget *table;
1246   GtkWidget *button;
1247   char buffer[32];
1248   int i, j;
1249
1250   if (!window)
1251     {
1252       window = gtk_dialog_new ();
1253
1254       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1255                           GTK_SIGNAL_FUNC(destroy_window),
1256                           &window);
1257       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1258                           GTK_SIGNAL_FUNC(destroy_window),
1259                           &window);
1260
1261       gtk_window_set_title (GTK_WINDOW (window), "dialog");
1262       gtk_container_border_width (GTK_CONTAINER (window), 0);
1263
1264
1265       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1266       gtk_container_border_width (GTK_CONTAINER (scrolled_window), 10);
1267       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1268                                       GTK_POLICY_AUTOMATIC,
1269                                       GTK_POLICY_AUTOMATIC);
1270       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
1271                           scrolled_window, TRUE, TRUE, 0);
1272       gtk_widget_show (scrolled_window);
1273
1274       table = gtk_table_new (20, 20, FALSE);
1275       gtk_table_set_row_spacings (GTK_TABLE (table), 10);
1276       gtk_table_set_col_spacings (GTK_TABLE (table), 10);
1277       gtk_container_add (GTK_CONTAINER (scrolled_window), table);
1278       gtk_widget_show (table);
1279
1280       for (i = 0; i < 20; i++)
1281         for (j = 0; j < 20; j++)
1282           {
1283             sprintf (buffer, "button (%d,%d)\n", i, j);
1284             button = gtk_toggle_button_new_with_label (buffer);
1285             gtk_table_attach_defaults (GTK_TABLE (table), button,
1286                                        i, i+1, j, j+1);
1287             gtk_widget_show (button);
1288           }
1289
1290
1291       button = gtk_button_new_with_label ("close");
1292       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1293                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1294                                  GTK_OBJECT (window));
1295       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1296       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
1297                           button, TRUE, TRUE, 0);
1298       gtk_widget_grab_default (button);
1299       gtk_widget_show (button);
1300     }
1301
1302   if (!GTK_WIDGET_VISIBLE (window))
1303     gtk_widget_show (window);
1304   else
1305     gtk_widget_destroy (window);
1306 }
1307
1308 /*
1309  * GtkEntry
1310  */
1311
1312 void entry_toggle_editable (GtkWidget *checkbutton,
1313                             GtkWidget *entry)
1314 {
1315    gtk_entry_set_editable(GTK_ENTRY(entry),
1316                           GTK_TOGGLE_BUTTON(checkbutton)->active);
1317 }
1318
1319 void
1320 create_entry ()
1321 {
1322   static GtkWidget *window = NULL;
1323   GtkWidget *box1;
1324   GtkWidget *box2;
1325   GtkWidget *editable_check;
1326   GtkWidget *entry, *cb;
1327   GtkWidget *button;
1328   GtkWidget *separator;
1329   GList *cbitems = NULL;
1330
1331   if (!window)
1332     {
1333       cbitems = g_list_append(cbitems, "item1");
1334       cbitems = g_list_append(cbitems, "item2");
1335       cbitems = g_list_append(cbitems, "and item3");
1336       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1337
1338       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1339                           GTK_SIGNAL_FUNC(destroy_window),
1340                           &window);
1341       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1342                           GTK_SIGNAL_FUNC(destroy_window),
1343                           &window);
1344
1345       gtk_window_set_title (GTK_WINDOW (window), "entry");
1346       gtk_container_border_width (GTK_CONTAINER (window), 0);
1347
1348
1349       box1 = gtk_vbox_new (FALSE, 0);
1350       gtk_container_add (GTK_CONTAINER (window), box1);
1351       gtk_widget_show (box1);
1352
1353
1354       box2 = gtk_vbox_new (FALSE, 10);
1355       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1356       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1357       gtk_widget_show (box2);
1358
1359       entry = gtk_entry_new ();
1360       gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
1361       gtk_entry_select_region (GTK_ENTRY (entry), 
1362                                0, GTK_ENTRY(entry)->text_length);
1363       gtk_box_pack_start (GTK_BOX (box2), entry, TRUE, TRUE, 0);
1364       gtk_widget_show (entry);
1365
1366       cb = gtk_combo_new ();
1367       gtk_combo_set_popdown_strings (GTK_COMBO (cb), cbitems);
1368       gtk_entry_set_text (GTK_ENTRY (GTK_COMBO(cb)->entry), "hello world");
1369       gtk_entry_select_region (GTK_ENTRY (GTK_COMBO(cb)->entry),
1370                                0, GTK_ENTRY(entry)->text_length);
1371       gtk_box_pack_start (GTK_BOX (box2), cb, TRUE, TRUE, 0);
1372       gtk_widget_show (cb);
1373
1374       editable_check = gtk_check_button_new_with_label("Editable");
1375       gtk_box_pack_start (GTK_BOX (box2), editable_check, TRUE, TRUE, 0);
1376       gtk_signal_connect (GTK_OBJECT(editable_check), "toggled",
1377                           GTK_SIGNAL_FUNC(entry_toggle_editable), entry);
1378       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(editable_check), TRUE);
1379       gtk_widget_show (editable_check);
1380
1381       separator = gtk_hseparator_new ();
1382       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1383       gtk_widget_show (separator);
1384
1385
1386       box2 = gtk_vbox_new (FALSE, 10);
1387       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1388       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1389       gtk_widget_show (box2);
1390
1391
1392       button = gtk_button_new_with_label ("close");
1393       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1394                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1395                                  GTK_OBJECT (window));
1396       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1397       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1398       gtk_widget_grab_default (button);
1399       gtk_widget_show (button);
1400     }
1401
1402   if (!GTK_WIDGET_VISIBLE (window))
1403     gtk_widget_show (window);
1404   /*  else
1405     gtk_widget_destroy (window); */
1406 }
1407
1408 /*
1409  * GtkList
1410  */
1411 void
1412 list_add (GtkWidget *widget,
1413           GtkWidget *list)
1414 {
1415   static int i = 1;
1416   gchar buffer[64];
1417   GtkWidget *list_item;
1418
1419   sprintf (buffer, "added item %d", i++);
1420   list_item = gtk_list_item_new_with_label (buffer);
1421   gtk_widget_show (list_item);
1422   gtk_container_add (GTK_CONTAINER (list), list_item);
1423 }
1424
1425 void
1426 list_remove (GtkWidget *widget,
1427              GtkWidget *list)
1428 {
1429   GList *tmp_list;
1430   GList *clear_list;
1431
1432   tmp_list = GTK_LIST (list)->selection;
1433   clear_list = NULL;
1434
1435   while (tmp_list)
1436     {
1437       clear_list = g_list_prepend (clear_list, tmp_list->data);
1438       tmp_list = tmp_list->next;
1439     }
1440
1441   clear_list = g_list_reverse (clear_list);
1442
1443   gtk_list_remove_items (GTK_LIST (list), clear_list);
1444
1445   g_list_free (clear_list);
1446 }
1447
1448 void
1449 create_list ()
1450 {
1451   static GtkWidget *window = NULL;
1452   static char *list_items[] =
1453   {
1454     "hello",
1455     "world",
1456     "blah",
1457     "foo",
1458     "bar",
1459     "argh",
1460     "spencer",
1461     "is a",
1462     "wussy",
1463     "programmer",
1464   };
1465   static int nlist_items = sizeof (list_items) / sizeof (list_items[0]);
1466
1467   GtkWidget *box1;
1468   GtkWidget *box2;
1469   GtkWidget *scrolled_win;
1470   GtkWidget *list;
1471   GtkWidget *list_item;
1472   GtkWidget *button;
1473   GtkWidget *separator;
1474   int i;
1475
1476   if (!window)
1477     {
1478       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1479
1480       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1481                           GTK_SIGNAL_FUNC(destroy_window),
1482                           &window);
1483       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1484                           GTK_SIGNAL_FUNC(destroy_window),
1485                           &window);
1486
1487       gtk_window_set_title (GTK_WINDOW (window), "list");
1488       gtk_container_border_width (GTK_CONTAINER (window), 0);
1489
1490
1491       box1 = gtk_vbox_new (FALSE, 0);
1492       gtk_container_add (GTK_CONTAINER (window), box1);
1493       gtk_widget_show (box1);
1494
1495
1496       box2 = gtk_vbox_new (FALSE, 10);
1497       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1498       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1499       gtk_widget_show (box2);
1500
1501
1502       scrolled_win = gtk_scrolled_window_new (NULL, NULL);
1503       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
1504                                       GTK_POLICY_AUTOMATIC, 
1505                                       GTK_POLICY_AUTOMATIC);
1506       gtk_box_pack_start (GTK_BOX (box2), scrolled_win, TRUE, TRUE, 0);
1507       gtk_widget_show (scrolled_win);
1508
1509       list = gtk_list_new ();
1510       gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_MULTIPLE);
1511       gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_BROWSE);
1512       gtk_container_add (GTK_CONTAINER (scrolled_win), list);
1513       gtk_widget_show (list);
1514
1515       for (i = 0; i < nlist_items; i++)
1516         {
1517           list_item = gtk_list_item_new_with_label (list_items[i]);
1518           gtk_container_add (GTK_CONTAINER (list), list_item);
1519           gtk_widget_show (list_item);
1520         }
1521
1522       button = gtk_button_new_with_label ("add");
1523       GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_FOCUS);
1524       gtk_signal_connect (GTK_OBJECT (button), "clicked",
1525                           GTK_SIGNAL_FUNC(list_add),
1526                           list);
1527       gtk_box_pack_start (GTK_BOX (box2), button, FALSE, TRUE, 0);
1528       gtk_widget_show (button);
1529
1530       button = gtk_button_new_with_label ("remove");
1531       GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_FOCUS);
1532       gtk_signal_connect (GTK_OBJECT (button), "clicked",
1533                           GTK_SIGNAL_FUNC(list_remove),
1534                           list);
1535       gtk_box_pack_start (GTK_BOX (box2), button, FALSE, TRUE, 0);
1536       gtk_widget_show (button);
1537
1538
1539       separator = gtk_hseparator_new ();
1540       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1541       gtk_widget_show (separator);
1542
1543
1544       box2 = gtk_vbox_new (FALSE, 10);
1545       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1546       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1547       gtk_widget_show (box2);
1548
1549
1550       button = gtk_button_new_with_label ("close");
1551       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1552                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1553                                  GTK_OBJECT (window));
1554       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1555       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1556       gtk_widget_grab_default (button);
1557       gtk_widget_show (button);
1558     }
1559
1560   if (!GTK_WIDGET_VISIBLE (window))
1561     gtk_widget_show (window);
1562   else
1563     gtk_widget_destroy (window);
1564 }
1565
1566 /*
1567  * GtkCList
1568  */
1569 #define TESTGTK_CLIST_COLUMNS 7
1570 static gint clist_rows = 0;
1571 static gint clist_selected_row = 0;
1572
1573 void
1574 add1000_clist (GtkWidget *widget, gpointer data)
1575 {
1576   gint i;
1577   char text[TESTGTK_CLIST_COLUMNS][50];
1578   char *texts[TESTGTK_CLIST_COLUMNS];
1579
1580   for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
1581     {
1582       texts[i] = text[i];
1583       sprintf (text[i], "Column %d", i);
1584     }
1585   
1586   sprintf (text[1], "Right");
1587   sprintf (text[2], "Center");
1588   
1589   gtk_clist_freeze (GTK_CLIST (data));
1590   for (i = 0; i < 1000; i++)
1591     {
1592       sprintf (text[0], "Row %d", clist_rows++);
1593       gtk_clist_append (GTK_CLIST (data), texts);
1594     }
1595   gtk_clist_thaw (GTK_CLIST (data));
1596
1597 }
1598
1599 void
1600 add10000_clist (GtkWidget *widget, gpointer data)
1601 {
1602   gint i;
1603   char text[TESTGTK_CLIST_COLUMNS][50];
1604   char *texts[TESTGTK_CLIST_COLUMNS];
1605
1606   for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
1607     {
1608       texts[i] = text[i];
1609       sprintf (text[i], "Column %d", i);
1610     }
1611   
1612   sprintf (text[1], "Right");
1613   sprintf (text[2], "Center");
1614   
1615   gtk_clist_freeze (GTK_CLIST (data));
1616   for (i = 0; i < 10000; i++)
1617     {
1618       sprintf (text[0], "Row %d", clist_rows++);
1619       gtk_clist_append (GTK_CLIST (data), texts);
1620     }
1621   gtk_clist_thaw (GTK_CLIST (data));
1622
1623 }
1624
1625 void
1626 clear_clist (GtkWidget *widget, gpointer data)
1627 {
1628   gtk_clist_clear (GTK_CLIST (data));
1629   clist_rows = 0;
1630 }
1631
1632 void
1633 remove_row_clist (GtkWidget *widget, gpointer data)
1634 {
1635   gtk_clist_remove (GTK_CLIST (data), clist_selected_row);
1636   clist_rows--;
1637 }
1638
1639 void
1640 show_titles_clist (GtkWidget *widget, gpointer data)
1641 {
1642   gtk_clist_column_titles_show (GTK_CLIST (data));
1643 }
1644
1645 void
1646 hide_titles_clist (GtkWidget *widget, gpointer data)
1647 {
1648   gtk_clist_column_titles_hide (GTK_CLIST (data));
1649 }
1650
1651 void
1652 select_clist (GtkWidget *widget,
1653               gint row, 
1654               gint column, 
1655               GdkEventButton *bevent)
1656 {
1657   gint button = 0;
1658
1659   if (bevent)
1660     button = bevent->button;
1661
1662   g_print ("GtkCList Selection: row %d column %d button %d\n", 
1663            row, column, button);
1664
1665   clist_selected_row = row;
1666 }
1667
1668 void
1669 list_selection_clist (GtkWidget *widget, gpointer data)
1670 {
1671   GList *list;
1672   GtkCListRow *clist_row;
1673   GtkCList *clist;
1674
1675 }
1676
1677 void
1678 create_clist ()
1679 {
1680   gint i;
1681   static GtkWidget *window = NULL;
1682
1683   static char *titles[] =
1684   {
1685     "Title 0",
1686     "Title 1",
1687     "Title 2",
1688     "Title 3",
1689     "Title 4",
1690     "Title 5",
1691     "Title 6"
1692   };
1693
1694   char text[TESTGTK_CLIST_COLUMNS][50];
1695   char *texts[TESTGTK_CLIST_COLUMNS];
1696
1697   GtkWidget *box1;
1698   GtkWidget *box2;
1699   GtkWidget *clist;
1700   GtkWidget *button;
1701   GtkWidget *separator;
1702
1703
1704   if (!window)
1705     {
1706       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1707
1708       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1709                           GTK_SIGNAL_FUNC(destroy_window),
1710                           &window);
1711       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1712                           GTK_SIGNAL_FUNC(destroy_window),
1713                           &window);
1714
1715       gtk_window_set_title (GTK_WINDOW (window), "clist");
1716       gtk_container_border_width (GTK_CONTAINER (window), 0);
1717
1718
1719       box1 = gtk_vbox_new (FALSE, 0);
1720       gtk_container_add (GTK_CONTAINER (window), box1);
1721       gtk_widget_show (box1);
1722
1723
1724       box2 = gtk_hbox_new (FALSE, 10);
1725       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1726       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
1727       gtk_widget_show (box2);
1728
1729       /* create GtkCList here so we have a pointer to throw at the 
1730        * button callbacks -- more is done with it later */
1731       clist = gtk_clist_new_with_titles (TESTGTK_CLIST_COLUMNS, titles);
1732
1733       /* control buttons */
1734       button = gtk_button_new_with_label ("Add 1,000 Rows");
1735       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1736
1737       gtk_signal_connect (GTK_OBJECT (button),
1738                           "clicked",
1739                           (GtkSignalFunc) add1000_clist,
1740                           (gpointer) clist);
1741
1742       gtk_widget_show (button);
1743
1744
1745       button = gtk_button_new_with_label ("Add 10,000 Rows");
1746       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1747
1748       gtk_signal_connect (GTK_OBJECT (button),
1749                           "clicked",
1750                           (GtkSignalFunc) add10000_clist,
1751                           (gpointer) clist);
1752
1753       gtk_widget_show (button);
1754
1755       button = gtk_button_new_with_label ("Clear List");
1756       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1757
1758       gtk_signal_connect (GTK_OBJECT (button),
1759                           "clicked",
1760                           (GtkSignalFunc) clear_clist,
1761                           (gpointer) clist);
1762
1763       gtk_widget_show (button);
1764
1765       button = gtk_button_new_with_label ("Remove Row");
1766       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1767
1768       gtk_signal_connect (GTK_OBJECT (button),
1769                           "clicked",
1770                           (GtkSignalFunc) remove_row_clist,
1771                           (gpointer) clist);
1772
1773       gtk_widget_show (button);
1774
1775       /* second layer of buttons */
1776       box2 = gtk_hbox_new (FALSE, 10);
1777       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1778       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
1779       gtk_widget_show (box2);
1780
1781       button = gtk_button_new_with_label ("Show Title Buttons");
1782       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1783
1784       gtk_signal_connect (GTK_OBJECT (button),
1785                           "clicked",
1786                           (GtkSignalFunc) show_titles_clist,
1787                           (gpointer) clist);
1788
1789       gtk_widget_show (button);
1790
1791       button = gtk_button_new_with_label ("Hide Title Buttons");
1792       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1793
1794       gtk_signal_connect (GTK_OBJECT (button),
1795                           "clicked",
1796                           (GtkSignalFunc) hide_titles_clist,
1797                           (gpointer) clist);
1798
1799       gtk_widget_show (button);
1800
1801       /* vbox for the list itself */
1802       box2 = gtk_vbox_new (FALSE, 10);
1803       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1804       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1805       gtk_widget_show (box2);
1806
1807       /* 
1808        * the rest of the clist configuration
1809        */
1810       gtk_clist_set_row_height (GTK_CLIST (clist), 20);
1811       
1812       gtk_signal_connect (GTK_OBJECT (clist), 
1813                           "select_row",
1814                           (GtkSignalFunc) select_clist, 
1815                           NULL);
1816
1817       gtk_clist_set_column_width (GTK_CLIST (clist), 0, 100);
1818
1819       for (i = 1; i < TESTGTK_CLIST_COLUMNS; i++)
1820         gtk_clist_set_column_width (GTK_CLIST (clist), i, 80);
1821
1822       gtk_clist_set_selection_mode (GTK_CLIST (clist), GTK_SELECTION_BROWSE);
1823
1824       gtk_clist_set_policy (GTK_CLIST (clist), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1825
1826       gtk_clist_set_column_justification (GTK_CLIST (clist), 1, GTK_JUSTIFY_RIGHT);
1827       gtk_clist_set_column_justification (GTK_CLIST (clist), 2, GTK_JUSTIFY_CENTER);
1828       
1829       for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
1830         {
1831           texts[i] = text[i];
1832           sprintf (text[i], "Column %d", i);
1833         }
1834
1835       sprintf (text[1], "Right");
1836       sprintf (text[2], "Center");
1837
1838       for (i = 0; i < 100; i++)
1839         {
1840           sprintf (text[0], "Row %d", clist_rows++);
1841           gtk_clist_append (GTK_CLIST (clist), texts);
1842         }
1843
1844       gtk_container_border_width (GTK_CONTAINER (clist), 5);
1845       gtk_box_pack_start (GTK_BOX (box2), clist, TRUE, TRUE, 0);
1846       gtk_widget_show (clist);
1847
1848
1849       separator = gtk_hseparator_new ();
1850       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1851       gtk_widget_show (separator);
1852
1853       box2 = gtk_vbox_new (FALSE, 10);
1854       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1855       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1856       gtk_widget_show (box2);
1857
1858       button = gtk_button_new_with_label ("close");
1859       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1860                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
1861                                  GTK_OBJECT (window));
1862
1863       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1864       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1865       gtk_widget_grab_default (button);
1866
1867       gtk_widget_show (button);
1868     }
1869
1870   if (!GTK_WIDGET_VISIBLE (window))
1871     gtk_widget_show (window);
1872   else
1873     gtk_widget_destroy (window);
1874
1875 }
1876
1877 /*
1878  * GtkColorSelect
1879  */
1880 void
1881 color_selection_ok (GtkWidget               *w,
1882                     GtkColorSelectionDialog *cs)
1883 {
1884   GtkColorSelection *colorsel;
1885   gdouble color[4];
1886
1887   colorsel=GTK_COLOR_SELECTION(cs->colorsel);
1888
1889   gtk_color_selection_get_color(colorsel,color);
1890   gtk_color_selection_set_color(colorsel,color);
1891 }
1892
1893 void
1894 color_selection_changed (GtkWidget *w,
1895                          GtkColorSelectionDialog *cs)
1896 {
1897   GtkColorSelection *colorsel;
1898   gdouble color[4];
1899
1900   colorsel=GTK_COLOR_SELECTION(cs->colorsel);
1901   gtk_color_selection_get_color(colorsel,color);
1902 }
1903
1904 void
1905 create_color_selection ()
1906 {
1907   static GtkWidget *window = NULL;
1908
1909   if (!window)
1910     {
1911       gtk_preview_set_install_cmap (TRUE);
1912       gtk_widget_push_visual (gtk_preview_get_visual ());
1913       gtk_widget_push_colormap (gtk_preview_get_cmap ());
1914
1915       window = gtk_color_selection_dialog_new ("color selection dialog");
1916
1917       gtk_color_selection_set_opacity (
1918         GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (window)->colorsel),
1919         TRUE);
1920
1921       gtk_color_selection_set_update_policy(
1922         GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (window)->colorsel),
1923         GTK_UPDATE_CONTINUOUS);
1924
1925       gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
1926
1927       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1928                           GTK_SIGNAL_FUNC(destroy_window),
1929                           &window);
1930       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1931                           GTK_SIGNAL_FUNC(destroy_window),
1932                           &window);
1933
1934       gtk_signal_connect (
1935         GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->colorsel),
1936         "color_changed",
1937         GTK_SIGNAL_FUNC(color_selection_changed),
1938         window);
1939
1940       gtk_signal_connect (
1941         GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->ok_button),
1942         "clicked",
1943         GTK_SIGNAL_FUNC(color_selection_ok),
1944         window);
1945
1946       gtk_signal_connect_object (
1947         GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->cancel_button),
1948         "clicked",
1949         GTK_SIGNAL_FUNC(gtk_widget_destroy),
1950         GTK_OBJECT (window));
1951
1952       gtk_widget_pop_colormap ();
1953       gtk_widget_pop_visual ();
1954     }
1955
1956   if (!GTK_WIDGET_VISIBLE (window))
1957     gtk_widget_show (window);
1958   else
1959     gtk_widget_destroy (window);
1960 }
1961
1962
1963 void
1964 file_selection_ok (GtkWidget        *w,
1965                    GtkFileSelection *fs)
1966 {
1967   g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
1968   gtk_widget_destroy (fs);
1969 }
1970
1971 void
1972 create_file_selection ()
1973 {
1974   static GtkWidget *window = NULL;
1975
1976   if (!window)
1977     {
1978       window = gtk_file_selection_new ("file selection dialog");
1979       gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
1980
1981       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1982                           GTK_SIGNAL_FUNC(destroy_window),
1983                           &window);
1984       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
1985                           GTK_SIGNAL_FUNC(destroy_window),
1986                           &window);
1987
1988       gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (window)->ok_button),
1989                           "clicked", GTK_SIGNAL_FUNC(file_selection_ok),
1990                           window);
1991       gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (window)->cancel_button),
1992                                  "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
1993                                  GTK_OBJECT (window));
1994     }
1995
1996   if (!GTK_WIDGET_VISIBLE (window))
1997     gtk_widget_show (window);
1998   else
1999     gtk_widget_destroy (window);
2000 }
2001
2002
2003 /*
2004  * GtkDialog
2005  */
2006 static GtkWidget *dialog_window = NULL;
2007
2008 void
2009 label_toggle (GtkWidget  *widget,
2010               GtkWidget **label)
2011 {
2012   if (!(*label))
2013     {
2014       *label = gtk_label_new ("Dialog Test");
2015       gtk_signal_connect (GTK_OBJECT (*label),
2016                           "destroy",
2017                           GTK_SIGNAL_FUNC (gtk_widget_destroyed),
2018                           label);
2019       gtk_misc_set_padding (GTK_MISC (*label), 10, 10);
2020       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox), 
2021                           *label, TRUE, TRUE, 0);
2022       gtk_widget_show (*label);
2023     }
2024   else
2025     gtk_widget_destroy (*label);
2026 }
2027
2028 void
2029 create_dialog ()
2030 {
2031   static GtkWidget *label;
2032   GtkWidget *button;
2033
2034   if (!dialog_window)
2035     {
2036       dialog_window = gtk_dialog_new ();
2037
2038       gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy",
2039                           GTK_SIGNAL_FUNC(destroy_window),
2040                           &dialog_window);
2041       gtk_signal_connect (GTK_OBJECT (dialog_window), "delete_event",
2042                           GTK_SIGNAL_FUNC(destroy_window),
2043                           &dialog_window);
2044
2045       gtk_window_set_title (GTK_WINDOW (dialog_window), "dialog");
2046       gtk_container_border_width (GTK_CONTAINER (dialog_window), 0);
2047
2048       button = gtk_button_new_with_label ("OK");
2049       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2050       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area), 
2051                           button, TRUE, TRUE, 0);
2052       gtk_widget_grab_default (button);
2053       gtk_widget_show (button);
2054
2055       button = gtk_button_new_with_label ("Toggle");
2056       gtk_signal_connect (GTK_OBJECT (button), "clicked",
2057                           GTK_SIGNAL_FUNC (label_toggle),
2058                           &label);
2059       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2060       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area),
2061                           button, TRUE, TRUE, 0);
2062       gtk_widget_show (button);
2063
2064       label = NULL;
2065     }
2066
2067   if (!GTK_WIDGET_VISIBLE (dialog_window))
2068     gtk_widget_show (dialog_window);
2069   else
2070     gtk_widget_destroy (dialog_window);
2071 }
2072
2073
2074 /*
2075  * GtkRange
2076  */
2077 void
2078 create_range_controls ()
2079 {
2080   static GtkWidget *window = NULL;
2081   GtkWidget *box1;
2082   GtkWidget *box2;
2083   GtkWidget *button;
2084   GtkWidget *scrollbar;
2085   GtkWidget *scale;
2086   GtkWidget *separator;
2087   GtkObject *adjustment;
2088
2089   if (!window)
2090     {
2091       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2092
2093       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2094                           GTK_SIGNAL_FUNC(destroy_window),
2095                           &window);
2096       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2097                           GTK_SIGNAL_FUNC(destroy_window),
2098                           &window);
2099
2100       gtk_window_set_title (GTK_WINDOW (window), "range controls");
2101       gtk_container_border_width (GTK_CONTAINER (window), 0);
2102
2103
2104       box1 = gtk_vbox_new (FALSE, 0);
2105       gtk_container_add (GTK_CONTAINER (window), box1);
2106       gtk_widget_show (box1);
2107
2108
2109       box2 = gtk_vbox_new (FALSE, 10);
2110       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2111       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2112       gtk_widget_show (box2);
2113
2114
2115       adjustment = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
2116
2117       scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
2118       gtk_widget_set_usize (GTK_WIDGET (scale), 150, 30);
2119       gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
2120       gtk_scale_set_digits (GTK_SCALE (scale), 1);
2121       gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
2122       gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
2123       gtk_widget_show (scale);
2124
2125       scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (adjustment));
2126       gtk_range_set_update_policy (GTK_RANGE (scrollbar), 
2127                                    GTK_UPDATE_CONTINUOUS);
2128       gtk_box_pack_start (GTK_BOX (box2), scrollbar, TRUE, TRUE, 0);
2129       gtk_widget_show (scrollbar);
2130
2131
2132       separator = gtk_hseparator_new ();
2133       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2134       gtk_widget_show (separator);
2135
2136
2137       box2 = gtk_vbox_new (FALSE, 10);
2138       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2139       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2140       gtk_widget_show (box2);
2141
2142
2143       button = gtk_button_new_with_label ("close");
2144       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2145                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2146                                  GTK_OBJECT (window));
2147       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2148       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2149       gtk_widget_grab_default (button);
2150       gtk_widget_show (button);
2151     }
2152
2153   if (!GTK_WIDGET_VISIBLE (window))
2154     gtk_widget_show (window);
2155   else
2156     gtk_widget_destroy (window);
2157 }
2158
2159
2160 /*
2161  * GtkRulers
2162  */
2163 void
2164 create_rulers ()
2165 {
2166   static GtkWidget *window = NULL;
2167   GtkWidget *table;
2168   GtkWidget *ruler;
2169
2170   if (!window)
2171     {
2172       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2173
2174       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2175                           GTK_SIGNAL_FUNC(destroy_window),
2176                           &window);
2177       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2178                           GTK_SIGNAL_FUNC(destroy_window),
2179                           &window);
2180
2181       gtk_window_set_title (GTK_WINDOW (window), "rulers");
2182       gtk_widget_set_usize (window, 300, 300);
2183       gtk_widget_set_events (window, 
2184                              GDK_POINTER_MOTION_MASK 
2185                              | GDK_POINTER_MOTION_HINT_MASK);
2186       gtk_container_border_width (GTK_CONTAINER (window), 0);
2187
2188       table = gtk_table_new (2, 2, FALSE);
2189       gtk_container_add (GTK_CONTAINER (window), table);
2190       gtk_widget_show (table);
2191
2192       ruler = gtk_hruler_new ();
2193       gtk_ruler_set_range (GTK_RULER (ruler), 5, 15, 0, 20);
2194
2195       gtk_signal_connect_object (
2196         GTK_OBJECT (window), 
2197         "motion_notify_event",
2198         GTK_SIGNAL_FUNC(
2199           GTK_WIDGET_CLASS (GTK_OBJECT (ruler)->klass)->motion_notify_event),
2200         GTK_OBJECT (ruler));
2201
2202       gtk_table_attach (GTK_TABLE (table), ruler, 1, 2, 0, 1,
2203                         GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
2204       gtk_widget_show (ruler);
2205
2206
2207       ruler = gtk_vruler_new ();
2208       gtk_ruler_set_range (GTK_RULER (ruler), 5, 15, 0, 20);
2209
2210       gtk_signal_connect_object (
2211         GTK_OBJECT (window), 
2212         "motion_notify_event",
2213         GTK_SIGNAL_FUNC (GTK_WIDGET_CLASS (GTK_OBJECT (ruler)->klass)->motion_notify_event),
2214         GTK_OBJECT (ruler));
2215
2216       gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 2,
2217                         GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2218       gtk_widget_show (ruler);
2219     }
2220
2221   if (!GTK_WIDGET_VISIBLE (window))
2222     gtk_widget_show (window);
2223   else
2224     gtk_widget_destroy (window);
2225 }
2226
2227
2228 /*
2229  * GtkText
2230  */
2231 void
2232 create_text ()
2233 {
2234   static GtkWidget *window = NULL;
2235   GtkWidget *box1;
2236   GtkWidget *box2;
2237   GtkWidget *button;
2238   GtkWidget *separator;
2239   GtkWidget *table;
2240   GtkWidget *hscrollbar;
2241   GtkWidget *vscrollbar;
2242   GtkWidget *text;
2243
2244   if (!window)
2245     {
2246       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2247       gtk_widget_set_name (window, "text window");
2248
2249       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2250                           GTK_SIGNAL_FUNC(destroy_window),
2251                           &window);
2252       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2253                           GTK_SIGNAL_FUNC(destroy_window),
2254                           &window);
2255
2256       gtk_window_set_title (GTK_WINDOW (window), "test");
2257       gtk_container_border_width (GTK_CONTAINER (window), 0);
2258
2259
2260       box1 = gtk_vbox_new (FALSE, 0);
2261       gtk_container_add (GTK_CONTAINER (window), box1);
2262       gtk_widget_show (box1);
2263
2264
2265       box2 = gtk_vbox_new (FALSE, 10);
2266       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2267       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2268       gtk_widget_show (box2);
2269
2270
2271       table = gtk_table_new (2, 2, FALSE);
2272       gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
2273       gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
2274       gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
2275       gtk_widget_show (table);
2276
2277       text = gtk_text_new (NULL, NULL);
2278       gtk_text_set_editable (GTK_TEXT (text), TRUE);
2279       gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
2280       gtk_widget_show (text);
2281
2282       hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
2283       gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
2284                         GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
2285       gtk_widget_show (hscrollbar);
2286
2287       vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
2288       gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
2289                         GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2290       gtk_widget_show (vscrollbar);
2291
2292       gtk_text_freeze (GTK_TEXT (text));
2293
2294       gtk_widget_realize (text);
2295
2296       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2297                        "spencer blah blah blah\n", -1);
2298       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2299                        "kimball\n", -1);
2300       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2301                        "is\n", -1);
2302       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2303                        "a\n", -1);
2304       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2305                        "wuss.\n", -1);
2306       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2307                        "but\n", -1);
2308       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
2309                        "josephine\n", -1);
2310       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2311                        "(his\n", -1);
2312       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2313                        "girlfriend\n", -1);
2314       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2315                        "is\n", -1);
2316       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2317                        "not).\n", -1);
2318       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2319                        "why?\n", -1);
2320       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2321                        "because\n", -1);
2322       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2323                        "spencer\n", -1);
2324       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2325                        "puked\n", -1);
2326       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2327                        "last\n", -1);
2328       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2329                        "night\n", -1);
2330       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2331                        "but\n", -1);
2332       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2333                        "josephine\n", -1);
2334       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2335                        "did\n", -1);
2336       gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, 
2337                        "not", -1);
2338
2339       gtk_text_thaw (GTK_TEXT (text));
2340
2341       separator = gtk_hseparator_new ();
2342       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2343       gtk_widget_show (separator);
2344
2345
2346       box2 = gtk_vbox_new (FALSE, 10);
2347       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2348       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2349       gtk_widget_show (box2);
2350
2351
2352       button = gtk_button_new_with_label ("close");
2353       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2354                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2355                                  GTK_OBJECT (window));
2356       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2357       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2358       gtk_widget_grab_default (button);
2359       gtk_widget_show (button);
2360     }
2361
2362   if (!GTK_WIDGET_VISIBLE (window))
2363     gtk_widget_show (window);
2364   else
2365     gtk_widget_destroy (window);
2366 }
2367
2368
2369 /*
2370  * GtkNotebook
2371  */
2372 void
2373 rotate_notebook (GtkButton   *button,
2374                  GtkNotebook *notebook)
2375 {
2376   gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos + 1) % 4);
2377 }
2378
2379 void
2380 create_notebook ()
2381 {
2382   static GtkWidget *window = NULL;
2383   GtkWidget *box1;
2384   GtkWidget *box2;
2385   GtkWidget *button;
2386   GtkWidget *separator;
2387   GtkWidget *notebook;
2388   GtkWidget *frame;
2389   GtkWidget *label;
2390   char buffer[32];
2391   int i;
2392
2393   if (!window)
2394     {
2395       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2396
2397       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2398                           GTK_SIGNAL_FUNC(destroy_window),
2399                           &window);
2400       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2401                           GTK_SIGNAL_FUNC(destroy_window),
2402                           &window);
2403
2404       gtk_window_set_title (GTK_WINDOW (window), "notebook");
2405       gtk_container_border_width (GTK_CONTAINER (window), 0);
2406
2407
2408       box1 = gtk_vbox_new (FALSE, 0);
2409       gtk_container_add (GTK_CONTAINER (window), box1);
2410       gtk_widget_show (box1);
2411
2412
2413       box2 = gtk_vbox_new (FALSE, 10);
2414       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2415       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2416       gtk_widget_show (box2);
2417
2418
2419       notebook = gtk_notebook_new ();
2420       gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
2421       gtk_box_pack_start (GTK_BOX (box2), notebook, TRUE, TRUE, 0);
2422       gtk_widget_show (notebook);
2423
2424
2425       for (i = 0; i < 5; i++)
2426         {
2427           sprintf (buffer, "Page %d", i+1);
2428
2429           frame = gtk_frame_new (buffer);
2430           gtk_container_border_width (GTK_CONTAINER (frame), 10);
2431           gtk_widget_set_usize (frame, 200, 150);
2432           gtk_widget_show (frame);
2433
2434           label = gtk_label_new (buffer);
2435           gtk_container_add (GTK_CONTAINER (frame), label);
2436           gtk_widget_show (label);
2437
2438           label = gtk_label_new (buffer);
2439           gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
2440         }
2441
2442
2443       separator = gtk_hseparator_new ();
2444       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2445       gtk_widget_show (separator);
2446
2447
2448       box2 = gtk_hbox_new (FALSE, 10);
2449       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2450       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2451       gtk_widget_show (box2);
2452
2453
2454       button = gtk_button_new_with_label ("close");
2455       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2456                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2457                                  GTK_OBJECT (window));
2458       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2459       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2460       gtk_widget_grab_default (button);
2461       gtk_widget_show (button);
2462
2463       button = gtk_button_new_with_label ("next");
2464       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2465                                  GTK_SIGNAL_FUNC(gtk_notebook_next_page),
2466                                  GTK_OBJECT (notebook));
2467       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2468       gtk_widget_show (button);
2469
2470       button = gtk_button_new_with_label ("prev");
2471       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2472                                  GTK_SIGNAL_FUNC(gtk_notebook_prev_page),
2473                                  GTK_OBJECT (notebook));
2474       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2475       gtk_widget_show (button);
2476
2477       button = gtk_button_new_with_label ("rotate");
2478       gtk_signal_connect (GTK_OBJECT (button), "clicked",
2479                           GTK_SIGNAL_FUNC(rotate_notebook),
2480                           notebook);
2481       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2482       gtk_widget_show (button);
2483     }
2484
2485   if (!GTK_WIDGET_VISIBLE (window))
2486     gtk_widget_show (window);
2487   else
2488     gtk_widget_destroy (window);
2489 }
2490
2491
2492 /*
2493  * GtkPanes
2494  */
2495 void
2496 create_panes ()
2497 {
2498   static GtkWidget *window = NULL;
2499   GtkWidget *frame;
2500   GtkWidget *hpaned;
2501   GtkWidget *vpaned;
2502
2503   if (!window)
2504     {
2505       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2506
2507       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2508                           GTK_SIGNAL_FUNC(destroy_window),
2509                           &window);
2510       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2511                           GTK_SIGNAL_FUNC(destroy_window),
2512                           &window);
2513
2514       gtk_window_set_title (GTK_WINDOW (window), "Panes");
2515       gtk_container_border_width (GTK_CONTAINER (window), 0);
2516
2517       vpaned = gtk_vpaned_new ();
2518       gtk_container_add (GTK_CONTAINER (window), vpaned);
2519       gtk_container_border_width (GTK_CONTAINER(vpaned), 5);
2520       gtk_widget_show (vpaned);
2521
2522       hpaned = gtk_hpaned_new ();
2523       gtk_paned_add1 (GTK_PANED (vpaned), hpaned);
2524
2525       frame = gtk_frame_new (NULL);
2526       gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
2527       gtk_widget_set_usize (frame, 60, 60);
2528       gtk_paned_add1 (GTK_PANED (hpaned), frame);
2529       gtk_widget_show (frame);
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, 80, 60);
2534       gtk_paned_add2 (GTK_PANED (hpaned), frame);
2535       gtk_widget_show (frame);
2536
2537       gtk_widget_show (hpaned);
2538
2539       frame = gtk_frame_new (NULL);
2540       gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
2541       gtk_widget_set_usize (frame, 60, 80);
2542       gtk_paned_add2 (GTK_PANED (vpaned), frame);
2543       gtk_widget_show (frame);
2544     }
2545
2546   if (!GTK_WIDGET_VISIBLE (window))
2547     gtk_widget_show (window);
2548   else
2549     gtk_widget_destroy (window);
2550 }
2551
2552
2553 /*
2554  * Drag -N- Drop
2555  */
2556
2557 gboolean
2558 dnd_drop_destroy_popup (GtkWidget *widget, GtkWindow **window)
2559 {
2560   if(GTK_IS_BUTTON(widget)) /* I.e. they clicked the close button */
2561     gtk_widget_destroy(GTK_WIDGET(*window));
2562   else {
2563     gtk_grab_remove(GTK_WIDGET(*window));
2564     *window = NULL;
2565   }
2566   return TRUE;
2567 }
2568
2569 void
2570 dnd_drop (GtkWidget *button, GdkEvent *event)
2571 {
2572   static GtkWidget *window = NULL;
2573   GtkWidget *vbox, *lbl, *btn;
2574   gchar *msg;
2575
2576   window = gtk_window_new(GTK_WINDOW_DIALOG);
2577   gtk_container_border_width (GTK_CONTAINER(window), 10);
2578
2579   gtk_signal_connect (GTK_OBJECT (window), "destroy",
2580                       GTK_SIGNAL_FUNC(dnd_drop_destroy_popup),
2581                       &window);
2582   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2583                       GTK_SIGNAL_FUNC(dnd_drop_destroy_popup),
2584                       &window);
2585
2586   vbox = gtk_vbox_new(FALSE, 5);
2587
2588   /* Display message that we got from drop source */
2589   msg = g_malloc(strlen(event->dropdataavailable.data)
2590                  + strlen(event->dropdataavailable.data_type) + 100);
2591   sprintf(msg, "Drop data of type %s was:\n\n%s",
2592           event->dropdataavailable.data_type,
2593           (char *)event->dropdataavailable.data);
2594   lbl = gtk_label_new(msg);
2595   gtk_label_set_justify(GTK_LABEL(lbl), GTK_JUSTIFY_FILL);
2596   g_free(msg);
2597   gtk_widget_show(lbl);
2598   gtk_box_pack_start_defaults(GTK_BOX(vbox), lbl);
2599
2600   /* Provide an obvious way out of this heinousness */
2601   btn = gtk_button_new_with_label("Continue with life in\nspite of this oppression");
2602   gtk_signal_connect (GTK_OBJECT (btn), "clicked",
2603                       GTK_SIGNAL_FUNC(dnd_drop_destroy_popup),
2604                       &window);
2605   gtk_widget_show(btn);
2606   gtk_box_pack_start_defaults(GTK_BOX(vbox), btn);
2607
2608   gtk_container_add(GTK_CONTAINER(window), vbox);
2609
2610   gtk_widget_show(vbox);
2611   gtk_grab_add(window);
2612   gtk_widget_show(window);
2613 }
2614
2615 void
2616 dnd_drag_request (GtkWidget *button, GdkEvent *event)
2617 {
2618 #define DND_STRING "Bill Gates demands royalties for\nyour use of his innovation."
2619   gtk_widget_dnd_data_set (button, event, DND_STRING, strlen(DND_STRING) + 1);
2620 }
2621
2622 void
2623 create_dnd ()
2624 {
2625   static GtkWidget *window = NULL;
2626   GtkWidget *box1;
2627   GtkWidget *box2;
2628   GtkWidget *box3;
2629   GtkWidget *frame;
2630   GtkWidget *button;
2631   GtkWidget *separator;
2632
2633   /* For clarity... */
2634   char *possible_drag_types[] = {"text/plain"};
2635   char *accepted_drop_types[] = {"text/plain"};
2636
2637   if (!window)
2638     {
2639       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2640
2641       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2642                           GTK_SIGNAL_FUNC(destroy_window),
2643                           &window);
2644       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2645                           GTK_SIGNAL_FUNC(destroy_window),
2646                           &window);
2647
2648       gtk_window_set_title (GTK_WINDOW (window), "Drag -N- Drop");
2649       gtk_container_border_width (GTK_CONTAINER (window), 0);
2650
2651       box1 = gtk_vbox_new (FALSE, 0);
2652       gtk_container_add (GTK_CONTAINER (window), box1);
2653       gtk_widget_show (box1);
2654
2655       box2 = gtk_hbox_new (FALSE, 5);
2656       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2657       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
2658       gtk_widget_show (box2);
2659
2660       frame = gtk_frame_new ("Drag");
2661       gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0);
2662       gtk_widget_show (frame);
2663
2664       box3 = gtk_vbox_new (FALSE, 5);
2665       gtk_container_border_width (GTK_CONTAINER (box3), 5);
2666       gtk_container_add (GTK_CONTAINER (frame), box3);
2667       gtk_widget_show (box3);
2668
2669       /*
2670        * FROM Button
2671        */
2672       button = gtk_button_new_with_label ("Drag me!");
2673       gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0);
2674       gtk_widget_show (button);
2675
2676       /*
2677        * currently, the widget has to be realized to
2678        * set dnd on it, this needs to change
2679        */
2680       gtk_widget_realize (button);
2681       gtk_signal_connect (GTK_OBJECT (button),
2682                           "drag_request_event",
2683                           GTK_SIGNAL_FUNC(dnd_drag_request),
2684                           button);
2685       
2686       gtk_widget_dnd_drag_set (button, TRUE, possible_drag_types, 1);
2687
2688
2689       frame = gtk_frame_new ("Drop");
2690       gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0);
2691       gtk_widget_show (frame);
2692
2693       box3 = gtk_vbox_new (FALSE, 5);
2694       gtk_container_border_width (GTK_CONTAINER (box3), 5);
2695       gtk_container_add (GTK_CONTAINER (frame), box3);
2696       gtk_widget_show (box3);
2697
2698
2699       /*
2700        * TO Button
2701        */
2702       button = gtk_button_new_with_label ("To");
2703       gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0);
2704       gtk_widget_show (button);
2705
2706       gtk_widget_realize (button);
2707       gtk_signal_connect (GTK_OBJECT (button), 
2708                           "drop_data_available_event",
2709                           GTK_SIGNAL_FUNC(dnd_drop),
2710                           button);
2711
2712       gtk_widget_dnd_drop_set (button, TRUE, accepted_drop_types, 1, FALSE);
2713
2714
2715       separator = gtk_hseparator_new ();
2716       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
2717       gtk_widget_show (separator);
2718
2719
2720       box2 = gtk_vbox_new (FALSE, 10);
2721       gtk_container_border_width (GTK_CONTAINER (box2), 10);
2722       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
2723       gtk_widget_show (box2);
2724
2725
2726       button = gtk_button_new_with_label ("close");
2727
2728       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2729                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2730                                  GTK_OBJECT (window));
2731
2732       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
2733       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2734       gtk_widget_grab_default (button);
2735       gtk_widget_show (button);
2736     }
2737
2738   if (!GTK_WIDGET_VISIBLE (window))
2739     gtk_widget_show (window);
2740   else
2741     gtk_widget_destroy (window);
2742 }
2743
2744 /*
2745  * Shaped Windows
2746  */
2747 static GdkWindow *root_win = NULL;
2748 static GtkWidget *modeller = NULL;
2749 static GtkWidget *sheets = NULL;
2750 static GtkWidget *rings = NULL;
2751
2752 typedef struct _cursoroffset {gint x,y;} CursorOffset;
2753
2754 static void
2755 shape_pressed (GtkWidget *widget, GdkEventButton *event)
2756 {
2757   CursorOffset *p;
2758
2759   /* ignore double and triple click */
2760   if (event->type != GDK_BUTTON_PRESS)
2761     return;
2762
2763   p = gtk_object_get_user_data (GTK_OBJECT(widget));
2764   p->x = (int) event->x;
2765   p->y = (int) event->y;
2766
2767   gtk_grab_add (widget);
2768   gdk_pointer_grab (widget->window, TRUE,
2769                     GDK_BUTTON_RELEASE_MASK |
2770                     GDK_BUTTON_MOTION_MASK,
2771                     NULL, NULL, 0);
2772 }
2773
2774
2775 static void
2776 shape_released (GtkWidget *widget)
2777 {
2778   gtk_grab_remove (widget);
2779   gdk_pointer_ungrab (0);
2780 }
2781
2782 static void
2783 shape_motion (GtkWidget      *widget, 
2784               GdkEventMotion *event)
2785 {
2786   gint xp, yp;
2787   CursorOffset * p;
2788   GdkModifierType mask;
2789
2790   p = gtk_object_get_user_data (GTK_OBJECT (widget));
2791
2792   gdk_window_get_pointer (root_win, &xp, &yp, &mask);
2793   gtk_widget_set_uposition (widget, xp  - p->x, yp  - p->y);
2794 }
2795
2796 GtkWidget *
2797 shape_create_icon (char     *xpm_file,
2798                    gint      x,
2799                    gint      y,
2800                    gint      px,
2801                    gint      py,
2802                    gint      window_type)
2803 {
2804   GtkWidget *window;
2805   GtkWidget *pixmap;
2806   GtkWidget *fixed;
2807   CursorOffset* icon_pos;
2808   GdkGC* gc;
2809   GdkBitmap *gdk_pixmap_mask;
2810   GdkPixmap *gdk_pixmap;
2811   GtkStyle *style;
2812
2813   style = gtk_widget_get_default_style ();
2814   gc = style->black_gc; 
2815
2816   /*
2817    * GDK_WINDOW_TOPLEVEL works also, giving you a title border
2818    */
2819   window = gtk_window_new (window_type);
2820   
2821   fixed = gtk_fixed_new ();
2822   gtk_widget_set_usize (fixed, 100,100);
2823   gtk_container_add (GTK_CONTAINER (window), fixed);
2824   gtk_widget_show (fixed);
2825   
2826   gdk_pixmap = gdk_pixmap_create_from_xpm (window->window, &gdk_pixmap_mask, 
2827                                            &style->bg[GTK_STATE_NORMAL],
2828                                            xpm_file);
2829
2830   pixmap = gtk_pixmap_new (gdk_pixmap, gdk_pixmap_mask);
2831   gtk_fixed_put (GTK_FIXED (fixed), pixmap, px,py);
2832   gtk_widget_show (pixmap);
2833   
2834   gtk_widget_shape_combine_mask (window, gdk_pixmap_mask, px,py);
2835
2836   gtk_widget_set_events (window, 
2837                          gtk_widget_get_events (window) |
2838                          GDK_BUTTON_MOTION_MASK |
2839                          GDK_BUTTON_PRESS_MASK);
2840
2841   gtk_signal_connect (GTK_OBJECT (window), "button_press_event",
2842                       GTK_SIGNAL_FUNC (shape_pressed),NULL);
2843   gtk_signal_connect (GTK_OBJECT (window), "button_release_event",
2844                       GTK_SIGNAL_FUNC (shape_released),NULL);
2845   gtk_signal_connect (GTK_OBJECT (window), "motion_notify_event",
2846                       GTK_SIGNAL_FUNC (shape_motion),NULL);
2847
2848   icon_pos = g_new (CursorOffset, 1);
2849   gtk_object_set_user_data(GTK_OBJECT(window), icon_pos);
2850
2851   gtk_widget_set_uposition (window, x, y);
2852   gtk_widget_show (window);
2853
2854   return window;
2855 }
2856
2857 void 
2858 create_shapes ()
2859 {
2860   root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
2861
2862   if (!modeller)
2863     {
2864       modeller = shape_create_icon ("Modeller.xpm",
2865                                     440, 140, 0,0, GTK_WINDOW_POPUP);
2866
2867       gtk_signal_connect (GTK_OBJECT (modeller), "destroy",
2868                           GTK_SIGNAL_FUNC(destroy_window),
2869                           &modeller);
2870       gtk_signal_connect (GTK_OBJECT (modeller), "delete_event",
2871                           GTK_SIGNAL_FUNC(destroy_window),
2872                           &modeller);
2873     }
2874   else
2875     gtk_widget_destroy (modeller);
2876
2877   if (!sheets)
2878     {
2879       sheets = shape_create_icon ("FilesQueue.xpm",
2880                                   580, 170, 0,0, GTK_WINDOW_POPUP);
2881
2882       gtk_signal_connect (GTK_OBJECT (sheets), "destroy",
2883                           GTK_SIGNAL_FUNC(destroy_window),
2884                           &sheets);
2885       gtk_signal_connect (GTK_OBJECT (sheets), "delete_event",
2886                           GTK_SIGNAL_FUNC(destroy_window),
2887                           &sheets);
2888
2889     }
2890   else
2891     gtk_widget_destroy (sheets);
2892
2893   if (!rings)
2894     {
2895       rings = shape_create_icon ("3DRings.xpm",
2896                                  460, 270, 25,25, GTK_WINDOW_TOPLEVEL);
2897
2898       gtk_signal_connect (GTK_OBJECT (rings), "destroy",
2899                           GTK_SIGNAL_FUNC(destroy_window),
2900                           &rings);
2901       gtk_signal_connect (GTK_OBJECT (rings), "delete_event",
2902                           GTK_SIGNAL_FUNC(destroy_window),
2903                           &rings);
2904     }
2905   else
2906     gtk_widget_destroy (rings);
2907 }
2908
2909
2910 /*
2911  * Progress Bar
2912  */
2913 static int progress_timer = 0;
2914
2915 gint
2916 progress_timeout (gpointer data)
2917 {
2918   gfloat new_val;
2919
2920   new_val = GTK_PROGRESS_BAR (data)->percentage;
2921   if (new_val >= 1.0)
2922     new_val = 0.0;
2923   new_val += 0.02;
2924
2925   gtk_progress_bar_update (GTK_PROGRESS_BAR (data), new_val);
2926
2927   return TRUE;
2928 }
2929
2930 void
2931 destroy_progress (GtkWidget  *widget,
2932                   GtkWidget **window)
2933 {
2934   destroy_window (widget, window);
2935   gtk_timeout_remove (progress_timer);
2936   progress_timer = 0;
2937 }
2938
2939 void
2940 create_progress_bar ()
2941 {
2942   static GtkWidget *window = NULL;
2943   GtkWidget *button;
2944   GtkWidget *vbox;
2945   GtkWidget *pbar;
2946   GtkWidget *label;
2947
2948   if (!window)
2949     {
2950       window = gtk_dialog_new ();
2951
2952       gtk_signal_connect (GTK_OBJECT (window), "destroy",
2953                           GTK_SIGNAL_FUNC(destroy_progress),
2954                           &window);
2955       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
2956                           GTK_SIGNAL_FUNC(destroy_progress),
2957                           &window);
2958
2959       gtk_window_set_title (GTK_WINDOW (window), "dialog");
2960       gtk_container_border_width (GTK_CONTAINER (window), 0);
2961
2962
2963       vbox = gtk_vbox_new (FALSE, 5);
2964       gtk_container_border_width (GTK_CONTAINER (vbox), 10);
2965       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
2966                           vbox, TRUE, TRUE, 0);
2967       gtk_widget_show (vbox);
2968
2969       label = gtk_label_new ("progress...");
2970       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
2971       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
2972       gtk_widget_show (label);
2973
2974       pbar = gtk_progress_bar_new ();
2975       gtk_widget_set_usize (pbar, 200, 20);
2976       gtk_box_pack_start (GTK_BOX (vbox), pbar, TRUE, TRUE, 0);
2977       gtk_widget_show (pbar);
2978
2979       progress_timer = gtk_timeout_add (100, progress_timeout, pbar);
2980
2981       button = gtk_button_new_with_label ("close");
2982       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
2983                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
2984                                  GTK_OBJECT (window));
2985       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2986       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
2987                           button, TRUE, TRUE, 0);
2988       gtk_widget_grab_default (button);
2989       gtk_widget_show (button);
2990     }
2991
2992   if (!GTK_WIDGET_VISIBLE (window))
2993     gtk_widget_show (window);
2994   else
2995     gtk_widget_destroy (window);
2996 }
2997
2998
2999 /*
3000  * Color Preview
3001  */
3002 static int color_idle = 0;
3003
3004 gint
3005 color_idle_func (GtkWidget *preview)
3006 {
3007   static int count = 1;
3008   guchar buf[768];
3009   int i, j, k;
3010
3011   for (i = 0; i < 256; i++)
3012     {
3013       for (j = 0, k = 0; j < 256; j++)
3014         {
3015           buf[k+0] = i + count;
3016           buf[k+1] = 0;
3017           buf[k+2] = j + count;
3018           k += 3;
3019         }
3020
3021       gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3022     }
3023
3024   count += 1;
3025
3026   gtk_widget_draw (preview, NULL);
3027
3028   return TRUE;
3029 }
3030
3031 void
3032 color_preview_destroy (GtkWidget  *widget,
3033                        GtkWidget **window)
3034 {
3035   gtk_idle_remove (color_idle);
3036   color_idle = 0;
3037
3038   destroy_window (widget, window);
3039 }
3040
3041 void
3042 create_color_preview ()
3043 {
3044   static GtkWidget *window = NULL;
3045   GtkWidget *preview;
3046   guchar buf[768];
3047   int i, j, k;
3048
3049   if (!window)
3050     {
3051       gtk_widget_push_visual (gtk_preview_get_visual ());
3052       gtk_widget_push_colormap (gtk_preview_get_cmap ());
3053
3054       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3055
3056       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3057                           GTK_SIGNAL_FUNC(color_preview_destroy),
3058                           &window);
3059       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3060                           GTK_SIGNAL_FUNC(color_preview_destroy),
3061                           &window);
3062
3063       gtk_window_set_title (GTK_WINDOW (window), "test");
3064       gtk_container_border_width (GTK_CONTAINER (window), 10);
3065
3066       preview = gtk_preview_new (GTK_PREVIEW_COLOR);
3067       gtk_preview_size (GTK_PREVIEW (preview), 256, 256);
3068       gtk_container_add (GTK_CONTAINER (window), preview);
3069       gtk_widget_show (preview);
3070
3071       for (i = 0; i < 256; i++)
3072         {
3073           for (j = 0, k = 0; j < 256; j++)
3074             {
3075               buf[k+0] = i;
3076               buf[k+1] = 0;
3077               buf[k+2] = j;
3078               k += 3;
3079             }
3080
3081           gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3082         }
3083
3084       color_idle = gtk_idle_add ((GtkFunction) color_idle_func, preview);
3085
3086       gtk_widget_pop_colormap ();
3087       gtk_widget_pop_visual ();
3088     }
3089
3090   if (!GTK_WIDGET_VISIBLE (window))
3091     gtk_widget_show (window);
3092   else
3093     gtk_widget_destroy (window);
3094 }
3095
3096
3097 /*
3098  * Gray Preview
3099  */
3100 static int gray_idle = 0;
3101
3102 gint
3103 gray_idle_func (GtkWidget *preview)
3104 {
3105   static int count = 1;
3106   guchar buf[256];
3107   int i, j;
3108
3109   for (i = 0; i < 256; i++)
3110     {
3111       for (j = 0; j < 256; j++)
3112         buf[j] = i + j + count;
3113
3114       gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3115     }
3116
3117   count += 1;
3118
3119   gtk_widget_draw (preview, NULL);
3120
3121   return TRUE;
3122 }
3123
3124 void
3125 gray_preview_destroy (GtkWidget  *widget,
3126                       GtkWidget **window)
3127 {
3128   gtk_idle_remove (gray_idle);
3129   gray_idle = 0;
3130
3131   destroy_window (widget, window);
3132 }
3133
3134 void
3135 create_gray_preview ()
3136 {
3137   static GtkWidget *window = NULL;
3138   GtkWidget *preview;
3139   guchar buf[256];
3140   int i, j;
3141
3142   if (!window)
3143     {
3144       gtk_widget_push_visual (gtk_preview_get_visual ());
3145       gtk_widget_push_colormap (gtk_preview_get_cmap ());
3146
3147       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3148
3149       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3150                           GTK_SIGNAL_FUNC(gray_preview_destroy),
3151                           &window);
3152       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3153                           GTK_SIGNAL_FUNC(gray_preview_destroy),
3154                           &window);
3155
3156       gtk_window_set_title (GTK_WINDOW (window), "test");
3157       gtk_container_border_width (GTK_CONTAINER (window), 10);
3158
3159       preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
3160       gtk_preview_size (GTK_PREVIEW (preview), 256, 256);
3161       gtk_container_add (GTK_CONTAINER (window), preview);
3162       gtk_widget_show (preview);
3163
3164       for (i = 0; i < 256; i++)
3165         {
3166           for (j = 0; j < 256; j++)
3167             buf[j] = i + j;
3168
3169           gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256);
3170         }
3171
3172       gray_idle = gtk_idle_add ((GtkFunction) gray_idle_func, preview);
3173
3174       gtk_widget_pop_colormap ();
3175       gtk_widget_pop_visual ();
3176     }
3177
3178   if (!GTK_WIDGET_VISIBLE (window))
3179     gtk_widget_show (window);
3180   else
3181     gtk_widget_destroy (window);
3182 }
3183
3184
3185 /*
3186  * Selection Test
3187  */
3188 void
3189 selection_test_received (GtkWidget *list, GtkSelectionData *data)
3190 {
3191   GdkAtom *atoms;
3192   GtkWidget *list_item;
3193   GList *item_list;
3194   int i, l;
3195
3196   if (data->length < 0)
3197     {
3198       g_print ("Selection retrieval failed\n");
3199       return;
3200     }
3201   if (data->type != GDK_SELECTION_TYPE_ATOM)
3202     {
3203       g_print ("Selection \"TARGETS\" was not returned as atoms!\n");
3204       return;
3205     }
3206
3207   /* Clear out any current list items */
3208
3209   gtk_list_clear_items (GTK_LIST(list), 0, -1);
3210
3211   /* Add new items to list */
3212
3213   atoms = (GdkAtom *)data->data;
3214
3215   item_list = NULL;
3216   l = data->length / sizeof (GdkAtom);
3217   for (i = 0; i < l; i++)
3218     {
3219       char *name;
3220       name = gdk_atom_name (atoms[i]);
3221       if (name != NULL)
3222         {
3223           list_item = gtk_list_item_new_with_label (name);
3224           g_free (name);
3225         }
3226       else
3227         list_item = gtk_list_item_new_with_label ("(bad atom)");
3228
3229       gtk_widget_show (list_item);
3230       item_list = g_list_append (item_list, list_item);
3231     }
3232
3233   gtk_list_append_items (GTK_LIST (list), item_list);
3234
3235   return;
3236 }
3237
3238 void
3239 selection_test_get_targets (GtkWidget *widget, GtkWidget *list)
3240 {
3241   static GdkAtom targets_atom = GDK_NONE;
3242
3243   if (targets_atom == GDK_NONE)
3244     targets_atom = gdk_atom_intern ("TARGETS", FALSE);
3245
3246   gtk_selection_convert (list, GDK_SELECTION_PRIMARY, targets_atom,
3247                          GDK_CURRENT_TIME);
3248 }
3249
3250 void
3251 create_selection_test ()
3252 {
3253   static GtkWidget *window = NULL;
3254   GtkWidget *button;
3255   GtkWidget *vbox;
3256   GtkWidget *scrolled_win;
3257   GtkWidget *list;
3258   GtkWidget *label;
3259
3260   if (!window)
3261     {
3262       window = gtk_dialog_new ();
3263
3264       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3265                           GTK_SIGNAL_FUNC(destroy_window),
3266                           &window);
3267       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3268                           GTK_SIGNAL_FUNC(destroy_window),
3269                           &window);
3270
3271       gtk_window_set_title (GTK_WINDOW (window), "Selection Test");
3272       gtk_container_border_width (GTK_CONTAINER (window), 0);
3273
3274       /* Create the list */
3275
3276       vbox = gtk_vbox_new (FALSE, 5);
3277       gtk_container_border_width (GTK_CONTAINER (vbox), 10);
3278       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox,
3279                           TRUE, TRUE, 0);
3280       gtk_widget_show (vbox);
3281
3282       label = gtk_label_new ("Gets available targets for current selection");
3283       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
3284       gtk_widget_show (label);
3285
3286       scrolled_win = gtk_scrolled_window_new (NULL, NULL);
3287       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
3288                                       GTK_POLICY_AUTOMATIC, 
3289                                       GTK_POLICY_AUTOMATIC);
3290       gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
3291       gtk_widget_set_usize (scrolled_win, 100, 200);
3292       gtk_widget_show (scrolled_win);
3293
3294       list = gtk_list_new ();
3295       gtk_container_add (GTK_CONTAINER (scrolled_win), list);
3296
3297       gtk_signal_connect (GTK_OBJECT(list), "selection_received",
3298                           GTK_SIGNAL_FUNC (selection_test_received), NULL);
3299       gtk_widget_show (list);
3300
3301       /* .. And create some buttons */
3302       button = gtk_button_new_with_label ("Get Targets");
3303       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
3304                           button, TRUE, TRUE, 0);
3305
3306       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3307                           GTK_SIGNAL_FUNC (selection_test_get_targets), list);
3308       gtk_widget_show (button);
3309
3310       button = gtk_button_new_with_label ("Quit");
3311       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
3312                           button, TRUE, TRUE, 0);
3313
3314       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3315                                  GTK_SIGNAL_FUNC (gtk_widget_destroy),
3316                                  GTK_OBJECT (window));
3317       gtk_widget_show (button);
3318     }
3319
3320   if (!GTK_WIDGET_VISIBLE (window))
3321     gtk_widget_show (window);
3322   else
3323     gtk_widget_destroy (window);
3324 }
3325
3326
3327 /*
3328  * Gamma Curve
3329  */
3330 void
3331 create_gamma_curve ()
3332 {
3333   static GtkWidget *window = NULL, *curve;
3334   static int count = 0;
3335   gfloat vec[256];
3336   gint max;
3337   gint i;
3338
3339   if (!window)
3340     {
3341       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3342       gtk_window_set_title (GTK_WINDOW (window), "test");
3343       gtk_container_border_width (GTK_CONTAINER (window), 10);
3344
3345       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3346                           GTK_SIGNAL_FUNC(destroy_window),
3347                           &window);
3348       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3349                           GTK_SIGNAL_FUNC(destroy_window),
3350                           &window);
3351
3352       curve = gtk_gamma_curve_new ();
3353       gtk_container_add (GTK_CONTAINER (window), curve);
3354       gtk_widget_show (curve);
3355     }
3356
3357   max = 127 + (count % 2)*128;
3358   gtk_curve_set_range (GTK_CURVE (GTK_GAMMA_CURVE (curve)->curve),
3359                        0, max, 0, max);
3360   for (i = 0; i < max; ++i)
3361     vec[i] = (127 / sqrt (max)) * sqrt (i);
3362   gtk_curve_set_vector (GTK_CURVE (GTK_GAMMA_CURVE (curve)->curve),
3363                         max, vec);
3364
3365   if (!GTK_WIDGET_VISIBLE (window))
3366     gtk_widget_show (window);
3367   else if (count % 4 == 3)
3368     {
3369       gtk_widget_destroy (window);
3370       window = NULL;
3371     }
3372
3373   ++count;
3374 }
3375
3376 static int scroll_test_pos = 0.0;
3377 static GdkGC *scroll_test_gc = NULL;
3378
3379 static gint
3380 scroll_test_expose (GtkWidget *widget, GdkEventExpose *event,
3381                     GtkAdjustment *adj)
3382 {
3383   gint i,j;
3384   gint imin, imax, jmin, jmax;
3385   
3386   imin = (event->area.x) / 10;
3387   imax = (event->area.x + event->area.width + 9) / 10;
3388
3389   jmin = ((int)adj->value + event->area.y) / 10;
3390   jmax = ((int)adj->value + event->area.y + event->area.height + 9) / 10;
3391
3392   gdk_window_clear_area (widget->window,
3393                          event->area.x, event->area.y,
3394                          event->area.width, event->area.height);
3395
3396   for (i=imin; i<imax; i++)
3397     for (j=jmin; j<jmax; j++)
3398       if ((i+j) % 2)
3399         gdk_draw_rectangle (widget->window, 
3400                             widget->style->black_gc,
3401                             TRUE,
3402                             10*i, 10*j - (int)adj->value, 1+i%10, 1+j%10);
3403
3404   return TRUE;
3405 }
3406
3407 static void
3408 scroll_test_configure (GtkWidget *widget, GdkEventConfigure *event,
3409                        GtkAdjustment *adj)
3410 {
3411   adj->page_increment = 0.9 * widget->allocation.height;
3412   adj->page_size = widget->allocation.height;
3413
3414   gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed");
3415 }
3416
3417 static void
3418 scroll_test_adjustment_changed (GtkAdjustment *adj, GtkWidget *widget)
3419 {
3420   gint source_min = (int)adj->value - scroll_test_pos;
3421   gint source_max = source_min + widget->allocation.height;
3422   gint dest_min = 0;
3423   gint dest_max = widget->allocation.height;
3424   GdkRectangle rect;
3425   GdkEvent *event;
3426
3427   scroll_test_pos = adj->value;
3428
3429   if (!GTK_WIDGET_DRAWABLE (widget))
3430     return;
3431
3432   if (source_min < 0)
3433     {
3434       rect.x = 0; 
3435       rect.y = 0;
3436       rect.width = widget->allocation.width;
3437       rect.height = -source_min;
3438       if (rect.height > widget->allocation.height)
3439         rect.height = widget->allocation.height;
3440
3441       source_min = 0;
3442       dest_min = rect.height;
3443     }
3444   else
3445     {
3446       rect.x = 0;
3447       rect.y = 2*widget->allocation.height - source_max;
3448       if (rect.y < 0)
3449         rect.y = 0;
3450       rect.width = widget->allocation.width;
3451       rect.height = widget->allocation.height - rect.y;
3452
3453       source_max = widget->allocation.height;
3454       dest_max = rect.y;
3455     }
3456
3457   if (source_min != source_max)
3458     {
3459       if (scroll_test_gc == NULL)
3460         {
3461           scroll_test_gc = gdk_gc_new (widget->window);
3462           gdk_gc_set_exposures (scroll_test_gc, TRUE);
3463         }
3464
3465       gdk_draw_pixmap (widget->window,
3466                        scroll_test_gc,
3467                        widget->window,
3468                        0, source_min,
3469                        0, dest_min,
3470                        widget->allocation.width,
3471                        source_max - source_min);
3472
3473       /* Make sure graphics expose events are processed before scrolling
3474        * again */
3475       
3476       while ((event = gdk_event_get_graphics_expose (widget->window)) != NULL)
3477         {
3478           gtk_widget_event (widget, event);
3479           if (event->expose.count == 0)
3480             {
3481               gdk_event_free (event);
3482               break;
3483             }
3484           gdk_event_free (event);
3485         }
3486     }
3487
3488
3489   if (rect.height != 0)
3490     gtk_widget_draw (widget, &rect);
3491 }
3492
3493
3494 void
3495 create_scroll_test ()
3496 {
3497   static GtkWidget *window = NULL;
3498   GtkWidget *hbox;
3499   GtkWidget *drawing_area;
3500   GtkWidget *scrollbar;
3501   GtkWidget *button;
3502   GtkAdjustment *adj;
3503   
3504   if (!window)
3505     {
3506       window = gtk_dialog_new ();
3507
3508       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3509                           GTK_SIGNAL_FUNC(destroy_window),
3510                           &window);
3511       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3512                           GTK_SIGNAL_FUNC(destroy_window),
3513                           &window);
3514
3515       gtk_window_set_title (GTK_WINDOW (window), "Scroll Test");
3516       gtk_container_border_width (GTK_CONTAINER (window), 0);
3517
3518       hbox = gtk_hbox_new (FALSE, 0);
3519       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), hbox,
3520                           TRUE, TRUE, 0);
3521       gtk_widget_show (hbox);
3522
3523       drawing_area = gtk_drawing_area_new ();
3524       gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200);
3525       gtk_box_pack_start (GTK_BOX (hbox), drawing_area, TRUE, TRUE, 0);
3526       gtk_widget_show (drawing_area);
3527
3528       gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK);
3529
3530       adj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 1000.0, 1.0, 180.0, 200.0));
3531       scroll_test_pos = 0.0;
3532
3533       scrollbar = gtk_vscrollbar_new (adj);
3534       gtk_box_pack_start (GTK_BOX (hbox), scrollbar, FALSE, FALSE, 0);
3535       gtk_widget_show (scrollbar);
3536
3537       gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
3538                           GTK_SIGNAL_FUNC (scroll_test_expose), adj);
3539       gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event",
3540                           GTK_SIGNAL_FUNC (scroll_test_configure), adj);
3541
3542       
3543       gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
3544                           GTK_SIGNAL_FUNC (scroll_test_adjustment_changed),
3545                           drawing_area);
3546       
3547       /* .. And create some buttons */
3548
3549       button = gtk_button_new_with_label ("Quit");
3550       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
3551                           button, TRUE, TRUE, 0);
3552
3553       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3554                                  GTK_SIGNAL_FUNC (gtk_widget_destroy),
3555                                  GTK_OBJECT (window));
3556       gtk_widget_show (button);
3557     }
3558
3559   if (!GTK_WIDGET_VISIBLE (window))
3560     gtk_widget_show (window);
3561   else
3562     gtk_widget_destroy (window);
3563 }
3564
3565 /*
3566  * Timeout Test
3567  */
3568 static int timer = 0;
3569
3570 void
3571 timeout_test (GtkWidget *label)
3572 {
3573   static int count = 0;
3574   static char buffer[32];
3575
3576   sprintf (buffer, "count: %d", ++count);
3577   gtk_label_set (GTK_LABEL (label), buffer);
3578 }
3579
3580 void
3581 start_timeout_test (GtkWidget *widget,
3582                     GtkWidget *label)
3583 {
3584   if (!timer)
3585     {
3586       timer = gtk_timeout_add (100, (GtkFunction) timeout_test, label);
3587     }
3588 }
3589
3590 void
3591 stop_timeout_test (GtkWidget *widget,
3592                    gpointer   data)
3593 {
3594   if (timer)
3595     {
3596       gtk_timeout_remove (timer);
3597       timer = 0;
3598     }
3599 }
3600
3601 void
3602 destroy_timeout_test (GtkWidget  *widget,
3603                       GtkWidget **window)
3604 {
3605   destroy_window (widget, window);
3606   stop_timeout_test (NULL, NULL);
3607 }
3608
3609 void
3610 create_timeout_test ()
3611 {
3612   static GtkWidget *window = NULL;
3613   GtkWidget *button;
3614   GtkWidget *label;
3615
3616   if (!window)
3617     {
3618       window = gtk_dialog_new ();
3619
3620       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3621                           GTK_SIGNAL_FUNC(destroy_timeout_test),
3622                           &window);
3623       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3624                           GTK_SIGNAL_FUNC(destroy_timeout_test),
3625                           &window);
3626
3627       gtk_window_set_title (GTK_WINDOW (window), "Timeout Test");
3628       gtk_container_border_width (GTK_CONTAINER (window), 0);
3629
3630       label = gtk_label_new ("count: 0");
3631       gtk_misc_set_padding (GTK_MISC (label), 10, 10);
3632       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
3633                           label, TRUE, TRUE, 0);
3634       gtk_widget_show (label);
3635
3636       button = gtk_button_new_with_label ("close");
3637       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3638                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
3639                                  GTK_OBJECT (window));
3640       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3641       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3642                           button, TRUE, TRUE, 0);
3643       gtk_widget_grab_default (button);
3644       gtk_widget_show (button);
3645
3646       button = gtk_button_new_with_label ("start");
3647       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3648                           GTK_SIGNAL_FUNC(start_timeout_test),
3649                           label);
3650       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3651       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3652                           button, TRUE, TRUE, 0);
3653       gtk_widget_show (button);
3654
3655       button = gtk_button_new_with_label ("stop");
3656       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3657                           GTK_SIGNAL_FUNC(stop_timeout_test),
3658                           NULL);
3659       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3660       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3661                           button, TRUE, TRUE, 0);
3662       gtk_widget_show (button);
3663     }
3664
3665   if (!GTK_WIDGET_VISIBLE (window))
3666     gtk_widget_show (window);
3667   else
3668     gtk_widget_destroy (window);
3669 }
3670
3671
3672 /*
3673  * Idle Test
3674  */
3675 static int idle = 0;
3676
3677 gint
3678 idle_test (GtkWidget *label)
3679 {
3680   static int count = 0;
3681   static char buffer[32];
3682
3683   sprintf (buffer, "count: %d", ++count);
3684   gtk_label_set (GTK_LABEL (label), buffer);
3685
3686   return TRUE;
3687 }
3688
3689 void
3690 start_idle_test (GtkWidget *widget,
3691                  GtkWidget *label)
3692 {
3693   if (!idle)
3694     {
3695       idle = gtk_idle_add ((GtkFunction) idle_test, label);
3696     }
3697 }
3698
3699 void
3700 stop_idle_test (GtkWidget *widget,
3701                 gpointer   data)
3702 {
3703   if (idle)
3704     {
3705       gtk_idle_remove (idle);
3706       idle = 0;
3707     }
3708 }
3709
3710 void
3711 destroy_idle_test (GtkWidget  *widget,
3712                    GtkWidget **window)
3713 {
3714   destroy_window (widget, window);
3715   stop_idle_test (NULL, NULL);
3716 }
3717
3718 void
3719 create_idle_test ()
3720 {
3721   static GtkWidget *window = NULL;
3722   GtkWidget *button;
3723   GtkWidget *label;
3724
3725   if (!window)
3726     {
3727       window = gtk_dialog_new ();
3728
3729       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3730                           GTK_SIGNAL_FUNC(destroy_idle_test),
3731                           &window);
3732       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3733                           GTK_SIGNAL_FUNC(destroy_idle_test),
3734                           &window);
3735
3736       gtk_window_set_title (GTK_WINDOW (window), "Idle Test");
3737       gtk_container_border_width (GTK_CONTAINER (window), 0);
3738
3739       label = gtk_label_new ("count: 0");
3740       gtk_misc_set_padding (GTK_MISC (label), 10, 10);
3741       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
3742                           label, TRUE, TRUE, 0);
3743       gtk_widget_show (label);
3744
3745       button = gtk_button_new_with_label ("close");
3746       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3747                                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
3748                                  GTK_OBJECT (window));
3749       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3750       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3751                           button, TRUE, TRUE, 0);
3752       gtk_widget_grab_default (button);
3753       gtk_widget_show (button);
3754
3755       button = gtk_button_new_with_label ("start");
3756       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3757                           GTK_SIGNAL_FUNC(start_idle_test),
3758                           label);
3759       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3760       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3761                           button, TRUE, TRUE, 0);
3762       gtk_widget_show (button);
3763
3764       button = gtk_button_new_with_label ("stop");
3765       gtk_signal_connect (GTK_OBJECT (button), "clicked",
3766                           GTK_SIGNAL_FUNC(stop_idle_test),
3767                           NULL);
3768       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3769       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
3770                           button, TRUE, TRUE, 0);
3771       gtk_widget_show (button);
3772     }
3773
3774   if (!GTK_WIDGET_VISIBLE (window))
3775     gtk_widget_show (window);
3776   else
3777     gtk_widget_destroy (window);
3778 }
3779
3780 void
3781 test_destroy (GtkWidget  *widget,
3782               GtkWidget **window)
3783 {
3784   destroy_window (widget, window);
3785   gtk_main_quit ();
3786 }
3787
3788 /*
3789  * Basic Test
3790  */
3791 void
3792 create_test ()
3793 {
3794   static GtkWidget *window = NULL;
3795
3796   if (!window)
3797     {
3798       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3799
3800       gtk_signal_connect (GTK_OBJECT (window), "destroy",
3801                           GTK_SIGNAL_FUNC(test_destroy),
3802                           &window);
3803       gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3804                           GTK_SIGNAL_FUNC(test_destroy),
3805                           &window);
3806
3807
3808       gtk_window_set_title (GTK_WINDOW (window), "test");
3809       gtk_container_border_width (GTK_CONTAINER (window), 0);
3810     }
3811
3812   if (!GTK_WIDGET_VISIBLE (window))
3813     {
3814       gtk_widget_show (window);
3815
3816       g_print ("create_test: start\n");
3817       gtk_main ();
3818       g_print ("create_test: done\n");
3819     }
3820   else
3821     gtk_widget_destroy (window);
3822 }
3823
3824
3825 /*
3826  * Main Window and Exit
3827  */
3828 void
3829 do_exit (GtkWidget *widget, GtkWidget *window)
3830 {
3831   gtk_widget_destroy (window);
3832   gtk_main_quit ();
3833 }
3834
3835 void
3836 create_main_window ()
3837 {
3838   struct {
3839     char *label;
3840     void (*func) ();
3841   } buttons[] =
3842     {
3843       { "buttons", create_buttons },
3844       { "toggle buttons", create_toggle_buttons },
3845       { "check buttons", create_check_buttons },
3846       { "radio buttons", create_radio_buttons },
3847       { "button box", create_button_box },
3848       { "toolbar", create_toolbar },
3849       { "handle box", create_handle_box },
3850       { "reparent", create_reparent },
3851       { "pixmap", create_pixmap },
3852       { "tooltips", create_tooltips },
3853       { "menus", create_menus },
3854       { "scrolled windows", create_scrolled_windows },
3855       { "drawing areas", NULL },
3856       { "entry", create_entry },
3857       { "list", create_list },
3858       { "clist", create_clist},
3859       { "color selection", create_color_selection },
3860       { "file selection", create_file_selection },
3861       { "dialog", create_dialog },
3862       { "miscellaneous", NULL },
3863       { "range controls", create_range_controls },
3864       { "rulers", create_rulers },
3865       { "text", create_text },
3866       { "notebook", create_notebook },
3867       { "panes", create_panes },
3868       { "shapes", create_shapes },
3869       { "dnd", create_dnd },
3870       { "progress bar", create_progress_bar },
3871       { "preview color", create_color_preview },
3872       { "preview gray", create_gray_preview },
3873       { "gamma curve", create_gamma_curve },
3874       { "test scrolling", create_scroll_test },
3875       { "test selection", create_selection_test },
3876       { "test timeout", create_timeout_test },
3877       { "test idle", create_idle_test },
3878       { "test", create_test },
3879     };
3880   int nbuttons = sizeof (buttons) / sizeof (buttons[0]);
3881   GtkWidget *window;
3882   GtkWidget *box1;
3883   GtkWidget *box2;
3884   GtkWidget *scrolled_window;
3885   GtkWidget *button;
3886   GtkWidget *separator;
3887   int i;
3888
3889   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3890   gtk_widget_set_name (window, "main window");
3891   gtk_widget_set_usize (window, 200, 400);
3892   gtk_widget_set_uposition (window, 20, 20);
3893
3894   gtk_signal_connect (GTK_OBJECT (window), "destroy",
3895                       GTK_SIGNAL_FUNC(gtk_main_quit),
3896                       NULL);
3897   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
3898                       GTK_SIGNAL_FUNC(gtk_main_quit),
3899                       NULL);
3900
3901   box1 = gtk_vbox_new (FALSE, 0);
3902   gtk_container_add (GTK_CONTAINER (window), box1);
3903   gtk_widget_show (box1);
3904
3905   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
3906   gtk_container_border_width (GTK_CONTAINER (scrolled_window), 10);
3907   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
3908                                   GTK_POLICY_AUTOMATIC, 
3909                                   GTK_POLICY_AUTOMATIC);
3910   gtk_box_pack_start (GTK_BOX (box1), scrolled_window, TRUE, TRUE, 0);
3911   gtk_widget_show (scrolled_window);
3912
3913   box2 = gtk_vbox_new (FALSE, 0);
3914   gtk_container_border_width (GTK_CONTAINER (box2), 10);
3915   gtk_container_add (GTK_CONTAINER (scrolled_window), box2);
3916   gtk_widget_show (box2);
3917
3918   for (i = 0; i < nbuttons; i++)
3919     {
3920       button = gtk_button_new_with_label (buttons[i].label);
3921       if (buttons[i].func)
3922         gtk_signal_connect (GTK_OBJECT (button), 
3923                             "clicked", 
3924                             GTK_SIGNAL_FUNC(buttons[i].func),
3925                             NULL);
3926       else
3927         gtk_widget_set_sensitive (button, FALSE);
3928       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
3929       gtk_widget_show (button);
3930     }
3931
3932   separator = gtk_hseparator_new ();
3933   gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
3934   gtk_widget_show (separator);
3935
3936   box2 = gtk_vbox_new (FALSE, 10);
3937   gtk_container_border_width (GTK_CONTAINER (box2), 10);
3938   gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
3939   gtk_widget_show (box2);
3940
3941   button = gtk_button_new_with_label ("close");
3942   gtk_signal_connect (GTK_OBJECT (button), "clicked",
3943                       GTK_SIGNAL_FUNC (do_exit),
3944                       window);
3945   gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
3946   GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
3947   gtk_widget_grab_default (button);
3948   gtk_widget_show (button);
3949
3950   gtk_widget_show (window);
3951 }
3952
3953 int
3954 main (int argc, char *argv[])
3955 {
3956   gtk_set_locale ();
3957
3958   gtk_init (&argc, &argv);
3959   gtk_rc_parse ("testgtkrc");
3960
3961   create_main_window ();
3962
3963   gtk_main ();
3964
3965   return 0;
3966 }