| 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/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "remoting/host/chromoting_host.h" | 13 #include "remoting/host/chromoting_host.h" |
| 13 // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have | 14 // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have |
| 14 // a dependency on the plugin's resource header. | 15 // a dependency on the plugin's resource header. |
| 15 #include "remoting/host/plugin/host_plugin_resource.h" | 16 #include "remoting/host/plugin/host_plugin_resource.h" |
| 17 #include "remoting/host/ui_strings.h" |
| 16 | 18 |
| 17 // TODO(garykac): Lots of duplicated code in this file and | 19 // TODO(garykac): Lots of duplicated code in this file and |
| 18 // continue_window_win.cc. These global floating windows are temporary so | 20 // 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 | 21 // they should be deleted soon. If we need to expand this then we should |
| 20 // create a class with the shared code. | 22 // create a class with the shared code. |
| 21 | 23 |
| 22 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. | 24 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. |
| 23 // This is defined in: | 25 // This is defined in: |
| 24 // Plugin: host_plugin.cc | 26 // Plugin: host_plugin.cc |
| 25 // SimpleHost: simple_host_process.cc | 27 // SimpleHost: simple_host_process.cc |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 const std::string& username) OVERRIDE; | 40 const std::string& username) OVERRIDE; |
| 39 virtual void Hide() OVERRIDE; | 41 virtual void Hide() OVERRIDE; |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, | 44 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, |
| 43 LPARAM lParam); | 45 LPARAM lParam); |
| 44 | 46 |
| 45 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); | 47 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
| 46 | 48 |
| 47 void ShutdownHost(); | 49 void ShutdownHost(); |
| 48 void SetDisconnectButtonText(HWND hwnd); | |
| 49 void EndDialog(int result); | 50 void EndDialog(int result); |
| 51 void SetStrings(const UiStrings& strings, const std::string& username); |
| 50 | 52 |
| 51 remoting::ChromotingHost* host_; | 53 remoting::ChromotingHost* host_; |
| 52 std::string username_; | |
| 53 HWND hwnd_; | 54 HWND hwnd_; |
| 54 bool has_hotkey_; | 55 bool has_hotkey_; |
| 55 | 56 |
| 56 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); | 57 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 DisconnectWindowWin::DisconnectWindowWin() | 60 DisconnectWindowWin::DisconnectWindowWin() |
| 60 : host_(NULL), | 61 : host_(NULL), |
| 61 username_(""), | |
| 62 hwnd_(NULL), | 62 hwnd_(NULL), |
| 63 has_hotkey_(false) { | 63 has_hotkey_(false) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 DisconnectWindowWin::~DisconnectWindowWin() { | 66 DisconnectWindowWin::~DisconnectWindowWin() { |
| 67 EndDialog(0); | 67 EndDialog(0); |
| 68 } | 68 } |
| 69 | 69 |
| 70 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, | 70 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, |
| 71 WPARAM wParam, LPARAM lParam) { | 71 WPARAM wParam, LPARAM lParam) { |
| 72 DisconnectWindowWin* win = NULL; | 72 DisconnectWindowWin* win = NULL; |
| 73 if (msg == WM_INITDIALOG) { | 73 if (msg == WM_INITDIALOG) { |
| 74 win = reinterpret_cast<DisconnectWindowWin*>(lParam); | 74 win = reinterpret_cast<DisconnectWindowWin*>(lParam); |
| 75 CHECK(win); | 75 CHECK(win); |
| 76 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); | 76 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); |
| 77 } else { | 77 } else { |
| 78 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); | 78 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); |
| 79 win = reinterpret_cast<DisconnectWindowWin*>(lp); | 79 win = reinterpret_cast<DisconnectWindowWin*>(lp); |
| 80 } | 80 } |
| 81 if (win == NULL) | 81 if (win == NULL) |
| 82 return FALSE; | 82 return FALSE; |
| 83 return win->OnDialogMessage(hwnd, msg, wParam, lParam); | 83 return win->OnDialogMessage(hwnd, msg, wParam, lParam); |
| 84 } | 84 } |
| 85 | 85 |
| 86 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, | 86 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, |
| 87 WPARAM wParam, LPARAM lParam) { | 87 WPARAM wParam, LPARAM lParam) { |
| 88 switch (msg) { | 88 switch (msg) { |
| 89 case WM_INITDIALOG: | |
| 90 { | |
| 91 // Update UI string placeholders with actual strings. | |
| 92 std::wstring w_title = UTF8ToWide(kTitle); | |
| 93 SetWindowText(hwnd, w_title.c_str()); | |
| 94 | |
| 95 SetDisconnectButtonText(hwnd); | |
| 96 | |
| 97 HWND hwndSharingWith = GetDlgItem(hwnd, IDC_DISCONNECT_SHARINGWITH); | |
| 98 CHECK(hwndSharingWith); | |
| 99 std::wstring w_sharing = UTF8ToWide(kSharingWith); | |
| 100 SetWindowText(hwndSharingWith, w_sharing.c_str()); | |
| 101 | |
| 102 // Update username in dialog. | |
| 103 HWND hwndUsername = GetDlgItem(hwnd, IDC_DISCONNECT_USERNAME); | |
| 104 CHECK(hwndUsername); | |
| 105 std::wstring w_username = UTF8ToWide(username_); | |
| 106 SetWindowText(hwndUsername, w_username.c_str()); | |
| 107 } | |
| 108 return TRUE; | |
| 109 case WM_HOTKEY: | 89 case WM_HOTKEY: |
| 110 { | 90 ShutdownHost(); |
| 111 ShutdownHost(); | 91 EndDialog(0); |
| 112 EndDialog(0); | |
| 113 } | |
| 114 return TRUE; | 92 return TRUE; |
| 115 case WM_CLOSE: | 93 case WM_CLOSE: |
| 116 // Ignore close messages. | 94 // Ignore close messages. |
| 117 return TRUE; | 95 return TRUE; |
| 118 case WM_DESTROY: | 96 case WM_DESTROY: |
| 119 // Ensure we don't try to use the HWND anymore. | 97 // Ensure we don't try to use the HWND anymore. |
| 120 hwnd_ = NULL; | 98 hwnd_ = NULL; |
| 121 return TRUE; | 99 return TRUE; |
| 122 case WM_COMMAND: | 100 case WM_COMMAND: |
| 123 switch (LOWORD(wParam)) { | 101 switch (LOWORD(wParam)) { |
| 124 case IDC_DISCONNECT: | 102 case IDC_DISCONNECT: |
| 125 { | 103 ShutdownHost(); |
| 126 ShutdownHost(); | 104 EndDialog(LOWORD(wParam)); |
| 127 EndDialog(LOWORD(wParam)); | |
| 128 } | |
| 129 return TRUE; | 105 return TRUE; |
| 130 } | 106 } |
| 131 } | 107 } |
| 132 return FALSE; | 108 return FALSE; |
| 133 } | 109 } |
| 134 | 110 |
| 135 void DisconnectWindowWin::Show(ChromotingHost* host, | 111 void DisconnectWindowWin::Show(ChromotingHost* host, |
| 136 const std::string& username) { | 112 const std::string& username) { |
| 137 host_ = host; | 113 host_ = host; |
| 138 username_ = username; | |
| 139 | 114 |
| 140 CHECK(!hwnd_); | 115 CHECK(!hwnd_); |
| 141 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, | 116 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, |
| 142 (DLGPROC)DialogProc, (LPARAM)this); | 117 (DLGPROC)DialogProc, (LPARAM)this); |
| 143 if (!hwnd_) { | 118 if (!hwnd_) { |
| 144 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; | 119 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; |
| 145 return; | 120 return; |
| 146 } | 121 } |
| 147 | 122 |
| 148 ShowWindow(hwnd_, SW_SHOW); | |
| 149 | |
| 150 // Set up handler for Ctrl-Alt-Esc shortcut. | 123 // Set up handler for Ctrl-Alt-Esc shortcut. |
| 151 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, | 124 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, |
| 152 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) { | 125 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) { |
| 153 has_hotkey_ = true; | 126 has_hotkey_ = true; |
| 154 } | 127 } |
| 155 SetDisconnectButtonText(hwnd_); | 128 |
| 129 SetStrings(host->ui_strings(), username); |
| 130 ShowWindow(hwnd_, SW_SHOW); |
| 156 } | 131 } |
| 157 | 132 |
| 158 void DisconnectWindowWin::ShutdownHost() { | 133 void DisconnectWindowWin::ShutdownHost() { |
| 159 CHECK(host_); | 134 CHECK(host_); |
| 160 host_->Shutdown(NULL); | 135 host_->Shutdown(NULL); |
| 161 } | 136 } |
| 162 | 137 |
| 163 void DisconnectWindowWin::SetDisconnectButtonText(HWND hwnd) { | 138 void DisconnectWindowWin::SetStrings(const UiStrings& strings, |
| 164 HWND hwndButton = GetDlgItem(hwnd, IDC_DISCONNECT); | 139 const std::string& username) { |
| 140 SetWindowText(hwnd_, strings.product_name.c_str()); |
| 141 |
| 142 HWND hwndButton = GetDlgItem(hwnd_, IDC_DISCONNECT); |
| 165 CHECK(hwndButton); | 143 CHECK(hwndButton); |
| 166 std::wstring w_button = UTF8ToWide(kDisconnectButton); | 144 const WCHAR* label = |
| 167 if (has_hotkey_) | 145 has_hotkey_ ? strings.disconnect_button_text_plus_shortcut.c_str() |
| 168 w_button += UTF8ToWide(kDisconnectKeysWin); | 146 : strings.disconnect_button_text.c_str(); |
| 169 SetWindowText(hwndButton, w_button.c_str()); | 147 SetWindowText(hwndButton, label); |
| 148 |
| 149 HWND hwndSharingWith = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH); |
| 150 CHECK(hwndSharingWith); |
| 151 string16 text = ReplaceStringPlaceholders( |
| 152 strings.disconnect_message, UTF8ToUTF16(username), NULL); |
| 153 SetWindowText(hwndSharingWith, text.c_str()); |
| 170 } | 154 } |
| 171 | 155 |
| 172 void DisconnectWindowWin::Hide() { | 156 void DisconnectWindowWin::Hide() { |
| 173 EndDialog(0); | 157 EndDialog(0); |
| 174 } | 158 } |
| 175 | 159 |
| 176 void DisconnectWindowWin::EndDialog(int result) { | 160 void DisconnectWindowWin::EndDialog(int result) { |
| 177 if (has_hotkey_) { | 161 if (has_hotkey_) { |
| 178 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); | 162 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); |
| 179 has_hotkey_ = false; | 163 has_hotkey_ = false; |
| 180 } | 164 } |
| 181 | 165 |
| 182 if (hwnd_) { | 166 if (hwnd_) { |
| 183 ::EndDialog(hwnd_, result); | 167 ::EndDialog(hwnd_, result); |
| 184 hwnd_ = NULL; | 168 hwnd_ = NULL; |
| 185 } | 169 } |
| 186 } | 170 } |
| 187 | 171 |
| 188 DisconnectWindow* DisconnectWindow::Create() { | 172 DisconnectWindow* DisconnectWindow::Create() { |
| 189 return new DisconnectWindowWin; | 173 return new DisconnectWindowWin; |
| 190 } | 174 } |
| 191 | 175 |
| 192 } // namespace remoting | 176 } // namespace remoting |
| OLD | NEW |