Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/setup/win/host_configurer_window.h" | |
| 6 | |
| 7 #include <atlbase.h> | |
| 8 #include <atlwin.h> | |
| 9 #include <windows.h> | |
| 10 | |
| 11 #include "base/string16.h" | |
| 12 #include "remoting/host/setup/win/start_host_window.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 string16 LoadString(int id) { | |
| 17 const int kMaxStringSize = 8 * 1024; | |
| 18 scoped_array<char16> str(new char16[kMaxStringSize + 1]); | |
| 19 int result = ::LoadString(NULL, id, str.get(), kMaxStringSize); | |
|
alexeypa (please no reviews)
2012/10/11 16:57:52
According to MSDN if you pass 0 as the size of the
simonmorris
2012/10/11 21:27:35
Removed.
| |
| 20 str[std::min(result, kMaxStringSize)] = 0; | |
|
alexeypa (please no reviews)
2012/10/11 16:57:52
LoadString NULL terminates the string during trunc
simonmorris
2012/10/11 21:27:35
Removed.
| |
| 21 return string16(str.get()); | |
|
alexeypa (please no reviews)
2012/10/11 16:57:52
nit: This will scan the string again to find '\0'.
simonmorris
2012/10/11 21:27:35
Removed.
| |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace remoting { | |
| 27 | |
| 28 HostConfigurerWindow::HostConfigurerWindow( | |
| 29 net::URLRequestContextGetter* url_request_context_getter) | |
| 30 : url_request_context_getter_(url_request_context_getter) { | |
| 31 } | |
| 32 | |
| 33 void HostConfigurerWindow::OnCancel(UINT code, int id, HWND control) { | |
| 34 ExitProcess(0); | |
|
alexeypa (please no reviews)
2012/10/11 16:57:52
ExitProcess is a bad way to exit a process having
simonmorris
2012/10/11 21:27:35
EndDialog works, and seems more appropriate.
| |
| 35 } | |
| 36 | |
| 37 void HostConfigurerWindow::OnClose() { | |
| 38 ExitProcess(0); | |
| 39 } | |
| 40 | |
| 41 LRESULT HostConfigurerWindow::OnInitDialog(HWND wparam, LPARAM lparam) { | |
| 42 SetWindowText(LoadString(IDS_TITLE).c_str()); | |
|
alexeypa (please no reviews)
2012/10/11 16:57:52
Since you are using ATL, CWindow class provides ni
simonmorris
2012/10/11 21:27:35
I didn't find anything that could simplify the lin
| |
| 43 ::EnableWindow(GetDlgItem(IDC_CHANGE_PIN), FALSE); | |
|
alexeypa (please no reviews)
2012/10/11 16:57:52
nit you don't need to force the global scope here.
simonmorris
2012/10/11 21:27:35
I do, because of the nice wrapper for EnableWindow
| |
| 44 ::EnableWindow(GetDlgItem(IDC_STOP_HOST), FALSE); | |
| 45 PositionWindow(); | |
| 46 return TRUE; | |
| 47 } | |
| 48 | |
| 49 void HostConfigurerWindow::OnOk(UINT code, int id, HWND control) { | |
| 50 ExitProcess(0); | |
| 51 } | |
| 52 | |
| 53 void HostConfigurerWindow::OnStartHost(UINT code, int id, HWND control) { | |
| 54 StartHostWindow start_host_window(url_request_context_getter_); | |
| 55 start_host_window.DoModal(); | |
| 56 } | |
| 57 | |
| 58 void HostConfigurerWindow::PositionWindow() { | |
| 59 // Get the window dimensions. | |
| 60 RECT rect; | |
| 61 if (!GetWindowRect(&rect)) { | |
| 62 return; | |
| 63 } | |
| 64 | |
| 65 // Position against the owner window unless it is minimized or invisible. | |
| 66 HWND owner = ::GetWindow(m_hWnd, GW_OWNER); | |
| 67 if (owner != NULL) { | |
| 68 DWORD style = ::GetWindowLong(owner, GWL_STYLE); | |
| 69 if ((style & WS_MINIMIZE) != 0 || (style & WS_VISIBLE) == 0) { | |
| 70 owner = NULL; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 // Make sure that the window will not end up split by a monitor's boundary. | |
| 75 RECT area_rect; | |
| 76 if (!::SystemParametersInfo(SPI_GETWORKAREA, NULL, &area_rect, NULL)) { | |
| 77 return; | |
| 78 } | |
| 79 | |
| 80 // On a multi-monitor system use the monitor where the owner window is shown. | |
| 81 RECT owner_rect = area_rect; | |
| 82 if (owner != NULL && ::GetWindowRect(owner, &owner_rect)) { | |
| 83 HMONITOR monitor = ::MonitorFromRect(&owner_rect, MONITOR_DEFAULTTONEAREST); | |
| 84 if (monitor != NULL) { | |
| 85 MONITORINFO monitor_info = {0}; | |
| 86 monitor_info.cbSize = sizeof(monitor_info); | |
| 87 if (::GetMonitorInfo(monitor, &monitor_info)) { | |
| 88 area_rect = monitor_info.rcWork; | |
| 89 } | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 LONG width = rect.right - rect.left; | |
|
alexeypa (please no reviews)
2012/10/11 16:57:52
nit: Does this math work on 1024x768 resolution?
simonmorris
2012/10/11 21:27:35
Yes.
| |
| 94 LONG height = rect.bottom - rect.top; | |
| 95 // Avoid the center of the owner rectangle, because the host controller will | |
| 96 // put its confirmation window there. | |
| 97 LONG x = (3 * owner_rect.left + owner_rect.right) / 4 - (width / 2); | |
| 98 LONG y = (3 * owner_rect.top + owner_rect.bottom) / 4 - (height / 2); | |
| 99 | |
| 100 x = std::max(x, area_rect.left); | |
| 101 x = std::min(x, area_rect.right - width); | |
| 102 y = std::max(y, area_rect.top); | |
| 103 y = std::min(y, area_rect.bottom - width); | |
| 104 | |
| 105 SetWindowPos(NULL, x, y, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | |
| 106 } | |
| 107 | |
| 108 } // namespace remoting | |
| OLD | NEW |