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..15b41a96a621decf3cce6c5c919e32e8996a8bd0 |
| --- /dev/null |
| +++ b/remoting/host/setup/win/host_configurer_window.cc |
| @@ -0,0 +1,107 @@ |
| +// 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 <atlstr.h> |
| +#include <atlwin.h> |
| +#include <windows.h> |
| + |
| +#include "base/string16.h" |
| +#include "remoting/host/setup/win/start_host_window.h" |
| + |
| +namespace { |
| + |
| +CAtlString LoadString(int id) { |
| + CAtlString s; |
| + s.LoadString(id); |
| + return s; |
| +} |
| + |
| +} // 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) { |
| + EndDialog(IDCANCEL); |
| +} |
| + |
| +void HostConfigurerWindow::OnClose() { |
| + EndDialog(IDCANCEL); |
| +} |
| + |
| +LRESULT HostConfigurerWindow::OnInitDialog(HWND wparam, LPARAM lparam) { |
| + SetWindowText(LoadString(IDS_TITLE)); |
|
alexeypa (please no reviews)
2012/10/12 17:09:35
This is the only call to LoadString. Calling CStri
simonmorris
2012/10/15 16:51:42
I've moved the code to a separate file, so it can
|
| + ::EnableWindow(GetDlgItem(IDC_CHANGE_PIN), FALSE); |
|
alexeypa (please no reviews)
2012/10/12 17:09:35
if (!GetDlgItem(IDC_CHANGE_PIN).EnableWindow(FALSE
simonmorris
2012/10/15 16:51:42
Done.
|
| + ::EnableWindow(GetDlgItem(IDC_STOP_HOST), FALSE); |
|
alexeypa (please no reviews)
2012/10/12 17:09:35
Same as above.
simonmorris
2012/10/15 16:51:42
Done.
|
| + PositionWindow(); |
| + return TRUE; |
| +} |
| + |
| +void HostConfigurerWindow::OnOk(UINT code, int id, HWND control) { |
| + EndDialog(IDCANCEL); |
| +} |
| + |
| +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; |
| + 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); |
|
alexeypa (please no reviews)
2012/10/12 17:09:35
nit: I think PositionWindow should return the stat
simonmorris
2012/10/15 16:51:42
Failure to reposition the window should never be f
|
| +} |
| + |
| +} // namespace remoting |