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

Side by Side Diff: remoting/host/setup/win/host_configurer_window.cc

Issue 11090063: [Chromoting] Add a simple Windows app that registers and starts a host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review. Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
(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 <atlstr.h>
9 #include <atlwin.h>
10 #include <windows.h>
11
12 #include "base/string16.h"
13 #include "remoting/host/setup/win/start_host_window.h"
14
15 namespace {
16
17 CAtlString LoadString(int id) {
18 CAtlString s;
19 s.LoadString(id);
20 return s;
21 }
22
23 } // namespace
24
25 namespace remoting {
26
27 HostConfigurerWindow::HostConfigurerWindow(
28 net::URLRequestContextGetter* url_request_context_getter)
29 : url_request_context_getter_(url_request_context_getter) {
30 }
31
32 void HostConfigurerWindow::OnCancel(UINT code, int id, HWND control) {
33 EndDialog(IDCANCEL);
34 }
35
36 void HostConfigurerWindow::OnClose() {
37 EndDialog(IDCANCEL);
38 }
39
40 LRESULT HostConfigurerWindow::OnInitDialog(HWND wparam, LPARAM lparam) {
41 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
42 ::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.
43 ::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.
44 PositionWindow();
45 return TRUE;
46 }
47
48 void HostConfigurerWindow::OnOk(UINT code, int id, HWND control) {
49 EndDialog(IDCANCEL);
50 }
51
52 void HostConfigurerWindow::OnStartHost(UINT code, int id, HWND control) {
53 StartHostWindow start_host_window(url_request_context_getter_);
54 start_host_window.DoModal();
55 }
56
57 void HostConfigurerWindow::PositionWindow() {
58 // Get the window dimensions.
59 RECT rect;
60 if (!GetWindowRect(&rect)) {
61 return;
62 }
63
64 // Position against the owner window unless it is minimized or invisible.
65 HWND owner = ::GetWindow(m_hWnd, GW_OWNER);
66 if (owner != NULL) {
67 DWORD style = ::GetWindowLong(owner, GWL_STYLE);
68 if ((style & WS_MINIMIZE) != 0 || (style & WS_VISIBLE) == 0) {
69 owner = NULL;
70 }
71 }
72
73 // Make sure that the window will not end up split by a monitor's boundary.
74 RECT area_rect;
75 if (!::SystemParametersInfo(SPI_GETWORKAREA, NULL, &area_rect, NULL)) {
76 return;
77 }
78
79 // On a multi-monitor system use the monitor where the owner window is shown.
80 RECT owner_rect = area_rect;
81 if (owner != NULL && ::GetWindowRect(owner, &owner_rect)) {
82 HMONITOR monitor = ::MonitorFromRect(&owner_rect, MONITOR_DEFAULTTONEAREST);
83 if (monitor != NULL) {
84 MONITORINFO monitor_info = {0};
85 monitor_info.cbSize = sizeof(monitor_info);
86 if (::GetMonitorInfo(monitor, &monitor_info)) {
87 area_rect = monitor_info.rcWork;
88 }
89 }
90 }
91
92 LONG width = rect.right - rect.left;
93 LONG height = rect.bottom - rect.top;
94 // Avoid the center of the owner rectangle, because the host controller will
95 // put its confirmation window there.
96 LONG x = (3 * owner_rect.left + owner_rect.right) / 4 - (width / 2);
97 LONG y = (3 * owner_rect.top + owner_rect.bottom) / 4 - (height / 2);
98
99 x = std::max(x, area_rect.left);
100 x = std::min(x, area_rect.right - width);
101 y = std::max(y, area_rect.top);
102 y = std::min(y, area_rect.bottom - width);
103
104 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
105 }
106
107 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698