← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2438: Add some scroll bars

 

------------------------------------------------------------
revno: 2438
committer: Jacek Sieka <arnetheduck@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Wed 2011-02-23 21:19:48 +0100
message:
  Add some scroll bars
added:
  dwt/include/dwt/widgets/ScrolledContainer.h
  dwt/src/widgets/ScrolledContainer.cpp
modified:
  win32/UsersFrame.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/widgets/ScrolledContainer.h'
--- dwt/include/dwt/widgets/ScrolledContainer.h	1970-01-01 00:00:00 +0000
+++ dwt/include/dwt/widgets/ScrolledContainer.h	2011-02-23 20:19:48 +0000
@@ -0,0 +1,84 @@
+/*
+  DC++ Widget Toolkit
+
+  Copyright (c) 2007-2011, Jacek Sieka
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without modification,
+  are permitted provided that the following conditions are met:
+
+      * Redistributions of source code must retain the above copyright notice,
+        this list of conditions and the following disclaimer.
+      * Redistributions in binary form must reproduce the above copyright notice,
+        this list of conditions and the following disclaimer in the documentation
+        and/or other materials provided with the distribution.
+      * Neither the name of the DWT nor the names of its contributors
+        may be used to endorse or promote products derived from this software
+        without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef DWT_SCROLLEDCONTAINER_H_
+#define DWT_SCROLLEDCONTAINER_H_
+
+#include "../aspects/AspectChild.h"
+
+#include "Container.h"
+
+namespace dwt {
+
+class ScrolledContainer :
+	public Control,
+	// Aspects
+	public AspectChild<ScrolledContainer>
+{
+	typedef Control BaseType;
+
+public:
+	typedef ScrolledContainer ThisType;
+
+	typedef ThisType* ObjectType;
+
+	struct Seed : public BaseType::Seed {
+		typedef ThisType WidgetType;
+
+		Seed(DWORD style = 0, DWORD exStyle = 0);
+	};
+
+	virtual Point getPreferredSize();
+
+	/** Layout the widget in the specified rectangle (in client coordinates) */
+	virtual void layout(const Rectangle& rect);
+
+	/// Returns true if handled, else false
+	virtual bool handleMessage(const MSG &msg, LRESULT &retVal);
+
+protected:
+	friend class WidgetCreator<ScrolledContainer>;
+
+	ScrolledContainer(Widget* parent, Dispatcher& dispatcher = NormalDispatcher::getDefault()) : BaseType(parent, dispatcher) { };
+
+private:
+
+	void setScrollInfo(int type, int page, int max, int pos = 0);
+};
+
+inline ScrolledContainer::Seed::Seed(DWORD style, DWORD exStyle) :
+BaseType::Seed(style | WS_CHILD | WS_HSCROLL | WS_VSCROLL, exStyle)
+{
+}
+
+}
+
+#endif /* DWT_SCROLLEDCONTAINER_H_ */

=== added file 'dwt/src/widgets/ScrolledContainer.cpp'
--- dwt/src/widgets/ScrolledContainer.cpp	1970-01-01 00:00:00 +0000
+++ dwt/src/widgets/ScrolledContainer.cpp	2011-02-23 20:19:48 +0000
@@ -0,0 +1,102 @@
+#include <dwt/widgets/ScrolledContainer.h>
+
+namespace dwt {
+
+Point ScrolledContainer::getPreferredSize() {
+	auto child = getChild();
+	return child ? child->getPreferredSize() : Point(0, 0);
+}
+
+void ScrolledContainer::layout(const Rectangle &rect) {
+	BaseType::layout(rect);
+	auto child = getChild();
+	if(!child) {
+		return;
+	}
+
+	auto clientSize = getClientSize();
+	auto childSize = child->getPreferredSize();
+
+	::ShowScrollBar(handle(), SB_HORZ, childSize.x > clientSize.x);
+	::ShowScrollBar(handle(), SB_VERT, childSize.y > clientSize.y);
+
+	clientSize = getClientSize();
+
+	if(childSize.x > clientSize.x) {
+		setScrollInfo(SB_HORZ, clientSize.x, childSize.x);
+	}
+
+	if(childSize.y > childSize.y) {
+		setScrollInfo(SB_VERT, clientSize.y, childSize.y);
+	}
+
+	child->layout(Rectangle(childSize));
+}
+
+void ScrolledContainer::setScrollInfo(int type, int page, int max, int pos) {
+	SCROLLINFO si = { sizeof(SCROLLINFO) };
+
+	si.fMask = SIF_ALL;
+	si.nMin = 0;
+	si.nMax = max - 1;
+	si.nPos = pos;
+	si.nPage = type == SB_HORZ ? getClientSize().x : getClientSize().y;
+	::SetScrollInfo(handle(), type, &si, TRUE);
+}
+
+bool ScrolledContainer::handleMessage(const MSG &msg, LRESULT &retVal) {
+	if(!(msg.message == WM_HSCROLL || msg.message == WM_VSCROLL)) {
+		return false;
+	}
+
+	auto child = getChild();
+
+	if(!child) {
+		return false;
+	}
+
+	auto childSize = child->getWindowSize();
+
+	SCROLLINFO si = { sizeof(SCROLLINFO), SIF_ALL };
+
+	auto type = msg.message == WM_HSCROLL ? SB_HORZ : SB_VERT;
+    ::GetScrollInfo(handle(), type, &si);
+
+    auto orig = si.nPos;
+
+    switch (LOWORD (msg.wParam)) {
+    case SB_TOP:
+    	si.nPos = 0;
+    	break;
+    case SB_BOTTOM:
+    	si.nPos = si.nMax;
+    	break;
+    case SB_LINELEFT:
+        si.nPos -= 1;
+        break;
+    case SB_LINERIGHT:
+        si.nPos += 1;
+        break;
+    case SB_PAGELEFT:
+        si.nPos -= si.nPage;
+        break;
+    case SB_PAGERIGHT:
+        si.nPos += si.nPage;
+        break;
+    case SB_THUMBTRACK:
+        si.nPos = si.nTrackPos;
+        break;
+    }
+
+    ::SetScrollInfo(handle(), type, &si, FALSE);
+
+	::GetScrollInfo(handle(), type, &si);
+	auto hDiff = type == SB_HORZ ? orig - si.nPos : 0;
+	auto vDiff = type == SB_VERT ? orig - si.nPos : 0;
+
+	::ScrollWindowEx(handle(), hDiff, vDiff, NULL, NULL, NULL, NULL, SW_INVALIDATE | SW_SCROLLCHILDREN);
+
+	return true;
+}
+
+}

=== modified file 'win32/UsersFrame.cpp'
--- win32/UsersFrame.cpp	2011-02-21 21:12:46 +0000
+++ win32/UsersFrame.cpp	2011-02-23 20:19:48 +0000
@@ -31,6 +31,7 @@
 #include <dcpp/version.h>
 
 #include <dwt/widgets/Splitter.h>
+#include <dwt/widgets/ScrolledContainer.h>
 
 const string UsersFrame::id = "Users";
 const string& UsersFrame::getId() const { return id; }
@@ -145,10 +146,9 @@
 	}
 
 	{
-		Grid::Seed cs(0, 1);
-		cs.style |= WS_VSCROLL;
-		userInfo = addChild(cs);
-		splitter->setSecond(userInfo);
+		auto scroll = addChild(dwt::ScrolledContainer::Seed());
+		userInfo = scroll->addChild(Grid::Seed(0, 1));
+		splitter->setSecond(scroll);
 	}
 
 	{