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 #include "gdkx.h" /* For GDK_WINDOWING */
29 #if GDK_WINDOWING == GDK_WINDOWING_X11
30 #include <X11/Xlocale.h> /* so we get the right setlocale */
38 #include "gtkbutton.h"
40 #include "gtkcompat.h"
41 #include "gtkhscrollbar.h"
42 #include "gtkhseparator.h"
44 #include "gtkpreview.h"
46 #include "gtkscrolledwindow.h"
47 #include "gtkselection.h"
48 #include "gtksignal.h"
52 #include "gtkvscrollbar.h"
53 #include "gtkwidget.h"
54 #include "gtkwindow.h"
55 #include "gtkprivate.h"
56 #include "gdk/gdki18n.h"
61 /* Private type definitions
63 typedef struct _GtkInitFunction GtkInitFunction;
64 typedef struct _GtkQuitFunction GtkQuitFunction;
65 typedef struct _GtkClosure GtkClosure;
66 typedef struct _GtkKeySnooperData GtkKeySnooperData;
68 struct _GtkInitFunction
74 struct _GtkQuitFunction
78 GtkCallbackMarshal marshal;
81 GtkDestroyNotify destroy;
86 GtkCallbackMarshal marshal;
88 GtkDestroyNotify destroy;
91 struct _GtkKeySnooperData
98 static void gtk_exit_func (void);
99 static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
100 static void gtk_quit_destroy (GtkQuitFunction *quitf);
101 static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
104 static void gtk_destroy_closure (gpointer data);
105 static gboolean gtk_invoke_idle_timeout (gpointer data);
106 static void gtk_invoke_input (gpointer data,
108 GdkInputCondition condition);
111 static void gtk_error (gchar *str);
112 static void gtk_warning (gchar *str);
113 static void gtk_message (gchar *str);
114 static void gtk_print (gchar *str);
117 const guint gtk_major_version = GTK_MAJOR_VERSION;
118 const guint gtk_minor_version = GTK_MINOR_VERSION;
119 const guint gtk_micro_version = GTK_MICRO_VERSION;
120 const guint gtk_binary_age = GTK_BINARY_AGE;
121 const guint gtk_interface_age = GTK_INTERFACE_AGE;
123 static guint gtk_main_loop_level = 0;
124 static gint gtk_initialized = FALSE;
125 static GList *current_events = NULL;
127 static GSList *main_loops = NULL; /* stack of currently executing main loops */
129 static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
130 * widget is the first one on the list.
132 static GList *init_functions = NULL; /* A list of init functions.
134 static GList *quit_functions = NULL; /* A list of quit functions.
136 static GMemChunk *quit_mem_chunk = NULL;
138 static GSList *key_snoopers = NULL;
140 static GdkVisual *gtk_visual; /* The visual to be used in creating new
143 static GdkColormap *gtk_colormap; /* The colormap to be used in creating new
147 guint gtk_debug_flags = 0; /* Global GTK debug flag */
149 #ifdef G_ENABLE_DEBUG
150 static const GDebugKey gtk_debug_keys[] = {
151 {"objects", GTK_DEBUG_OBJECTS},
152 {"misc", GTK_DEBUG_MISC},
153 {"signals", GTK_DEBUG_SIGNALS},
154 {"dnd", GTK_DEBUG_DND},
155 {"plugsocket", GTK_DEBUG_PLUGSOCKET}
158 static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
160 #endif /* G_ENABLE_DEBUG */
163 gtk_check_version (guint required_major,
164 guint required_minor,
165 guint required_micro)
167 if (required_major > GTK_MAJOR_VERSION)
168 return "Gtk+ version too old (major mismatch)";
169 if (required_major < GTK_MAJOR_VERSION)
170 return "Gtk+ version too new (major mismatch)";
171 if (required_minor > GTK_MINOR_VERSION)
172 return "Gtk+ version too old (minor mismatch)";
173 if (required_minor < GTK_MINOR_VERSION)
174 return "Gtk+ version too new (minor mismatch)";
175 if (required_micro < GTK_MICRO_VERSION - GTK_BINARY_AGE)
176 return "Gtk+ version too new (micro mismatch)";
177 if (required_micro > GTK_MICRO_VERSION)
178 return "Gtk+ version too old (micro mismatch)";
183 static gchar *add_dll_suffix(gchar *module_name)
185 gchar *suffix = strrchr(module_name, '.');
187 if (!suffix || stricmp(suffix, ".dll"))
189 gchar *old = module_name;
191 module_name = g_strconcat (module_name, ".dll", NULL);
194 return (module_name);
199 gtk_init_check (int *argc,
202 extern void gtk_object_post_arg_parsing_init (void);
203 GSList *gtk_modules = NULL;
205 gchar *env_string = NULL;
211 g_set_error_handler (gtk_error);
212 g_set_warning_handler (gtk_warning);
213 g_set_message_handler (gtk_message);
214 g_set_print_handler (gtk_print);
217 /* Initialize "gdk". We pass along the 'argc' and 'argv'
218 * parameters as they contain information that GDK uses
220 if (!gdk_init_check (argc, argv))
223 gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
225 #ifdef G_ENABLE_DEBUG
226 env_string = getenv ("GTK_DEBUG");
227 if (env_string != NULL)
229 gtk_debug_flags = g_parse_debug_string (env_string,
234 #endif /* G_ENABLE_DEBUG */
236 env_string = getenv ("GTK_MODULES");
239 gchar **modules, **as;
242 modules = g_strsplit (env_string, G_SEARCHPATH_SEPARATOR_S, -1);
244 modules = g_strsplit (env_string, ";", -1);
246 for (as = modules; *as; as++)
249 gtk_modules = g_slist_prepend (gtk_modules, *as);
261 for (i = 1; i < *argc;)
263 if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
264 strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
266 gchar *module_name = (*argv)[i] + 12;
268 if (*module_name == '=')
274 module_name = (*argv)[i];
278 gtk_modules = g_slist_prepend (gtk_modules, g_strdup (module_name));
280 else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
282 GLogLevelFlags fatal_mask;
284 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
285 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
286 g_log_set_always_fatal (fatal_mask);
289 #ifdef G_ENABLE_DEBUG
290 else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
291 (strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
293 gchar *equal_pos = strchr ((*argv)[i], '=');
295 if (equal_pos != NULL)
297 gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
301 else if ((i + 1) < *argc && (*argv)[i + 1])
303 gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
311 else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
312 (strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 0))
314 gchar *equal_pos = strchr ((*argv)[i], '=');
316 if (equal_pos != NULL)
318 gtk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
322 else if ((i + 1) < *argc && (*argv)[i + 1])
324 gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
332 #endif /* G_ENABLE_DEBUG */
336 for (i = 1; i < *argc; i++)
338 for (k = i; k < *argc; k++)
339 if ((*argv)[k] != NULL)
345 for (j = i + k; j < *argc; j++)
346 (*argv)[j-k] = (*argv)[j];
352 /* load gtk modules */
353 gtk_modules = g_slist_reverse (gtk_modules);
354 for (slist = gtk_modules; slist; slist = slist->next)
357 GModule *module = NULL;
358 GtkModuleInitFunc modinit_func = NULL;
360 module_name = slist->data;
363 if (!g_path_is_absolute (module_name))
365 gchar *old = module_name;
367 module_name = g_module_build_path (NULL, module_name);
371 module_name = add_dll_suffix(module_name);
373 if (g_module_supported ())
375 module = g_module_open (module_name, G_MODULE_BIND_LAZY);
377 g_module_symbol (module, "gtk_module_init", (gpointer*) &modinit_func) &&
380 if (!g_slist_find (gtk_modules, modinit_func))
382 g_module_make_resident (module);
383 slist->data = modinit_func;
387 g_module_close (module);
394 g_warning ("Failed to load module \"%s\": %s",
395 module ? g_module_name (module) : module_name,
398 g_module_close (module);
400 g_free (module_name);
404 bindtextdomain("gtk+", GTK_LOCALEDIR);
407 /* Initialize the default visual and colormap to be
408 * used in creating widgets. (We want to use the system
409 * defaults so as to be nice to the colormap).
411 gtk_visual = gdk_visual_get_system ();
412 gtk_colormap = gdk_colormap_get_system ();
415 gtk_object_post_arg_parsing_init ();
420 /* Register an exit function to make sure we are able to cleanup.
422 g_atexit (gtk_exit_func);
424 /* Set the 'initialized' flag.
426 gtk_initialized = TRUE;
428 /* initialize gtk modules
430 for (slist = gtk_modules; slist; slist = slist->next)
434 GtkModuleInitFunc modinit;
436 modinit = slist->data;
437 modinit (argc, argv);
440 g_slist_free (gtk_modules);
443 /* No use warning on Win32, there aren't any non-devel versions anyhow... */
444 g_warning ("" "YOU ARE USING THE DEVEL BRANCH 1.3.x OF GTK+ WHICH IS CURRENTLY\n"
445 " UNDER HEAVY DEVELOPMENT AND FREQUENTLY INTRODUCES INSTABILITIES.\n"
446 " if you don't know why you are getting this, you probably want to\n"
447 " use the stable branch which can be retrived from\n"
448 " ftp://ftp.gtk.org/pub/gtk/v1.2/ or via CVS with\n"
449 " cvs checkout -r glib-1-2 glib; cvs checkout -r gtk-1-2 gtk+");
455 gtk_init (int *argc, char ***argv)
457 if (!gtk_init_check (argc, argv))
459 g_warning ("cannot open display: %s", gdk_get_display ());
465 gtk_exit (int errorcode)
467 /* Only if "gtk" has been initialized should we de-initialize.
469 /* de-initialisation is done by the gtk_exit_funct(),
470 * no need to do this here (Alex J.)
476 gtk_set_locale (void)
478 return gdk_set_locale ();
486 GtkInitFunction *init;
489 gtk_main_loop_level++;
491 loop = g_main_new (TRUE);
492 main_loops = g_slist_prepend (main_loops, loop);
494 tmp_list = functions = init_functions;
495 init_functions = NULL;
499 init = tmp_list->data;
500 tmp_list = tmp_list->next;
502 (* init->function) (init->data);
505 g_list_free (functions);
507 if (g_main_is_running (main_loops->data))
509 GDK_THREADS_LEAVE ();
511 GDK_THREADS_ENTER ();
517 GList *reinvoke_list = NULL;
518 GtkQuitFunction *quitf;
520 while (quit_functions)
522 quitf = quit_functions->data;
524 quit_functions = g_list_remove_link (quit_functions, quit_functions);
526 if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
527 gtk_quit_invoke_function (quitf))
529 reinvoke_list = g_list_prepend (reinvoke_list, quitf);
533 g_list_free (tmp_list);
534 gtk_quit_destroy (quitf);
541 work = g_list_last (reinvoke_list);
543 quit_functions->prev = work;
544 work->next = quit_functions;
545 quit_functions = work;
551 main_loops = g_slist_remove (main_loops, loop);
553 g_main_destroy (loop);
555 gtk_main_loop_level--;
559 gtk_main_level (void)
561 return gtk_main_loop_level;
567 g_return_if_fail (main_loops != NULL);
569 g_main_quit (main_loops->data);
573 gtk_events_pending (void)
575 return g_main_pending();
579 gtk_main_iteration (void)
581 g_main_iteration (TRUE);
584 return !g_main_is_running (main_loops->data);
590 gtk_main_iteration_do (gboolean blocking)
592 g_main_iteration (blocking);
595 return !g_main_is_running (main_loops->data);
601 gtk_main_do_event (GdkEvent *event)
603 GtkWidget *event_widget;
604 GtkWidget *grab_widget;
605 GdkEvent *next_event;
608 /* If there are any events pending then get the next one.
610 next_event = gdk_event_peek ();
612 /* Try to compress enter/leave notify events. These event
613 * pairs occur when the mouse is dragged quickly across
614 * a window with many buttons (or through a menu). Instead
615 * of highlighting and de-highlighting each widget that
616 * is crossed it is better to simply de-highlight the widget
617 * which contained the mouse initially and highlight the
618 * widget which ends up containing the mouse.
621 if (((event->type == GDK_ENTER_NOTIFY) ||
622 (event->type == GDK_LEAVE_NOTIFY)) &&
623 ((next_event->type == GDK_ENTER_NOTIFY) ||
624 (next_event->type == GDK_LEAVE_NOTIFY)) &&
625 (next_event->type != event->type) &&
626 (next_event->any.window == event->any.window))
628 /* Throw both the peeked copy and the queued copy away
630 gdk_event_free (next_event);
631 next_event = gdk_event_get ();
632 gdk_event_free (next_event);
638 gdk_event_free (next_event);
640 /* Find the widget which got the event. We store the widget
641 * in the user_data field of GdkWindow's.
642 * Ignore the event if we don't have a widget for it, except
643 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
644 * Though this happens rarely, bogus events can occour
645 * for e.g. destroyed GdkWindows.
647 event_widget = gtk_get_event_widget (event);
650 /* To handle selection INCR transactions, we select
651 * PropertyNotify events on the requestor window and create
652 * a corresponding (fake) GdkWindow so that events get
653 * here. There won't be a widget though, so we have to handle
656 if (event->type == GDK_PROPERTY_NOTIFY)
657 gtk_selection_incr_event (event->any.window,
663 /* Push the event onto a stack of current events for
664 * gtk_current_event_get().
666 current_events = g_list_prepend (current_events, event);
668 /* If there is a grab in effect...
672 grab_widget = grabs->data;
674 /* If the grab widget is an ancestor of the event widget
675 * then we send the event to the original event widget.
676 * This is the key to implementing modality.
678 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
679 gtk_widget_is_ancestor (event_widget, grab_widget))
680 grab_widget = event_widget;
684 grab_widget = event_widget;
687 /* Not all events get sent to the grabbing widget.
688 * The delete, destroy, expose, focus change and resize
689 * events still get sent to the event widget because
690 * 1) these events have no meaning for the grabbing widget
691 * and 2) redirecting these events to the grabbing widget
692 * could cause the display to be messed up.
694 * Drag events are also not redirected, since it isn't
695 * clear what the semantics of that would be.
703 gtk_widget_ref (event_widget);
704 if (!gtk_widget_event (event_widget, event) &&
705 !GTK_OBJECT_DESTROYED (event_widget))
706 gtk_widget_destroy (event_widget);
707 gtk_widget_unref (event_widget);
711 gtk_widget_ref (event_widget);
712 gtk_widget_event (event_widget, event);
713 if (!GTK_OBJECT_DESTROYED (event_widget))
714 gtk_widget_destroy (event_widget);
715 gtk_widget_unref (event_widget);
718 case GDK_PROPERTY_NOTIFY:
721 case GDK_FOCUS_CHANGE:
725 case GDK_SELECTION_CLEAR:
726 case GDK_SELECTION_REQUEST:
727 case GDK_SELECTION_NOTIFY:
728 case GDK_CLIENT_EVENT:
729 case GDK_VISIBILITY_NOTIFY:
730 gtk_widget_event (event_widget, event);
733 case GDK_BUTTON_PRESS:
734 case GDK_2BUTTON_PRESS:
735 case GDK_3BUTTON_PRESS:
736 /* We treat button 4-5 specially, assume we have
737 * a MS-style scrollwheel mouse, and try to find
738 * a plausible widget to scroll. We also trap
739 * button 4-5 double and triple clicks here, since
740 * they will be generated if the user scrolls quickly.
742 if ((grab_widget == event_widget) &&
743 (event->button.button == 4 || event->button.button == 5))
745 GtkWidget *range = NULL;
746 GtkWidget *scrollwin;
748 if (GTK_IS_RANGE (event_widget))
749 range = event_widget;
752 scrollwin = gtk_widget_get_ancestor (event_widget,
753 GTK_TYPE_SCROLLED_WINDOW);
755 range = GTK_SCROLLED_WINDOW (scrollwin)->vscrollbar;
758 if (range && GTK_WIDGET_VISIBLE (range))
760 if (event->type == GDK_BUTTON_PRESS)
762 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
763 gfloat new_value = adj->value + ((event->button.button == 4) ?
764 -adj->page_increment / 2:
765 adj->page_increment / 2);
766 new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
767 gtk_adjustment_set_value (adj, new_value);
772 gtk_propagate_event (grab_widget, event);
776 case GDK_KEY_RELEASE:
779 if (gtk_invoke_key_snoopers (grab_widget, event))
782 /* else fall through */
783 case GDK_MOTION_NOTIFY:
784 case GDK_BUTTON_RELEASE:
785 case GDK_PROXIMITY_IN:
786 case GDK_PROXIMITY_OUT:
787 gtk_propagate_event (grab_widget, event);
790 case GDK_ENTER_NOTIFY:
791 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
793 gtk_widget_event (grab_widget, event);
794 if (event_widget == grab_widget)
795 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
799 case GDK_LEAVE_NOTIFY:
800 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
802 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
803 gtk_widget_event (event_widget, event);
805 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
806 gtk_widget_event (grab_widget, event);
809 case GDK_DRAG_STATUS:
810 case GDK_DROP_FINISHED:
811 gtk_drag_source_handle_event (event_widget, event);
815 case GDK_DRAG_MOTION:
817 gtk_drag_dest_handle_event (event_widget, event);
821 tmp_list = current_events;
822 current_events = g_list_remove_link (current_events, tmp_list);
823 g_list_free_1 (tmp_list);
839 gtk_grab_add (GtkWidget *widget)
841 g_return_if_fail (widget != NULL);
843 if (!GTK_WIDGET_HAS_GRAB (widget))
845 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
847 grabs = g_slist_prepend (grabs, widget);
848 gtk_widget_ref (widget);
853 gtk_grab_get_current (void)
856 return GTK_WIDGET (grabs->data);
861 gtk_grab_remove (GtkWidget *widget)
863 g_return_if_fail (widget != NULL);
865 if (GTK_WIDGET_HAS_GRAB (widget))
867 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
869 grabs = g_slist_remove (grabs, widget);
870 gtk_widget_unref (widget);
875 gtk_init_add (GtkFunction function,
878 GtkInitFunction *init;
880 init = g_new (GtkInitFunction, 1);
881 init->function = function;
884 init_functions = g_list_prepend (init_functions, init);
888 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
891 GtkKeySnooperData *data;
892 static guint snooper_id = 1;
894 g_return_val_if_fail (snooper != NULL, 0);
896 data = g_new (GtkKeySnooperData, 1);
897 data->func = snooper;
898 data->func_data = func_data;
899 data->id = snooper_id++;
900 key_snoopers = g_slist_prepend (key_snoopers, data);
906 gtk_key_snooper_remove (guint snooper_id)
908 GtkKeySnooperData *data = NULL;
911 slist = key_snoopers;
915 if (data->id == snooper_id)
922 key_snoopers = g_slist_remove (key_snoopers, data);
926 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
930 gint return_val = FALSE;
932 slist = key_snoopers;
933 while (slist && !return_val)
935 GtkKeySnooperData *data;
939 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
946 gtk_quit_add_full (guint main_level,
947 GtkFunction function,
948 GtkCallbackMarshal marshal,
950 GtkDestroyNotify destroy)
952 static guint quit_id = 1;
953 GtkQuitFunction *quitf;
955 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
958 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
959 512, G_ALLOC_AND_FREE);
961 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
963 quitf->id = quit_id++;
964 quitf->main_level = main_level;
965 quitf->function = function;
966 quitf->marshal = marshal;
968 quitf->destroy = destroy;
970 quit_functions = g_list_prepend (quit_functions, quitf);
976 gtk_quit_destroy (GtkQuitFunction *quitf)
979 quitf->destroy (quitf->data);
980 g_mem_chunk_free (quit_mem_chunk, quitf);
984 gtk_quit_destructor (GtkObject **object_p)
987 gtk_object_destroy (*object_p);
994 gtk_quit_add_destroy (guint main_level,
997 GtkObject **object_p;
999 g_return_if_fail (main_level > 0);
1000 g_return_if_fail (object != NULL);
1001 g_return_if_fail (GTK_IS_OBJECT (object));
1003 object_p = g_new (GtkObject*, 1);
1005 gtk_signal_connect (object,
1007 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1009 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
1013 gtk_quit_add (guint main_level,
1014 GtkFunction function,
1017 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
1021 gtk_quit_remove (guint id)
1023 GtkQuitFunction *quitf;
1026 tmp_list = quit_functions;
1029 quitf = tmp_list->data;
1031 if (quitf->id == id)
1033 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1034 g_list_free (tmp_list);
1035 gtk_quit_destroy (quitf);
1040 tmp_list = tmp_list->next;
1045 gtk_quit_remove_by_data (gpointer data)
1047 GtkQuitFunction *quitf;
1050 tmp_list = quit_functions;
1053 quitf = tmp_list->data;
1055 if (quitf->data == data)
1057 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1058 g_list_free (tmp_list);
1059 gtk_quit_destroy (quitf);
1064 tmp_list = tmp_list->next;
1069 gtk_timeout_add_full (guint32 interval,
1070 GtkFunction function,
1071 GtkCallbackMarshal marshal,
1073 GtkDestroyNotify destroy)
1077 GtkClosure *closure;
1079 closure = g_new (GtkClosure, 1);
1080 closure->marshal = marshal;
1081 closure->data = data;
1082 closure->destroy = destroy;
1084 return g_timeout_add_full (0, interval,
1085 gtk_invoke_idle_timeout,
1087 gtk_destroy_closure);
1090 return g_timeout_add_full (0, interval, function, data, destroy);
1094 gtk_timeout_add (guint32 interval,
1095 GtkFunction function,
1098 return g_timeout_add_full (0, interval, function, data, NULL);
1102 gtk_timeout_remove (guint tag)
1104 g_source_remove (tag);
1108 gtk_idle_add_full (gint priority,
1109 GtkFunction function,
1110 GtkCallbackMarshal marshal,
1112 GtkDestroyNotify destroy)
1116 GtkClosure *closure;
1118 closure = g_new (GtkClosure, 1);
1119 closure->marshal = marshal;
1120 closure->data = data;
1121 closure->destroy = destroy;
1123 return g_idle_add_full (priority,
1124 gtk_invoke_idle_timeout,
1126 gtk_destroy_closure);
1129 return g_idle_add_full (priority, function, data, destroy);
1133 gtk_idle_add (GtkFunction function,
1136 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1140 gtk_idle_add_priority (gint priority,
1141 GtkFunction function,
1144 return g_idle_add_full (priority, function, data, NULL);
1148 gtk_idle_remove (guint tag)
1150 g_source_remove (tag);
1154 gtk_idle_remove_by_data (gpointer data)
1156 if (!g_idle_remove_by_data (data))
1157 g_warning ("gtk_idle_remove_by_data(%p): no such idle", data);
1161 gtk_input_add_full (gint source,
1162 GdkInputCondition condition,
1163 GdkInputFunction function,
1164 GtkCallbackMarshal marshal,
1166 GtkDestroyNotify destroy)
1170 GtkClosure *closure;
1172 closure = g_new (GtkClosure, 1);
1173 closure->marshal = marshal;
1174 closure->data = data;
1175 closure->destroy = destroy;
1177 return gdk_input_add_full (source,
1179 (GdkInputFunction) gtk_invoke_input,
1181 (GdkDestroyNotify) gtk_destroy_closure);
1184 return gdk_input_add_full (source, condition, function, data, destroy);
1188 gtk_input_remove (guint tag)
1190 g_source_remove (tag);
1194 gtk_destroy_closure (gpointer data)
1196 GtkClosure *closure = data;
1198 if (closure->destroy)
1199 (closure->destroy) (closure->data);
1204 gtk_invoke_idle_timeout (gpointer data)
1206 GtkClosure *closure = data;
1209 gint ret_val = FALSE;
1210 args[0].name = NULL;
1211 args[0].type = GTK_TYPE_BOOL;
1212 args[0].d.pointer_data = &ret_val;
1213 closure->marshal (NULL, closure->data, 0, args);
1218 gtk_invoke_input (gpointer data,
1220 GdkInputCondition condition)
1222 GtkClosure *closure = data;
1225 args[0].type = GTK_TYPE_INT;
1226 args[0].name = NULL;
1227 GTK_VALUE_INT(args[0]) = source;
1228 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1229 args[1].name = NULL;
1230 GTK_VALUE_FLAGS(args[1]) = condition;
1231 args[2].type = GTK_TYPE_NONE;
1232 args[2].name = NULL;
1234 closure->marshal (NULL, closure->data, 2, args);
1238 gtk_get_current_event (void)
1241 return gdk_event_copy ((GdkEvent *) current_events->data);
1247 gtk_get_event_widget (GdkEvent *event)
1252 if (event && event->any.window)
1253 gdk_window_get_user_data (event->any.window, (void**) &widget);
1259 gtk_exit_func (void)
1261 if (gtk_initialized)
1263 gtk_initialized = FALSE;
1264 gtk_preview_uninit ();
1270 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1272 if (!quitf->marshal)
1273 return quitf->function (quitf->data);
1277 gint ret_val = FALSE;
1279 args[0].name = NULL;
1280 args[0].type = GTK_TYPE_BOOL;
1281 args[0].d.pointer_data = &ret_val;
1282 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1290 gtk_propagate_event (GtkWidget *widget,
1295 g_return_if_fail (widget != NULL);
1296 g_return_if_fail (GTK_IS_WIDGET (widget));
1297 g_return_if_fail (event != NULL);
1299 handled_event = FALSE;
1301 if ((event->type == GDK_KEY_PRESS) ||
1302 (event->type == GDK_KEY_RELEASE))
1304 /* Only send key events within Window widgets to the Window
1305 * The Window widget will in turn pass the
1306 * key event on to the currently focused widget
1311 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1314 if (GTK_WIDGET_IS_SENSITIVE (window))
1315 gtk_widget_event (window, event);
1317 handled_event = TRUE; /* don't send to widget */
1321 /* Other events get propagated up the widget tree
1322 * so that parents can see the button and motion
1323 * events of the children.
1325 while (!handled_event && widget)
1329 gtk_widget_ref (widget);
1330 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1331 tmp = widget->parent;
1332 gtk_widget_unref (widget);
1339 gtk_error (gchar *str)
1345 gtk_warning (gchar *str)
1351 gtk_message (gchar *str)
1357 gtk_print (gchar *str)
1359 static GtkWidget *window = NULL;
1360 static GtkWidget *text;
1361 static int level = 0;
1365 GtkWidget *hscrollbar;
1366 GtkWidget *vscrollbar;
1367 GtkWidget *separator;
1372 fputs (str, stdout);
1379 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1381 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1382 (GtkSignalFunc) gtk_widget_destroyed,
1385 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1387 box1 = gtk_vbox_new (FALSE, 0);
1388 gtk_container_add (GTK_CONTAINER (window), box1);
1389 gtk_widget_show (box1);
1392 box2 = gtk_vbox_new (FALSE, 10);
1393 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1394 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1395 gtk_widget_show (box2);
1398 table = gtk_table_new (2, 2, FALSE);
1399 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1400 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1401 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1402 gtk_widget_show (table);
1404 text = gtk_text_new (NULL, NULL);
1405 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1406 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1407 gtk_widget_show (text);
1408 gtk_widget_realize (text);
1410 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1411 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1412 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1413 gtk_widget_show (hscrollbar);
1415 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1416 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1417 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1418 gtk_widget_show (vscrollbar);
1420 separator = gtk_hseparator_new ();
1421 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1422 gtk_widget_show (separator);
1425 box2 = gtk_vbox_new (FALSE, 10);
1426 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1427 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1428 gtk_widget_show (box2);
1431 button = gtk_button_new_with_label ("close");
1432 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1433 (GtkSignalFunc) gtk_widget_hide,
1434 GTK_OBJECT (window));
1435 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1436 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1437 gtk_widget_grab_default (button);
1438 gtk_widget_show (button);
1442 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1445 if (!GTK_WIDGET_VISIBLE (window))
1446 gtk_widget_show (window);