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 "gtkscrolledwindow.h"
33 #include "gtkselection.h"
34 #include "gtksignal.h"
38 #include "gtkvscrollbar.h"
39 #include "gtkwidget.h"
40 #include "gtkwindow.h"
41 #include "gtkprivate.h"
42 #include "gdk/gdki18n.h"
47 /* Private type definitions
49 typedef struct _GtkInitFunction GtkInitFunction;
50 typedef struct _GtkQuitFunction GtkQuitFunction;
51 typedef struct _GtkClosure GtkClosure;
52 typedef struct _GtkKeySnooperData GtkKeySnooperData;
54 struct _GtkInitFunction
60 struct _GtkQuitFunction
64 GtkCallbackMarshal marshal;
67 GtkDestroyNotify destroy;
72 GtkCallbackMarshal marshal;
74 GtkDestroyNotify destroy;
77 struct _GtkKeySnooperData
84 static void gtk_exit_func (void);
85 static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
86 static void gtk_quit_destroy (GtkQuitFunction *quitf);
87 static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
90 static void gtk_destroy_closure (gpointer data);
91 static gboolean gtk_invoke_idle_timeout (gpointer data);
92 static void gtk_invoke_input (gpointer data,
94 GdkInputCondition condition);
97 static void gtk_error (gchar *str);
98 static void gtk_warning (gchar *str);
99 static void gtk_message (gchar *str);
100 static void gtk_print (gchar *str);
103 const guint gtk_major_version = GTK_MAJOR_VERSION;
104 const guint gtk_minor_version = GTK_MINOR_VERSION;
105 const guint gtk_micro_version = GTK_MICRO_VERSION;
106 const guint gtk_binary_age = GTK_BINARY_AGE;
107 const guint gtk_interface_age = GTK_INTERFACE_AGE;
109 static guint gtk_main_loop_level = 0;
110 static gint gtk_initialized = FALSE;
111 static GList *current_events = NULL;
113 static GSList *main_loops = NULL; /* stack of currently executing main loops */
115 static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
116 * widget is the first one on the list.
118 static GList *init_functions = NULL; /* A list of init functions.
120 static GList *quit_functions = NULL; /* A list of quit functions.
122 static GMemChunk *quit_mem_chunk = NULL;
124 static GSList *key_snoopers = NULL;
126 static GdkVisual *gtk_visual; /* The visual to be used in creating new
129 static GdkColormap *gtk_colormap; /* The colormap to be used in creating new
133 guint gtk_debug_flags = 0; /* Global GTK debug flag */
135 #ifdef G_ENABLE_DEBUG
136 static const GDebugKey gtk_debug_keys[] = {
137 {"objects", GTK_DEBUG_OBJECTS},
138 {"misc", GTK_DEBUG_MISC},
139 {"signals", GTK_DEBUG_SIGNALS},
140 {"dnd", GTK_DEBUG_DND}
143 static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
145 #endif /* G_ENABLE_DEBUG */
148 gtk_check_version (guint required_major,
149 guint required_minor,
150 guint required_micro)
152 if (required_major > GTK_MAJOR_VERSION)
153 return "Gtk+ version too old (major mismatch)";
154 if (required_major < GTK_MAJOR_VERSION)
155 return "Gtk+ version too new (major mismatch)";
156 if (required_minor > GTK_MINOR_VERSION)
157 return "Gtk+ version too old (minor mismatch)";
158 if (required_minor < GTK_MINOR_VERSION)
159 return "Gtk+ version too new (minor mismatch)";
160 if (required_micro < GTK_MICRO_VERSION - GTK_BINARY_AGE)
161 return "Gtk+ version too new (micro mismatch)";
162 if (required_micro > GTK_MICRO_VERSION)
163 return "Gtk+ version too old (micro mismatch)";
172 GSList *gtk_modules = NULL;
174 gchar *env_string = NULL;
179 /* There is some argument for putting this in a separate
180 * function ... but I don't think that it is much
181 * of a restriction to require that GTK+ be used
182 * single threaded until gtk_init().
186 g_set_error_handler (gtk_error);
187 g_set_warning_handler (gtk_warning);
188 g_set_message_handler (gtk_message);
189 g_set_print_handler (gtk_print);
192 /* Initialize "gdk". We pass along the 'argc' and 'argv'
193 * parameters as they contain information that GDK uses
195 gdk_init (argc, argv);
197 gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
199 #ifdef G_ENABLE_DEBUG
200 env_string = getenv ("GTK_DEBUG");
201 if (env_string != NULL)
203 gtk_debug_flags = g_parse_debug_string (env_string,
208 #endif /* G_ENABLE_DEBUG */
210 env_string = getenv ("GTK_MODULES");
213 gchar **modules, **as;
215 modules = g_strsplit (env_string, ":", -1);
216 for (as = modules; *as; as++)
219 gtk_modules = g_slist_prepend (gtk_modules, *as);
231 for (i = 1; i < *argc;)
233 if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
234 strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
236 gchar *module_name = (*argv)[i] + 12;
238 if (*module_name == '=')
244 module_name = (*argv)[i];
248 gtk_modules = g_slist_prepend (gtk_modules, g_strdup (module_name));
250 else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
252 GLogLevelFlags fatal_mask;
254 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
255 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
256 g_log_set_always_fatal (fatal_mask);
259 #ifdef G_ENABLE_DEBUG
260 else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
261 (strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
263 gchar *equal_pos = strchr ((*argv)[i], '=');
265 if (equal_pos != NULL)
267 gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
271 else if ((i + 1) < *argc && (*argv)[i + 1])
273 gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
281 else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
282 (strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 0))
284 gchar *equal_pos = strchr ((*argv)[i], '=');
286 if (equal_pos != NULL)
288 gtk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
292 else if ((i + 1) < *argc && (*argv)[i + 1])
294 gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
302 #endif /* G_ENABLE_DEBUG */
306 for (i = 1; i < *argc; i++)
308 for (k = i; k < *argc; k++)
309 if ((*argv)[k] != NULL)
315 for (j = i + k; j < *argc; j++)
316 (*argv)[j-k] = (*argv)[j];
322 /* load gtk modules */
323 gtk_modules = g_slist_reverse (gtk_modules);
324 for (slist = gtk_modules; slist; slist = slist->next)
327 GModule *module = NULL;
328 GtkModuleInitFunc modinit_func = NULL;
330 module_name = slist->data;
332 if (!(module_name[0] == '/' ||
333 (module_name[0] == 'l' &&
334 module_name[1] == 'i' &&
335 module_name[2] == 'b')))
337 gchar *old = module_name;
339 module_name = g_strconcat ("lib", module_name, ".so", NULL);
342 if (g_module_supported ())
344 module = g_module_open (module_name, G_MODULE_BIND_LAZY);
346 g_module_symbol (module, "gtk_module_init", (gpointer*) &modinit_func) &&
349 if (!g_slist_find (gtk_modules, modinit_func))
351 g_module_make_resident (module);
352 slist->data = modinit_func;
356 g_module_close (module);
363 g_warning ("Failed to load module \"%s\": %s",
364 module ? g_module_name (module) : module_name,
367 g_module_close (module);
369 g_free (module_name);
373 bindtextdomain("gtk+",GTK_LOCALEDIR);
376 /* Initialize the default visual and colormap to be
377 * used in creating widgets. (We want to use the system
378 * defaults so as to be nice to the colormap).
380 gtk_visual = gdk_visual_get_system ();
381 gtk_colormap = gdk_colormap_get_system ();
388 /* Register an exit function to make sure we are able to cleanup.
390 g_atexit (gtk_exit_func);
392 /* Set the 'initialized' flag.
394 gtk_initialized = TRUE;
396 /* initialize gtk modules
398 for (slist = gtk_modules; slist; slist = slist->next)
402 GtkModuleInitFunc modinit;
404 modinit = slist->data;
405 modinit (argc, argv);
408 g_slist_free (gtk_modules);
412 gtk_exit (int errorcode)
414 /* Only if "gtk" has been initialized should we de-initialize.
416 /* de-initialisation is done by the gtk_exit_funct(),
417 * no need to do this here (Alex J.)
423 gtk_set_locale (void)
425 return gdk_set_locale ();
433 GtkInitFunction *init;
436 gtk_main_loop_level++;
438 loop = g_main_new (TRUE);
439 main_loops = g_slist_prepend (main_loops, loop);
441 tmp_list = functions = init_functions;
442 init_functions = NULL;
446 init = tmp_list->data;
447 tmp_list = tmp_list->next;
449 (* init->function) (init->data);
452 g_list_free (functions);
454 if (g_main_is_running (main_loops->data))
456 GDK_THREADS_LEAVE ();
458 GDK_THREADS_ENTER ();
464 GList *reinvoke_list = NULL;
465 GtkQuitFunction *quitf;
467 while (quit_functions)
469 quitf = quit_functions->data;
471 quit_functions = g_list_remove_link (quit_functions, quit_functions);
473 if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
474 gtk_quit_invoke_function (quitf))
476 reinvoke_list = g_list_prepend (reinvoke_list, quitf);
480 g_list_free (tmp_list);
481 gtk_quit_destroy (quitf);
488 work = g_list_last (reinvoke_list);
490 quit_functions->prev = work;
491 work->next = quit_functions;
492 quit_functions = work;
498 main_loops = g_slist_remove (main_loops, loop);
500 g_main_destroy (loop);
502 gtk_main_loop_level--;
506 gtk_main_level (void)
508 return gtk_main_loop_level;
514 g_return_if_fail (main_loops != NULL);
516 g_main_quit (main_loops->data);
520 gtk_events_pending (void)
522 return g_main_pending();
526 gtk_main_iteration (void)
528 g_main_iteration (TRUE);
531 return !g_main_is_running (main_loops->data);
537 gtk_main_iteration_do (gboolean blocking)
539 g_main_iteration (blocking);
542 return !g_main_is_running (main_loops->data);
548 gtk_main_do_event (GdkEvent *event)
550 GtkWidget *event_widget;
551 GtkWidget *grab_widget;
552 GdkEvent *next_event;
555 /* If there are any events pending then get the next one.
557 next_event = gdk_event_peek ();
559 /* Try to compress enter/leave notify events. These event
560 * pairs occur when the mouse is dragged quickly across
561 * a window with many buttons (or through a menu). Instead
562 * of highlighting and de-highlighting each widget that
563 * is crossed it is better to simply de-highlight the widget
564 * which contained the mouse initially and highlight the
565 * widget which ends up containing the mouse.
568 if (((event->type == GDK_ENTER_NOTIFY) ||
569 (event->type == GDK_LEAVE_NOTIFY)) &&
570 ((next_event->type == GDK_ENTER_NOTIFY) ||
571 (next_event->type == GDK_LEAVE_NOTIFY)) &&
572 (next_event->type != event->type) &&
573 (next_event->any.window == event->any.window))
575 /* Throw both the peeked copy and the queued copy away
577 gdk_event_free (next_event);
578 next_event = gdk_event_get ();
579 gdk_event_free (next_event);
585 gdk_event_free (next_event);
587 /* Find the widget which got the event. We store the widget
588 * in the user_data field of GdkWindow's.
589 * Ignore the event if we don't have a widget for it, except
590 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
591 * Though this happens rarely, bogus events can occour
592 * for e.g. destroyed GdkWindows.
594 event_widget = gtk_get_event_widget (event);
597 /* To handle selection INCR transactions, we select
598 * PropertyNotify events on the requestor window and create
599 * a corresponding (fake) GdkWindow so that events get
600 * here. There won't be a widget though, so we have to handle
603 if (event->type == GDK_PROPERTY_NOTIFY)
604 gtk_selection_incr_event (event->any.window,
610 /* Push the event onto a stack of current events for
611 * gtk_current_event_get().
613 current_events = g_list_prepend (current_events, event);
615 /* If there is a grab in effect...
619 grab_widget = grabs->data;
621 /* If the grab widget is an ancestor of the event widget
622 * then we send the event to the original event widget.
623 * This is the key to implementing modality.
625 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
626 gtk_widget_is_ancestor (event_widget, grab_widget))
627 grab_widget = event_widget;
631 grab_widget = event_widget;
634 /* Not all events get sent to the grabbing widget.
635 * The delete, destroy, expose, focus change and resize
636 * events still get sent to the event widget because
637 * 1) these events have no meaning for the grabbing widget
638 * and 2) redirecting these events to the grabbing widget
639 * could cause the display to be messed up.
641 * Drag events are also not redirected, since it isn't
642 * clear what the semantics of that would be.
650 gtk_widget_ref (event_widget);
651 if (!gtk_widget_event (event_widget, event) &&
652 !GTK_OBJECT_DESTROYED (event_widget))
653 gtk_widget_destroy (event_widget);
654 gtk_widget_unref (event_widget);
658 gtk_widget_ref (event_widget);
659 gtk_widget_event (event_widget, event);
660 if (!GTK_OBJECT_DESTROYED (event_widget))
661 gtk_widget_destroy (event_widget);
662 gtk_widget_unref (event_widget);
665 case GDK_PROPERTY_NOTIFY:
668 case GDK_FOCUS_CHANGE:
672 case GDK_SELECTION_CLEAR:
673 case GDK_SELECTION_REQUEST:
674 case GDK_SELECTION_NOTIFY:
675 case GDK_CLIENT_EVENT:
676 case GDK_VISIBILITY_NOTIFY:
677 gtk_widget_event (event_widget, event);
680 case GDK_BUTTON_PRESS:
681 case GDK_2BUTTON_PRESS:
682 case GDK_3BUTTON_PRESS:
683 /* We treat button 4-5 specially, assume we have
684 * a MS-style scrollwheel mouse, and try to find
685 * a plausible widget to scroll. We also trap
686 * button 4-5 double and triple clicks here, since
687 * they will be generated if the user scrolls quickly.
689 if ((grab_widget == event_widget) &&
690 (event->button.button == 4 || event->button.button == 5))
692 GtkWidget *range = NULL;
693 GtkWidget *scrollwin;
695 if (GTK_IS_RANGE (event_widget))
696 range = event_widget;
699 scrollwin = gtk_widget_get_ancestor (event_widget,
700 GTK_TYPE_SCROLLED_WINDOW);
702 range = GTK_SCROLLED_WINDOW (scrollwin)->vscrollbar;
705 if (range && GTK_WIDGET_VISIBLE (range))
707 if (event->type == GDK_BUTTON_PRESS)
709 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
710 gfloat new_value = adj->value + ((event->button.button == 4) ?
711 -adj->page_increment / 2:
712 adj->page_increment / 2);
713 new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
714 gtk_adjustment_set_value (adj, new_value);
719 gtk_propagate_event (grab_widget, event);
723 case GDK_KEY_RELEASE:
726 if (gtk_invoke_key_snoopers (grab_widget, event))
729 /* else fall through */
730 case GDK_MOTION_NOTIFY:
731 case GDK_BUTTON_RELEASE:
732 case GDK_PROXIMITY_IN:
733 case GDK_PROXIMITY_OUT:
734 gtk_propagate_event (grab_widget, event);
737 case GDK_ENTER_NOTIFY:
738 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
740 gtk_widget_event (grab_widget, event);
741 if (event_widget == grab_widget)
742 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
746 case GDK_LEAVE_NOTIFY:
747 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
749 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
750 gtk_widget_event (event_widget, event);
752 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
753 gtk_widget_event (grab_widget, event);
756 case GDK_DRAG_STATUS:
757 case GDK_DROP_FINISHED:
758 gtk_drag_source_handle_event (event_widget, event);
762 case GDK_DRAG_MOTION:
764 gtk_drag_dest_handle_event (event_widget, event);
768 tmp_list = current_events;
769 current_events = g_list_remove_link (current_events, tmp_list);
770 g_list_free_1 (tmp_list);
786 gtk_grab_add (GtkWidget *widget)
788 g_return_if_fail (widget != NULL);
790 if (!GTK_WIDGET_HAS_GRAB (widget))
792 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
794 grabs = g_slist_prepend (grabs, widget);
795 gtk_widget_ref (widget);
800 gtk_grab_get_current (void)
803 return GTK_WIDGET (grabs->data);
808 gtk_grab_remove (GtkWidget *widget)
810 g_return_if_fail (widget != NULL);
812 if (GTK_WIDGET_HAS_GRAB (widget))
814 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
816 grabs = g_slist_remove (grabs, widget);
817 gtk_widget_unref (widget);
822 gtk_init_add (GtkFunction function,
825 GtkInitFunction *init;
827 init = g_new (GtkInitFunction, 1);
828 init->function = function;
831 init_functions = g_list_prepend (init_functions, init);
835 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
838 GtkKeySnooperData *data;
839 static guint snooper_id = 1;
841 g_return_val_if_fail (snooper != NULL, 0);
843 data = g_new (GtkKeySnooperData, 1);
844 data->func = snooper;
845 data->func_data = func_data;
846 data->id = snooper_id++;
847 key_snoopers = g_slist_prepend (key_snoopers, data);
853 gtk_key_snooper_remove (guint snooper_id)
855 GtkKeySnooperData *data = NULL;
858 slist = key_snoopers;
862 if (data->id == snooper_id)
869 key_snoopers = g_slist_remove (key_snoopers, data);
873 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
877 gint return_val = FALSE;
879 slist = key_snoopers;
880 while (slist && !return_val)
882 GtkKeySnooperData *data;
886 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
893 gtk_quit_add_full (guint main_level,
894 GtkFunction function,
895 GtkCallbackMarshal marshal,
897 GtkDestroyNotify destroy)
899 static guint quit_id = 1;
900 GtkQuitFunction *quitf;
902 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
905 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
906 512, G_ALLOC_AND_FREE);
908 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
910 quitf->id = quit_id++;
911 quitf->main_level = main_level;
912 quitf->function = function;
913 quitf->marshal = marshal;
915 quitf->destroy = destroy;
917 quit_functions = g_list_prepend (quit_functions, quitf);
923 gtk_quit_destroy (GtkQuitFunction *quitf)
926 quitf->destroy (quitf->data);
927 g_mem_chunk_free (quit_mem_chunk, quitf);
931 gtk_quit_destructor (GtkObject **object_p)
934 gtk_object_destroy (*object_p);
941 gtk_quit_add_destroy (guint main_level,
944 GtkObject **object_p;
946 g_return_if_fail (main_level > 0);
947 g_return_if_fail (object != NULL);
948 g_return_if_fail (GTK_IS_OBJECT (object));
950 object_p = g_new (GtkObject*, 1);
952 gtk_signal_connect (object,
954 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
956 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
960 gtk_quit_add (guint main_level,
961 GtkFunction function,
964 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
968 gtk_quit_remove (guint id)
970 GtkQuitFunction *quitf;
973 tmp_list = quit_functions;
976 quitf = tmp_list->data;
980 quit_functions = g_list_remove_link (quit_functions, tmp_list);
981 g_list_free (tmp_list);
982 gtk_quit_destroy (quitf);
987 tmp_list = tmp_list->next;
992 gtk_quit_remove_by_data (gpointer data)
994 GtkQuitFunction *quitf;
997 tmp_list = quit_functions;
1000 quitf = tmp_list->data;
1002 if (quitf->data == data)
1004 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1005 g_list_free (tmp_list);
1006 gtk_quit_destroy (quitf);
1011 tmp_list = tmp_list->next;
1016 gtk_timeout_add_full (guint32 interval,
1017 GtkFunction function,
1018 GtkCallbackMarshal marshal,
1020 GtkDestroyNotify destroy)
1024 GtkClosure *closure;
1026 closure = g_new (GtkClosure, 1);
1027 closure->marshal = marshal;
1028 closure->data = data;
1029 closure->destroy = destroy;
1031 return g_timeout_add_full (0, interval,
1032 gtk_invoke_idle_timeout,
1034 gtk_destroy_closure);
1037 return g_timeout_add_full (0, interval, function, data, destroy);
1041 gtk_timeout_add (guint32 interval,
1042 GtkFunction function,
1045 return g_timeout_add_full (0, interval, function, data, NULL);
1049 gtk_timeout_remove (guint tag)
1051 g_source_remove (tag);
1055 gtk_idle_add_full (gint priority,
1056 GtkFunction function,
1057 GtkCallbackMarshal marshal,
1059 GtkDestroyNotify destroy)
1063 GtkClosure *closure;
1065 closure = g_new (GtkClosure, 1);
1066 closure->marshal = marshal;
1067 closure->data = data;
1068 closure->destroy = destroy;
1070 return g_idle_add_full (priority,
1071 gtk_invoke_idle_timeout,
1073 gtk_destroy_closure);
1076 return g_idle_add_full (priority, function, data, destroy);
1080 gtk_idle_add (GtkFunction function,
1083 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1087 gtk_idle_add_priority (gint priority,
1088 GtkFunction function,
1091 return g_idle_add_full (priority, function, data, NULL);
1095 gtk_idle_remove (guint tag)
1097 g_source_remove (tag);
1101 gtk_idle_remove_by_data (gpointer data)
1103 if (!g_idle_remove_by_data (data))
1104 g_warning ("gtk_idle_remove_by_data(%p): no such idle", data);
1108 gtk_input_add_full (gint source,
1109 GdkInputCondition condition,
1110 GdkInputFunction function,
1111 GtkCallbackMarshal marshal,
1113 GtkDestroyNotify destroy)
1117 GtkClosure *closure;
1119 closure = g_new (GtkClosure, 1);
1120 closure->marshal = marshal;
1121 closure->data = data;
1122 closure->destroy = destroy;
1124 return gdk_input_add_full (source,
1126 (GdkInputFunction) gtk_invoke_input,
1128 (GdkDestroyNotify) gtk_destroy_closure);
1131 return gdk_input_add_full (source, condition, function, data, destroy);
1135 gtk_input_remove (guint tag)
1137 g_source_remove (tag);
1141 gtk_destroy_closure (gpointer data)
1143 GtkClosure *closure = data;
1145 if (closure->destroy)
1146 (closure->destroy) (closure->data);
1151 gtk_invoke_idle_timeout (gpointer data)
1153 GtkClosure *closure = data;
1156 gint ret_val = FALSE;
1157 args[0].name = NULL;
1158 args[0].type = GTK_TYPE_BOOL;
1159 args[0].d.pointer_data = &ret_val;
1160 closure->marshal (NULL, closure->data, 0, args);
1165 gtk_invoke_input (gpointer data,
1167 GdkInputCondition condition)
1169 GtkClosure *closure = data;
1172 args[0].type = GTK_TYPE_INT;
1173 args[0].name = NULL;
1174 GTK_VALUE_INT(args[0]) = source;
1175 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1176 args[1].name = NULL;
1177 GTK_VALUE_FLAGS(args[1]) = condition;
1178 args[2].type = GTK_TYPE_NONE;
1179 args[2].name = NULL;
1181 closure->marshal (NULL, closure->data, 2, args);
1185 gtk_get_current_event (void)
1188 return gdk_event_copy ((GdkEvent *) current_events->data);
1194 gtk_get_event_widget (GdkEvent *event)
1199 if (event && event->any.window)
1200 gdk_window_get_user_data (event->any.window, (void**) &widget);
1206 gtk_exit_func (void)
1208 if (gtk_initialized)
1210 gtk_initialized = FALSE;
1211 gtk_preview_uninit ();
1217 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1219 if (!quitf->marshal)
1220 return quitf->function (quitf->data);
1224 gint ret_val = FALSE;
1226 args[0].name = NULL;
1227 args[0].type = GTK_TYPE_BOOL;
1228 args[0].d.pointer_data = &ret_val;
1229 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1237 gtk_propagate_event (GtkWidget *widget,
1242 g_return_if_fail (widget != NULL);
1243 g_return_if_fail (GTK_IS_WIDGET (widget));
1244 g_return_if_fail (event != NULL);
1246 handled_event = FALSE;
1248 if ((event->type == GDK_KEY_PRESS) ||
1249 (event->type == GDK_KEY_RELEASE))
1251 /* Only send key events within Window widgets to the Window
1252 * The Window widget will in turn pass the
1253 * key event on to the currently focused widget
1258 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1261 if (GTK_WIDGET_IS_SENSITIVE (window))
1262 gtk_widget_event (window, event);
1264 handled_event = TRUE; /* don't send to widget */
1268 /* Other events get propagated up the widget tree
1269 * so that parents can see the button and motion
1270 * events of the children.
1272 while (!handled_event && widget)
1276 gtk_widget_ref (widget);
1277 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1278 tmp = widget->parent;
1279 gtk_widget_unref (widget);
1286 gtk_error (gchar *str)
1292 gtk_warning (gchar *str)
1298 gtk_message (gchar *str)
1304 gtk_print (gchar *str)
1306 static GtkWidget *window = NULL;
1307 static GtkWidget *text;
1308 static int level = 0;
1312 GtkWidget *hscrollbar;
1313 GtkWidget *vscrollbar;
1314 GtkWidget *separator;
1319 fputs (str, stdout);
1326 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1328 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1329 (GtkSignalFunc) gtk_widget_destroyed,
1332 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1334 box1 = gtk_vbox_new (FALSE, 0);
1335 gtk_container_add (GTK_CONTAINER (window), box1);
1336 gtk_widget_show (box1);
1339 box2 = gtk_vbox_new (FALSE, 10);
1340 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1341 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1342 gtk_widget_show (box2);
1345 table = gtk_table_new (2, 2, FALSE);
1346 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1347 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1348 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1349 gtk_widget_show (table);
1351 text = gtk_text_new (NULL, NULL);
1352 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1353 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1354 gtk_widget_show (text);
1355 gtk_widget_realize (text);
1357 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1358 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1359 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1360 gtk_widget_show (hscrollbar);
1362 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1363 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1364 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1365 gtk_widget_show (vscrollbar);
1367 separator = gtk_hseparator_new ();
1368 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1369 gtk_widget_show (separator);
1372 box2 = gtk_vbox_new (FALSE, 10);
1373 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1374 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1375 gtk_widget_show (box2);
1378 button = gtk_button_new_with_label ("close");
1379 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1380 (GtkSignalFunc) gtk_widget_hide,
1381 GTK_OBJECT (window));
1382 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1383 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1384 gtk_widget_grab_default (button);
1385 gtk_widget_show (button);
1389 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1392 if (!GTK_WIDGET_VISIBLE (window))
1393 gtk_widget_show (window);