← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2691: better removal of grid rows/columns

 

------------------------------------------------------------
revno: 2691
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2011-11-30 20:58:51 +0100
message:
  better removal of grid rows/columns
modified:
  dwt/include/dwt/widgets/Grid.h
  dwt/src/widgets/Grid.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dwt/include/dwt/widgets/Grid.h'
--- dwt/include/dwt/widgets/Grid.h	2011-03-15 19:52:17 +0000
+++ dwt/include/dwt/widgets/Grid.h	2011-11-30 19:58:51 +0000
@@ -88,17 +88,23 @@
 	};
 
 	virtual void layout();
-	void addRow(const GridInfo& gp) { rows.push_back(gp); }
-	void addColumn(const GridInfo& gp) { columns.push_back(gp); }
-
-	void removeRow(size_t i) { rows.erase(rows.begin() + i); }
-	void removeColumn(size_t i) { columns.erase(columns.begin() + i); }
-
-	void clearRows() { rows.clear(); }
-	void clearColumns() { columns.clear(); }
-
-	void setWidget(Widget* w, size_t row, size_t column, size_t rowSpan = 1, size_t colSpan = 1);
-	void setWidget(Widget* w);
+
+	size_t addRow(const GridInfo& gp);
+	size_t addColumn(const GridInfo& gp);
+
+	/// Remove the row that contains the specified widget.
+	void removeRow(Control* w);
+	/// Remove the row that contains the specified widget.
+	void removeColumn(Control* w);
+
+	void removeRow(size_t row);
+	void removeColumn(size_t column);
+
+	void clearRows();
+	void clearColumns();
+
+	void setWidget(Control* w, size_t row, size_t column, size_t rowSpan = 1, size_t colSpan = 1);
+	void setWidget(Control* w);
 
 	size_t getSpacing() const { return spacing; }
 	void setSpacing(size_t spacing_) { spacing = spacing_; }
@@ -124,12 +130,12 @@
 private:
 
 	struct WidgetInfo {
-		WidgetInfo(Widget* w_, size_t row_, size_t column_, size_t rowSpan_, size_t colSpan_) :
+		WidgetInfo(Control* w_, size_t row_, size_t column_, size_t rowSpan_, size_t colSpan_) :
 			w(w_), row(row_), column(column_), rowSpan(rowSpan_), colSpan(colSpan_), noResize(false) { }
-		WidgetInfo(Widget* w_) :
+		WidgetInfo(Control* w_) :
 			w(w_), noResize(true) { }
 
-		Widget* w;
+		Control* w;
 
 		size_t row;
 		size_t column;
@@ -158,7 +164,7 @@
 
 	Point actualSpacing() const;
 
-	WidgetInfo* getWidgetInfo(HWND hwnd);
+	WidgetInfo* getWidgetInfo(Control* w);
 
 	void handleEnabled(bool enabled);
 };

=== modified file 'dwt/src/widgets/Grid.cpp'
--- dwt/src/widgets/Grid.cpp	2011-04-24 19:53:20 +0000
+++ dwt/src/widgets/Grid.cpp	2011-11-30 19:58:51 +0000
@@ -66,8 +66,8 @@
 
 Point Grid::getPreferredSize() {
 	// Make sure we have WidgetInfo's for every child...
-	auto children = getChildren<Widget>();
-	std::for_each(children.first, children.second, [=](Widget* w) { getWidgetInfo(w->handle()); });
+	auto children = getChildren<Control>();
+	std::for_each(children.first, children.second, [this](Control* w) { getWidgetInfo(w); });
 
 	std::vector<size_t> rowSize = calcSizes(rows, columns, 0, true);
 	std::vector<size_t> colSize = calcSizes(columns, rows, 0, false);
@@ -160,10 +160,10 @@
 
 void Grid::layout() {
 	auto size = getClientSize();
-	auto children = getChildren<Widget>();
+	auto children = getChildren<Control>();
 
 	// Make sure we have WidgetInfo's for every child...
-	std::for_each(children.first, children.second, [=](Widget* w) { getWidgetInfo(w->handle()); });
+	std::for_each(children.first, children.second, [this](Control* w) { getWidgetInfo(w); });
 
 	Point as = actualSpacing();
 
@@ -175,11 +175,8 @@
 
 	util::HoldResize hr(this, boost::distance(children));
 	for(auto i = children.first; i != children.second; ++i) {
-		WidgetInfo* wi = getWidgetInfo((*i)->handle());
-		if(!wi || !wi->w)
-			continue;
-
-		if(wi->noResize) {
+		WidgetInfo* wi = getWidgetInfo(*i);
+		if(!wi || wi->noResize) {
 			continue;
 		}
 
@@ -225,9 +222,9 @@
 	}
 }
 
-Grid::WidgetInfo* Grid::getWidgetInfo(HWND hwnd) {
+Grid::WidgetInfo* Grid::getWidgetInfo(Control* w) {
 	for(WidgetInfoList::iterator i = widgetInfo.begin(); i != widgetInfo.end(); ++i) {
-		if(i->w->handle() == hwnd) {
+		if(i->w == w) {
 			return &(*i);
 		}
 	}
@@ -255,17 +252,88 @@
 		return 0;
 	}
 
-	Widget* w = hwnd_cast<Widget*>(hwnd);
-	if(!w) {
-		return 0;
-	}
-
 	widgetInfo.push_back(WidgetInfo(w, r, c, 1, 1));
 	return &widgetInfo.back();
 }
 
-void Grid::setWidget(Widget* w, size_t row, size_t column, size_t rowSpan, size_t colSpan) {
-	dwtassert(w->getParent() == this, _T("Widget must be a child of the grid"));
+size_t Grid::addRow(const GridInfo& gp) {
+	rows.push_back(gp);
+	return rows.size() - 1;
+}
+
+size_t Grid::addColumn(const GridInfo& gp) {
+	columns.push_back(gp);
+	return columns.size() - 1;
+}
+
+void Grid::removeRow(Control* w) {
+	for(auto i = widgetInfo.cbegin(), iend = widgetInfo.cend(); i != iend; ++i) {
+		if(i->w == w) {
+			removeRow(i->row);
+			break;
+		}
+	}
+}
+
+void Grid::removeColumn(Control* w) {
+	for(auto i = widgetInfo.cbegin(), iend = widgetInfo.cend(); i != iend; ++i) {
+		if(i->w == w) {
+			removeColumn(i->column);
+			break;
+		}
+	}
+}
+
+void Grid::removeRow(size_t row) {
+	rows.erase(rows.begin() + row);
+
+	for(auto i = widgetInfo.begin(); i != widgetInfo.end();) {
+
+		if(i->row == row) {
+			auto w = i->w;
+			i = widgetInfo.erase(i);
+			w->close();
+
+		} else {
+			if(i->row > row) {
+				--i->row;
+			}
+
+			++i;
+		}
+	}
+}
+
+void Grid::removeColumn(size_t column) {
+	columns.erase(columns.begin() + column);
+
+	for(auto i = widgetInfo.begin(); i != widgetInfo.end();) {
+
+		if(i->column == column) {
+			auto w = i->w;
+			i = widgetInfo.erase(i);
+			w->close();
+
+		} else {
+			if(i->column > column) {
+				--i->column;
+			}
+
+			++i;
+		}
+	}
+}
+
+void Grid::clearRows() {
+	rows.clear();
+}
+
+void Grid::clearColumns() {
+	columns.clear();
+}
+
+void Grid::setWidget(Control* w, size_t row, size_t column, size_t rowSpan, size_t colSpan) {
+	dwtassert(w->getParent() == this, _T("Control must be a child of the grid"));
 
 	for(WidgetInfoList::iterator i = widgetInfo.begin(), iend = widgetInfo.end(); i != iend; ++i) {
 		if(i->w == w) {
@@ -280,7 +348,7 @@
 	widgetInfo.push_back(WidgetInfo(w, row, column, rowSpan, colSpan));
 }
 
-void Grid::setWidget(Widget* w) {
+void Grid::setWidget(Control* w) {
 	for(WidgetInfoList::iterator i = widgetInfo.begin(), iend = widgetInfo.end(); i != iend; ++i) {
 		if(i->w == w) {
 			i->noResize = true;