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