← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2456: Use deferwindowpos here and there

 

------------------------------------------------------------
revno: 2456
committer: Jacek Sieka <arnetheduck@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Tue 2011-03-15 23:39:48 +0100
message:
  Use deferwindowpos here and there
added:
  dwt/include/dwt/util/HoldResize.h
modified:
  dwt/src/widgets/Grid.cpp
  dwt/src/widgets/SplitterContainer.cpp
  win32/HubFrame.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
=== added file 'dwt/include/dwt/util/HoldResize.h'
--- dwt/include/dwt/util/HoldResize.h	1970-01-01 00:00:00 +0000
+++ dwt/include/dwt/util/HoldResize.h	2011-03-15 22:39:48 +0000
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2001-2011 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef DWT_HOLDRESIZE_H_
+#define DWT_HOLDRESIZE_H_
+
+#include <vector>
+
+#include "../Widget.h"
+#include "../Rectangle.h"
+
+namespace dwt { namespace util {
+
+class HoldResize {
+public:
+	HoldResize(Widget *parent, size_t hint) : parent(parent) { sizes.reserve(hint); }
+
+	~HoldResize() {
+		if(sizes.empty()) {
+			return;
+		}
+
+		if(!resizeDefered()) {
+			resizeNormal();
+		}
+	}
+
+	void resize(Widget *child, const Rectangle &r) {
+		WINDOWPOS pos = { child->handle(), NULL, r.left(), r.top(), r.width(), r.height() };
+		sizes.push_back(pos);
+	}
+
+private:
+
+	Widget *parent;
+	std::vector<WINDOWPOS> sizes;
+
+	bool resizeDefered() {
+		auto h = ::BeginDeferWindowPos(sizes.size());
+		for(auto i = sizes.begin(); i != sizes.end(); ++i) {
+			h = ::DeferWindowPos(h, i->hwnd, NULL, i->x, i->y, i->cx, i->cy, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
+			if(h == NULL) {
+				return false;
+			}
+		}
+
+		if(!::EndDeferWindowPos(h)) {
+			return false;
+		}
+
+		return true;
+	}
+
+	void resizeNormal() {
+		for(auto i = sizes.begin(); i != sizes.end(); ++i) {
+			::SetWindowPos(i->hwnd, NULL, i->x, i->y, i->cx, i->cy, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
+		}
+	}
+};
+} }
+
+#endif /* DWT_HOLDRESIZE_H_ */

=== modified file 'dwt/src/widgets/Grid.cpp'
--- dwt/src/widgets/Grid.cpp	2011-03-15 19:52:17 +0000
+++ dwt/src/widgets/Grid.cpp	2011-03-15 22:39:48 +0000
@@ -31,6 +31,9 @@
 
 #include <dwt/widgets/Grid.h>
 #include <dwt/util/check.h>
+#include <dwt/util/HoldResize.h>
+
+#include <boost/range/distance.hpp>
 
 #include <algorithm>
 #include <numeric>
@@ -167,6 +170,7 @@
 	std::vector<size_t> rowSize = calcSizes(rows, columns, size.y, true);
 	std::vector<size_t> colSize = calcSizes(columns, rows, size.x, false);
 
+	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)
@@ -215,7 +219,7 @@
 		case GridInfo::STRETCH: break; // Do nothing
 		}
 
-		::MoveWindow(wi->w->handle(), x, y, w, h, TRUE);
+		hr.resize(wi->w, Rectangle(x, y, w, h));
 	}
 }
 

=== modified file 'dwt/src/widgets/SplitterContainer.cpp'
--- dwt/src/widgets/SplitterContainer.cpp	2011-03-15 19:52:17 +0000
+++ dwt/src/widgets/SplitterContainer.cpp	2011-03-15 22:39:48 +0000
@@ -31,8 +31,10 @@
 
 #include <dwt/widgets/SplitterContainer.h>
 #include <dwt/widgets/Splitter.h>
+#include <dwt/util/HoldResize.h>
 
 #include <boost/next_prior.hpp>
+#include <boost/range/distance.hpp>
 #include <boost/range/algorithm/for_each.hpp>
 
 namespace dwt {
@@ -101,6 +103,7 @@
 
 	auto splitter_iter = splitters.first;
 
+	util::HoldResize hr(this, boost::distance(children));
 	for_each(children, [&](Widget *w) {
 		if(isSplitter(w)) {
 			return;
@@ -109,17 +112,17 @@
 		if(splitter_iter == splitters.second) {
 			// Last splitter, the next control gets any remaining space
 			sz = std::max(avail - p, 0l);
-			::MoveWindow(w->handle(), rc.left(), rc.top(), rc.width(), rc.height(), TRUE);
+			hr.resize(w, rc);
 		} else {
 			auto splitter = *splitter_iter;
 			auto ss = horizontal ? splitter->getPreferredSize().y : splitter->getPreferredSize().x;
 			sz = std::max(static_cast<int>(avail * splitter->getRelativePos() - ss / 2. - p), 0);
-			::MoveWindow(w->handle(), rc.left(), rc.top(), rc.width(), rc.height(), TRUE);
+			hr.resize(w, rc);
 
 			p += sz;
 
 			sz = ss;
-			::MoveWindow(splitter->handle(), rc.left(), rc.top(), rc.width(), rc.height(), TRUE);
+			hr.resize(splitter, rc);
 			p += sz;
 			splitter_iter++;
 		}

=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2011-03-15 21:16:24 +0000
+++ win32/HubFrame.cpp	2011-03-15 22:39:48 +0000
@@ -36,6 +36,7 @@
 #include <dcpp/version.h>
 #include <dcpp/WindowInfo.h>
 
+#include <dwt/util/HoldResize.h>
 #include <dwt/widgets/SplitterContainer.h>
 
 const string HubFrame::id = WindowManager::hub();
@@ -188,11 +189,11 @@
 		filterType->onSelectionChanged([this] { updateUserList(); });
 	}
 
+	initStatus();
 	showUsers = addChild(WinUtil::Seeds::splitCheckBox);
 	showUsers->setHelpId(IDH_HUB_SHOW_USERS);
 	showUsers->setChecked(BOOLSETTING(GET_USER_INFO));
 
-	initStatus();
 	status->setSize(STATUS_SHOW_USERS, showUsers->getPreferredSize().x);
 	status->onDblClicked(STATUS_STATUS, std::bind(&HubFrame::openLog, this, false));
 
@@ -265,9 +266,10 @@
 	r.size.y -= status->refresh();
 	status->mapWidget(STATUS_SHOW_USERS, showUsers);
 
+	dwt::util::HoldResize hr(this, 2);
 	int ymessage = message->getTextSize(_T("A")).y * messageLines + 10;
 	dwt::Rectangle rm(0, r.size.y - ymessage, r.width(), ymessage);
-	message->resize(rm);
+	hr.resize(message, rm);
 
 	r.size.y -= rm.size.y + border;
 
@@ -279,7 +281,7 @@
 		paned->setSecond(0);
 	}
 	*/
-	paned->resize(r);
+	hr.resize(paned, r);
 }
 
 void HubFrame::updateStatus() {