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.
19 #include <X11/Xlocale.h> /* so we get the right setlocale */
24 #include "gtkbutton.h"
26 #include "gtkfeatures.h"
27 #include "gtkhscrollbar.h"
28 #include "gtkhseparator.h"
30 #include "gtkpreview.h"
32 #include "gtkselection.h"
33 #include "gtksignal.h"
37 #include "gtkvscrollbar.h"
38 #include "gtkwidget.h"
39 #include "gtkwindow.h"
40 #include "gtkprivate.h"
41 #include "gdk/gdki18n.h"
46 /* Private type definitions
48 typedef struct _GtkInitFunction GtkInitFunction;
49 typedef struct _GtkQuitFunction GtkQuitFunction;
50 typedef struct _GtkClosure GtkClosure;
51 typedef struct _GtkKeySnooperData GtkKeySnooperData;
53 struct _GtkInitFunction
59 struct _GtkQuitFunction
63 GtkCallbackMarshal marshal;
66 GtkDestroyNotify destroy;
71 GtkCallbackMarshal marshal;
73 GtkDestroyNotify destroy;
76 struct _GtkKeySnooperData
83 static void gtk_exit_func (void);
84 static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
85 static void gtk_quit_destroy (GtkQuitFunction *quitf);
86 static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
89 static void gtk_destroy_closure (gpointer data);
90 static gboolean gtk_invoke_idle_timeout (gpointer data);
91 static void gtk_invoke_input (gpointer data,
93 GdkInputCondition condition);
96 static void gtk_error (gchar *str);
97 static void gtk_warning (gchar *str);
98 static void gtk_message (gchar *str);
99 static void gtk_print (gchar *str);
102 const guint gtk_major_version = GTK_MAJOR_VERSION;
103 const guint gtk_minor_version = GTK_MINOR_VERSION;
104 const guint gtk_micro_version = GTK_MICRO_VERSION;
105 const guint gtk_binary_age = GTK_BINARY_AGE;
106 const guint gtk_interface_age = GTK_INTERFACE_AGE;
108 static guint gtk_main_loop_level = 0;
109 static gint gtk_initialized = FALSE;
110 static GList *current_events = NULL;
112 static GSList *main_loops = NULL; /* stack of currently executing main loops */
114 static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
115 * widget is the first one on the list.
117 static GList *init_functions = NULL; /* A list of init functions.
119 static GList *quit_functions = NULL; /* A list of quit functions.
121 static GMemChunk *quit_mem_chunk = NULL;
123 static GSList *key_snoopers = NULL;
125 static GdkVisual *gtk_visual; /* The visual to be used in creating new
128 static GdkColormap *gtk_colormap; /* The colormap to be used in creating new
132 guint gtk_debug_flags = 0; /* Global GTK debug flag */
134 #ifdef G_ENABLE_DEBUG
135 static const GDebugKey gtk_debug_keys[] = {
136 {"objects", GTK_DEBUG_OBJECTS},
137 {"misc", GTK_DEBUG_MISC},
138 {"signals", GTK_DEBUG_SIGNALS},
139 {"dnd", GTK_DEBUG_DND}
142 static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
144 #endif /* G_ENABLE_DEBUG */
147 gtk_check_version (guint required_major,
148 guint required_minor,
149 guint required_micro)
151 if (required_major > GTK_MAJOR_VERSION)
152 return "Gtk+ version to old (major mismatch)";
153 if (required_major < GTK_MAJOR_VERSION)
154 return "Gtk+ version to new (major mismatch)";
155 if (required_minor > GTK_MINOR_VERSION)
156 return "Gtk+ version to old (minor mismatch)";
157 if (required_minor < GTK_MINOR_VERSION)
158 return "Gtk+ version to new (minor mismatch)";
159 if (required_micro < GTK_MICRO_VERSION - GTK_BINARY_AGE)
160 return "Gtk+ version to new (micro mismatch)";
161 if (required_micro > GTK_MICRO_VERSION)
162 return "Gtk+ version to old (micro mismatch)";
171 GSList *gtk_modules = NULL;
173 gchar *env_string = NULL;
178 /* There is some argument for putting this in a separate
179 * function ... but I don't think that it is much
180 * of a restriction to require that GTK+ be used
181 * single threaded until gtk_init().
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);
191 /* Initialize "gdk". We pass along the 'argc' and 'argv'
192 * parameters as they contain information that GDK uses
194 gdk_init (argc, argv);
196 gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
198 #ifdef G_ENABLE_DEBUG
199 env_string = getenv ("GTK_DEBUG");
200 if (env_string != NULL)
202 gtk_debug_flags = g_parse_debug_string (env_string,
207 #endif /* G_ENABLE_DEBUG */
209 env_string = getenv ("GTK_MODULES");
212 gchar **modules, **as;
214 modules = g_strsplit (env_string, ":", -1);
215 for (as = modules; *as; as++)
218 gtk_modules = g_slist_prepend (gtk_modules, *as);
230 for (i = 1; i < *argc;)
232 if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
233 strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
235 gchar *module_name = (*argv)[i] + 12;
237 if (*module_name == '=')
243 module_name = (*argv)[i];
247 gtk_modules = g_slist_prepend (gtk_modules, g_strdup (module_name));
249 else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
251 GLogLevelFlags fatal_mask;
253 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
254 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
255 g_log_set_always_fatal (fatal_mask);
258 #ifdef G_ENABLE_DEBUG
259 else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
260 (strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
262 gchar *equal_pos = strchr ((*argv)[i], '=');
264 if (equal_pos != NULL)
266 gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
270 else if ((i + 1) < *argc && (*argv)[i + 1])
272 gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
280 else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
281 (strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 0))
283 gchar *equal_pos = strchr ((*argv)[i], '=');
285 if (equal_pos != NULL)
287 gtk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
291 else if ((i + 1) < *argc && (*argv)[i + 1])
293 gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
301 #endif /* G_ENABLE_DEBUG */
305 for (i = 1; i < *argc; i++)
307 for (k = i; k < *argc; k++)
308 if ((*argv)[k] != NULL)
314 for (j = i + k; j < *argc; j++)
315 (*argv)[j-k] = (*argv)[j];
321 /* load gtk modules */
322 gtk_modules = g_slist_reverse (gtk_modules);
323 for (slist = gtk_modules; slist; slist = slist->next)
326 GModule *module = NULL;
327 GtkModuleInitFunc modinit_func = NULL;
329 module_name = slist->data;
331 if (!(module_name[0] == '/' ||
332 (module_name[0] == 'l' &&
333 module_name[1] == 'i' &&
334 module_name[2] == 'b')))
336 gchar *old = module_name;
338 module_name = g_strconcat ("lib", module_name, ".so", NULL);
341 if (g_module_supported ())
343 module = g_module_open (module_name, G_MODULE_BIND_LAZY);
345 g_module_symbol (module, "gtk_module_init", (gpointer*) &modinit_func) &&
348 if (!g_slist_find (gtk_modules, modinit_func))
350 g_module_make_resident (module);
351 slist->data = modinit_func;
355 g_module_close (module);
362 g_warning ("Failed to load module \"%s\": %s",
363 module ? g_module_name (module) : module_name,
366 g_module_close (module);
368 g_free (module_name);
372 bindtextdomain("gtk+",GTK_LOCALEDIR);
375 /* Initialize the default visual and colormap to be
376 * used in creating widgets. (We want to use the system
377 * defaults so as to be nice to the colormap).
379 gtk_visual = gdk_visual_get_system ();
380 gtk_colormap = gdk_colormap_get_system ();
387 /* Register an exit function to make sure we are able to cleanup.
389 g_atexit (gtk_exit_func);
391 /* Set the 'initialized' flag.
393 gtk_initialized = TRUE;
395 /* initialize gtk modules
397 for (slist = gtk_modules; slist; slist = slist->next)
401 GtkModuleInitFunc modinit;
403 modinit = slist->data;
404 modinit (argc, argv);
407 g_slist_free (gtk_modules);
411 gtk_exit (int errorcode)
413 /* Only if "gtk" has been initialized should we de-initialize.
415 /* de-initialisation is done by the gtk_exit_funct(),
416 * no need to do this here (Alex J.)
422 gtk_set_locale (void)
424 return gdk_set_locale ();
432 GtkInitFunction *init;
435 gtk_main_loop_level++;
437 loop = g_main_new (TRUE);
438 main_loops = g_slist_prepend (main_loops, loop);
440 tmp_list = functions = init_functions;
441 init_functions = NULL;
445 init = tmp_list->data;
446 tmp_list = tmp_list->next;
448 (* init->function) (init->data);
451 g_list_free (functions);
453 if (g_main_is_running (main_loops->data))
455 GDK_THREADS_LEAVE ();
457 GDK_THREADS_ENTER ();
463 GList *reinvoke_list = NULL;
464 GtkQuitFunction *quitf;
466 while (quit_functions)
468 quitf = quit_functions->data;
470 quit_functions = g_list_remove_link (quit_functions, quit_functions);
472 if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
473 gtk_quit_invoke_function (quitf))
475 reinvoke_list = g_list_prepend (reinvoke_list, quitf);
479 g_list_free (tmp_list);
480 gtk_quit_destroy (quitf);
487 work = g_list_last (reinvoke_list);
489 quit_functions->prev = work;
490 work->next = quit_functions;
491 quit_functions = work;
497 main_loops = g_slist_remove (main_loops, loop);
499 g_main_destroy (loop);
501 gtk_main_loop_level--;
505 gtk_main_level (void)
507 return gtk_main_loop_level;
513 g_return_if_fail (main_loops != NULL);
515 g_main_quit (main_loops->data);
519 gtk_events_pending (void)
521 return g_main_pending();
525 gtk_main_iteration (void)
527 g_main_iteration (TRUE);
530 return !g_main_is_running (main_loops->data);
536 gtk_main_iteration_do (gboolean blocking)
538 g_main_iteration (blocking);
541 return !g_main_is_running (main_loops->data);
547 gtk_main_do_event (GdkEvent *event)
549 GtkWidget *event_widget;
550 GtkWidget *grab_widget;
551 GdkEvent *next_event;
554 /* If there are any events pending then get the next one.
556 next_event = gdk_event_get ();
558 /* Try to compress enter/leave notify events. These event
559 * pairs occur when the mouse is dragged quickly across
560 * a window with many buttons (or through a menu). Instead
561 * of highlighting and de-highlighting each widget that
562 * is crossed it is better to simply de-highlight the widget
563 * which contained the mouse initially and highlight the
564 * widget which ends up containing the mouse.
567 if (((event->type == GDK_ENTER_NOTIFY) ||
568 (event->type == GDK_LEAVE_NOTIFY)) &&
569 ((next_event->type == GDK_ENTER_NOTIFY) ||
570 (next_event->type == GDK_LEAVE_NOTIFY)) &&
571 (next_event->type != event->type) &&
572 (next_event->any.window == event->any.window))
574 gdk_event_free (next_event);
583 gdk_event_put (next_event);
584 gdk_event_free (next_event);
588 /* Find the widget which got the event. We store the widget
589 * in the user_data field of GdkWindow's.
590 * Ignore the event if we don't have a widget for it, except
591 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
592 * Though this happens rarely, bogus events can occour
593 * for e.g. destroyed GdkWindows.
595 event_widget = gtk_get_event_widget (event);
598 /* To handle selection INCR transactions, we select
599 * PropertyNotify events on the requestor window and create
600 * a corresponding (fake) GdkWindow so that events get
601 * here. There won't be a widget though, so we have to handle
604 if (event->type == GDK_PROPERTY_NOTIFY)
605 gtk_selection_incr_event (event->any.window,
611 /* Push the event onto a stack of current events for
612 * gtk_current_event_get().
614 current_events = g_list_prepend (current_events, event);
616 /* If there is a grab in effect...
620 grab_widget = grabs->data;
622 /* If the grab widget is an ancestor of the event widget
623 * then we send the event to the original event widget.
624 * This is the key to implementing modality.
626 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
627 gtk_widget_is_ancestor (event_widget, grab_widget))
628 grab_widget = event_widget;
632 grab_widget = event_widget;
635 /* Not all events get sent to the grabbing widget.
636 * The delete, destroy, expose, focus change and resize
637 * events still get sent to the event widget because
638 * 1) these events have no meaning for the grabbing widget
639 * and 2) redirecting these events to the grabbing widget
640 * could cause the display to be messed up.
642 * Drag events are also not redirected, since it isn't
643 * clear what the semantics of that would be.
651 gtk_widget_ref (event_widget);
652 if (!gtk_widget_event (event_widget, event) &&
653 !GTK_OBJECT_DESTROYED (event_widget))
654 gtk_widget_destroy (event_widget);
655 gtk_widget_unref (event_widget);
659 gtk_widget_ref (event_widget);
660 gtk_widget_event (event_widget, event);
661 if (!GTK_OBJECT_DESTROYED (event_widget))
662 gtk_widget_destroy (event_widget);
663 gtk_widget_unref (event_widget);
666 case GDK_PROPERTY_NOTIFY:
669 case GDK_FOCUS_CHANGE:
673 case GDK_SELECTION_CLEAR:
674 case GDK_SELECTION_REQUEST:
675 case GDK_SELECTION_NOTIFY:
676 case GDK_CLIENT_EVENT:
677 case GDK_VISIBILITY_NOTIFY:
678 gtk_widget_event (event_widget, event);
682 case GDK_KEY_RELEASE:
685 if (gtk_invoke_key_snoopers (grab_widget, event))
688 /* else fall through */
689 case GDK_MOTION_NOTIFY:
690 case GDK_BUTTON_PRESS:
691 case GDK_2BUTTON_PRESS:
692 case GDK_3BUTTON_PRESS:
693 case GDK_BUTTON_RELEASE:
694 case GDK_PROXIMITY_IN:
695 case GDK_PROXIMITY_OUT:
696 gtk_propagate_event (grab_widget, event);
699 case GDK_ENTER_NOTIFY:
700 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
702 gtk_widget_event (grab_widget, event);
703 if (event_widget == grab_widget)
704 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
708 case GDK_LEAVE_NOTIFY:
709 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
711 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
712 gtk_widget_event (event_widget, event);
714 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
715 gtk_widget_event (grab_widget, event);
718 case GDK_DRAG_STATUS:
719 case GDK_DROP_FINISHED:
720 gtk_drag_source_handle_event (event_widget, event);
724 case GDK_DRAG_MOTION:
726 gtk_drag_dest_handle_event (event_widget, event);
730 tmp_list = current_events;
731 current_events = g_list_remove_link (current_events, tmp_list);
732 g_list_free_1 (tmp_list);
748 gtk_grab_add (GtkWidget *widget)
750 g_return_if_fail (widget != NULL);
752 if (!GTK_WIDGET_HAS_GRAB (widget))
754 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
756 grabs = g_slist_prepend (grabs, widget);
757 gtk_widget_ref (widget);
762 gtk_grab_get_current (void)
765 return GTK_WIDGET (grabs->data);
770 gtk_grab_remove (GtkWidget *widget)
772 g_return_if_fail (widget != NULL);
774 if (GTK_WIDGET_HAS_GRAB (widget))
776 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
778 grabs = g_slist_remove (grabs, widget);
779 gtk_widget_unref (widget);
784 gtk_init_add (GtkFunction function,
787 GtkInitFunction *init;
789 init = g_new (GtkInitFunction, 1);
790 init->function = function;
793 init_functions = g_list_prepend (init_functions, init);
797 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
800 GtkKeySnooperData *data;
801 static guint snooper_id = 1;
803 g_return_val_if_fail (snooper != NULL, 0);
805 data = g_new (GtkKeySnooperData, 1);
806 data->func = snooper;
807 data->func_data = func_data;
808 data->id = snooper_id++;
809 key_snoopers = g_slist_prepend (key_snoopers, data);
815 gtk_key_snooper_remove (guint snooper_id)
817 GtkKeySnooperData *data = NULL;
820 slist = key_snoopers;
824 if (data->id == snooper_id)
831 key_snoopers = g_slist_remove (key_snoopers, data);
835 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
839 gint return_val = FALSE;
841 slist = key_snoopers;
842 while (slist && !return_val)
844 GtkKeySnooperData *data;
848 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
855 gtk_quit_add_full (guint main_level,
856 GtkFunction function,
857 GtkCallbackMarshal marshal,
859 GtkDestroyNotify destroy)
861 static guint quit_id = 1;
862 GtkQuitFunction *quitf;
864 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
867 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
868 512, G_ALLOC_AND_FREE);
870 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
872 quitf->id = quit_id++;
873 quitf->main_level = main_level;
874 quitf->function = function;
875 quitf->marshal = marshal;
877 quitf->destroy = destroy;
879 quit_functions = g_list_prepend (quit_functions, quitf);
885 gtk_quit_destroy (GtkQuitFunction *quitf)
888 quitf->destroy (quitf->data);
889 g_mem_chunk_free (quit_mem_chunk, quitf);
893 gtk_quit_destructor (GtkObject **object_p)
896 gtk_object_destroy (*object_p);
903 gtk_quit_add_destroy (guint main_level,
906 GtkObject **object_p;
908 g_return_if_fail (main_level > 0);
909 g_return_if_fail (object != NULL);
910 g_return_if_fail (GTK_IS_OBJECT (object));
912 object_p = g_new (GtkObject*, 1);
914 gtk_signal_connect (object,
916 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
918 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
922 gtk_quit_add (guint main_level,
923 GtkFunction function,
926 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
930 gtk_quit_remove (guint id)
932 GtkQuitFunction *quitf;
935 tmp_list = quit_functions;
938 quitf = tmp_list->data;
942 quit_functions = g_list_remove_link (quit_functions, tmp_list);
943 g_list_free (tmp_list);
944 gtk_quit_destroy (quitf);
949 tmp_list = tmp_list->next;
954 gtk_quit_remove_by_data (gpointer data)
956 GtkQuitFunction *quitf;
959 tmp_list = quit_functions;
962 quitf = tmp_list->data;
964 if (quitf->data == data)
966 quit_functions = g_list_remove_link (quit_functions, tmp_list);
967 g_list_free (tmp_list);
968 gtk_quit_destroy (quitf);
973 tmp_list = tmp_list->next;
978 gtk_timeout_add_full (guint32 interval,
979 GtkFunction function,
980 GtkCallbackMarshal marshal,
982 GtkDestroyNotify destroy)
988 closure = g_new (GtkClosure, 1);
989 closure->marshal = marshal;
990 closure->data = data;
991 closure->destroy = destroy;
993 return g_timeout_add_full (0, interval,
994 gtk_invoke_idle_timeout,
996 gtk_destroy_closure);
999 return g_timeout_add_full (0, interval, function, data, destroy);
1003 gtk_timeout_add (guint32 interval,
1004 GtkFunction function,
1007 return g_timeout_add_full (0, interval, function, data, NULL);
1011 gtk_timeout_remove (guint tag)
1013 g_source_remove (tag);
1017 gtk_idle_add_full (gint priority,
1018 GtkFunction function,
1019 GtkCallbackMarshal marshal,
1021 GtkDestroyNotify destroy)
1025 GtkClosure *closure;
1027 closure = g_new (GtkClosure, 1);
1028 closure->marshal = marshal;
1029 closure->data = data;
1030 closure->destroy = destroy;
1032 return g_idle_add_full (priority,
1033 gtk_invoke_idle_timeout,
1035 gtk_destroy_closure);
1038 return g_idle_add_full (priority, function, data, destroy);
1042 gtk_idle_add (GtkFunction function,
1045 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1049 gtk_idle_add_priority (gint priority,
1050 GtkFunction function,
1053 return g_idle_add_full (priority, function, data, NULL);
1057 gtk_idle_remove (guint tag)
1059 g_source_remove (tag);
1063 gtk_idle_remove_by_data (gpointer data)
1065 g_source_remove_by_user_data (data);
1069 gtk_input_add_full (gint source,
1070 GdkInputCondition condition,
1071 GdkInputFunction function,
1072 GtkCallbackMarshal marshal,
1074 GtkDestroyNotify destroy)
1078 GtkClosure *closure;
1080 closure = g_new (GtkClosure, 1);
1081 closure->marshal = marshal;
1082 closure->data = data;
1083 closure->destroy = destroy;
1085 return gdk_input_add_full (source,
1087 (GdkInputFunction) gtk_invoke_input,
1089 (GdkDestroyNotify) gtk_destroy_closure);
1092 return gdk_input_add_full (source, condition, function, data, destroy);
1096 gtk_input_remove (guint tag)
1098 g_source_remove (tag);
1102 gtk_destroy_closure (gpointer data)
1104 GtkClosure *closure = data;
1106 if (closure->destroy)
1107 (closure->destroy) (closure->data);
1112 gtk_invoke_idle_timeout (gpointer data)
1114 GtkClosure *closure = data;
1117 gint ret_val = FALSE;
1118 args[0].name = NULL;
1119 args[0].type = GTK_TYPE_BOOL;
1120 args[0].d.pointer_data = &ret_val;
1121 closure->marshal (NULL, closure->data, 0, args);
1126 gtk_invoke_input (gpointer data,
1128 GdkInputCondition condition)
1130 GtkClosure *closure = data;
1133 args[0].type = GTK_TYPE_INT;
1134 args[0].name = NULL;
1135 GTK_VALUE_INT(args[0]) = source;
1136 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1137 args[1].name = NULL;
1138 GTK_VALUE_FLAGS(args[1]) = condition;
1139 args[2].type = GTK_TYPE_NONE;
1140 args[2].name = NULL;
1142 closure->marshal (NULL, closure->data, 2, args);
1146 gtk_get_current_event (void)
1149 return gdk_event_copy ((GdkEvent *) current_events->data);
1155 gtk_get_event_widget (GdkEvent *event)
1160 if (event && event->any.window)
1161 gdk_window_get_user_data (event->any.window, (void**) &widget);
1167 gtk_exit_func (void)
1169 if (gtk_initialized)
1171 gtk_initialized = FALSE;
1172 gtk_preview_uninit ();
1178 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1180 if (!quitf->marshal)
1181 return quitf->function (quitf->data);
1185 gint ret_val = FALSE;
1187 args[0].name = NULL;
1188 args[0].type = GTK_TYPE_BOOL;
1189 args[0].d.pointer_data = &ret_val;
1190 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1198 gtk_propagate_event (GtkWidget *widget,
1203 g_return_if_fail (widget != NULL);
1204 g_return_if_fail (GTK_IS_WIDGET (widget));
1205 g_return_if_fail (event != NULL);
1207 handled_event = FALSE;
1209 if ((event->type == GDK_KEY_PRESS) ||
1210 (event->type == GDK_KEY_RELEASE))
1212 /* Only send key events within Window widgets to the Window
1213 * The Window widget will in turn pass the
1214 * key event on to the currently focused widget
1219 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1222 if (GTK_WIDGET_IS_SENSITIVE (window))
1223 gtk_widget_event (window, event);
1225 handled_event = TRUE; /* don't send to widget */
1229 /* Other events get propagated up the widget tree
1230 * so that parents can see the button and motion
1231 * events of the children.
1233 while (!handled_event && widget)
1237 gtk_widget_ref (widget);
1238 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1239 tmp = widget->parent;
1240 gtk_widget_unref (widget);
1247 gtk_error (gchar *str)
1253 gtk_warning (gchar *str)
1259 gtk_message (gchar *str)
1265 gtk_print (gchar *str)
1267 static GtkWidget *window = NULL;
1268 static GtkWidget *text;
1269 static int level = 0;
1273 GtkWidget *hscrollbar;
1274 GtkWidget *vscrollbar;
1275 GtkWidget *separator;
1280 fputs (str, stdout);
1287 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1289 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1290 (GtkSignalFunc) gtk_widget_destroyed,
1293 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1295 box1 = gtk_vbox_new (FALSE, 0);
1296 gtk_container_add (GTK_CONTAINER (window), box1);
1297 gtk_widget_show (box1);
1300 box2 = gtk_vbox_new (FALSE, 10);
1301 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1302 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1303 gtk_widget_show (box2);
1306 table = gtk_table_new (2, 2, FALSE);
1307 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1308 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1309 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1310 gtk_widget_show (table);
1312 text = gtk_text_new (NULL, NULL);
1313 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1314 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1315 gtk_widget_show (text);
1316 gtk_widget_realize (text);
1318 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1319 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1320 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1321 gtk_widget_show (hscrollbar);
1323 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1324 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1325 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1326 gtk_widget_show (vscrollbar);
1328 separator = gtk_hseparator_new ();
1329 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1330 gtk_widget_show (separator);
1333 box2 = gtk_vbox_new (FALSE, 10);
1334 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1335 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1336 gtk_widget_show (box2);
1339 button = gtk_button_new_with_label ("close");
1340 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1341 (GtkSignalFunc) gtk_widget_hide,
1342 GTK_OBJECT (window));
1343 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1344 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1345 gtk_widget_grab_default (button);
1346 gtk_widget_show (button);
1350 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1353 if (!GTK_WIDGET_VISIBLE (window))
1354 gtk_widget_show (window);