Re: Help with retreiving children?



On Mon, 21 Aug 2000 alaric@portone.com wrote:

> 
> Hi there... 
> 
> I am creating an app using GTK+... I don't like global variables, or
> exporting large numbers of variables to implement functionality.
> 
> I have a form with multiple entries and combos and spin-buttons and I
> would like to be able to access those widgets without having a global
> variable for each.
> 
> I'm thinking something along the line of using a function on the top-level
> widget to return a pointer to the requested child-widget (requested by
> name, since I did name all my widgets, and whats the point of names if
> this isn't it?)
> 
> So if there's any functionality like this, or other suggestions, it would
> be greatly appreciated.  I've been through the docs, unfortunately they're
> a bit sketchy on the more complex topics.

    I would recomend you to (ab)use gtk_object_set_data/gtk_object_get_data,
in the toplevel widget, e.g.
	gtk_object_set_data(GTK_OBJECT(mywindow),"total-btn",total_button);
and then, when ptr is needed, extract it like this:
	GtkWidget* total_button =
GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(mywindow),"total-btn"));

in order to save typing, I always use the following macros:
GOSD(obj,name,data) gtk_object_set_data(GTK_OBJECT(obj),name,(gpointer)data)
GOGD(obj,name) gtk_object_get_data(GTK_OBJECT(obj),name)
GOSI(obj,name,val) GOSD(obj,name,GINT_TO_POINTER(val))
GOGI(obj,name) GPOINTER_TO_INT(GOGD(obj,name))
GOGW(obj,name) (GtkWidget*)(GOGD(obj,name))

  
> 
> 
> Thanks loads,
> 
> Leeman 
> alaric@portone.com
> 
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-list
> 

 Best regards,
  -Vlad






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