OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/disconnect_window.h" | 5 #include "remoting/host/disconnect_window.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "remoting/host/chromoting_host.h" | 12 #include "remoting/host/chromoting_host.h" |
13 // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have | 13 // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have |
14 // a dependency on the plugin's resource header. | 14 // a dependency on the plugin's resource header. |
15 #include "remoting/host/plugin/host_plugin_resource.h" | 15 #include "remoting/host/plugin/host_plugin_resource.h" |
16 | 16 |
17 // TODO(garykac): Lots of duplicated code in this file and | 17 // TODO(garykac): Lots of duplicated code in this file and |
18 // continue_window_win.cc. These global floating windows are temporary so | 18 // continue_window_win.cc. These global floating windows are temporary so |
19 // they should be deleted soon. If we need to expand this then we should | 19 // they should be deleted soon. If we need to expand this then we should |
20 // create a class with the shared code. | 20 // create a class with the shared code. |
21 | 21 |
22 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. | 22 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. |
23 // This is defined in: | 23 // This is defined in: |
24 // Plugin: host_plugin.cc | 24 // Plugin: host_plugin.cc |
25 // SimpleHost: simple_host_process.cc | 25 // SimpleHost: simple_host_process.cc |
26 extern HMODULE g_hModule; | 26 extern HMODULE g_hModule; |
27 | 27 |
28 const int DISCONNECT_HOTKEY_ID = 1000; | |
Wez
2011/08/11 22:15:24
Is there any significance to this choice of value?
garykac
2011/08/11 23:04:49
It must be between 0x0000 and 0xbfff.
Having a na
| |
29 | |
28 namespace remoting { | 30 namespace remoting { |
29 | 31 |
30 class DisconnectWindowWin : public DisconnectWindow { | 32 class DisconnectWindowWin : public DisconnectWindow { |
31 public: | 33 public: |
32 DisconnectWindowWin(); | 34 DisconnectWindowWin(); |
33 virtual ~DisconnectWindowWin(); | 35 virtual ~DisconnectWindowWin(); |
34 | 36 |
35 virtual void Show(remoting::ChromotingHost* host, | 37 virtual void Show(remoting::ChromotingHost* host, |
36 const std::string& username) OVERRIDE; | 38 const std::string& username) OVERRIDE; |
37 virtual void Hide() OVERRIDE; | 39 virtual void Hide() OVERRIDE; |
38 | 40 |
39 private: | 41 private: |
40 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, | 42 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, |
41 LPARAM lParam); | 43 LPARAM lParam); |
42 | 44 |
43 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); | 45 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
44 | 46 |
47 void ShutdownHost(); | |
45 void EndDialog(); | 48 void EndDialog(); |
49 void RemoveKeyHandler(); | |
46 | 50 |
47 remoting::ChromotingHost* host_; | 51 remoting::ChromotingHost* host_; |
48 std::string username_; | 52 std::string username_; |
49 HWND hwnd_; | 53 HWND hwnd_; |
54 bool has_hotkey_; | |
50 | 55 |
51 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); | 56 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); |
52 }; | 57 }; |
53 | 58 |
54 DisconnectWindowWin::DisconnectWindowWin() | 59 DisconnectWindowWin::DisconnectWindowWin() |
55 : host_(NULL), | 60 : host_(NULL), |
56 username_(""), | 61 username_(""), |
57 hwnd_(NULL) { | 62 hwnd_(NULL), |
63 has_hotkey_(false) { | |
58 } | 64 } |
59 | 65 |
60 DisconnectWindowWin::~DisconnectWindowWin() { | 66 DisconnectWindowWin::~DisconnectWindowWin() { |
61 EndDialog(); | 67 EndDialog(); |
62 } | 68 } |
63 | 69 |
64 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, | 70 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, |
65 WPARAM wParam, LPARAM lParam) { | 71 WPARAM wParam, LPARAM lParam) { |
66 DisconnectWindowWin* win = NULL; | 72 DisconnectWindowWin* win = NULL; |
67 if (msg == WM_INITDIALOG) { | 73 if (msg == WM_INITDIALOG) { |
(...skipping 14 matching lines...) Expand all Loading... | |
82 switch (msg) { | 88 switch (msg) { |
83 case WM_INITDIALOG: | 89 case WM_INITDIALOG: |
84 { | 90 { |
85 // Update UI string placeholders with actual strings. | 91 // Update UI string placeholders with actual strings. |
86 std::wstring w_title = UTF8ToWide(kTitle); | 92 std::wstring w_title = UTF8ToWide(kTitle); |
87 SetWindowText(hwnd, w_title.c_str()); | 93 SetWindowText(hwnd, w_title.c_str()); |
88 | 94 |
89 HWND hwndButton = GetDlgItem(hwnd, IDC_DISCONNECT); | 95 HWND hwndButton = GetDlgItem(hwnd, IDC_DISCONNECT); |
90 CHECK(hwndButton); | 96 CHECK(hwndButton); |
91 std::wstring w_button = UTF8ToWide(kDisconnectButton); | 97 std::wstring w_button = UTF8ToWide(kDisconnectButton); |
92 w_button += UTF8ToWide(kDisconnectKeysWin); | 98 if (has_hotkey_) |
99 w_button += UTF8ToWide(kDisconnectKeysWin); | |
93 SetWindowText(hwndButton, w_button.c_str()); | 100 SetWindowText(hwndButton, w_button.c_str()); |
94 | 101 |
95 HWND hwndSharingWith = GetDlgItem(hwnd, IDC_DISCONNECT_SHARINGWITH); | 102 HWND hwndSharingWith = GetDlgItem(hwnd, IDC_DISCONNECT_SHARINGWITH); |
96 CHECK(hwndSharingWith); | 103 CHECK(hwndSharingWith); |
97 std::wstring w_sharing = UTF8ToWide(kSharingWith); | 104 std::wstring w_sharing = UTF8ToWide(kSharingWith); |
98 SetWindowText(hwndSharingWith, w_sharing.c_str()); | 105 SetWindowText(hwndSharingWith, w_sharing.c_str()); |
99 | 106 |
100 // Update username in dialog. | 107 // Update username in dialog. |
101 HWND hwndUsername = GetDlgItem(hwnd, IDC_DISCONNECT_USERNAME); | 108 HWND hwndUsername = GetDlgItem(hwnd, IDC_DISCONNECT_USERNAME); |
102 CHECK(hwndUsername); | 109 CHECK(hwndUsername); |
103 std::wstring w_username = UTF8ToWide(username_); | 110 std::wstring w_username = UTF8ToWide(username_); |
104 SetWindowText(hwndUsername, w_username.c_str()); | 111 SetWindowText(hwndUsername, w_username.c_str()); |
105 } | 112 } |
106 return TRUE; | 113 return TRUE; |
114 case WM_HOTKEY: | |
115 { | |
116 ShutdownHost(); | |
117 EndDialog(); | |
118 } | |
119 return TRUE; | |
107 case WM_CLOSE: | 120 case WM_CLOSE: |
108 // Ignore close messages. | 121 // Ignore close messages. |
109 return TRUE; | 122 return TRUE; |
110 case WM_DESTROY: | 123 case WM_DESTROY: |
111 // Ensure we don't try to use the HWND anymore. | 124 // Ensure we don't try to use the HWND anymore. |
112 hwnd_ = NULL; | 125 hwnd_ = NULL; |
113 return TRUE; | 126 return TRUE; |
114 case WM_COMMAND: | 127 case WM_COMMAND: |
115 switch (LOWORD(wParam)) { | 128 switch (LOWORD(wParam)) { |
116 case IDC_DISCONNECT: | 129 case IDC_DISCONNECT: |
117 { | 130 { |
118 CHECK(host_); | 131 ShutdownHost(); |
119 host_->Shutdown(NULL); | 132 RemoveKeyHandler(); |
120 ::EndDialog(hwnd, LOWORD(wParam)); | 133 ::EndDialog(hwnd, LOWORD(wParam)); |
121 hwnd_ = NULL; | 134 hwnd_ = NULL; |
Wez
2011/08/11 22:15:24
These lines look almost identical to EndDialog() b
garykac
2011/08/11 23:04:49
I was sortof trying to avoid having a |result| par
garykac
2011/08/11 23:04:49
I was sortof trying to avoid having a |result| par
| |
122 } | 135 } |
123 return TRUE; | 136 return TRUE; |
124 } | 137 } |
125 } | 138 } |
126 return FALSE; | 139 return FALSE; |
127 } | 140 } |
128 | 141 |
129 void DisconnectWindowWin::Show(ChromotingHost* host, | 142 void DisconnectWindowWin::Show(ChromotingHost* host, |
130 const std::string& username) { | 143 const std::string& username) { |
131 host_ = host; | 144 host_ = host; |
132 username_ = username; | 145 username_ = username; |
133 | 146 |
134 CHECK(!hwnd_); | 147 CHECK(!hwnd_); |
135 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, | 148 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, |
136 (DLGPROC)DialogProc, (LPARAM)this); | 149 (DLGPROC)DialogProc, (LPARAM)this); |
137 if (!hwnd_) { | 150 if (!hwnd_) { |
138 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; | 151 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; |
139 return; | 152 return; |
140 } | 153 } |
141 | 154 |
142 ShowWindow(hwnd_, SW_SHOW); | 155 ShowWindow(hwnd_, SW_SHOW); |
156 | |
157 // Set up handler for Ctrl-Alt-Esc shortcut. | |
158 if (!has_hotkey_) { | |
159 RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, MOD_ALT | MOD_CONTROL, | |
160 VK_ESCAPE); | |
Wez
2011/08/11 22:15:24
I thought we were going to not display the hot-key
garykac
2011/08/11 23:04:49
Added SetDisconnectButtonText call here. Previousl
Wez
2011/08/11 23:58:30
My point is not about when you set the button text
garykac
2011/08/12 00:23:16
Argh. I completely missed that point (which Jamie
| |
161 has_hotkey_ = true; | |
162 } | |
163 } | |
164 | |
165 void DisconnectWindowWin::ShutdownHost() { | |
166 CHECK(host_); | |
167 host_->Shutdown(NULL); | |
143 } | 168 } |
144 | 169 |
145 void DisconnectWindowWin::Hide() { | 170 void DisconnectWindowWin::Hide() { |
146 EndDialog(); | 171 EndDialog(); |
147 } | 172 } |
148 | 173 |
149 void DisconnectWindowWin::EndDialog() { | 174 void DisconnectWindowWin::EndDialog() { |
175 RemoveKeyHandler(); | |
150 if (hwnd_) { | 176 if (hwnd_) { |
151 ::EndDialog(hwnd_, 0); | 177 ::EndDialog(hwnd_, 0); |
152 hwnd_ = NULL; | 178 hwnd_ = NULL; |
153 } | 179 } |
154 } | 180 } |
155 | 181 |
182 void DisconnectWindowWin::RemoveKeyHandler() { | |
Wez
2011/08/11 22:15:24
nit: Does this really need to be a separate functi
garykac
2011/08/11 23:04:49
*need*? No. But it's called from multiple places
Wez
2011/08/11 23:58:30
It's called from two places, both of which then do
garykac
2011/08/12 00:23:16
Actually it's called in 1 place now that EndDialog
| |
183 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); | |
184 has_hotkey_ = false; | |
185 } | |
186 | |
156 DisconnectWindow* DisconnectWindow::Create() { | 187 DisconnectWindow* DisconnectWindow::Create() { |
157 return new DisconnectWindowWin; | 188 return new DisconnectWindowWin; |
158 } | 189 } |
159 | 190 |
160 } // namespace remoting | 191 } // namespace remoting |
OLD | NEW |