Re: name -> widget func?



To get a specific widget, say in a window with other 300
widgets, use set_data/get_data functions, as in the following example:

when you create the button:
gtk_object_set_data (GTK_OBJECT (window), "my_button", button);

when you want it back:
button = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (window), "my_button");

Carlos


What if you wanted to use in integer instead of "my_button" in each case?
like:
for(i=0;i<count;i++)
button[i] = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (window), i );

That's fine, I use it myself, others in this list use this method as well.
You just have to fully understand the implications. Imagine that i
is equal to 5. Then you are passing an address as, say 0000000005,
then when you get it back you convert this address back to a number
so 0000000005  becomes 5 again (Of course if you try to access
this 0000000005 memory position you will have a crash...). The only
limitation of this method is, if your machine uses 32 bits to
describe a memory address then you cannot pass numbers bigger
than that... which means 2**32-1 (unsigned integer), a fairly large integer! 

This method is also often used to pass numbers 
as data parameters in gtk_signal_connect commands.

This is from my own code (APP_LAYER is an integer in an enumeration):

gtk_object_set_data (GTK_OBJECT (menu), "select", (gpointer) APP_LAYER);

Carlos




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