Chromium Code Reviews| Index: remoting/host/setup/win/host_configurer_window.cc |
| diff --git a/remoting/host/setup/win/host_configurer_window.cc b/remoting/host/setup/win/host_configurer_window.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..869cedc17c520521042d5992d33fd179c1923251 |
| --- /dev/null |
| +++ b/remoting/host/setup/win/host_configurer_window.cc |
| @@ -0,0 +1,108 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/setup/win/host_configurer_window.h" |
| + |
| +#include <atlbase.h> |
| +#include <atlwin.h> |
| +#include <windows.h> |
| + |
| +#include "base/string16.h" |
| +#include "remoting/host/setup/win/start_host_window.h" |
| + |
| +namespace { |
| + |
| +string16 LoadString(int id) { |
| + const int kMaxStringSize = 8 * 1024; |
| + scoped_array<char16> str(new char16[kMaxStringSize + 1]); |
| + 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.
|
| + 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.
|
| + 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.
|
| +} |
| + |
| +} // namespace |
| + |
| +namespace remoting { |
| + |
| +HostConfigurerWindow::HostConfigurerWindow( |
| + net::URLRequestContextGetter* url_request_context_getter) |
| + : url_request_context_getter_(url_request_context_getter) { |
| +} |
| + |
| +void HostConfigurerWindow::OnCancel(UINT code, int id, HWND control) { |
| + 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.
|
| +} |
| + |
| +void HostConfigurerWindow::OnClose() { |
| + ExitProcess(0); |
| +} |
| + |
| +LRESULT HostConfigurerWindow::OnInitDialog(HWND wparam, LPARAM lparam) { |
| + 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
|
| + ::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
|
| + ::EnableWindow(GetDlgItem(IDC_STOP_HOST), FALSE); |
| + PositionWindow(); |
| + return TRUE; |
| +} |
| + |
| +void HostConfigurerWindow::OnOk(UINT code, int id, HWND control) { |
| + ExitProcess(0); |
| +} |
| + |
| +void HostConfigurerWindow::OnStartHost(UINT code, int id, HWND control) { |
| + StartHostWindow start_host_window(url_request_context_getter_); |
| + start_host_window.DoModal(); |
| +} |
| + |
| +void HostConfigurerWindow::PositionWindow() { |
| + // Get the window dimensions. |
| + RECT rect; |
| + if (!GetWindowRect(&rect)) { |
| + return; |
| + } |
| + |
| + // Position against the owner window unless it is minimized or invisible. |
| + HWND owner = ::GetWindow(m_hWnd, GW_OWNER); |
| + if (owner != NULL) { |
| + DWORD style = ::GetWindowLong(owner, GWL_STYLE); |
| + if ((style & WS_MINIMIZE) != 0 || (style & WS_VISIBLE) == 0) { |
| + owner = NULL; |
| + } |
| + } |
| + |
| + // Make sure that the window will not end up split by a monitor's boundary. |
| + RECT area_rect; |
| + if (!::SystemParametersInfo(SPI_GETWORKAREA, NULL, &area_rect, NULL)) { |
| + return; |
| + } |
| + |
| + // On a multi-monitor system use the monitor where the owner window is shown. |
| + RECT owner_rect = area_rect; |
| + if (owner != NULL && ::GetWindowRect(owner, &owner_rect)) { |
| + HMONITOR monitor = ::MonitorFromRect(&owner_rect, MONITOR_DEFAULTTONEAREST); |
| + if (monitor != NULL) { |
| + MONITORINFO monitor_info = {0}; |
| + monitor_info.cbSize = sizeof(monitor_info); |
| + if (::GetMonitorInfo(monitor, &monitor_info)) { |
| + area_rect = monitor_info.rcWork; |
| + } |
| + } |
| + } |
| + |
| + 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.
|
| + LONG height = rect.bottom - rect.top; |
| + // Avoid the center of the owner rectangle, because the host controller will |
| + // put its confirmation window there. |
| + LONG x = (3 * owner_rect.left + owner_rect.right) / 4 - (width / 2); |
| + LONG y = (3 * owner_rect.top + owner_rect.bottom) / 4 - (height / 2); |
| + |
| + x = std::max(x, area_rect.left); |
| + x = std::min(x, area_rect.right - width); |
| + y = std::max(y, area_rect.top); |
| + y = std::min(y, area_rect.bottom - width); |
| + |
| + SetWindowPos(NULL, x, y, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
| +} |
| + |
| +} // namespace remoting |