← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2719: add tooltip support to TypedTable

 

------------------------------------------------------------
revno: 2719
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2011-12-14 19:25:45 +0100
message:
  add tooltip support to TypedTable
modified:
  win32/HubFrame.cpp
  win32/HubFrame.h
  win32/TransferView.cpp
  win32/TransferView.h
  win32/TypedTable.h
  win32/UserInfoBase.h
  win32/UsersFrame.cpp
  win32/UsersFrame.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 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2011-12-11 18:36:51 +0000
+++ win32/HubFrame.cpp	2011-12-14 18:25:45 +0000
@@ -200,8 +200,6 @@
 		users->onKeyDown([this](int c) { return handleUsersKeyDown(c); });
 		users->onContextMenu([this](const dwt::ScreenCoordinate &sc) { return handleUsersContextMenu(sc); });
 
-		prepareUserList(users);
-
 		TextBox::Seed cs = WinUtil::Seeds::textBox;
 		cs.style |= ES_AUTOHSCROLL;
 		filter = userGrid->addChild(cs);

=== modified file 'win32/HubFrame.h'
--- win32/HubFrame.h	2011-12-10 18:51:47 +0000
+++ win32/HubFrame.h	2011-12-14 18:25:45 +0000
@@ -130,6 +130,7 @@
 		}
 		int getImage(int col) const;
 		int getStyle(HFONT& font, COLORREF& textColor, COLORREF& bgColor, int) const;
+		using UserInfoBase::getTooltip;
 
 		static int compareItems(const UserInfo* a, const UserInfo* b, int col);
 		bool update(const Identity& identity, int sortCol);

=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp	2011-11-21 19:04:08 +0000
+++ win32/TransferView.cpp	2011-12-14 18:25:45 +0000
@@ -127,8 +127,6 @@
 		connections->onKeyDown([this](int c) { return handleKeyDown(c); });
 		connections->onDblClicked([this] { handleDblClicked(); });
 		connections->onCustomDraw([this](NMLVCUSTOMDRAW& data) { return handleCustomDraw(data); });
-
-		prepareUserList(connections);
 	}
 
 	{

=== modified file 'win32/TransferView.h'
--- win32/TransferView.h	2011-11-21 19:04:08 +0000
+++ win32/TransferView.h	2011-12-14 18:25:45 +0000
@@ -133,6 +133,7 @@
 		int getImage(int col) const {
 			return col == 0 ? (download ? IMAGE_DOWNLOAD : IMAGE_UPLOAD) : -1;
 		}
+		using UserInfoBase::getTooltip;
 
 		static int compareItems(const ConnectionInfo* a, const ConnectionInfo* b, int col);
 	};

=== modified file 'win32/TypedTable.h'
--- win32/TypedTable.h	2011-11-21 19:04:08 +0000
+++ win32/TypedTable.h	2011-12-14 18:25:45 +0000
@@ -46,7 +46,11 @@
 - CDRF_DODEFAULT to keep the default style for the item.
 - CDRF_NEWFONT to change the style of the item.
 - CDRF_NOTIFYSUBITEMDRAW to request custom styles for each sub-item (getStyle will then be called
-for each sub-item). */
+for each sub-item).
+
+@note Support for tooltips:
+The ContentType class must provide a tstring getTooltip() [const] function. Note that tooltips are
+only for the first column. */
 template<typename ContentType, bool managed>
 class TypedTable : public Table
 {
@@ -73,12 +77,16 @@
 	}
 
 	void create(const Seed& seed) {
+#ifdef _DEBUG
+		writeDebugInfo();
+#endif
 		BaseType::create(seed);
 
 		addTextEvent<ContentType>();
 		addImageEvent<ContentType>();
 		addSortEvent<ContentType>();
 		addStyleEvent<ContentType>();
+		addTooltipEvent<ContentType>();
 	}
 
 	int insert(ContentType* item) {
@@ -175,6 +183,10 @@
 	HAS_FUNC(HasStyleC_, getStyle, int (ContentType::*)(HFONT&, COLORREF&, COLORREF&, int) const);
 #define HasStyle (HasStyle_<T>::value || HasStyleC_<T>::value)
 
+	HAS_FUNC(HasTooltip_, getTooltip, tstring (ContentType::*)());
+	HAS_FUNC(HasTooltipC_, getTooltip, tstring (ContentType::*)() const);
+#define HasTooltip (HasTooltip_<T>::value || HasTooltipC_<T>::value)
+
 	template<typename T> typename std::enable_if<HasText, void>::type addTextEvent() {
 		this->onRaw([this](WPARAM, LPARAM lParam) -> LRESULT {
 			auto& data = *reinterpret_cast<NMLVDISPINFO*>(lParam);
@@ -208,6 +220,19 @@
 	}
 	template<typename T> typename std::enable_if<!HasStyle, void>::type addStyleEvent() { }
 
+	template<typename T> typename std::enable_if<HasTooltip, void>::type addTooltipEvent() {
+		this->setTooltips([this](int i) -> tstring { return this->getData(i)->getTooltip(); });
+	}
+	template<typename T> typename std::enable_if<!HasTooltip, void>::type addTooltipEvent() { }
+
+#ifdef _DEBUG
+	void writeDebugInfo() {
+		typedef ContentType T;
+		printf("Creating a TypedTable<%s>; text: %d, images: %d, sorting: %d, custom styles: %d, tooltips: %d\n",
+			typeid(T).name(), HasText, HasImage, HasSort, HasStyle, HasTooltip);
+	}
+#endif
+
 	template<typename T> typename std::enable_if<HasSort, int>::type getSortPos(ContentType* a) {
 		int high = this->size();
 		if((this->getSortColumn() == -1) || (high == 0))

=== modified file 'win32/UserInfoBase.h'
--- win32/UserInfoBase.h	2011-12-11 18:36:51 +0000
+++ win32/UserInfoBase.h	2011-12-14 18:25:45 +0000
@@ -160,11 +160,6 @@
 		if(!traits.isSet(UserTraits::chatNotIgnoredOnly))
 			menu->appendItem(T_("Un-ignore chat"), [this] { this->t().handleIgnoreChat(false); });
 	}
-
-	template<typename TableType>
-	void prepareUserList(TableType* table) {
-		table->setTooltips([table](int i) -> tstring { return table->getData(i)->getTooltip(); });
-	}
 };
 
 #endif /*USERINFOBASE_H_*/

=== modified file 'win32/UsersFrame.cpp'
--- win32/UsersFrame.cpp	2011-11-30 20:54:12 +0000
+++ win32/UsersFrame.cpp	2011-12-14 18:25:45 +0000
@@ -166,7 +166,6 @@
 		users->onSelectionChanged([this] { handleSelectionChanged(); });
 		users->setSmallImageList(userIcons);
 		users->onLeftMouseDown([this](const dwt::MouseEvent &me) { return handleClick(me); });
-		prepareUserList(users);
 	}
 
 	{

=== modified file 'win32/UsersFrame.h'
--- win32/UsersFrame.h	2011-11-21 19:04:08 +0000
+++ win32/UsersFrame.h	2011-12-14 18:25:45 +0000
@@ -95,6 +95,7 @@
 			default: return -1;
 			}
 		}
+		using UserInfoBase::getTooltip;
 
 		static int compareItems(const UserInfo* a, const UserInfo* b, int col) {
 			switch(col) {