Re: Callbacks for windows that return large amounts of data



"Luesley, William" wrote:

If I create a dialog window which obtains a lot of data form the user
in multiple widgets, what is the best way to get at that data in the
associated callback function?
 
The two thoughts I'd had were either making the widgets required
global(yuck!),  or using gtk_object_set_data to link all the widgets
to the parent widget, and then pass the parent widget as data to the
callback. 
However, neither of these ideas sounds totally correct to me.

Clarification: I understand your question as asking for a way to obtain
pointers / handles to widgets and not the data / contents / states of
widgets.

For this (the former) purpose Glade provides the lookup_widget ()
function which is only available when the form was created with Glade
and not changed significantly afterwards.

A slightly more generic / independent way is provided by my
widget_find_by_name () function which is available at
http://www.spamkiller.bytechase.cx/democode/widget_find_by_name.c

To use it you just need to pass it a pointer to a suitable container (or
parent window) which can easily be obtained inside any callback function
via (possibly repeated) gtk_widget_get_parent (). No more need for
global variables or other special precautions. However, you should name
your widgets (at least the important ones) comprehensible.

http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-get-parent
http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-set-name



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