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 extern gboolean gdk_using_threads;
48 /* Private type definitions
50 typedef struct _GtkInitFunction GtkInitFunction;
51 typedef struct _GtkQuitFunction GtkQuitFunction;
52 typedef struct _GtkClosure GtkClosure;
53 typedef struct _GtkKeySnooperData GtkKeySnooperData;
55 struct _GtkInitFunction
61 struct _GtkQuitFunction
65 GtkCallbackMarshal marshal;
68 GtkDestroyNotify destroy;
73 GtkCallbackMarshal marshal;
75 GtkDestroyNotify destroy;
78 struct _GtkKeySnooperData
85 static void gtk_exit_func (void);
86 static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
87 static void gtk_quit_destroy (GtkQuitFunction *quitf);
88 static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
90 static void gtk_propagate_event (GtkWidget *widget,
93 static void gtk_destroy_closure (gpointer data);
94 static gboolean gtk_invoke_idle_timeout (gpointer data);
95 static void gtk_invoke_input (gpointer data,
97 GdkInputCondition condition);
100 static void gtk_error (gchar *str);
101 static void gtk_warning (gchar *str);
102 static void gtk_message (gchar *str);
103 static void gtk_print (gchar *str);
106 const guint gtk_major_version = GTK_MAJOR_VERSION;
107 const guint gtk_minor_version = GTK_MINOR_VERSION;
108 const guint gtk_micro_version = GTK_MICRO_VERSION;
109 const guint gtk_binary_age = GTK_BINARY_AGE;
110 const guint gtk_interface_age = GTK_INTERFACE_AGE;
112 static guint gtk_main_loop_level = 0;
113 static gint gtk_initialized = FALSE;
114 static GList *current_events = NULL;
116 static GSList *main_loops = NULL; /* stack of currently executing main loops */
118 static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
119 * widget is the first one on the list.
121 static GList *init_functions = NULL; /* A list of init functions.
123 static GList *quit_functions = NULL; /* A list of quit functions.
125 static GMemChunk *quit_mem_chunk = NULL;
127 static GSList *key_snoopers = NULL;
129 static GdkVisual *gtk_visual; /* The visual to be used in creating new
132 static GdkColormap *gtk_colormap; /* The colormap to be used in creating new
136 guint gtk_debug_flags = 0; /* Global GTK debug flag */
138 GMutex *gtk_threads_mutex = NULL; /* Global GTK lock */
140 #ifdef G_ENABLE_DEBUG
141 static const GDebugKey gtk_debug_keys[] = {
142 {"objects", GTK_DEBUG_OBJECTS},
143 {"misc", GTK_DEBUG_MISC},
144 {"signals", GTK_DEBUG_SIGNALS},
145 {"dnd", GTK_DEBUG_DND}
148 static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
150 #endif /* G_ENABLE_DEBUG */
153 gtk_check_version (guint required_major,
154 guint required_minor,
155 guint required_micro)
157 if (required_major > GTK_MAJOR_VERSION)
158 return "Gtk+ version to old (major mismatch)";
159 if (required_major < GTK_MAJOR_VERSION)
160 return "Gtk+ version to new (major mismatch)";
161 if (required_minor > GTK_MINOR_VERSION)
162 return "Gtk+ version to old (minor mismatch)";
163 if (required_minor < GTK_MINOR_VERSION)
164 return "Gtk+ version to new (minor mismatch)";
165 if (required_micro < GTK_MICRO_VERSION - GTK_BINARY_AGE)
166 return "Gtk+ version to new (micro mismatch)";
167 if (required_micro > GTK_MICRO_VERSION)
168 return "Gtk+ version to old (micro mismatch)";
177 GSList *gtk_modules = NULL;
179 gchar *env_string = NULL;
184 /* There is some argument for putting this in a separate
185 * function ... but I don't think that it is much
186 * of a restriction to require that GTK+ be used
187 * single threaded until gtk_init().
190 if (g_thread_supported)
191 gtk_threads_mutex = g_mutex_new ();
194 g_set_error_handler (gtk_error);
195 g_set_warning_handler (gtk_warning);
196 g_set_message_handler (gtk_message);
197 g_set_print_handler (gtk_print);
200 /* Initialize "gdk". We pass along the 'argc' and 'argv'
201 * parameters as they contain information that GDK uses
203 gdk_init (argc, argv);
205 gdk_event_handler_set ((GdkEventFunc *)gtk_main_do_event, NULL, NULL);
207 #ifdef G_ENABLE_DEBUG
208 env_string = getenv ("GTK_DEBUG");
209 if (env_string != NULL)
211 gtk_debug_flags = g_parse_debug_string (env_string,
216 #endif /* G_ENABLE_DEBUG */
218 env_string = getenv ("GTK_MODULES");
221 gchar **modules, **as;
223 modules = g_strsplit (env_string, ":", -1);
224 for (as = modules; *as; as++)
227 gtk_modules = g_slist_prepend (gtk_modules, *as);
239 for (i = 1; i < *argc;)
241 if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
242 strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
244 gchar *module_name = (*argv)[i] + 12;
246 if (*module_name == '=')
252 module_name = (*argv)[i];
256 gtk_modules = g_slist_prepend (gtk_modules, g_strdup (module_name));
258 else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
260 GLogLevelFlags fatal_mask;
262 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
263 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
264 g_log_set_always_fatal (fatal_mask);
267 #ifdef G_ENABLE_DEBUG
268 else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
269 (strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
271 gchar *equal_pos = strchr ((*argv)[i], '=');
273 if (equal_pos != NULL)
275 gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
279 else if ((i + 1) < *argc && (*argv)[i + 1])
281 gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
289 else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
290 (strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 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 #endif /* G_ENABLE_DEBUG */
314 for (i = 1; i < *argc; i++)
316 for (k = i; k < *argc; k++)
317 if ((*argv)[k] != NULL)
323 for (j = i + k; j < *argc; j++)
324 (*argv)[j-k] = (*argv)[j];
330 /* load gtk modules */
331 gtk_modules = g_slist_reverse (gtk_modules);
332 for (slist = gtk_modules; slist; slist = slist->next)
335 GModule *module = NULL;
336 GtkModuleInitFunc modinit_func = NULL;
338 module_name = slist->data;
340 if (!(module_name[0] == '/' ||
341 (module_name[0] == 'l' &&
342 module_name[1] == 'i' &&
343 module_name[2] == 'b')))
345 gchar *old = module_name;
347 module_name = g_strconcat ("lib", module_name, ".so", NULL);
350 if (g_module_supported ())
352 module = g_module_open (module_name, G_MODULE_BIND_LAZY);
354 g_module_symbol (module, "gtk_module_init", (gpointer*) &modinit_func) &&
357 if (!g_slist_find (gtk_modules, modinit_func))
359 g_module_make_resident (module);
360 slist->data = modinit_func;
364 g_module_close (module);
371 g_warning ("Failed to load module \"%s\": %s",
372 module ? g_module_name (module) : module_name,
375 g_module_close (module);
377 g_free (module_name);
381 bindtextdomain("gtk+",GTK_LOCALEDIR);
384 /* Initialize the default visual and colormap to be
385 * used in creating widgets. (We want to use the system
386 * defaults so as to be nice to the colormap).
388 gtk_visual = gdk_visual_get_system ();
389 gtk_colormap = gdk_colormap_get_system ();
396 /* Register an exit function to make sure we are able to cleanup.
398 g_atexit (gtk_exit_func);
400 /* Set the 'initialized' flag.
402 gtk_initialized = TRUE;
404 /* initialize gtk modules
406 for (slist = gtk_modules; slist; slist = slist->next)
410 GtkModuleInitFunc modinit;
412 modinit = slist->data;
413 modinit (argc, argv);
416 g_slist_free (gtk_modules);
420 gtk_exit (int errorcode)
422 /* Only if "gtk" has been initialized should we de-initialize.
424 /* de-initialisation is done by the gtk_exit_funct(),
425 * no need to do this here (Alex J.)
431 gtk_set_locale (void)
433 return gdk_set_locale ();
441 GtkInitFunction *init;
446 gtk_main_loop_level++;
448 tmp_list = functions = init_functions;
449 init_functions = NULL;
453 init = tmp_list->data;
454 tmp_list = tmp_list->next;
456 (* init->function) (init->data);
459 g_list_free (functions);
461 loop = g_main_new ();
462 main_loops = g_slist_prepend (main_loops, loop);
468 g_main_destroy (loop);
470 tmp_node = main_loops;
471 main_loops = g_slist_remove_link (main_loops, main_loops);
472 g_slist_free_1 (tmp_node);
476 GList *reinvoke_list = NULL;
477 GtkQuitFunction *quitf;
479 while (quit_functions)
481 quitf = quit_functions->data;
483 quit_functions = g_list_remove_link (quit_functions, quit_functions);
485 if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
486 gtk_quit_invoke_function (quitf))
488 reinvoke_list = g_list_prepend (reinvoke_list, quitf);
492 g_list_free (tmp_list);
493 gtk_quit_destroy (quitf);
500 work = g_list_last (reinvoke_list);
502 quit_functions->prev = work;
503 work->next = quit_functions;
504 quit_functions = work;
508 gtk_main_loop_level--;
512 gtk_main_level (void)
514 return gtk_main_loop_level;
520 g_main_quit (main_loops->data);
524 gtk_events_pending (void)
526 return g_main_pending();
530 gtk_main_iteration (void)
532 return g_main_iteration (TRUE);
536 gtk_main_iteration_do (gboolean blocking)
538 return g_main_iteration (blocking);
542 gtk_main_do_event (GdkEvent *event)
544 GtkWidget *event_widget;
545 GtkWidget *grab_widget;
546 GdkEvent *next_event;
549 /* If there are any events pending then get the next one.
551 next_event = gdk_event_get ();
553 /* Try to compress enter/leave notify events. These event
554 * pairs occur when the mouse is dragged quickly across
555 * a window with many buttons (or through a menu). Instead
556 * of highlighting and de-highlighting each widget that
557 * is crossed it is better to simply de-highlight the widget
558 * which contained the mouse initially and highlight the
559 * widget which ends up containing the mouse.
562 if (((event->type == GDK_ENTER_NOTIFY) ||
563 (event->type == GDK_LEAVE_NOTIFY)) &&
564 ((next_event->type == GDK_ENTER_NOTIFY) ||
565 (next_event->type == GDK_LEAVE_NOTIFY)) &&
566 (next_event->type != event->type) &&
567 (next_event->any.window == event->any.window))
569 gdk_event_free (next_event);
577 gdk_event_put (next_event);
580 /* Find the widget which got the event. We store the widget
581 * in the user_data field of GdkWindow's.
582 * Ignore the event if we don't have a widget for it, except
583 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
584 * Though this happens rarely, bogus events can occour
585 * for e.g. destroyed GdkWindows.
587 event_widget = gtk_get_event_widget (event);
590 /* To handle selection INCR transactions, we select
591 * PropertyNotify events on the requestor window and create
592 * a corresponding (fake) GdkWindow so that events get
593 * here. There won't be a widget though, so we have to handle
596 if (event->type == GDK_PROPERTY_NOTIFY)
597 gtk_selection_incr_event (event->any.window,
603 /* Push the event onto a stack of current events for
604 * gtk_current_event_get().
606 current_events = g_list_prepend (current_events, event);
608 /* If there is a grab in effect...
612 grab_widget = grabs->data;
614 /* If the grab widget is an ancestor of the event widget
615 * then we send the event to the original event widget.
616 * This is the key to implementing modality.
618 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
619 gtk_widget_is_ancestor (event_widget, grab_widget))
620 grab_widget = event_widget;
624 grab_widget = event_widget;
627 /* Not all events get sent to the grabbing widget.
628 * The delete, destroy, expose, focus change and resize
629 * events still get sent to the event widget because
630 * 1) these events have no meaning for the grabbing widget
631 * and 2) redirecting these events to the grabbing widget
632 * could cause the display to be messed up.
634 * Drag events are also not redirected, since it isn't
635 * clear what the semantics of that would be.
643 gtk_widget_ref (event_widget);
644 if (!gtk_widget_event (event_widget, event) &&
645 !GTK_OBJECT_DESTROYED (event_widget))
646 gtk_widget_destroy (event_widget);
647 gtk_widget_unref (event_widget);
651 gtk_widget_ref (event_widget);
652 gtk_widget_event (event_widget, event);
653 if (!GTK_OBJECT_DESTROYED (event_widget))
654 gtk_widget_destroy (event_widget);
655 gtk_widget_unref (event_widget);
658 case GDK_PROPERTY_NOTIFY:
661 case GDK_FOCUS_CHANGE:
665 case GDK_SELECTION_CLEAR:
666 case GDK_SELECTION_REQUEST:
667 case GDK_SELECTION_NOTIFY:
668 case GDK_CLIENT_EVENT:
669 case GDK_VISIBILITY_NOTIFY:
670 gtk_widget_event (event_widget, event);
674 case GDK_KEY_RELEASE:
677 if (gtk_invoke_key_snoopers (grab_widget, event))
680 /* else fall through */
681 case GDK_MOTION_NOTIFY:
682 case GDK_BUTTON_PRESS:
683 case GDK_2BUTTON_PRESS:
684 case GDK_3BUTTON_PRESS:
685 case GDK_BUTTON_RELEASE:
686 case GDK_PROXIMITY_IN:
687 case GDK_PROXIMITY_OUT:
688 gtk_propagate_event (grab_widget, event);
691 case GDK_ENTER_NOTIFY:
692 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
694 gtk_widget_event (grab_widget, event);
695 if (event_widget == grab_widget)
696 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
700 case GDK_LEAVE_NOTIFY:
701 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
703 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
704 gtk_widget_event (event_widget, event);
706 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
707 gtk_widget_event (grab_widget, event);
710 case GDK_DRAG_STATUS:
711 case GDK_DROP_FINISHED:
712 gtk_drag_source_handle_event (event_widget, event);
716 case GDK_DRAG_MOTION:
718 gtk_drag_dest_handle_event (event_widget, event);
722 tmp_list = current_events;
723 current_events = g_list_remove_link (current_events, tmp_list);
724 g_list_free_1 (tmp_list);
740 gtk_grab_add (GtkWidget *widget)
742 g_return_if_fail (widget != NULL);
744 if (!GTK_WIDGET_HAS_GRAB (widget))
746 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
748 grabs = g_slist_prepend (grabs, widget);
749 gtk_widget_ref (widget);
754 gtk_grab_get_current (void)
757 return GTK_WIDGET (grabs->data);
762 gtk_grab_remove (GtkWidget *widget)
764 g_return_if_fail (widget != NULL);
766 if (GTK_WIDGET_HAS_GRAB (widget))
768 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
770 grabs = g_slist_remove (grabs, widget);
771 gtk_widget_unref (widget);
776 gtk_init_add (GtkFunction function,
779 GtkInitFunction *init;
781 init = g_new (GtkInitFunction, 1);
782 init->function = function;
785 init_functions = g_list_prepend (init_functions, init);
789 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
792 GtkKeySnooperData *data;
793 static guint snooper_id = 1;
795 g_return_val_if_fail (snooper != NULL, 0);
797 data = g_new (GtkKeySnooperData, 1);
798 data->func = snooper;
799 data->func_data = func_data;
800 data->id = snooper_id++;
801 key_snoopers = g_slist_prepend (key_snoopers, data);
807 gtk_key_snooper_remove (guint snooper_id)
809 GtkKeySnooperData *data = NULL;
812 slist = key_snoopers;
816 if (data->id == snooper_id)
823 key_snoopers = g_slist_remove (key_snoopers, data);
827 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
831 gint return_val = FALSE;
833 slist = key_snoopers;
834 while (slist && !return_val)
836 GtkKeySnooperData *data;
840 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
847 gtk_quit_add_full (guint main_level,
848 GtkFunction function,
849 GtkCallbackMarshal marshal,
851 GtkDestroyNotify destroy)
853 static guint quit_id = 1;
854 GtkQuitFunction *quitf;
856 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
859 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
860 512, G_ALLOC_AND_FREE);
862 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
864 quitf->id = quit_id++;
865 quitf->main_level = main_level;
866 quitf->function = function;
867 quitf->marshal = marshal;
869 quitf->destroy = destroy;
871 quit_functions = g_list_prepend (quit_functions, quitf);
877 gtk_quit_destroy (GtkQuitFunction *quitf)
880 quitf->destroy (quitf->data);
881 g_mem_chunk_free (quit_mem_chunk, quitf);
885 gtk_quit_destructor (GtkObject **object_p)
888 gtk_object_destroy (*object_p);
895 gtk_quit_add_destroy (guint main_level,
898 GtkObject **object_p;
900 g_return_if_fail (main_level > 0);
901 g_return_if_fail (object != NULL);
902 g_return_if_fail (GTK_IS_OBJECT (object));
904 object_p = g_new (GtkObject*, 1);
906 gtk_signal_connect (object,
908 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
910 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
914 gtk_quit_add (guint main_level,
915 GtkFunction function,
918 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
922 gtk_quit_remove (guint id)
924 GtkQuitFunction *quitf;
927 tmp_list = quit_functions;
930 quitf = tmp_list->data;
934 quit_functions = g_list_remove_link (quit_functions, tmp_list);
935 g_list_free (tmp_list);
936 gtk_quit_destroy (quitf);
941 tmp_list = tmp_list->next;
946 gtk_quit_remove_by_data (gpointer data)
948 GtkQuitFunction *quitf;
951 tmp_list = quit_functions;
954 quitf = tmp_list->data;
956 if (quitf->data == data)
958 quit_functions = g_list_remove_link (quit_functions, tmp_list);
959 g_list_free (tmp_list);
960 gtk_quit_destroy (quitf);
965 tmp_list = tmp_list->next;
970 gtk_timeout_add_full (guint32 interval,
971 GtkFunction function,
972 GtkCallbackMarshal marshal,
974 GtkDestroyNotify destroy)
980 closure = g_new (GtkClosure, 1);
981 closure->marshal = marshal;
982 closure->data = data;
983 closure->destroy = destroy;
985 return g_timeout_add_full (0, interval,
986 gtk_invoke_idle_timeout,
988 gtk_destroy_closure);
991 return g_timeout_add_full (0, interval, function, data, destroy);
995 gtk_timeout_add (guint32 interval,
996 GtkFunction function,
999 return g_timeout_add_full (0, interval, function, data, NULL);
1003 gtk_timeout_add_interp (guint32 interval,
1004 GtkCallbackMarshal function,
1006 GtkDestroyNotify destroy)
1008 return gtk_timeout_add_full (interval, NULL, function, data, destroy);
1012 gtk_timeout_remove (guint tag)
1014 g_source_remove (tag);
1018 gtk_idle_add_full (gint priority,
1019 GtkFunction function,
1020 GtkCallbackMarshal marshal,
1022 GtkDestroyNotify destroy)
1026 GtkClosure *closure;
1028 closure = g_new (GtkClosure, 1);
1029 closure->marshal = marshal;
1030 closure->data = data;
1031 closure->destroy = destroy;
1033 return g_idle_add_full (priority,
1034 gtk_invoke_idle_timeout,
1036 gtk_destroy_closure);
1039 return g_idle_add_full (priority, function, data, destroy);
1043 gtk_idle_add (GtkFunction function,
1046 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1050 gtk_idle_add_priority (gint priority,
1051 GtkFunction function,
1054 return g_idle_add_full (priority, function, data, NULL);
1058 gtk_idle_add_interp (GtkCallbackMarshal marshal,
1060 GtkDestroyNotify destroy)
1062 return gtk_idle_add_full (GTK_PRIORITY_DEFAULT, NULL, marshal, data, destroy);
1066 gtk_idle_remove (guint tag)
1068 g_source_remove (tag);
1072 gtk_idle_remove_by_data (gpointer data)
1074 g_source_remove_by_user_data (data);
1078 gtk_input_add_full (gint source,
1079 GdkInputCondition condition,
1080 GdkInputFunction function,
1081 GtkCallbackMarshal marshal,
1083 GtkDestroyNotify destroy)
1087 GtkClosure *closure;
1089 closure = g_new (GtkClosure, 1);
1090 closure->marshal = marshal;
1091 closure->data = data;
1092 closure->destroy = destroy;
1094 return gdk_input_add_full (source,
1096 (GdkInputFunction) gtk_invoke_input,
1098 (GdkDestroyNotify) gtk_destroy_closure);
1101 return gdk_input_add_full (source, condition, function, data, destroy);
1105 gtk_input_remove (guint tag)
1107 g_source_remove (tag);
1111 gtk_destroy_closure (gpointer data)
1113 GtkClosure *closure = data;
1114 if (closure->destroy)
1115 (closure->destroy) (closure->data);
1120 gtk_invoke_idle_timeout (gpointer data)
1122 GtkClosure *closure = data;
1125 gint ret_val = FALSE;
1126 args[0].name = NULL;
1127 args[0].type = GTK_TYPE_BOOL;
1128 args[0].d.pointer_data = &ret_val;
1129 closure->marshal (NULL, closure->data, 0, args);
1134 gtk_invoke_input (gpointer data,
1136 GdkInputCondition condition)
1138 GtkClosure *closure = data;
1141 args[0].type = GTK_TYPE_INT;
1142 args[0].name = NULL;
1143 GTK_VALUE_INT(args[0]) = source;
1144 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1145 args[1].name = NULL;
1146 GTK_VALUE_FLAGS(args[1]) = condition;
1147 args[2].type = GTK_TYPE_NONE;
1148 args[2].name = NULL;
1150 closure->marshal (NULL, closure->data, 2, args);
1154 gtk_get_current_event (void)
1157 return gdk_event_copy ((GdkEvent *) current_events->data);
1163 gtk_get_event_widget (GdkEvent *event)
1168 if (event && event->any.window)
1169 gdk_window_get_user_data (event->any.window, (void**) &widget);
1175 gtk_exit_func (void)
1177 if (gtk_initialized)
1179 gtk_initialized = FALSE;
1180 gtk_preview_uninit ();
1186 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1188 if (!quitf->marshal)
1189 return quitf->function (quitf->data);
1193 gint ret_val = FALSE;
1195 args[0].name = NULL;
1196 args[0].type = GTK_TYPE_BOOL;
1197 args[0].d.pointer_data = &ret_val;
1198 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1206 gtk_propagate_event (GtkWidget *widget,
1211 g_return_if_fail (widget != NULL);
1212 g_return_if_fail (event != NULL);
1214 handled_event = FALSE;
1216 if ((event->type == GDK_KEY_PRESS) ||
1217 (event->type == GDK_KEY_RELEASE))
1219 /* Only send key events within Window widgets to the Window
1220 * The Window widget will in turn pass the
1221 * key event on to the currently focused widget
1226 window = gtk_widget_get_ancestor (widget, gtk_window_get_type ());
1229 if (GTK_WIDGET_IS_SENSITIVE (window))
1230 gtk_widget_event (window, event);
1232 handled_event = TRUE; /* don't send to widget */
1236 /* Other events get propagated up the widget tree
1237 * so that parents can see the button and motion
1238 * events of the children.
1240 while (!handled_event && widget)
1244 gtk_widget_ref (widget);
1245 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1246 tmp = widget->parent;
1247 gtk_widget_unref (widget);
1253 gtk_threads_enter ()
1259 gtk_threads_leave ()
1266 gtk_error (gchar *str)
1272 gtk_warning (gchar *str)
1278 gtk_message (gchar *str)
1284 gtk_print (gchar *str)
1286 static GtkWidget *window = NULL;
1287 static GtkWidget *text;
1288 static int level = 0;
1292 GtkWidget *hscrollbar;
1293 GtkWidget *vscrollbar;
1294 GtkWidget *separator;
1299 fputs (str, stdout);
1306 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1308 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1309 (GtkSignalFunc) gtk_widget_destroyed,
1312 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1314 box1 = gtk_vbox_new (FALSE, 0);
1315 gtk_container_add (GTK_CONTAINER (window), box1);
1316 gtk_widget_show (box1);
1319 box2 = gtk_vbox_new (FALSE, 10);
1320 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1321 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1322 gtk_widget_show (box2);
1325 table = gtk_table_new (2, 2, FALSE);
1326 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1327 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1328 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1329 gtk_widget_show (table);
1331 text = gtk_text_new (NULL, NULL);
1332 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1333 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1334 gtk_widget_show (text);
1335 gtk_widget_realize (text);
1337 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1338 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1339 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1340 gtk_widget_show (hscrollbar);
1342 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1343 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1344 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1345 gtk_widget_show (vscrollbar);
1347 separator = gtk_hseparator_new ();
1348 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1349 gtk_widget_show (separator);
1352 box2 = gtk_vbox_new (FALSE, 10);
1353 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1354 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1355 gtk_widget_show (box2);
1358 button = gtk_button_new_with_label ("close");
1359 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1360 (GtkSignalFunc) gtk_widget_hide,
1361 GTK_OBJECT (window));
1362 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1363 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1364 gtk_widget_grab_default (button);
1365 gtk_widget_show (button);
1369 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1372 if (!GTK_WIDGET_VISIBLE (window))
1373 gtk_widget_show (window);