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

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

Issue 21059003: Localized Chromoting Host on Mac and Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 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 | « remoting/host/disconnect_window_mac.mm ('k') | remoting/host/host_main.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <windows.h> 5 #include <windows.h>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/process/memory.h" 9 #include "base/process/memory.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/win/scoped_gdi_object.h" 12 #include "base/win/scoped_gdi_object.h"
13 #include "base/win/scoped_hdc.h" 13 #include "base/win/scoped_hdc.h"
14 #include "base/win/scoped_select_object.h" 14 #include "base/win/scoped_select_object.h"
15 #include "remoting/host/client_session_control.h" 15 #include "remoting/host/client_session_control.h"
16 #include "remoting/host/host_window.h" 16 #include "remoting/host/host_window.h"
17 #include "remoting/host/ui_strings.h"
18 #include "remoting/host/win/core_resource.h" 17 #include "remoting/host/win/core_resource.h"
19 18
20 namespace remoting { 19 namespace remoting {
21 20
22 namespace { 21 namespace {
23 22
24 const int DISCONNECT_HOTKEY_ID = 1000; 23 const int DISCONNECT_HOTKEY_ID = 1000;
25 24
26 // Maximum length of "Your desktop is shared with ..." message in UTF-16 25 // Maximum length of "Your desktop is shared with ..." message in UTF-16
27 // characters. 26 // characters.
28 const size_t kMaxSharingWithTextLength = 100; 27 const size_t kMaxSharingWithTextLength = 100;
29 28
30 const wchar_t kShellTrayWindowName[] = L"Shell_TrayWnd"; 29 const wchar_t kShellTrayWindowName[] = L"Shell_TrayWnd";
31 const int kWindowBorderRadius = 14; 30 const int kWindowBorderRadius = 14;
32 31
33 // Margin between dialog controls (in dialog units). 32 // Margin between dialog controls (in dialog units).
34 const int kWindowTextMargin = 8; 33 const int kWindowTextMargin = 8;
35 34
36 class DisconnectWindowWin : public HostWindow { 35 class DisconnectWindowWin : public HostWindow {
37 public: 36 public:
38 explicit DisconnectWindowWin(const UiStrings& ui_strings); 37 DisconnectWindowWin();
39 virtual ~DisconnectWindowWin(); 38 virtual ~DisconnectWindowWin();
40 39
41 // HostWindow overrides. 40 // HostWindow overrides.
42 virtual void Start( 41 virtual void Start(
43 const base::WeakPtr<ClientSessionControl>& client_session_control) 42 const base::WeakPtr<ClientSessionControl>& client_session_control)
44 OVERRIDE; 43 OVERRIDE;
45 44
46 protected: 45 protected:
47 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wparam, 46 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wparam,
48 LPARAM lparam); 47 LPARAM lparam);
(...skipping 12 matching lines...) Expand all
61 60
62 // Trys to position the dialog window above the taskbar. 61 // Trys to position the dialog window above the taskbar.
63 void SetDialogPosition(); 62 void SetDialogPosition();
64 63
65 // Applies localization string and resizes the dialog. 64 // Applies localization string and resizes the dialog.
66 bool SetStrings(); 65 bool SetStrings();
67 66
68 // Used to disconnect the client session. 67 // Used to disconnect the client session.
69 base::WeakPtr<ClientSessionControl> client_session_control_; 68 base::WeakPtr<ClientSessionControl> client_session_control_;
70 69
71 // Localized UI strings.
72 UiStrings ui_strings_;
73
74 // Specifies the remote user name. 70 // Specifies the remote user name.
75 std::string username_; 71 std::string username_;
76 72
77 HWND hwnd_; 73 HWND hwnd_;
78 bool has_hotkey_; 74 bool has_hotkey_;
79 base::win::ScopedGDIObject<HPEN> border_pen_; 75 base::win::ScopedGDIObject<HPEN> border_pen_;
80 76
81 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); 77 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin);
82 }; 78 };
83 79
(...skipping 16 matching lines...) Expand all
100 base::win::ScopedGetDC dc(control); 96 base::win::ScopedGetDC dc(control);
101 base::win::ScopedSelectObject font( 97 base::win::ScopedSelectObject font(
102 dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0)); 98 dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0));
103 if (!DrawText(dc, text.c_str(), -1, &rect, DT_CALCRECT | DT_SINGLELINE)) 99 if (!DrawText(dc, text.c_str(), -1, &rect, DT_CALCRECT | DT_SINGLELINE))
104 return false; 100 return false;
105 101
106 *width = rect.right; 102 *width = rect.right;
107 return true; 103 return true;
108 } 104 }
109 105
110 DisconnectWindowWin::DisconnectWindowWin(const UiStrings& ui_strings) 106 DisconnectWindowWin::DisconnectWindowWin()
111 : ui_strings_(ui_strings), 107 : hwnd_(NULL),
112 hwnd_(NULL),
113 has_hotkey_(false), 108 has_hotkey_(false),
114 border_pen_(CreatePen(PS_SOLID, 5, 109 border_pen_(CreatePen(PS_SOLID, 5,
115 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) { 110 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) {
116 } 111 }
117 112
118 DisconnectWindowWin::~DisconnectWindowWin() { 113 DisconnectWindowWin::~DisconnectWindowWin() {
119 EndDialog(); 114 EndDialog();
120 } 115 }
121 116
122 void DisconnectWindowWin::Start( 117 void DisconnectWindowWin::Start(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return TRUE; 219 return TRUE;
225 } 220 }
226 } 221 }
227 return FALSE; 222 return FALSE;
228 } 223 }
229 224
230 bool DisconnectWindowWin::BeginDialog() { 225 bool DisconnectWindowWin::BeginDialog() {
231 DCHECK(CalledOnValidThread()); 226 DCHECK(CalledOnValidThread());
232 DCHECK(!hwnd_); 227 DCHECK(!hwnd_);
233 228
234 // Load the dialog resource so that we can modify the RTL flags if necessary.
235 HMODULE module = base::GetModuleFromAddress(&DialogProc); 229 HMODULE module = base::GetModuleFromAddress(&DialogProc);
236 HRSRC dialog_resource = 230 hwnd_ = CreateDialogParam(module, MAKEINTRESOURCE(IDD_DISCONNECT), NULL,
237 FindResource(module, MAKEINTRESOURCE(IDD_DISCONNECT), RT_DIALOG); 231 DialogProc, reinterpret_cast<LPARAM>(this));
238 if (!dialog_resource)
239 return false;
240
241 HGLOBAL dialog_template = LoadResource(module, dialog_resource);
242 if (!dialog_template)
243 return false;
244
245 DLGTEMPLATE* dialog_pointer =
246 reinterpret_cast<DLGTEMPLATE*>(LockResource(dialog_template));
247 if (!dialog_pointer)
248 return false;
249
250 // The actual resource type is DLGTEMPLATEEX, but this is not defined in any
251 // standard headers, so we treat it as a generic pointer and manipulate the
252 // correct offsets explicitly.
253 scoped_ptr<unsigned char[]> rtl_dialog_template;
254 if (ui_strings_.direction == UiStrings::RTL) {
255 unsigned long dialog_template_size =
256 SizeofResource(module, dialog_resource);
257 rtl_dialog_template.reset(new unsigned char[dialog_template_size]);
258 memcpy(rtl_dialog_template.get(), dialog_pointer, dialog_template_size);
259 DWORD* rtl_dwords = reinterpret_cast<DWORD*>(rtl_dialog_template.get());
260 rtl_dwords[2] |= (WS_EX_LAYOUTRTL | WS_EX_RTLREADING);
261 dialog_pointer = reinterpret_cast<DLGTEMPLATE*>(rtl_dwords);
262 }
263
264 hwnd_ = CreateDialogIndirectParam(module, dialog_pointer, NULL,
265 DialogProc, reinterpret_cast<LPARAM>(this));
266 if (!hwnd_) 232 if (!hwnd_)
267 return false; 233 return false;
268 234
269 // Set up handler for Ctrl-Alt-Esc shortcut. 235 // Set up handler for Ctrl-Alt-Esc shortcut.
270 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, 236 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID,
271 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) { 237 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) {
272 has_hotkey_ = true; 238 has_hotkey_ = true;
273 } 239 }
274 240
275 if (!SetStrings()) 241 if (!SetStrings())
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return false; 383 return false;
418 if (!SetWindowRgn(hwnd_, rgn, TRUE)) 384 if (!SetWindowRgn(hwnd_, rgn, TRUE))
419 return false; 385 return false;
420 386
421 return true; 387 return true;
422 } 388 }
423 389
424 } // namespace 390 } // namespace
425 391
426 // static 392 // static
427 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow( 393 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow() {
428 const UiStrings& ui_strings) { 394 return scoped_ptr<HostWindow>(new DisconnectWindowWin());
429 return scoped_ptr<HostWindow>(new DisconnectWindowWin(ui_strings));
430 } 395 }
431 396
432 } // namespace remoting 397 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/disconnect_window_mac.mm ('k') | remoting/host/host_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698