Re: Sample simple container.



On Fri, 2007-03-30 at 22:01 -0300, Alexandre Moreira wrote:
> On 3/30/07, Murray Cumming <murrayc murrayc com> wrote:
> > On Fri, 2007-03-30 at 16:45 -0300, Alexandre Moreira wrote:
> > > I would like to have a way to create composite widgets without
> > > exposing the base Container  methods (Let's say I used a box... it
> > > would have the box's methods and all the GtkContainer methods... and I
> > > wouldn't like client code to call gtk_container_add on a widget that
> > > is not supposed to "mean" a container)
> > >
> > > So, I would like to create an as-simple-as-it-gets container that
> > > descended only from GtkWidget  so that it wouldn't really have methods
> > > to act like a container (Its only child widget would be set as a
> > > constructor parameter and overrided by its descendants).
> >
> > I can offer a simpe custom container in gtkmm:
> > http://svn.gnome.org/viewcvs/gtkmm/trunk/examples/book/custom/custom_container/
> >
> > It derives from Gtk::Container, but I'd expect any container to do that.
> 
> Thanks Murray, I'll give this one a better look.
> 
> It just stroke me that I don't need a "container" in the GtkContainer
> sense of the word, only a widget that is capable of delegating every
> event handler it has to a single child. Like size allocate, expose,
> etc...
> 
> Can anyone help me with the methods I'd have to override to pass
> events on to this child widget ?
> 

You are better off deriving from a GtkContainer subclass, and letting
the GtkContainer do all that stuff for you (container will do things
like propagate expose events to child widgets that dont have thier
own GdkWindow and other things that you dont want to bother
understanding)

Also, there is no need to look for a sample custom container outside
of gtk+, gtk+ is already full of container implementations, take
GtkFrame for example - GtkFrame allows the user to add one child
(it is a GtkBin iirc), and it also has a tab label widget.

If all you need is to police the api so that people dont screw with
your composite widget, you could just override the add()/remove() 
vfuncs and print a warning in them instead of performing and add/remove.

Cheers,
                -Tristan





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