Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: remoting/host/disconnect_window_win.cc

Issue 810133003: replace NULL->nullptr in src/remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/disconnect_window_linux.cc ('k') | remoting/host/dns_blackhole_checker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/process/memory.h" 9 #include "base/process/memory.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 base::win::ScopedSelectObject font( 99 base::win::ScopedSelectObject font(
100 dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0)); 100 dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0));
101 if (!DrawText(dc, text.c_str(), -1, &rect, DT_CALCRECT | DT_SINGLELINE)) 101 if (!DrawText(dc, text.c_str(), -1, &rect, DT_CALCRECT | DT_SINGLELINE))
102 return false; 102 return false;
103 103
104 *width = rect.right; 104 *width = rect.right;
105 return true; 105 return true;
106 } 106 }
107 107
108 DisconnectWindowWin::DisconnectWindowWin() 108 DisconnectWindowWin::DisconnectWindowWin()
109 : hwnd_(NULL), 109 : hwnd_(nullptr),
110 has_hotkey_(false), 110 has_hotkey_(false),
111 border_pen_(CreatePen(PS_SOLID, 5, 111 border_pen_(CreatePen(PS_SOLID, 5,
112 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) { 112 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) {
113 } 113 }
114 114
115 DisconnectWindowWin::~DisconnectWindowWin() { 115 DisconnectWindowWin::~DisconnectWindowWin() {
116 EndDialog(); 116 EndDialog();
117 } 117 }
118 118
119 void DisconnectWindowWin::Start( 119 void DisconnectWindowWin::Start(
120 const base::WeakPtr<ClientSessionControl>& client_session_control) { 120 const base::WeakPtr<ClientSessionControl>& client_session_control) {
121 DCHECK(CalledOnValidThread()); 121 DCHECK(CalledOnValidThread());
122 DCHECK(!client_session_control_); 122 DCHECK(!client_session_control_);
123 DCHECK(client_session_control); 123 DCHECK(client_session_control);
124 124
125 client_session_control_ = client_session_control; 125 client_session_control_ = client_session_control;
126 126
127 std::string client_jid = client_session_control_->client_jid(); 127 std::string client_jid = client_session_control_->client_jid();
128 username_ = client_jid.substr(0, client_jid.find('/')); 128 username_ = client_jid.substr(0, client_jid.find('/'));
129 if (!BeginDialog()) 129 if (!BeginDialog())
130 EndDialog(); 130 EndDialog();
131 } 131 }
132 132
133 INT_PTR CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, 133 INT_PTR CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd,
134 UINT message, 134 UINT message,
135 WPARAM wparam, 135 WPARAM wparam,
136 LPARAM lparam) { 136 LPARAM lparam) {
137 LONG_PTR self = NULL; 137 LONG_PTR self = 0;
138 if (message == WM_INITDIALOG) { 138 if (message == WM_INITDIALOG) {
139 self = lparam; 139 self = lparam;
140 140
141 // Store |this| to the window's user data. 141 // Store |this| to the window's user data.
142 SetLastError(ERROR_SUCCESS); 142 SetLastError(ERROR_SUCCESS);
143 LONG_PTR result = SetWindowLongPtr(hwnd, DWLP_USER, self); 143 LONG_PTR result = SetWindowLongPtr(hwnd, DWLP_USER, self);
144 if (result == 0 && GetLastError() != ERROR_SUCCESS) 144 if (result == 0 && GetLastError() != ERROR_SUCCESS)
145 reinterpret_cast<DisconnectWindowWin*>(self)->EndDialog(); 145 reinterpret_cast<DisconnectWindowWin*>(self)->EndDialog();
146 } else { 146 } else {
147 self = GetWindowLongPtr(hwnd, DWLP_USER); 147 self = GetWindowLongPtr(hwnd, DWLP_USER);
(...skipping 21 matching lines...) Expand all
169 case WM_COMMAND: 169 case WM_COMMAND:
170 switch (LOWORD(wparam)) { 170 switch (LOWORD(wparam)) {
171 case IDC_DISCONNECT: 171 case IDC_DISCONNECT:
172 EndDialog(); 172 EndDialog();
173 return TRUE; 173 return TRUE;
174 } 174 }
175 return FALSE; 175 return FALSE;
176 176
177 // Ensure we don't try to use the HWND anymore. 177 // Ensure we don't try to use the HWND anymore.
178 case WM_DESTROY: 178 case WM_DESTROY:
179 hwnd_ = NULL; 179 hwnd_ = nullptr;
180 180
181 // Ensure that the disconnect callback is invoked even if somehow our 181 // Ensure that the disconnect callback is invoked even if somehow our
182 // window gets destroyed. 182 // window gets destroyed.
183 EndDialog(); 183 EndDialog();
184 184
185 return TRUE; 185 return TRUE;
186 186
187 // Ensure the dialog stays visible if the work area dimensions change. 187 // Ensure the dialog stays visible if the work area dimensions change.
188 case WM_SETTINGCHANGE: 188 case WM_SETTINGCHANGE:
189 if (wparam == SPI_SETWORKAREA) 189 if (wparam == SPI_SETWORKAREA)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 } 223 }
224 return FALSE; 224 return FALSE;
225 } 225 }
226 226
227 bool DisconnectWindowWin::BeginDialog() { 227 bool DisconnectWindowWin::BeginDialog() {
228 DCHECK(CalledOnValidThread()); 228 DCHECK(CalledOnValidThread());
229 DCHECK(!hwnd_); 229 DCHECK(!hwnd_);
230 230
231 HMODULE module = base::GetModuleFromAddress(&DialogProc); 231 HMODULE module = base::GetModuleFromAddress(&DialogProc);
232 hwnd_ = CreateDialogParam(module, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, 232 hwnd_ = CreateDialogParam(module, MAKEINTRESOURCE(IDD_DISCONNECT), nullptr,
233 DialogProc, reinterpret_cast<LPARAM>(this)); 233 DialogProc, reinterpret_cast<LPARAM>(this));
234 if (!hwnd_) 234 if (!hwnd_)
235 return false; 235 return false;
236 236
237 // Set up handler for Ctrl-Alt-Esc shortcut. 237 // Set up handler for Ctrl-Alt-Esc shortcut.
238 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, 238 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID,
239 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) { 239 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) {
240 has_hotkey_ = true; 240 has_hotkey_ = true;
241 } 241 }
242 242
243 if (!SetStrings()) 243 if (!SetStrings())
244 return false; 244 return false;
245 245
246 SetDialogPosition(); 246 SetDialogPosition();
247 ShowWindow(hwnd_, SW_SHOW); 247 ShowWindow(hwnd_, SW_SHOW);
248 return IsWindowVisible(hwnd_) != FALSE; 248 return IsWindowVisible(hwnd_) != FALSE;
249 } 249 }
250 250
251 void DisconnectWindowWin::EndDialog() { 251 void DisconnectWindowWin::EndDialog() {
252 DCHECK(CalledOnValidThread()); 252 DCHECK(CalledOnValidThread());
253 253
254 if (has_hotkey_) { 254 if (has_hotkey_) {
255 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); 255 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID);
256 has_hotkey_ = false; 256 has_hotkey_ = false;
257 } 257 }
258 258
259 if (hwnd_) { 259 if (hwnd_) {
260 DestroyWindow(hwnd_); 260 DestroyWindow(hwnd_);
261 hwnd_ = NULL; 261 hwnd_ = nullptr;
262 } 262 }
263 263
264 if (client_session_control_) 264 if (client_session_control_)
265 client_session_control_->DisconnectSession(); 265 client_session_control_->DisconnectSession();
266 } 266 }
267 267
268 // Returns |control| rectangle in the dialog coordinates. 268 // Returns |control| rectangle in the dialog coordinates.
269 bool DisconnectWindowWin::GetControlRect(HWND control, RECT* rect) { 269 bool DisconnectWindowWin::GetControlRect(HWND control, RECT* rect) {
270 if (!GetWindowRect(control, rect)) 270 if (!GetWindowRect(control, rect))
271 return false; 271 return false;
272 SetLastError(ERROR_SUCCESS); 272 SetLastError(ERROR_SUCCESS);
273 int result = MapWindowPoints(HWND_DESKTOP, hwnd_, 273 int result = MapWindowPoints(HWND_DESKTOP, hwnd_,
274 reinterpret_cast<LPPOINT>(rect), 2); 274 reinterpret_cast<LPPOINT>(rect), 2);
275 if (!result && GetLastError() != ERROR_SUCCESS) 275 if (!result && GetLastError() != ERROR_SUCCESS)
276 return false; 276 return false;
277 277
278 return true; 278 return true;
279 } 279 }
280 280
281 void DisconnectWindowWin::SetDialogPosition() { 281 void DisconnectWindowWin::SetDialogPosition() {
282 DCHECK(CalledOnValidThread()); 282 DCHECK(CalledOnValidThread());
283 283
284 // Try to center the window above the task-bar. If that fails, use the 284 // Try to center the window above the task-bar. If that fails, use the
285 // primary monitor. If that fails (very unlikely), use the default position. 285 // primary monitor. If that fails (very unlikely), use the default position.
286 HWND taskbar = FindWindow(kShellTrayWindowName, NULL); 286 HWND taskbar = FindWindow(kShellTrayWindowName, nullptr);
287 HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); 287 HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY);
288 MONITORINFO monitor_info = {sizeof(monitor_info)}; 288 MONITORINFO monitor_info = {sizeof(monitor_info)};
289 RECT window_rect; 289 RECT window_rect;
290 if (GetMonitorInfo(monitor, &monitor_info) && 290 if (GetMonitorInfo(monitor, &monitor_info) &&
291 GetWindowRect(hwnd_, &window_rect)) { 291 GetWindowRect(hwnd_, &window_rect)) {
292 int window_width = window_rect.right - window_rect.left; 292 int window_width = window_rect.right - window_rect.left;
293 int window_height = window_rect.bottom - window_rect.top; 293 int window_height = window_rect.bottom - window_rect.top;
294 int top = monitor_info.rcWork.bottom - window_height; 294 int top = monitor_info.rcWork.bottom - window_height;
295 int left = (monitor_info.rcWork.right + monitor_info.rcWork.left - 295 int left = (monitor_info.rcWork.right + monitor_info.rcWork.left -
296 window_width) / 2; 296 window_width) / 2;
297 SetWindowPos(hwnd_, NULL, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); 297 SetWindowPos(hwnd_, nullptr, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
298 } 298 }
299 } 299 }
300 300
301 bool DisconnectWindowWin::SetStrings() { 301 bool DisconnectWindowWin::SetStrings() {
302 DCHECK(CalledOnValidThread()); 302 DCHECK(CalledOnValidThread());
303 303
304 // Localize the disconnect button text and measure length of the old and new 304 // Localize the disconnect button text and measure length of the old and new
305 // labels. 305 // labels.
306 HWND hwnd_button = GetDlgItem(hwnd_, IDC_DISCONNECT); 306 HWND hwnd_button = GetDlgItem(hwnd_, IDC_DISCONNECT);
307 HWND hwnd_message = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH); 307 HWND hwnd_message = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH);
308 if (!hwnd_button || !hwnd_message) 308 if (!hwnd_button || !hwnd_message)
309 return false; 309 return false;
310 310
311 base::string16 button_text; 311 base::string16 button_text;
312 base::string16 message_text; 312 base::string16 message_text;
313 if (!GetControlText(hwnd_button, &button_text) || 313 if (!GetControlText(hwnd_button, &button_text) ||
314 !GetControlText(hwnd_message, &message_text)) { 314 !GetControlText(hwnd_message, &message_text)) {
315 return false; 315 return false;
316 } 316 }
317 317
318 // Format and truncate "Your desktop is shared with ..." message. 318 // Format and truncate "Your desktop is shared with ..." message.
319 message_text = ReplaceStringPlaceholders(message_text, 319 message_text = ReplaceStringPlaceholders(message_text,
320 base::UTF8ToUTF16(username_), 320 base::UTF8ToUTF16(username_),
321 NULL); 321 nullptr);
322 if (message_text.length() > kMaxSharingWithTextLength) 322 if (message_text.length() > kMaxSharingWithTextLength)
323 message_text.erase(kMaxSharingWithTextLength); 323 message_text.erase(kMaxSharingWithTextLength);
324 324
325 if (!SetWindowText(hwnd_message, message_text.c_str())) 325 if (!SetWindowText(hwnd_message, message_text.c_str()))
326 return false; 326 return false;
327 327
328 // Calculate the margin between controls in pixels. 328 // Calculate the margin between controls in pixels.
329 RECT rect = {0}; 329 RECT rect = {0};
330 rect.right = kWindowTextMargin; 330 rect.right = kWindowTextMargin;
331 if (!MapDialogRect(hwnd_, &rect)) 331 if (!MapDialogRect(hwnd_, &rect))
332 return false; 332 return false;
333 int margin = rect.right; 333 int margin = rect.right;
334 334
335 // Resize |hwnd_message| so that the text is not clipped. 335 // Resize |hwnd_message| so that the text is not clipped.
336 RECT message_rect; 336 RECT message_rect;
337 if (!GetControlRect(hwnd_message, &message_rect)) 337 if (!GetControlRect(hwnd_message, &message_rect))
338 return false; 338 return false;
339 339
340 LONG control_width; 340 LONG control_width;
341 if (!GetControlTextWidth(hwnd_message, message_text, &control_width)) 341 if (!GetControlTextWidth(hwnd_message, message_text, &control_width))
342 return false; 342 return false;
343 message_rect.right = message_rect.left + control_width + margin; 343 message_rect.right = message_rect.left + control_width + margin;
344 344
345 if (!SetWindowPos(hwnd_message, NULL, 345 if (!SetWindowPos(hwnd_message, nullptr,
346 message_rect.left, message_rect.top, 346 message_rect.left, message_rect.top,
347 message_rect.right - message_rect.left, 347 message_rect.right - message_rect.left,
348 message_rect.bottom - message_rect.top, 348 message_rect.bottom - message_rect.top,
349 SWP_NOZORDER)) { 349 SWP_NOZORDER)) {
350 return false; 350 return false;
351 } 351 }
352 352
353 // Reposition and resize |hwnd_button| as well. 353 // Reposition and resize |hwnd_button| as well.
354 RECT button_rect; 354 RECT button_rect;
355 if (!GetControlRect(hwnd_button, &button_rect)) 355 if (!GetControlRect(hwnd_button, &button_rect))
356 return false; 356 return false;
357 357
358 if (!GetControlTextWidth(hwnd_button, button_text, &control_width)) 358 if (!GetControlTextWidth(hwnd_button, button_text, &control_width))
359 return false; 359 return false;
360 360
361 button_rect.left = message_rect.right; 361 button_rect.left = message_rect.right;
362 button_rect.right = button_rect.left + control_width + margin * 2; 362 button_rect.right = button_rect.left + control_width + margin * 2;
363 if (!SetWindowPos(hwnd_button, NULL, 363 if (!SetWindowPos(hwnd_button, nullptr,
364 button_rect.left, button_rect.top, 364 button_rect.left, button_rect.top,
365 button_rect.right - button_rect.left, 365 button_rect.right - button_rect.left,
366 button_rect.bottom - button_rect.top, 366 button_rect.bottom - button_rect.top,
367 SWP_NOZORDER)) { 367 SWP_NOZORDER)) {
368 return false; 368 return false;
369 } 369 }
370 370
371 // Resize the whole window to fit the resized controls. 371 // Resize the whole window to fit the resized controls.
372 RECT window_rect; 372 RECT window_rect;
373 if (!GetWindowRect(hwnd_, &window_rect)) 373 if (!GetWindowRect(hwnd_, &window_rect))
374 return false; 374 return false;
375 int width = button_rect.right + margin; 375 int width = button_rect.right + margin;
376 int height = window_rect.bottom - window_rect.top; 376 int height = window_rect.bottom - window_rect.top;
377 if (!SetWindowPos(hwnd_, NULL, 0, 0, width, height, 377 if (!SetWindowPos(hwnd_, nullptr, 0, 0, width, height,
378 SWP_NOMOVE | SWP_NOZORDER)) { 378 SWP_NOMOVE | SWP_NOZORDER)) {
379 return false; 379 return false;
380 } 380 }
381 381
382 // Make the corners of the disconnect window rounded. 382 // Make the corners of the disconnect window rounded.
383 HRGN rgn = CreateRoundRectRgn(0, 0, width, height, kWindowBorderRadius, 383 HRGN rgn = CreateRoundRectRgn(0, 0, width, height, kWindowBorderRadius,
384 kWindowBorderRadius); 384 kWindowBorderRadius);
385 if (!rgn) 385 if (!rgn)
386 return false; 386 return false;
387 if (!SetWindowRgn(hwnd_, rgn, TRUE)) 387 if (!SetWindowRgn(hwnd_, rgn, TRUE))
388 return false; 388 return false;
389 389
390 return true; 390 return true;
391 } 391 }
392 392
393 } // namespace 393 } // namespace
394 394
395 // static 395 // static
396 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { 396 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow() {
397 return make_scoped_ptr(new DisconnectWindowWin()); 397 return make_scoped_ptr(new DisconnectWindowWin());
398 } 398 }
399 399
400 } // namespace remoting 400 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/disconnect_window_linux.cc ('k') | remoting/host/dns_blackhole_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698