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