Re: [gtk-list] Re: How do I send arguments with signals?




Mike Arnold <mike@thale.life.nottingham.ac.uk> writes:

> > void hello (GtkWidget *label)
> 
> This is not a GtkSignalFunc function, and I would have thought generated
> an error during compilation!.
> 
> The correct version would be 
> 
> void hello(GtkWidget *widget, gpointer data)
> 
> The data would be the label widget and I'm not entirely sure what the
> widget represents, never had to use it!

Since one typically uses an explicit cast to GtkSignalFunc when
calling gtk_signal_connect, the compiler can't check the type of
the function. In fact, the correct function can look quite different
for different signals types. For event signals, the callback looks like:

int my_event_handler(GtkWidget *widget, GtdEventWhatever *event, gpointer
		     data)

But the first argument is always the widget to which the signal
belongs (e.g., the widget in which the event occurred), unless 
it was connected with gtk_signal_connect_object, in which case,
it will be the fourth argument of the gtk_signal_connect_object
call.

> One thing that puzzles me, and perhaps someone may be able to enlightent
> me on this, is why most of the functions are declared static??  I've
> never seen another program use so many static functions as the GTK/GIMP
> does...... not criticism, but not being a Computer Scientist I'm just
> curious. I just do it to follow suite, without really understanding the
> importance of it!

In C, a static function is one that is localized to one object file.
The fact that gtk and the GIMP have so many is probably an indication
of good programming style. The code is broken up into small chunks
with well defined interfaces between them.

Regards,
                                        Owen



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