Re: Properties on interfaces



On Thu, 2003-02-13 at 19:36, Matthias Clasen wrote:
> On Fri, 2003-02-14 at 00:25, Owen Taylor wrote:
> > Fooling around with this a little more, two fairly obvious
> > issues came up:
> > 
> >  * What get_property/set_property methods get called? 
> >    Maybe the ones for the type for which add_interface() is called?
> >    But that doesn't allow overriding the implementation in
> >    derived classes, and also doesn't    
> 
> There is no other set_property method, or is there ? the interface
> doesn't provide any implementations, only interfaces.

Remember, get_property/set_property aren't called like normal
virtual functions. One might think that it works like:

 "Most derived set_property is called. If it doesn't handle
  the property, then it chains to the parent, which checks
  if it handles it.

But instead, the way it works is that the get_property() 
for the class where the property is installed is called
directly, with a class-specific property ID.

Calling the set_property() for the most-derived class isn't
going to work, since then inheriting from a class breaks
its interface-derived properties.

So, we need some way to say "class X's set_property() handles 
setting the properties for interface Y".

A completely different way of doing it would be to have 
separate get_property()/set_property() functions for each
interface ... that is have something like:

 g_object_interface_set_property_functions (GTypeInterface g_iface,
                                            get_function, set_function);

Though you'd still need the strcmp() chain. (See below.)

> >  * What to do about property IDs, since they are different
> >    for each class that has a given interface?
> 
> Is this a problem ? g_object_set_property looks up the paramspecs by
> name anyway. That is also how overriding paramspecs in derived classes
> works: use the same name.

The question here is not in the lookup, but rather in the
implementation of set_property(). set_property() implementations
generally switch over the property ID, but if you don't
have a property ID for interface properties, then you have
to do a strcmp() chain over the name.

> > What I was thinking about to solve these problems is something
> > like:
> > 
> >  g_object_class_install_interface_property (file_chooser_dialog_class, 
> >                                             PROP_FILENAME,
> >                                             "filename",
> >                                             GTK_TYPE_FILE_CHOOSER);
> > 
> > Which says to forward PROP_FILENAME/filename to the "filename" property
> > of the GtkFileChooser interface.
> 
> What does "forwarding" mean here, considering that the
> get_property/set_property implementation is in the dialog_class anyway ?
> If it only means to reuse the paramspec from the interface property,
> couldn't you achieve the same effect by
> 
> g_object_class_install_property (file_chooser_dialog_class,
>                                  PROP_FILENAME,
>                                  g_param_spec_pool_lookup (pspec_pool,
>                                               "filename",
>                                               GTK_TYPE_FILE_CHOOSER));

Doesn't work. A paramspec can't be installed for multiple classes.

Regards,
                                          Owen





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