Re: how to access a widget ?



On Sun, 2004-08-29 at 22:54, edward hage wrote:
> Hello,
> 
> I have made a program which shows a table with buttons, created like this
> ..........
> 
> for (i=0; i < vertical - 1; i++)
> { ............. etc.
>    ...........etc. ....etc.......
>   for (j=1; j < vertical; j++)
>   {
>     if (i < j)
>     {
>      button = gtk_button_new ();
>      gtk_button_set_label ( (GtkButton *) button , " ");
>      gtk_table_attach_defaults (GTK_TABLE (table), button , 1 + j, 2 + j, 1 + i, 2 + i);
>      g_signal_connect (GTK_OBJECT(button), "clicked", (GCallback) toggle_location_event, 
> GINT_TO_POINTER (sum(i)+j));
>     }
>   }
> .....etc............
> }
> 
> I have a call-back function toggle_location_event which can change the text of the button 
> which is pressed.
> Now I also want to change the text of a button that is not pressed ( in 
> toggle_location_event). I know the location i and j of that button, but I don't know how 
> to change the text because I don't have the object-name myself (because I use  button = 
> gtk_button_new () lots of times to create more widgets which don't have unique names).
> 
> How can I retrieve the widget from the known location so I can change the text on the button ?

You can cache a matrix with your buttons and the last changed buttons in
a structure[1] and then send this structure[2] as user data (in the
callback).

1 -
struct buttons_matrix {
	GtkButtons * table[][];
	gint last_x;
	gint last_y;
};

2 -
struct change_button {
	struct buttons_matrix *m;
	gint x;
	gint y;
};

So your problem resolves in two issues: a) you need a central structure
for holding your data (maybe a GObject?); b) you may need to create
auxiliar structures for sending multiple arguments trough callbacks.




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