blob: c62289b5a2fe3e3e553a6dfba1d98953448000c7 [file] [log] [blame]
[email protected]3361e1f2012-03-20 20:31:441// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]38a4d772011-06-16 21:25:342// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/host/continue_window.h"
6
[email protected]0e6a47e2011-06-22 22:30:387#include <windows.h>
8
[email protected]38a4d772011-06-16 21:25:349#include "base/compiler_specific.h"
10#include "base/logging.h"
[email protected]ac6eedd12011-07-06 22:19:1411#include "base/utf_string_conversions.h"
[email protected]0e6a47e2011-06-22 22:30:3812#include "remoting/host/chromoting_host.h"
13// TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have
14// a dependency on the plugin's resource header.
15#include "remoting/host/plugin/host_plugin_resource.h"
16
17// TODO(garykac): Lots of duplicated code in this file and
18// disconnect_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
20// create a class with the shared code.
21
22// HMODULE from DllMain/WinMain. This is needed to find our dialog resource.
23// This is defined in:
24// Plugin: host_plugin.cc
25// SimpleHost: simple_host_process.cc
26extern HMODULE g_hModule;
[email protected]38a4d772011-06-16 21:25:3427
28namespace remoting {
29
[email protected]0e6a47e2011-06-22 22:30:3830class ContinueWindowWin : public ContinueWindow {
[email protected]38a4d772011-06-16 21:25:3431 public:
[email protected]0e6a47e2011-06-22 22:30:3832 ContinueWindowWin();
33 virtual ~ContinueWindowWin();
[email protected]38a4d772011-06-16 21:25:3434
[email protected]1bafb3c2011-11-23 23:39:5035 virtual void Show(remoting::ChromotingHost* host,
36 const ContinueSessionCallback& callback) OVERRIDE;
[email protected]38a4d772011-06-16 21:25:3437 virtual void Hide() OVERRIDE;
38
39 private:
[email protected]0e6a47e2011-06-22 22:30:3840 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam,
41 LPARAM lParam);
42
43 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
44
45 void EndDialog();
[email protected]29b05822011-09-09 18:17:0546 void SetStrings(const UiStrings& strings);
[email protected]0e6a47e2011-06-22 22:30:3847
48 remoting::ChromotingHost* host_;
[email protected]1bafb3c2011-11-23 23:39:5049 ContinueSessionCallback callback_;
[email protected]0e6a47e2011-06-22 22:30:3850 HWND hwnd_;
51
[email protected]38a4d772011-06-16 21:25:3452 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin);
53};
54
[email protected]0e6a47e2011-06-22 22:30:3855ContinueWindowWin::ContinueWindowWin()
56 : host_(NULL),
57 hwnd_(NULL) {
58}
59
60ContinueWindowWin::~ContinueWindowWin() {
61 EndDialog();
62}
63
64BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg,
65 WPARAM wParam, LPARAM lParam) {
66 ContinueWindowWin* win = NULL;
67 if (msg == WM_INITDIALOG) {
68 win = reinterpret_cast<ContinueWindowWin*>(lParam);
69 CHECK(win);
70 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win);
71 } else {
72 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER);
73 win = reinterpret_cast<ContinueWindowWin*>(lp);
74 }
75 if (win == NULL)
76 return FALSE;
77 return win->OnDialogMessage(hwnd, msg, wParam, lParam);
78}
79
80BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
81 WPARAM wParam, LPARAM lParam) {
82 switch (msg) {
[email protected]0e6a47e2011-06-22 22:30:3883 case WM_CLOSE:
84 // Ignore close messages.
85 return TRUE;
86 case WM_DESTROY:
87 // Ensure we don't try to use the HWND anymore.
88 hwnd_ = NULL;
89 return TRUE;
90 case WM_COMMAND:
91 switch (LOWORD(wParam)) {
[email protected]ac6eedd12011-07-06 22:19:1492 case IDC_CONTINUE_DEFAULT:
[email protected]1bafb3c2011-11-23 23:39:5093 callback_.Run(true);
[email protected]29b05822011-09-09 18:17:0594 ::EndDialog(hwnd, LOWORD(wParam));
95 hwnd_ = NULL;
[email protected]0e6a47e2011-06-22 22:30:3896 return TRUE;
[email protected]ac6eedd12011-07-06 22:19:1497 case IDC_CONTINUE_CANCEL:
[email protected]1bafb3c2011-11-23 23:39:5098 callback_.Run(false);
[email protected]29b05822011-09-09 18:17:0599 ::EndDialog(hwnd, LOWORD(wParam));
100 hwnd_ = NULL;
[email protected]ac6eedd12011-07-06 22:19:14101 return TRUE;
[email protected]0e6a47e2011-06-22 22:30:38102 }
103 }
104 return FALSE;
105}
106
[email protected]1bafb3c2011-11-23 23:39:50107void ContinueWindowWin::Show(ChromotingHost* host,
108 const ContinueSessionCallback& callback) {
[email protected]0e6a47e2011-06-22 22:30:38109 host_ = host;
[email protected]1bafb3c2011-11-23 23:39:50110 callback_ = callback;
[email protected]0e6a47e2011-06-22 22:30:38111
112 CHECK(!hwnd_);
113 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_CONTINUE), NULL,
114 (DLGPROC)DialogProc, (LPARAM)this);
115 if (!hwnd_) {
116 LOG(ERROR) << "Unable to create Disconnect dialog for remoting.";
117 return;
118 }
119
[email protected]29b05822011-09-09 18:17:05120 SetStrings(host->ui_strings());
[email protected]0e6a47e2011-06-22 22:30:38121 ShowWindow(hwnd_, SW_SHOW);
[email protected]38a4d772011-06-16 21:25:34122}
123
124void ContinueWindowWin::Hide() {
[email protected]0e6a47e2011-06-22 22:30:38125 EndDialog();
126}
127
128void ContinueWindowWin::EndDialog() {
129 if (hwnd_) {
130 ::EndDialog(hwnd_, 0);
131 hwnd_ = NULL;
132 }
[email protected]38a4d772011-06-16 21:25:34133}
134
[email protected]29b05822011-09-09 18:17:05135void ContinueWindowWin::SetStrings(const UiStrings& strings) {
136 SetWindowText(hwnd_, strings.product_name.c_str());
137
138 HWND hwndMessage = GetDlgItem(hwnd_, IDC_CONTINUE_MESSAGE);
139 CHECK(hwndMessage);
140 SetWindowText(hwndMessage, strings.continue_prompt.c_str());
141
142 HWND hwndDefault = GetDlgItem(hwnd_, IDC_CONTINUE_DEFAULT);
143 CHECK(hwndDefault);
144 SetWindowText(hwndDefault, strings.continue_button_text.c_str());
145
146 HWND hwndCancel = GetDlgItem(hwnd_, IDC_CONTINUE_CANCEL);
147 CHECK(hwndCancel);
148 SetWindowText(hwndCancel, strings.stop_sharing_button_text.c_str());
149}
150
[email protected]3361e1f2012-03-20 20:31:44151scoped_ptr<ContinueWindow> ContinueWindow::Create() {
152 return scoped_ptr<ContinueWindow>(new ContinueWindowWin());
[email protected]38a4d772011-06-16 21:25:34153}
154
155} // namespace remoting