Index: remoting/host/disconnect_window_win.cc |
=================================================================== |
--- remoting/host/disconnect_window_win.cc (revision 96410) |
+++ remoting/host/disconnect_window_win.cc (working copy) |
@@ -25,6 +25,8 @@ |
// SimpleHost: simple_host_process.cc |
extern HMODULE g_hModule; |
+const int DISCONNECT_HOTKEY_ID = 1000; |
+ |
namespace remoting { |
class DisconnectWindowWin : public DisconnectWindow { |
@@ -42,11 +44,15 @@ |
BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
- void EndDialog(); |
+ void ShutdownHost(); |
+ void SetDisconnectButtonText(HWND hwnd); |
+ void EndDialog(int result); |
+ void RemoveKeyHandler(); |
remoting::ChromotingHost* host_; |
std::string username_; |
HWND hwnd_; |
+ bool has_hotkey_; |
DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); |
}; |
@@ -54,11 +60,12 @@ |
DisconnectWindowWin::DisconnectWindowWin() |
: host_(NULL), |
username_(""), |
- hwnd_(NULL) { |
+ hwnd_(NULL), |
+ has_hotkey_(false) { |
} |
DisconnectWindowWin::~DisconnectWindowWin() { |
- EndDialog(); |
+ EndDialog(0); |
} |
BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, |
@@ -86,11 +93,7 @@ |
std::wstring w_title = UTF8ToWide(kTitle); |
SetWindowText(hwnd, w_title.c_str()); |
- HWND hwndButton = GetDlgItem(hwnd, IDC_DISCONNECT); |
- CHECK(hwndButton); |
- std::wstring w_button = UTF8ToWide(kDisconnectButton); |
- w_button += UTF8ToWide(kDisconnectKeysWin); |
- SetWindowText(hwndButton, w_button.c_str()); |
+ SetDisconnectButtonText(hwnd); |
HWND hwndSharingWith = GetDlgItem(hwnd, IDC_DISCONNECT_SHARINGWITH); |
CHECK(hwndSharingWith); |
@@ -104,6 +107,12 @@ |
SetWindowText(hwndUsername, w_username.c_str()); |
} |
return TRUE; |
+ case WM_HOTKEY: |
+ { |
+ ShutdownHost(); |
+ EndDialog(0); |
+ } |
+ return TRUE; |
case WM_CLOSE: |
// Ignore close messages. |
return TRUE; |
@@ -115,10 +124,8 @@ |
switch (LOWORD(wParam)) { |
case IDC_DISCONNECT: |
{ |
- CHECK(host_); |
- host_->Shutdown(NULL); |
- ::EndDialog(hwnd, LOWORD(wParam)); |
- hwnd_ = NULL; |
+ ShutdownHost(); |
+ EndDialog(LOWORD(wParam)); |
} |
return TRUE; |
} |
@@ -140,19 +147,47 @@ |
} |
ShowWindow(hwnd_, SW_SHOW); |
+ |
+ // Set up handler for Ctrl-Alt-Esc shortcut. |
+ if (!has_hotkey_) { |
+ RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, MOD_ALT | MOD_CONTROL, |
+ VK_ESCAPE); |
+ has_hotkey_ = true; |
Jamie
2011/08/12 00:00:33
Surely this depends on the return value of Registe
garykac
2011/08/12 00:23:16
Surely I shouldn't be writing code today... :-(
|
+ } |
+ SetDisconnectButtonText(hwnd_); |
} |
+void DisconnectWindowWin::ShutdownHost() { |
+ CHECK(host_); |
+ host_->Shutdown(NULL); |
+} |
+ |
+void DisconnectWindowWin::SetDisconnectButtonText(HWND hwnd) { |
+ HWND hwndButton = GetDlgItem(hwnd, IDC_DISCONNECT); |
+ CHECK(hwndButton); |
+ std::wstring w_button = UTF8ToWide(kDisconnectButton); |
+ if (has_hotkey_) |
+ w_button += UTF8ToWide(kDisconnectKeysWin); |
+ SetWindowText(hwndButton, w_button.c_str()); |
+} |
+ |
void DisconnectWindowWin::Hide() { |
- EndDialog(); |
+ EndDialog(0); |
} |
-void DisconnectWindowWin::EndDialog() { |
+void DisconnectWindowWin::EndDialog(int result) { |
+ RemoveKeyHandler(); |
if (hwnd_) { |
- ::EndDialog(hwnd_, 0); |
+ ::EndDialog(hwnd_, result); |
hwnd_ = NULL; |
} |
} |
+void DisconnectWindowWin::RemoveKeyHandler() { |
+ UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); |
Jamie
2011/08/12 00:00:33
Should be conditional on has_hotkey_
garykac
2011/08/12 00:23:16
Done.
|
+ has_hotkey_ = false; |
+} |
+ |
DisconnectWindow* DisconnectWindow::Create() { |
return new DisconnectWindowWin; |
} |