Re: [gtk-list] Passing (gpointer)data to a signal




On Fri, 18 Jun 1999, Duane Johnson wrote:
> 
> When a new signal is created, a marshalling function must be used so that the
> signal's parameters can be specified dynamically.  However, I would like to
> know why the parameters have to be specified twice?  By this, I mean that they
> need to be defined once in the name of the marshalling function, and once at
> the end of the gtk_signal_new function.  Why is that?
>

Gtk needs to know what the parameters are, and there's no way for a C
program to determine the name of a function, so it can't get that
information from the marshaller name. The marshaller name is purely to
help you find the proper marshaller to use. 
 
> Also, when I define a callback function as having, for example, two pointers
> as parameters, is that the total number of parameters that the callback MUST
> have?  The reason I ask this, is when I call "gtk_signal_emit" I pass along
> some parameters to the callback function... but what about the (gpointer)data
> that the user passes?  My widget can't possibly know that value, so how is it
> passed?
> 

All callbacks automatically have two arguments: the emitting object, and
the user data. If you don't specify any parameters for the signal, you
will still have these two. Look at the NONE__NONE marhsaller:

typedef void (*GtkSignal_NONE__NONE) (GtkObject * object,
                                      gpointer user_data);
void 
gtk_marshal_NONE__NONE (GtkObject * object,
                        GtkSignalFunc func,
                        gpointer func_data,
                        GtkArg * args)
{
  GtkSignal_NONE__NONE rfunc;
  rfunc = (GtkSignal_NONE__NONE) func;
  (*rfunc) (object,
            func_data);
}

The arguments to gtk_signal_emit() are the object, the signal name, the
signal parameters (not including the two automatic parameters), and a
location for the signal's return value.

The "emitting object" parameter comes from the first arg to
gtk_signal_emit(), and the "user data" is stored by Gtk when someone calls
gtk_signal_connect().

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]