I just thought I'd post how I intended to implement a tab control widget, so you can tell me if I'm going wrong. Bear in mind I'm not trying to create a multi-line tablist, nor am I adding tab scrolling, although both could be added later. I'm hitting a few issues I think because I want to allow people to define the content of the tab panes in XML using the standard child window idiom; however internally it makes more sense for the children to be children of the TabPane (a child of the TabControl) for clipping purposes. Anyway, here's what I think right now:
TabControl is the main class and is derived from Window, this is basically just a parent for the classes that do the real work. It contains within it a number of TabButton (derived from BuutonBase) instances, one for each tab, and a single TabPane instance (derived from Static), the clipping content area of the pane. It stores the currently active tab (as an index), which also maps to the corresponding index of the child of the TabPane.
What I want to do is this: when you add a child window to the TabControl, it actually becomes a child of the internal TabPane (so it becomes a grandchild). Only one child of TabPane will be visible at once. However, in order to delegate the adding / removing of children to the TabPane child, I would need to override addChildWindow, which is unfortunately non-virtual on Window. I only have access to onChildAdded, which is not enough to veto the direct add AFAIK.
The reason I want to do it this way is that it makes it simple in XML. You can write:
Code: Select all
<Window Type="Taharez Tab Control" Name="MyTab">
<Window Type="Taharez StaticText" Name="YouTextyThing">
<Property Name="Text" Value="Some Text"/>
...
And what you get is your StaticText object placed automatically in the 'content' area of the control, since it's actually a child of the TabPane. Otherwise, you'd have to define both the TabPane and the TabButtons in the XML which makes it harder and more error prone.
I suppose instead of overriding addChildWindow I could just keep everything as a child of TabControl, and manually shunt other children down into the tab pane area, but this feels wrong to me.
So, can I make addChildWindow (and removeChildWindow) virtual? Obviously when I'm adding the TabButton and TabPane instances as children I'll have to use a method which does not trigger a new tab. Will I also have to do something with getActiveChild(), or is this ok since the active child will be the TabPane, which itself will contain the content areas?
Thanks