OLD | NEW |
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 "remoting/host/continue_window.h" | 5 #include "remoting/host/continue_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" | |
13 #include "remoting/host/host_ui_resource.h" | 12 #include "remoting/host/host_ui_resource.h" |
| 13 #include "remoting/host/ui_strings.h" |
14 | 14 |
15 // TODO(garykac): Lots of duplicated code in this file and | 15 // TODO(garykac): Lots of duplicated code in this file and |
16 // disconnect_window_win.cc. These global floating windows are temporary so | 16 // disconnect_window_win.cc. These global floating windows are temporary so |
17 // they should be deleted soon. If we need to expand this then we should | 17 // they should be deleted soon. If we need to expand this then we should |
18 // create a class with the shared code. | 18 // create a class with the shared code. |
19 | 19 |
20 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. | 20 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. |
21 // This is defined in: | 21 // This is defined in: |
22 // Plugin: host_plugin.cc | 22 // Plugin: host_plugin.cc |
23 // SimpleHost: simple_host_process.cc | 23 // SimpleHost: simple_host_process.cc |
24 extern HMODULE g_hModule; | 24 extern HMODULE g_hModule; |
25 | 25 |
26 namespace remoting { | 26 namespace remoting { |
27 | 27 |
28 class ContinueWindowWin : public ContinueWindow { | 28 class ContinueWindowWin : public ContinueWindow { |
29 public: | 29 public: |
30 ContinueWindowWin(); | 30 explicit ContinueWindowWin(const UiStrings* ui_strings); |
31 virtual ~ContinueWindowWin(); | 31 virtual ~ContinueWindowWin(); |
32 | 32 |
33 virtual void Show(remoting::ChromotingHost* host, | 33 virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; |
34 const ContinueSessionCallback& callback) OVERRIDE; | |
35 virtual void Hide() OVERRIDE; | 34 virtual void Hide() OVERRIDE; |
36 | 35 |
37 private: | 36 private: |
38 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, | 37 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, |
39 LPARAM lParam); | 38 LPARAM lParam); |
40 | 39 |
41 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); | 40 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
42 | 41 |
43 void EndDialog(); | 42 void EndDialog(); |
44 void SetStrings(const UiStrings& strings); | 43 void SetStrings(); |
45 | 44 |
46 remoting::ChromotingHost* host_; | |
47 ContinueSessionCallback callback_; | 45 ContinueSessionCallback callback_; |
48 HWND hwnd_; | 46 HWND hwnd_; |
49 | 47 |
| 48 // Points to the localized strings. |
| 49 const UiStrings* ui_strings_; |
| 50 |
50 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); | 51 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); |
51 }; | 52 }; |
52 | 53 |
53 ContinueWindowWin::ContinueWindowWin() | 54 ContinueWindowWin::ContinueWindowWin(const UiStrings* ui_strings) |
54 : host_(NULL), | 55 : hwnd_(NULL), |
55 hwnd_(NULL) { | 56 ui_strings_(ui_strings) { |
56 } | 57 } |
57 | 58 |
58 ContinueWindowWin::~ContinueWindowWin() { | 59 ContinueWindowWin::~ContinueWindowWin() { |
59 EndDialog(); | 60 EndDialog(); |
60 } | 61 } |
61 | 62 |
62 BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg, | 63 BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg, |
63 WPARAM wParam, LPARAM lParam) { | 64 WPARAM wParam, LPARAM lParam) { |
64 ContinueWindowWin* win = NULL; | 65 ContinueWindowWin* win = NULL; |
65 if (msg == WM_INITDIALOG) { | 66 if (msg == WM_INITDIALOG) { |
(...skipping 29 matching lines...) Expand all Loading... |
95 case IDC_CONTINUE_CANCEL: | 96 case IDC_CONTINUE_CANCEL: |
96 callback_.Run(false); | 97 callback_.Run(false); |
97 ::EndDialog(hwnd, LOWORD(wParam)); | 98 ::EndDialog(hwnd, LOWORD(wParam)); |
98 hwnd_ = NULL; | 99 hwnd_ = NULL; |
99 return TRUE; | 100 return TRUE; |
100 } | 101 } |
101 } | 102 } |
102 return FALSE; | 103 return FALSE; |
103 } | 104 } |
104 | 105 |
105 void ContinueWindowWin::Show(ChromotingHost* host, | 106 void ContinueWindowWin::Show(const ContinueSessionCallback& callback) { |
106 const ContinueSessionCallback& callback) { | |
107 host_ = host; | |
108 callback_ = callback; | 107 callback_ = callback; |
109 | 108 |
110 CHECK(!hwnd_); | 109 CHECK(!hwnd_); |
111 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_CONTINUE), NULL, | 110 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_CONTINUE), NULL, |
112 (DLGPROC)DialogProc, (LPARAM)this); | 111 (DLGPROC)DialogProc, (LPARAM)this); |
113 if (!hwnd_) { | 112 if (!hwnd_) { |
114 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; | 113 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; |
115 return; | 114 return; |
116 } | 115 } |
117 | 116 |
118 SetStrings(host->ui_strings()); | 117 SetStrings(); |
119 ShowWindow(hwnd_, SW_SHOW); | 118 ShowWindow(hwnd_, SW_SHOW); |
120 } | 119 } |
121 | 120 |
122 void ContinueWindowWin::Hide() { | 121 void ContinueWindowWin::Hide() { |
123 EndDialog(); | 122 EndDialog(); |
124 } | 123 } |
125 | 124 |
126 void ContinueWindowWin::EndDialog() { | 125 void ContinueWindowWin::EndDialog() { |
127 if (hwnd_) { | 126 if (hwnd_) { |
128 ::DestroyWindow(hwnd_); | 127 ::DestroyWindow(hwnd_); |
129 hwnd_ = NULL; | 128 hwnd_ = NULL; |
130 } | 129 } |
131 } | 130 } |
132 | 131 |
133 void ContinueWindowWin::SetStrings(const UiStrings& strings) { | 132 void ContinueWindowWin::SetStrings() { |
134 SetWindowText(hwnd_, strings.product_name.c_str()); | 133 SetWindowText(hwnd_, ui_strings_->product_name.c_str()); |
135 | 134 |
136 HWND hwndMessage = GetDlgItem(hwnd_, IDC_CONTINUE_MESSAGE); | 135 HWND hwndMessage = GetDlgItem(hwnd_, IDC_CONTINUE_MESSAGE); |
137 CHECK(hwndMessage); | 136 CHECK(hwndMessage); |
138 SetWindowText(hwndMessage, strings.continue_prompt.c_str()); | 137 SetWindowText(hwndMessage, ui_strings_->continue_prompt.c_str()); |
139 | 138 |
140 HWND hwndDefault = GetDlgItem(hwnd_, IDC_CONTINUE_DEFAULT); | 139 HWND hwndDefault = GetDlgItem(hwnd_, IDC_CONTINUE_DEFAULT); |
141 CHECK(hwndDefault); | 140 CHECK(hwndDefault); |
142 SetWindowText(hwndDefault, strings.continue_button_text.c_str()); | 141 SetWindowText(hwndDefault, ui_strings_->continue_button_text.c_str()); |
143 | 142 |
144 HWND hwndCancel = GetDlgItem(hwnd_, IDC_CONTINUE_CANCEL); | 143 HWND hwndCancel = GetDlgItem(hwnd_, IDC_CONTINUE_CANCEL); |
145 CHECK(hwndCancel); | 144 CHECK(hwndCancel); |
146 SetWindowText(hwndCancel, strings.stop_sharing_button_text.c_str()); | 145 SetWindowText(hwndCancel, ui_strings_->stop_sharing_button_text.c_str()); |
147 } | 146 } |
148 | 147 |
149 scoped_ptr<ContinueWindow> ContinueWindow::Create() { | 148 scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { |
150 return scoped_ptr<ContinueWindow>(new ContinueWindowWin()); | 149 return scoped_ptr<ContinueWindow>(new ContinueWindowWin(ui_strings)); |
151 } | 150 } |
152 | 151 |
153 } // namespace remoting | 152 } // namespace remoting |
OLD | NEW |