[Scummvm-cvs-logs] SF.net SVN: scummvm: [27168] scummvm/trunk/gui

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jun 7 17:14:59 CEST 2007


Revision: 27168
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27168&view=rev
Author:   fingolfin
Date:     2007-06-07 08:14:58 -0700 (Thu, 07 Jun 2007)

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

Modified Paths:
--------------
    scummvm/trunk/gui/TabWidget.cpp
    scummvm/trunk/gui/TabWidget.h

Modified: scummvm/trunk/gui/TabWidget.cpp
===================================================================
--- scummvm/trunk/gui/TabWidget.cpp	2007-06-07 12:39:38 UTC (rev 27167)
+++ scummvm/trunk/gui/TabWidget.cpp	2007-06-07 15:14:58 UTC (rev 27168)
@@ -114,6 +114,38 @@
 	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) {

Modified: scummvm/trunk/gui/TabWidget.h
===================================================================
--- scummvm/trunk/gui/TabWidget.h	2007-06-07 12:39:38 UTC (rev 27167)
+++ scummvm/trunk/gui/TabWidget.h	2007-06-07 15:14:58 UTC (rev 27168)
@@ -62,18 +62,21 @@
 
 	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 @@
 	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);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list