Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/NotificationMessage.cpp

Issue 11557015: Tooltip notification. Check for update fixes. (Closed)
Patch Set: Addressing comments Created Sept. 16, 2013, 1:49 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/plugin/NotificationMessage.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/plugin/NotificationMessage.cpp
@@ -0,0 +1,100 @@
+#include <Windows.h>
+#include <CommCtrl.h>
+
+#include "NotificationMessage.h"
+
+NotificationMessage::NotificationMessage()
+{
+ CommonControlsInitialize();
+}
+
+NotificationMessage::NotificationMessage(HWND parent)
+{
+ parentWindow = parent;
+ CommonControlsInitialize();
+};
+
+bool NotificationMessage::commonControlsInitialized(false);
+
+void NotificationMessage::CommonControlsInitialize()
+{
+ if (!commonControlsInitialized)
+ {
+ INITCOMMONCONTROLSEX commControls;
+ commControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ commControls.dwICC = ICC_BAR_CLASSES;
+ InitCommonControlsEx(&commControls);
+ commonControlsInitialized = true;
+ }
+}
+
+bool NotificationMessage::Show(std::wstring message, std::wstring title, int icon)
+{
+ toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
+ TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
+ 0, 0,
+ 0, 0,
+ parentWindow, NULL, NULL,
+ NULL);
+
+ SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+ TOOLINFO ti;
Wladimir Palant 2013/09/19 08:59:16 We should declare this as TOOLINFOW explicitly.
+ ti.cbSize = sizeof(TOOLINFO);
Wladimir Palant 2013/09/19 08:59:16 Indentation is off, convert tabs to spaces?
+ ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
+ ti.hwnd = toolTipWindow;
+ ti.hinst = NULL;
+ ti.uId = (UINT_PTR)parentWindow;
+ ti.lpszText = (LPWSTR)message.c_str();
Wladimir Palant 2013/09/19 08:59:16 I think that the conversion to LPWSTR is unnecessa
Oleksandr 2013/09/25 10:03:14 We need to remove const here.
Wladimir Palant 2013/09/25 10:27:14 Please use const_cast to indicate that. It's a pit
+ GetClientRect(parentWindow, &ti.rect);
+
+ LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
Wladimir Palant 2013/09/19 08:59:16 The conversion to LPTOOLINFO is unnecessary - &ti
+
+ RECT rect;
+ GetWindowRect(parentWindow, &rect);
+ Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
+
+ res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str());
+ res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)(LPTOOLINFO) &ti);
Wladimir Palant 2013/09/19 08:59:16 Same here, the conversion to LPTOOLINFO is unneces
+
+ return true;
+}
+
+bool NotificationMessage::Hide()
+{
+ DestroyWindow(toolTipWindow);
+ toolTipWindow = 0;
+ return true;
+}
+
+void NotificationMessage::Move(short x, short y)
+{
+ ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, (LPARAM)(LPTOOLINFO)MAKELONG(x, y));
Wladimir Palant 2013/09/19 08:59:16 The conversion to LPTOOLINFO is wrong here, that's
+ return;
+}
+
+bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon)
+{
+ TOOLINFO ti;
+ ti.cbSize = sizeof(TOOLINFO);
Wladimir Palant 2013/09/19 08:59:16 As above, this should be TOOLINFOW.
+ ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
+ ti.hwnd = toolTipWindow;
+ ti.hinst = NULL;
+ ti.uId = (UINT_PTR)parentWindow;
+ ti.lpszText = (LPWSTR)text.c_str();
Wladimir Palant 2013/09/19 08:59:16 As above, the conversion to LPWSTR seems unnecessa
+ GetClientRect(parentWindow, &ti.rect);
+ LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str());
+ res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
+ return res == TRUE;
+}
+
+void NotificationMessage::SetParent(HWND parent)
+{
+ parentWindow = parent;
+}
+bool NotificationMessage::IsVisible()
Wladimir Palant 2013/09/19 08:59:16 Nit: Empty line before this function.
+{
+ if (toolTipWindow == 0)
+ return false;
+ return IsWindowVisible(toolTipWindow);
Wladimir Palant 2013/09/19 08:59:16 Given that we never hide the window but always des
Oleksandr 2013/09/25 10:03:14 The window may become hidden without us hiding it.
Wladimir Palant 2013/09/25 10:27:14 I see. We could react to WM_WINDOWPOSCHANGED then
Oleksandr 2013/09/25 12:37:45 Did that. Also if we do miss the NotificationMessa
+}

Powered by Google App Engine
This is Rietveld