Re: name -> widget func?



Given a text name and the TopLevel widget, I'd like to retrieve the proper
child GtkWidget*.  What function does that?

Example: window1 has a child widget button1.  
Given: toplevel = (GtkWidget*)window1; name = (char*)"button1";
      myButton = (GtkWidget*) GetWidgetByName(name, toplevel);
Result:
      myButton would point to button1

You can get the direct child as in the following example:

label = GTK_BIN (button)->child;

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");

The glib list allocated by the set_data function will be removed
automatically when the top object is removed (in this case the window).

set_data/get_data are a very simple and elegant way to pass
temporary data (typically widget addresses) to dialog windows,
because if you set your data to the dialog then it will be
automatically freed when you destroy the dialog (the
dialog address itself would be passed in a structure 
using the data parameter in gtk_signal_connect.)

Carlos




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