Re: About widgets and callbacks...



Here are four possibilities:

1. Use global variables for your widgets.

2. Create a struct containing pointers to all your widgets and use the
userdata field to pass this struct around in all callbacks.

3. Use the g_object_set_data() method to attach miscellaneous pointers
to your widgets. I.e. in the widget construction do:

    GtkWidget *w_tree_view, *w_button;
    w_tree_view = gtk_tree_view_new(...);
    :
    w_button = gtk_button_new();
    g_object_set_data(G_OBJECT(w_button), "tree_view", w_tree_view);
    g_signal_connect(G_OBJECT(w_button), "clicked",
G_CALLBACK(cb_button_clicked), NULL);

and in the callback cb_button_clicked() do:

   GtkWidget *w_tree_view =
GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "tree_view"));

This method is similar to what glade is doing.

4. Create your own container widget, e.g. by gob2 and put all your
widgets in it. This is a fancy way of doing the struct callback I
mentioned above.

Hope this helps.

Regards,
Dov


On 3/23/06, Gonzalo Aguilar Delgado <gad aguilardelgado com> wrote:
> Hello all!
>
> I have a question about how to deal with widget interaction inside
> callbacks...
>
>
> Supose I have a TreeView and a Button in a glade GUI (or Manual gui),
> each one far from the other... (Separated)
>
> When I click in the button.
>         How can I get a reference from the TreeView?
>
> Because trasversing all the GTK tree can be a pain...
>
>
> --
> Gonzalo Aguilar Delgado - Ingeniero en Informática
>         [ Seguridad & Medios de pago ]
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>



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