Re: [gtk-list] Re: stubs and callbacks
- From: Tim Janik <Tim Janik Hamburg Netsurf DE>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: stubs and callbacks
- Date: Mon, 19 Jan 1998 23:14:09 +0100 (CET)
On 19 Jan 1998, Tero Pulkkinen wrote:
> David Monniaux <monniaux@clipper.ens.fr> writes:
> > I have problems with callbacks.
> > I'd like to use gtk_signal_connect to bind a signal to a generic function
> > with a specific parameter.
> > I used:
> > value mlgtk_callback_exec(GtkObject *obj, value x)
> >
> > gtk_signal_connect(object, name, mlgtk_callback_exec, SOME_VALUE);
> >
> > Will x be equal to SOME_VALUE or to a pointer on SOME_VALUE?
depends on the type of signal, as described below, but there is another
solution, though it's not obvious:
gtk_signal_connect_object (object,
name,
GTK_SIGNAL_FUNC (mlgtk_callback_exec),
(GtkObject*) SOME_VALUE);
this will invoke
mlgtk_callback_exec (SOME_VALUE, other signal dependant arguments);
don't use GTK_OBJECT (SOME_VALUE) cause this would make a type check,
which most probably results in segfaults.
this use is not the primray idea for gtk_signal_connect_object, but it is
asured that SOME_VALUE will be untouched in the internals of signal
emissions.
you will only get unpredictable results with signals that expect a return
value, it is mostly ok to return (gint) 0; in such cases.
>
> Which signal are you connecting? Maybe the signal has arguments of its
> own and you'll need to skip those arguments.
>
> The SOME_VALUE can only be pointer type, thus passing anything else in
> that cept pointer should give type error.
>
> struct foo *f;
> gint foo_event_signal(GtkObject *o, GdkEventButton*, struct foo *f);
>
> gtk_signal_connect(object,"button_press_event",foo_event_signal,f);
>
> It is a problem with C that there's no type checking and compiler cannot
> detect bad connect() calls. :(
>
> --
> -- Tero Pulkkinen -- terop@modeemi.cs.tut.fi --
>
> --
> 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]