Hi!
   The best and simplest way to get rid of global varriables would be
to define a structure that would contain all the data you need and
then you can keep passing it's pointer around in the callbacks using
the 'user_data' argument. If you want to use g_object_set/get_data()
instead, thats also possible and very easy (you don't even have to
define a new structure, since you can assign different string keys for
different kinds of data). IMHO, the g_object_set/get_data() API
reference (1) is good enough and there doesn't need to be an example
code for all possible scenerios in the tutorials/docs.

1. 
http://developer.gnome.org/doc/API/2.0/gobject/gobject-The-Base-Object-Type.html#g-object-set-data

On 11/26/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> This is my global variable version:
>
>    #include <gtk/gtk.h>
>
>    #include "callbacks.h"
>    #include "interface.h"
>    #include "support.h"
>
>    GtkWidget *window2, *window1, *label1, *entry1;
>
>    void
>    on_button1_clicked                     (GtkButton       *button,
>                                         gpointer         user_data)
>    {
>     window1 = lookup_widget(button,"window1");
>     window2=create_window2();
>     gtk_widget_show(window2);
>     gtk_grab_add(window2);
>    }
>
>
>    void
>    on_button2_clicked                     (GtkButton       *button,
>                                            gpointer         user_data)
>    {
>     label1 = lookup_widget(window1,"label1");
>     entry1 = lookup_widget(window2,"entry1");
>     gtk_label_set_text(label1,gtk_entry_get_text(entry1));
>     gtk_grab_remove(window1);
>     gtk_widget_destroy(window2);
>    }
>
> Thanks,
> Kim
> ---- "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I am about to start a new app, and would like to improve my programming 
> > style. I have been using global variables to pass data from "popup" windows 
> > back to a main window. I have seen discussion about using 
> > g_object_set_data, but have not progressed to being able to use it 
> > confidently.
> >
> > Does anyone know of a simple example using g_object_set_data. The sort of 
> > thing I am thinking about is a main window with a label and button, that 
> > pops up a child window with an entry and a button. Clicking the child 
> > windows button returns the string in the entry back to the main windows 
> > label.
> >
> > This sort of example would be very useful in the tutorial.
> >
> > Thanks,
> > Kim
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > gtk-app-devel-list@gnome.org
> > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>


-- 
Regards,

Zeeshan Ali,
Software Design Engineer,
Open Source Software Operations,
Nokia,
Helsinki, Finland.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to