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 extern void gtk_object_post_arg_parsing_init (void);
201 GSList *gtk_modules = NULL;
203 gchar *env_string = NULL;
209 g_set_error_handler (gtk_error);
210 g_set_warning_handler (gtk_warning);
211 g_set_message_handler (gtk_message);
212 g_set_print_handler (gtk_print);
215 /* Initialize "gdk". We pass along the 'argc' and 'argv'
216 * parameters as they contain information that GDK uses
218 if (!gdk_init_check (argc, argv))
221 gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
223 #ifdef G_ENABLE_DEBUG
224 env_string = getenv ("GTK_DEBUG");
225 if (env_string != NULL)
227 gtk_debug_flags = g_parse_debug_string (env_string,
232 #endif /* G_ENABLE_DEBUG */
234 env_string = getenv ("GTK_MODULES");
237 gchar **modules, **as;
240 modules = g_strsplit (env_string, G_SEARCHPATH_SEPARATOR_S, -1);
242 modules = g_strsplit (env_string, ";", -1);
244 for (as = modules; *as; as++)
247 gtk_modules = g_slist_prepend (gtk_modules, *as);
259 for (i = 1; i < *argc;)
261 if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
262 strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
264 gchar *module_name = (*argv)[i] + 12;
266 if (*module_name == '=')
268 else if (i + 1 < *argc)
272 module_name = (*argv)[i];
276 if (module_name && *module_name)
277 gtk_modules = g_slist_prepend (gtk_modules, g_strdup (module_name));
279 else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
281 GLogLevelFlags fatal_mask;
283 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
284 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
285 g_log_set_always_fatal (fatal_mask);
288 #ifdef G_ENABLE_DEBUG
289 else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
290 (strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
292 gchar *equal_pos = strchr ((*argv)[i], '=');
294 if (equal_pos != NULL)
296 gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
300 else if ((i + 1) < *argc && (*argv)[i + 1])
302 gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
310 else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
311 (strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 0))
313 gchar *equal_pos = strchr ((*argv)[i], '=');
315 if (equal_pos != NULL)
317 gtk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
321 else if ((i + 1) < *argc && (*argv)[i + 1])
323 gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
331 #endif /* G_ENABLE_DEBUG */
335 for (i = 1; i < *argc; i++)
337 for (k = i; k < *argc; k++)
338 if ((*argv)[k] != NULL)
344 for (j = i + k; j < *argc; j++)
345 (*argv)[j-k] = (*argv)[j];
351 /* load gtk modules */
352 gtk_modules = g_slist_reverse (gtk_modules);
353 for (slist = gtk_modules; slist; slist = slist->next)
356 GModule *module = NULL;
357 GtkModuleInitFunc modinit_func = NULL;
359 module_name = slist->data;
362 if (!g_path_is_absolute (module_name))
364 gchar *old = module_name;
366 module_name = g_module_build_path (NULL, module_name);
370 module_name = add_dll_suffix(module_name);
372 if (g_module_supported ())
374 module = g_module_open (module_name, G_MODULE_BIND_LAZY);
376 g_module_symbol (module, "gtk_module_init", (gpointer*) &modinit_func) &&
379 if (!g_slist_find (gtk_modules, modinit_func))
381 g_module_make_resident (module);
382 slist->data = modinit_func;
386 g_module_close (module);
393 g_warning ("Failed to load module \"%s\": %s",
394 module ? g_module_name (module) : module_name,
397 g_module_close (module);
399 g_free (module_name);
404 bindtextdomain("gtk+", GTK_LOCALEDIR);
407 /* GTk+ locale dir is %WinDir%\gtk+\locale */
408 extern char *get_gtk_sysconf_directory ();
409 bindtextdomain ("gtk+", g_strconcat (get_gtk_sysconf_directory (),
417 /* Initialize the default visual and colormap to be
418 * used in creating widgets. (We want to use the system
419 * defaults so as to be nice to the colormap).
421 gtk_visual = gdk_visual_get_system ();
422 gtk_colormap = gdk_colormap_get_system ();
425 gtk_object_post_arg_parsing_init ();
430 /* Register an exit function to make sure we are able to cleanup.
432 g_atexit (gtk_exit_func);
434 /* Set the 'initialized' flag.
436 gtk_initialized = TRUE;
438 /* initialize gtk modules
440 for (slist = gtk_modules; slist; slist = slist->next)
444 GtkModuleInitFunc modinit;
446 modinit = slist->data;
447 modinit (argc, argv);
450 g_slist_free (gtk_modules);
453 /* No use warning on Win32, there aren't any non-devel versions anyhow... */
454 g_warning ("" "YOU ARE USING THE DEVEL BRANCH 1.3.x OF GTK+ WHICH IS CURRENTLY\n"
455 " UNDER HEAVY DEVELOPMENT AND FREQUENTLY INTRODUCES INSTABILITIES.\n"
456 " if you don't know why you are getting this, you probably want to\n"
457 " use the stable branch which can be retrived from\n"
458 " ftp://ftp.gtk.org/pub/gtk/v1.2/ or via CVS with\n"
459 " cvs checkout -r glib-1-2 glib; cvs checkout -r gtk-1-2 gtk+");
465 gtk_init (int *argc, char ***argv)
467 if (!gtk_init_check (argc, argv))
469 g_warning ("cannot open display: %s", gdk_get_display ());
475 gtk_exit (gint errorcode)
477 /* Only if "gtk" has been initialized should we de-initialize.
479 /* de-initialisation is done by the gtk_exit_funct(),
480 * no need to do this here (Alex J.)
486 gtk_set_locale (void)
488 return gdk_set_locale ();
496 GtkInitFunction *init;
499 gtk_main_loop_level++;
501 loop = g_main_new (TRUE);
502 main_loops = g_slist_prepend (main_loops, loop);
504 tmp_list = functions = init_functions;
505 init_functions = NULL;
509 init = tmp_list->data;
510 tmp_list = tmp_list->next;
512 (* init->function) (init->data);
515 g_list_free (functions);
517 if (g_main_is_running (main_loops->data))
519 GDK_THREADS_LEAVE ();
521 GDK_THREADS_ENTER ();
527 GList *reinvoke_list = NULL;
528 GtkQuitFunction *quitf;
530 while (quit_functions)
532 quitf = quit_functions->data;
534 tmp_list = quit_functions;
535 quit_functions = g_list_remove_link (quit_functions, quit_functions);
536 g_list_free_1 (tmp_list);
538 if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
539 gtk_quit_invoke_function (quitf))
541 reinvoke_list = g_list_prepend (reinvoke_list, quitf);
545 gtk_quit_destroy (quitf);
552 work = g_list_last (reinvoke_list);
554 quit_functions->prev = work;
555 work->next = quit_functions;
556 quit_functions = work;
562 main_loops = g_slist_remove (main_loops, loop);
564 g_main_destroy (loop);
566 gtk_main_loop_level--;
570 gtk_main_level (void)
572 return gtk_main_loop_level;
578 g_return_if_fail (main_loops != NULL);
580 g_main_quit (main_loops->data);
584 gtk_events_pending (void)
588 GDK_THREADS_LEAVE ();
589 result = g_main_pending();
590 GDK_THREADS_ENTER ();
596 gtk_main_iteration (void)
598 GDK_THREADS_LEAVE ();
599 g_main_iteration (TRUE);
600 GDK_THREADS_ENTER ();
603 return !g_main_is_running (main_loops->data);
609 gtk_main_iteration_do (gboolean blocking)
611 GDK_THREADS_LEAVE ();
612 g_main_iteration (blocking);
613 GDK_THREADS_ENTER ();
616 return !g_main_is_running (main_loops->data);
622 gtk_main_do_event (GdkEvent *event)
624 GtkWidget *event_widget;
625 GtkWidget *grab_widget;
626 GdkEvent *next_event;
629 /* If there are any events pending then get the next one.
631 next_event = gdk_event_peek ();
633 /* Try to compress enter/leave notify events. These event
634 * pairs occur when the mouse is dragged quickly across
635 * a window with many buttons (or through a menu). Instead
636 * of highlighting and de-highlighting each widget that
637 * is crossed it is better to simply de-highlight the widget
638 * which contained the mouse initially and highlight the
639 * widget which ends up containing the mouse.
642 if (((event->type == GDK_ENTER_NOTIFY) ||
643 (event->type == GDK_LEAVE_NOTIFY)) &&
644 ((next_event->type == GDK_ENTER_NOTIFY) ||
645 (next_event->type == GDK_LEAVE_NOTIFY)) &&
646 (next_event->type != event->type) &&
647 (next_event->any.window == event->any.window))
649 /* Throw both the peeked copy and the queued copy away
651 gdk_event_free (next_event);
652 next_event = gdk_event_get ();
653 gdk_event_free (next_event);
659 gdk_event_free (next_event);
661 /* Find the widget which got the event. We store the widget
662 * in the user_data field of GdkWindow's.
663 * Ignore the event if we don't have a widget for it, except
664 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
665 * Though this happens rarely, bogus events can occour
666 * for e.g. destroyed GdkWindows.
668 event_widget = gtk_get_event_widget (event);
671 /* To handle selection INCR transactions, we select
672 * PropertyNotify events on the requestor window and create
673 * a corresponding (fake) GdkWindow so that events get
674 * here. There won't be a widget though, so we have to handle
677 if (event->type == GDK_PROPERTY_NOTIFY)
678 gtk_selection_incr_event (event->any.window,
684 /* Push the event onto a stack of current events for
685 * gtk_current_event_get().
687 current_events = g_list_prepend (current_events, event);
689 /* If there is a grab in effect...
693 grab_widget = grabs->data;
695 /* If the grab widget is an ancestor of the event widget
696 * then we send the event to the original event widget.
697 * This is the key to implementing modality.
699 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
700 gtk_widget_is_ancestor (event_widget, grab_widget))
701 grab_widget = event_widget;
705 grab_widget = event_widget;
708 /* Not all events get sent to the grabbing widget.
709 * The delete, destroy, expose, focus change and resize
710 * events still get sent to the event widget because
711 * 1) these events have no meaning for the grabbing widget
712 * and 2) redirecting these events to the grabbing widget
713 * could cause the display to be messed up.
715 * Drag events are also not redirected, since it isn't
716 * clear what the semantics of that would be.
724 gtk_widget_ref (event_widget);
725 if (!gtk_widget_event (event_widget, event) &&
726 !GTK_OBJECT_DESTROYED (event_widget))
727 gtk_widget_destroy (event_widget);
728 gtk_widget_unref (event_widget);
732 /* Unexpected GDK_DESTROY from the outside, ignore for
733 * child windows, handle like a GDK_DELETE for toplevels
735 if (!event_widget->parent)
737 gtk_widget_ref (event_widget);
738 if (!gtk_widget_event (event_widget, event) &&
739 !GTK_OBJECT_DESTROYED (event_widget))
740 gtk_widget_destroy (event_widget);
741 gtk_widget_unref (event_widget);
745 case GDK_PROPERTY_NOTIFY:
748 case GDK_FOCUS_CHANGE:
752 case GDK_SELECTION_CLEAR:
753 case GDK_SELECTION_REQUEST:
754 case GDK_SELECTION_NOTIFY:
755 case GDK_CLIENT_EVENT:
756 case GDK_VISIBILITY_NOTIFY:
757 gtk_widget_event (event_widget, event);
761 case GDK_BUTTON_PRESS:
762 case GDK_2BUTTON_PRESS:
763 case GDK_3BUTTON_PRESS:
764 gtk_propagate_event (grab_widget, event);
768 case GDK_KEY_RELEASE:
771 if (gtk_invoke_key_snoopers (grab_widget, event))
774 /* else fall through */
775 case GDK_MOTION_NOTIFY:
776 case GDK_BUTTON_RELEASE:
777 case GDK_PROXIMITY_IN:
778 case GDK_PROXIMITY_OUT:
779 gtk_propagate_event (grab_widget, event);
782 case GDK_ENTER_NOTIFY:
783 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
785 gtk_widget_event (grab_widget, event);
786 if (event_widget == grab_widget)
787 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
791 case GDK_LEAVE_NOTIFY:
792 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
794 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
795 gtk_widget_event (event_widget, event);
797 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
798 gtk_widget_event (grab_widget, event);
801 case GDK_DRAG_STATUS:
802 case GDK_DROP_FINISHED:
803 gtk_drag_source_handle_event (event_widget, event);
807 case GDK_DRAG_MOTION:
809 gtk_drag_dest_handle_event (event_widget, event);
813 tmp_list = current_events;
814 current_events = g_list_remove_link (current_events, tmp_list);
815 g_list_free_1 (tmp_list);
831 gtk_grab_add (GtkWidget *widget)
833 g_return_if_fail (widget != NULL);
835 if (!GTK_WIDGET_HAS_GRAB (widget))
837 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
839 grabs = g_slist_prepend (grabs, widget);
840 gtk_widget_ref (widget);
845 gtk_grab_get_current (void)
848 return GTK_WIDGET (grabs->data);
853 gtk_grab_remove (GtkWidget *widget)
855 g_return_if_fail (widget != NULL);
857 if (GTK_WIDGET_HAS_GRAB (widget))
859 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
861 grabs = g_slist_remove (grabs, widget);
862 gtk_widget_unref (widget);
867 gtk_init_add (GtkFunction function,
870 GtkInitFunction *init;
872 init = g_new (GtkInitFunction, 1);
873 init->function = function;
876 init_functions = g_list_prepend (init_functions, init);
880 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
883 GtkKeySnooperData *data;
884 static guint snooper_id = 1;
886 g_return_val_if_fail (snooper != NULL, 0);
888 data = g_new (GtkKeySnooperData, 1);
889 data->func = snooper;
890 data->func_data = func_data;
891 data->id = snooper_id++;
892 key_snoopers = g_slist_prepend (key_snoopers, data);
898 gtk_key_snooper_remove (guint snooper_id)
900 GtkKeySnooperData *data = NULL;
903 slist = key_snoopers;
907 if (data->id == snooper_id)
914 key_snoopers = g_slist_remove (key_snoopers, data);
918 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
922 gint return_val = FALSE;
924 slist = key_snoopers;
925 while (slist && !return_val)
927 GtkKeySnooperData *data;
931 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
938 gtk_quit_add_full (guint main_level,
939 GtkFunction function,
940 GtkCallbackMarshal marshal,
942 GtkDestroyNotify destroy)
944 static guint quit_id = 1;
945 GtkQuitFunction *quitf;
947 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
950 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
951 512, G_ALLOC_AND_FREE);
953 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
955 quitf->id = quit_id++;
956 quitf->main_level = main_level;
957 quitf->function = function;
958 quitf->marshal = marshal;
960 quitf->destroy = destroy;
962 quit_functions = g_list_prepend (quit_functions, quitf);
968 gtk_quit_destroy (GtkQuitFunction *quitf)
971 quitf->destroy (quitf->data);
972 g_mem_chunk_free (quit_mem_chunk, quitf);
976 gtk_quit_destructor (GtkObject **object_p)
979 gtk_object_destroy (*object_p);
986 gtk_quit_add_destroy (guint main_level,
989 GtkObject **object_p;
991 g_return_if_fail (main_level > 0);
992 g_return_if_fail (object != NULL);
993 g_return_if_fail (GTK_IS_OBJECT (object));
995 object_p = g_new (GtkObject*, 1);
997 gtk_signal_connect (object,
999 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1001 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
1005 gtk_quit_add (guint main_level,
1006 GtkFunction function,
1009 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
1013 gtk_quit_remove (guint id)
1015 GtkQuitFunction *quitf;
1018 tmp_list = quit_functions;
1021 quitf = tmp_list->data;
1023 if (quitf->id == id)
1025 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1026 g_list_free (tmp_list);
1027 gtk_quit_destroy (quitf);
1032 tmp_list = tmp_list->next;
1037 gtk_quit_remove_by_data (gpointer data)
1039 GtkQuitFunction *quitf;
1042 tmp_list = quit_functions;
1045 quitf = tmp_list->data;
1047 if (quitf->data == data)
1049 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1050 g_list_free (tmp_list);
1051 gtk_quit_destroy (quitf);
1056 tmp_list = tmp_list->next;
1061 gtk_timeout_add_full (guint32 interval,
1062 GtkFunction function,
1063 GtkCallbackMarshal marshal,
1065 GtkDestroyNotify destroy)
1069 GtkClosure *closure;
1071 closure = g_new (GtkClosure, 1);
1072 closure->marshal = marshal;
1073 closure->data = data;
1074 closure->destroy = destroy;
1076 return g_timeout_add_full (0, interval,
1077 gtk_invoke_idle_timeout,
1079 gtk_destroy_closure);
1082 return g_timeout_add_full (0, interval, function, data, destroy);
1086 gtk_timeout_add (guint32 interval,
1087 GtkFunction function,
1090 return g_timeout_add_full (0, interval, function, data, NULL);
1094 gtk_timeout_remove (guint tag)
1096 g_source_remove (tag);
1100 gtk_idle_add_full (gint priority,
1101 GtkFunction function,
1102 GtkCallbackMarshal marshal,
1104 GtkDestroyNotify destroy)
1108 GtkClosure *closure;
1110 closure = g_new (GtkClosure, 1);
1111 closure->marshal = marshal;
1112 closure->data = data;
1113 closure->destroy = destroy;
1115 return g_idle_add_full (priority,
1116 gtk_invoke_idle_timeout,
1118 gtk_destroy_closure);
1121 return g_idle_add_full (priority, function, data, destroy);
1125 gtk_idle_add (GtkFunction function,
1128 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1132 gtk_idle_add_priority (gint priority,
1133 GtkFunction function,
1136 return g_idle_add_full (priority, function, data, NULL);
1140 gtk_idle_remove (guint tag)
1142 g_source_remove (tag);
1146 gtk_idle_remove_by_data (gpointer data)
1148 if (!g_idle_remove_by_data (data))
1149 g_warning ("gtk_idle_remove_by_data(%p): no such idle", data);
1153 gtk_input_add_full (gint source,
1154 GdkInputCondition condition,
1155 GdkInputFunction function,
1156 GtkCallbackMarshal marshal,
1158 GtkDestroyNotify destroy)
1162 GtkClosure *closure;
1164 closure = g_new (GtkClosure, 1);
1165 closure->marshal = marshal;
1166 closure->data = data;
1167 closure->destroy = destroy;
1169 return gdk_input_add_full (source,
1171 (GdkInputFunction) gtk_invoke_input,
1173 (GdkDestroyNotify) gtk_destroy_closure);
1176 return gdk_input_add_full (source, condition, function, data, destroy);
1180 gtk_input_remove (guint tag)
1182 g_source_remove (tag);
1186 gtk_destroy_closure (gpointer data)
1188 GtkClosure *closure = data;
1190 if (closure->destroy)
1191 (closure->destroy) (closure->data);
1196 gtk_invoke_idle_timeout (gpointer data)
1198 GtkClosure *closure = data;
1201 gint ret_val = FALSE;
1202 args[0].name = NULL;
1203 args[0].type = GTK_TYPE_BOOL;
1204 args[0].d.pointer_data = &ret_val;
1205 closure->marshal (NULL, closure->data, 0, args);
1210 gtk_invoke_input (gpointer data,
1212 GdkInputCondition condition)
1214 GtkClosure *closure = data;
1217 args[0].type = GTK_TYPE_INT;
1218 args[0].name = NULL;
1219 GTK_VALUE_INT(args[0]) = source;
1220 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1221 args[1].name = NULL;
1222 GTK_VALUE_FLAGS(args[1]) = condition;
1223 args[2].type = GTK_TYPE_NONE;
1224 args[2].name = NULL;
1226 closure->marshal (NULL, closure->data, 2, args);
1230 gtk_get_current_event (void)
1233 return gdk_event_copy ((GdkEvent *) current_events->data);
1239 gtk_get_event_widget (GdkEvent *event)
1244 if (event && event->any.window)
1245 gdk_window_get_user_data (event->any.window, (void**) &widget);
1251 gtk_exit_func (void)
1253 if (gtk_initialized)
1255 gtk_initialized = FALSE;
1256 gtk_preview_uninit ();
1262 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1264 if (!quitf->marshal)
1265 return quitf->function (quitf->data);
1269 gint ret_val = FALSE;
1271 args[0].name = NULL;
1272 args[0].type = GTK_TYPE_BOOL;
1273 args[0].d.pointer_data = &ret_val;
1274 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1282 gtk_propagate_event (GtkWidget *widget,
1287 g_return_if_fail (widget != NULL);
1288 g_return_if_fail (GTK_IS_WIDGET (widget));
1289 g_return_if_fail (event != NULL);
1291 handled_event = FALSE;
1293 if ((event->type == GDK_KEY_PRESS) ||
1294 (event->type == GDK_KEY_RELEASE))
1296 /* Only send key events within Window widgets to the Window
1297 * The Window widget will in turn pass the
1298 * key event on to the currently focused widget
1303 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1306 if (GTK_WIDGET_IS_SENSITIVE (window))
1307 gtk_widget_event (window, event);
1309 handled_event = TRUE; /* don't send to widget */
1313 /* Other events get propagated up the widget tree
1314 * so that parents can see the button and motion
1315 * events of the children.
1317 while (!handled_event && widget)
1321 gtk_widget_ref (widget);
1322 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1323 tmp = widget->parent;
1324 gtk_widget_unref (widget);
1331 gtk_error (gchar *str)
1337 gtk_warning (gchar *str)
1343 gtk_message (gchar *str)
1349 gtk_print (gchar *str)
1351 static GtkWidget *window = NULL;
1352 static GtkWidget *text;
1353 static int level = 0;
1357 GtkWidget *hscrollbar;
1358 GtkWidget *vscrollbar;
1359 GtkWidget *separator;
1364 fputs (str, stdout);
1371 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1373 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1374 (GtkSignalFunc) gtk_widget_destroyed,
1377 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1379 box1 = gtk_vbox_new (FALSE, 0);
1380 gtk_container_add (GTK_CONTAINER (window), box1);
1381 gtk_widget_show (box1);
1384 box2 = gtk_vbox_new (FALSE, 10);
1385 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1386 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1387 gtk_widget_show (box2);
1390 table = gtk_table_new (2, 2, FALSE);
1391 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1392 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1393 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1394 gtk_widget_show (table);
1396 text = gtk_text_new (NULL, NULL);
1397 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1398 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1399 gtk_widget_show (text);
1400 gtk_widget_realize (text);
1402 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1403 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1404 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1405 gtk_widget_show (hscrollbar);
1407 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1408 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1409 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1410 gtk_widget_show (vscrollbar);
1412 separator = gtk_hseparator_new ();
1413 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1414 gtk_widget_show (separator);
1417 box2 = gtk_vbox_new (FALSE, 10);
1418 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1419 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1420 gtk_widget_show (box2);
1423 button = gtk_button_new_with_label ("close");
1424 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1425 (GtkSignalFunc) gtk_widget_hide,
1426 GTK_OBJECT (window));
1427 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1428 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1429 gtk_widget_grab_default (button);
1430 gtk_widget_show (button);
1434 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1437 if (!GTK_WIDGET_VISIBLE (window))
1438 gtk_widget_show (window);