| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/screen_capture_notification_ui.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/i18n/rtl.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "base/win/scoped_gdi_object.h" | 15 #include "base/win/scoped_gdi_object.h" |
| 15 #include "base/win/scoped_hdc.h" | 16 #include "base/win/scoped_hdc.h" |
| 16 #include "base/win/scoped_select_object.h" | 17 #include "base/win/scoped_select_object.h" |
| 17 #include "remoting/host/ui_strings.h" | 18 #include "chrome/app/chrome_dll_resource.h" |
| 18 #include "remoting/host/win/core_resource.h" | 19 #include "grit/generated_resources.h" |
| 19 | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 // TODO(garykac): Lots of duplicated code in this file and | |
| 21 // continue_window_win.cc. If we need to expand this then we should | |
| 22 // create a class with the shared code. | |
| 23 | 21 |
| 24 namespace { | 22 namespace { |
| 25 | 23 |
| 26 const int DISCONNECT_HOTKEY_ID = 1000; | |
| 27 | |
| 28 // Maximum length of "Your desktop is shared with ..." message in UTF-16 | 24 // Maximum length of "Your desktop is shared with ..." message in UTF-16 |
| 29 // characters. | 25 // characters. |
| 30 const size_t kMaxSharingWithTextLength = 100; | 26 const size_t kMaxSharingWithTextLength = 100; |
| 31 | 27 |
| 32 const wchar_t kShellTrayWindowName[] = L"Shell_TrayWnd"; | 28 const wchar_t kShellTrayWindowName[] = L"Shell_TrayWnd"; |
| 33 const int kWindowBorderRadius = 14; | 29 const int kWindowBorderRadius = 14; |
| 34 | 30 |
| 35 } // namespace anonymous | 31 } // namespace anonymous |
| 36 | 32 |
| 37 namespace remoting { | 33 class ScreenCaptureNotificationUIWin : public ScreenCaptureNotificationUI { |
| 34 public: |
| 35 ScreenCaptureNotificationUIWin(); |
| 36 virtual ~ScreenCaptureNotificationUIWin(); |
| 38 | 37 |
| 39 class DisconnectWindowWin : public DisconnectWindow { | 38 // ScreenCaptureNotificationUI interface. |
| 40 public: | 39 virtual bool Show(const base::Closure& stop_callback, |
| 41 explicit DisconnectWindowWin(const UiStrings* ui_strings); | 40 const string16& title) OVERRIDE; |
| 42 virtual ~DisconnectWindowWin(); | |
| 43 | 41 |
| 44 // DisconnectWindow interface. | 42 private: |
| 45 virtual bool Show(const base::Closure& disconnect_callback, | |
| 46 const std::string& username) OVERRIDE; | |
| 47 virtual void Hide() OVERRIDE; | |
| 48 | |
| 49 private: | |
| 50 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wparam, | 43 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wparam, |
| 51 LPARAM lparam); | 44 LPARAM lparam); |
| 52 | 45 |
| 53 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); | 46 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
| 54 | 47 |
| 55 // Creates the dialog window and registers the disconnect hot key. | 48 // Creates the dialog window. |
| 56 bool BeginDialog(const std::string& username); | 49 bool BeginDialog(const string16& title); |
| 57 | 50 |
| 58 // Closes the dialog, unregisters the hot key and invokes the disconnect | 51 // Closes the dialog and invokes the disconnect callback, if set. |
| 59 // callback, if set. | |
| 60 void EndDialog(); | 52 void EndDialog(); |
| 61 | 53 |
| 62 // Trys to position the dialog window above the taskbar. | 54 // Trys to position the dialog window above the taskbar. |
| 63 void SetDialogPosition(); | 55 void SetDialogPosition(); |
| 64 | 56 |
| 65 // Applies localization string and resizes the dialog. | 57 // Applies localization string and resizes the dialog. |
| 66 bool SetStrings(const string16& username); | 58 bool UpdateStrings(const string16& title); |
| 67 | 59 |
| 68 base::Closure disconnect_callback_; | 60 base::Closure stop_callback_; |
| 69 HWND hwnd_; | 61 HWND hwnd_; |
| 70 bool has_hotkey_; | |
| 71 base::win::ScopedGDIObject<HPEN> border_pen_; | 62 base::win::ScopedGDIObject<HPEN> border_pen_; |
| 72 | 63 |
| 73 // Points to the localized strings. | 64 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUIWin); |
| 74 const UiStrings* ui_strings_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); | |
| 77 }; | 65 }; |
| 78 | 66 |
| 79 static int GetControlTextWidth(HWND control) { | 67 static int GetControlTextWidth(HWND control) { |
| 80 RECT rect = {0, 0, 0, 0}; | 68 RECT rect = {0, 0, 0, 0}; |
| 81 WCHAR text[256]; | 69 WCHAR text[256]; |
| 82 int result = GetWindowText(control, text, arraysize(text)); | 70 int result = GetWindowText(control, text, arraysize(text)); |
| 83 if (result) { | 71 if (result) { |
| 84 base::win::ScopedGetDC dc(control); | 72 base::win::ScopedGetDC dc(control); |
| 85 base::win::ScopedSelectObject font( | 73 base::win::ScopedSelectObject font( |
| 86 dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0)); | 74 dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0)); |
| 87 DrawText(dc, text, -1, &rect, DT_CALCRECT | DT_SINGLELINE); | 75 DrawText(dc, text, -1, &rect, DT_CALCRECT | DT_SINGLELINE); |
| 88 } | 76 } |
| 89 return rect.right; | 77 return rect.right; |
| 90 } | 78 } |
| 91 | 79 |
| 92 DisconnectWindowWin::DisconnectWindowWin(const UiStrings* ui_strings) | 80 ScreenCaptureNotificationUIWin::ScreenCaptureNotificationUIWin() |
| 93 : hwnd_(NULL), | 81 : hwnd_(NULL), |
| 94 has_hotkey_(false), | |
| 95 border_pen_(CreatePen(PS_SOLID, 5, | 82 border_pen_(CreatePen(PS_SOLID, 5, |
| 96 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))), | 83 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) { |
| 97 ui_strings_(ui_strings) { | |
| 98 } | 84 } |
| 99 | 85 |
| 100 DisconnectWindowWin::~DisconnectWindowWin() { | 86 ScreenCaptureNotificationUIWin::~ScreenCaptureNotificationUIWin() { |
| 101 Hide(); | 87 stop_callback_.Reset(); |
| 88 EndDialog(); |
| 102 } | 89 } |
| 103 | 90 |
| 104 bool DisconnectWindowWin::Show(const base::Closure& disconnect_callback, | 91 bool ScreenCaptureNotificationUIWin::Show( |
| 105 const std::string& username) { | 92 const base::Closure& stop_callback, |
| 106 DCHECK(disconnect_callback_.is_null()); | 93 const string16& title) { |
| 107 DCHECK(!disconnect_callback.is_null()); | 94 DCHECK(stop_callback_.is_null()); |
| 95 DCHECK(!stop_callback.is_null()); |
| 108 | 96 |
| 109 disconnect_callback_ = disconnect_callback; | 97 stop_callback_ = stop_callback; |
| 110 | 98 |
| 111 if (BeginDialog(username)) { | 99 if (BeginDialog(title)) { |
| 112 return true; | 100 return true; |
| 113 } else { | 101 } else { |
| 114 Hide(); | 102 stop_callback_ = stop_callback; |
| 103 EndDialog(); |
| 115 return false; | 104 return false; |
| 116 } | 105 } |
| 117 } | 106 } |
| 118 | 107 |
| 119 void DisconnectWindowWin::Hide() { | 108 INT_PTR CALLBACK ScreenCaptureNotificationUIWin::DialogProc( |
| 120 // Clear the |disconnect_callback_| so it won't be invoked by EndDialog(). | 109 HWND hwnd, UINT message, |
| 121 disconnect_callback_.Reset(); | 110 WPARAM wparam, LPARAM lparam) { |
| 122 EndDialog(); | |
| 123 } | |
| 124 | |
| 125 INT_PTR CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT message, | |
| 126 WPARAM wparam, LPARAM lparam) { | |
| 127 LONG_PTR self = NULL; | 111 LONG_PTR self = NULL; |
| 128 if (message == WM_INITDIALOG) { | 112 if (message == WM_INITDIALOG) { |
| 129 self = lparam; | 113 self = lparam; |
| 130 | 114 |
| 131 // Store |this| to the window's user data. | 115 // Store |this| to the window's user data. |
| 132 SetLastError(ERROR_SUCCESS); | 116 SetLastError(ERROR_SUCCESS); |
| 133 LONG_PTR result = SetWindowLongPtr(hwnd, DWLP_USER, self); | 117 LONG_PTR result = SetWindowLongPtr(hwnd, DWLP_USER, self); |
| 134 if (result == 0 && GetLastError() != ERROR_SUCCESS) | 118 if (result == 0 && GetLastError() != ERROR_SUCCESS) |
| 135 reinterpret_cast<DisconnectWindowWin*>(self)->EndDialog(); | 119 reinterpret_cast<ScreenCaptureNotificationUIWin*>(self)->EndDialog(); |
| 136 } else { | 120 } else { |
| 137 self = GetWindowLongPtr(hwnd, DWLP_USER); | 121 self = GetWindowLongPtr(hwnd, DWLP_USER); |
| 138 } | 122 } |
| 139 | 123 |
| 140 if (self) { | 124 if (self) { |
| 141 return reinterpret_cast<DisconnectWindowWin*>(self)->OnDialogMessage( | 125 return reinterpret_cast<ScreenCaptureNotificationUIWin*>(self)-> |
| 142 hwnd, message, wparam, lparam); | 126 OnDialogMessage(hwnd, message, wparam, lparam); |
| 143 } | 127 } |
| 144 return FALSE; | 128 return FALSE; |
| 145 } | 129 } |
| 146 | 130 |
| 147 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message, | 131 BOOL ScreenCaptureNotificationUIWin::OnDialogMessage(HWND hwnd, UINT message, |
| 148 WPARAM wparam, LPARAM lparam) { | 132 WPARAM wparam, LPARAM lparam) { |
| 149 switch (message) { | 133 switch (message) { |
| 150 // Ignore close messages. | 134 // Ignore close messages. |
| 151 case WM_CLOSE: | 135 case WM_CLOSE: |
| 152 return TRUE; | 136 return TRUE; |
| 153 | 137 |
| 154 // Handle the Disconnect button. | 138 // Handle the Stop button. |
| 155 case WM_COMMAND: | 139 case WM_COMMAND: |
| 156 switch (LOWORD(wparam)) { | 140 switch (LOWORD(wparam)) { |
| 157 case IDC_DISCONNECT: | 141 case IDC_SCREEN_CAPTURE_STOP: |
| 158 EndDialog(); | 142 EndDialog(); |
| 159 return TRUE; | 143 return TRUE; |
| 160 } | 144 } |
| 161 return FALSE; | 145 return FALSE; |
| 162 | 146 |
| 163 // Ensure we don't try to use the HWND anymore. | 147 // Ensure we don't try to use the HWND anymore. |
| 164 case WM_DESTROY: | 148 case WM_DESTROY: |
| 165 hwnd_ = NULL; | 149 hwnd_ = NULL; |
| 166 | 150 |
| 167 // Ensure that the disconnect callback is invoked even if somehow our | 151 // Ensure that the stop callback is invoked even if somehow our window |
| 168 // window gets destroyed. | 152 // gets destroyed. |
| 169 EndDialog(); | 153 EndDialog(); |
| 170 | 154 |
| 171 return TRUE; | 155 return TRUE; |
| 172 | 156 |
| 173 // Ensure the dialog stays visible if the work area dimensions change. | 157 // Ensure the dialog stays visible if the work area dimensions change. |
| 174 case WM_SETTINGCHANGE: | 158 case WM_SETTINGCHANGE: |
| 175 if (wparam == SPI_SETWORKAREA) | 159 if (wparam == SPI_SETWORKAREA) |
| 176 SetDialogPosition(); | 160 SetDialogPosition(); |
| 177 return TRUE; | 161 return TRUE; |
| 178 | 162 |
| 179 // Ensure the dialog stays visible if the display dimensions change. | 163 // Ensure the dialog stays visible if the display dimensions change. |
| 180 case WM_DISPLAYCHANGE: | 164 case WM_DISPLAYCHANGE: |
| 181 SetDialogPosition(); | 165 SetDialogPosition(); |
| 182 return TRUE; | 166 return TRUE; |
| 183 | 167 |
| 184 // Handle the disconnect hot-key. | |
| 185 case WM_HOTKEY: | |
| 186 EndDialog(); | |
| 187 return TRUE; | |
| 188 | |
| 189 // Let the window be draggable by its client area by responding | 168 // Let the window be draggable by its client area by responding |
| 190 // that the entire window is the title bar. | 169 // that the entire window is the title bar. |
| 191 case WM_NCHITTEST: | 170 case WM_NCHITTEST: |
| 192 SetWindowLongPtr(hwnd, DWLP_MSGRESULT, HTCAPTION); | 171 SetWindowLongPtr(hwnd, DWLP_MSGRESULT, HTCAPTION); |
| 193 return TRUE; | 172 return TRUE; |
| 194 | 173 |
| 195 case WM_PAINT: { | 174 case WM_PAINT: { |
| 196 PAINTSTRUCT ps; | 175 PAINTSTRUCT ps; |
| 197 HDC hdc = BeginPaint(hwnd_, &ps); | 176 HDC hdc = BeginPaint(hwnd_, &ps); |
| 198 RECT rect; | 177 RECT rect; |
| 199 GetClientRect(hwnd_, &rect); | 178 GetClientRect(hwnd_, &rect); |
| 200 { | 179 { |
| 201 base::win::ScopedSelectObject border(hdc, border_pen_); | 180 base::win::ScopedSelectObject border(hdc, border_pen_); |
| 202 base::win::ScopedSelectObject brush(hdc, GetStockObject(NULL_BRUSH)); | 181 base::win::ScopedSelectObject brush(hdc, GetStockObject(NULL_BRUSH)); |
| 203 RoundRect(hdc, rect.left, rect.top, rect.right - 1, rect.bottom - 1, | 182 RoundRect(hdc, rect.left, rect.top, rect.right - 1, rect.bottom - 1, |
| 204 kWindowBorderRadius, kWindowBorderRadius); | 183 kWindowBorderRadius, kWindowBorderRadius); |
| 205 } | 184 } |
| 206 EndPaint(hwnd_, &ps); | 185 EndPaint(hwnd_, &ps); |
| 207 return TRUE; | 186 return TRUE; |
| 208 } | 187 } |
| 209 } | 188 } |
| 210 return FALSE; | 189 return FALSE; |
| 211 } | 190 } |
| 212 | 191 |
| 213 bool DisconnectWindowWin::BeginDialog(const std::string& username) { | 192 bool ScreenCaptureNotificationUIWin::BeginDialog(const string16& title) { |
| 214 DCHECK(!hwnd_); | 193 DCHECK(!hwnd_); |
| 215 | 194 |
| 195 // TODO(sergeyu): Currently this code relies on resources for the dialog. Fix |
| 196 // it to work without resources. |
| 197 |
| 216 // Load the dialog resource so that we can modify the RTL flags if necessary. | 198 // Load the dialog resource so that we can modify the RTL flags if necessary. |
| 217 HMODULE module = base::GetModuleFromAddress(&DialogProc); | 199 HMODULE module = base::GetModuleFromAddress(&DialogProc); |
| 218 HRSRC dialog_resource = | 200 HRSRC dialog_resource = FindResource( |
| 219 FindResource(module, MAKEINTRESOURCE(IDD_DISCONNECT), RT_DIALOG); | 201 module, MAKEINTRESOURCE(IDD_SCREEN_CAPTURE_NOTIFICATION), RT_DIALOG); |
| 220 if (!dialog_resource) | 202 if (!dialog_resource) |
| 221 return false; | 203 return false; |
| 222 | 204 |
| 223 HGLOBAL dialog_template = LoadResource(module, dialog_resource); | 205 HGLOBAL dialog_template = LoadResource(module, dialog_resource); |
| 224 if (!dialog_template) | 206 if (!dialog_template) |
| 225 return false; | 207 return false; |
| 226 | 208 |
| 227 DLGTEMPLATE* dialog_pointer = | 209 DLGTEMPLATE* dialog_pointer = |
| 228 reinterpret_cast<DLGTEMPLATE*>(LockResource(dialog_template)); | 210 reinterpret_cast<DLGTEMPLATE*>(LockResource(dialog_template)); |
| 229 if (!dialog_pointer) | 211 if (!dialog_pointer) |
| 230 return false; | 212 return false; |
| 231 | 213 |
| 232 // The actual resource type is DLGTEMPLATEEX, but this is not defined in any | 214 // The actual resource type is DLGTEMPLATEEX, but this is not defined in any |
| 233 // standard headers, so we treat it as a generic pointer and manipulate the | 215 // standard headers, so we treat it as a generic pointer and manipulate the |
| 234 // correct offsets explicitly. | 216 // correct offsets explicitly. |
| 235 scoped_array<unsigned char> rtl_dialog_template; | 217 scoped_array<unsigned char> rtl_dialog_template; |
| 236 if (ui_strings_->direction == UiStrings::RTL) { | 218 if (base::i18n::IsRTL()) { |
| 237 unsigned long dialog_template_size = | 219 unsigned long dialog_template_size = |
| 238 SizeofResource(module, dialog_resource); | 220 SizeofResource(module, dialog_resource); |
| 239 rtl_dialog_template.reset(new unsigned char[dialog_template_size]); | 221 rtl_dialog_template.reset(new unsigned char[dialog_template_size]); |
| 240 memcpy(rtl_dialog_template.get(), dialog_pointer, dialog_template_size); | 222 memcpy(rtl_dialog_template.get(), dialog_pointer, dialog_template_size); |
| 241 DWORD* rtl_dwords = reinterpret_cast<DWORD*>(rtl_dialog_template.get()); | 223 DWORD* rtl_dwords = reinterpret_cast<DWORD*>(rtl_dialog_template.get()); |
| 242 rtl_dwords[2] |= (WS_EX_LAYOUTRTL | WS_EX_RTLREADING); | 224 rtl_dwords[2] |= (WS_EX_LAYOUTRTL | WS_EX_RTLREADING); |
| 243 dialog_pointer = reinterpret_cast<DLGTEMPLATE*>(rtl_dwords); | 225 dialog_pointer = reinterpret_cast<DLGTEMPLATE*>(rtl_dwords); |
| 244 } | 226 } |
| 245 | 227 |
| 246 hwnd_ = CreateDialogIndirectParam(module, dialog_pointer, NULL, | 228 hwnd_ = CreateDialogIndirectParam(module, dialog_pointer, NULL, |
| 247 DialogProc, reinterpret_cast<LPARAM>(this)); | 229 DialogProc, reinterpret_cast<LPARAM>(this)); |
| 248 if (!hwnd_) | 230 if (!hwnd_) |
| 249 return false; | 231 return false; |
| 250 | 232 |
| 251 // Set up handler for Ctrl-Alt-Esc shortcut. | 233 if (!UpdateStrings(title)) |
| 252 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, | |
| 253 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) { | |
| 254 has_hotkey_ = true; | |
| 255 } | |
| 256 | |
| 257 if (!SetStrings(UTF8ToUTF16(username))) | |
| 258 return false; | 234 return false; |
| 259 | 235 |
| 260 SetDialogPosition(); | 236 SetDialogPosition(); |
| 261 ShowWindow(hwnd_, SW_SHOW); | 237 ShowWindow(hwnd_, SW_SHOW); |
| 262 return IsWindowVisible(hwnd_) != FALSE; | 238 return IsWindowVisible(hwnd_) != FALSE; |
| 263 } | 239 } |
| 264 | 240 |
| 265 void DisconnectWindowWin::EndDialog() { | 241 void ScreenCaptureNotificationUIWin::EndDialog() { |
| 266 if (has_hotkey_) { | |
| 267 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); | |
| 268 has_hotkey_ = false; | |
| 269 } | |
| 270 | |
| 271 if (hwnd_) { | 242 if (hwnd_) { |
| 272 DestroyWindow(hwnd_); | 243 DestroyWindow(hwnd_); |
| 273 hwnd_ = NULL; | 244 hwnd_ = NULL; |
| 274 } | 245 } |
| 275 | 246 |
| 276 if (!disconnect_callback_.is_null()) { | 247 if (!stop_callback_.is_null()) { |
| 277 disconnect_callback_.Run(); | 248 stop_callback_.Run(); |
| 278 disconnect_callback_.Reset(); | 249 stop_callback_.Reset(); |
| 279 } | 250 } |
| 280 } | 251 } |
| 281 | 252 |
| 282 void DisconnectWindowWin::SetDialogPosition() { | 253 void ScreenCaptureNotificationUIWin::SetDialogPosition() { |
| 283 // Try to center the window above the task-bar. If that fails, use the | 254 // Try to center the window above the task-bar. If that fails, use the |
| 284 // primary monitor. If that fails (very unlikely), use the default position. | 255 // primary monitor. If that fails (very unlikely), use the default position. |
| 285 HWND taskbar = FindWindow(kShellTrayWindowName, NULL); | 256 HWND taskbar = FindWindow(kShellTrayWindowName, NULL); |
| 286 HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); | 257 HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); |
| 287 MONITORINFO monitor_info = {sizeof(monitor_info)}; | 258 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
| 288 RECT window_rect; | 259 RECT window_rect; |
| 289 if (GetMonitorInfo(monitor, &monitor_info) && | 260 if (GetMonitorInfo(monitor, &monitor_info) && |
| 290 GetWindowRect(hwnd_, &window_rect)) { | 261 GetWindowRect(hwnd_, &window_rect)) { |
| 291 int window_width = window_rect.right - window_rect.left; | 262 int window_width = window_rect.right - window_rect.left; |
| 292 int window_height = window_rect.bottom - window_rect.top; | 263 int window_height = window_rect.bottom - window_rect.top; |
| 293 int top = monitor_info.rcWork.bottom - window_height; | 264 int top = monitor_info.rcWork.bottom - window_height; |
| 294 int left = (monitor_info.rcWork.right + monitor_info.rcWork.left - | 265 int left = (monitor_info.rcWork.right + monitor_info.rcWork.left - |
| 295 window_width) / 2; | 266 window_width) / 2; |
| 296 SetWindowPos(hwnd_, NULL, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); | 267 SetWindowPos(hwnd_, NULL, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); |
| 297 } | 268 } |
| 298 } | 269 } |
| 299 | 270 |
| 300 bool DisconnectWindowWin::SetStrings(const string16& username) { | 271 bool ScreenCaptureNotificationUIWin::UpdateStrings(const string16& title) { |
| 301 if (!SetWindowText(hwnd_, ui_strings_->product_name.c_str())) | 272 string16 window_title = |
| 273 l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TITLE, |
| 274 title); |
| 275 if (!SetWindowText(hwnd_, window_title.c_str())) |
| 302 return false; | 276 return false; |
| 303 | 277 |
| 304 // Localize the disconnect button text and measure length of the old and new | 278 // Localize the disconnect button text and measure length of the old and new |
| 305 // labels. | 279 // labels. |
| 306 HWND disconnect_button = GetDlgItem(hwnd_, IDC_DISCONNECT); | 280 HWND stop_button = GetDlgItem(hwnd_, IDC_SCREEN_CAPTURE_STOP); |
| 307 if (!disconnect_button) | 281 if (!stop_button) |
| 308 return false; | 282 return false; |
| 309 int button_old_required_width = GetControlTextWidth(disconnect_button); | 283 int button_old_required_width = GetControlTextWidth(stop_button); |
| 310 if (!SetWindowText(disconnect_button, | 284 string16 button_label = |
| 311 ui_strings_->disconnect_button_text.c_str())) { | 285 l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP); |
| 286 if (!SetWindowText(stop_button, button_label.c_str())) |
| 312 return false; | 287 return false; |
| 313 } | 288 int button_new_required_width = GetControlTextWidth(stop_button); |
| 314 int button_new_required_width = GetControlTextWidth(disconnect_button); | |
| 315 int button_width_delta = | 289 int button_width_delta = |
| 316 button_new_required_width - button_old_required_width; | 290 button_new_required_width - button_old_required_width; |
| 317 | 291 |
| 318 // Format and truncate "Your desktop is shared with ..." message. | 292 // Format and truncate "Your desktop is shared with ..." message. |
| 319 string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message, | 293 |
| 320 username, NULL); | 294 string16 text = l10n_util::GetStringFUTF16( |
| 295 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT, title); |
| 321 if (text.length() > kMaxSharingWithTextLength) | 296 if (text.length() > kMaxSharingWithTextLength) |
| 322 text.erase(kMaxSharingWithTextLength); | 297 text.erase(kMaxSharingWithTextLength); |
| 323 | 298 |
| 324 // Set localized and truncated "Your desktop is shared with ..." message and | 299 // Set localized and truncated "Your desktop is shared with ..." message and |
| 325 // measure length of the old and new text. | 300 // measure length of the old and new text. |
| 326 HWND sharing_with_label = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH); | 301 HWND sharing_with_label = GetDlgItem(hwnd_, IDC_SCREEN_CAPTURE_TEXT); |
| 327 if (!sharing_with_label) | 302 if (!sharing_with_label) |
| 328 return false; | 303 return false; |
| 329 int label_old_required_width = GetControlTextWidth(sharing_with_label); | 304 int label_old_required_width = GetControlTextWidth(sharing_with_label); |
| 330 if (!SetWindowText(sharing_with_label, text.c_str())) | 305 if (!SetWindowText(sharing_with_label, text.c_str())) |
| 331 return false; | 306 return false; |
| 332 int label_new_required_width = GetControlTextWidth(sharing_with_label); | 307 int label_new_required_width = GetControlTextWidth(sharing_with_label); |
| 333 int label_width_delta = label_new_required_width - label_old_required_width; | 308 int label_width_delta = label_new_required_width - label_old_required_width; |
| 334 | 309 |
| 335 // Reposition the controls such that the label lies to the left of the | 310 // Reposition the controls such that the label lies to the left of the |
| 336 // disconnect button (assuming LTR layout). The dialog template determines | 311 // disconnect button (assuming LTR layout). The dialog template determines |
| 337 // the controls' spacing; update their size to fit the localized content. | 312 // the controls' spacing; update their size to fit the localized content. |
| 338 RECT label_rect; | 313 RECT label_rect; |
| 339 if (!GetClientRect(sharing_with_label, &label_rect)) | 314 if (!GetClientRect(sharing_with_label, &label_rect)) |
| 340 return false; | 315 return false; |
| 341 if (!SetWindowPos(sharing_with_label, NULL, 0, 0, | 316 if (!SetWindowPos(sharing_with_label, NULL, 0, 0, |
| 342 label_rect.right + label_width_delta, label_rect.bottom, | 317 label_rect.right + label_width_delta, label_rect.bottom, |
| 343 SWP_NOMOVE | SWP_NOZORDER)) { | 318 SWP_NOMOVE | SWP_NOZORDER)) { |
| 344 return false; | 319 return false; |
| 345 } | 320 } |
| 346 | 321 |
| 347 // Reposition the disconnect button as well. | 322 // Reposition the disconnect button as well. |
| 348 RECT button_rect; | 323 RECT button_rect; |
| 349 if (!GetWindowRect(disconnect_button, &button_rect)) | 324 if (!GetWindowRect(stop_button, &button_rect)) |
| 350 return false; | 325 return false; |
| 351 int button_width = button_rect.right - button_rect.left; | 326 int button_width = button_rect.right - button_rect.left; |
| 352 int button_height = button_rect.bottom - button_rect.top; | 327 int button_height = button_rect.bottom - button_rect.top; |
| 353 SetLastError(ERROR_SUCCESS); | 328 SetLastError(ERROR_SUCCESS); |
| 354 int result = MapWindowPoints(HWND_DESKTOP, hwnd_, | 329 int result = MapWindowPoints(HWND_DESKTOP, hwnd_, |
| 355 reinterpret_cast<LPPOINT>(&button_rect), 2); | 330 reinterpret_cast<LPPOINT>(&button_rect), 2); |
| 356 if (!result && GetLastError() != ERROR_SUCCESS) | 331 if (!result && GetLastError() != ERROR_SUCCESS) |
| 357 return false; | 332 return false; |
| 358 if (!SetWindowPos(disconnect_button, NULL, | 333 if (!SetWindowPos(stop_button, NULL, |
| 359 button_rect.left + label_width_delta, button_rect.top, | 334 button_rect.left + label_width_delta, button_rect.top, |
| 360 button_width + button_width_delta, button_height, | 335 button_width + button_width_delta, button_height, |
| 361 SWP_NOZORDER)) { | 336 SWP_NOZORDER)) { |
| 362 return false; | 337 return false; |
| 363 } | 338 } |
| 364 | 339 |
| 365 // Resize the whole window to fit the resized controls. | 340 // Resize the whole window to fit the resized controls. |
| 366 RECT window_rect; | 341 RECT window_rect; |
| 367 if (!GetWindowRect(hwnd_, &window_rect)) | 342 if (!GetWindowRect(hwnd_, &window_rect)) |
| 368 return false; | 343 return false; |
| 369 int width = (window_rect.right - window_rect.left) + | 344 int width = (window_rect.right - window_rect.left) + |
| 370 button_width_delta + label_width_delta; | 345 button_width_delta + label_width_delta; |
| 371 int height = window_rect.bottom - window_rect.top; | 346 int height = window_rect.bottom - window_rect.top; |
| 372 if (!SetWindowPos(hwnd_, NULL, 0, 0, width, height, | 347 if (!SetWindowPos(hwnd_, NULL, 0, 0, width, height, |
| 373 SWP_NOMOVE | SWP_NOZORDER)) { | 348 SWP_NOMOVE | SWP_NOZORDER)) { |
| 374 return false; | 349 return false; |
| 375 } | 350 } |
| 376 | 351 |
| 377 // Make the corners of the disconnect window rounded. | 352 // Make the corners of the disconnect window rounded. |
| 378 HRGN rgn = CreateRoundRectRgn(0, 0, width, height, kWindowBorderRadius, | 353 HRGN rgn = CreateRoundRectRgn(0, 0, width, height, kWindowBorderRadius, |
| 379 kWindowBorderRadius); | 354 kWindowBorderRadius); |
| 380 if (!rgn) | 355 if (!rgn) |
| 381 return false; | 356 return false; |
| 382 if (!SetWindowRgn(hwnd_, rgn, TRUE)) | 357 if (!SetWindowRgn(hwnd_, rgn, TRUE)) |
| 383 return false; | 358 return false; |
| 384 | 359 |
| 385 return true; | 360 return true; |
| 386 } | 361 } |
| 387 | 362 |
| 388 scoped_ptr<DisconnectWindow> DisconnectWindow::Create( | 363 scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create() { |
| 389 const UiStrings* ui_strings) { | 364 return scoped_ptr<ScreenCaptureNotificationUI>( |
| 390 return scoped_ptr<DisconnectWindow>(new DisconnectWindowWin(ui_strings)); | 365 new ScreenCaptureNotificationUIWin()); |
| 391 } | 366 } |
| 392 | |
| 393 } // namespace remoting | |
| OLD | NEW |