]> Pileus Git - ~andy/gtk/blob - gtk/gtkmain.c
changed handler tags to be of type guint, reflecting the internal tag
[~andy/gtk] / gtk / gtkmain.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 "gtkbutton.h"
21 #include "gtkhscrollbar.h"
22 #include "gtkhseparator.h"
23 #include "gtkmain.h"
24 #include "gtkpreview.h"
25 #include "gtkrc.h"
26 #include "gtkselection.h"
27 #include "gtksignal.h"
28 #include "gtktable.h"
29 #include "gtktext.h"
30 #include "gtkvbox.h"
31 #include "gtkvscrollbar.h"
32 #include "gtkwidget.h"
33 #include "gtkwindow.h"
34 #include "gtkprivate.h"
35 #include "../config.h"
36
37
38 /* Private type definitions
39  */
40 typedef struct _GtkInitFunction          GtkInitFunction;
41 typedef struct _GtkQuitFunction          GtkQuitFunction;
42 typedef struct _GtkTimeoutFunction       GtkTimeoutFunction;
43 typedef struct _GtkIdleFunction          GtkIdleFunction;
44 typedef struct _GtkInputFunction         GtkInputFunction;
45 typedef struct _GtkKeySnooperData        GtkKeySnooperData;
46
47 struct _GtkInitFunction
48 {
49   GtkFunction function;
50   gpointer data;
51 };
52
53 struct _GtkQuitFunction
54 {
55   guint id;
56   guint main_level;
57   GtkCallbackMarshal marshal;
58   GtkFunction function;
59   gpointer data;
60   GtkDestroyNotify destroy;
61 };
62
63 struct _GtkTimeoutFunction
64 {
65   guint tag;
66   guint32 start;
67   guint32 interval;
68   guint32 originterval;
69   GtkFunction function;
70   GtkCallbackMarshal marshal;
71   gpointer data;
72   GtkDestroyNotify destroy;
73 };
74
75 struct _GtkIdleFunction
76 {
77   guint tag;
78   gint priority;
79   GtkCallbackMarshal marshal;
80   GtkFunction function;
81   gpointer data;
82   GtkDestroyNotify destroy;
83 };
84
85 struct _GtkInputFunction
86 {
87   GtkCallbackMarshal callback;
88   gpointer data;
89   GtkDestroyNotify destroy;
90 };
91
92 struct _GtkKeySnooperData
93 {
94   GtkKeySnoopFunc func;
95   gpointer func_data;
96   guint id;
97 };
98
99 static void  gtk_exit_func               (void);
100 static gint  gtk_quit_invoke_function    (GtkQuitFunction    *quitf);
101 static void  gtk_quit_destroy            (GtkQuitFunction    *quitf);
102 static void  gtk_timeout_insert          (GtkTimeoutFunction *timeoutf);
103 static void  gtk_handle_current_timeouts (guint32             the_time);
104 static void  gtk_handle_current_idles    (void);
105 static gint  gtk_invoke_key_snoopers     (GtkWidget          *grab_widget,
106                                           GdkEvent           *event);
107 static void  gtk_handle_timeouts         (void);
108 static void  gtk_handle_idle             (void);
109 static void  gtk_handle_timer            (void);
110 static void  gtk_propagate_event         (GtkWidget          *widget,
111                                           GdkEvent           *event);
112 static void  gtk_error                   (gchar              *str);
113 static void  gtk_warning                 (gchar              *str);
114 static void  gtk_message                 (gchar              *str);
115 static void  gtk_print                   (gchar              *str);
116
117 static gint  gtk_idle_compare            (gpointer            a, 
118                                           gpointer            b);
119
120 static gint  gtk_timeout_compare         (gpointer            a, 
121                                           gpointer            b);
122
123 const guint gtk_major_version = GTK_MAJOR_VERSION;
124 const guint gtk_minor_version = GTK_MINOR_VERSION;
125 const guint gtk_micro_version = GTK_MICRO_VERSION;
126
127 static gboolean iteration_done = FALSE;
128 static guint main_level = 0;
129 static gint initialized = FALSE;
130 static GdkEvent *next_event = NULL;
131 static GList *current_events = NULL;
132
133 static GSList *grabs = NULL;               /* A stack of unique grabs. The grabbing
134                                             *  widget is the first one on the list.
135                                             */
136 static GList *init_functions = NULL;       /* A list of init functions.
137                                             */
138 static GList *quit_functions = NULL;       /* A list of quit functions.
139                                             */
140 static GList *timeout_functions = NULL;    /* A list of timeout functions sorted by
141                                             *  when the length of the time interval
142                                             *  remaining. Therefore, the first timeout
143                                             *  function to expire is at the head of
144                                             *  the list and the last to expire is at
145                                             *  the tail of the list.
146                                             */
147 static GList *idle_functions = NULL;       /* A list of idle functions.
148                                             */
149
150 static GList *current_idles = NULL;
151 static GList *current_timeouts = NULL;
152 static GMemChunk *timeout_mem_chunk = NULL;
153 static GMemChunk *idle_mem_chunk = NULL;
154 static GMemChunk *quit_mem_chunk = NULL;
155
156 static GSList *key_snoopers = NULL;
157
158 static GdkVisual *gtk_visual;              /* The visual to be used in creating new
159                                             *  widgets.
160                                             */
161 static GdkColormap *gtk_colormap;          /* The colormap to be used in creating new
162                                             *  widgets.
163                                             */
164
165 guint gtk_debug_flags = 0;                 /* Global GTK debug flag */
166
167 #ifdef G_ENABLE_DEBUG
168 static GDebugKey gtk_debug_keys[] = {
169   {"objects", GTK_DEBUG_OBJECTS}
170 };
171
172 static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
173
174 #endif /* G_ENABLE_DEBUG */
175
176
177
178
179 void
180 gtk_init (int    *argc,
181           char ***argv)
182 {
183   if (0)
184     {
185       g_set_error_handler (gtk_error);
186       g_set_warning_handler (gtk_warning);
187       g_set_message_handler (gtk_message);
188       g_set_print_handler (gtk_print);
189     }
190   
191   /* Initialize "gdk". We pass along the 'argc' and 'argv'
192    *  parameters as they contain information that GDK uses
193    */
194   gdk_init (argc, argv);
195   
196 #ifdef G_ENABLE_DEBUG
197   {
198     gchar *debug_string = getenv("GTK_DEBUG");
199     if (debug_string != NULL)
200       gtk_debug_flags = g_parse_debug_string (debug_string,
201                                               gtk_debug_keys,
202                                               gtk_ndebug_keys);
203   }
204
205   if (argc && argv)
206     {
207       gint i;
208       
209       for (i = 1; i < *argc;)
210         {
211           if ((*argv)[i] == NULL)
212             {
213               i += 1;
214               continue;
215             }
216
217           if (strcmp ("--gtk-debug", (*argv)[i]) == 0)
218             {
219               (*argv)[i] = NULL;
220
221               if ((i + 1) < *argc && (*argv)[i + 1])
222                 {
223                   gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
224                                                            gtk_debug_keys,
225                                                            gtk_ndebug_keys);
226                   (*argv)[i + 1] = NULL;
227                   i += 1;
228                 }
229             }
230           else if (strcmp ("--gtk-no-debug", (*argv)[i]) == 0)
231             {
232               (*argv)[i] = NULL;
233
234               if ((i + 1) < *argc && (*argv)[i + 1])
235                 {
236                   gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
237                                                             gtk_debug_keys,
238                                                             gtk_ndebug_keys);
239                   (*argv)[i + 1] = NULL;
240                   i += 1;
241                 }
242             }
243           i += 1;
244         }
245     }
246
247 #endif /* G_ENABLE_DEBUG */
248
249   /* Initialize the default visual and colormap to be
250    *  used in creating widgets. (We want to use the system
251    *  defaults so as to be nice to the colormap).
252    */
253   gtk_visual = gdk_visual_get_system ();
254   gtk_colormap = gdk_colormap_get_system ();
255   gtk_rc_init ();
256   
257   gtk_type_init ();
258   
259   /* Register an exit function to make sure we are able to cleanup.
260    */
261   if (ATEXIT (gtk_exit_func))
262     g_warning ("unable to register exit function");
263   
264   /* Set the 'initialized' flag.
265    */
266   initialized = TRUE;
267 }
268
269 void
270 gtk_exit (int errorcode)
271 {
272   /* Only if "gtk" has been initialized should we de-initialize.
273    */
274   /* de-initialisation is done by the gtk_exit_funct(),
275    * no need to do this here (Alex J.)
276    */
277   gdk_exit(errorcode);
278 }
279
280 gchar*
281 gtk_set_locale ()
282 {
283   return gdk_set_locale ();
284 }
285
286 void
287 gtk_main ()
288 {
289   GList *tmp_list;
290   GList *functions;
291   GtkInitFunction *init;
292   int old_done;
293   
294   main_level++;
295   
296   tmp_list = functions = init_functions;
297   init_functions = NULL;
298   
299   while (tmp_list)
300     {
301       init = tmp_list->data;
302       tmp_list = tmp_list->next;
303       
304       (* init->function) (init->data);
305       g_free (init);
306     }
307   g_list_free (functions);
308   
309   old_done = iteration_done;
310   while (!gtk_main_iteration ())
311     ;
312   iteration_done = old_done;
313
314   if (quit_functions)
315     {
316       GList *reinvoke_list = NULL;
317       GtkQuitFunction *quitf;
318
319       while (quit_functions)
320         {
321           quitf = quit_functions->data;
322
323           quit_functions = g_list_remove_link (quit_functions, quit_functions);
324
325           if ((quitf->main_level &&
326                quitf->main_level != main_level) ||
327               gtk_quit_invoke_function (quitf) == FALSE)
328             {
329               g_list_free (tmp_list);
330               gtk_quit_destroy (quitf);
331             }
332           else
333             {
334               reinvoke_list = g_list_prepend (reinvoke_list, quitf);
335             }
336         }
337       if (reinvoke_list)
338         {
339           GList *tmp_list;
340           
341           tmp_list = g_list_last (reinvoke_list);
342           if (quit_functions)
343             quit_functions->prev = tmp_list;
344           tmp_list->next = quit_functions;
345           quit_functions = tmp_list;
346         }
347     }
348               
349   main_level--;
350 }
351
352 guint
353 gtk_main_level (void)
354 {
355   return main_level;
356 }
357
358 void
359 gtk_main_quit ()
360 {
361   iteration_done = TRUE;
362 }
363
364 gint
365 gtk_events_pending (void)
366 {
367   gint result = gdk_events_pending() + ((next_event != NULL) ? 1 : 0);
368
369   if (idle_functions &&
370       (((GtkIdleFunction *)idle_functions->data)->priority >=
371        GTK_PRIORITY_INTERNAL))
372     result += 1;
373
374   return result;
375 }
376
377 gint 
378 gtk_main_iteration ()
379 {
380   return gtk_main_iteration_do (TRUE);
381 }
382
383 gint
384 gtk_main_iteration_do (gboolean blocking)
385 {
386   GtkWidget *event_widget;
387   GtkWidget *grab_widget;
388   GdkEvent *event = NULL;
389   GList *tmp_list;
390   
391   iteration_done = FALSE;
392   
393   /* If this is a recursive call, and there are pending timeouts or
394    * idles, finish them, then return immediately to avoid blocking
395    * in gdk_event_get()
396    */
397   if (current_timeouts)
398     {
399       gtk_handle_current_timeouts( gdk_time_get());
400       return iteration_done;
401     }
402   if (current_idles)
403     {
404       gtk_handle_current_idles ();
405       return iteration_done;
406     }
407   
408   /* If there is a valid event in 'next_event' then move it to 'event'
409    */
410   if (next_event)
411     {
412       event = next_event;
413       next_event = NULL;
414     }
415   
416   /* If we don't have an event then get one.
417    */
418   if (!event)
419     {
420       /* Handle setting of the "gdk" timer. If there are no
421        *  timeout functions, then the timer is turned off.
422        *  If there are timeout functions, then the timer is
423        *  set to the shortest timeout interval (which is
424        *  the first timeout function).
425        */
426       gtk_handle_timer ();
427       
428       if (blocking) event = gdk_event_get ();
429     }
430   
431   /* "gdk_event_get" can return FALSE if the timer goes off
432    *  and no events are pending. Therefore, we should make
433    *  sure that we got an event before continuing.
434    */
435   if (event)
436     {
437       /* If there are any events pending then get the next one.
438        */
439       if (gdk_events_pending () > 0)
440         next_event = gdk_event_get ();
441       
442       /* Try to compress enter/leave notify events. These event
443        *  pairs occur when the mouse is dragged quickly across
444        *  a window with many buttons (or through a menu). Instead
445        *  of highlighting and de-highlighting each widget that
446        *  is crossed it is better to simply de-highlight the widget
447        *  which contained the mouse initially and highlight the
448        *  widget which ends up containing the mouse.
449        */
450       if (next_event)
451         if (((event->type == GDK_ENTER_NOTIFY) ||
452              (event->type == GDK_LEAVE_NOTIFY)) &&
453             ((next_event->type == GDK_ENTER_NOTIFY) ||
454              (next_event->type == GDK_LEAVE_NOTIFY)) &&
455             (next_event->type != event->type) &&
456             (next_event->any.window == event->any.window))
457           {
458             gdk_event_free (event);
459             gdk_event_free (next_event);
460             next_event = NULL;
461             
462             goto event_handling_done;
463           }
464       
465       /* Find the widget which got the event. We store the widget
466        *  in the user_data field of GdkWindow's.
467        *  Ignore the event if we don't have a widget for it, except
468        *  for GDK_PROPERTY_NOTIFY events which are handled specialy.
469        *  Though this happens rarely, bogus events can occour
470        *  for e.g. destroyed GdkWindows. 
471        */
472       event_widget = gtk_get_event_widget (event);
473       if (!event_widget)
474         {
475           /* To handle selection INCR transactions, we select
476            * PropertyNotify events on the requestor window and create
477            * a corresponding (fake) GdkWindow so that events get
478            * here. There won't be a widget though, so we have to handle
479            * them specially
480            */
481           if (event->type == GDK_PROPERTY_NOTIFY)
482             gtk_selection_incr_event (event->any.window,
483                                       &event->property);
484           
485           gdk_event_free (event);
486           
487           goto event_handling_done;
488         }
489       
490       /* Push the event onto a stack of current events for
491        * gtk_current_event_get().
492        */
493       current_events = g_list_prepend (current_events, event);
494       
495       /* If there is a grab in effect...
496        */
497       if (grabs)
498         {
499           grab_widget = grabs->data;
500           
501           /* If the grab widget is an ancestor of the event widget
502            *  then we send the event to the original event widget.
503            *  This is the key to implementing modality.
504            */
505           if (gtk_widget_is_ancestor (event_widget, grab_widget))
506             grab_widget = event_widget;
507         }
508       else
509         {
510           grab_widget = event_widget;
511         }
512
513       /* Not all events get sent to the grabbing widget.
514        * The delete, destroy, expose, focus change and resize
515        *  events still get sent to the event widget because
516        *  1) these events have no meaning for the grabbing widget
517        *  and 2) redirecting these events to the grabbing widget
518        *  could cause the display to be messed up.
519        */
520       switch (event->type)
521         {
522         case GDK_NOTHING:
523           break;
524           
525         case GDK_DELETE:
526           gtk_widget_ref (event_widget);
527           if (gtk_widget_event (event_widget, event))
528             gtk_widget_destroy (event_widget);
529           gtk_widget_unref (event_widget);
530           break;
531           
532         case GDK_DESTROY:
533           gtk_widget_ref (event_widget);
534           gtk_widget_event (event_widget, event);
535           gtk_widget_destroy (event_widget);
536           gtk_widget_unref (event_widget);
537           break;
538           
539         case GDK_PROPERTY_NOTIFY:
540         case GDK_EXPOSE:
541         case GDK_NO_EXPOSE:
542         case GDK_FOCUS_CHANGE:
543         case GDK_CONFIGURE:
544         case GDK_MAP:
545         case GDK_UNMAP:
546         case GDK_SELECTION_CLEAR:
547         case GDK_SELECTION_REQUEST:
548         case GDK_SELECTION_NOTIFY:
549         case GDK_CLIENT_EVENT:
550         case GDK_DRAG_BEGIN:
551         case GDK_DRAG_REQUEST:
552         case GDK_DROP_ENTER:
553         case GDK_DROP_LEAVE:
554         case GDK_DROP_DATA_AVAIL:
555         case GDK_VISIBILITY_NOTIFY:
556           gtk_widget_event (event_widget, event);
557           break;
558           
559         case GDK_KEY_PRESS:
560         case GDK_KEY_RELEASE:
561           if (key_snoopers)
562             {
563               if (gtk_invoke_key_snoopers (grab_widget, event))
564                 break;
565             }
566           /* else fall through */
567         case GDK_MOTION_NOTIFY:
568         case GDK_BUTTON_PRESS:
569         case GDK_2BUTTON_PRESS:
570         case GDK_3BUTTON_PRESS:
571         case GDK_BUTTON_RELEASE:
572         case GDK_PROXIMITY_IN:
573         case GDK_PROXIMITY_OUT:
574         case GDK_OTHER_EVENT:
575           gtk_propagate_event (grab_widget, event);
576           break;
577           
578         case GDK_ENTER_NOTIFY:
579           if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
580             {
581               gtk_widget_event (grab_widget, event);
582               if (event_widget == grab_widget)
583                 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
584             }
585           break;
586           
587         case GDK_LEAVE_NOTIFY:
588           if (GTK_WIDGET_LEAVE_PENDING (event_widget))
589             {
590               GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
591               gtk_widget_event (event_widget, event);
592             }
593           else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
594             gtk_widget_event (grab_widget, event);
595           break;
596         }
597       
598       tmp_list = current_events;
599       current_events = g_list_remove_link (current_events, tmp_list);
600       g_list_free_1 (tmp_list);
601       
602       gdk_event_free (event);
603     }
604   else
605     {
606       if (gdk_events_pending() == 0)
607         gtk_handle_idle ();
608     }
609   
610 event_handling_done:
611   
612   /* Handle timeout functions that may have expired.
613    */
614   gtk_handle_timeouts ();
615   
616   return iteration_done;
617 }
618
619 gint
620 gtk_true (void)
621 {
622   return TRUE;
623 }
624
625 gint
626 gtk_false (void)
627 {
628   return FALSE;
629 }
630
631 void
632 gtk_grab_add (GtkWidget *widget)
633 {
634   g_return_if_fail (widget != NULL);
635   
636   if (!GTK_WIDGET_HAS_GRAB (widget))
637     {
638       GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
639       
640       grabs = g_slist_prepend (grabs, widget);
641       gtk_widget_ref (widget);
642     }
643 }
644
645 GtkWidget*
646 gtk_grab_get_current (void)
647 {
648   if (grabs)
649     return GTK_WIDGET (grabs->data);
650   return NULL;
651 }
652
653 void
654 gtk_grab_remove (GtkWidget *widget)
655 {
656   g_return_if_fail (widget != NULL);
657   
658   if (GTK_WIDGET_HAS_GRAB (widget))
659     {
660       GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
661       
662       grabs = g_slist_remove (grabs, widget);
663       gtk_widget_unref (widget);
664     }
665 }
666
667 void
668 gtk_init_add (GtkFunction function,
669               gpointer    data)
670 {
671   GtkInitFunction *init;
672   
673   init = g_new (GtkInitFunction, 1);
674   init->function = function;
675   init->data = data;
676   
677   init_functions = g_list_prepend (init_functions, init);
678 }
679
680 guint
681 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
682                          gpointer        func_data)
683 {
684   GtkKeySnooperData *data;
685   static guint snooper_id = 1;
686
687   g_return_val_if_fail (snooper != NULL, 0);
688
689   data = g_new (GtkKeySnooperData, 1);
690   data->func = snooper;
691   data->func_data = func_data;
692   data->id = snooper_id++;
693   key_snoopers = g_slist_prepend (key_snoopers, data);
694
695   return data->id;
696 }
697
698 void
699 gtk_key_snooper_remove (guint            snooper_id)
700 {
701   GtkKeySnooperData *data = NULL;
702   GSList *slist;
703
704   slist = key_snoopers;
705   while (slist)
706     {
707       data = slist->data;
708       if (data->id == snooper_id)
709         break;
710
711       slist = slist->next;
712       data = NULL;
713     }
714   if (data)
715     key_snoopers = g_slist_remove (key_snoopers, data);
716 }
717
718 static gint
719 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
720                          GdkEvent  *event)
721 {
722   GSList *slist;
723   gint return_val = FALSE;
724
725   slist = key_snoopers;
726   while (slist && !return_val)
727     {
728       GtkKeySnooperData *data;
729
730       data = slist->data;
731       slist = slist->next;
732       return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
733     }
734
735   return return_val;
736 }
737
738 guint
739 gtk_timeout_add_full (guint32            interval,
740                       GtkFunction        function,
741                       GtkCallbackMarshal marshal,
742                       gpointer           data,
743                       GtkDestroyNotify   destroy)
744 {
745   static guint timeout_tag = 1;
746   GtkTimeoutFunction *timeoutf;
747   
748   g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
749
750   /* Create a new timeout function structure.
751    * The start time is the current time.
752    */
753   if (!timeout_mem_chunk)
754     timeout_mem_chunk = g_mem_chunk_new ("timeout mem chunk", sizeof (GtkTimeoutFunction),
755                                          1024, G_ALLOC_AND_FREE);
756   
757   timeoutf = g_chunk_new (GtkTimeoutFunction, timeout_mem_chunk);
758   
759   timeoutf->tag = timeout_tag++;
760   timeoutf->start = gdk_time_get ();
761   timeoutf->interval = interval;
762   timeoutf->originterval = interval;
763   timeoutf->function = function;
764   timeoutf->marshal = marshal;
765   timeoutf->data = data;
766   timeoutf->destroy = destroy;
767   
768   gtk_timeout_insert (timeoutf);
769   
770   return timeoutf->tag;
771 }
772
773 static void
774 gtk_timeout_destroy (GtkTimeoutFunction *timeoutf)
775 {
776   if (timeoutf->destroy)
777     (timeoutf->destroy) (timeoutf->data);
778   g_mem_chunk_free (timeout_mem_chunk, timeoutf);
779 }
780
781 guint
782 gtk_timeout_add (guint32     interval,
783                  GtkFunction function,
784                  gpointer    data)
785 {
786   return gtk_timeout_add_full (interval, function, FALSE, data, NULL);
787 }
788
789 guint
790 gtk_timeout_add_interp (guint32            interval,
791                         GtkCallbackMarshal function,
792                         gpointer           data,
793                         GtkDestroyNotify   destroy)
794 {
795   return gtk_timeout_add_full (interval, NULL, function, data, destroy);
796 }
797
798 void
799 gtk_timeout_remove (guint tag)
800 {
801   GtkTimeoutFunction *timeoutf;
802   GList *tmp_list;
803   
804   /* Remove a timeout function.
805    * (Which, basically, involves searching the
806    *  list for the tag).
807    */
808   tmp_list = timeout_functions;
809   while (tmp_list)
810     {
811       timeoutf = tmp_list->data;
812       
813       if (timeoutf->tag == tag)
814         {
815           timeout_functions = g_list_remove_link (timeout_functions, tmp_list);
816           g_list_free (tmp_list);
817           gtk_timeout_destroy (timeoutf);
818           
819           return;
820         }
821       
822       tmp_list = tmp_list->next;
823     }
824   
825   tmp_list = current_timeouts;
826   while (tmp_list)
827     {
828       timeoutf = tmp_list->data;
829       
830       if (timeoutf->tag == tag)
831         {
832           current_timeouts = g_list_remove_link (current_timeouts, tmp_list);
833           g_list_free (tmp_list);
834           gtk_timeout_destroy (timeoutf);
835           
836           return;
837         }
838       
839       tmp_list = tmp_list->next;
840     }
841 }
842
843 /* We rely on some knowledge of how g_list_insert_sorted works to make
844  * sure that we insert at the _end_ of the idles of this priority
845  */
846 static gint
847 gtk_idle_compare (gpointer a, gpointer b)
848 {
849   return (((GtkIdleFunction *)a)->priority < ((GtkIdleFunction *)b)->priority)
850     ? -1 : 1;
851 }
852
853 guint
854 gtk_quit_add_full (guint                main_level,
855                    GtkFunction          function,
856                    GtkCallbackMarshal   marshal,
857                    gpointer             data,
858                    GtkDestroyNotify     destroy)
859 {
860   static guint quit_id = 1;
861   GtkQuitFunction *quitf;
862   
863   g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
864
865   if (!quit_mem_chunk)
866     quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
867                                       512, G_ALLOC_AND_FREE);
868   
869   quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
870   
871   quitf->id = quit_id++;
872   quitf->main_level = main_level;
873   quitf->function = function;
874   quitf->marshal = marshal;
875   quitf->data = data;
876   quitf->destroy = destroy;
877
878   quit_functions = g_list_prepend (quit_functions, quitf);
879   
880   return quitf->id;
881 }
882
883 guint
884 gtk_idle_add_full (gint                 priority,
885                    GtkFunction          function,
886                    GtkCallbackMarshal   marshal,
887                    gpointer             data,
888                    GtkDestroyNotify     destroy)
889 {
890   static guint idle_tag = 1;
891   GtkIdleFunction *idlef;
892   
893   g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
894
895   if (!idle_mem_chunk)
896     idle_mem_chunk = g_mem_chunk_new ("idle mem chunk", sizeof (GtkIdleFunction),
897                                       1024, G_ALLOC_AND_FREE);
898   
899   idlef = g_chunk_new (GtkIdleFunction, idle_mem_chunk);
900   
901   idlef->tag = idle_tag++;
902   idlef->priority = priority;
903   idlef->function = function;
904   idlef->marshal = marshal;
905   idlef->data = data;
906   idlef->destroy = destroy;
907
908   idle_functions = g_list_insert_sorted (idle_functions, idlef, gtk_idle_compare);
909   
910   return idlef->tag;
911 }
912
913 guint
914 gtk_idle_add_interp  (GtkCallbackMarshal   marshal,
915                       gpointer             data,
916                       GtkDestroyNotify     destroy)
917 {
918   return gtk_idle_add_full (GTK_PRIORITY_DEFAULT, NULL, marshal, data, destroy);
919 }
920
921 static void
922 gtk_idle_destroy (GtkIdleFunction *idlef)
923 {
924   if (idlef->destroy)
925     idlef->destroy (idlef->data);
926   g_mem_chunk_free (idle_mem_chunk, idlef);
927 }
928
929 static void
930 gtk_quit_destroy (GtkQuitFunction *quitf)
931 {
932   if (quitf->destroy)
933     quitf->destroy (quitf->data);
934   g_mem_chunk_free (quit_mem_chunk, quitf);
935 }
936
937 guint
938 gtk_quit_add (guint       main_level,
939               GtkFunction function,
940               gpointer    data)
941 {
942   return gtk_quit_add_full (main_level, function, NULL, data, NULL);
943 }
944
945 guint
946 gtk_idle_add (GtkFunction function,
947               gpointer    data)
948 {
949   return gtk_idle_add_full (GTK_PRIORITY_DEFAULT, function, NULL, data, NULL);
950 }
951
952 guint       
953 gtk_idle_add_priority   (gint               priority,
954                          GtkFunction        function,
955                          gpointer           data)
956 {
957   return gtk_idle_add_full (priority, function, NULL, data, NULL);
958 }
959
960 void
961 gtk_quit_remove (guint id)
962 {
963   GtkQuitFunction *quitf;
964   GList *tmp_list;
965   
966   tmp_list = quit_functions;
967   while (tmp_list)
968     {
969       quitf = tmp_list->data;
970       
971       if (quitf->id == id)
972         {
973           quit_functions = g_list_remove_link (quit_functions, tmp_list);
974           g_list_free (tmp_list);
975           gtk_quit_destroy (quitf);
976           
977           return;
978         }
979       
980       tmp_list = tmp_list->next;
981     }
982 }
983
984 void
985 gtk_quit_remove_by_data (gpointer data)
986 {
987   GtkQuitFunction *quitf;
988   GList *tmp_list;
989   
990   tmp_list = quit_functions;
991   while (tmp_list)
992     {
993       quitf = tmp_list->data;
994       
995       if (quitf->data == data)
996         {
997           quit_functions = g_list_remove_link (quit_functions, tmp_list);
998           g_list_free (tmp_list);
999           gtk_quit_destroy (quitf);
1000
1001           return;
1002         }
1003       
1004       tmp_list = tmp_list->next;
1005     }
1006 }
1007
1008 void
1009 gtk_idle_remove (guint tag)
1010 {
1011   GtkIdleFunction *idlef;
1012   GList *tmp_list;
1013   
1014   tmp_list = idle_functions;
1015   while (tmp_list)
1016     {
1017       idlef = tmp_list->data;
1018       
1019       if (idlef->tag == tag)
1020         {
1021           idle_functions = g_list_remove_link (idle_functions, tmp_list);
1022           g_list_free (tmp_list);
1023           gtk_idle_destroy (idlef);
1024           
1025           return;
1026         }
1027       
1028       tmp_list = tmp_list->next;
1029     }
1030   
1031   tmp_list = current_idles;
1032   while (tmp_list)
1033     {
1034       idlef = tmp_list->data;
1035       
1036       if (idlef->tag == tag)
1037         {
1038           current_idles = g_list_remove_link (current_idles, tmp_list);
1039           g_list_free (tmp_list);
1040           gtk_idle_destroy (idlef);
1041           
1042           return;
1043         }
1044       
1045       tmp_list = tmp_list->next;
1046     }
1047 }
1048
1049 void
1050 gtk_idle_remove_by_data (gpointer data)
1051 {
1052   GtkIdleFunction *idlef;
1053   GList *tmp_list;
1054   
1055   tmp_list = idle_functions;
1056   while (tmp_list)
1057     {
1058       idlef = tmp_list->data;
1059       
1060       if (idlef->data == data)
1061         {
1062           idle_functions = g_list_remove_link (idle_functions, tmp_list);
1063           g_list_free (tmp_list);
1064           gtk_idle_destroy (idlef);
1065           
1066           return;
1067         }
1068       
1069       tmp_list = tmp_list->next;
1070     }
1071   
1072   tmp_list = current_idles;
1073   while (tmp_list)
1074     {
1075       idlef = tmp_list->data;
1076       
1077       if (idlef->data == data)
1078         {
1079           current_idles = g_list_remove_link (current_idles, tmp_list);
1080           g_list_free (tmp_list);
1081           gtk_idle_destroy (idlef);
1082           
1083           return;
1084         }
1085       
1086       tmp_list = tmp_list->next;
1087     }
1088 }
1089
1090 static void
1091 gtk_invoke_input_function (GtkInputFunction *input,
1092                            gint source,
1093                            GdkInputCondition condition)
1094 {
1095   GtkArg args[3];
1096   args[0].type = GTK_TYPE_INT;
1097   args[0].name = NULL;
1098   GTK_VALUE_INT(args[0]) = source;
1099   args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1100   args[1].name = NULL;
1101   GTK_VALUE_FLAGS(args[1]) = condition;
1102   args[2].type = GTK_TYPE_NONE;
1103   args[2].name = NULL;
1104
1105   input->callback (NULL, input->data, 2, args);
1106 }
1107
1108 static void
1109 gtk_destroy_input_function (GtkInputFunction *input)
1110 {
1111   if (input->destroy)
1112     (input->destroy) (input->data);
1113   g_free (input);
1114 }
1115
1116 guint
1117 gtk_input_add_full (gint source,
1118                     GdkInputCondition condition,
1119                     GdkInputFunction function,
1120                     GtkCallbackMarshal marshal,
1121                     gpointer data,
1122                     GtkDestroyNotify destroy)
1123 {
1124   if (marshal)
1125     {
1126       GtkInputFunction *input;
1127
1128       input = g_new (GtkInputFunction, 1);
1129       input->callback = marshal;
1130       input->data = data;
1131       input->destroy = destroy;
1132
1133       return gdk_input_add_full (source,
1134                                  condition,
1135                                  (GdkInputFunction) gtk_invoke_input_function,
1136                                  input,
1137                                  (GdkDestroyNotify) gtk_destroy_input_function);
1138     }
1139   else
1140     return gdk_input_add_full (source, condition, function, data, destroy);
1141 }
1142
1143 guint
1144 gtk_input_add_interp (gint source,
1145                       GdkInputCondition condition,
1146                       GtkCallbackMarshal callback,
1147                       gpointer data,
1148                       GtkDestroyNotify destroy)
1149 {
1150   return gtk_input_add_full (source, condition, NULL, callback, data, destroy);
1151 }
1152
1153 void
1154 gtk_input_remove (guint tag)
1155 {
1156   gdk_input_remove (tag);
1157 }
1158
1159 GdkEvent *
1160 gtk_get_current_event ()
1161 {
1162   if (current_events)
1163     return gdk_event_copy ((GdkEvent *) current_events->data);
1164   else
1165     return NULL;
1166 }
1167
1168 GtkWidget*
1169 gtk_get_event_widget (GdkEvent *event)
1170 {
1171   GtkWidget *widget;
1172
1173   widget = NULL;
1174   if (event->any.window)
1175     gdk_window_get_user_data (event->any.window, (void**) &widget);
1176   
1177   return widget;
1178 }
1179
1180 static void
1181 gtk_exit_func ()
1182 {
1183   if (initialized)
1184     {
1185       initialized = FALSE;
1186       gtk_preview_uninit ();
1187     }
1188 }
1189
1190
1191 /* We rely on some knowledge of how g_list_insert_sorted works to make
1192  * sure that we insert after timeouts of equal interval
1193  */
1194 static gint
1195 gtk_timeout_compare (gpointer a, gpointer b)
1196 {
1197   return (((GtkTimeoutFunction *)a)->interval < 
1198           ((GtkTimeoutFunction *)b)->interval)
1199     ? -1 : 1;
1200 }
1201
1202 static void
1203 gtk_timeout_insert (GtkTimeoutFunction *timeoutf)
1204 {
1205   g_assert (timeoutf != NULL);
1206   
1207   /* Insert the timeout function appropriately.
1208    * Appropriately meaning sort it into the list
1209    *  of timeout functions.
1210    */
1211   timeout_functions = g_list_insert_sorted (timeout_functions, timeoutf,
1212                                             gtk_timeout_compare);
1213 }
1214
1215 static gint
1216 gtk_invoke_timeout_function (GtkTimeoutFunction *timeoutf)
1217 {
1218   if (!timeoutf->marshal)
1219     return timeoutf->function (timeoutf->data);
1220   else
1221     {
1222       GtkArg args[1];
1223       gint ret_val = FALSE;
1224       args[0].name = NULL;
1225       args[0].type = GTK_TYPE_BOOL;
1226       args[0].d.pointer_data = &ret_val;
1227       ((GtkCallbackMarshal)timeoutf->function) (NULL,
1228                                                 timeoutf->data,
1229                                                 0, args);
1230       return ret_val;
1231     }
1232 }
1233
1234 static void
1235 gtk_handle_current_timeouts (guint32 the_time)
1236 {
1237   GList *tmp_list;
1238   GtkTimeoutFunction *timeoutf;
1239   
1240   while (current_timeouts)
1241     {
1242       tmp_list = current_timeouts;
1243       timeoutf = tmp_list->data;
1244       
1245       current_timeouts = g_list_remove_link (current_timeouts, tmp_list);
1246       g_list_free (tmp_list);
1247       
1248       if (gtk_invoke_timeout_function (timeoutf) == FALSE)
1249         {
1250           gtk_timeout_destroy (timeoutf);
1251         }
1252       else
1253         {
1254           timeoutf->interval = timeoutf->originterval;
1255           timeoutf->start = the_time;
1256           gtk_timeout_insert (timeoutf);
1257         }
1258     }
1259 }
1260
1261 static void
1262 gtk_handle_timeouts ()
1263 {
1264   guint32 the_time;
1265   GList *tmp_list;
1266   GList *tmp_list2;
1267   GtkTimeoutFunction *timeoutf;
1268   
1269   /* Caller must already have called gtk_handle_current_timeouts if
1270    * necessary */
1271   g_assert (current_timeouts == NULL);
1272   
1273   if (timeout_functions)
1274     {
1275       the_time = gdk_time_get ();
1276       
1277       tmp_list = timeout_functions;
1278       while (tmp_list)
1279         {
1280           timeoutf = tmp_list->data;
1281           
1282           if (timeoutf->interval <= (the_time - timeoutf->start))
1283             {
1284               tmp_list2 = tmp_list;
1285               tmp_list = tmp_list->next;
1286               
1287               timeout_functions = g_list_remove_link (timeout_functions, tmp_list2);
1288               current_timeouts = g_list_concat (current_timeouts, tmp_list2);
1289             }
1290           else
1291             {
1292               timeoutf->interval -= (the_time - timeoutf->start);
1293               timeoutf->start = the_time;
1294               tmp_list = tmp_list->next;
1295             }
1296         }
1297       
1298       if (current_timeouts)
1299         gtk_handle_current_timeouts(the_time);
1300     }
1301 }
1302
1303 static gint
1304 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1305 {
1306   if (!quitf->marshal)
1307     return quitf->function (quitf->data);
1308   else
1309     {
1310       GtkArg args[1];
1311       gint ret_val = FALSE;
1312
1313       args[0].name = NULL;
1314       args[0].type = GTK_TYPE_BOOL;
1315       args[0].d.pointer_data = &ret_val;
1316       ((GtkCallbackMarshal) quitf->marshal) (NULL,
1317                                              quitf->data,
1318                                              0, args);
1319       return ret_val;
1320     }
1321 }
1322
1323 static gint
1324 gtk_idle_invoke_function (GtkIdleFunction *idlef)
1325 {
1326   if (!idlef->marshal)
1327     return idlef->function (idlef->data);
1328   else
1329     {
1330       GtkArg args[1];
1331       gint ret_val = FALSE;
1332
1333       args[0].name = NULL;
1334       args[0].type = GTK_TYPE_BOOL;
1335       args[0].d.pointer_data = &ret_val;
1336       ((GtkCallbackMarshal) idlef->marshal) (NULL,
1337                                              idlef->data,
1338                                              0, args);
1339       return ret_val;
1340     }
1341 }
1342
1343 static void
1344 gtk_handle_current_idles ()
1345 {
1346   GList *tmp_list;
1347   GList *tmp_list2;
1348   GtkIdleFunction *idlef;
1349   
1350   while (current_idles)
1351     {
1352       tmp_list = current_idles;
1353       idlef = tmp_list->data;
1354       
1355       current_idles = g_list_remove_link (current_idles, tmp_list);
1356       
1357       if (gtk_idle_invoke_function (idlef) == FALSE)
1358         {
1359           g_list_free (tmp_list);
1360           gtk_idle_destroy (idlef);
1361         }
1362       else
1363         {
1364           /* Insert the idle function back into the list of idle
1365            * functions at the end of the idles of this priority
1366            */
1367           tmp_list2 = idle_functions;
1368           while (tmp_list2 &&
1369                  (((GtkIdleFunction *)tmp_list2->data)->priority <= idlef->priority))
1370             tmp_list2 = tmp_list2->next;
1371
1372           if (!tmp_list2)
1373             idle_functions = g_list_concat (idle_functions, tmp_list);
1374           else if (tmp_list2 == idle_functions)
1375             {
1376               tmp_list->next = idle_functions;
1377               if (idle_functions)
1378                 idle_functions->prev = tmp_list;
1379               idle_functions = tmp_list;
1380             }
1381           else
1382             {
1383               tmp_list->prev = tmp_list2->prev;
1384               tmp_list->next = tmp_list2;
1385               tmp_list2->prev->next = tmp_list;
1386               tmp_list2->prev = tmp_list;
1387             }
1388         }
1389     }
1390 }
1391
1392 static void
1393 gtk_handle_idle ()
1394 {
1395   /* Caller must already have called gtk_handle_current_idles if
1396    * necessary
1397    */
1398   g_assert (current_idles == NULL);
1399   
1400   /* Handle only the idle functions that have the highest priority */
1401   if (idle_functions)
1402     {
1403       GList *tmp_list;
1404       gint top_priority;
1405
1406       tmp_list = idle_functions;
1407       top_priority = ((GtkIdleFunction *)tmp_list->data)->priority;
1408  
1409       while (tmp_list &&
1410              (((GtkIdleFunction *)tmp_list->data)->priority == top_priority))
1411         tmp_list = tmp_list->next;
1412
1413       current_idles = idle_functions;
1414       idle_functions = tmp_list;
1415
1416       if (tmp_list) 
1417         {
1418           tmp_list->prev->next = NULL;
1419           tmp_list->prev = NULL;
1420         }
1421       
1422       gtk_handle_current_idles();
1423     }
1424 }
1425
1426 static void
1427 gtk_handle_timer ()
1428 {
1429   GtkTimeoutFunction *timeoutf;
1430   
1431   if (idle_functions)
1432     {
1433       gdk_timer_set (0);
1434       gdk_timer_enable ();
1435     }
1436   else if (timeout_functions)
1437     {
1438       timeoutf = timeout_functions->data;
1439       gdk_timer_set (timeoutf->interval);
1440       gdk_timer_enable ();
1441     }
1442   else
1443     {
1444       gdk_timer_set (0);
1445       gdk_timer_disable ();
1446     }
1447 }
1448
1449 static void
1450 gtk_propagate_event (GtkWidget *widget,
1451                      GdkEvent  *event)
1452 {
1453   GtkWidget *parent;
1454   GtkWidget *tmp;
1455   gint handled_event;
1456   
1457   g_return_if_fail (widget != NULL);
1458   g_return_if_fail (event != NULL);
1459   
1460   handled_event = FALSE;
1461   gtk_widget_ref (widget);
1462
1463   if ((event->type == GDK_KEY_PRESS) ||
1464       (event->type == GDK_KEY_RELEASE))
1465     {
1466
1467       /* Only send key events to window widgets.
1468        *  The window widget will in turn pass the
1469        *  key event on to the currently focused widget
1470        *  for that window.
1471        */
1472       parent = gtk_widget_get_ancestor (widget, gtk_window_get_type ());
1473       handled_event = (parent &&
1474                        GTK_WIDGET_IS_SENSITIVE (parent) &&
1475                        gtk_widget_event (parent, event));
1476     }
1477   
1478   /* Other events get propagated up the widget tree
1479    *  so that parents can see the button and motion
1480    *  events of the children.
1481    */
1482   tmp = widget;
1483   while (!handled_event && tmp)
1484     {
1485       gtk_widget_ref (tmp);
1486       handled_event = !GTK_WIDGET_IS_SENSITIVE (tmp) || gtk_widget_event (tmp, event);
1487       parent = tmp->parent;
1488       gtk_widget_unref (tmp);
1489       tmp = parent;
1490     }
1491
1492   gtk_widget_unref (widget);
1493 }
1494
1495
1496 static void
1497 gtk_error (gchar *str)
1498 {
1499   gtk_print (str);
1500 }
1501
1502 static void
1503 gtk_warning (gchar *str)
1504 {
1505   gtk_print (str);
1506 }
1507
1508 static void
1509 gtk_message (gchar *str)
1510 {
1511   gtk_print (str);
1512 }
1513
1514 static void
1515 gtk_print (gchar *str)
1516 {
1517   static GtkWidget *window = NULL;
1518   static GtkWidget *text;
1519   static int level = 0;
1520   GtkWidget *box1;
1521   GtkWidget *box2;
1522   GtkWidget *table;
1523   GtkWidget *hscrollbar;
1524   GtkWidget *vscrollbar;
1525   GtkWidget *separator;
1526   GtkWidget *button;
1527   
1528   if (level > 0)
1529     {
1530       fputs (str, stdout);
1531       fflush (stdout);
1532       return;
1533     }
1534   
1535   if (!window)
1536     {
1537       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1538       
1539       gtk_signal_connect (GTK_OBJECT (window), "destroy",
1540                           (GtkSignalFunc) gtk_widget_destroyed,
1541                           &window);
1542       
1543       gtk_window_set_title (GTK_WINDOW (window), "Messages");
1544       
1545       box1 = gtk_vbox_new (FALSE, 0);
1546       gtk_container_add (GTK_CONTAINER (window), box1);
1547       gtk_widget_show (box1);
1548       
1549       
1550       box2 = gtk_vbox_new (FALSE, 10);
1551       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1552       gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1553       gtk_widget_show (box2);
1554       
1555       
1556       table = gtk_table_new (2, 2, FALSE);
1557       gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1558       gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1559       gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1560       gtk_widget_show (table);
1561       
1562       text = gtk_text_new (NULL, NULL);
1563       gtk_text_set_editable (GTK_TEXT (text), FALSE);
1564       gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1565       gtk_widget_show (text);
1566       gtk_widget_realize (text);
1567       
1568       hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1569       gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1570                         GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1571       gtk_widget_show (hscrollbar);
1572       
1573       vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1574       gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1575                         GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1576       gtk_widget_show (vscrollbar);
1577       
1578       separator = gtk_hseparator_new ();
1579       gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1580       gtk_widget_show (separator);
1581       
1582       
1583       box2 = gtk_vbox_new (FALSE, 10);
1584       gtk_container_border_width (GTK_CONTAINER (box2), 10);
1585       gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1586       gtk_widget_show (box2);
1587       
1588       
1589       button = gtk_button_new_with_label ("close");
1590       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1591                                  (GtkSignalFunc) gtk_widget_hide,
1592                                  GTK_OBJECT (window));
1593       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1594       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1595       gtk_widget_grab_default (button);
1596       gtk_widget_show (button);
1597     }
1598   
1599   level += 1;
1600   gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1601   level -= 1;
1602   
1603   if (!GTK_WIDGET_VISIBLE (window))
1604     gtk_widget_show (window);
1605 }