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: More and more comments addressing Created Sept. 25, 2013, 12:31 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() 6 NotificationMessage::NotificationMessage()
7 { 7 {
8 CommonControlsInitialize(); 8 toolTipWindow = 0;
9 InitializeCommonControls();
9 } 10 }
10 11
11 NotificationMessage::NotificationMessage(HWND parent) 12 NotificationMessage::NotificationMessage(HWND parent)
Wladimir Palant 2013/09/25 14:00:44 You can merge the two constuctors by specifying 0
12 { 13 {
13 parentWindow = parent; 14 parentWindow = parent;
14 CommonControlsInitialize(); 15 toolTipWindow = 0;
16 InitializeCommonControls();
15 }; 17 };
16 18
17 bool NotificationMessage::commonControlsInitialized(false); 19 bool NotificationMessage::commonControlsInitialized(false);
18 20
19 void NotificationMessage::CommonControlsInitialize() 21 void NotificationMessage::InitializeCommonControls()
20 { 22 {
21 if (!commonControlsInitialized) 23 if (!commonControlsInitialized)
22 { 24 {
23 INITCOMMONCONTROLSEX commControls; 25 INITCOMMONCONTROLSEX commControls;
24 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX); 26 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
25 commControls.dwICC = ICC_BAR_CLASSES; 27 commControls.dwICC = ICC_BAR_CLASSES;
26 InitCommonControlsEx(&commControls); 28 InitCommonControlsEx(&commControls);
27 commonControlsInitialized = true; 29 commonControlsInitialized = true;
28 } 30 }
29 } 31 }
30 32
31 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico n) 33 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico n)
32 { 34 {
35 if (toolTipWindow != 0)
36 {
37 Hide();
38 }
33 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, 39 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
34 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, 40 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
35 0, 0, 41 0, 0,
36 0, 0, 42 0, 0,
37 parentWindow, NULL, NULL, 43 parentWindow, NULL, NULL,
38 NULL); 44 NULL);
39 45
40 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, 46 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0,
41 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 47 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
42 TOOLINFO ti; 48 TOOLINFOW ti;
43 » ti.cbSize = sizeof(TOOLINFO); 49 ti.cbSize = sizeof(TOOLINFOW);
44 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 50 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
45 » ti.hwnd = toolTipWindow; 51 ti.hwnd = toolTipWindow;
46 » ti.hinst = NULL; 52 ti.hinst = NULL;
47 » ti.uId = (UINT_PTR)parentWindow; 53 ti.uId = (UINT_PTR)parentWindow;
48 » ti.lpszText = (LPWSTR)message.c_str();» » 54 ti.lpszText = const_cast<LPWSTR>(message.c_str());
49 GetClientRect(parentWindow, &ti.rect); 55 GetClientRect(parentWindow, &ti.rect);
50 56
51 » LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM) (LPT OOLINFO) &ti); 57 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti);
52 58
53 RECT rect; 59 RECT rect;
54 GetWindowRect(parentWindow, &rect); 60 GetWindowRect(parentWindow, &rect);
55 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect. top) / 2); 61 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect. top) / 2);
56 62
57 » res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_s tr()); 63 res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str());
Wladimir Palant 2013/09/25 14:00:44 Not sure where my comment on the previous changese
58 » res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)(LPT OOLINFO) &ti); 64 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
59 65
60 return true; 66 return true;
61 } 67 }
62 68
63 bool NotificationMessage::Hide() 69 bool NotificationMessage::Hide()
64 { 70 {
65 DestroyWindow(toolTipWindow); 71 if (IsVisible())
Wladimir Palant 2013/09/25 14:00:44 This seems to be the wrong check to me - we want t
66 toolTipWindow = 0; 72 {
67 return true; 73 DestroyWindow(toolTipWindow);
74 toolTipWindow = 0;
75 return true;
76 }
77 else
78 {
79 return false;
80 }
68 } 81 }
69 82
70 void NotificationMessage::Move(short x, short y) 83 void NotificationMessage::Move(short x, short y)
71 { 84 {
72 » ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, (LPARAM)(LPTOOLINFO)M AKELONG(x, y)); 85 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y));
73 return; 86 return;
74 } 87 }
75 88
76 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon) 89 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon)
77 { 90 {
78 TOOLINFO ti; 91 TOOLINFOW ti;
79 » ti.cbSize = sizeof(TOOLINFO); 92 ti.cbSize = sizeof(TOOLINFOW);
80 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 93 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
81 » ti.hwnd = toolTipWindow; 94 ti.hwnd = toolTipWindow;
82 » ti.hinst = NULL; 95 ti.hinst = NULL;
83 » ti.uId = (UINT_PTR)parentWindow; 96 ti.uId = (UINT_PTR)parentWindow;
84 » ti.lpszText = (LPWSTR)text.c_str();» » 97 ti.lpszText = const_cast<LPWSTR>(text.c_str());
85 GetClientRect(parentWindow, &ti.rect); 98 GetClientRect(parentWindow, &ti.rect);
86 » LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)t itle.c_str()); 99 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c _str());
87 » res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); 100 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
88 return res == TRUE; 101 return res == TRUE;
89 } 102 }
90 103
91 void NotificationMessage::SetParent(HWND parent) 104 void NotificationMessage::SetParent(HWND parent)
92 { 105 {
93 parentWindow = parent; 106 parentWindow = parent;
94 } 107 }
108
95 bool NotificationMessage::IsVisible() 109 bool NotificationMessage::IsVisible()
96 { 110 {
97 if (toolTipWindow == 0) 111 if (toolTipWindow == 0)
98 return false; 112 return false;
99 return IsWindowVisible(toolTipWindow); 113 return IsWindowVisible(toolTipWindow);
100 } 114 }
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