← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2577: Modal dialog fixes

 

------------------------------------------------------------
revno: 2577
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2011-07-05 14:16:32 +0200
message:
  Modal dialog fixes
added:
  dwt/src/widgets/MessageBox.cpp
modified:
  changelog.txt
  dwt/include/dwt/Widget.h
  dwt/include/dwt/widgets/MessageBox.h
  dwt/include/dwt/widgets/ModalDialog.h
  dwt/src/Widget.cpp
  dwt/src/widgets/Control.cpp
  dwt/src/widgets/ModalDialog.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 'changelog.txt'
--- changelog.txt	2011-07-03 17:15:51 +0000
+++ changelog.txt	2011-07-05 12:16:32 +0000
@@ -33,6 +33,7 @@
 * [L#189241] Store crash reports in a CrashLog.txt file (poy)
 * Improve "View as text" windows (poy)
 * [L#804024] [ADC] Separate application and version in INF (ullner)
+* [L#696761] Modal dialog fixes (poy)
 
 -- 0.782 2011-03-05 --
 * Prevent a remote crash triggered via malformed user commands (poy)

=== modified file 'dwt/include/dwt/Widget.h'
--- dwt/include/dwt/Widget.h	2011-03-15 19:52:17 +0000
+++ dwt/include/dwt/Widget.h	2011-07-05 12:16:32 +0000
@@ -157,6 +157,9 @@
 	 */
 	void setHandle(HWND hwnd);
 
+	/// get the top-most parent window of this widget (either a main window or a modal dialog).
+	Widget* getRoot() const;
+
 protected:
 	/** Most Widgets can override the creational parameters which sets the style and the
 	  * initial position of the Widget, those Widgets will take an object of this type to

=== modified file 'dwt/include/dwt/widgets/MessageBox.h'
--- dwt/include/dwt/widgets/MessageBox.h	2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/widgets/MessageBox.h	2011-07-05 12:16:32 +0000
@@ -41,18 +41,6 @@
 
 namespace dwt {
 
-/// MessageBox class
-/** \ingroup WidgetControls
-  * \image html messagebox.PNG
-  * Class for showing a MessageBox. <br>
-  * Either derive from it, call WidgetFactory::createMessageBox or use normal
-  * Constructor. <br>
-  * Note! <br>
-  * If you wish to use this class with Parent classes other than those from SmartWin
-  * you need to expose a public function called "parent" taking no arguments returning
-  * and HWND in the Parent template parameter. <br>
-  * The complete signature of the function will then be "HWND parent()"
-  */
 class MessageBox
 {
 public:
@@ -67,7 +55,7 @@
 	~MessageBox()
 	{}
 
-	explicit MessageBox( dwt::Widget * parent = 0 );
+	explicit MessageBox(Widget* parent);
 
 	// Next three enums are here INTENTIONALLY to abstract away Win32API
 	/// Enums for which buttons you want the MessageBox to have.
@@ -113,39 +101,14 @@
 		RETBOX_YES = IDYES
 	};
 
-	/// Shows the actual MessageBox
-	/** First parameter is the body shown inside the Message Box. <br>
-	  * Second parameter is the HEADER of the Message Box ( the text shown in the
-	  * blue line, optional parameter ) <br>
-	  * Third parameter is the Buttons you want the Message Box to have ( optional
-	  * parameter ) <br>
-	  * Fourth parameter is the Icon you want the Message Box to display ( normally
-	  * in the upper left corner )
-	  */
-	RetVal show( const tstring & body,
-		const tstring & header = _T( "Message" ),
-		Buttons buttons = BOX_OK,
-		Icon icon = BOX_ICONINFORMATION );
+	RetVal show(const tstring& message, const tstring& title, Buttons buttons = BOX_OK, Icon icon = BOX_ICONINFORMATION);
+
+	Widget* getParent() const { return parent; }
 
 private:
-	Widget* itsParent;
-
-	HWND getParentHandle() { return itsParent ? itsParent->handle() : NULL; }
+	Widget* parent;
 };
 
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Implementation of class
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-inline MessageBox::MessageBox( Widget * parent )
-	: itsParent( parent )
-{}
-
-inline MessageBox::RetVal MessageBox::show( const tstring & body, const tstring & header, Buttons buttons, Icon icon )
-{
-	return static_cast< RetVal >( ::MessageBox( getParentHandle(), body.c_str(), header.c_str(), buttons | icon ) );
-}
-
 }
 
 #endif

=== modified file 'dwt/include/dwt/widgets/ModalDialog.h'
--- dwt/include/dwt/widgets/ModalDialog.h	2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/widgets/ModalDialog.h	2011-07-05 12:16:32 +0000
@@ -95,18 +95,6 @@
 		Seed(const Point& size, DWORD styles_ = 0);
 	};
 
-	/// Creates a Modal Dialog Window defined in C++ alone.
-	/** This version creates a dialog window without using a Dialog Resource ID. <br>
-	  * To be called by the invoker of the dialog. <br>
-	  * The return comes from the parameter to endDialog() <br>
-	  * You must call onInitDialog( &MyModalDialogWidget::initDialog ); in the
-	  * constructor of your dialog, <br>
-	  * and in your initDialog you create the dialog's Widgets yourself. <br>
-	  * Example : <br>
-	  * LabelPtr prompt = createLabel(); <br>
-	  * prompt->setBounds( 10, 100, 100, 50 ); <br>
-	  * prompt->setText( _T("testing") );
-	  */
 	void create(const Seed& cs);
 
 	/// Display the dialog and return only when the dialog has been dismissed
@@ -144,14 +132,6 @@
 
 	virtual ~ModalDialog();
 
-	/// Specify how a resourceless dialog's window appears.
-	/** The derived pure dialog class can control the DLGTEMPLATE parameters used in
-	  * create() with this protected call. <br>
-	  * The calling layer is prevented from doing so. <br>
-	  * See DLGTEMPLATE as used in ::DialogBoxIndirectParam for details.
-	  */
-	void setDlgTemplate( DLGTEMPLATE inTemplate );
-
 	/// Called by default when WM_CLOSE is posted to the dialog
 	bool defaultClosing() {
 		endDialog(IDCANCEL);

=== modified file 'dwt/src/Widget.cpp'
--- dwt/src/Widget.cpp	2011-03-15 19:52:17 +0000
+++ dwt/src/Widget.cpp	2011-07-05 12:16:32 +0000
@@ -98,6 +98,10 @@
 	::SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProc::wndProc));
 }
 
+Widget* Widget::getRoot() const {
+	return hwnd_cast<Widget*>(::GetAncestor(handle(), GA_ROOT));
+}
+
 void Widget::addRemoveStyle(DWORD addStyle, bool add) {
 	util::win32::updateStyle(handle(), GWL_STYLE, addStyle, add);
 }

=== modified file 'dwt/src/widgets/Control.cpp'
--- dwt/src/widgets/Control.cpp	2011-06-01 19:02:45 +0000
+++ dwt/src/widgets/Control.cpp	2011-07-05 12:16:32 +0000
@@ -96,6 +96,11 @@
 }
 
 bool Control::handleMessage(const MSG& msg, LRESULT& retVal) {
+	if(msg.message == WM_CLOSE && !getRoot()->getEnabled()) {
+		// disallow closing disabled windows.
+		return true;
+	}
+
 	bool handled = BaseType::handleMessage(msg, retVal);
 	if(handled)
 		return handled;

=== added file 'dwt/src/widgets/MessageBox.cpp'
--- dwt/src/widgets/MessageBox.cpp	1970-01-01 00:00:00 +0000
+++ dwt/src/widgets/MessageBox.cpp	2011-07-05 12:16:32 +0000
@@ -0,0 +1,53 @@
+/*
+  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.
+*/
+
+#include <dwt/widgets/MessageBox.h>
+
+#include <dwt/util/check.h>
+
+namespace dwt {
+
+MessageBox::MessageBox(Widget* parent) :
+parent(parent)
+{
+	dwtassert(parent, _T("A MessageBox must have a valid parent"));
+}
+
+MessageBox::RetVal MessageBox::show(const tstring& message, const tstring& title, Buttons buttons, Icon icon) {
+	auto root = getParent()->getRoot();
+	if(!root || !root->getEnabled()) {
+		return RETBOX_CANCEL;
+	}
+
+	return static_cast<RetVal>(::MessageBox(getParent()->handle(), message.c_str(), title.c_str(), buttons | icon));
+}
+
+}

=== modified file 'dwt/src/widgets/ModalDialog.cpp'
--- dwt/src/widgets/ModalDialog.cpp	2011-04-07 14:57:29 +0000
+++ dwt/src/widgets/ModalDialog.cpp	2011-07-05 12:16:32 +0000
@@ -80,14 +80,14 @@
 }
 
 int ModalDialog::show() {
-	bool enabled = false;
-
-	Widget* root = hwnd_cast<Widget*>(::GetAncestor(getParentHandle(), GA_ROOT));
-
-	if(root) {
-		enabled = !root->setEnabled(false);
+	auto root = getParent()->getRoot();
+	if(!root || !root->getEnabled()) {
+		::DestroyWindow(handle());
+		return IDCANCEL;
 	}
 
+	root->setEnabled(false);
+
 	setVisible(true);
 
 	while(!quit) {
@@ -96,9 +96,7 @@
 		}
 	}
 
-	if(enabled) {
-		root->setEnabled(true);
-	}
+	root->setEnabled(true);
 
 	::DestroyWindow(handle());