Re: Program Structure

I am having trouble understanding the structure of programming a GTK+
app. My biggest hangup is how do I modify a widget that is nested in a
window several levels down?  I looked at mapping to it by name or
creating a master structure containing all the widget pointers.  Neither
of these look very practical.  Another method I thought of was creating
a callback that responds to a signal manufactured by another widget.
This last I am not sure how to approach, but I am hoping I can send data
to the widget that responds to the signal.  This problem probably has a
simpler solution.  I am new to programming this way as opposed to a
linear program. I am used to having access to all my data all the time.
I would like to keep my apps object oriented, but I am not understanding
how to make widgets talk to each other easily without destroying the OO

Yer on the right track from the start. :)  I use structures quite a lot in
big GTK+ apps like Vertex3D and ManEdit.

Typical structure would look like:

typedef struct {

        GtkWidget *toplevel;    /* The toplevel GtkWindow */
        GtkWidget *department_ctree;
        GtkWidget *inventory_clist;
        GtkWidget *close_button;

        GtkCTreeNode *selected_department_item;
        int selected_inventory_item;

} my_inventory_struct;

This `window' as a whole, may contain several GTK+ widgets, more than
what's listed in the struct, but they are not important and as such not

If yer worried about deallocating memory, then you need not worry
as destroying the toplevel GtkWindow will destroy each subsequent widget.

I would prefer to destroy each item in the two lists before destroying the
toplevel window just to be formal and neat.

If from what yer implying that you have a ton of important widgets, you
may want to make a pointer array index to a list of GtkWidgets that you
created, ie:

        GtkWidget **widget_list;
        int total_widgets;

This pair indicates all the important widgets, where each pointer points
to a GtkWidget pointer.

Use realloc() to adjust the widget_list and be sure to update
total_widgets appropriatly.

free() the widget_list pointer array (but not each pointer) when yer done.

Hope that helps!

Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
..__                         ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..

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