1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #ifdef GDK_WINDOWING_X11
28 #include <X11/Xlocale.h> /* so we get the right setlocale */
36 #include "gtkbutton.h"
38 #include "gtkcompat.h"
39 #include "gtkhscrollbar.h"
40 #include "gtkhseparator.h"
42 #include "gtkpreview.h"
44 #include "gtkscrolledwindow.h"
45 #include "gtkselection.h"
46 #include "gtksignal.h"
50 #include "gtkvscrollbar.h"
51 #include "gtkwidget.h"
52 #include "gtkwindow.h"
53 #include "gtkprivate.h"
54 #include "gdk/gdki18n.h"
59 /* Private type definitions
61 typedef struct _GtkInitFunction GtkInitFunction;
62 typedef struct _GtkQuitFunction GtkQuitFunction;
63 typedef struct _GtkClosure GtkClosure;
64 typedef struct _GtkKeySnooperData GtkKeySnooperData;
66 struct _GtkInitFunction
72 struct _GtkQuitFunction
76 GtkCallbackMarshal marshal;
79 GtkDestroyNotify destroy;
84 GtkCallbackMarshal marshal;
86 GtkDestroyNotify destroy;
89 struct _GtkKeySnooperData
96 static void gtk_exit_func (void);
97 static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
98 static void gtk_quit_destroy (GtkQuitFunction *quitf);
99 static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
102 static void gtk_destroy_closure (gpointer data);
103 static gboolean gtk_invoke_idle_timeout (gpointer data);
104 static void gtk_invoke_input (gpointer data,
106 GdkInputCondition condition);
109 static void gtk_error (gchar *str);
110 static void gtk_warning (gchar *str);
111 static void gtk_message (gchar *str);
112 static void gtk_print (gchar *str);
115 const guint gtk_major_version = GTK_MAJOR_VERSION;
116 const guint gtk_minor_version = GTK_MINOR_VERSION;
117 const guint gtk_micro_version = GTK_MICRO_VERSION;
118 const guint gtk_binary_age = GTK_BINARY_AGE;
119 const guint gtk_interface_age = GTK_INTERFACE_AGE;
121 static guint gtk_main_loop_level = 0;
122 static gint gtk_initialized = FALSE;
123 static GList *current_events = NULL;
125 static GSList *main_loops = NULL; /* stack of currently executing main loops */
127 static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
128 * widget is the first one on the list.
130 static GList *init_functions = NULL; /* A list of init functions.
132 static GList *quit_functions = NULL; /* A list of quit functions.
134 static GMemChunk *quit_mem_chunk = NULL;
136 static GSList *key_snoopers = NULL;
138 static GdkVisual *gtk_visual; /* The visual to be used in creating new
141 static GdkColormap *gtk_colormap; /* The colormap to be used in creating new
145 guint gtk_debug_flags = 0; /* Global GTK debug flag */
147 #ifdef G_ENABLE_DEBUG
148 static const GDebugKey gtk_debug_keys[] = {
149 {"objects", GTK_DEBUG_OBJECTS},
150 {"misc", GTK_DEBUG_MISC},
151 {"signals", GTK_DEBUG_SIGNALS},
152 {"dnd", GTK_DEBUG_DND},
153 {"plugsocket", GTK_DEBUG_PLUGSOCKET}
156 static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
158 #endif /* G_ENABLE_DEBUG */
161 gtk_check_version (guint required_major,
162 guint required_minor,
163 guint required_micro)
165 if (required_major > GTK_MAJOR_VERSION)
166 return "Gtk+ version too old (major mismatch)";
167 if (required_major < GTK_MAJOR_VERSION)
168 return "Gtk+ version too new (major mismatch)";
169 if (required_minor > GTK_MINOR_VERSION)
170 return "Gtk+ version too old (minor mismatch)";
171 if (required_minor < GTK_MINOR_VERSION)
172 return "Gtk+ version too new (minor mismatch)";
173 if (required_micro < GTK_MICRO_VERSION - GTK_BINARY_AGE)
174 return "Gtk+ version too new (micro mismatch)";
175 if (required_micro > GTK_MICRO_VERSION)
176 return "Gtk+ version too old (micro mismatch)";
181 static gchar *add_dll_suffix(gchar *module_name)
183 gchar *suffix = strrchr(module_name, '.');
185 if (!suffix || stricmp(suffix, ".dll"))
187 gchar *old = module_name;
189 module_name = g_strconcat (module_name, ".dll", NULL);
192 return (module_name);
197 gtk_init_check (int *argc,
200 GSList *gtk_modules = NULL;
202 gchar *env_string = NULL;
208 g_set_error_handler (gtk_error);
209 g_set_warning_handler (gtk_warning);
210 g_set_message_handler (gtk_message);
211 g_set_print_handler (gtk_print);
214 /* Initialize "gdk". We pass along the 'argc' and 'argv'
215 * parameters as they contain information that GDK uses
217 if (!gdk_init_check (argc, argv))
220 gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
222 #ifdef G_ENABLE_DEBUG
223 env_string = getenv ("GTK_DEBUG");
224 if (env_string != NULL)
226 gtk_debug_flags = g_parse_debug_string (env_string,
231 #endif /* G_ENABLE_DEBUG */
233 env_string = getenv ("GTK_MODULES");
236 gchar **modules, **as;
239 modules = g_strsplit (env_string, G_SEARCHPATH_SEPARATOR_S, -1);
241 modules = g_strsplit (env_string, ";", -1);
243 for (as = modules; *as; as++)
246 gtk_modules = g_slist_prepend (gtk_modules, *as);
258 for (i = 1; i < *argc;)
260 if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
261 strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
263 gchar *module_name = (*argv)[i] + 12;
265 if (*module_name == '=')
267 else if (i + 1 < *argc)
271 module_name = (*argv)[i];
275 if (module_name && *module_name)
276 gtk_modules = g_slist_prepend (gtk_modules, g_strdup (module_name));
278 else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
280 GLogLevelFlags fatal_mask;
282 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
283 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
284 g_log_set_always_fatal (fatal_mask);
287 #ifdef G_ENABLE_DEBUG
288 else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
289 (strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
291 gchar *equal_pos = strchr ((*argv)[i], '=');
293 if (equal_pos != NULL)
295 gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
299 else if ((i + 1) < *argc && (*argv)[i + 1])
301 gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
309 else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
310 (strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 0))
312 gchar *equal_pos = strchr ((*argv)[i], '=');
314 if (equal_pos != NULL)
316 gtk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
320 else if ((i + 1) < *argc && (*argv)[i + 1])
322 gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
330 #endif /* G_ENABLE_DEBUG */
334 for (i = 1; i < *argc; i++)
336 for (k = i; k < *argc; k++)
337 if ((*argv)[k] != NULL)
343 for (j = i + k; j < *argc; j++)
344 (*argv)[j-k] = (*argv)[j];
350 /* load gtk modules */
351 gtk_modules = g_slist_reverse (gtk_modules);
352 for (slist = gtk_modules; slist; slist = slist->next)
355 GModule *module = NULL;
356 GtkModuleInitFunc modinit_func = NULL;
358 module_name = slist->data;
361 if (!g_path_is_absolute (module_name))
363 gchar *old = module_name;
365 module_name = g_module_build_path (NULL, module_name);
369 module_name = add_dll_suffix(module_name);
371 if (g_module_supported ())
373 module = g_module_open (module_name, G_MODULE_BIND_LAZY);
375 g_module_symbol (module, "gtk_module_init", (gpointer*) &modinit_func) &&
378 if (!g_slist_find (gtk_modules, modinit_func))
380 g_module_make_resident (module);
381 slist->data = modinit_func;
385 g_module_close (module);
392 g_warning ("Failed to load module \"%s\": %s",
393 module ? g_module_name (module) : module_name,
396 g_module_close (module);
398 g_free (module_name);
403 bindtextdomain("gtk+", GTK_LOCALEDIR);
406 /* GTk+ locale dir is %WinDir%\gtk+\locale */
407 extern char *get_gtk_sysconf_directory ();
408 bindtextdomain ("gtk+", g_strconcat (get_gtk_sysconf_directory (),
416 /* Initialize the default visual and colormap to be
417 * used in creating widgets. (We want to use the system
418 * defaults so as to be nice to the colormap).
420 gtk_visual = gdk_visual_get_system ();
421 gtk_colormap = gdk_colormap_get_system ();
428 /* Register an exit function to make sure we are able to cleanup.
430 g_atexit (gtk_exit_func);
432 /* Set the 'initialized' flag.
434 gtk_initialized = TRUE;
436 /* initialize gtk modules
438 for (slist = gtk_modules; slist; slist = slist->next)
442 GtkModuleInitFunc modinit;
444 modinit = slist->data;
445 modinit (argc, argv);
448 g_slist_free (gtk_modules);
451 /* No use warning on Win32, there aren't any non-devel versions anyhow... */
452 g_warning ("" "YOU ARE USING THE DEVEL BRANCH 1.3.x OF GTK+ WHICH IS CURRENTLY\n"
453 " UNDER HEAVY DEVELOPMENT AND FREQUENTLY INTRODUCES INSTABILITIES.\n"
454 " if you don't know why you are getting this, you probably want to\n"
455 " use the stable branch which can be retrived from\n"
456 " ftp://ftp.gtk.org/pub/gtk/v1.2/ or via CVS with\n"
457 " cvs checkout -r glib-1-2 glib; cvs checkout -r gtk-1-2 gtk+");
463 gtk_init (int *argc, char ***argv)
465 if (!gtk_init_check (argc, argv))
467 g_warning ("cannot open display: %s", gdk_get_display ());
473 gtk_exit (gint errorcode)
475 /* Only if "gtk" has been initialized should we de-initialize.
477 /* de-initialisation is done by the gtk_exit_funct(),
478 * no need to do this here (Alex J.)
484 gtk_set_locale (void)
486 return gdk_set_locale ();
494 GtkInitFunction *init;
497 gtk_main_loop_level++;
499 loop = g_main_new (TRUE);
500 main_loops = g_slist_prepend (main_loops, loop);
502 tmp_list = functions = init_functions;
503 init_functions = NULL;
507 init = tmp_list->data;
508 tmp_list = tmp_list->next;
510 (* init->function) (init->data);
513 g_list_free (functions);
515 if (g_main_is_running (main_loops->data))
517 GDK_THREADS_LEAVE ();
519 GDK_THREADS_ENTER ();
525 GList *reinvoke_list = NULL;
526 GtkQuitFunction *quitf;
528 while (quit_functions)
530 quitf = quit_functions->data;
532 tmp_list = quit_functions;
533 quit_functions = g_list_remove_link (quit_functions, quit_functions);
534 g_list_free_1 (tmp_list);
536 if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
537 gtk_quit_invoke_function (quitf))
539 reinvoke_list = g_list_prepend (reinvoke_list, quitf);
543 gtk_quit_destroy (quitf);
550 work = g_list_last (reinvoke_list);
552 quit_functions->prev = work;
553 work->next = quit_functions;
554 quit_functions = work;
560 main_loops = g_slist_remove (main_loops, loop);
562 g_main_destroy (loop);
564 gtk_main_loop_level--;
568 gtk_main_level (void)
570 return gtk_main_loop_level;
576 g_return_if_fail (main_loops != NULL);
578 g_main_quit (main_loops->data);
582 gtk_events_pending (void)
586 GDK_THREADS_LEAVE ();
587 result = g_main_pending();
588 GDK_THREADS_ENTER ();
594 gtk_main_iteration (void)
596 GDK_THREADS_LEAVE ();
597 g_main_iteration (TRUE);
598 GDK_THREADS_ENTER ();
601 return !g_main_is_running (main_loops->data);
607 gtk_main_iteration_do (gboolean blocking)
609 GDK_THREADS_LEAVE ();
610 g_main_iteration (blocking);
611 GDK_THREADS_ENTER ();
614 return !g_main_is_running (main_loops->data);
620 gtk_main_do_event (GdkEvent *event)
622 GtkWidget *event_widget;
623 GtkWidget *grab_widget;
624 GdkEvent *next_event;
627 /* If there are any events pending then get the next one.
629 next_event = gdk_event_peek ();
631 /* Try to compress enter/leave notify events. These event
632 * pairs occur when the mouse is dragged quickly across
633 * a window with many buttons (or through a menu). Instead
634 * of highlighting and de-highlighting each widget that
635 * is crossed it is better to simply de-highlight the widget
636 * which contained the mouse initially and highlight the
637 * widget which ends up containing the mouse.
640 if (((event->type == GDK_ENTER_NOTIFY) ||
641 (event->type == GDK_LEAVE_NOTIFY)) &&
642 ((next_event->type == GDK_ENTER_NOTIFY) ||
643 (next_event->type == GDK_LEAVE_NOTIFY)) &&
644 (next_event->type != event->type) &&
645 (next_event->any.window == event->any.window))
647 /* Throw both the peeked copy and the queued copy away
649 gdk_event_free (next_event);
650 next_event = gdk_event_get ();
651 gdk_event_free (next_event);
657 gdk_event_free (next_event);
659 /* Find the widget which got the event. We store the widget
660 * in the user_data field of GdkWindow's.
661 * Ignore the event if we don't have a widget for it, except
662 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
663 * Though this happens rarely, bogus events can occour
664 * for e.g. destroyed GdkWindows.
666 event_widget = gtk_get_event_widget (event);
669 /* To handle selection INCR transactions, we select
670 * PropertyNotify events on the requestor window and create
671 * a corresponding (fake) GdkWindow so that events get
672 * here. There won't be a widget though, so we have to handle
675 if (event->type == GDK_PROPERTY_NOTIFY)
676 gtk_selection_incr_event (event->any.window,
682 /* Push the event onto a stack of current events for
683 * gtk_current_event_get().
685 current_events = g_list_prepend (current_events, event);
687 /* If there is a grab in effect...
691 grab_widget = grabs->data;
693 /* If the grab widget is an ancestor of the event widget
694 * then we send the event to the original event widget.
695 * This is the key to implementing modality.
697 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
698 gtk_widget_is_ancestor (event_widget, grab_widget))
699 grab_widget = event_widget;
703 grab_widget = event_widget;
706 /* Not all events get sent to the grabbing widget.
707 * The delete, destroy, expose, focus change and resize
708 * events still get sent to the event widget because
709 * 1) these events have no meaning for the grabbing widget
710 * and 2) redirecting these events to the grabbing widget
711 * could cause the display to be messed up.
713 * Drag events are also not redirected, since it isn't
714 * clear what the semantics of that would be.
722 gtk_widget_ref (event_widget);
723 if ((!grabs || gtk_widget_get_toplevel (grabs->data) == event_widget) &&
724 !gtk_widget_event (event_widget, event))
725 gtk_widget_destroy (event_widget);
726 gtk_widget_unref (event_widget);
730 /* Unexpected GDK_DESTROY from the outside, ignore for
731 * child windows, handle like a GDK_DELETE for toplevels
733 if (!event_widget->parent)
735 gtk_widget_ref (event_widget);
736 if (!gtk_widget_event (event_widget, event) &&
737 !GTK_OBJECT_DESTROYED (event_widget))
738 gtk_widget_destroy (event_widget);
739 gtk_widget_unref (event_widget);
744 if (event->any.window)
745 gdk_window_begin_paint_rect (event->any.window, &event->expose.area);
747 gtk_widget_event (event_widget, event);
749 if (event->any.window)
750 gdk_window_end_paint (event->any.window);
753 case GDK_PROPERTY_NOTIFY:
755 case GDK_FOCUS_CHANGE:
759 case GDK_SELECTION_CLEAR:
760 case GDK_SELECTION_REQUEST:
761 case GDK_SELECTION_NOTIFY:
762 case GDK_CLIENT_EVENT:
763 case GDK_VISIBILITY_NOTIFY:
764 gtk_widget_event (event_widget, event);
768 case GDK_BUTTON_PRESS:
769 case GDK_2BUTTON_PRESS:
770 case GDK_3BUTTON_PRESS:
771 gtk_propagate_event (grab_widget, event);
775 case GDK_KEY_RELEASE:
778 if (gtk_invoke_key_snoopers (grab_widget, event))
781 /* else fall through */
782 case GDK_MOTION_NOTIFY:
783 case GDK_BUTTON_RELEASE:
784 case GDK_PROXIMITY_IN:
785 case GDK_PROXIMITY_OUT:
786 gtk_propagate_event (grab_widget, event);
789 case GDK_ENTER_NOTIFY:
790 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
792 gtk_widget_event (grab_widget, event);
793 if (event_widget == grab_widget)
794 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
798 case GDK_LEAVE_NOTIFY:
799 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
801 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
802 gtk_widget_event (event_widget, event);
804 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
805 gtk_widget_event (grab_widget, event);
808 case GDK_DRAG_STATUS:
809 case GDK_DROP_FINISHED:
810 gtk_drag_source_handle_event (event_widget, event);
814 case GDK_DRAG_MOTION:
816 gtk_drag_dest_handle_event (event_widget, event);
820 tmp_list = current_events;
821 current_events = g_list_remove_link (current_events, tmp_list);
822 g_list_free_1 (tmp_list);
838 gtk_grab_add (GtkWidget *widget)
840 g_return_if_fail (widget != NULL);
842 if (!GTK_WIDGET_HAS_GRAB (widget))
844 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
846 grabs = g_slist_prepend (grabs, widget);
847 gtk_widget_ref (widget);
852 gtk_grab_get_current (void)
855 return GTK_WIDGET (grabs->data);
860 gtk_grab_remove (GtkWidget *widget)
862 g_return_if_fail (widget != NULL);
864 if (GTK_WIDGET_HAS_GRAB (widget))
866 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
868 grabs = g_slist_remove (grabs, widget);
869 gtk_widget_unref (widget);
874 gtk_init_add (GtkFunction function,
877 GtkInitFunction *init;
879 init = g_new (GtkInitFunction, 1);
880 init->function = function;
883 init_functions = g_list_prepend (init_functions, init);
887 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
890 GtkKeySnooperData *data;
891 static guint snooper_id = 1;
893 g_return_val_if_fail (snooper != NULL, 0);
895 data = g_new (GtkKeySnooperData, 1);
896 data->func = snooper;
897 data->func_data = func_data;
898 data->id = snooper_id++;
899 key_snoopers = g_slist_prepend (key_snoopers, data);
905 gtk_key_snooper_remove (guint snooper_id)
907 GtkKeySnooperData *data = NULL;
910 slist = key_snoopers;
914 if (data->id == snooper_id)
921 key_snoopers = g_slist_remove (key_snoopers, data);
925 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
929 gint return_val = FALSE;
931 slist = key_snoopers;
932 while (slist && !return_val)
934 GtkKeySnooperData *data;
938 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
945 gtk_quit_add_full (guint main_level,
946 GtkFunction function,
947 GtkCallbackMarshal marshal,
949 GtkDestroyNotify destroy)
951 static guint quit_id = 1;
952 GtkQuitFunction *quitf;
954 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
957 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
958 512, G_ALLOC_AND_FREE);
960 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
962 quitf->id = quit_id++;
963 quitf->main_level = main_level;
964 quitf->function = function;
965 quitf->marshal = marshal;
967 quitf->destroy = destroy;
969 quit_functions = g_list_prepend (quit_functions, quitf);
975 gtk_quit_destroy (GtkQuitFunction *quitf)
978 quitf->destroy (quitf->data);
979 g_mem_chunk_free (quit_mem_chunk, quitf);
983 gtk_quit_destructor (GtkObject **object_p)
986 gtk_object_destroy (*object_p);
993 gtk_quit_add_destroy (guint main_level,
996 GtkObject **object_p;
998 g_return_if_fail (main_level > 0);
999 g_return_if_fail (object != NULL);
1000 g_return_if_fail (GTK_IS_OBJECT (object));
1002 object_p = g_new (GtkObject*, 1);
1004 gtk_signal_connect (object,
1006 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1008 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
1012 gtk_quit_add (guint main_level,
1013 GtkFunction function,
1016 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
1020 gtk_quit_remove (guint id)
1022 GtkQuitFunction *quitf;
1025 tmp_list = quit_functions;
1028 quitf = tmp_list->data;
1030 if (quitf->id == id)
1032 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1033 g_list_free (tmp_list);
1034 gtk_quit_destroy (quitf);
1039 tmp_list = tmp_list->next;
1044 gtk_quit_remove_by_data (gpointer data)
1046 GtkQuitFunction *quitf;
1049 tmp_list = quit_functions;
1052 quitf = tmp_list->data;
1054 if (quitf->data == data)
1056 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1057 g_list_free (tmp_list);
1058 gtk_quit_destroy (quitf);
1063 tmp_list = tmp_list->next;
1068 gtk_timeout_add_full (guint32 interval,
1069 GtkFunction function,
1070 GtkCallbackMarshal marshal,
1072 GtkDestroyNotify destroy)
1076 GtkClosure *closure;
1078 closure = g_new (GtkClosure, 1);
1079 closure->marshal = marshal;
1080 closure->data = data;
1081 closure->destroy = destroy;
1083 return g_timeout_add_full (0, interval,
1084 gtk_invoke_idle_timeout,
1086 gtk_destroy_closure);
1089 return g_timeout_add_full (0, interval, function, data, destroy);
1093 gtk_timeout_add (guint32 interval,
1094 GtkFunction function,
1097 return g_timeout_add_full (0, interval, function, data, NULL);
1101 gtk_timeout_remove (guint tag)
1103 g_source_remove (tag);
1107 gtk_idle_add_full (gint priority,
1108 GtkFunction function,
1109 GtkCallbackMarshal marshal,
1111 GtkDestroyNotify destroy)
1115 GtkClosure *closure;
1117 closure = g_new (GtkClosure, 1);
1118 closure->marshal = marshal;
1119 closure->data = data;
1120 closure->destroy = destroy;
1122 return g_idle_add_full (priority,
1123 gtk_invoke_idle_timeout,
1125 gtk_destroy_closure);
1128 return g_idle_add_full (priority, function, data, destroy);
1132 gtk_idle_add (GtkFunction function,
1135 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1139 gtk_idle_add_priority (gint priority,
1140 GtkFunction function,
1143 return g_idle_add_full (priority, function, data, NULL);
1147 gtk_idle_remove (guint tag)
1149 g_source_remove (tag);
1153 gtk_idle_remove_by_data (gpointer data)
1155 if (!g_idle_remove_by_data (data))
1156 g_warning ("gtk_idle_remove_by_data(%p): no such idle", data);
1160 gtk_input_add_full (gint source,
1161 GdkInputCondition condition,
1162 GdkInputFunction function,
1163 GtkCallbackMarshal marshal,
1165 GtkDestroyNotify destroy)
1169 GtkClosure *closure;
1171 closure = g_new (GtkClosure, 1);
1172 closure->marshal = marshal;
1173 closure->data = data;
1174 closure->destroy = destroy;
1176 return gdk_input_add_full (source,
1178 (GdkInputFunction) gtk_invoke_input,
1180 (GdkDestroyNotify) gtk_destroy_closure);
1183 return gdk_input_add_full (source, condition, function, data, destroy);
1187 gtk_input_remove (guint tag)
1189 g_source_remove (tag);
1193 gtk_destroy_closure (gpointer data)
1195 GtkClosure *closure = data;
1197 if (closure->destroy)
1198 (closure->destroy) (closure->data);
1203 gtk_invoke_idle_timeout (gpointer data)
1205 GtkClosure *closure = data;
1208 gint ret_val = FALSE;
1209 args[0].name = NULL;
1210 args[0].type = GTK_TYPE_BOOL;
1211 args[0].d.pointer_data = &ret_val;
1212 closure->marshal (NULL, closure->data, 0, args);
1217 gtk_invoke_input (gpointer data,
1219 GdkInputCondition condition)
1221 GtkClosure *closure = data;
1224 args[0].type = GTK_TYPE_INT;
1225 args[0].name = NULL;
1226 GTK_VALUE_INT(args[0]) = source;
1227 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1228 args[1].name = NULL;
1229 GTK_VALUE_FLAGS(args[1]) = condition;
1230 args[2].type = GTK_TYPE_NONE;
1231 args[2].name = NULL;
1233 closure->marshal (NULL, closure->data, 2, args);
1237 gtk_get_current_event (void)
1240 return gdk_event_copy ((GdkEvent *) current_events->data);
1246 gtk_get_event_widget (GdkEvent *event)
1251 if (event && event->any.window)
1252 gdk_window_get_user_data (event->any.window, (void**) &widget);
1258 gtk_exit_func (void)
1260 if (gtk_initialized)
1262 gtk_initialized = FALSE;
1263 gtk_preview_uninit ();
1269 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1271 if (!quitf->marshal)
1272 return quitf->function (quitf->data);
1276 gint ret_val = FALSE;
1278 args[0].name = NULL;
1279 args[0].type = GTK_TYPE_BOOL;
1280 args[0].d.pointer_data = &ret_val;
1281 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1289 gtk_propagate_event (GtkWidget *widget,
1294 g_return_if_fail (widget != NULL);
1295 g_return_if_fail (GTK_IS_WIDGET (widget));
1296 g_return_if_fail (event != NULL);
1298 handled_event = FALSE;
1300 if ((event->type == GDK_KEY_PRESS) ||
1301 (event->type == GDK_KEY_RELEASE))
1303 /* Only send key events within Window widgets to the Window
1304 * The Window widget will in turn pass the
1305 * key event on to the currently focused widget
1310 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1313 if (GTK_WIDGET_IS_SENSITIVE (window))
1314 gtk_widget_event (window, event);
1316 handled_event = TRUE; /* don't send to widget */
1320 /* Other events get propagated up the widget tree
1321 * so that parents can see the button and motion
1322 * events of the children.
1324 while (!handled_event && widget)
1328 gtk_widget_ref (widget);
1329 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1330 tmp = widget->parent;
1331 gtk_widget_unref (widget);
1338 gtk_error (gchar *str)
1344 gtk_warning (gchar *str)
1350 gtk_message (gchar *str)
1356 gtk_print (gchar *str)
1358 static GtkWidget *window = NULL;
1359 static GtkWidget *text;
1360 static int level = 0;
1364 GtkWidget *hscrollbar;
1365 GtkWidget *vscrollbar;
1366 GtkWidget *separator;
1371 fputs (str, stdout);
1378 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1380 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1381 (GtkSignalFunc) gtk_widget_destroyed,
1384 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1386 box1 = gtk_vbox_new (FALSE, 0);
1387 gtk_container_add (GTK_CONTAINER (window), box1);
1388 gtk_widget_show (box1);
1391 box2 = gtk_vbox_new (FALSE, 10);
1392 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1393 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1394 gtk_widget_show (box2);
1397 table = gtk_table_new (2, 2, FALSE);
1398 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1399 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1400 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1401 gtk_widget_show (table);
1403 text = gtk_text_new (NULL, NULL);
1404 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1405 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1406 gtk_widget_show (text);
1407 gtk_widget_realize (text);
1409 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1410 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1411 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1412 gtk_widget_show (hscrollbar);
1414 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1415 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1416 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1417 gtk_widget_show (vscrollbar);
1419 separator = gtk_hseparator_new ();
1420 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1421 gtk_widget_show (separator);
1424 box2 = gtk_vbox_new (FALSE, 10);
1425 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1426 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1427 gtk_widget_show (box2);
1430 button = gtk_button_new_with_label ("close");
1431 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1432 (GtkSignalFunc) gtk_widget_hide,
1433 GTK_OBJECT (window));
1434 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1435 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1436 gtk_widget_grab_default (button);
1437 gtk_widget_show (button);
1441 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1444 if (!GTK_WIDGET_VISIBLE (window))
1445 gtk_widget_show (window);