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_peek ();
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 /* Throw both the peeked copy and the queued copy away
576 gdk_event_free (next_event);
577 next_event = gdk_event_get ();
578 gdk_event_free (next_event);
584 gdk_event_free (next_event);
586 /* Find the widget which got the event. We store the widget
587 * in the user_data field of GdkWindow's.
588 * Ignore the event if we don't have a widget for it, except
589 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
590 * Though this happens rarely, bogus events can occour
591 * for e.g. destroyed GdkWindows.
593 event_widget = gtk_get_event_widget (event);
596 /* To handle selection INCR transactions, we select
597 * PropertyNotify events on the requestor window and create
598 * a corresponding (fake) GdkWindow so that events get
599 * here. There won't be a widget though, so we have to handle
602 if (event->type == GDK_PROPERTY_NOTIFY)
603 gtk_selection_incr_event (event->any.window,
609 /* Push the event onto a stack of current events for
610 * gtk_current_event_get().
612 current_events = g_list_prepend (current_events, event);
614 /* If there is a grab in effect...
618 grab_widget = grabs->data;
620 /* If the grab widget is an ancestor of the event widget
621 * then we send the event to the original event widget.
622 * This is the key to implementing modality.
624 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
625 gtk_widget_is_ancestor (event_widget, grab_widget))
626 grab_widget = event_widget;
630 grab_widget = event_widget;
633 /* Not all events get sent to the grabbing widget.
634 * The delete, destroy, expose, focus change and resize
635 * events still get sent to the event widget because
636 * 1) these events have no meaning for the grabbing widget
637 * and 2) redirecting these events to the grabbing widget
638 * could cause the display to be messed up.
640 * Drag events are also not redirected, since it isn't
641 * clear what the semantics of that would be.
649 gtk_widget_ref (event_widget);
650 if (!gtk_widget_event (event_widget, event) &&
651 !GTK_OBJECT_DESTROYED (event_widget))
652 gtk_widget_destroy (event_widget);
653 gtk_widget_unref (event_widget);
657 gtk_widget_ref (event_widget);
658 gtk_widget_event (event_widget, event);
659 if (!GTK_OBJECT_DESTROYED (event_widget))
660 gtk_widget_destroy (event_widget);
661 gtk_widget_unref (event_widget);
664 case GDK_PROPERTY_NOTIFY:
667 case GDK_FOCUS_CHANGE:
671 case GDK_SELECTION_CLEAR:
672 case GDK_SELECTION_REQUEST:
673 case GDK_SELECTION_NOTIFY:
674 case GDK_CLIENT_EVENT:
675 case GDK_VISIBILITY_NOTIFY:
676 gtk_widget_event (event_widget, event);
680 case GDK_KEY_RELEASE:
683 if (gtk_invoke_key_snoopers (grab_widget, event))
686 /* else fall through */
687 case GDK_MOTION_NOTIFY:
688 case GDK_BUTTON_PRESS:
689 case GDK_2BUTTON_PRESS:
690 case GDK_3BUTTON_PRESS:
691 case GDK_BUTTON_RELEASE:
692 case GDK_PROXIMITY_IN:
693 case GDK_PROXIMITY_OUT:
694 gtk_propagate_event (grab_widget, event);
697 case GDK_ENTER_NOTIFY:
698 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
700 gtk_widget_event (grab_widget, event);
701 if (event_widget == grab_widget)
702 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
706 case GDK_LEAVE_NOTIFY:
707 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
709 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
710 gtk_widget_event (event_widget, event);
712 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
713 gtk_widget_event (grab_widget, event);
716 case GDK_DRAG_STATUS:
717 case GDK_DROP_FINISHED:
718 gtk_drag_source_handle_event (event_widget, event);
722 case GDK_DRAG_MOTION:
724 gtk_drag_dest_handle_event (event_widget, event);
728 tmp_list = current_events;
729 current_events = g_list_remove_link (current_events, tmp_list);
730 g_list_free_1 (tmp_list);
746 gtk_grab_add (GtkWidget *widget)
748 g_return_if_fail (widget != NULL);
750 if (!GTK_WIDGET_HAS_GRAB (widget))
752 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
754 grabs = g_slist_prepend (grabs, widget);
755 gtk_widget_ref (widget);
760 gtk_grab_get_current (void)
763 return GTK_WIDGET (grabs->data);
768 gtk_grab_remove (GtkWidget *widget)
770 g_return_if_fail (widget != NULL);
772 if (GTK_WIDGET_HAS_GRAB (widget))
774 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
776 grabs = g_slist_remove (grabs, widget);
777 gtk_widget_unref (widget);
782 gtk_init_add (GtkFunction function,
785 GtkInitFunction *init;
787 init = g_new (GtkInitFunction, 1);
788 init->function = function;
791 init_functions = g_list_prepend (init_functions, init);
795 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
798 GtkKeySnooperData *data;
799 static guint snooper_id = 1;
801 g_return_val_if_fail (snooper != NULL, 0);
803 data = g_new (GtkKeySnooperData, 1);
804 data->func = snooper;
805 data->func_data = func_data;
806 data->id = snooper_id++;
807 key_snoopers = g_slist_prepend (key_snoopers, data);
813 gtk_key_snooper_remove (guint snooper_id)
815 GtkKeySnooperData *data = NULL;
818 slist = key_snoopers;
822 if (data->id == snooper_id)
829 key_snoopers = g_slist_remove (key_snoopers, data);
833 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
837 gint return_val = FALSE;
839 slist = key_snoopers;
840 while (slist && !return_val)
842 GtkKeySnooperData *data;
846 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
853 gtk_quit_add_full (guint main_level,
854 GtkFunction function,
855 GtkCallbackMarshal marshal,
857 GtkDestroyNotify destroy)
859 static guint quit_id = 1;
860 GtkQuitFunction *quitf;
862 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
865 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
866 512, G_ALLOC_AND_FREE);
868 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
870 quitf->id = quit_id++;
871 quitf->main_level = main_level;
872 quitf->function = function;
873 quitf->marshal = marshal;
875 quitf->destroy = destroy;
877 quit_functions = g_list_prepend (quit_functions, quitf);
883 gtk_quit_destroy (GtkQuitFunction *quitf)
886 quitf->destroy (quitf->data);
887 g_mem_chunk_free (quit_mem_chunk, quitf);
891 gtk_quit_destructor (GtkObject **object_p)
894 gtk_object_destroy (*object_p);
901 gtk_quit_add_destroy (guint main_level,
904 GtkObject **object_p;
906 g_return_if_fail (main_level > 0);
907 g_return_if_fail (object != NULL);
908 g_return_if_fail (GTK_IS_OBJECT (object));
910 object_p = g_new (GtkObject*, 1);
912 gtk_signal_connect (object,
914 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
916 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
920 gtk_quit_add (guint main_level,
921 GtkFunction function,
924 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
928 gtk_quit_remove (guint id)
930 GtkQuitFunction *quitf;
933 tmp_list = quit_functions;
936 quitf = tmp_list->data;
940 quit_functions = g_list_remove_link (quit_functions, tmp_list);
941 g_list_free (tmp_list);
942 gtk_quit_destroy (quitf);
947 tmp_list = tmp_list->next;
952 gtk_quit_remove_by_data (gpointer data)
954 GtkQuitFunction *quitf;
957 tmp_list = quit_functions;
960 quitf = tmp_list->data;
962 if (quitf->data == data)
964 quit_functions = g_list_remove_link (quit_functions, tmp_list);
965 g_list_free (tmp_list);
966 gtk_quit_destroy (quitf);
971 tmp_list = tmp_list->next;
976 gtk_timeout_add_full (guint32 interval,
977 GtkFunction function,
978 GtkCallbackMarshal marshal,
980 GtkDestroyNotify destroy)
986 closure = g_new (GtkClosure, 1);
987 closure->marshal = marshal;
988 closure->data = data;
989 closure->destroy = destroy;
991 return g_timeout_add_full (0, interval,
992 gtk_invoke_idle_timeout,
994 gtk_destroy_closure);
997 return g_timeout_add_full (0, interval, function, data, destroy);
1001 gtk_timeout_add (guint32 interval,
1002 GtkFunction function,
1005 return g_timeout_add_full (0, interval, function, data, NULL);
1009 gtk_timeout_remove (guint tag)
1011 g_source_remove (tag);
1015 gtk_idle_add_full (gint priority,
1016 GtkFunction function,
1017 GtkCallbackMarshal marshal,
1019 GtkDestroyNotify destroy)
1023 GtkClosure *closure;
1025 closure = g_new (GtkClosure, 1);
1026 closure->marshal = marshal;
1027 closure->data = data;
1028 closure->destroy = destroy;
1030 return g_idle_add_full (priority,
1031 gtk_invoke_idle_timeout,
1033 gtk_destroy_closure);
1036 return g_idle_add_full (priority, function, data, destroy);
1040 gtk_idle_add (GtkFunction function,
1043 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1047 gtk_idle_add_priority (gint priority,
1048 GtkFunction function,
1051 return g_idle_add_full (priority, function, data, NULL);
1055 gtk_idle_remove (guint tag)
1057 g_source_remove (tag);
1061 gtk_idle_remove_by_data (gpointer data)
1063 if (!g_idle_remove_by_data (data))
1064 g_warning ("gtk_idle_remove_by_data(%p): no such idle", data);
1068 gtk_input_add_full (gint source,
1069 GdkInputCondition condition,
1070 GdkInputFunction 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 gdk_input_add_full (source,
1086 (GdkInputFunction) gtk_invoke_input,
1088 (GdkDestroyNotify) gtk_destroy_closure);
1091 return gdk_input_add_full (source, condition, function, data, destroy);
1095 gtk_input_remove (guint tag)
1097 g_source_remove (tag);
1101 gtk_destroy_closure (gpointer data)
1103 GtkClosure *closure = data;
1105 if (closure->destroy)
1106 (closure->destroy) (closure->data);
1111 gtk_invoke_idle_timeout (gpointer data)
1113 GtkClosure *closure = data;
1116 gint ret_val = FALSE;
1117 args[0].name = NULL;
1118 args[0].type = GTK_TYPE_BOOL;
1119 args[0].d.pointer_data = &ret_val;
1120 closure->marshal (NULL, closure->data, 0, args);
1125 gtk_invoke_input (gpointer data,
1127 GdkInputCondition condition)
1129 GtkClosure *closure = data;
1132 args[0].type = GTK_TYPE_INT;
1133 args[0].name = NULL;
1134 GTK_VALUE_INT(args[0]) = source;
1135 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1136 args[1].name = NULL;
1137 GTK_VALUE_FLAGS(args[1]) = condition;
1138 args[2].type = GTK_TYPE_NONE;
1139 args[2].name = NULL;
1141 closure->marshal (NULL, closure->data, 2, args);
1145 gtk_get_current_event (void)
1148 return gdk_event_copy ((GdkEvent *) current_events->data);
1154 gtk_get_event_widget (GdkEvent *event)
1159 if (event && event->any.window)
1160 gdk_window_get_user_data (event->any.window, (void**) &widget);
1166 gtk_exit_func (void)
1168 if (gtk_initialized)
1170 gtk_initialized = FALSE;
1171 gtk_preview_uninit ();
1177 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1179 if (!quitf->marshal)
1180 return quitf->function (quitf->data);
1184 gint ret_val = FALSE;
1186 args[0].name = NULL;
1187 args[0].type = GTK_TYPE_BOOL;
1188 args[0].d.pointer_data = &ret_val;
1189 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1197 gtk_propagate_event (GtkWidget *widget,
1202 g_return_if_fail (widget != NULL);
1203 g_return_if_fail (GTK_IS_WIDGET (widget));
1204 g_return_if_fail (event != NULL);
1206 handled_event = FALSE;
1208 if ((event->type == GDK_KEY_PRESS) ||
1209 (event->type == GDK_KEY_RELEASE))
1211 /* Only send key events within Window widgets to the Window
1212 * The Window widget will in turn pass the
1213 * key event on to the currently focused widget
1218 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1221 if (GTK_WIDGET_IS_SENSITIVE (window))
1222 gtk_widget_event (window, event);
1224 handled_event = TRUE; /* don't send to widget */
1228 /* Other events get propagated up the widget tree
1229 * so that parents can see the button and motion
1230 * events of the children.
1232 while (!handled_event && widget)
1236 gtk_widget_ref (widget);
1237 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1238 tmp = widget->parent;
1239 gtk_widget_unref (widget);
1246 gtk_error (gchar *str)
1252 gtk_warning (gchar *str)
1258 gtk_message (gchar *str)
1264 gtk_print (gchar *str)
1266 static GtkWidget *window = NULL;
1267 static GtkWidget *text;
1268 static int level = 0;
1272 GtkWidget *hscrollbar;
1273 GtkWidget *vscrollbar;
1274 GtkWidget *separator;
1279 fputs (str, stdout);
1286 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1288 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1289 (GtkSignalFunc) gtk_widget_destroyed,
1292 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1294 box1 = gtk_vbox_new (FALSE, 0);
1295 gtk_container_add (GTK_CONTAINER (window), box1);
1296 gtk_widget_show (box1);
1299 box2 = gtk_vbox_new (FALSE, 10);
1300 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1301 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1302 gtk_widget_show (box2);
1305 table = gtk_table_new (2, 2, FALSE);
1306 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1307 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1308 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1309 gtk_widget_show (table);
1311 text = gtk_text_new (NULL, NULL);
1312 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1313 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1314 gtk_widget_show (text);
1315 gtk_widget_realize (text);
1317 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1318 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1319 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1320 gtk_widget_show (hscrollbar);
1322 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1323 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1324 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1325 gtk_widget_show (vscrollbar);
1327 separator = gtk_hseparator_new ();
1328 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1329 gtk_widget_show (separator);
1332 box2 = gtk_vbox_new (FALSE, 10);
1333 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1334 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1335 gtk_widget_show (box2);
1338 button = gtk_button_new_with_label ("close");
1339 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1340 (GtkSignalFunc) gtk_widget_hide,
1341 GTK_OBJECT (window));
1342 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1343 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1344 gtk_widget_grab_default (button);
1345 gtk_widget_show (button);
1349 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1352 if (!GTK_WIDGET_VISIBLE (window))
1353 gtk_widget_show (window);