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: Evem more comments addressing Created Sept. 25, 2013, 2:30 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
« no previous file with comments | « src/plugin/NotificationMessage.h ('k') | src/plugin/PluginClass.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <Windows.h> 1 #include <Windows.h>
2 #include <CommCtrl.h> 2 #include <CommCtrl.h>
3 3
4 #include "NotificationMessage.h" 4 #include "NotificationMessage.h"
5 5
6 NotificationMessage::NotificationMessage()
7 {
8 CommonControlsInitialize();
9 }
10
11 NotificationMessage::NotificationMessage(HWND parent) 6 NotificationMessage::NotificationMessage(HWND parent)
12 { 7 {
13 parentWindow = parent; 8 parentWindow = parent;
Felix Dahlke 2013/10/01 12:59:53 Would rather do this in the initialiser list.
14 CommonControlsInitialize(); 9 toolTipWindow = 0;
10 InitializeCommonControls();
15 }; 11 };
16 12
17 bool NotificationMessage::commonControlsInitialized(false); 13 bool NotificationMessage::commonControlsInitialized(false);
18 14
19 void NotificationMessage::CommonControlsInitialize() 15 void NotificationMessage::InitializeCommonControls()
20 { 16 {
21 if (!commonControlsInitialized) 17 if (!commonControlsInitialized)
22 { 18 {
23 INITCOMMONCONTROLSEX commControls; 19 INITCOMMONCONTROLSEX commControls;
24 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX); 20 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
25 commControls.dwICC = ICC_BAR_CLASSES; 21 commControls.dwICC = ICC_BAR_CLASSES;
26 InitCommonControlsEx(&commControls); 22 InitCommonControlsEx(&commControls);
27 commonControlsInitialized = true; 23 commonControlsInitialized = true;
28 } 24 }
29 } 25 }
30 26
31 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico n) 27 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico n)
32 { 28 {
29 if (toolTipWindow != 0)
30 {
31 Hide();
32 }
33 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, 33 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
34 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, 34 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
35 0, 0, 35 0, 0,
36 0, 0, 36 0, 0,
37 parentWindow, NULL, NULL, 37 parentWindow, NULL, NULL,
38 NULL); 38 NULL);
39 39
40 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, 40 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0,
41 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 41 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
42 TOOLINFO ti; 42 TOOLINFOW ti;
Felix Dahlke 2013/10/01 12:59:53 Would rather have all members set to zeroes, just
43 » ti.cbSize = sizeof(TOOLINFO); 43 ti.cbSize = sizeof(TOOLINFOW);
44 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 44 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
45 » ti.hwnd = toolTipWindow; 45 ti.hwnd = toolTipWindow;
46 » ti.hinst = NULL; 46 ti.hinst = NULL;
47 » ti.uId = (UINT_PTR)parentWindow; 47 ti.uId = (UINT_PTR)parentWindow;
48 » ti.lpszText = (LPWSTR)message.c_str();» » 48 ti.lpszText = const_cast<LPWSTR>(message.c_str());
Felix Dahlke 2013/10/01 12:59:53 Can you get rid of this trailing whitespace?
49 GetClientRect(parentWindow, &ti.rect); 49 GetClientRect(parentWindow, &ti.rect);
50 50
51 » LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM) (LPT OOLINFO) &ti); 51 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti);
52 52
53 RECT rect; 53 RECT rect;
54 GetWindowRect(parentWindow, &rect); 54 GetWindowRect(parentWindow, &rect);
55 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect. top) / 2); 55 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect. top) / 2);
56 56
57 » res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_s tr()); 57 SetTextAndIcon(message.c_str(), title.c_str(), icon);
Wladimir Palant 2013/09/25 15:12:48 Calling c_str() is unnecessary here. Also, this is
58 » res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)(LPT OOLINFO) &ti); 58 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
59 59
60 return true; 60 return true;
61 } 61 }
62 62
63 bool NotificationMessage::Hide() 63 void NotificationMessage::Hide()
64 { 64 {
65 DestroyWindow(toolTipWindow); 65 if (toolTipWindow != 0)
66 toolTipWindow = 0; 66 {
67 return true; 67 DestroyWindow(toolTipWindow);
68 toolTipWindow = 0;
69 }
68 } 70 }
69 71
70 void NotificationMessage::Move(short x, short y) 72 void NotificationMessage::Move(short x, short y)
71 { 73 {
72 » ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, (LPARAM)(LPTOOLINFO)M AKELONG(x, y)); 74 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y));
73 return; 75 return;
74 } 76 }
75 77
76 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon) 78 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon)
77 { 79 {
78 TOOLINFO ti; 80 TOOLINFOW ti;
Felix Dahlke 2013/10/01 12:59:53 As above, would prefer to default initialise this
79 » ti.cbSize = sizeof(TOOLINFO); 81 ti.cbSize = sizeof(TOOLINFOW);
80 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 82 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
81 » ti.hwnd = toolTipWindow; 83 ti.hwnd = toolTipWindow;
82 » ti.hinst = NULL; 84 ti.hinst = NULL;
83 » ti.uId = (UINT_PTR)parentWindow; 85 ti.uId = (UINT_PTR)parentWindow;
84 » ti.lpszText = (LPWSTR)text.c_str();» » 86 ti.lpszText = const_cast<LPWSTR>(text.c_str());
85 GetClientRect(parentWindow, &ti.rect); 87 GetClientRect(parentWindow, &ti.rect);
86 » LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)t itle.c_str()); 88 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c _str());
87 » res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); 89 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
88 return res == TRUE; 90 return res == TRUE;
89 } 91 }
90 92
91 void NotificationMessage::SetParent(HWND parent) 93 void NotificationMessage::SetParent(HWND parent)
92 { 94 {
93 parentWindow = parent; 95 parentWindow = parent;
94 } 96 }
97
95 bool NotificationMessage::IsVisible() 98 bool NotificationMessage::IsVisible()
96 { 99 {
97 if (toolTipWindow == 0) 100 if (toolTipWindow == 0)
98 return false; 101 return false;
99 return IsWindowVisible(toolTipWindow); 102 return IsWindowVisible(toolTipWindow);
100 } 103 }
OLDNEW
« no previous file with comments | « src/plugin/NotificationMessage.h ('k') | src/plugin/PluginClass.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld