Re: Custom container + Child type with interface



Okay, that's got that bit sorted, thanks.

Next question - The interface I have defined basically just mandates a
few properties. The container that requires children to implement this
interface only ever reads these properties.

Some implementers of the interface will determine the value of the
interface properties based on various bits of internal state
information. Other implementers will be passed the property values via
their constructors.

So as far as the container and some implementers are concerned, the
interface properties only need to be G_PARAM_READABLE. In other cases,
the properties might need to be (G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY).

I assume that the interface definition has to go with the lowest common
denominator, which I think is G_PARAM_READWRITE. In that case, what
should implementers do where the properties are not settable (because
they are derived from other state information)?

Should I just omit setters for those implementers and use
G_OBJECT_WARN_INVALID_PROPERTY_ID() if something tries to set the
relevant properties?

Matt.

On Sun, 2009-12-20 at 16:14 +0100, David Nečas wrote:
> On Sun, Dec 20, 2009 at 01:57:06PM +0000, Matthew Bucknall wrote:
> > I'm implementing a custom container widget which needs to only accept
> > child widgets which derive from GtkWidget (obviously) but also implement
> > a custom Interface called GpanesPanel.
> > 
> > I'm not sure how to enforce this rule within my code's API. What type
> > should the container's child_type() method return? GPANES_TYPE_PANEL or
> > GTK_TYPE_WIDGET? Likewise, I'm not sure what type custom insertion
> > methods for my container should accept, GpanesPanel or GtkWidget?
> > 
> > It doesn't seem enough to use GPANES_TYPE_PANEL/GpanesPanel because, as
> > it stands, any non-widget class could implement the GpanesPanel
> > interface but would be unusable as a container child.
> 
> Returing GPANES_TYPE_PANEL would be probably better as it can be ensured
> that the thing is also a widget (see below).
> 
> Note that GtkContainer methods do not use child_type at preset,
> gtk_container_add() simply checks that the child is a GtkWidget, leaving
> specific checks for add() implementation in subclasses.  This might be
> an implementation detail though...
> 
> > Is there anything I can put in the GpanesPanel interface definition that
> > states that it can only be applied to classes derived from GtkWidget?
> 
> Yes, g_type_interface_add_prerequisite() can do that.
> 
> Yeti
> 




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