Re: Fwd: Programming style



César Leonardo Blum Silveira wrote:
Hello all,

I have a few doubts about the way I code my GTK applications. One of
them is: Is it ok to use many global variables for the widgets? For
example, in a glade app where callbacks are of the form

void callback(GtkWidget *widget)

Note that you dont have to use global variables OR functions
that lookup widgets on hash-tables (glade_xml_get_widget) OR
functions that recurse through your heirarchy looking for
the widgets "name" property (as Gus suggested).

Every widget callback comes with a "user_data" argument,
and you can pass the desired data through that argument
(which is just as fast as using a global variable and is
just as clean as using a lookup_widget type of routine).

Note that libglade supports the passing of other objects
through to your signal callbacks user_data also, For example:

  you can attatch "on_close_button_clicked" to the clicked
signal of "close_button" with "main_window" as the user data
argument by setting the "object" field of the signal to
"main_window" (using glade-2)

in which case your callback should look like:

void
on_close_button_clicked (GtkButton *close_button,
                         GtkWindow *main_window)
{
    /* ... */
}

So you can even get all of this done using
   glade_xml_signal_autoconnect().

Cheers,
                                    -Tristan




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