← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2511: fix spinners

 

------------------------------------------------------------
revno: 2511
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2011-04-24 21:53:20 +0200
message:
  fix spinners
modified:
  dwt/include/dwt/aspects/AspectEnabled.h
  dwt/include/dwt/widgets/Spinner.h
  dwt/include/dwt/widgets/StatusBar.h
  dwt/src/widgets/Grid.cpp
  dwt/src/widgets/Spinner.cpp
  dwt/src/widgets/StatusBar.cpp
  win32/HistoryPage.cpp
  win32/MainWindow.cpp
  win32/PropPage.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/aspects/AspectEnabled.h'
--- dwt/include/dwt/aspects/AspectEnabled.h	2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/aspects/AspectEnabled.h	2011-04-24 19:53:20 +0000
@@ -58,8 +58,8 @@
 
 	static bool isEnabled(const MSG& msg) { return msg.wParam > 0; }
 
-	typedef Dispatchers::ConvertBase<bool, &AspectEnabled<WidgetType>::isEnabled> EnabledDispatcher;
-	friend class Dispatchers::ConvertBase<bool, &AspectEnabled<WidgetType>::isEnabled>;
+	typedef Dispatchers::ConvertBase<bool, &AspectEnabled<WidgetType>::isEnabled, 0, false> EnabledDispatcher;
+	friend class Dispatchers::ConvertBase<bool, &AspectEnabled<WidgetType>::isEnabled, 0, false>;
 
 public:
 

=== modified file 'dwt/include/dwt/widgets/Spinner.h'
--- dwt/include/dwt/widgets/Spinner.h	2011-03-15 19:52:17 +0000
+++ dwt/include/dwt/widgets/Spinner.h	2011-04-24 19:53:20 +0000
@@ -90,10 +90,10 @@
 		int minValue;
 		int maxValue;
 
-		Widget* buddy;
+		Control* buddy;
 
 		/// Fills with default parameters
-		Seed(int minValue_ = UD_MINVAL, int maxValue_ = UD_MAXVAL, Widget* buddy_ = 0);
+		Seed(int minValue_ = UD_MINVAL, int maxValue_ = UD_MAXVAL, Control* buddy_ = 0);
 	};
 
 	/// Sets the range of the Spinner
@@ -111,9 +111,9 @@
 	  * And if you change the value of the buddy control the Spinner Control will
 	  * automatically also change its value.
 	  */
-	void assignBuddy(Widget* buddy);
+	void assignBuddy(Control* buddy);
 
-	Widget* getBuddy() const;
+	Control* getBuddy() const;
 
 	/// Returns the value of the control
 	/** The value can be any value between the minimum and maximum range defined in
@@ -136,70 +136,22 @@
 	  */
 	void create(const Seed &cs = Seed());
 
-	virtual void layout();
-
 protected:
 	// Constructor Taking pointer to parent
-	explicit Spinner( Widget * parent );
+	explicit Spinner(Widget* parent);
 
 	// Protected to avoid direct instantiation, you can inherit and use
 	// WidgetFactory class which is friend
 	virtual ~Spinner() { }
+
 private:
 	friend class ChainingDispatcher;
 	static const TCHAR windowClass[];
+
+	void handleSized();
+	void assignBuddy_(Control* buddy);
 };
 
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Implementation of class
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-inline void Spinner::setRange( int minimum, int maximum )
-{
-	sendMessage(UDM_SETRANGE32, static_cast< WPARAM >( minimum ), static_cast< LPARAM >( maximum ));
-}
-
-inline void Spinner::assignBuddy(Widget* buddy) {
-	assert(buddy && buddy->handle() && buddy->getParent() == getParent());
-	sendMessage(UDM_SETBUDDY, reinterpret_cast< WPARAM >( buddy->handle() ));
-}
-
-inline Widget* Spinner::getBuddy() const {
-	return hwnd_cast<Widget*>(reinterpret_cast<HWND>(sendMessage(UDM_GETBUDDY)));
-}
-
-inline int Spinner::getValue()
-{
-#ifdef WINCE
-	LRESULT retVal = sendMessage(UDM_GETPOS);
-	if ( HIWORD( retVal ) != 0 )
-	{
-		dwtWin32DebugFail(" Something went wrong while trying to retrieve value if Spinner");
-	}
-	return LOWORD( retVal );
-#else
-	return sendMessage(UDM_GETPOS32);
-#endif //! WINCE
-}
-
-inline int Spinner::setValue( int v )
-{
-#ifdef WINCE
-	return sendMessage(UDM_SETPOS, 0, v);
-#else
-	return sendMessage(UDM_SETPOS32, 0, v);
-#endif
-}
-
-inline void Spinner::onUpdate(const Dispatcher::F& f) {
-	setCallback(Message(WM_NOTIFY, UDN_DELTAPOS), Dispatcher(f));
-}
-
-inline Spinner::Spinner(dwt::Widget * parent )
-	: BaseType(parent, ChainingDispatcher::superClass<Spinner>())
-{
-}
-
 }
 
 #endif

=== modified file 'dwt/include/dwt/widgets/StatusBar.h'
--- dwt/include/dwt/widgets/StatusBar.h	2011-04-24 15:09:54 +0000
+++ dwt/include/dwt/widgets/StatusBar.h	2011-04-24 19:53:20 +0000
@@ -118,8 +118,15 @@
 	/// Sets the help id of the given part. If not set, the help id of the whole status bar is used instead.
 	void setHelpId(unsigned part, unsigned id);
 
-	/// embed a widget into a part. the widget will be automatically positioned.
-	void setWidget(unsigned part, Control* widget, const Rectangle& padding = Rectangle(0, 0, 0, 0));
+	/** embed a widget into a part. the widget will be automatically positioned.
+	@param padding Rectangle to denote padding space, where:
+	- left pos of the rectangle = left padding.
+	- top pos of the rectangle = top padding.
+	- width of the rectangle = right padding.
+	- height of the rectangle = bottom padding.
+	(these conventions play well with Rectangle constructors, which also function by width/height.)
+	*/
+	void setWidget(unsigned part, Control* widget, const Rectangle& padding = Rectangle());
 
 	void onClicked(unsigned part, const F& f);
 	void onRightClicked(unsigned part, const F& f);

=== modified file 'dwt/src/widgets/Grid.cpp'
--- dwt/src/widgets/Grid.cpp	2011-04-07 14:57:29 +0000
+++ dwt/src/widgets/Grid.cpp	2011-04-24 19:53:20 +0000
@@ -180,7 +180,6 @@
 			continue;
 
 		if(wi->noResize) {
-			wi->w->layout();
 			continue;
 		}
 

=== modified file 'dwt/src/widgets/Spinner.cpp'
--- dwt/src/widgets/Spinner.cpp	2011-03-15 19:52:17 +0000
+++ dwt/src/widgets/Spinner.cpp	2011-04-24 19:53:20 +0000
@@ -31,11 +31,13 @@
 
 #include <dwt/widgets/Spinner.h>
 
+#include <dwt/util/check.h>
+
 namespace dwt {
 
 const TCHAR Spinner::windowClass[] = UPDOWN_CLASS;
 
-Spinner::Seed::Seed(int minValue_, int maxValue_, Widget* buddy_) :
+Spinner::Seed::Seed(int minValue_, int maxValue_, Control* buddy_) :
 BaseType::Seed(WS_CHILD | UDS_ARROWKEYS | UDS_NOTHOUSANDS),
 minValue(minValue_),
 maxValue(maxValue_),
@@ -45,6 +47,11 @@
 		style |= UDS_ALIGNRIGHT | UDS_SETBUDDYINT;
 }
 
+Spinner::Spinner(Widget * parent) :
+BaseType(parent, ChainingDispatcher::superClass<Spinner>())
+{
+}
+
 void Spinner::create(const Seed& cs) {
 	BaseType::create(cs);
 	setRange(cs.minValue, cs.maxValue);
@@ -52,10 +59,46 @@
 		assignBuddy(cs.buddy);
 }
 
-void Spinner::layout() {
-	Widget* w = getBuddy();
-	if(w)
-		assignBuddy(w);
+void Spinner::setRange(int minimum, int maximum) {
+	sendMessage(UDM_SETRANGE32, static_cast<WPARAM>(minimum), static_cast<LPARAM>(maximum));
+}
+
+void Spinner::assignBuddy(Control* buddy) {
+	dwtassert(buddy && buddy->handle() && buddy->getParent() == getParent(), _T("A spinner and its buddy must have the same parent"));
+	assignBuddy_(buddy);
+	buddy->onSized([this](const SizedEvent&) { handleSized(); });
+}
+
+Control* Spinner::getBuddy() const {
+	return hwnd_cast<Control*>(reinterpret_cast<HWND>(sendMessage(UDM_GETBUDDY)));
+}
+
+int Spinner::getValue() {
+	return sendMessage(UDM_GETPOS32);
+}
+
+int Spinner::setValue(int v) {
+	return sendMessage(UDM_SETPOS32, 0, v);
+}
+
+void Spinner::onUpdate(const Dispatcher::F& f) {
+	setCallback(Message(WM_NOTIFY, UDN_DELTAPOS), Dispatcher(f));
+}
+
+void Spinner::handleSized() {
+	// the widget will be resized to accomodate the spinner - avoid recursion.
+	static bool recursion = false;
+	if(recursion)
+		return;
+	recursion = true;
+
+	assignBuddy_(getBuddy());
+
+	recursion = false;
+}
+
+void Spinner::assignBuddy_(Control* buddy) {
+	sendMessage(UDM_SETBUDDY, reinterpret_cast<WPARAM>(buddy->handle()));
 }
 
 }

=== modified file 'dwt/src/widgets/StatusBar.cpp'
--- dwt/src/widgets/StatusBar.cpp	2011-04-24 15:09:54 +0000
+++ dwt/src/widgets/StatusBar.cpp	2011-04-24 19:53:20 +0000
@@ -195,7 +195,7 @@
 void StatusBar::WidgetPart::layout(POINT* offset) {
 	::SetWindowPos(widget->handle(), HWND_TOP,
 		offset[0].x + padding.left(), offset[0].y + padding.top(),
-		offset[1].x - offset[0].x - padding.right(), offset[1].y - offset[0].y - padding.bottom(),
+		offset[1].x - offset[0].x - padding.width(), offset[1].y - offset[0].y - padding.height(),
 		SWP_NOACTIVATE | SWP_NOOWNERZORDER);
 }
 

=== modified file 'win32/HistoryPage.cpp'
--- win32/HistoryPage.cpp	2011-03-27 10:50:56 +0000
+++ win32/HistoryPage.cpp	2011-04-24 19:53:20 +0000
@@ -35,7 +35,7 @@
 template<typename T>
 GridPtr addSubGrid(T parent, size_t rows) {
 	GridPtr grid = parent->addChild(Grid::Seed(rows, 2));
-	grid->column(0).mode = GridInfo::AUTO;
+	grid->column(0).mode = GridInfo::FILL;
 	grid->column(0).align = GridInfo::BOTTOM_RIGHT;
 	grid->column(1).size = 40;
 	grid->column(1).mode = GridInfo::STATIC;
@@ -66,9 +66,8 @@
 {
 	setHelpId(IDH_HISTORYPAGE);
 
-	grid->column(0).mode = GridInfo::FILL;
-
 	GroupBox::Seed gs;
+	gs.style |= BS_RIGHT;
 
 	{
 		gs.caption = T_("Chat lines to recall from history when opening a window");

=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp	2011-04-24 15:09:54 +0000
+++ win32/MainWindow.cpp	2011-04-24 19:53:20 +0000
@@ -438,10 +438,10 @@
 
 	updateAwayStatus();
 
-	slotsSpin = addChild(Spinner::Seed(1));
+	slotsSpin = addChild(Spinner::Seed());
 	slotsSpin->setHelpId(IDH_MAIN_SLOTS_SPIN);
 	slotsSpin->onUpdate([this](int, int delta) { return handleSlotsUpdate(delta); });
-	status->setWidget(STATUS_SLOTS_SPIN, slotsSpin, dwt::Rectangle(0, 1, 3, 2));
+	status->setWidget(STATUS_SLOTS_SPIN, slotsSpin, dwt::Rectangle(0, 0, 3, 1));
 	status->setSize(STATUS_SLOTS_SPIN, 22);
 
 	/// @todo set to resizedrag width really
@@ -1407,10 +1407,9 @@
 }
 
 bool MainWindow::handleSlotsUpdate(int delta) {
-	// Prevent double-info-updated
 	int newSlots = SETTING(SLOTS) + delta;
 	SettingsManager::getInstance()->set(SettingsManager::SLOTS, newSlots);
-	ThrottleManager::setSetting(SettingsManager::SLOTS, newSlots);
+	ThrottleManager::setSetting(ThrottleManager::getCurSetting(SettingsManager::SLOTS), newSlots);
 	updateStatus();
 	return true;
 }

=== modified file 'win32/PropPage.cpp'
--- win32/PropPage.cpp	2011-04-23 13:04:47 +0000
+++ win32/PropPage.cpp	2011-04-24 19:53:20 +0000
@@ -31,7 +31,11 @@
 const dwt::Rectangle padding(7, 4, 14, 21);
 
 PropPage::PropPage(dwt::Widget* parent, int rows, int cols) : dwt::Container(parent), grid(0) {
-	create(Seed(0, WS_EX_CONTROLPARENT));
+	{
+		Seed seed(0, WS_EX_CONTROLPARENT);
+		seed.style &= ~WS_VISIBLE;
+		create(seed);
+	}
 
 	grid = addChild(Grid::Seed(rows, cols));
 	grid->setSpacing(10);