source: vendor/synergy/1.3.1/cmd/launcher/CGlobalOptions.cpp

Last change on this file was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 7.5 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2002 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include "CConfig.h"
16#include "ProtocolTypes.h"
17#include "CStringUtil.h"
18#include "CArch.h"
19#include "CGlobalOptions.h"
20#include "LaunchUtil.h"
21#include "resource.h"
22
23static const int s_defaultDelay = 250;
24static const int s_defaultHeartbeat = 5000;
25
26//
27// CGlobalOptions
28//
29
30CGlobalOptions* CGlobalOptions::s_singleton = NULL;
31
32CGlobalOptions::CGlobalOptions(HWND parent, CConfig* config) :
33 m_parent(parent),
34 m_config(config),
35 m_delayTime(s_defaultDelay),
36 m_twoTapTime(s_defaultDelay),
37 m_heartbeatTime(s_defaultHeartbeat)
38{
39 assert(s_singleton == NULL);
40 s_singleton = this;
41}
42
43CGlobalOptions::~CGlobalOptions()
44{
45 s_singleton = NULL;
46}
47
48void
49CGlobalOptions::doModal()
50{
51 // do dialog
52 DialogBoxParam(s_instance, MAKEINTRESOURCE(IDD_GLOBAL_OPTIONS),
53 m_parent, dlgProc, (LPARAM)this);
54}
55
56void
57CGlobalOptions::init(HWND hwnd)
58{
59 HWND child;
60 char buffer[30];
61
62 // reset options
63 sprintf(buffer, "%d", m_delayTime);
64 child = getItem(hwnd, IDC_GLOBAL_DELAY_CHECK);
65 setItemChecked(child, false);
66 child = getItem(hwnd, IDC_GLOBAL_DELAY_TIME);
67 setWindowText(child, buffer);
68 sprintf(buffer, "%d", m_twoTapTime);
69 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_CHECK);
70 setItemChecked(child, false);
71 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_TIME);
72 setWindowText(child, buffer);
73 sprintf(buffer, "%d", m_heartbeatTime);
74 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_CHECK);
75 setItemChecked(child, false);
76 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_TIME);
77 setWindowText(child, buffer);
78 child = getItem(hwnd, IDC_GLOBAL_SCREENSAVER_SYNC);
79 setItemChecked(child, true);
80 child = getItem(hwnd, IDC_GLOBAL_RELATIVE_MOVES);
81 setItemChecked(child, false);
82 child = getItem(hwnd, IDC_GLOBAL_LEAVE_FOREGROUND);
83 setItemChecked(child, false);
84
85 // get the global options
86 const CConfig::CScreenOptions* options = m_config->getOptions("");
87 if (options != NULL) {
88 for (CConfig::CScreenOptions::const_iterator index = options->begin();
89 index != options->end(); ++index) {
90 const OptionID id = index->first;
91 const OptionValue value = index->second;
92 if (id == kOptionScreenSwitchDelay) {
93 if (value > 0) {
94 sprintf(buffer, "%d", value);
95 child = getItem(hwnd, IDC_GLOBAL_DELAY_CHECK);
96 setItemChecked(child, true);
97 child = getItem(hwnd, IDC_GLOBAL_DELAY_TIME);
98 setWindowText(child, buffer);
99 }
100 }
101 else if (id == kOptionScreenSwitchTwoTap) {
102 if (value > 0) {
103 sprintf(buffer, "%d", value);
104 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_CHECK);
105 setItemChecked(child, true);
106 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_TIME);
107 setWindowText(child, buffer);
108 }
109 }
110 else if (id == kOptionHeartbeat) {
111 if (value > 0) {
112 sprintf(buffer, "%d", value);
113 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_CHECK);
114 setItemChecked(child, true);
115 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_TIME);
116 setWindowText(child, buffer);
117 }
118 }
119 else if (id == kOptionScreenSaverSync) {
120 child = getItem(hwnd, IDC_GLOBAL_SCREENSAVER_SYNC);
121 setItemChecked(child, (value != 0));
122 }
123 else if (id == kOptionRelativeMouseMoves) {
124 child = getItem(hwnd, IDC_GLOBAL_RELATIVE_MOVES);
125 setItemChecked(child, (value != 0));
126 }
127 else if (id == kOptionWin32KeepForeground) {
128 child = getItem(hwnd, IDC_GLOBAL_LEAVE_FOREGROUND);
129 setItemChecked(child, (value != 0));
130 }
131 }
132 }
133}
134
135bool
136CGlobalOptions::save(HWND hwnd)
137{
138 HWND child;
139 int newDelayTime = 0;
140 int newTwoTapTime = 0;
141 int newHeartbeatTime = 0;
142
143 // get requested options
144 child = getItem(hwnd, IDC_GLOBAL_DELAY_CHECK);
145 if (isItemChecked(child)) {
146 child = getItem(hwnd, IDC_GLOBAL_DELAY_TIME);
147 newDelayTime = getTime(hwnd, child, true);
148 if (newDelayTime == 0) {
149 return false;
150 }
151 }
152 else {
153 child = getItem(hwnd, IDC_GLOBAL_DELAY_TIME);
154 newDelayTime = getTime(hwnd, child, false);
155 if (newDelayTime == 0) {
156 newDelayTime = s_defaultDelay;
157 }
158 }
159 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_CHECK);
160 if (isItemChecked(child)) {
161 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_TIME);
162 newTwoTapTime = getTime(hwnd, child, true);
163 if (newTwoTapTime == 0) {
164 return false;
165 }
166 }
167 else {
168 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_TIME);
169 newTwoTapTime = getTime(hwnd, child, false);
170 if (newTwoTapTime == 0) {
171 newTwoTapTime = s_defaultDelay;
172 }
173 }
174 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_CHECK);
175 if (isItemChecked(child)) {
176 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_TIME);
177 newHeartbeatTime = getTime(hwnd, child, true);
178 if (newHeartbeatTime == 0) {
179 return false;
180 }
181 }
182 else {
183 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_TIME);
184 newHeartbeatTime = getTime(hwnd, child, false);
185 if (newHeartbeatTime == 0) {
186 newHeartbeatTime = s_defaultHeartbeat;
187 }
188 }
189
190 // remove existing config options
191 m_config->removeOption("", kOptionScreenSwitchDelay);
192 m_config->removeOption("", kOptionScreenSwitchTwoTap);
193 m_config->removeOption("", kOptionHeartbeat);
194 m_config->removeOption("", kOptionScreenSaverSync);
195 m_config->removeOption("", kOptionRelativeMouseMoves);
196 m_config->removeOption("", kOptionWin32KeepForeground);
197
198 // add requested options
199 child = getItem(hwnd, IDC_GLOBAL_DELAY_CHECK);
200 if (isItemChecked(child)) {
201 m_config->addOption("", kOptionScreenSwitchDelay, newDelayTime);
202 }
203 child = getItem(hwnd, IDC_GLOBAL_TWO_TAP_CHECK);
204 if (isItemChecked(child)) {
205 m_config->addOption("", kOptionScreenSwitchTwoTap, newTwoTapTime);
206 }
207 child = getItem(hwnd, IDC_GLOBAL_HEARTBEAT_CHECK);
208 if (isItemChecked(child)) {
209 m_config->addOption("", kOptionHeartbeat, newHeartbeatTime);
210 }
211 child = getItem(hwnd, IDC_GLOBAL_SCREENSAVER_SYNC);
212 if (!isItemChecked(child)) {
213 m_config->addOption("", kOptionScreenSaverSync, 0);
214 }
215 child = getItem(hwnd, IDC_GLOBAL_RELATIVE_MOVES);
216 if (isItemChecked(child)) {
217 m_config->addOption("", kOptionRelativeMouseMoves, 1);
218 }
219 child = getItem(hwnd, IDC_GLOBAL_LEAVE_FOREGROUND);
220 if (isItemChecked(child)) {
221 m_config->addOption("", kOptionWin32KeepForeground, 1);
222 }
223
224 // save last values
225 m_delayTime = newDelayTime;
226 m_twoTapTime = newTwoTapTime;
227 m_heartbeatTime = newHeartbeatTime;
228 return true;
229}
230
231int
232CGlobalOptions::getTime(HWND hwnd, HWND child, bool reportError)
233{
234 CString valueString = getWindowText(child);
235 int value = atoi(valueString.c_str());
236 if (value < 1) {
237 if (reportError) {
238 showError(hwnd, CStringUtil::format(
239 getString(IDS_INVALID_TIME).c_str(),
240 valueString.c_str()));
241 SetFocus(child);
242 }
243 return 0;
244 }
245 return value;
246}
247
248BOOL
249CGlobalOptions::doDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM)
250{
251 switch (message) {
252 case WM_INITDIALOG:
253 init(hwnd);
254 return TRUE;
255
256 case WM_COMMAND:
257 switch (LOWORD(wParam)) {
258 case IDOK:
259 if (save(hwnd)) {
260 EndDialog(hwnd, 0);
261 }
262 return TRUE;
263
264 case IDCANCEL:
265 EndDialog(hwnd, 0);
266 return TRUE;
267 }
268 break;
269
270 default:
271 break;
272 }
273
274 return FALSE;
275}
276
277BOOL CALLBACK
278CGlobalOptions::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
279{
280 return s_singleton->doDlgProc(hwnd, message, wParam, lParam);
281}
Note: See TracBrowser for help on using the repository browser.