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