Re: [gtk-list] Gtk+ Signal question
- From: Tim Janik <timj gtk org>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Gtk+ Signal question
- Date: Mon, 20 Jul 1998 22:12:20 +0200 (CEST)
On Mon, 20 Jul 1998, Michael Lausch wrote:
>
> Suppose i have a class which emits two signals. `error' and
> `warning'. I want to have a defautl action for this signals, if the
> user didn't connect any actions to the signal. The default action
> should not be executed, if the user wants to handle the signals. If no
> actions are connected to the signals, the default action shoudl be
> executed.
>
> How can this be done?
implement a handler for that warning function:
static void
my_handler (GtkWidget *widget)
{
printf ("hey, i guess i should warn you!\n");
}
and in class_init you do
widget_signals[DEBUG_MSG] =
gtk_signal_new ("warning_msg",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (GtkWidgetClass, warning_msg),
gtk_signal_default_marshaller,
GTK_TYPE_NONE, 0);
widget_class->warning_msg = my_handler;
now when you later connect to this signal, your handler needs to stop the
emission, so the classes default handler doesn't get called:
void
user_handler (GtkWidget *widget, gpointer data)
{
printf ("warning ignored!\n");
gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "warning_msg");
}
that would be the usual way to do this. however another approach exists:
class_init:
widget_signals[DEBUG_MSG] =
gtk_signal_new ("warning_msg",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (GtkWidgetClass, warning_msg),
gtk_signal_default_marshaller,
GTK_TYPE_NONE, 0);
widget_class->warning_msg = my_handler;
and the default handler:
static void
my_handler (GtkWidget *widget)
{
/* check for pending handlers on this signal:
*/
if (!gtk_signal_handler_pending (GTK_OBJECT (widget), widget_signals[DEBUG_MSG], FALSE))
{
printf ("hey, i guess i should warn you!\n");
}
}
note the differences in the signal run type during signal creation. in the
former example we use RUN_LAST so that our handler can be skipped when the
emisison is stopped at the users request. in the latter we use RUN_FIRST and
decide what to do in this function by checking whether there are actually
user handlers pending or not.
> --
> Michael Lausch/g.a.m.s. edv dienstleistungen gmbh
> See my web page <http://www.gams.net/~mla> or query PGP key server for PGP key.
> "Reality is that which, when you stop believing in it, doesn't go away".
> -- Philip K. Dick
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
>
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]