If you use Glade to generate source code for your interface (rather
than using ) you should make use of the
lookup_widget() function that Glade defines for you (in
support.c) to access your widgets. You pass this function a
pointer to any widget in a window and the name of the widget that you
want to get (where the name is a string and is the same as the
Name in the Properties dialog for the widget). The
function will return a pointer to the widget whose name matches the
string you supply.
The lookup_widget() function relies on you giving a
pointer to any other widget in the same tree (perhaps a pointer to the
root of the widget hierarchy for that particular application window or
dialog). Usually in a signal handler (the callbacks that you write in
callbacks.c) you can use the first argument to the signal
handler as the first parameter to lookup_widget(). For
example you may have a button in you window called button1
and when it is clicked you may want to access some text entry field
that has the name ``entry1.'' In callbacks.c
you may have a callback:
void
on_button1_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *entry1;
entry1 = lookup_widget (GTK_WIDGET (button), "entry1");
...
}
|
Internally Glade uses gtk_object_set_data() for
storing pointers to all the widgets in a window using the names set in
the property editor as the key. Then, inside
lookup_widget(), gtk_object_get_data() is
used to retrieve the pointer indexed by this key. These two functions
are also available to the developer for their own purposes.
Subsections
Copyright © 1995-2006 [email protected]
|