quit handlers and idle_remove_by_data fixups

-timj
This commit is contained in:
Tim Janik 1998-03-01 04:53:56 +00:00
parent 91c1c8dddb
commit d491547e86
3 changed files with 195 additions and 11 deletions

16
NEWS
View File

@ -2,13 +2,18 @@ Forthcoming Changes for GTK+ 0.99.4:
* Reference counting revolution integrated.
Refer to docs/refcounting.txt on this issue.
* Implementation of a decent debugging system, see docs/debugging.txt.
* Implementation of a decent debugging system, you would want
to export GTK_DEBUG=objects if you are going to develop gtk applications,
refer to docs/debugging.txt for further information.
* Additions on the signal code for querying information about certain signals,
and pending handlers of signals.
* Support for user signals, and major changes to internal signal handler
handling for proper signal removal and invokation of after signals.
* GtkTooltips became a true descendant of GtkObject and facilitates an
extra tip string which can be used as e.g. an index into context help.
* Additional signals for various widgets e.g, GtkHandleBox::child_attached,
GtkHandleBox::child_detached, GtkWidget::style_set, GtkWidget::parent_set.
* GtkTooltips became a true descendant of GtkObject via derivation from
GtkData and facilitates an extra tip string which can be used as e.g. an
index into context help.
* Split up of the widget/object flags into a private and a public portion,
consult docs/widget_system.txt on this.
* Support for hot keys on gtk programs via gtk_key_snooper_install().
@ -16,13 +21,18 @@ Forthcoming Changes for GTK+ 0.99.4:
simple callback functions as well.
* Idle functions are now prioritized.
* Many enhancements to GtkNotebook.
* New widget GtkSpinButton, check out testgtk.
* New widget GtkTipsQuery for letting the user query tooltips of widgets.
* Gdk now supports regions.
* Access masks for widget arguments (GTK_ARG_READABLE/GTK_ARG_WRITABLE).
* Function replacements:
g_string_hash() -> g_str_hash()
g_string_equal() -> g_str_equal()
gtk_tooltips_set_tips() -> gtk_tooltips_set_tip()
* Support for quit handlers in gtk_main().
* Motif window mangaer hints support.
* Widget arguments are now flagged for readability/writability.
* Various FAQ updates.
* Clean ups and many many bug fixes by a lot of people all over the place.
* New, long and descriptive ChangeLog entries for bored readers ;)

View File

@ -37,6 +37,7 @@
/* Private type definitions
*/
typedef struct _GtkInitFunction GtkInitFunction;
typedef struct _GtkQuitFunction GtkQuitFunction;
typedef struct _GtkTimeoutFunction GtkTimeoutFunction;
typedef struct _GtkIdleFunction GtkIdleFunction;
typedef struct _GtkInputFunction GtkInputFunction;
@ -48,6 +49,16 @@ struct _GtkInitFunction
gpointer data;
};
struct _GtkQuitFunction
{
gint tag;
guint main_level;
GtkCallbackMarshal marshal;
GtkFunction function;
gpointer data;
GtkDestroyNotify destroy;
};
struct _GtkTimeoutFunction
{
gint tag;
@ -85,6 +96,8 @@ struct _GtkKeySnooperData
};
static void gtk_exit_func (void);
static gint gtk_quit_invoke_function (GtkQuitFunction *quitf);
static void gtk_quit_destroy (GtkQuitFunction *quitf);
static void gtk_timeout_insert (GtkTimeoutFunction *timeoutf);
static void gtk_handle_current_timeouts (guint32 the_time);
static void gtk_handle_current_idles (void);
@ -117,6 +130,8 @@ static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
*/
static GList *init_functions = NULL; /* A list of init functions.
*/
static GList *quit_functions = NULL; /* A list of quit functions.
*/
static GList *timeout_functions = NULL; /* A list of timeout functions sorted by
* when the length of the time interval
* remaining. Therefore, the first timeout
@ -131,6 +146,7 @@ static GList *current_idles = NULL;
static GList *current_timeouts = NULL;
static GMemChunk *timeout_mem_chunk = NULL;
static GMemChunk *idle_mem_chunk = NULL;
static GMemChunk *quit_mem_chunk = NULL;
static GSList *key_snoopers = NULL;
@ -283,14 +299,48 @@ gtk_main ()
(* init->function) (init->data);
g_free (init);
}
g_list_free (functions);
old_done = iteration_done;
while (!gtk_main_iteration ())
;
iteration_done = old_done;
if (quit_functions)
{
GList *reinvoke_list = NULL;
GtkQuitFunction *quitf;
while (quit_functions)
{
quitf = quit_functions->data;
quit_functions = g_list_remove_link (quit_functions, quit_functions);
if ((quitf->main_level &&
quitf->main_level != main_level) ||
gtk_quit_invoke_function (quitf) == FALSE)
{
g_list_free (tmp_list);
gtk_quit_destroy (quitf);
}
else
{
reinvoke_list = g_list_prepend (reinvoke_list, quitf);
}
}
if (reinvoke_list)
{
GList *tmp_list;
tmp_list = g_list_last (reinvoke_list);
if (quit_functions)
quit_functions->prev = tmp_list;
tmp_list->next = quit_functions;
quit_functions = tmp_list;
}
}
main_level--;
}
@ -795,6 +845,36 @@ gtk_idle_compare (gpointer a, gpointer b)
? -1 : 1;
}
gint
gtk_quit_add_full (guint main_level,
GtkFunction function,
GtkCallbackMarshal marshal,
gpointer data,
GtkDestroyNotify destroy)
{
static gint quit_tag = 1;
GtkQuitFunction *quitf;
g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
if (!quit_mem_chunk)
quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
512, G_ALLOC_AND_FREE);
quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
quitf->tag = quit_tag++;
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->tag;
}
gint
gtk_idle_add_full (gint priority,
GtkFunction function,
@ -841,6 +921,22 @@ gtk_idle_destroy (GtkIdleFunction *idlef)
g_mem_chunk_free (idle_mem_chunk, idlef);
}
static void
gtk_quit_destroy (GtkQuitFunction *quitf)
{
if (quitf->destroy)
quitf->destroy (quitf->data);
g_mem_chunk_free (quit_mem_chunk, quitf);
}
gint
gtk_quit_add (guint main_level,
GtkFunction function,
gpointer data)
{
return gtk_quit_add_full (main_level, function, NULL, data, NULL);
}
gint
gtk_idle_add (GtkFunction function,
gpointer data)
@ -856,6 +952,54 @@ gtk_idle_add_priority (gint priority,
return gtk_idle_add_full (priority, function, NULL, data, NULL);
}
void
gtk_quit_remove (gint tag)
{
GtkQuitFunction *quitf;
GList *tmp_list;
tmp_list = quit_functions;
while (tmp_list)
{
quitf = tmp_list->data;
if (quitf->tag == tag)
{
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;
}
}
void
gtk_idle_remove (gint tag)
{
@ -912,7 +1056,7 @@ gtk_idle_remove_by_data (gpointer data)
{
idle_functions = g_list_remove_link (idle_functions, tmp_list);
g_list_free (tmp_list);
g_mem_chunk_free (idle_mem_chunk, idlef);
gtk_idle_destroy (idlef);
return;
}
@ -929,7 +1073,7 @@ gtk_idle_remove_by_data (gpointer data)
{
current_idles = g_list_remove_link (current_idles, tmp_list);
g_list_free (tmp_list);
g_mem_chunk_free (idle_mem_chunk, idlef);
gtk_idle_destroy (idlef);
return;
}
@ -1149,6 +1293,26 @@ gtk_handle_timeouts ()
}
}
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 = GTK_TYPE_BOOL;
args[0].d.pointer_data = &ret_val;
((GtkCallbackMarshal) quitf->marshal) (NULL,
quitf->data,
0, args);
return ret_val;
}
}
static gint
gtk_idle_invoke_function (GtkIdleFunction *idlef)
{
@ -1158,12 +1322,13 @@ gtk_idle_invoke_function (GtkIdleFunction *idlef)
{
GtkArg args[1];
gint ret_val = FALSE;
args[0].name = NULL;
args[0].type = GTK_TYPE_BOOL;
args[0].d.pointer_data = &ret_val;
((GtkCallbackMarshal)idlef->marshal) (NULL,
idlef->data,
0, args);
((GtkCallbackMarshal) idlef->marshal) (NULL,
idlef->data,
0, args);
return ret_val;
}
}

View File

@ -60,7 +60,16 @@ void gtk_grab_remove (GtkWidget *widget);
void gtk_init_add (GtkFunction function,
gpointer data);
gint gtk_quit_add (guint main_level,
GtkFunction function,
gpointer data);
gint gtk_quit_add_full (guint main_level,
GtkFunction function,
GtkCallbackMarshal marshal,
gpointer data,
GtkDestroyNotify destroy);
void gtk_quit_remove (gint tag);
void gtk_quit_remove_by_data (gpointer data);
gint gtk_timeout_add_full (guint32 interval,
GtkFunction function,
GtkCallbackMarshal marshal,