Added TabWidget::removeTab method; and updated some comments in TabWidget.h

svn-id: r27168
This commit is contained in:
Max Horn 2007-06-07 15:14:58 +00:00
parent 7e29cf35de
commit 0bebe25e0f
2 changed files with 48 additions and 9 deletions

View File

@ -114,6 +114,38 @@ int TabWidget::addTab(const String &title) {
return _activeTab;
}
void TabWidget::removeTab(int tabID) {
assert(0 <= tabID && tabID < (int)_tabs.size());
// Deactive the tab if it's currently the active one
if (tabID == _activeTab) {
_tabs[tabID].firstWidget = _firstWidget;
releaseFocus();
_firstWidget = 0;
}
// Dispose the widgets in that tab and then the tab itself
delete _tabs[tabID].firstWidget;
_tabs.remove_at(tabID);
// Adjust _firstVisibleTab if necessary
if (_firstVisibleTab >= (int)_tabs.size()) {
_firstVisibleTab = MAX(0, (int)_tabs.size() - 1);
}
// The active tab was removed, so select a new active one (if any remains)
if (tabID == _activeTab) {
_activeTab = -1;
if (tabID >= (int)_tabs.size())
tabID = _tabs.size() - 1;
if (tabID >= 0)
setActiveTab(tabID);
}
// Finally trigger a redraw
_boss->draw();
}
void TabWidget::setActiveTab(int tabID) {
assert(0 <= tabID && tabID < (int)_tabs.size());
if (_activeTab != tabID) {

View File

@ -62,18 +62,21 @@ public:
void init();
virtual int16 getChildY() const;
// Problem: how to add items to a tab?
// First off, widget should allow non-dialog bosses, (i.e. also other widgets)
// Could add a common base class for Widgets and Dialogs.
// Then you add tabs using the following method, which returns a unique ID
/**
* Add a new tab with the given title. Returns a unique ID which can be used
* to identify the tab (to remove it / activate it etc.).
*/
int addTab(const String &title);
// Maybe we need to remove tabs again? Hm
//void removeTab(int tabID);
/**
* Remove the tab with the given tab ID. Disposes all child widgets of that tab.
* TODO: This code is *unfinished*. In particular, it changes the
* tabIDs, so that they are not unique anymore! This is bad.
*/
void removeTab(int tabID);
/** Set the active tab by specifying a valid tab ID.
/**
* Set the active tab by specifying a valid tab ID.
* setActiveTab changes the value of _firstWidget. This means new
* Widgets are always added to the active tab.
*/
@ -88,6 +91,10 @@ public:
virtual void draw();
protected:
// We overload getChildY to make sure child widgets are positioned correctly.
// Essentially this compensates for the space taken up by the tab title header.
virtual int16 getChildY() const;
virtual void drawWidget(bool hilite);
virtual Widget *findWidget(int x, int y);