<!-- ##### FUNCTION gtk_main_level ##### -->
<para>
-Asks for the current nesting level of the main loop. This can be useful
-when calling gtk_quit_add().
+Asks for the current nesting level of the main loop.
</para>
@void:
@Returns:
-<!-- ##### FUNCTION gtk_quit_add_destroy ##### -->
-<para>
-Trigger destruction of @object in case the mainloop at level @main_level
-is quit.
-</para>
-
-@main_level: Level of the mainloop which shall trigger the destruction.
-@object: Object to be destroyed.
-@Deprecated: This function is going to be removed in GTK+ 3.0
-
-
-<!-- ##### FUNCTION gtk_quit_add ##### -->
-<para>
-Registers a function to be called when an instance of the mainloop is left.
-</para>
-
-@main_level: Level at which termination the function shall be called. You
- can pass 0 here to have the function run at the termination of the current
- mainloop.
-@function: The function to call. This should return 0 to be removed from the
- list of quit handlers. Otherwise the function might be called again.
-@data: Pointer to pass when calling @function.
-@Returns: A handle for this quit handler (you need this for gtk_quit_remove())
- or 0 if you passed a %NULL pointer in @function.
-@Deprecated: This function is going to be removed in GTK+ 3.0
-
-
<!-- ##### USER_FUNCTION GtkCallbackMarshal ##### -->
<para>
@type:
@name:
-<!-- ##### FUNCTION gtk_quit_add_full ##### -->
-<para>
-Registers a function to be called when an instance of the mainloop is left.
-In comparison to gtk_quit_add() this function adds the possibility to
-pass a marshaller and a function to be called when the quit handler is freed.
-</para>
-<para>
-The former can be used to run interpreted code instead of a compiled function
-while the latter can be used to free the information stored in @data (while
-you can do this in @function as well)... So this function will mostly be
-used by GTK+ wrappers for languages other than C.
-</para>
-
-@main_level: Level at which termination the function shall be called. You
- can pass 0 here to have the function run at the termination of the current
- mainloop.
-@function: The function to call. This should return 0 to be removed from the
- list of quit handlers. Otherwise the function might be called again.
-@marshal: The marshaller to be used. If this is non-%NULL, @function is
- ignored.
-@data: Pointer to pass when calling @function.
-@destroy: Function to call to destruct @data. Gets @data as argument.
-@Returns: A handle for this quit handler (you need this for gtk_quit_remove())
- or 0 if you passed a %NULL pointer in @function.
-@Deprecated: This function is going to be removed in GTK+ 3.0
-
-
-<!-- ##### FUNCTION gtk_quit_remove ##### -->
-<para>
-Removes a quit handler by its identifier.
-</para>
-
-@quit_handler_id: Identifier for the handler returned when installing it.
-@Deprecated: This function is going to be removed in GTK+ 3.0
-
-
-<!-- ##### FUNCTION gtk_quit_remove_by_data ##### -->
-<para>
-Removes a quit handler identified by its @data field.
-</para>
-
-@data: The pointer passed as @data to gtk_quit_add() or gtk_quit_add_full().
-@Deprecated: This function is going to be removed in GTK+ 3.0
-
<!-- ##### MACRO GTK_PRIORITY_RESIZE ##### -->
<para>
/* Private type definitions
*/
-typedef struct _GtkQuitFunction GtkQuitFunction;
typedef struct _GtkKeySnooperData GtkKeySnooperData;
-struct _GtkQuitFunction
-{
- guint id;
- guint main_level;
- GtkCallbackMarshal marshal;
- GtkFunction function;
- gpointer data;
- GDestroyNotify destroy;
-};
-
struct _GtkKeySnooperData
{
GtkKeySnoopFunc func;
guint id;
};
-static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
-static void gtk_quit_destroy (GtkQuitFunction *quitf);
static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
GdkEvent *event);
static GSList *main_loops = NULL; /* stack of currently executing main loops */
-static GList *quit_functions = NULL; /* A list of quit functions.
- */
static GSList *key_snoopers = NULL;
static guint debug_flags = 0; /* Global GTK debug flag */
void
gtk_main (void)
{
- GList *tmp_list;
GMainLoop *loop;
gtk_main_loop_level++;
-
+
loop = g_main_loop_new (NULL, TRUE);
main_loops = g_slist_prepend (main_loops, loop);
gdk_flush ();
}
- if (quit_functions)
- {
- GList *reinvoke_list = NULL;
- GtkQuitFunction *quitf;
-
- while (quit_functions)
- {
- quitf = quit_functions->data;
-
- tmp_list = quit_functions;
- quit_functions = g_list_remove_link (quit_functions, quit_functions);
- g_list_free_1 (tmp_list);
-
- if ((quitf->main_level && quitf->main_level != gtk_main_loop_level) ||
- gtk_quit_invoke_function (quitf))
- {
- reinvoke_list = g_list_prepend (reinvoke_list, quitf);
- }
- else
- {
- gtk_quit_destroy (quitf);
- }
- }
- if (reinvoke_list)
- {
- GList *work;
-
- work = g_list_last (reinvoke_list);
- if (quit_functions)
- quit_functions->prev = work;
- work->next = quit_functions;
- quit_functions = work;
- }
-
- gdk_flush ();
- }
-
main_loops = g_slist_remove (main_loops, loop);
g_main_loop_unref (loop);
return return_val;
}
-guint
-gtk_quit_add_full (guint main_level,
- GtkFunction function,
- GtkCallbackMarshal marshal,
- gpointer data,
- GDestroyNotify destroy)
-{
- static guint quit_id = 1;
- GtkQuitFunction *quitf;
-
- g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
-
- quitf = g_slice_new (GtkQuitFunction);
-
- quitf->id = quit_id++;
- quitf->main_level = main_level;
- quitf->function = function;
- quitf->marshal = marshal;
- quitf->data = data;
- quitf->destroy = destroy;
-
- quit_functions = g_list_prepend (quit_functions, quitf);
-
- return quitf->id;
-}
-
-static void
-gtk_quit_destroy (GtkQuitFunction *quitf)
-{
- if (quitf->destroy)
- quitf->destroy (quitf->data);
- g_slice_free (GtkQuitFunction, quitf);
-}
-
-static gint
-gtk_quit_destructor (GtkWidget **object_p)
-{
- if (*object_p)
- gtk_widget_destroy (*object_p);
- g_free (object_p);
-
- return FALSE;
-}
-
-void
-gtk_quit_add_destroy (guint main_level,
- GtkWidget *object)
-{
- GtkWidget **object_p;
-
- g_return_if_fail (main_level > 0);
- g_return_if_fail (GTK_IS_WIDGET (object));
-
- object_p = g_new (GtkWidget*, 1);
- *object_p = object;
- g_signal_connect (object,
- "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- object_p);
- gtk_quit_add (main_level, (GtkFunction) gtk_quit_destructor, object_p);
-}
-
-guint
-gtk_quit_add (guint main_level,
- GtkFunction function,
- gpointer data)
-{
- return gtk_quit_add_full (main_level, function, NULL, data, NULL);
-}
-
-void
-gtk_quit_remove (guint id)
-{
- GtkQuitFunction *quitf;
- GList *tmp_list;
-
- tmp_list = quit_functions;
- while (tmp_list)
- {
- quitf = tmp_list->data;
-
- if (quitf->id == id)
- {
- quit_functions = g_list_remove_link (quit_functions, tmp_list);
- g_list_free (tmp_list);
- gtk_quit_destroy (quitf);
-
- return;
- }
-
- tmp_list = tmp_list->next;
- }
-}
-
-void
-gtk_quit_remove_by_data (gpointer data)
-{
- GtkQuitFunction *quitf;
- GList *tmp_list;
-
- tmp_list = quit_functions;
- while (tmp_list)
- {
- quitf = tmp_list->data;
-
- if (quitf->data == data)
- {
- quit_functions = g_list_remove_link (quit_functions, tmp_list);
- g_list_free (tmp_list);
- gtk_quit_destroy (quitf);
-
- return;
- }
-
- tmp_list = tmp_list->next;
- }
-}
-
/**
* gtk_get_current_event:
*
return widget;
}
-static gint
-gtk_quit_invoke_function (GtkQuitFunction *quitf)
-{
- if (!quitf->marshal)
- return quitf->function (quitf->data);
- else
- {
- GtkArg args[1];
- gint ret_val = FALSE;
-
- args[0].name = NULL;
- args[0].type = G_TYPE_BOOLEAN;
- args[0].d.pointer_data = &ret_val;
- ((GtkCallbackMarshal) quitf->marshal) (NULL,
- quitf->data,
- 0, args);
- return ret_val;
- }
-}
-
/**
* gtk_propagate_event:
* @widget: a #GtkWidget