Re: newbie question
- From: Dov Grobgeld <dov grobgeld gmail com>
- To: Tadej Borovšak <tadeboro gmail com>
- Cc: frederico schardong <frede sch gmail com>, gtk-app-devel-list gnome org
- Subject: Re: newbie question
- Date: Wed, 11 Mar 2009 18:14:12 +0200
Hi Frederico,
(Copied from my own post from Mar 23, 2006 12:31:00 pm)
Here are four additional 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 or vala 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
2009/3/11 Tadej Borovšak <tadeboro gmail com>
2009/3/11 frederico schardong <frede sch gmail com>:
void my_callback_function (GtkButton *widget, gpointer user_ptr);
...
g_signal_connect( G_OBJECT( widget), "clicked",
G_CALLBACK( my_callback_function), user_ptr );
void my_callback_function (GtkButton *widget, gpointer user_ptr) {
...
}
http://library.gnome.org/devel/gtk/unstable/GtkButton.html
but how I can pass to my_callback_function the gtk_drawing_area? I
know about the g_signal_connect.. but I not know how pass another
widget, without the widget being passed the first parameter of
function..
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Hello.
Just pass your drawing area as a last parameter to g_signal_connect
function.
Simple code would look like:
---------- CODE -----------
int
main( int argc, char **argv )
{
GtkWidget *button = gtk_button_new();
GtkWidget *draw = gtk_drawing_area_new();
g_signal_connect( G_OBJECT( button ), "clicked",
G_CALLBACK( cb_clicked ), draw );
/* More code here */
}
/* Callback function */
static void
cb_clicked( GtkButton *button,
GtkWidget *draw )
{
/* Code here to save your work */
}
------- /CODE ----------
--
Tadej Borovšak
tadeboro gmail com
tadej borovsak gmail com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]