← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2981: Add a link control to dwt

 

------------------------------------------------------------
revno: 2981
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2012-07-03 21:15:39 +0200
message:
  Add a link control to dwt
added:
  dwt/include/dwt/widgets/Link.h
  dwt/src/widgets/Link.cpp
modified:
  changelog.txt
  dwt/include/dwt/forward.h
  win32/AboutDlg.cpp
  win32/PluginPage.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	2012-07-01 19:31:19 +0000
+++ changelog.txt	2012-07-03 19:15:39 +0000
@@ -23,6 +23,7 @@
 * [L#1016907] Exclude temporary downloads from queue dupe check (emtee)
 * Greatly improve user command removal time when closing a hub
 * Add plugin API (Crise, iceman50)
+* [dwt] Add a link control (poy)
 
 -- 0.799 2012-05-05 --
 * Add icons (iceman50)

=== modified file 'dwt/include/dwt/forward.h'
--- dwt/include/dwt/forward.h	2012-06-08 15:27:48 +0000
+++ dwt/include/dwt/forward.h	2012-07-03 19:15:39 +0000
@@ -102,6 +102,9 @@
 class Label;
 typedef Label* LabelPtr;
 
+class Link;
+typedef Link* LinkPtr;
+
 class LoadDialog;
 
 class Menu;

=== added file 'dwt/include/dwt/widgets/Link.h'
--- dwt/include/dwt/widgets/Link.h	1970-01-01 00:00:00 +0000
+++ dwt/include/dwt/widgets/Link.h	2012-07-03 19:15:39 +0000
@@ -0,0 +1,83 @@
+/*
+  DC++ Widget Toolkit
+
+  Copyright (c) 2007-2012, 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 SmartWin++ 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_LINK_H
+#define DWT_LINK_H
+
+#include "../aspects/Caption.h"
+#include "Control.h"
+
+namespace dwt {
+
+/** This control can display text and clickable links. */
+class Link :
+	public Control,
+	public aspects::Caption<Link>
+{
+	typedef Control BaseType;
+	friend class WidgetCreator<Link>;
+
+public:
+	typedef Link ThisType;
+	typedef ThisType* ObjectType;
+
+	struct Seed : public BaseType::Seed {
+		typedef ThisType WidgetType;
+
+		FontPtr font;
+
+		/** @param link whether to treat the initial text as a link of its own, or as a mixed
+		link/text (with <a> tags). */
+		Seed(const tstring& caption = tstring(), bool link = false);
+	};
+
+	void create(const Seed& seed = Seed());
+
+	void setLink(const tstring& link, size_t index = 0);
+
+	Point getPreferredSize();
+
+protected:
+	// Constructor Taking pointer to parent
+	explicit Link(Widget* parent);
+
+	// Protected to avoid direct instantiation, you can inherit and use
+	// WidgetFactory class which is friend
+	virtual ~Link() { }
+
+private:
+	friend class ChainingDispatcher;
+	static const TCHAR windowClass[];
+};
+
+}
+
+#endif

=== added file 'dwt/src/widgets/Link.cpp'
--- dwt/src/widgets/Link.cpp	1970-01-01 00:00:00 +0000
+++ dwt/src/widgets/Link.cpp	2012-07-03 19:15:39 +0000
@@ -0,0 +1,72 @@
+/*
+  DC++ Widget Toolkit
+
+  Copyright (c) 2007-2012, 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/Link.h>
+
+namespace dwt {
+
+const TCHAR Link::windowClass[] = WC_LINK;
+
+Link::Seed::Seed(const tstring& caption, bool link) :
+	BaseType::Seed(WS_CHILD | WS_TABSTOP, 0, link ? _T("<a href=\"") + caption + _T("\">") + caption + _T("</a>") : caption),
+	font(0)
+{
+}
+
+Link::Link(Widget* parent) :
+	BaseType(parent, ChainingDispatcher::superClass<Link>())
+{
+}
+
+void Link::create(const Seed& seed) {
+	BaseType::create(seed);
+	setFont(seed.font);
+
+	auto openLink = [](WPARAM, LPARAM lParam) -> LRESULT {
+		::ShellExecute(0, 0, reinterpret_cast<NMLINK*>(lParam)->item.szUrl, 0, 0, SW_SHOWNORMAL);
+		return 0;
+	};
+	onRaw(openLink, Message(WM_NOTIFY, NM_CLICK));
+	onRaw(openLink, Message(WM_NOTIFY, NM_RETURN));
+}
+
+void Link::setLink(const tstring& link, size_t index) {
+	LITEM item = { LIF_ITEMINDEX | LIF_URL, index };
+	link.copy(item.szUrl, std::min(link.size(), L_MAX_URL_LENGTH - 1));
+}
+
+Point Link::getPreferredSize() {
+	SIZE size = { 0 };
+	sendMessage(LM_GETIDEALSIZE, getParent()->getClientSize().x, reinterpret_cast<LPARAM>(&size));
+	return Point(size.cx, size.cy);
+}
+
+}

=== modified file 'win32/AboutDlg.cpp'
--- win32/AboutDlg.cpp	2012-01-13 20:55:20 +0000
+++ win32/AboutDlg.cpp	2012-07-03 19:15:39 +0000
@@ -28,6 +28,7 @@
 
 #include <dwt/widgets/Grid.h>
 #include <dwt/widgets/Label.h>
+#include <dwt/widgets/Link.h>
 
 #include "resource.h"
 #include "WinUtil.h"
@@ -35,6 +36,7 @@
 using dwt::Grid;
 using dwt::GridInfo;
 using dwt::Label;
+using dwt::Link;
 
 static const char thanks[] = "Big thanks to all donators and people who have contributed with ideas "
 "and code! Thanks go out to sourceforge.net for hosting the project. "
@@ -89,17 +91,18 @@
 	ls.style |= SS_CENTER;
 
 	{
-		auto cur = grid->addChild(gs)->addChild(Grid::Seed(3, 1));
+		auto cur = grid->addChild(gs)->addChild(Grid::Seed(4, 1));
 		cur->column(0).mode = GridInfo::FILL;
 		cur->column(0).align = GridInfo::CENTER;
 
 		cur->addChild(Label::Seed(WinUtil::createIcon(IDI_DCPP, 48)));
 
 		ls.caption = Text::toT(dcpp::fullVersionString) + _T("\n(c) Copyright 2001-2012 Jacek Sieka\n");
-		ls.caption += T_("Ex-codeveloper: Per Lind\303\251n\nGraphics: Martin Skogevall et al.\nDC++ is licenced under GPL\n");
-		ls.caption += _T("http://dcplusplus.sourceforge.net/";);
+		ls.caption += T_("Ex-codeveloper: Per Lind\303\251n\nGraphics: Martin Skogevall et al.\nDC++ is licenced under GPL");
 		cur->addChild(ls);
 
+		cur->addChild(Link::Seed(_T("http://dcplusplus.sourceforge.net/";), true));
+
 		gs.caption = T_("TTH");
 		auto seed = WinUtil::Seeds::Dialog::textBox;
 		seed.style |= ES_READONLY;
@@ -135,10 +138,11 @@
 	ls.caption = T_("Downloading...");
 	version = grid->addChild(gs)->addChild(ls);
 
-	WinUtil::addDlgButtons(grid,
+	auto buttons = WinUtil::addDlgButtons(grid,
 		[this] { endDialog(IDOK); },
-		[this] { endDialog(IDCANCEL); }
-		).second->setVisible(false);
+		[this] { endDialog(IDCANCEL); });
+	buttons.first->setFocus();
+	buttons.second->setVisible(false);
 
 	setText(T_("About DC++"));
 	setSmallIcon(WinUtil::createIcon(IDI_DCPP, 16));

=== modified file 'win32/PluginPage.cpp'
--- win32/PluginPage.cpp	2012-07-03 17:17:03 +0000
+++ win32/PluginPage.cpp	2012-07-03 19:15:39 +0000
@@ -25,6 +25,7 @@
 
 #include <dwt/widgets/Grid.h>
 #include <dwt/widgets/Label.h>
+#include <dwt/widgets/Link.h>
 #include <dwt/widgets/LoadDialog.h>
 #include <dwt/widgets/MessageBox.h>
 
@@ -38,6 +39,7 @@
 using dwt::Grid;
 using dwt::GridInfo;
 using dwt::Label;
+using dwt::Link;
 using dwt::LoadDialog;
 
 #define IDH_PLUGIN_PAGE 0
@@ -206,11 +208,12 @@
 	auto addInfo = [this, infoGrid](tstring name, const string& value, bool link) {
 		infoGrid->addRow();
 		infoGrid->addChild(Label::Seed(name));
-		auto control = infoGrid->addChild(Label::Seed(value.empty() ?
-			T_("<Information unavailable>") : Text::toT(value)));
 		if(link && !value.empty()) {
-			/// @todo proper link control
-			control->onClicked([control] { WinUtil::openLink(control->getText()); });
+			auto valueT = Text::toT(value);
+			infoGrid->addChild(Link::Seed(valueT, true));
+		} else {
+			infoGrid->addChild(Label::Seed(value.empty() ?
+				T_("<Information unavailable>") : Text::toT(value)));
 		}
 	};