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: Evem more comments addressing Created Sept. 25, 2013, 2:30 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(HWND parent) 6 NotificationMessage::NotificationMessage(HWND parent): parentWindow(parent)
7 { 7 {
8 parentWindow = parent;
Felix Dahlke 2013/10/01 12:59:53 Would rather do this in the initialiser list.
9 toolTipWindow = 0; 8 toolTipWindow = 0;
10 InitializeCommonControls(); 9 InitializeCommonControls();
11 }; 10 };
12 11
13 bool NotificationMessage::commonControlsInitialized(false); 12 bool NotificationMessage::commonControlsInitialized(false);
14 13
15 void NotificationMessage::InitializeCommonControls() 14 void NotificationMessage::InitializeCommonControls()
16 { 15 {
17 if (!commonControlsInitialized) 16 if (!commonControlsInitialized)
18 { 17 {
(...skipping 13 matching lines...) Expand all
32 } 31 }
33 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, 32 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
34 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, 33 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
35 0, 0, 34 0, 0,
36 0, 0, 35 0, 0,
37 parentWindow, NULL, NULL, 36 parentWindow, NULL, NULL,
38 NULL); 37 NULL);
39 38
40 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, 39 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0,
41 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 40 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
42 TOOLINFOW ti; 41 TOOLINFOW ti = {};
Felix Dahlke 2013/10/01 12:59:53 Would rather have all members set to zeroes, just
43 ti.cbSize = sizeof(TOOLINFOW); 42 ti.cbSize = sizeof(TOOLINFOW);
44 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 43 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
45 ti.hwnd = toolTipWindow; 44 ti.hwnd = toolTipWindow;
46 ti.hinst = NULL; 45 ti.hinst = NULL;
47 ti.uId = (UINT_PTR)parentWindow; 46 ti.uId = (UINT_PTR)parentWindow;
48 ti.lpszText = const_cast<LPWSTR>(message.c_str()); 47 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); 48 GetClientRect(parentWindow, &ti.rect);
50 49
51 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti); 50 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti);
52 51
53 RECT rect; 52 RECT rect;
54 GetWindowRect(parentWindow, &rect); 53 GetWindowRect(parentWindow, &rect);
55 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);
56 55
57 SetTextAndIcon(message.c_str(), title.c_str(), icon); 56 SetTextAndIcon(message, title, 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)&ti); 57 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
59 58
60 return true; 59 return true;
61 } 60 }
62 61
63 void NotificationMessage::Hide() 62 void NotificationMessage::Hide()
64 { 63 {
65 if (toolTipWindow != 0) 64 if (toolTipWindow != 0)
66 { 65 {
67 DestroyWindow(toolTipWindow); 66 DestroyWindow(toolTipWindow);
68 toolTipWindow = 0; 67 toolTipWindow = 0;
69 } 68 }
70 } 69 }
71 70
72 void NotificationMessage::Move(short x, short y) 71 void NotificationMessage::Move(short x, short y)
73 { 72 {
74 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y)); 73 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y));
75 return; 74 return;
76 } 75 }
77 76
78 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon) 77 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon)
79 { 78 {
80 TOOLINFOW ti; 79 TOOLINFOW ti = {};
Felix Dahlke 2013/10/01 12:59:53 As above, would prefer to default initialise this
81 ti.cbSize = sizeof(TOOLINFOW); 80 ti.cbSize = sizeof(TOOLINFOW);
82 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
83 ti.hwnd = toolTipWindow; 81 ti.hwnd = toolTipWindow;
84 ti.hinst = NULL; 82 ti.hinst = NULL;
85 ti.uId = (UINT_PTR)parentWindow; 83 ti.uId = (UINT_PTR)parentWindow;
86 ti.lpszText = const_cast<LPWSTR>(text.c_str()); 84 ti.lpszText = const_cast<LPWSTR>(text.c_str());
87 GetClientRect(parentWindow, &ti.rect);
88 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c _str()); 85 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c _str());
89 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); 86 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
90 return res == TRUE; 87 return res == TRUE;
91 } 88 }
92 89
93 void NotificationMessage::SetParent(HWND parent) 90 void NotificationMessage::SetParent(HWND parent)
94 { 91 {
95 parentWindow = parent; 92 parentWindow = parent;
96 } 93 }
97 94
98 bool NotificationMessage::IsVisible() 95 bool NotificationMessage::IsVisible()
99 { 96 {
100 if (toolTipWindow == 0) 97 if (toolTipWindow == 0)
101 return false; 98 return false;
102 return IsWindowVisible(toolTipWindow); 99 return IsWindowVisible(toolTipWindow);
103 } 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