linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05675
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2938: wait some time before showing help tooltips; position them better
------------------------------------------------------------
revno: 2938
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2012-06-02 14:48:00 +0200
message:
wait some time before showing help tooltips; position them better
modified:
dwt/include/dwt/widgets/ToolTip.h
dwt/src/widgets/ToolTip.cpp
win32/SettingsDialog.cpp
win32/WinUtil.cpp
win32/WinUtil.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/widgets/ToolTip.h'
--- dwt/include/dwt/widgets/ToolTip.h 2012-01-13 20:55:20 +0000
+++ dwt/include/dwt/widgets/ToolTip.h 2012-06-02 12:48:00 +0000
@@ -73,7 +73,7 @@
void setText(const tstring& text_);
void setText(Widget* widget, const tstring& text);
- void addTool(Widget* widget);
+ void addTool(Widget* widget, LPTSTR text = LPSTR_TEXTCALLBACK);
void setTool(Widget* widget, F callback);
void setMaxTipWidth(int width);
=== modified file 'dwt/src/widgets/ToolTip.cpp'
--- dwt/src/widgets/ToolTip.cpp 2012-01-13 20:55:20 +0000
+++ dwt/src/widgets/ToolTip.cpp 2012-06-02 12:48:00 +0000
@@ -60,10 +60,10 @@
setTool(widget, [this](tstring& ret) { ret = text; });
}
-void ToolTip::addTool(Widget* widget) {
+void ToolTip::addTool(Widget* widget, LPTSTR text) {
TOOLINFO ti = { sizeof(TOOLINFO), TTF_IDISHWND | TTF_SUBCLASS, getParent()->handle(),
reinterpret_cast<UINT_PTR>(widget->handle()) };
- ti.lpszText = LPSTR_TEXTCALLBACK;
+ ti.lpszText = text;
sendMessage(TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&ti));
}
=== modified file 'win32/SettingsDialog.cpp'
--- win32/SettingsDialog.cpp 2012-04-15 22:19:38 +0000
+++ win32/SettingsDialog.cpp 2012-06-02 12:48:00 +0000
@@ -218,17 +218,29 @@
tip = addChild(ToolTip::Seed());
// make tooltips last longer
- auto timeout = tip->getDelay(TTDT_AUTOPOP) * 3;
- tip->setDelay(TTDT_AUTOPOP, timeout);
-
- tip->addCallback(dwt::Message(WM_NOTIFY, TTN_GETDISPINFO), [timeout](const MSG& msg, LRESULT&) -> bool {
- auto& ttdi = *reinterpret_cast<LPNMTTDISPINFO>(msg.lParam);
+ tip->setDelay(TTDT_AUTOPOP, tip->getDelay(TTDT_AUTOPOP) * 3);
+
+ // wait more time before displaying tooltips
+ tip->setDelay(TTDT_INITIAL, tip->getDelay(TTDT_INITIAL) + 1000);
+ tip->setDelay(TTDT_RESHOW, tip->getDelay(TTDT_INITIAL));
+
+ // on TTN_SHOW, hide the actual tooltip and display our rich one in its place.
+ tip->onRaw([this](WPARAM, LPARAM lParam) -> LRESULT {
+ auto pos = tip->getWindowRect().pos;
+ ::SetWindowPos(tip->handle(), 0, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOACTIVATE);
+ auto& ttdi = *reinterpret_cast<LPNMTTDISPINFO>(lParam);
auto widget = dwt::hwnd_cast<dwt::Control*>(reinterpret_cast<HWND>(ttdi.hdr.idFrom));
if(widget) {
- WinUtil::helpTooltip(widget, timeout);
+ WinUtil::helpTooltip(widget, pos);
}
- return true;
- });
+ return TRUE;
+ }, dwt::Message(WM_NOTIFY, TTN_SHOW));
+
+ // kill our rich tooltip on TTN_POP.
+ tip->onRaw([this](WPARAM, LPARAM) -> LRESULT {
+ WinUtil::killHelpTooltip();
+ return 0;
+ }, dwt::Message(WM_NOTIFY, TTN_POP));
/*
* catch WM_SETFOCUS messages (onFocus events) sent to every children of this dialog. the normal
@@ -264,8 +276,9 @@
/* associate a tooltip callback with every widget; a tooltip will be shown for those that
provide a valid cshelp id; the tooltip will disappear when hovering others (to be as
- discreet as possible). */
- dialog->tip->addTool(widget);
+ discreet as possible). the tooltip is provided a random text to make it believe in its
+ usefulness (we will actually hide it and show our own rich one on top of it). */
+ dialog->tip->addTool(widget, _T("M"));
// special refresh logic for tables as they may have different help ids for each item.
if(table) {
@@ -274,7 +287,7 @@
static int prevId = -1;
if(static_cast<int>(id) != prevId) {
prevId = static_cast<int>(id);
- dialog->tip->sendMessage(TTM_UPDATE);
+ dialog->tip->refresh();
}
return false;
});
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2012-05-30 17:28:37 +0000
+++ win32/WinUtil.cpp 2012-06-02 12:48:00 +0000
@@ -954,23 +954,9 @@
typedef RichTextBox BaseType;
public:
- HelpPopup(dwt::Widget* parent, const tstring& text, unsigned timeout = 0, bool multiline = false) :
- BaseType(parent), text(text), timeout(timeout)
+ HelpPopup(dwt::Widget* parent, const tstring& text, const dwt::Point& pos = dwt::Point(), bool multiline = false) :
+ BaseType(parent)
{
- // where to position the popup.
- dwt::Point pt;
- if(!tooltip && isAnyKeyPressed()) {
- auto rect = parent->getWindowRect();
- pt.x = rect.left() + rect.width() / 2;
- pt.y = rect.bottom() + margin;
- } else {
- pt = dwt::Point::fromLParam(::GetMessagePos());
- if(tooltip) {
- // don't cover the parent window.
- pt.y = parent->getWindowRect().bottom() + margin;
- }
- }
-
// create the box as an invisible popup window.
auto seed = WinUtil::Seeds::richTextBox;
seed.style = WS_POPUP | ES_READONLY;
@@ -985,12 +971,12 @@
sendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(LOWORD(margins) + margin, HIWORD(margins) + margin));
// let the control figure out what the best size is.
- onRaw([this, pt](WPARAM, LPARAM l) { return this->resize(l, pt); }, dwt::Message(WM_NOTIFY, EN_REQUESTRESIZE));
+ onRaw([this, text, pos](WPARAM, LPARAM l) { return this->resize(l, text, pos); }, dwt::Message(WM_NOTIFY, EN_REQUESTRESIZE));
setText(text);
}
private:
- LRESULT resize(LPARAM lParam, const dwt::Point& pos) {
+ LRESULT resize(LPARAM lParam, const tstring& text, dwt::Point pos) {
if(getVisible())
return 0;
@@ -998,7 +984,7 @@
if(rect.width() > getWindowRect().width() && !hasStyle(ES_MULTILINE)) {
// can't add ES_MULTILINE at run time, so create the control again.
- new ThisType(getParent(), text, timeout, true);
+ new ThisType(getParent(), text, pos, true);
close();
return 0;
}
@@ -1010,6 +996,17 @@
helpPopup = this;
onDestroy([this] { if(this == helpPopup) helpPopup = nullptr; });
+ // where to position the popup.
+ if(!tooltip) {
+ if(isAnyKeyPressed()) {
+ auto rect = getParent()->getWindowRect();
+ pos.x = rect.left() + rect.width() / 2;
+ pos.y = rect.bottom() + margin;
+ } else {
+ pos = dwt::Point::fromLParam(::GetMessagePos());
+ }
+ }
+
// adjust the size to account for borders and margins.
rect.pos = pos;
rect.size.x += ::GetSystemMetrics(SM_CXEDGE) * 2;
@@ -1022,7 +1019,6 @@
if(tooltip) {
// this help popup acts as a tooltip; it will close by itself.
- setTimer([this] { return !this->close(); }, timeout);
onMouseMove([this](const dwt::MouseEvent&) { return this->close(); });
} else {
@@ -1057,9 +1053,6 @@
static const long margin = 6;
static const long maxWidth = 400;
-
- const tstring text;
- unsigned timeout;
};
void WinUtil::help(dwt::Control* widget) {
@@ -1070,6 +1063,7 @@
if(id >= IDH_CSHELP_BEGIN && id <= IDH_CSHELP_END) {
// context-sensitive help
new HelpPopup<false>(widget, Text::toT(getHelpText(id)));
+
} else {
#ifdef HAVE_HTMLHELP_H
if(id < IDH_BEGIN || id > IDH_END)
@@ -1079,15 +1073,20 @@
}
}
-void WinUtil::helpTooltip(dwt::Control* widget, unsigned timeout) {
+void WinUtil::helpTooltip(dwt::Control* widget, const dwt::Point& pos) {
+ killHelpTooltip();
+
auto id = widget->getHelpId();
if(id >= IDH_CSHELP_BEGIN && id <= IDH_CSHELP_END) {
// context-sensitive help
- new HelpPopup<true>(widget, Text::toT(getHelpText(id)), timeout);
+ new HelpPopup<true>(widget, Text::toT(getHelpText(id)), pos);
+ }
+}
- } else if(helpPopup) {
- // close the previous one.
+void WinUtil::killHelpTooltip() {
+ if(helpPopup) {
helpPopup->close();
+ helpPopup = nullptr;
}
}
=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h 2012-06-01 17:26:20 +0000
+++ win32/WinUtil.h 2012-06-02 12:48:00 +0000
@@ -295,7 +295,8 @@
static void help(dwt::Control* widget);
static void helpId(dwt::Control* widget, unsigned id);
- static void helpTooltip(dwt::Control* widget, unsigned timeout);
+ static void helpTooltip(dwt::Control* widget, const dwt::Point& pos);
+ static void killHelpTooltip();
static string getHelpText(unsigned id);
// URL related