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 comments addressed Created Sept. 25, 2013, 9:57 a.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 CommonControlsInitialize();
9 } 9 }
10 10
11 NotificationMessage::NotificationMessage(HWND parent) 11 NotificationMessage::NotificationMessage(HWND parent)
12 { 12 {
13 parentWindow = parent; 13 parentWindow = parent;
14 CommonControlsInitialize(); 14 CommonControlsInitialize();
15 }; 15 };
16 16
17 bool NotificationMessage::commonControlsInitialized(false); 17 bool NotificationMessage::commonControlsInitialized(false);
18 18
19 void NotificationMessage::CommonControlsInitialize() 19 void NotificationMessage::InitializeCommonControls()
20 { 20 {
21 if (!commonControlsInitialized) 21 if (!commonControlsInitialized)
22 { 22 {
23 INITCOMMONCONTROLSEX commControls; 23 INITCOMMONCONTROLSEX commControls;
24 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX); 24 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
25 commControls.dwICC = ICC_BAR_CLASSES; 25 commControls.dwICC = ICC_BAR_CLASSES;
26 InitCommonControlsEx(&commControls); 26 InitCommonControlsEx(&commControls);
27 commonControlsInitialized = true; 27 commonControlsInitialized = true;
28 } 28 }
29 } 29 }
30 30
31 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico n) 31 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico n)
32 { 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;
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());
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 res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str());
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 bool NotificationMessage::Hide()
64 { 64 {
65 DestroyWindow(toolTipWindow); 65 if (IsVisible())
66 toolTipWindow = 0; 66 {
67 return true; 67 DestroyWindow(toolTipWindow);
68 toolTipWindow = 0;
69 return true;
70 }
71 else
72 {
73 return false;
74 }
68 } 75 }
69 76
70 void NotificationMessage::Move(short x, short y) 77 void NotificationMessage::Move(short x, short y)
71 { 78 {
72 » ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, (LPARAM)(LPTOOLINFO)M AKELONG(x, y)); 79 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y));
73 return; 80 return;
74 } 81 }
75 82
76 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon) 83 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon)
77 { 84 {
78 TOOLINFO ti; 85 TOOLINFOW ti;
79 » ti.cbSize = sizeof(TOOLINFO); 86 ti.cbSize = sizeof(TOOLINFOW);
80 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 87 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
81 » ti.hwnd = toolTipWindow; 88 ti.hwnd = toolTipWindow;
82 » ti.hinst = NULL; 89 ti.hinst = NULL;
83 » ti.uId = (UINT_PTR)parentWindow; 90 ti.uId = (UINT_PTR)parentWindow;
84 » ti.lpszText = (LPWSTR)text.c_str();» » 91 ti.lpszText = const_cast<LPWSTR>(text.c_str());
85 GetClientRect(parentWindow, &ti.rect); 92 GetClientRect(parentWindow, &ti.rect);
86 » LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)t itle.c_str()); 93 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c _str());
87 » res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); 94 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
88 return res == TRUE; 95 return res == TRUE;
89 } 96 }
90 97
91 void NotificationMessage::SetParent(HWND parent) 98 void NotificationMessage::SetParent(HWND parent)
92 { 99 {
93 parentWindow = parent; 100 parentWindow = parent;
94 } 101 }
102
95 bool NotificationMessage::IsVisible() 103 bool NotificationMessage::IsVisible()
96 { 104 {
97 if (toolTipWindow == 0) 105 if (toolTipWindow == 0)
98 return false; 106 return false;
99 return IsWindowVisible(toolTipWindow); 107 return IsWindowVisible(toolTipWindow);
100 } 108 }
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