Re: [gtk-list] Basic Q. on callbacks and signal handling



> Hi,
> I am going through the gtk tutorials (at gtk.org). I can't
> explain this to myself. when we setup a callback for an event, we also
> pass the pointer to the widget that emitted the signal to that callback.
Actually, no we don't.

> In tutorial 8 (range buttons), in the first call back
> cb_pos_menu_select , the widget that emits the signal is passed as an
> argument to this function.
Correct. GTK+ passes this in, not you. If you don't need it, you don't have
to use it. But the function is invoked with this piece of data supplied as
the first argument.

> going by this, it would seem that once we set up the signal
> handler, all the connections between the widget and the call back
> function are maintained internally by GTK.
Exactly!

>so now my real question...
> why do I need to pass the widget as an argument in this particular call
> back function (it does not serve any purpose).
You aren't. You must simply give 3 pieces of information to GTK+, which
widget,
which signal from that widget, and what function to invoke when that signal
(from
that widget) occurs. You pass data in through the last parameter of the
gtk_signal_connect().

If you look at the make_menu_item() for "Top", this is what is executed:

    item = gtk_menu_item_new_with_label ("Top");
    gtk_signal_connect (GTK_OBJECT (item), "activate",
                        cb_pos_menu_select, GTK_POS_TOP);
    gtk_widget_show (item);


So, cb_pos_menu_select() will be invoked when the user activates the "Top"
menu item,
(and GTK_POS_TOP is passed to the pos parameter). (Again, GTK+ supplies the
widget (it's always possible more than one widget uses the same callback).)
If you don't
need it, don't use it...

Does this help?
Donna
 > --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
/dev/null
>
>



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