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

Side by Side Diff: remoting/host/disconnect_window_win.cc

Issue 7613009: Add support for Disconnect hot key in Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
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
45 void EndDialog(); 47 void ShutdownHost();
48 void SetDisconnectButtonText(HWND hwnd);
49 void EndDialog(int result);
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(0);
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) {
68 win = reinterpret_cast<DisconnectWindowWin*>(lParam); 74 win = reinterpret_cast<DisconnectWindowWin*>(lParam);
69 CHECK(win); 75 CHECK(win);
70 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); 76 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win);
71 } else { 77 } else {
72 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); 78 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER);
73 win = reinterpret_cast<DisconnectWindowWin*>(lp); 79 win = reinterpret_cast<DisconnectWindowWin*>(lp);
74 } 80 }
75 if (win == NULL) 81 if (win == NULL)
76 return FALSE; 82 return FALSE;
77 return win->OnDialogMessage(hwnd, msg, wParam, lParam); 83 return win->OnDialogMessage(hwnd, msg, wParam, lParam);
78 } 84 }
79 85
80 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, 86 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
81 WPARAM wParam, LPARAM lParam) { 87 WPARAM wParam, LPARAM lParam) {
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 SetDisconnectButtonText(hwnd);
90 CHECK(hwndButton);
91 std::wstring w_button = UTF8ToWide(kDisconnectButton);
92 w_button += UTF8ToWide(kDisconnectKeysWin);
93 SetWindowText(hwndButton, w_button.c_str());
94 96
95 HWND hwndSharingWith = GetDlgItem(hwnd, IDC_DISCONNECT_SHARINGWITH); 97 HWND hwndSharingWith = GetDlgItem(hwnd, IDC_DISCONNECT_SHARINGWITH);
96 CHECK(hwndSharingWith); 98 CHECK(hwndSharingWith);
97 std::wstring w_sharing = UTF8ToWide(kSharingWith); 99 std::wstring w_sharing = UTF8ToWide(kSharingWith);
98 SetWindowText(hwndSharingWith, w_sharing.c_str()); 100 SetWindowText(hwndSharingWith, w_sharing.c_str());
99 101
100 // Update username in dialog. 102 // Update username in dialog.
101 HWND hwndUsername = GetDlgItem(hwnd, IDC_DISCONNECT_USERNAME); 103 HWND hwndUsername = GetDlgItem(hwnd, IDC_DISCONNECT_USERNAME);
102 CHECK(hwndUsername); 104 CHECK(hwndUsername);
103 std::wstring w_username = UTF8ToWide(username_); 105 std::wstring w_username = UTF8ToWide(username_);
104 SetWindowText(hwndUsername, w_username.c_str()); 106 SetWindowText(hwndUsername, w_username.c_str());
105 } 107 }
106 return TRUE; 108 return TRUE;
109 case WM_HOTKEY:
110 {
111 ShutdownHost();
112 EndDialog(0);
113 }
114 return TRUE;
107 case WM_CLOSE: 115 case WM_CLOSE:
108 // Ignore close messages. 116 // Ignore close messages.
109 return TRUE; 117 return TRUE;
110 case WM_DESTROY: 118 case WM_DESTROY:
111 // Ensure we don't try to use the HWND anymore. 119 // Ensure we don't try to use the HWND anymore.
112 hwnd_ = NULL; 120 hwnd_ = NULL;
113 return TRUE; 121 return TRUE;
114 case WM_COMMAND: 122 case WM_COMMAND:
115 switch (LOWORD(wParam)) { 123 switch (LOWORD(wParam)) {
116 case IDC_DISCONNECT: 124 case IDC_DISCONNECT:
117 { 125 {
118 CHECK(host_); 126 ShutdownHost();
119 host_->Shutdown(NULL); 127 EndDialog(LOWORD(wParam));
120 ::EndDialog(hwnd, LOWORD(wParam));
121 hwnd_ = NULL;
122 } 128 }
123 return TRUE; 129 return TRUE;
124 } 130 }
125 } 131 }
126 return FALSE; 132 return FALSE;
127 } 133 }
128 134
129 void DisconnectWindowWin::Show(ChromotingHost* host, 135 void DisconnectWindowWin::Show(ChromotingHost* host,
130 const std::string& username) { 136 const std::string& username) {
131 host_ = host; 137 host_ = host;
132 username_ = username; 138 username_ = username;
133 139
134 CHECK(!hwnd_); 140 CHECK(!hwnd_);
135 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, 141 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL,
136 (DLGPROC)DialogProc, (LPARAM)this); 142 (DLGPROC)DialogProc, (LPARAM)this);
137 if (!hwnd_) { 143 if (!hwnd_) {
138 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; 144 LOG(ERROR) << "Unable to create Disconnect dialog for remoting.";
139 return; 145 return;
140 } 146 }
141 147
142 ShowWindow(hwnd_, SW_SHOW); 148 ShowWindow(hwnd_, SW_SHOW);
149
150 // Set up handler for Ctrl-Alt-Esc shortcut.
151 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID,
152 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) {
153 has_hotkey_ = true;
154 }
155 SetDisconnectButtonText(hwnd_);
156 }
157
158 void DisconnectWindowWin::ShutdownHost() {
159 CHECK(host_);
160 host_->Shutdown(NULL);
161 }
162
163 void DisconnectWindowWin::SetDisconnectButtonText(HWND hwnd) {
164 HWND hwndButton = GetDlgItem(hwnd, IDC_DISCONNECT);
165 CHECK(hwndButton);
166 std::wstring w_button = UTF8ToWide(kDisconnectButton);
167 if (has_hotkey_)
168 w_button += UTF8ToWide(kDisconnectKeysWin);
169 SetWindowText(hwndButton, w_button.c_str());
143 } 170 }
144 171
145 void DisconnectWindowWin::Hide() { 172 void DisconnectWindowWin::Hide() {
146 EndDialog(); 173 EndDialog(0);
147 } 174 }
148 175
149 void DisconnectWindowWin::EndDialog() { 176 void DisconnectWindowWin::EndDialog(int result) {
177 if (has_hotkey_) {
178 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID);
179 has_hotkey_ = false;
180 }
181
150 if (hwnd_) { 182 if (hwnd_) {
151 ::EndDialog(hwnd_, 0); 183 ::EndDialog(hwnd_, result);
152 hwnd_ = NULL; 184 hwnd_ = NULL;
153 } 185 }
154 } 186 }
155 187
156 DisconnectWindow* DisconnectWindow::Create() { 188 DisconnectWindow* DisconnectWindow::Create() {
157 return new DisconnectWindowWin; 189 return new DisconnectWindowWin;
158 } 190 }
159 191
160 } // namespace remoting 192 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698