Re: gtk_type_foreach?

//On Mon, 21 Sep 1998, Johannes Keukelaar wrote:
//> //On 15 Sep 1998, Marius Vollmer wrote:
//> //
//> //> (Johannes Keukelaar) writes:
//> //> 
//> //> > Is there any reason why there is no gtk_type_foreach function?
//> //> 
//> //> Hmm.  I'm not saying that such a function wouldn't be useful, but you
//> //> must be aware that most types are dynamically added to the type
//> //> system.  You will only find GtkFileSelection in the type list after at
//> //> least one GtkFileSelection widget has been created.  (Types are never
//> //> removed from the system, tho.)
//> //
//> //I could probably find a use for this sort of thing too, but, exactly as
//> //Tim Janik describes, it is better implemented with a "hook" function that
//> //allows the programmer to get notified when new types are created. 
//> That _could_ be enough. But you'd have to define the hook such that, 
//> at the time of installation, it will be called for each of the types 
//> then registered. (But then, your hook might depend on that it gets 
//> called for more basic types before it gets called for their derived 
//> types. Interesting problem.)
//the call sequence for the class_foreach function will asure that the hook
//will get called for base classes first.
//note however that i'm talking class_foreach here, not type_forech, i.e.
//the hook gets invoked when the class is created not the type itself,
//and it is the actuall class pointer that is passed to the hook, not the
//type id itself (that can be retrived through the class of course).
//this will most times be shortly after the type got created but need not
//to be so. there is actually not much point in having a hook for pure
//type registrations at least i can't come up with somthing, and there
//wouldn't be much to pass to that function (other than the plain type id ;).

class_foreach? So not the new_class_hook? You've got me confused. :)

Yes, I see how new_class_hook (or whatever it's called) will get called in the 
right order (base classes first); base classes will obviously have to be 
created before their derived classes can be created.

For class_foreach, however, you would have to do more than just foreach over 
some hash table, I would think. That is, if you want to insure the proper 
calling order.

What I was thinking about above, though, was the following.

As some people pointed out, a new_class_hook is superior to a class_foreach 
construction in some ways. So it might be nice if we could get away with only 
using (and possibly even only implementing) new_class_hook. However, by the 
time you get around to installing your new_class_hook, some classes may already 
have been registered. If you want to make not using class_foreach feasible, 
you'll have to make sure that new_class_hook gets called at that time for those 
already existing classes, as well. And you'd have to do that in the proper 
order. Which is basically the same problem as for class_foreach.

As for why I need all this stuff, and why I was thinking in terms of GtkType 
instead of GtkObjectClass... I have a family of object classes that are derived 
from a common ancestor, GrNode, a child of GtkObject. I want to make this 
family extensible without requiring recompilation, so creating them with 
gr_some_kind_of_node_new( ) seems harder than using gr_node_new( 
"some-kind-of-node" ). To make this work, we can install all the types 
dynamically, by searching in the appropriate places, opening some dynamic 
library, calling the appropriate gr_some_kind_of_node_type( ) function (from a 
standard function in such a library, for example), and then use 
gtk_type_by_name to get the type in gr_node_new. What I would also like to do 
is create a menu that contains an item for each of the appropriate derived 

Since I have no idea when classes get created, and I can get all the 
information about a type from the GtkType (i.e. the name), I thought along 
lines of iterating over types.

When do classes get created? As soon as the type gets registered? Or only when 
an object gets made?

"Thank God I'm still an atheist!" -- Salvador Dali

<insert funny description here>

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