Sharing Variables in GTK+, & Re: State changing of Toggle Buttons



Hi Michal,
This might be the solution, if I understand you right.

General information.
If you write C code, and want to access lots of
variables from a Callback, then there are a few simple
ways.

1: Make all the variables global, so you can access
them anywhere[function] in C.

2: Make a single global structure and have its
elements
as the necessary widgets. This is followed in LibGlade
initialization policies, in the function
glade_xml_get_widget(xml_ptr,wid_name);

3: Use g_object_set_data(obj,name,ext_ptr) to save
some 
reference to ext_ptr with this obj. This is similar to
doing 
           obj["name"] = &ext_ptr; in C++ or any OOP
language.

To get the data (the operation obj["name"] in C++/OOP)
we have to use  
(typecast as necessary ) g_object_get_data(obj,name);



Re: State changing of Toggle Buttons
------------------------------------
Specific information.

/*You have 2 toggle btns t1 & t2.
  In you main function add this code. */

Simple solution: Make t1 & t2 global variables, so you
can access them anywhere.

[good] Complex solution: Make a reference of t1 with
t2. like this.

g_object_set_data(G_OBJECT(t1),"t2",t2);
g_object_set_data(G_OBJECT(t2),"t1",t1);

This creates reference of t2 with t1, and vice verca.

Now in your callback for code t1 do this.

int t1_activated(GtkWidget *t1,void *data)
{
  GtkWidget *t2;
  t2=g_object_get_data(G_OBJECT(t1),"t2");
  if(!t2)
  { g_message("T2 reference not found\n");
  }
 /* you have t1 & t2 now! */
}

Add similar CB code for t2.

Cheers
Muthu.



--- Michal Porzuczek <mporzuczek gmail com> wrote:
Hi,

I was wondering if it is possible to set a Toggle
Button's state to
something else when you are inside another Toogle
Button's callback. I
know there is the gtk_toggle_button_set_active
method but that
requires you to have the GtkToggleButton. Is there
another method that
only uses the Widget to change its state? Or is
there an easy way of
accessing the GtkToggleButton from the Widget?

Thanks in advance

Michal
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



                
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new Resources site
http://smallbusiness.yahoo.com/resources/



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