← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2363: put the toolbar in a rebar

 

------------------------------------------------------------
revno: 2363
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-12-23 16:57:01 +0100
message:
  put the toolbar in a rebar
modified:
  dwt/include/dwt/forward.h
  dwt/include/dwt/widgets/Rebar.h
  dwt/include/dwt/widgets/ToolBar.h
  dwt/src/widgets/Rebar.cpp
  dwt/src/widgets/ToolBar.cpp
  win32/MainWindow.cpp
  win32/MainWindow.h
  win32/stdafx.h


--
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/forward.h'
--- dwt/include/dwt/forward.h	2010-12-21 14:40:47 +0000
+++ dwt/include/dwt/forward.h	2010-12-23 15:57:01 +0000
@@ -87,6 +87,9 @@
 class RadioButton;
 typedef RadioButton* RadioButtonPtr;
 
+class Rebar;
+typedef Rebar* RebarPtr;
+
 class RichTextBox;
 typedef RichTextBox* RichTextBoxPtr;
 

=== modified file 'dwt/include/dwt/widgets/Rebar.h'
--- dwt/include/dwt/widgets/Rebar.h	2010-12-12 23:10:36 +0000
+++ dwt/include/dwt/widgets/Rebar.h	2010-12-23 15:57:01 +0000
@@ -83,13 +83,16 @@
 	  */
 	void create(const Seed& cs = Seed());
 
-#if 0
 	/// Refreshes the Rebar
 	/** Call this one after the container widget has been resized to make sure the
 	  * Rebar is having the right size...
 	  */
 	void refresh();
-#endif
+
+	void add(Widget* w, const tstring& text = tstring());
+	void remove(Widget* w);
+
+	unsigned size() const;
 
 protected:
 	// Protected to avoid direct instantiation
@@ -99,9 +102,6 @@
 private:
 	friend class ChainingDispatcher;
 	static const TCHAR windowClass[];
-
-	// Adds up the given child to a new rebar band...
-	void addChild( Widget * child, unsigned width, unsigned height, const tstring & txt );
 };
 
 }

=== modified file 'dwt/include/dwt/widgets/ToolBar.h'
--- dwt/include/dwt/widgets/ToolBar.h	2010-07-10 14:36:48 +0000
+++ dwt/include/dwt/widgets/ToolBar.h	2010-12-23 15:57:01 +0000
@@ -86,11 +86,6 @@
 	  */
 	void refresh();
 
-	/// Sets the size of buttons in the toolbar
-	/** This should be relative to the size of the bitmap used (if you use a bitmap)
-	  */
-	void setButtonSize( unsigned int width, unsigned int height );
-
 	/// Adds a bitmap to the toolbar that later can be referenced while adding buttons
 	/** Loads a bitmap that is contained in a BitmapPtr. <br>
 	  * noButtonsInBitmap is how many buttons there actually exists in the bitmap
@@ -199,6 +194,8 @@
 	  */
 	void create(const Seed& cs = Seed());
 
+	virtual Point getPreferredSize();
+
 protected:
 	// Constructor Taking pointer to parent
 	explicit ToolBar(Widget* parent);
@@ -268,15 +265,6 @@
 	sendMessage(TB_AUTOSIZE);
 }
 
-inline void ToolBar::setButtonSize( unsigned int width, unsigned int height )
-{
-	if ( sendMessage(TB_SETBUTTONSIZE, 0, static_cast< LPARAM >( MAKELONG( width, height ) ) ) != TRUE ||
-		sendMessage(TB_SETBITMAPSIZE, 0, static_cast< LPARAM >( MAKELONG( width, height ) ) ) != TRUE )
-	{
-		throw Win32Exception( "Error while trying to set toolbar button size...");
-	}
-}
-
 /*
 
 void ToolBar::addBitmap( HBITMAP hBit, unsigned int noButtonsInBitmap )

=== modified file 'dwt/src/widgets/Rebar.cpp'
--- dwt/src/widgets/Rebar.cpp	2010-12-12 23:10:36 +0000
+++ dwt/src/widgets/Rebar.cpp	2010-12-23 15:57:01 +0000
@@ -30,14 +30,13 @@
 */
 
 #include <dwt/widgets/Rebar.h>
-#include <dwt/DWTException.h>
 
 namespace dwt {
 
 const TCHAR Rebar::windowClass[] = REBARCLASSNAME;
 
 Rebar::Seed::Seed() :
-BaseType::Seed(WS_CHILD | RBS_VARHEIGHT | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER)
+BaseType::Seed(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER | RBS_AUTOSIZE | RBS_VARHEIGHT, WS_EX_TOOLWINDOW)
 {
 }
 
@@ -50,40 +49,46 @@
 	BaseType::create(cs);
 }
 
-#if 0
 void Rebar::refresh() {
-	// This might look a bit stupid, but Windows API have some minor flaws. One of
-	// those flaws is that a Rebar (and a Toolbar) control must be "resized" with
-	// a dummy value to make sure the Rebar (&& the Toolbar) fills up the
-	// complete area of the container Widget...
-
-	if ( ::MoveWindow( this->handle(), 0, 0, 0, 0, TRUE ) == 0 ) {
-		dwtWin32DebugFail("Couldn't reposition windows");
-	}
-}
-#endif
-
-void Rebar::addChild( Widget * child,
-	unsigned width, unsigned height, const tstring & txt
-	)
-{
-	REBARBANDINFO rbBand;
-	rbBand.cbSize = sizeof( REBARBANDINFO );
-	rbBand.fMask = RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_STYLE;
-	if ( txt != _T( "" ) )
-	{
-		rbBand.fMask |= RBBIM_TEXT;
-		rbBand.lpText = const_cast < TCHAR * >( txt.c_str() );
-	}
-	rbBand.hwndChild = child->handle();
-	rbBand.cxMinChild = width;
-	rbBand.cyMinChild = height;
-	rbBand.cx = width;
-	rbBand.fStyle = 0; //RBBS_GRIPPERALWAYS;
-	if ( sendMessage( RB_INSERTBAND, ( WPARAM ) - 1, ( LPARAM ) & rbBand ) == 0 )
-	{
-		throw DWTException( "There was a problem when trying to insert a band into your Rebar object!");
-	}
+	// use dummy sizes to avoid flickering; the rebar will figure out the proper sizes by itself.
+	::MoveWindow(handle(), 0, 0, 0, 0, TRUE);
+}
+
+void Rebar::add(Widget* w, const tstring& text) {
+	if(size() == 0)
+		setVisible(true);
+
+	REBARBANDINFO info = { sizeof(REBARBANDINFO), RBBIM_CHILD | RBBIM_CHILDSIZE };
+
+	if(!text.empty()) {
+		info.fMask |= RBBIM_TEXT;
+		info.lpText = const_cast<LPTSTR>(text.c_str());
+	}
+
+	info.hwndChild = w->handle();
+
+	const Point size = w->getPreferredSize();
+	info.cxMinChild = size.x;
+	info.cyMinChild = size.y;
+
+	sendMessage(RB_INSERTBAND, static_cast<WPARAM>(-1), reinterpret_cast<LPARAM>(&info));
+}
+
+void Rebar::remove(Widget* w) {
+	for(unsigned i = 0, n = size(); i < n; ++i) {
+		REBARBANDINFO info = { sizeof(REBARBANDINFO), RBBIM_CHILD };
+		if(sendMessage(RB_GETBANDINFO, i, reinterpret_cast<LPARAM>(&info)) && info.hwndChild == w->handle()) {
+			sendMessage(RB_DELETEBAND, i);
+			break;
+		}
+	}
+
+	if(size() == 0)
+		setVisible(false);
+}
+
+unsigned Rebar::size() const {
+	return sendMessage(RB_GETBANDCOUNT);
 }
 
 }

=== modified file 'dwt/src/widgets/ToolBar.cpp'
--- dwt/src/widgets/ToolBar.cpp	2010-12-21 14:40:47 +0000
+++ dwt/src/widgets/ToolBar.cpp	2010-12-23 15:57:01 +0000
@@ -36,7 +36,7 @@
 const TCHAR ToolBar::windowClass[] = TOOLBARCLASSNAME;
 
 ToolBar::Seed::Seed() :
-BaseType::Seed(WS_CHILD | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE)
+BaseType::Seed(WS_CHILD | CCS_ADJUSTABLE | CCS_NODIVIDER | CCS_NORESIZE | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TOOLTIPS)
 {
 }
 
@@ -76,6 +76,11 @@
 	}
 }
 
+Point ToolBar::getPreferredSize() {
+	// don't care about the width
+	return Point(0, HIWORD(sendMessage(TB_GETBUTTONSIZE)) + HIWORD(sendMessage(TB_GETPADDING)));
+}
+
 void ToolBar::addButton(const std::string& id, const IconPtr& icon, const IconPtr& hotIcon, const tstring& text, unsigned helpId,
 						const Dispatcher::F& f, const DropDownFunction& dropDownF)
 {

=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp	2010-12-21 14:40:47 +0000
+++ win32/MainWindow.cpp	2010-12-23 15:57:01 +0000
@@ -66,9 +66,10 @@
 #include <dcpp/SimpleXML.h>
 #include <dcpp/ThrottleManager.h>
 
+#include <dwt/widgets/Notification.h>
+#include <dwt/widgets/Rebar.h>
+#include <dwt/widgets/Spinner.h>
 #include <dwt/widgets/ToolBar.h>
-#include <dwt/widgets/Spinner.h>
-#include <dwt/widgets/Notification.h>
 
 #ifdef HAVE_HTMLHELP_H
 #include <htmlhelp.h>
@@ -79,6 +80,7 @@
 
 MainWindow::MainWindow() :
 dwt::Window(0, dwt::NormalDispatcher::newClass<MainWindow>(mainIcon, mainSmallIcon)),
+rebar(0),
 paned(0),
 transfers(0),
 toolbar(0),
@@ -213,6 +215,8 @@
 
 	setHelpId(IDH_MAIN);
 
+	rebar = addChild(Rebar::Seed());
+
 	paned = addChild(HSplitter::Seed(SETTING(TRANSFERS_PANED_POS)));
 }
 
@@ -421,6 +425,8 @@
 
 	toolbar->onHelp(std::bind(&WinUtil::help, _1, _2));
 
+	rebar->add(toolbar);
+
 	viewMenu->checkItem(viewIndexes["Toolbar"], true);
 }
 
@@ -858,9 +864,9 @@
 void MainWindow::layout() {
 	dwt::Rectangle r(getClientSize());
 
-	if(toolbar) {
-		toolbar->refresh();
-		dwt::Point pt = toolbar->getWindowSize();
+	if(rebar->size() > 0) {
+		rebar->refresh();
+		dwt::Point pt = rebar->getWindowSize();
 		r.pos.y += pt.y;
 		r.size.y -= pt.y;
 	}
@@ -1260,6 +1266,7 @@
 
 void MainWindow::switchToolbar() {
 	if(toolbar) {
+		rebar->remove(toolbar);
 		::DestroyWindow(toolbar->handle());
 		toolbar = 0;
 

=== modified file 'win32/MainWindow.h'
--- win32/MainWindow.h	2010-12-21 14:40:47 +0000
+++ win32/MainWindow.h	2010-12-23 15:57:01 +0000
@@ -107,6 +107,7 @@
 		TIMER_SAVE
 	};
 
+	RebarPtr rebar;
 	HSplitterPtr paned;
 	MenuPtr mainMenu;
 	MenuPtr viewMenu;

=== modified file 'win32/stdafx.h'
--- win32/stdafx.h	2010-12-21 14:40:47 +0000
+++ win32/stdafx.h	2010-12-23 15:57:01 +0000
@@ -79,6 +79,8 @@
 using dwt::ProgressBarPtr;
 using dwt::RadioButton;
 using dwt::RadioButtonPtr;
+using dwt::Rebar;
+using dwt::RebarPtr;
 using dwt::SaveDialog;
 using dwt::Slider;
 using dwt::SliderPtr;