Re: [gtk-list] Re: Okay, newbie here
- From: Havoc Pennington <rhpennin midway uchicago edu>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Okay, newbie here
- Date: Sat, 21 Nov 1998 23:23:32 -0600 (CST)
On Sat, 21 Nov 1998, Christopher Wiegand wrote:
>
> So I need to store a pointer to my widgets in a linked list like thing? I've
> got the program to show things, but I need a way to reference those widgets
> after I've created them, in a whole 'nother function. I think I'm going to
> have to do a "widget collection" list or something. I was just hoping there
> was some builtin way of doing it, because the only other way I could think of
> is global variables, which are annoying...
>
Looks to me like this is more of a C question than a Gtk question - for
any program you need to know how to keep track of your objects. :-) The
answer is always, "it depends on what you want to do."
A linked list of widgets is useless - how do you know the type of each
widget? You might want a linked list of toplevel windows or something, but
not of all widgets. And global variables are mostly evil, albeit OK in
moderation.
Mostly you don't need to keep pointers for memory management; container
widgets will delete their children. You do need to be sure you
gtk_widget_destroy all toplevel widgets (usually windows).
Otherwise you only need to keep pointers to widgets you want to
manipulate. The nicest way is to copy the glib/gtk style: use C structs in
combination with "methods" to write OO code in C. Create struct _Foo with
pointers and other data you want to use, typedef to Foo, write a
constructor (Foo* foo_new()) and destructor (foo_destroy(Foo* f)), write
methods (foo_do_foo_thing(Foo* f)), etc. Discipline yourself to only
access the struct via the methods. (Alternatively, bail and use C++.)
There are thousands of lines of sample code on the CVS server; the only
way to learn is to read a few thousand of those, preferably with intent
to modify.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]