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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

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

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

2: Make a single global structure and have its
as the necessary widgets. This is followed in LibGlade
initialization policies, in the function

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

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.


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;
  { g_message("T2 reference not found\n");
 /* you have t1 & t2 now! */

Add similar CB code for t2.


--- Michal Porzuczek <[hidden email]> 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
> [hidden email]

Do you Yahoo!?
Yahoo! Small Business - Try our new Resources site
gtk-app-devel-list mailing list
[hidden email]