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

Delta Between Two Patch Sets: src/plugin/NotificationMessage.cpp

Issue 11557015: Tooltip notification. Check for update fixes. (Closed)
Left Patch Set: More and more comments addressing Created Sept. 25, 2013, 12:31 p.m.
Right Patch Set: Nits addressed Created Oct. 7, 2013, 9:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « .hgsubstate ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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(HWND parent): parentWindow(parent)
7 {
8 toolTipWindow = 0;
9 InitializeCommonControls();
10 }
11
12 NotificationMessage::NotificationMessage(HWND parent)
Wladimir Palant 2013/09/25 14:00:44 You can merge the two constuctors by specifying 0
13 { 7 {
14 parentWindow = parent;
15 toolTipWindow = 0; 8 toolTipWindow = 0;
16 InitializeCommonControls(); 9 InitializeCommonControls();
17 }; 10 };
18 11
19 bool NotificationMessage::commonControlsInitialized(false); 12 bool NotificationMessage::commonControlsInitialized(false);
20 13
21 void NotificationMessage::InitializeCommonControls() 14 void NotificationMessage::InitializeCommonControls()
22 { 15 {
23 if (!commonControlsInitialized) 16 if (!commonControlsInitialized)
24 { 17 {
(...skipping 13 matching lines...) Expand all
38 } 31 }
39 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, 32 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
40 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, 33 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
41 0, 0, 34 0, 0,
42 0, 0, 35 0, 0,
43 parentWindow, NULL, NULL, 36 parentWindow, NULL, NULL,
44 NULL); 37 NULL);
45 38
46 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, 39 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0,
47 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 40 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
48 TOOLINFOW ti; 41 TOOLINFOW ti = {};
49 ti.cbSize = sizeof(TOOLINFOW); 42 ti.cbSize = sizeof(TOOLINFOW);
50 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 43 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
51 ti.hwnd = toolTipWindow; 44 ti.hwnd = toolTipWindow;
52 ti.hinst = NULL; 45 ti.hinst = NULL;
53 ti.uId = (UINT_PTR)parentWindow; 46 ti.uId = (UINT_PTR)parentWindow;
54 ti.lpszText = const_cast<LPWSTR>(message.c_str()); 47 ti.lpszText = const_cast<LPWSTR>(message.c_str());
55 GetClientRect(parentWindow, &ti.rect); 48 GetClientRect(parentWindow, &ti.rect);
56 49
57 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti); 50 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti);
58 51
59 RECT rect; 52 RECT rect;
60 GetWindowRect(parentWindow, &rect); 53 GetWindowRect(parentWindow, &rect);
61 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect. top) / 2); 54 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect. top) / 2);
62 55
63 res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str()); 56 SetTextAndIcon(message, title, icon);
Wladimir Palant 2013/09/25 14:00:44 Not sure where my comment on the previous changese
64 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti); 57 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
65 58
66 return true; 59 return true;
67 } 60 }
68 61
69 bool NotificationMessage::Hide() 62 void NotificationMessage::Hide()
70 { 63 {
71 if (IsVisible()) 64 if (toolTipWindow != 0)
Wladimir Palant 2013/09/25 14:00:44 This seems to be the wrong check to me - we want t
72 { 65 {
73 DestroyWindow(toolTipWindow); 66 DestroyWindow(toolTipWindow);
74 toolTipWindow = 0; 67 toolTipWindow = 0;
75 return true;
76 }
77 else
78 {
79 return false;
80 } 68 }
81 } 69 }
82 70
83 void NotificationMessage::Move(short x, short y) 71 void NotificationMessage::Move(short x, short y)
84 { 72 {
85 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y)); 73 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y));
86 return; 74 return;
87 } 75 }
88 76
89 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon) 77 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon)
90 { 78 {
91 TOOLINFOW ti; 79 TOOLINFOW ti = {};
92 ti.cbSize = sizeof(TOOLINFOW); 80 ti.cbSize = sizeof(TOOLINFOW);
93 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
94 ti.hwnd = toolTipWindow; 81 ti.hwnd = toolTipWindow;
95 ti.hinst = NULL; 82 ti.hinst = NULL;
96 ti.uId = (UINT_PTR)parentWindow; 83 ti.uId = (UINT_PTR)parentWindow;
97 ti.lpszText = const_cast<LPWSTR>(text.c_str()); 84 ti.lpszText = const_cast<LPWSTR>(text.c_str());
98 GetClientRect(parentWindow, &ti.rect);
99 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c _str()); 85 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c _str());
100 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); 86 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
101 return res == TRUE; 87 return res == TRUE;
102 } 88 }
103 89
104 void NotificationMessage::SetParent(HWND parent) 90 void NotificationMessage::SetParent(HWND parent)
105 { 91 {
106 parentWindow = parent; 92 parentWindow = parent;
107 } 93 }
108 94
109 bool NotificationMessage::IsVisible() 95 bool NotificationMessage::IsVisible()
110 { 96 {
111 if (toolTipWindow == 0) 97 if (toolTipWindow == 0)
112 return false; 98 return false;
113 return IsWindowVisible(toolTipWindow); 99 return IsWindowVisible(toolTipWindow);
114 } 100 }
LEFTRIGHT
« .hgsubstate ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld