Re: How can it do that?



Here's my take,


On Mon, 21 Jan 2002, hzeng wrote:

> Hello,
>     I find the interest thing in many example code that you can create many same type of widgets use 
> a same widget name, but the system can differ these widgets although they have the same name.
> 
> such as:
> 
>     Widget *button;

button is a pointer to a GtkWidget-derived object.

>     button=gtk_button_new_with_label("button1");

This creats a new GtkButton object, and button points to it.

>     gtk_signal_connect(GTKOBJECT(button),"clicked",GTK_SIGNAL_FUNC(callback),(gpointer)"button1");
>     ...

This sets up a signal handler to invoke callback(button, "button1") .

>     button=gtk_button_new_with_label("button2");

This creates a *new* GtkButton object.  The previous value of "button" is 
lost now, but you must have attached the "first" button to a vbox or
something when you said "...", so Gtk still has control of it!

>     gtk_signal_connect(GTKOBJECT(button),"clicked",GTK_SIGNAL_FUNC(callback),(gpointer)"button2");
>     ...

This sets up *another* signal handler to invoke callback(button, 
"button2"), but "button" is not the same widget as the first time.

Once you add your widgets to containers, Gtk effectively owns them and 
you can forget about them if you want to, that's why this all works and 
you can recycle the same "GtkWidget *" for as many objects as you want, 
as long as you add them to some kind of widget container.

Hope this helps,
-Jamie


>  At this situation, the system still can know the "clicked" signal is
> come from button1 or come from button2 and the callback founction can
> print different message. I am wondered about these. Can I get the
> reason?
> 
> Thank you very much
> Hzeng
> ‚Ù%ŠËfj)bž	b²Ø-’X¬¶	è™ê+‚m§ïÿ™¨¥‚z&zŠàþf¢–f§þX¬¶)ߣø-’X¬






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