Re: [gtk-list] Re: widget name



On Mon, 27 Mar 2000, didi@altatech.com wrote:
> Andreas Scherf wrote:
> > 
> > On Fri, 24 Mar 2000, didi@altatech.com wrote:
> > > I create several buttons and set names for them.
> > > Can I later in different function reach the button using it's name?
> > YES use :
> I could not get it work, What parameter-widget you pass to this function
> > GtkWidget *
> >  get_widget(GtkWidget * widget, gchar * widget_name)
> > {
> >     GtkWidget *parent, *found_widget;
> > 
> >     for (;;) {
> >         if (GTK_IS_MENU(widget))
> >             parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
> >         else
> >             parent = widget->parent;
> >         if (parent == NULL)
> >             break;
> >         widget = parent;
> >     }
> > 
> >     found_widget = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(widget),
> >                                                      widget_name);
> >     if (!found_widget)
> >         g_warning("Widget not found: %s", widget_name);
> >     return found_widget;
> > }
> > 
> > > Thanks,
> > > Didi
This function works recursiv. So you could work with maybe the main dialog
widget. Define this widget static for this file you are working with maybee
like this :

static GtkWidget *main_window;

int main()
{
..
main_window = gtk_window_new(..);
more to come ...
..
} 
Now you could use get_widget with main_window and the widget name you give the 
other widget .... 
Hope this helps otherwise mail back and i`ll send you the whole pice of code ;)


Andreas Scherf

scherfa@fh-trier.de             
http://www.fh-trier.de/~scherfa

"It said uses Windows 98 or better, so I loaded Linux!"



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