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 Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #ifdef GDK_WINDOWING_X11
28 #include <X11/Xlocale.h> /* so we get the right setlocale */
36 #include "gtkbutton.h"
38 #include "gtkcompat.h"
39 #include "gtkhscrollbar.h"
40 #include "gtkhseparator.h"
42 #include "gtkpreview.h"
44 #include "gtkscrolledwindow.h"
45 #include "gtkselection.h"
46 #include "gtksignal.h"
50 #include "gtkvscrollbar.h"
51 #include "gtkwidget.h"
52 #include "gtkwindow.h"
53 #include "gtkprivate.h"
54 #include "gdk/gdki18n.h"
59 /* Private type definitions
61 typedef struct _GtkInitFunction GtkInitFunction;
62 typedef struct _GtkQuitFunction GtkQuitFunction;
63 typedef struct _GtkClosure GtkClosure;
64 typedef struct _GtkKeySnooperData GtkKeySnooperData;
66 struct _GtkInitFunction
72 struct _GtkQuitFunction
76 GtkCallbackMarshal marshal;
79 GtkDestroyNotify destroy;
84 GtkCallbackMarshal marshal;
86 GtkDestroyNotify destroy;
89 struct _GtkKeySnooperData
96 static void gtk_exit_func (void);
97 static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
98 static void gtk_quit_destroy (GtkQuitFunction *quitf);
99 static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
102 static void gtk_destroy_closure (gpointer data);
103 static gboolean gtk_invoke_idle_timeout (gpointer data);
104 static void gtk_invoke_input (gpointer data,
106 GdkInputCondition condition);
109 static void gtk_error (gchar *str);
110 static void gtk_warning (gchar *str);
111 static void gtk_message (gchar *str);
112 static void gtk_print (gchar *str);
115 const guint gtk_major_version = GTK_MAJOR_VERSION;
116 const guint gtk_minor_version = GTK_MINOR_VERSION;
117 const guint gtk_micro_version = GTK_MICRO_VERSION;
118 const guint gtk_binary_age = GTK_BINARY_AGE;
119 const guint gtk_interface_age = GTK_INTERFACE_AGE;
121 static guint gtk_main_loop_level = 0;
122 static gint gtk_initialized = FALSE;
123 static GList *current_events = NULL;
125 static GSList *main_loops = NULL; /* stack of currently executing main loops */
127 static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
128 * widget is the first one on the list.
130 static GList *init_functions = NULL; /* A list of init functions.
132 static GList *quit_functions = NULL; /* A list of quit functions.
134 static GMemChunk *quit_mem_chunk = NULL;
136 static GSList *key_snoopers = NULL;
138 static GdkVisual *gtk_visual; /* The visual to be used in creating new
141 static GdkColormap *gtk_colormap; /* The colormap to be used in creating new
145 guint gtk_debug_flags = 0; /* Global GTK debug flag */
147 #ifdef G_ENABLE_DEBUG
148 static const GDebugKey gtk_debug_keys[] = {
149 {"objects", GTK_DEBUG_OBJECTS},
150 {"misc", GTK_DEBUG_MISC},
151 {"signals", GTK_DEBUG_SIGNALS},
152 {"dnd", GTK_DEBUG_DND},
153 {"plugsocket", GTK_DEBUG_PLUGSOCKET},
154 {"text", GTK_DEBUG_TEXT}
157 static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
159 #endif /* G_ENABLE_DEBUG */
162 gtk_check_version (guint required_major,
163 guint required_minor,
164 guint required_micro)
166 if (required_major > GTK_MAJOR_VERSION)
167 return "Gtk+ version too old (major mismatch)";
168 if (required_major < GTK_MAJOR_VERSION)
169 return "Gtk+ version too new (major mismatch)";
170 if (required_minor > GTK_MINOR_VERSION)
171 return "Gtk+ version too old (minor mismatch)";
172 if (required_minor < GTK_MINOR_VERSION)
173 return "Gtk+ version too new (minor mismatch)";
174 if (required_micro < GTK_MICRO_VERSION - GTK_BINARY_AGE)
175 return "Gtk+ version too new (micro mismatch)";
176 if (required_micro > GTK_MICRO_VERSION)
177 return "Gtk+ version too old (micro mismatch)";
182 static gchar *add_dll_suffix(gchar *module_name)
184 gchar *suffix = strrchr(module_name, '.');
186 if (!suffix || stricmp(suffix, ".dll"))
188 gchar *old = module_name;
190 module_name = g_strconcat (module_name, ".dll", NULL);
193 return (module_name);
197 #undef gtk_init_check
200 gtk_init_check (int *argc,
203 GSList *gtk_modules = NULL;
205 gchar *env_string = NULL;
211 g_set_error_handler (gtk_error);
212 g_set_warning_handler (gtk_warning);
213 g_set_message_handler (gtk_message);
214 g_set_print_handler (gtk_print);
217 /* Initialize "gdk". We pass along the 'argc' and 'argv'
218 * parameters as they contain information that GDK uses
220 if (!gdk_init_check (argc, argv))
223 gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
225 #ifdef G_ENABLE_DEBUG
226 env_string = getenv ("GTK_DEBUG");
227 if (env_string != NULL)
229 gtk_debug_flags = g_parse_debug_string (env_string,
234 #endif /* G_ENABLE_DEBUG */
236 env_string = getenv ("GTK_MODULES");
239 gchar **modules, **as;
242 modules = g_strsplit (env_string, G_SEARCHPATH_SEPARATOR_S, -1);
244 modules = g_strsplit (env_string, ";", -1);
246 for (as = modules; *as; as++)
249 gtk_modules = g_slist_prepend (gtk_modules, *as);
261 for (i = 1; i < *argc;)
263 if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
264 strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
266 gchar *module_name = (*argv)[i] + 12;
268 if (*module_name == '=')
270 else if (i + 1 < *argc)
274 module_name = (*argv)[i];
278 if (module_name && *module_name)
279 gtk_modules = g_slist_prepend (gtk_modules, g_strdup (module_name));
281 else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
283 GLogLevelFlags fatal_mask;
285 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
286 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
287 g_log_set_always_fatal (fatal_mask);
290 #ifdef G_ENABLE_DEBUG
291 else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
292 (strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
294 gchar *equal_pos = strchr ((*argv)[i], '=');
296 if (equal_pos != NULL)
298 gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
302 else if ((i + 1) < *argc && (*argv)[i + 1])
304 gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
312 else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
313 (strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 0))
315 gchar *equal_pos = strchr ((*argv)[i], '=');
317 if (equal_pos != NULL)
319 gtk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
323 else if ((i + 1) < *argc && (*argv)[i + 1])
325 gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
333 #endif /* G_ENABLE_DEBUG */
337 for (i = 1; i < *argc; i++)
339 for (k = i; k < *argc; k++)
340 if ((*argv)[k] != NULL)
346 for (j = i + k; j < *argc; j++)
347 (*argv)[j-k] = (*argv)[j];
353 /* load gtk modules */
354 gtk_modules = g_slist_reverse (gtk_modules);
355 for (slist = gtk_modules; slist; slist = slist->next)
358 GModule *module = NULL;
359 GtkModuleInitFunc modinit_func = NULL;
361 module_name = slist->data;
364 if (!g_path_is_absolute (module_name))
366 gchar *old = module_name;
368 module_name = g_module_build_path (NULL, module_name);
372 module_name = add_dll_suffix(module_name);
374 if (g_module_supported ())
376 module = g_module_open (module_name, G_MODULE_BIND_LAZY);
378 g_module_symbol (module, "gtk_module_init", (gpointer*) &modinit_func) &&
381 if (!g_slist_find (gtk_modules, modinit_func))
383 g_module_make_resident (module);
384 slist->data = modinit_func;
388 g_module_close (module);
395 g_warning ("Failed to load module \"%s\": %s",
396 module ? g_module_name (module) : module_name,
399 g_module_close (module);
401 g_free (module_name);
406 bindtextdomain(GETTEXT_PACKAGE, GTK_LOCALEDIR);
409 /* GTk+ locale dir is %WinDir%\gtk+\locale */
410 bindtextdomain (GETTEXT_PACKAGE,
411 g_strconcat (gtk_win32_get_installation_directory (),
419 /* Initialize the default visual and colormap to be
420 * used in creating widgets. (We want to use the system
421 * defaults so as to be nice to the colormap).
423 gtk_visual = gdk_visual_get_system ();
424 gtk_colormap = gdk_colormap_get_system ();
431 /* Register an exit function to make sure we are able to cleanup.
433 g_atexit (gtk_exit_func);
435 /* Set the 'initialized' flag.
437 gtk_initialized = TRUE;
439 /* initialize gtk modules
441 for (slist = gtk_modules; slist; slist = slist->next)
445 GtkModuleInitFunc modinit;
447 modinit = slist->data;
448 modinit (argc, argv);
451 g_slist_free (gtk_modules);
454 /* No use warning on Win32, there aren't any non-devel versions anyhow... */
455 g_message ("" "YOU ARE USING THE DEVEL BRANCH 1.3.x OF GTK+ WHICH IS CURRENTLY\n"
456 " UNDER HEAVY DEVELOPMENT AND FREQUENTLY INTRODUCES INSTABILITIES.\n"
457 " if you don't know why you are getting this, you probably want to\n"
458 " use the stable branch which can be retrived from\n"
459 " ftp://ftp.gtk.org/pub/gtk/v1.2/ or via CVS with\n"
460 " cvs checkout -r glib-1-2 glib; cvs checkout -r gtk-1-2 gtk+");
469 gtk_init (int *argc, char ***argv)
471 if (!gtk_init_check (argc, argv))
473 g_warning ("cannot open display: %s", gdk_get_display ());
481 check_sizeof_GtkWindow (size_t sizeof_GtkWindow)
483 if (sizeof_GtkWindow != sizeof (GtkWindow))
484 g_error ("Incompatible build!\n"
485 "The code using GTK+ thinks GtkWindow is of different\n"
486 "size than it actually is in this build of GTK+.\n"
487 "On Windows, this probably means that you have compiled\n"
488 "your code with gcc without the -fnative-struct switch.");
491 /* These two functions might get more checks added later, thus pass
492 * in the number of extra args.
495 gtk_init_abi_check (int *argc, char ***argv, int num_checks, size_t sizeof_GtkWindow)
497 check_sizeof_GtkWindow (sizeof_GtkWindow);
498 gtk_init (argc, argv);
502 gtk_init_check_abi_check (int *argc, char ***argv, int num_checks, size_t sizeof_GtkWindow)
504 check_sizeof_GtkWindow (sizeof_GtkWindow);
505 return gtk_init_check (argc, argv);
511 gtk_exit (gint errorcode)
513 /* Only if "gtk" has been initialized should we de-initialize.
515 /* de-initialisation is done by the gtk_exit_funct(),
516 * no need to do this here (Alex J.)
522 gtk_set_locale (void)
524 return gdk_set_locale ();
528 gtk_get_default_language (void)
533 lang = g_strdup (setlocale (LC_CTYPE, NULL));
534 p = strchr (lang, '.');
537 p = strchr (lang, '@');
549 GtkInitFunction *init;
552 gtk_main_loop_level++;
554 loop = g_main_new (TRUE);
555 main_loops = g_slist_prepend (main_loops, loop);
557 tmp_list = functions = init_functions;
558 init_functions = NULL;
562 init = tmp_list->data;
563 tmp_list = tmp_list->next;
565 (* init->function) (init->data);
568 g_list_free (functions);
570 if (g_main_is_running (main_loops->data))
572 GDK_THREADS_LEAVE ();
574 GDK_THREADS_ENTER ();
580 GList *reinvoke_list = NULL;
581 GtkQuitFunction *quitf;
583 while (quit_functions)
585 quitf = quit_functions->data;
587 tmp_list = quit_functions;
588 quit_functions = g_list_remove_link (quit_functions, quit_functions);
589 g_list_free_1 (tmp_list);
591 if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
592 gtk_quit_invoke_function (quitf))
594 reinvoke_list = g_list_prepend (reinvoke_list, quitf);
598 gtk_quit_destroy (quitf);
605 work = g_list_last (reinvoke_list);
607 quit_functions->prev = work;
608 work->next = quit_functions;
609 quit_functions = work;
615 main_loops = g_slist_remove (main_loops, loop);
617 g_main_destroy (loop);
619 gtk_main_loop_level--;
623 gtk_main_level (void)
625 return gtk_main_loop_level;
631 g_return_if_fail (main_loops != NULL);
633 g_main_quit (main_loops->data);
637 gtk_events_pending (void)
641 GDK_THREADS_LEAVE ();
642 result = g_main_pending();
643 GDK_THREADS_ENTER ();
649 gtk_main_iteration (void)
651 GDK_THREADS_LEAVE ();
652 g_main_iteration (TRUE);
653 GDK_THREADS_ENTER ();
656 return !g_main_is_running (main_loops->data);
662 gtk_main_iteration_do (gboolean blocking)
664 GDK_THREADS_LEAVE ();
665 g_main_iteration (blocking);
666 GDK_THREADS_ENTER ();
669 return !g_main_is_running (main_loops->data);
675 gtk_main_do_event (GdkEvent *event)
677 GtkWidget *event_widget;
678 GtkWidget *grab_widget;
679 GdkEvent *next_event;
682 /* If there are any events pending then get the next one.
684 next_event = gdk_event_peek ();
686 /* Try to compress enter/leave notify events. These event
687 * pairs occur when the mouse is dragged quickly across
688 * a window with many buttons (or through a menu). Instead
689 * of highlighting and de-highlighting each widget that
690 * is crossed it is better to simply de-highlight the widget
691 * which contained the mouse initially and highlight the
692 * widget which ends up containing the mouse.
695 if (((event->type == GDK_ENTER_NOTIFY) ||
696 (event->type == GDK_LEAVE_NOTIFY)) &&
697 ((next_event->type == GDK_ENTER_NOTIFY) ||
698 (next_event->type == GDK_LEAVE_NOTIFY)) &&
699 (next_event->type != event->type) &&
700 (next_event->any.window == event->any.window))
702 /* Throw both the peeked copy and the queued copy away
704 gdk_event_free (next_event);
705 next_event = gdk_event_get ();
706 gdk_event_free (next_event);
712 gdk_event_free (next_event);
714 /* Find the widget which got the event. We store the widget
715 * in the user_data field of GdkWindow's.
716 * Ignore the event if we don't have a widget for it, except
717 * for GDK_PROPERTY_NOTIFY events which are handled specialy.
718 * Though this happens rarely, bogus events can occour
719 * for e.g. destroyed GdkWindows.
721 event_widget = gtk_get_event_widget (event);
724 /* To handle selection INCR transactions, we select
725 * PropertyNotify events on the requestor window and create
726 * a corresponding (fake) GdkWindow so that events get
727 * here. There won't be a widget though, so we have to handle
730 if (event->type == GDK_PROPERTY_NOTIFY)
731 gtk_selection_incr_event (event->any.window,
737 /* Push the event onto a stack of current events for
738 * gtk_current_event_get().
740 current_events = g_list_prepend (current_events, event);
742 /* If there is a grab in effect...
746 grab_widget = grabs->data;
748 /* If the grab widget is an ancestor of the event widget
749 * then we send the event to the original event widget.
750 * This is the key to implementing modality.
752 if (GTK_WIDGET_IS_SENSITIVE (event_widget) &&
753 gtk_widget_is_ancestor (event_widget, grab_widget))
754 grab_widget = event_widget;
758 grab_widget = event_widget;
761 /* Not all events get sent to the grabbing widget.
762 * The delete, destroy, expose, focus change and resize
763 * events still get sent to the event widget because
764 * 1) these events have no meaning for the grabbing widget
765 * and 2) redirecting these events to the grabbing widget
766 * could cause the display to be messed up.
768 * Drag events are also not redirected, since it isn't
769 * clear what the semantics of that would be.
777 gtk_widget_ref (event_widget);
778 if ((!grabs || gtk_widget_get_toplevel (grabs->data) == event_widget) &&
779 !gtk_widget_event (event_widget, event))
780 gtk_widget_destroy (event_widget);
781 gtk_widget_unref (event_widget);
785 /* Unexpected GDK_DESTROY from the outside, ignore for
786 * child windows, handle like a GDK_DELETE for toplevels
788 if (!event_widget->parent)
790 gtk_widget_ref (event_widget);
791 if (!gtk_widget_event (event_widget, event) &&
792 !GTK_OBJECT_DESTROYED (event_widget))
793 gtk_widget_destroy (event_widget);
794 gtk_widget_unref (event_widget);
799 if (event->any.window && GTK_WIDGET_DOUBLE_BUFFERED (event_widget))
800 gdk_window_begin_paint_rect (event->any.window, &event->expose.area);
802 gtk_widget_event (event_widget, event);
804 if (event->any.window && GTK_WIDGET_DOUBLE_BUFFERED (event_widget))
805 gdk_window_end_paint (event->any.window);
808 case GDK_PROPERTY_NOTIFY:
810 case GDK_FOCUS_CHANGE:
814 case GDK_SELECTION_CLEAR:
815 case GDK_SELECTION_REQUEST:
816 case GDK_SELECTION_NOTIFY:
817 case GDK_CLIENT_EVENT:
818 case GDK_VISIBILITY_NOTIFY:
819 gtk_widget_event (event_widget, event);
823 case GDK_BUTTON_PRESS:
824 case GDK_2BUTTON_PRESS:
825 case GDK_3BUTTON_PRESS:
826 gtk_propagate_event (grab_widget, event);
830 case GDK_KEY_RELEASE:
833 if (gtk_invoke_key_snoopers (grab_widget, event))
836 /* else fall through */
837 case GDK_MOTION_NOTIFY:
838 case GDK_BUTTON_RELEASE:
839 case GDK_PROXIMITY_IN:
840 case GDK_PROXIMITY_OUT:
841 gtk_propagate_event (grab_widget, event);
844 case GDK_ENTER_NOTIFY:
845 if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
847 gtk_widget_event (grab_widget, event);
848 if (event_widget == grab_widget)
849 GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
853 case GDK_LEAVE_NOTIFY:
854 if (GTK_WIDGET_LEAVE_PENDING (event_widget))
856 GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
857 gtk_widget_event (event_widget, event);
859 else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
860 gtk_widget_event (grab_widget, event);
863 case GDK_DRAG_STATUS:
864 case GDK_DROP_FINISHED:
865 gtk_drag_source_handle_event (event_widget, event);
869 case GDK_DRAG_MOTION:
871 gtk_drag_dest_handle_event (event_widget, event);
875 tmp_list = current_events;
876 current_events = g_list_remove_link (current_events, tmp_list);
877 g_list_free_1 (tmp_list);
893 gtk_grab_add (GtkWidget *widget)
895 g_return_if_fail (widget != NULL);
897 if (!GTK_WIDGET_HAS_GRAB (widget))
899 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
901 grabs = g_slist_prepend (grabs, widget);
902 gtk_widget_ref (widget);
907 gtk_grab_get_current (void)
910 return GTK_WIDGET (grabs->data);
915 gtk_grab_remove (GtkWidget *widget)
917 g_return_if_fail (widget != NULL);
919 if (GTK_WIDGET_HAS_GRAB (widget))
921 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
923 grabs = g_slist_remove (grabs, widget);
924 gtk_widget_unref (widget);
929 gtk_init_add (GtkFunction function,
932 GtkInitFunction *init;
934 init = g_new (GtkInitFunction, 1);
935 init->function = function;
938 init_functions = g_list_prepend (init_functions, init);
942 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
945 GtkKeySnooperData *data;
946 static guint snooper_id = 1;
948 g_return_val_if_fail (snooper != NULL, 0);
950 data = g_new (GtkKeySnooperData, 1);
951 data->func = snooper;
952 data->func_data = func_data;
953 data->id = snooper_id++;
954 key_snoopers = g_slist_prepend (key_snoopers, data);
960 gtk_key_snooper_remove (guint snooper_id)
962 GtkKeySnooperData *data = NULL;
965 slist = key_snoopers;
969 if (data->id == snooper_id)
976 key_snoopers = g_slist_remove (key_snoopers, data);
980 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
984 gint return_val = FALSE;
986 slist = key_snoopers;
987 while (slist && !return_val)
989 GtkKeySnooperData *data;
993 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
1000 gtk_quit_add_full (guint main_level,
1001 GtkFunction function,
1002 GtkCallbackMarshal marshal,
1004 GtkDestroyNotify destroy)
1006 static guint quit_id = 1;
1007 GtkQuitFunction *quitf;
1009 g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
1011 if (!quit_mem_chunk)
1012 quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
1013 512, G_ALLOC_AND_FREE);
1015 quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
1017 quitf->id = quit_id++;
1018 quitf->main_level = main_level;
1019 quitf->function = function;
1020 quitf->marshal = marshal;
1022 quitf->destroy = destroy;
1024 quit_functions = g_list_prepend (quit_functions, quitf);
1030 gtk_quit_destroy (GtkQuitFunction *quitf)
1033 quitf->destroy (quitf->data);
1034 g_mem_chunk_free (quit_mem_chunk, quitf);
1038 gtk_quit_destructor (GtkObject **object_p)
1041 gtk_object_destroy (*object_p);
1048 gtk_quit_add_destroy (guint main_level,
1051 GtkObject **object_p;
1053 g_return_if_fail (main_level > 0);
1054 g_return_if_fail (object != NULL);
1055 g_return_if_fail (GTK_IS_OBJECT (object));
1057 object_p = g_new (GtkObject*, 1);
1059 gtk_signal_connect (object,
1061 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1063 gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
1067 gtk_quit_add (guint main_level,
1068 GtkFunction function,
1071 return gtk_quit_add_full (main_level, function, NULL, data, NULL);
1075 gtk_quit_remove (guint id)
1077 GtkQuitFunction *quitf;
1080 tmp_list = quit_functions;
1083 quitf = tmp_list->data;
1085 if (quitf->id == id)
1087 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1088 g_list_free (tmp_list);
1089 gtk_quit_destroy (quitf);
1094 tmp_list = tmp_list->next;
1099 gtk_quit_remove_by_data (gpointer data)
1101 GtkQuitFunction *quitf;
1104 tmp_list = quit_functions;
1107 quitf = tmp_list->data;
1109 if (quitf->data == data)
1111 quit_functions = g_list_remove_link (quit_functions, tmp_list);
1112 g_list_free (tmp_list);
1113 gtk_quit_destroy (quitf);
1118 tmp_list = tmp_list->next;
1123 gtk_timeout_add_full (guint32 interval,
1124 GtkFunction function,
1125 GtkCallbackMarshal marshal,
1127 GtkDestroyNotify destroy)
1131 GtkClosure *closure;
1133 closure = g_new (GtkClosure, 1);
1134 closure->marshal = marshal;
1135 closure->data = data;
1136 closure->destroy = destroy;
1138 return g_timeout_add_full (0, interval,
1139 gtk_invoke_idle_timeout,
1141 gtk_destroy_closure);
1144 return g_timeout_add_full (0, interval, function, data, destroy);
1148 gtk_timeout_add (guint32 interval,
1149 GtkFunction function,
1152 return g_timeout_add_full (0, interval, function, data, NULL);
1156 gtk_timeout_remove (guint tag)
1158 g_source_remove (tag);
1162 gtk_idle_add_full (gint priority,
1163 GtkFunction function,
1164 GtkCallbackMarshal marshal,
1166 GtkDestroyNotify destroy)
1170 GtkClosure *closure;
1172 closure = g_new (GtkClosure, 1);
1173 closure->marshal = marshal;
1174 closure->data = data;
1175 closure->destroy = destroy;
1177 return g_idle_add_full (priority,
1178 gtk_invoke_idle_timeout,
1180 gtk_destroy_closure);
1183 return g_idle_add_full (priority, function, data, destroy);
1187 gtk_idle_add (GtkFunction function,
1190 return g_idle_add_full (GTK_PRIORITY_DEFAULT, function, data, NULL);
1194 gtk_idle_add_priority (gint priority,
1195 GtkFunction function,
1198 return g_idle_add_full (priority, function, data, NULL);
1202 gtk_idle_remove (guint tag)
1204 g_source_remove (tag);
1208 gtk_idle_remove_by_data (gpointer data)
1210 if (!g_idle_remove_by_data (data))
1211 g_warning ("gtk_idle_remove_by_data(%p): no such idle", data);
1215 gtk_input_add_full (gint source,
1216 GdkInputCondition condition,
1217 GdkInputFunction function,
1218 GtkCallbackMarshal marshal,
1220 GtkDestroyNotify destroy)
1224 GtkClosure *closure;
1226 closure = g_new (GtkClosure, 1);
1227 closure->marshal = marshal;
1228 closure->data = data;
1229 closure->destroy = destroy;
1231 return gdk_input_add_full (source,
1233 (GdkInputFunction) gtk_invoke_input,
1235 (GdkDestroyNotify) gtk_destroy_closure);
1238 return gdk_input_add_full (source, condition, function, data, destroy);
1242 gtk_input_remove (guint tag)
1244 g_source_remove (tag);
1248 gtk_destroy_closure (gpointer data)
1250 GtkClosure *closure = data;
1252 if (closure->destroy)
1253 (closure->destroy) (closure->data);
1258 gtk_invoke_idle_timeout (gpointer data)
1260 GtkClosure *closure = data;
1263 gint ret_val = FALSE;
1264 args[0].name = NULL;
1265 args[0].type = GTK_TYPE_BOOL;
1266 args[0].d.pointer_data = &ret_val;
1267 closure->marshal (NULL, closure->data, 0, args);
1272 gtk_invoke_input (gpointer data,
1274 GdkInputCondition condition)
1276 GtkClosure *closure = data;
1279 args[0].type = GTK_TYPE_INT;
1280 args[0].name = NULL;
1281 GTK_VALUE_INT(args[0]) = source;
1282 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
1283 args[1].name = NULL;
1284 GTK_VALUE_FLAGS(args[1]) = condition;
1285 args[2].type = GTK_TYPE_NONE;
1286 args[2].name = NULL;
1288 closure->marshal (NULL, closure->data, 2, args);
1292 gtk_get_current_event (void)
1295 return gdk_event_copy ((GdkEvent *) current_events->data);
1301 gtk_get_event_widget (GdkEvent *event)
1306 if (event && event->any.window)
1307 gdk_window_get_user_data (event->any.window, (void**) &widget);
1313 gtk_exit_func (void)
1315 if (gtk_initialized)
1317 gtk_initialized = FALSE;
1318 gtk_preview_uninit ();
1324 gtk_quit_invoke_function (GtkQuitFunction *quitf)
1326 if (!quitf->marshal)
1327 return quitf->function (quitf->data);
1331 gint ret_val = FALSE;
1333 args[0].name = NULL;
1334 args[0].type = GTK_TYPE_BOOL;
1335 args[0].d.pointer_data = &ret_val;
1336 ((GtkCallbackMarshal) quitf->marshal) (NULL,
1344 gtk_propagate_event (GtkWidget *widget,
1349 g_return_if_fail (widget != NULL);
1350 g_return_if_fail (GTK_IS_WIDGET (widget));
1351 g_return_if_fail (event != NULL);
1353 handled_event = FALSE;
1355 if ((event->type == GDK_KEY_PRESS) ||
1356 (event->type == GDK_KEY_RELEASE))
1358 /* Only send key events within Window widgets to the Window
1359 * The Window widget will in turn pass the
1360 * key event on to the currently focused widget
1365 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1368 if (GTK_WIDGET_IS_SENSITIVE (window))
1369 gtk_widget_event (window, event);
1371 handled_event = TRUE; /* don't send to widget */
1375 /* Other events get propagated up the widget tree
1376 * so that parents can see the button and motion
1377 * events of the children.
1379 while (!handled_event && widget)
1383 gtk_widget_ref (widget);
1384 handled_event = !GTK_WIDGET_IS_SENSITIVE (widget) || gtk_widget_event (widget, event);
1385 tmp = widget->parent;
1386 gtk_widget_unref (widget);
1393 gtk_error (gchar *str)
1399 gtk_warning (gchar *str)
1405 gtk_message (gchar *str)
1411 gtk_print (gchar *str)
1413 static GtkWidget *window = NULL;
1414 static GtkWidget *text;
1415 static int level = 0;
1419 GtkWidget *hscrollbar;
1420 GtkWidget *vscrollbar;
1421 GtkWidget *separator;
1426 fputs (str, stdout);
1433 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1435 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1436 (GtkSignalFunc) gtk_widget_destroyed,
1439 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1441 box1 = gtk_vbox_new (FALSE, 0);
1442 gtk_container_add (GTK_CONTAINER (window), box1);
1443 gtk_widget_show (box1);
1446 box2 = gtk_vbox_new (FALSE, 10);
1447 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1448 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1449 gtk_widget_show (box2);
1452 table = gtk_table_new (2, 2, FALSE);
1453 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1454 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1455 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1456 gtk_widget_show (table);
1458 text = gtk_text_new (NULL, NULL);
1459 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1460 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1461 gtk_widget_show (text);
1462 gtk_widget_realize (text);
1464 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1465 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1466 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1467 gtk_widget_show (hscrollbar);
1469 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1470 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1471 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1472 gtk_widget_show (vscrollbar);
1474 separator = gtk_hseparator_new ();
1475 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1476 gtk_widget_show (separator);
1479 box2 = gtk_vbox_new (FALSE, 10);
1480 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
1481 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1482 gtk_widget_show (box2);
1485 button = gtk_button_new_with_label ("close");
1486 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1487 (GtkSignalFunc) gtk_widget_hide,
1488 GTK_OBJECT (window));
1489 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1490 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1491 gtk_widget_grab_default (button);
1492 gtk_widget_show (button);
1496 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1499 if (!GTK_WIDGET_VISIBLE (window))
1500 gtk_widget_show (window);