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

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/run_loop.h"
13 #include "base/string16.h"
14 #include "remoting/host/setup/win/load_string_from_resource.h"
15 #include "remoting/host/setup/win/start_host_window.h"
16
17 namespace remoting {
18
19 HostConfigurerWindow::HostConfigurerWindow(
20 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
21 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
22 base::Closure on_destroy)
23 : url_request_context_getter_(url_request_context_getter),
24 ui_task_runner_(ui_task_runner),
25 on_destroy_(on_destroy) {
26 }
27
28 void HostConfigurerWindow::OnCancel(UINT code, int id, HWND control) {
29 DCHECK(ui_task_runner_->BelongsToCurrentThread());
30
31 Finish();
32 }
33
34 void HostConfigurerWindow::OnClose() {
35 DCHECK(ui_task_runner_->BelongsToCurrentThread());
36
37 Finish();
38 }
39
40 LRESULT HostConfigurerWindow::OnInitDialog(HWND wparam, LPARAM lparam) {
41 DCHECK(ui_task_runner_->BelongsToCurrentThread());
42
43 // Failure of any of these calls is acceptable.
44 SetWindowText(LoadStringFromResource(IDS_TITLE));
45 GetDlgItem(IDC_CHANGE_PIN).EnableWindow(FALSE);
46 GetDlgItem(IDC_STOP_HOST).EnableWindow(FALSE);
47 PositionWindow();
48 return TRUE;
49 }
50
51 void HostConfigurerWindow::OnOk(UINT code, int id, HWND control) {
52 DCHECK(ui_task_runner_->BelongsToCurrentThread());
53
54 Finish();
55 }
56
57 void HostConfigurerWindow::OnStartHost(UINT code, int id, HWND control) {
58 DCHECK(ui_task_runner_->BelongsToCurrentThread());
59
60 StartHostWindow start_host_window(url_request_context_getter_,
61 ui_task_runner_);
62 start_host_window.DoModal();
63 }
64
65 void HostConfigurerWindow::PositionWindow() {
66 DCHECK(ui_task_runner_->BelongsToCurrentThread());
67
68 // Get the window dimensions.
69 RECT rect;
70 if (!GetWindowRect(&rect)) {
71 return;
72 }
73
74 // Position against the owner window unless it is minimized or invisible.
75 HWND owner = ::GetWindow(m_hWnd, GW_OWNER);
76 if (owner != NULL) {
77 DWORD style = ::GetWindowLong(owner, GWL_STYLE);
78 if ((style & WS_MINIMIZE) != 0 || (style & WS_VISIBLE) == 0) {
79 owner = NULL;
80 }
81 }
82
83 // Make sure that the window will not end up split by a monitor's boundary.
84 RECT area_rect;
85 if (!::SystemParametersInfo(SPI_GETWORKAREA, NULL, &area_rect, NULL)) {
86 return;
87 }
88
89 // On a multi-monitor system use the monitor where the owner window is shown.
90 RECT owner_rect = area_rect;
91 if (owner != NULL && ::GetWindowRect(owner, &owner_rect)) {
92 HMONITOR monitor = ::MonitorFromRect(&owner_rect, MONITOR_DEFAULTTONEAREST);
93 if (monitor != NULL) {
94 MONITORINFO monitor_info = {0};
95 monitor_info.cbSize = sizeof(monitor_info);
96 if (::GetMonitorInfo(monitor, &monitor_info)) {
97 area_rect = monitor_info.rcWork;
98 }
99 }
100 }
101
102 LONG width = rect.right - rect.left;
103 LONG height = rect.bottom - rect.top;
104 // Avoid the center of the owner rectangle, because the host controller will
105 // put its confirmation window there.
106 LONG x = (3 * owner_rect.left + owner_rect.right) / 4 - (width / 2);
107 LONG y = (3 * owner_rect.top + owner_rect.bottom) / 4 - (height / 2);
108
109 x = std::max(x, area_rect.left);
110 x = std::min(x, area_rect.right - width);
111 y = std::max(y, area_rect.top);
112 y = std::min(y, area_rect.bottom - width);
113
114 SetWindowPos(NULL, x, y, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
115 }
116
117 void HostConfigurerWindow::Finish() {
118 DCHECK(ui_task_runner_->BelongsToCurrentThread());
119
120 DestroyWindow();
121 on_destroy_.Run();
122 }
123
124 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698