← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2113: use the same menu for all text-boxes; add a set of texts that dwt apps have to provide by contract

 

------------------------------------------------------------
revno: 2113
committer: poy <poy@xxxxxxxxxx>
branch nick: repo
timestamp: Fri 2010-03-26 22:55:05 +0100
message:
  use the same menu for all text-boxes; add a set of texts that dwt apps have to provide by contract
added:
  dwt/include/dwt/Texts.h
  win32/dwt_Texts.cpp
modified:
  changelog.txt
  dwt/include/dwt/aspects/AspectContextMenu.h
  dwt/include/dwt/widgets/TextBox.h
  dwt/src/widgets/TextBox.cpp
  win32/RichTextBox.cpp
  win32/RichTextBox.h
  win32/WinUtil.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	2010-03-20 17:04:00 +0000
+++ changelog.txt	2010-03-26 21:55:05 +0000
@@ -4,6 +4,7 @@
 * [L#539992] Shell menus for directories when browsing own file list (poy)
 * Parse separators in titles of user command param boxes (poy)
 * Fix painting issues with /clear <n> (poy)
+* Smooth text-box menus (poy)
 
 -- 0.761 2010-03-14 --
 * [L#533840] Fix crashes with themed menus (poy)

=== added file 'dwt/include/dwt/Texts.h'
--- dwt/include/dwt/Texts.h	1970-01-01 00:00:00 +0000
+++ dwt/include/dwt/Texts.h	2010-03-26 21:55:05 +0000
@@ -0,0 +1,48 @@
+/*
+  DC++ Widget Toolkit
+
+  Copyright (c) 2007-2010, 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_TEXTS_H
+#define DWT_TEXTS_H
+
+namespace dwt {
+
+struct Texts {
+	/** Texts used by DWT that the calling application should define. */
+	enum Text {
+		undo, cut, copy, paste, del, selAll // text-box menu commands
+	};
+
+	static tstring get(Text text);
+};
+
+}
+
+#endif

=== modified file 'dwt/include/dwt/aspects/AspectContextMenu.h'
--- dwt/include/dwt/aspects/AspectContextMenu.h	2010-02-11 21:44:13 +0000
+++ dwt/include/dwt/aspects/AspectContextMenu.h	2010-03-26 21:55:05 +0000
@@ -47,9 +47,7 @@
 		ContextMenuDispatcher(const F& f_) : BaseType(f_) { }
 
 		bool operator()(const MSG& msg, LRESULT& ret) const {
-			bool shown = f(ScreenCoordinate(Point::fromLParam(msg.lParam)));
-			ret = shown;
-			return shown;
+			return f(ScreenCoordinate(Point::fromLParam(msg.lParam)));
 		}
 	};
 

=== modified file 'dwt/include/dwt/widgets/TextBox.h'
--- dwt/include/dwt/widgets/TextBox.h	2010-03-26 17:15:26 +0000
+++ dwt/include/dwt/widgets/TextBox.h	2010-03-26 21:55:05 +0000
@@ -41,6 +41,7 @@
 #include "../aspects/AspectText.h"
 #include "../aspects/AspectUpdate.h"
 #include "Control.h"
+#include "Menu.h"
 
 namespace dwt {
 
@@ -157,6 +158,7 @@
 	unsigned getLineCount() const;
 
 	virtual tstring textUnderCursor(const ScreenCoordinate& p, bool includeSpaces = false) = 0;
+	virtual tstring getSelection() const = 0;
 
 	void setModify(bool modify = false);
 
@@ -169,6 +171,8 @@
 
 	virtual Point getPreferedSize();
 
+	virtual void addCommands(MenuPtr menu);
+
 	virtual bool handleMessage(const MSG& msg, LRESULT& retVal);
 
 protected:
@@ -185,6 +189,9 @@
 
 		/// number of lines this control occupies, used to guess its vertical size
 		unsigned lines;
+
+		/// seed to use for context menus
+		Menu::Seed menuSeed;
 	};
 
 	void create(const Seed& cs);
@@ -194,6 +201,7 @@
 
 private:
 	unsigned lines;
+	Menu::Seed menuSeed;
 };
 
 class TextBox :

=== modified file 'dwt/src/widgets/TextBox.cpp'
--- dwt/src/widgets/TextBox.cpp	2010-03-06 22:24:26 +0000
+++ dwt/src/widgets/TextBox.cpp	2010-03-26 21:55:05 +0000
@@ -32,6 +32,8 @@
 #include <dwt/widgets/TextBox.h>
 
 #include <dwt/CanvasClasses.h>
+#include <dwt/Texts.h>
+#include <dwt/WidgetCreator.h>
 #include <dwt/util/check.h>
 
 namespace dwt {
@@ -166,6 +168,30 @@
 	return ret;
 }
 
+void TextBoxBase::addCommands(MenuPtr menu) {
+	const bool writable = !hasStyle(ES_READONLY);
+	const bool text = !getText().empty();
+	const bool selection = !getSelection().empty();
+
+	if(writable) {
+		menu->appendItem(Texts::get(Texts::undo), std::tr1::bind(&TextBoxBase::sendMessage, this, WM_UNDO, 0, 0),
+			IconPtr(), sendMessage(EM_CANUNDO));
+		menu->appendSeparator();
+		menu->appendItem(Texts::get(Texts::cut), std::tr1::bind(&TextBoxBase::sendMessage, this, WM_CUT, 0, 0),
+			IconPtr(), selection);
+	}
+	menu->appendItem(Texts::get(Texts::copy), std::tr1::bind(&TextBoxBase::sendMessage, this, WM_COPY, 0, 0),
+		IconPtr(), selection);
+	if(writable) {
+		menu->appendItem(Texts::get(Texts::paste), std::tr1::bind(&TextBoxBase::sendMessage, this, WM_PASTE, 0, 0));
+		menu->appendItem(Texts::get(Texts::del), std::tr1::bind(&TextBoxBase::sendMessage, this, WM_CLEAR, 0, 0),
+			IconPtr(), selection);
+	}
+	menu->appendSeparator();
+	menu->appendItem(Texts::get(Texts::selAll), std::tr1::bind(&TextBoxBase::setSelection, this, 0, -1),
+		IconPtr(), text);
+}
+
 bool TextBoxBase::handleMessage(const MSG& msg, LRESULT& retVal) {
 	bool handled = BaseType::handleMessage(msg, retVal);
 
@@ -176,6 +202,21 @@
 		return true;
 	}
 
+	if(!handled && msg.message == WM_CONTEXTMENU) {
+		// process this here to give the host a chance to handle it differently.
+
+		// imitate AspectContextMenu
+		ScreenCoordinate pt(Point::fromLParam(msg.lParam));
+		if(pt.x() == -1 || pt.y() == -1) {
+			pt = getContextMenuPos();
+		}
+
+		MenuPtr menu(WidgetCreator<Menu>::create(getParent(), menuSeed));
+		addCommands(menu);
+		menu->open(pt, TPM_LEFTALIGN | TPM_RIGHTBUTTON);
+		return true;
+	}
+
 	return handled;
 }
 

=== modified file 'win32/RichTextBox.cpp'
--- win32/RichTextBox.cpp	2010-03-26 17:15:26 +0000
+++ win32/RichTextBox.cpp	2010-03-26 21:55:05 +0000
@@ -20,7 +20,6 @@
 
 #include "RichTextBox.h"
 
-#include "WinUtil.h"
 #include "ParamDlg.h"
 
 RichTextBox::Seed::Seed() : 
@@ -53,20 +52,19 @@
 		{
 			// imitate AspectKeyboard
 			return handleKeyDown(static_cast<int>(msg.wParam));
-		}
-
-	case WM_CONTEXTMENU:
-		{
-			// imitate AspectContextMenu
-			bool shown = handleContextMenu(dwt::ScreenCoordinate(dwt::Point::fromLParam(msg.lParam)));
-			retVal = shown;
-			return shown;
 		}
 	}
 
 	return false;
 }
 
+void RichTextBox::addCommands(MenuPtr menu) {
+	BaseType::addCommands(menu);
+
+	menu->appendSeparator();
+	menu->appendItem(T_("&Find...\tF3"), std::tr1::bind(&RichTextBox::handleFind, this), dwt::IconPtr(), !getText().empty());
+}
+
 bool RichTextBox::handleKeyDown(int c) {
 	switch(c) {
 	case VK_F3:
@@ -81,49 +79,7 @@
 	return false;
 }
 
-#define ID_EDIT_CLEAR 0xE120
-#define ID_EDIT_CLEAR_ALL 0xE121
-#define ID_EDIT_COPY 0xE122
-#define ID_EDIT_CUT 0xE123
-#define ID_EDIT_FIND 0xE124
-#define ID_EDIT_PASTE 0xE125
-#define ID_EDIT_PASTE_LINK 0xE126
-#define ID_EDIT_PASTE_SPECIAL 0xE127
-#define ID_EDIT_REPEAT 0xE128
-#define ID_EDIT_REPLACE 0xE129
-#define ID_EDIT_SELECT_ALL 0xE12A
-#define ID_EDIT_UNDO 0xE12B
-#define ID_EDIT_REDO 0xE12C
-
-bool RichTextBox::handleContextMenu(dwt::ScreenCoordinate pt) {
-	if(pt.x() == -1 || pt.y() == -1) {
-		pt = getContextMenuPos();
-	}
-
-	const bool writable = !hasStyle(ES_READONLY);
-
-	MenuPtr menu(dwt::WidgetCreator<Menu>::create(getParent(), WinUtil::Seeds::menu));
-	if(writable) {
-		menu->appendItem(T_("&Undo\tCtrl+Z"),
-			std::tr1::bind(&RichTextBox::sendMessage, this, WM_COMMAND, MAKEWPARAM(ID_EDIT_UNDO, 0), 0),
-			dwt::IconPtr(), sendMessage(EM_CANUNDO));
-		menu->appendSeparator();
-	}
-	menu->appendItem(T_("&Copy\tCtrl+C"), std::tr1::bind(&RichTextBox::handleCopy, this));
-	menu->appendSeparator();
-	menu->appendItem(T_("&Find...\tF3"), std::tr1::bind(&RichTextBox::handleFind, this));
-
-	menu->open(pt, TPM_LEFTALIGN | TPM_RIGHTBUTTON);
-	return true;
-}
-
-void RichTextBox::handleCopy()
-{
-	WinUtil::setClipboard(getSelection());
-}
-
-void RichTextBox::handleFind()
-{
+void RichTextBox::handleFind() {
 	findText(findTextPopup());
 }
 

=== modified file 'win32/RichTextBox.h'
--- win32/RichTextBox.h	2010-03-26 17:15:26 +0000
+++ win32/RichTextBox.h	2010-03-26 21:55:05 +0000
@@ -38,14 +38,13 @@
 
 	bool handleMessage(const MSG& msg, LRESULT& retVal);
 
+	void addCommands(MenuPtr menu);
+
 	tstring findTextPopup();
 	void findTextNext();
 
 private:
 	bool handleKeyDown(int c);
-	bool handleContextMenu(dwt::ScreenCoordinate pt);
-
-	void handleCopy();
 	void handleFind();
 };
 

=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp	2010-03-26 17:15:26 +0000
+++ win32/WinUtil.cpp	2010-03-26 21:55:05 +0000
@@ -205,6 +205,10 @@
 	xdoptionsTable.style |= LVS_SINGLESEL | LVS_NOCOLUMNHEADER;
 	xdoptionsTable.lvStyle |= LVS_EX_CHECKBOXES;
 
+	xtextBox.menuSeed = Seeds::menu;
+	xdTextBox.menuSeed = Seeds::menu;
+	xRichTextBox.menuSeed = Seeds::menu;
+
 	init_helpPath();
 
 	if(!helpPath.empty()) {

=== added file 'win32/dwt_Texts.cpp'
--- win32/dwt_Texts.cpp	1970-01-01 00:00:00 +0000
+++ win32/dwt_Texts.cpp	2010-03-26 21:55:05 +0000
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2001-2010 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.
+ */
+
+#include "stdafx.h"
+
+#include <dwt/Texts.h>
+
+#include <dcpp/Text.h>
+
+namespace dwt {
+
+tstring Texts::get(Text text) {
+	switch(text) {
+	case undo: return T_("&Undo\tCtrl+Z");
+	case cut: return T_("Cu&t\tCtrl+X");
+	case copy: return T_("&Copy\tCtrl+C");
+	case paste: return T_("&Paste\tCtrl+V");
+	case del: return T_("&Delete\tDel");
+	case selAll: return T_("Select &All\tCtrl+A");
+	}
+
+	assert(0);
+	return tstring();
+}
+
+}