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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include <Windows.h>
2 #include <CommCtrl.h>
3
4 #include "NotificationMessage.h"
5
6 NotificationMessage::NotificationMessage()
7 {
8 CommonControlsInitialize();
9 }
10
11 NotificationMessage::NotificationMessage(HWND parent)
12 {
13 parentWindow = parent;
14 CommonControlsInitialize();
15 };
16
17 bool NotificationMessage::commonControlsInitialized(false);
18
19 void NotificationMessage::CommonControlsInitialize()
20 {
21 if (!commonControlsInitialized)
22 {
23 INITCOMMONCONTROLSEX commControls;
24 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
25 commControls.dwICC = ICC_BAR_CLASSES;
26 InitCommonControlsEx(&commControls);
27 commonControlsInitialized = true;
28 }
29 }
30
31 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico n)
32 {
33 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
34 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
35 0, 0,
36 0, 0,
37 parentWindow, NULL, NULL,
38 NULL);
39
40 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0,
41 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
42 TOOLINFO ti;
Wladimir Palant 2013/09/19 08:59:16 We should declare this as TOOLINFOW explicitly.
43 ti.cbSize = sizeof(TOOLINFO);
Wladimir Palant 2013/09/19 08:59:16 Indentation is off, convert tabs to spaces?
44 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
45 ti.hwnd = toolTipWindow;
46 ti.hinst = NULL;
47 ti.uId = (UINT_PTR)parentWindow;
48 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
49 GetClientRect(parentWindow, &ti.rect);
50
51 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM) (LPT OOLINFO) &ti);
Wladimir Palant 2013/09/19 08:59:16 The conversion to LPTOOLINFO is unnecessary - &ti
52
53 RECT rect;
54 GetWindowRect(parentWindow, &rect);
55 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect. top) / 2);
56
57 res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_s tr());
58 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)(LPT OOLINFO) &ti);
Wladimir Palant 2013/09/19 08:59:16 Same here, the conversion to LPTOOLINFO is unneces
59
60 return true;
61 }
62
63 bool NotificationMessage::Hide()
64 {
65 DestroyWindow(toolTipWindow);
66 toolTipWindow = 0;
67 return true;
68 }
69
70 void NotificationMessage::Move(short x, short y)
71 {
72 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, (LPARAM)(LPTOOLINFO)M AKELONG(x, y));
Wladimir Palant 2013/09/19 08:59:16 The conversion to LPTOOLINFO is wrong here, that's
73 return;
74 }
75
76 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon)
77 {
78 TOOLINFO ti;
79 ti.cbSize = sizeof(TOOLINFO);
Wladimir Palant 2013/09/19 08:59:16 As above, this should be TOOLINFOW.
80 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
81 ti.hwnd = toolTipWindow;
82 ti.hinst = NULL;
83 ti.uId = (UINT_PTR)parentWindow;
84 ti.lpszText = (LPWSTR)text.c_str();
Wladimir Palant 2013/09/19 08:59:16 As above, the conversion to LPWSTR seems unnecessa
85 GetClientRect(parentWindow, &ti.rect);
86 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)t itle.c_str());
87 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
88 return res == TRUE;
89 }
90
91 void NotificationMessage::SetParent(HWND parent)
92 {
93 parentWindow = parent;
94 }
95 bool NotificationMessage::IsVisible()
Wladimir Palant 2013/09/19 08:59:16 Nit: Empty line before this function.
96 {
97 if (toolTipWindow == 0)
98 return false;
99 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
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld