Tab Controls


A TabControl can have a number of TabItems which each exclusively open up their own set of controls in the display area of the TabControl. TabItems are created as children of the TabControl. The text of TabItems is set at its' creation but can be accessed anytime using getText() & setText(). TabControls can be created with a number of different options. Please see the API documentation for more information.

One option that I thought was quite useful is TCS_RIGHTJUSTIFY where the TabItems are spaced so that they cover the entire width of the TabControl. The problem with this specification is that you also have to have TCS_MULTILINE as well. I have found that unless the quantity of TabItems is enough to exceed one full row then the desirable right-justification does not manifest itself.

Controls of any sort may be placed on a TabItem by creating them with the TabItem as the parent. ARWEN has to reparent this to be the TabControl since the TabControl is the only real control and TabItems are really attributes of it; not real controls in their own right. The x,y coordinates of any controls created in this way are relative to the TabControl's display area - as you can imagine. Please beware that the coordinates of controls on a TabItem are set at it's creation and if more than one row of tabItems is created then there may be undesirable clipping of the controls occuring. The solution is to decide to have a single row of tabs OR ensure that the uppermost coordinate of the controls will allow it to be unaffected should the number of rows of tabs increase.

When a TabItem is clicked then a WM_NOTIFY message is sent to the outgoing and incoming TabItems. The notification code will be in the wParam member and is TCN_SELCHANGING for the outgoing TabItem and TCN_SELCHANGE for the incoming TabItem. If the handler traps TCN_SELCHANGING it can return 1 to prevent the tab selection from changing. This behaviour may be useful where, say, an edit field has not been completed by the user and must be corrected before continuing. The id of the currently selected TabItem can be obtained by calling getIndex() and passing the id of the TabControl.

A TabItem may be opened/activated/selected by invoking setFocus(). I had imagined that I should be using a complementary pair such as getIndex/setIndex OR getFocus/setFocus but only the titles are intuitive not the expected behaviour. Would someone like to offer any suggestions on this?

The TabControl owner of the TabItems can be hidden or shown using setVisible(). If a TabControl is created but no TabItems are put in it then it will not show on the screen. However, do not use setVisible() to modify the appearance state of a TabItem as the program will crash. Also, I have not made any allowance for inserting a TabControl within a TabItem, although this seems an unlikely possibility anyway. TabItems can now be disabled (using setVisible()) even though the API does not properly allow for it. ARWEN emulates disabled behaviour for TabItems by trapping the TCN_SELCHANGING msg and then actually drawing the disabled text. To be able to draw text on a TabItem means that the TabControl must be owner-drawn and so I have decided to permanently set the TCS_OWNERDRAWFIXED flag at the creation of the Tab Control..