blob: da479993446832a23751c5de5c99c177f1aca216 [file] [log] [blame]
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001/* Copyright (C) 2004 TightVNC Team. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- RFB Player for Win32
20
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000021#include <rfb/LogWriter.h>
22#include <rfb/Exception.h>
23#include <rfb/Threading.h>
24
25#include <rfb_win32/Win32Util.h>
26#include <rfb_win32/WMShatter.h>
george82357c9f52005-03-21 01:28:12 +000027#include <rfb_win32/AboutDialog.h>
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000028
george820981b342005-03-19 11:19:00 +000029#include <rfbplayer/PixelFormatList.h>
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000030#include <rfbplayer/rfbplayer.h>
george82357c9f52005-03-21 01:28:12 +000031
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000032using namespace rfb;
33using namespace rfb::win32;
34
35// -=- Variables & consts
36
37static LogWriter vlog("RfbPlayer");
38
39TStr rfb::win32::AppName("RfbPlayer");
40extern const char* buildTime;
41
george82e6883de2005-02-08 14:42:12 +000042char wrong_cmd_msg[] =
43 "Wrong command-line parameters!\n"
44 "Use for help: rfbplayer -help";
45
46char usage_msg[] =
47 "usage: rfbplayer <options> <filename>\n"
48 "Command-line options:\n"
49 " -help \t- Provide usage information.\n"
george825caee412005-03-09 09:52:10 +000050 " -pf <mode> \t- Forces the pixel format for the session.\n"
george82dfb557b2005-03-21 18:26:50 +000051 " \t <mode>=r<r_bits>g<g_bits>b<b_bits>[le|be],\n"
52 " \t r_bits - size the red component, in bits,\n"
53 " \t g_bits - size the green component, in bits,\n"
54 " \t b_bits - size the blue component, in bits,\n"
55 " \t le - little endian byte order (default),\n"
56 " \t be - big endian byte order.\n"
57 " \t The r, g, b component is in any order.\n"
58 " \t Default: auto detect the pixel format.\n"
george82e6883de2005-02-08 14:42:12 +000059 " -speed <value>\t- Sets playback speed, where 1 is normal speed,\n"
60 " \t is double speed, 0.5 is half speed. Default: 1.0.\n"
61 " -pos <ms> \t- Sets initial time position in the session file,\n"
62 " \t in milliseconds. Default: 0.\n"
george825e7af742005-03-10 14:26:00 +000063 " -autoplay \t- Runs the player in the playback mode.\n";
george82e6883de2005-02-08 14:42:12 +000064
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000065// -=- RfbPlayer's defines
66
67#define strcasecmp _stricmp
george820981b342005-03-19 11:19:00 +000068#define UPF_REGISTRY_PATH "Software\\TightVnc\\RfbPlayer\\UserDefinedPF"
george825457d412005-02-19 06:43:09 +000069#define MAX_SPEED 10.00
70#define CALCULATION_ERROR MAX_SPEED / 1000
george82d4d69e62005-02-05 09:23:18 +000071#define MAX_POS_TRACKBAR_RANGE 50
george825e7af742005-03-10 14:26:00 +000072#define CTRL_BAR_HEIGHT 28
george8268d25142005-02-13 09:33:22 +000073#define DEFAULT_PLAYER_WIDTH 640
74#define DEFAULT_PLAYER_HEIGHT 480
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000075
george82d070c692005-01-19 16:44:04 +000076#define ID_TOOLBAR 500
77#define ID_PLAY 510
78#define ID_PAUSE 520
79#define ID_TIME_STATIC 530
80#define ID_SPEED_STATIC 540
81#define ID_SPEED_EDIT 550
82#define ID_POS_TRACKBAR 560
83#define ID_SPEED_UPDOWN 570
84
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000085//
george82357c9f52005-03-21 01:28:12 +000086// -=- AboutDialog global values
87//
88
89const WORD rfb::win32::AboutDialog::DialogId = IDD_ABOUT;
90const WORD rfb::win32::AboutDialog::Copyright = IDC_COPYRIGHT;
91const WORD rfb::win32::AboutDialog::Version = IDC_VERSION;
92const WORD rfb::win32::AboutDialog::BuildTime = IDC_BUILDTIME;
93const WORD rfb::win32::AboutDialog::Description = IDC_DESCRIPTION;
94
95//
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000096// -=- RfbPlayerClass
97
98//
99// Window class used as the basis for RfbPlayer instance
100//
101
102class RfbPlayerClass {
103public:
104 RfbPlayerClass();
105 ~RfbPlayerClass();
106 ATOM classAtom;
107 HINSTANCE instance;
108};
109
110LRESULT CALLBACK RfbPlayerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
111 LRESULT result;
112
113 if (msg == WM_CREATE)
114 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
115 else if (msg == WM_DESTROY) {
116 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000117 SetWindowLong(hwnd, GWL_USERDATA, 0);
118 }
119 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
120 if (!_this) {
121 vlog.info("null _this in %x, message %u", hwnd, msg);
122 return DefWindowProc(hwnd, msg, wParam, lParam);
123 }
124
125 try {
126 result = _this->processMainMessage(hwnd, msg, wParam, lParam);
127 } catch (rdr::Exception& e) {
128 vlog.error("untrapped: %s", e.str());
129 }
130
131 return result;
132};
133
134RfbPlayerClass::RfbPlayerClass() : classAtom(0) {
135 WNDCLASS wndClass;
136 wndClass.style = 0;
137 wndClass.lpfnWndProc = RfbPlayerProc;
138 wndClass.cbClsExtra = 0;
139 wndClass.cbWndExtra = 0;
140 wndClass.hInstance = instance = GetModuleHandle(0);
141 wndClass.hIcon = (HICON)LoadImage(GetModuleHandle(0),
george827214b822004-12-12 07:02:51 +0000142 MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_SHARED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000143 if (!wndClass.hIcon)
144 printf("unable to load icon:%ld", GetLastError());
145 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
146 wndClass.hbrBackground = HBRUSH(COLOR_WINDOW);
george82c2c691f2004-12-08 18:04:14 +0000147 wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000148 wndClass.lpszClassName = _T("RfbPlayerClass");
149 classAtom = RegisterClass(&wndClass);
150 if (!classAtom) {
151 throw rdr::SystemException("unable to register RfbPlayer window class",
152 GetLastError());
153 }
154}
155
156RfbPlayerClass::~RfbPlayerClass() {
157 if (classAtom) {
158 UnregisterClass((const TCHAR*)classAtom, instance);
159 }
160}
161
162RfbPlayerClass baseClass;
163
164//
165// -=- RfbFrameClass
166
167//
168// Window class used to displaying the rfb data
169//
170
171class RfbFrameClass {
172public:
173 RfbFrameClass();
174 ~RfbFrameClass();
175 ATOM classAtom;
176 HINSTANCE instance;
177};
178
179LRESULT CALLBACK FrameProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
180 LRESULT result;
181
182 if (msg == WM_CREATE)
183 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
184 else if (msg == WM_DESTROY)
185 SetWindowLong(hwnd, GWL_USERDATA, 0);
186 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
187 if (!_this) {
188 vlog.info("null _this in %x, message %u", hwnd, msg);
189 return DefWindowProc(hwnd, msg, wParam, lParam);
190 }
191
192 try {
193 result = _this->processFrameMessage(hwnd, msg, wParam, lParam);
194 } catch (rdr::Exception& e) {
195 vlog.error("untrapped: %s", e.str());
196 }
197
198 return result;
199}
200
201RfbFrameClass::RfbFrameClass() : classAtom(0) {
202 WNDCLASS wndClass;
203 wndClass.style = 0;
204 wndClass.lpfnWndProc = FrameProc;
205 wndClass.cbClsExtra = 0;
206 wndClass.cbWndExtra = 0;
207 wndClass.hInstance = instance = GetModuleHandle(0);
208 wndClass.hIcon = 0;
209 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
210 wndClass.hbrBackground = 0;
211 wndClass.lpszMenuName = 0;
212 wndClass.lpszClassName = _T("RfbPlayerClass1");
213 classAtom = RegisterClass(&wndClass);
214 if (!classAtom) {
215 throw rdr::SystemException("unable to register RfbPlayer window class",
216 GetLastError());
217 }
218}
219
220RfbFrameClass::~RfbFrameClass() {
221 if (classAtom) {
222 UnregisterClass((const TCHAR*)classAtom, instance);
223 }
224}
225
226RfbFrameClass frameClass;
227
228//
229// -=- RfbPlayer instance implementation
230//
231
george825e7af742005-03-10 14:26:00 +0000232RfbPlayer::RfbPlayer(char *_fileName, PlayerOptions *_options)
233: RfbProto(_fileName), fileName(_fileName), buffer(0), client_size(0, 0, 32, 32),
234 window_size(0, 0, 32, 32), cutText(0), seekMode(false), lastPos(0),
235 timeStatic(0), speedEdit(0), posTrackBar(0), speedUpDown(0),
george823104aec2005-02-21 13:20:56 +0000236 rfbReader(0), sessionTimeMs(0), sliderDraging(false), sliderStepMs(0),
george825e7af742005-03-10 14:26:00 +0000237 imageDataStartTime(0), rewindFlag(false), stopped(false) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000238
george825e7af742005-03-10 14:26:00 +0000239 // Save the player options
240 memcpy(&options, _options, sizeof(options));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000241
george823c8fbbf2005-01-24 11:09:08 +0000242 // Reset the full session time
243 strcpy(fullSessionTime, "00m:00s");
244
george820981b342005-03-19 11:19:00 +0000245 // Load the user defined pixel formats from the registry
246 supportedPF.readUserDefinedPF(HKEY_CURRENT_USER, UPF_REGISTRY_PATH);
247
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000248 // Create the main window
249 const TCHAR* name = _T("RfbPlayer");
george822ff7a612005-02-19 17:05:24 +0000250 int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - DEFAULT_PLAYER_WIDTH) / 2);
251 int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - DEFAULT_PLAYER_HEIGHT) / 2);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000252 mainHwnd = CreateWindow((const TCHAR*)baseClass.classAtom, name, WS_OVERLAPPEDWINDOW,
george822ff7a612005-02-19 17:05:24 +0000253 x, y, DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT, 0, 0, baseClass.instance, this);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000254 if (!mainHwnd) {
255 throw rdr::SystemException("unable to create WMNotifier window instance", GetLastError());
256 }
257 vlog.debug("created window \"%s\" (%x)", (const char*)CStr(name), getMainHandle());
258
259 // Create the backing buffer
260 buffer = new win32::DIBSectionBuffer(getFrameHandle());
george8210313102005-01-17 13:11:40 +0000261 setVisible(true);
george825beb62a2005-02-09 13:04:32 +0000262
george825e7af742005-03-10 14:26:00 +0000263 // If run with command-line parameters,
264 // open the session file with default settings, otherwise
265 // restore player settings from the registry
george8217e92cb2005-01-31 16:01:02 +0000266 if (fileName) {
267 openSessionFile(fileName);
george825e7af742005-03-10 14:26:00 +0000268 if (options.initTime > 0) setPos(options.initTime);
269 setSpeed(options.playbackSpeed);
george8263ebbcc2005-02-12 12:09:13 +0000270 } else {
george825e7af742005-03-10 14:26:00 +0000271 options.readFromRegistry();
george8263ebbcc2005-02-12 12:09:13 +0000272 disableTBandMenuItems();
george82f5302762005-02-13 12:31:03 +0000273 setTitle("None");
george8217e92cb2005-01-31 16:01:02 +0000274 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000275}
276
277RfbPlayer::~RfbPlayer() {
278 vlog.debug("~RfbPlayer");
george82ce8dc3a2005-01-31 13:06:54 +0000279 if (rfbReader) {
george82ce8dc3a2005-01-31 13:06:54 +0000280 delete rfbReader->join();
281 rfbReader = 0;
282 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000283 if (mainHwnd) {
284 setVisible(false);
285 DestroyWindow(mainHwnd);
286 mainHwnd = 0;
287 }
george825beb62a2005-02-09 13:04:32 +0000288 if (buffer) delete buffer;
289 if (cutText) delete [] cutText;
george827009c892005-02-19 12:49:42 +0000290 if (fileName) delete [] fileName;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000291 vlog.debug("~RfbPlayer done");
292}
293
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000294LRESULT
295RfbPlayer::processMainMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
296 switch (msg) {
297
298 // -=- Process standard window messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000299
300 case WM_CREATE:
301 {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000302 // Create the frame window
303 frameHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, (const TCHAR*)frameClass.classAtom,
304 0, WS_CHILD | WS_VISIBLE, 0, CTRL_BAR_HEIGHT, 10, CTRL_BAR_HEIGHT + 10,
305 hwnd, 0, frameClass.instance, this);
306
george82d070c692005-01-19 16:44:04 +0000307 createToolBar(hwnd);
308
george82006f2792005-02-05 07:40:47 +0000309 hMenu = GetMenu(hwnd);
george825c13c662005-01-27 14:48:23 +0000310
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000311 return 0;
312 }
313
george827214b822004-12-12 07:02:51 +0000314 // Process the main menu and toolbar's messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000315
316 case WM_COMMAND:
george825c13c662005-01-27 14:48:23 +0000317 switch (LOWORD(wParam)) {
george826e51fcc2005-02-06 13:30:49 +0000318 case ID_OPENFILE:
319 {
320 char curDir[_MAX_DIR];
321 static char filename[_MAX_PATH];
322 OPENFILENAME ofn;
323 memset((void *) &ofn, 0, sizeof(OPENFILENAME));
324 GetCurrentDirectory(sizeof(curDir), curDir);
325
326 ofn.lStructSize = sizeof(OPENFILENAME);
327 ofn.hwndOwner = getMainHandle();
328 ofn.lpstrFile = filename;
329 ofn.nMaxFile = sizeof(filename);
330 ofn.lpstrInitialDir = curDir;
331 ofn.lpstrFilter = "Rfb Session files (*.rfb)\0*.rfb\0" \
332 "All files (*.*)\0*.*\0";
333 ofn.lpstrDefExt = "rfb";
334 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
george829d5129a2005-02-21 13:32:39 +0000335 if (GetOpenFileName(&ofn)) {
george826e51fcc2005-02-06 13:30:49 +0000336 openSessionFile(filename);
george829d5129a2005-02-21 13:32:39 +0000337 }
george826e51fcc2005-02-06 13:30:49 +0000338 }
339 break;
george8271ca1772005-02-13 10:50:46 +0000340 case ID_CLOSEFILE:
341 closeSessionFile();
342 break;
george825c13c662005-01-27 14:48:23 +0000343 case ID_PLAY:
344 setPaused(false);
george825c13c662005-01-27 14:48:23 +0000345 break;
346 case ID_PAUSE:
347 setPaused(true);
george825c13c662005-01-27 14:48:23 +0000348 break;
349 case ID_STOP:
350 if (getTimeOffset() != 0) {
george82006f2792005-02-05 07:40:47 +0000351 stopPlayback();
george825c13c662005-01-27 14:48:23 +0000352 }
george825c13c662005-01-27 14:48:23 +0000353 break;
354 case ID_PLAYPAUSE:
george82bc999f42005-03-19 11:48:19 +0000355 if (rfbReader) {
356 if (isPaused()) {
357 setPaused(false);
358 } else {
359 setPaused(true);
360 }
george825c13c662005-01-27 14:48:23 +0000361 }
george825c13c662005-01-27 14:48:23 +0000362 break;
george827549df42005-02-08 16:31:02 +0000363 case ID_GOTO:
364 {
365 GotoPosDialog gotoPosDlg;
george82d9957b72005-03-11 14:22:14 +0000366 if (gotoPosDlg.showDialog(getMainHandle())) {
george821d5d40d2005-02-20 03:25:47 +0000367 long gotoTime = min(gotoPosDlg.getPos(), sessionTimeMs);
368 setPos(gotoTime);
369 updatePos(gotoTime);
george82a6900d72005-02-21 17:24:26 +0000370 setPaused(isPaused());;
george827549df42005-02-08 16:31:02 +0000371 }
372 }
373 break;
george825c13c662005-01-27 14:48:23 +0000374 case ID_FULLSCREEN:
375 MessageBox(getMainHandle(), "It is not working yet!", "RfbPlayer", MB_OK);
376 break;
george8231a36332005-02-06 17:27:34 +0000377 case ID_LOOP:
george825e7af742005-03-10 14:26:00 +0000378 options.loopPlayback = !options.loopPlayback;
379 if (options.loopPlayback) CheckMenuItem(hMenu, ID_LOOP, MF_CHECKED);
george8231a36332005-02-06 17:27:34 +0000380 else CheckMenuItem(hMenu, ID_LOOP, MF_UNCHECKED);
381 break;
george824ea27f62005-01-29 15:03:06 +0000382 case ID_RETURN:
383 // Update the speed if return pressed in speedEdit
384 if (speedEdit == GetFocus()) {
385 char speedStr[20], *stopStr;
386 GetWindowText(speedEdit, speedStr, sizeof(speedStr));
387 double speed = strtod(speedStr, &stopStr);
388 if (speed > 0) {
389 speed = min(MAX_SPEED, speed);
george824ea27f62005-01-29 15:03:06 +0000390 } else {
391 speed = getSpeed();
392 }
393 setSpeed(speed);
george824ea27f62005-01-29 15:03:06 +0000394 }
395 break;
george825e7af742005-03-10 14:26:00 +0000396 case ID_OPTIONS:
397 {
george825a6df072005-03-20 09:56:17 +0000398 OptionsDialog optionsDialog(&options, &supportedPF);
george82d9957b72005-03-11 14:22:14 +0000399 optionsDialog.showDialog(getMainHandle());
george825e7af742005-03-10 14:26:00 +0000400 }
401 break;
george8201aa6732005-02-06 17:13:03 +0000402 case ID_EXIT:
george8201aa6732005-02-06 17:13:03 +0000403 PostQuitMessage(0);
404 break;
george82ef5f7262005-02-08 15:09:26 +0000405 case ID_HELP_COMMANDLINESWITCHES:
george8259f84532005-02-08 15:01:39 +0000406 MessageBox(getMainHandle(),
407 usage_msg, "RfbPlayer", MB_OK | MB_ICONINFORMATION);
408 break;
george82357c9f52005-03-21 01:28:12 +0000409 case ID_ABOUT:
410 AboutDialog::instance.showDialog();
411 break;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000412 }
413 break;
414
415 // Update frame's window size and add scrollbars if required
416
417 case WM_SIZE:
418 {
george82d070c692005-01-19 16:44:04 +0000419
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000420 Point old_offset = bufferToClient(Point(0, 0));
421
422 // Update the cached sizing information
423 RECT r;
424 GetClientRect(getMainHandle(), &r);
425 MoveWindow(getFrameHandle(), 0, CTRL_BAR_HEIGHT, r.right - r.left,
426 r.bottom - r.top - CTRL_BAR_HEIGHT, TRUE);
427
428 GetWindowRect(getFrameHandle(), &r);
429 window_size = Rect(r.left, r.top, r.right, r.bottom);
430 GetClientRect(getFrameHandle(), &r);
431 client_size = Rect(r.left, r.top, r.right, r.bottom);
432
433 // Determine whether scrollbars are required
434 calculateScrollBars();
george82d070c692005-01-19 16:44:04 +0000435
436 // Resize the ToolBar
437 tb.autoSize();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000438
439 // Redraw if required
440 if (!old_offset.equals(bufferToClient(Point(0, 0))))
441 InvalidateRect(getFrameHandle(), 0, TRUE);
442 }
443 break;
george828a471482005-02-06 07:15:53 +0000444
445 // Process messages from posTrackBar
446
447 case WM_HSCROLL:
448 {
449 long Pos = SendMessage(posTrackBar, TBM_GETPOS, 0, 0);
450 Pos *= sliderStepMs;
451
452 switch (LOWORD(wParam)) {
453 case TB_PAGEUP:
454 case TB_PAGEDOWN:
455 case TB_LINEUP:
456 case TB_LINEDOWN:
457 case TB_THUMBTRACK:
458 sliderDraging = true;
459 updatePos(Pos);
460 return 0;
george82bcc129b2005-03-15 17:11:40 +0000461 case TB_THUMBPOSITION:
george828a471482005-02-06 07:15:53 +0000462 case TB_ENDTRACK:
463 setPos(Pos);
george82a6900d72005-02-21 17:24:26 +0000464 setPaused(isPaused());;
george82bcc129b2005-03-15 17:11:40 +0000465 updatePos(Pos);
george828a471482005-02-06 07:15:53 +0000466 sliderDraging = false;
467 return 0;
468 default:
469 break;
470 }
471 }
472 break;
george829e6e6cc2005-01-29 13:12:05 +0000473
474 case WM_NOTIFY:
475 switch (((NMHDR*)lParam)->code) {
476 case UDN_DELTAPOS:
477 if ((int)wParam == ID_SPEED_UPDOWN) {
george824ea27f62005-01-29 15:03:06 +0000478 BOOL lResult = FALSE;
george829e6e6cc2005-01-29 13:12:05 +0000479 char speedStr[20] = "\0";
480 DWORD speedRange = SendMessage(speedUpDown, UDM_GETRANGE, 0, 0);
481 LPNM_UPDOWN upDown = (LPNM_UPDOWN)lParam;
482 double speed;
483
george824ea27f62005-01-29 15:03:06 +0000484 // The out of range checking
george829e6e6cc2005-01-29 13:12:05 +0000485 if (upDown->iDelta > 0) {
486 speed = min(upDown->iPos + upDown->iDelta, LOWORD(speedRange)) * 0.5;
487 } else {
george824ea27f62005-01-29 15:03:06 +0000488 // It's need to round the UpDown position
489 if ((upDown->iPos * 0.5) != getSpeed()) {
490 upDown->iDelta = 0;
491 lResult = TRUE;
492 }
george829e6e6cc2005-01-29 13:12:05 +0000493 speed = max(upDown->iPos + upDown->iDelta, HIWORD(speedRange)) * 0.5;
494 }
george829e6e6cc2005-01-29 13:12:05 +0000495 sprintf(speedStr, "%.2f", speed);
496 SetWindowText(speedEdit, speedStr);
george825f326fe2005-02-20 08:01:01 +0000497 is->setSpeed(speed);
george825e7af742005-03-10 14:26:00 +0000498 options.playbackSpeed = speed;
george824ea27f62005-01-29 15:03:06 +0000499 return lResult;
george829e6e6cc2005-01-29 13:12:05 +0000500 }
george824ea27f62005-01-29 15:03:06 +0000501 }
george829e6e6cc2005-01-29 13:12:05 +0000502 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000503
504 case WM_CLOSE:
505 vlog.debug("WM_CLOSE %x", getMainHandle());
506 PostQuitMessage(0);
507 break;
508 }
509
510 return rfb::win32::SafeDefWindowProc(getMainHandle(), msg, wParam, lParam);
511}
512
513LRESULT RfbPlayer::processFrameMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
514 switch (msg) {
515
516 case WM_PAINT:
517 {
george821e846ff2005-02-24 13:13:33 +0000518 if (isSeeking() || rewindFlag) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000519 seekMode = true;
520 return 0;
521 } else {
522 if (seekMode) {
523 seekMode = false;
524 InvalidateRect(getFrameHandle(), 0, true);
525 UpdateWindow(getFrameHandle());
526 return 0;
527 }
528 }
529
530 PAINTSTRUCT ps;
531 HDC paintDC = BeginPaint(getFrameHandle(), &ps);
532 if (!paintDC)
533 throw SystemException("unable to BeginPaint", GetLastError());
534 Rect pr = Rect(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
535
536 if (!pr.is_empty()) {
537
538 if (buffer->bitmap) {
539
540 // Get device context
541 BitmapDC bitmapDC(paintDC, buffer->bitmap);
542
543 // Blit the border if required
544 Rect bufpos = bufferToClient(buffer->getRect());
545 if (!pr.enclosed_by(bufpos)) {
546 vlog.debug("draw border");
547 HBRUSH black = (HBRUSH) GetStockObject(BLACK_BRUSH);
548 RECT r;
549 SetRect(&r, 0, 0, bufpos.tl.x, client_size.height()); FillRect(paintDC, &r, black);
550 SetRect(&r, bufpos.tl.x, 0, bufpos.br.x, bufpos.tl.y); FillRect(paintDC, &r, black);
551 SetRect(&r, bufpos.br.x, 0, client_size.width(), client_size.height()); FillRect(paintDC, &r, black);
552 SetRect(&r, bufpos.tl.x, bufpos.br.y, bufpos.br.x, client_size.height()); FillRect(paintDC, &r, black);
553 }
554
555 // Do the blit
556 Point buf_pos = clientToBuffer(pr.tl);
557 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
558 bitmapDC, buf_pos.x, buf_pos.y, SRCCOPY))
559 throw SystemException("unable to BitBlt to window", GetLastError());
560
561 } else {
562 // Blit a load of black
563 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
564 0, 0, 0, BLACKNESS))
565 throw SystemException("unable to BitBlt to blank window", GetLastError());
566 }
567 }
568 EndPaint(getFrameHandle(), &ps);
569 }
570 return 0;
george8203c01da2005-03-16 12:36:53 +0000571
george82aff63ab2005-03-16 13:48:59 +0000572 // Process play/pause by the left mouse button
573 case WM_LBUTTONDOWN:
george8203c01da2005-03-16 12:36:53 +0000574 SendMessage(getMainHandle(), WM_COMMAND, ID_PLAYPAUSE, 0);
575 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000576
577 case WM_VSCROLL:
578 case WM_HSCROLL:
579 {
580 Point delta;
581 int newpos = (msg == WM_VSCROLL) ? scrolloffset.y : scrolloffset.x;
582
583 switch (LOWORD(wParam)) {
584 case SB_PAGEUP: newpos -= 50; break;
585 case SB_PAGEDOWN: newpos += 50; break;
586 case SB_LINEUP: newpos -= 5; break;
587 case SB_LINEDOWN: newpos += 5; break;
588 case SB_THUMBTRACK:
589 case SB_THUMBPOSITION: newpos = HIWORD(wParam); break;
590 default: vlog.info("received unknown scroll message");
591 };
592
593 if (msg == WM_HSCROLL)
594 setViewportOffset(Point(newpos, scrolloffset.y));
595 else
596 setViewportOffset(Point(scrolloffset.x, newpos));
597
598 SCROLLINFO si;
599 si.cbSize = sizeof(si);
600 si.fMask = SIF_POS;
601 si.nPos = newpos;
602 SetScrollInfo(getFrameHandle(), (msg == WM_VSCROLL) ? SB_VERT : SB_HORZ, &si, TRUE);
603 }
604 break;
605 }
606
607 return DefWindowProc(hwnd, msg, wParam, lParam);
608}
609
george82d070c692005-01-19 16:44:04 +0000610void RfbPlayer::createToolBar(HWND parentHwnd) {
611 RECT tRect;
612 InitCommonControls();
613
614 tb.create(ID_TOOLBAR, parentHwnd);
615 tb.addBitmap(4, IDB_TOOLBAR);
616
617 // Create the control buttons
618 tb.addButton(0, ID_PLAY);
619 tb.addButton(1, ID_PAUSE);
620 tb.addButton(2, ID_STOP);
621 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
622 tb.addButton(3, ID_FULLSCREEN);
623 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
624
625 // Create the static control for the time output
626 tb.addButton(125, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
627 tb.getButtonRect(6, &tRect);
628 timeStatic = CreateWindowEx(0, "Static", "00m:00s (00m:00s)",
629 WS_CHILD | WS_VISIBLE, tRect.left, tRect.top+2, tRect.right-tRect.left,
630 tRect.bottom-tRect.top, tb.getHandle(), (HMENU)ID_TIME_STATIC,
631 GetModuleHandle(0), 0);
632 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
633
634 // Create the trackbar control for the time position
635 tb.addButton(200, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
636 tb.getButtonRect(8, &tRect);
george82d4d69e62005-02-05 09:23:18 +0000637 posTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, "Trackbar Control",
george82d070c692005-01-19 16:44:04 +0000638 WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS | TBS_ENABLESELRANGE,
639 tRect.left, tRect.top, tRect.right-tRect.left, tRect.bottom-tRect.top,
640 parentHwnd, (HMENU)ID_POS_TRACKBAR, GetModuleHandle(0), 0);
641 // It's need to send notify messages to toolbar parent window
george82d4d69e62005-02-05 09:23:18 +0000642 SetParent(posTrackBar, tb.getHandle());
george82d070c692005-01-19 16:44:04 +0000643 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
644
645 // Create the label with "Speed:" caption
646 tb.addButton(50, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
647 tb.getButtonRect(10, &tRect);
648 CreateWindowEx(0, "Static", "Speed:", WS_CHILD | WS_VISIBLE,
649 tRect.left, tRect.top+2, tRect.right-tRect.left, tRect.bottom-tRect.top,
650 tb.getHandle(), (HMENU)ID_SPEED_STATIC, GetModuleHandle(0), 0);
651
652 // Create the edit control and the spin for the speed managing
653 tb.addButton(60, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
654 tb.getButtonRect(11, &tRect);
655 speedEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "1.00",
656 WS_CHILD | WS_VISIBLE | ES_RIGHT, tRect.left, tRect.top,
657 tRect.right-tRect.left, tRect.bottom-tRect.top, parentHwnd,
658 (HMENU)ID_SPEED_EDIT, GetModuleHandle(0), 0);
659 // It's need to send notify messages to toolbar parent window
660 SetParent(speedEdit, tb.getHandle());
661
662 speedUpDown = CreateUpDownControl(WS_CHILD | WS_VISIBLE
663 | WS_BORDER | UDS_ALIGNRIGHT, 0, 0, 0, 0, tb.getHandle(),
george829e6e6cc2005-01-29 13:12:05 +0000664 ID_SPEED_UPDOWN, GetModuleHandle(0), speedEdit, 20, 1, 2);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000665}
666
george82a21d2952005-02-12 11:30:03 +0000667void RfbPlayer::disableTBandMenuItems() {
668 // Disable the menu items
669 EnableMenuItem(hMenu, ID_CLOSEFILE, MF_GRAYED | MF_BYCOMMAND);
670 EnableMenuItem(hMenu, ID_FULLSCREEN, MF_GRAYED | MF_BYCOMMAND);
671 EnableMenuItem(GetSubMenu(hMenu, 1), 1, MF_GRAYED | MF_BYPOSITION);
672 EnableMenuItem(hMenu, ID_PLAYPAUSE, MF_GRAYED | MF_BYCOMMAND);
673 EnableMenuItem(hMenu, ID_STOP, MF_GRAYED | MF_BYCOMMAND);
674 EnableMenuItem(hMenu, ID_GOTO, MF_GRAYED | MF_BYCOMMAND);
675 EnableMenuItem(hMenu, ID_LOOP, MF_GRAYED | MF_BYCOMMAND);
676 EnableMenuItem(hMenu, ID_COPYTOCLIPBOARD, MF_GRAYED | MF_BYCOMMAND);
677 EnableMenuItem(hMenu, ID_FRAMEEXTRACT, MF_GRAYED | MF_BYCOMMAND);
678
679 // Disable the toolbar buttons and child controls
680 tb.enableButton(ID_PLAY, false);
681 tb.enableButton(ID_PAUSE, false);
682 tb.enableButton(ID_STOP, false);
683 tb.enableButton(ID_FULLSCREEN, false);
684 EnableWindow(posTrackBar, false);
685 EnableWindow(speedEdit, false);
george82e0a28ab2005-02-19 06:54:47 +0000686 EnableWindow(speedUpDown, false);
george82a21d2952005-02-12 11:30:03 +0000687}
688
george82f5043162005-02-12 11:37:18 +0000689void RfbPlayer::enableTBandMenuItems() {
690 // Enable the menu items
691 EnableMenuItem(hMenu, ID_CLOSEFILE, MF_ENABLED | MF_BYCOMMAND);
692 EnableMenuItem(hMenu, ID_FULLSCREEN, MF_ENABLED | MF_BYCOMMAND);
693 EnableMenuItem(GetSubMenu(hMenu, 1), 1, MF_ENABLED | MF_BYPOSITION);
694 EnableMenuItem(hMenu, ID_PLAYPAUSE, MF_ENABLED | MF_BYCOMMAND);
695 EnableMenuItem(hMenu, ID_STOP, MF_ENABLED | MF_BYCOMMAND);
696 EnableMenuItem(hMenu, ID_GOTO, MF_ENABLED | MF_BYCOMMAND);
697 EnableMenuItem(hMenu, ID_LOOP, MF_ENABLED | MF_BYCOMMAND);
698 EnableMenuItem(hMenu, ID_COPYTOCLIPBOARD, MF_ENABLED | MF_BYCOMMAND);
699 EnableMenuItem(hMenu, ID_FRAMEEXTRACT, MF_ENABLED | MF_BYCOMMAND);
700
701 // Enable the toolbar buttons and child controls
702 tb.enableButton(ID_PLAY, true);
703 tb.enableButton(ID_PAUSE, true);
704 tb.enableButton(ID_STOP, true);
705 tb.enableButton(ID_FULLSCREEN, true);
706 EnableWindow(posTrackBar, true);
707 EnableWindow(speedEdit, true);
george82e0a28ab2005-02-19 06:54:47 +0000708 EnableWindow(speedUpDown, true);
george82f5043162005-02-12 11:37:18 +0000709}
710
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000711void RfbPlayer::setVisible(bool visible) {
712 ShowWindow(getMainHandle(), visible ? SW_SHOW : SW_HIDE);
713 if (visible) {
714 // When the window becomes visible, make it active
715 SetForegroundWindow(getMainHandle());
716 SetActiveWindow(getMainHandle());
717 }
718}
719
720void RfbPlayer::setTitle(const char *title) {
721 char _title[256];
722 strcpy(_title, AppName);
723 strcat(_title, " - ");
724 strcat(_title, title);
725 SetWindowText(getMainHandle(), _title);
726}
727
728void RfbPlayer::setFrameSize(int width, int height) {
729 // Calculate and set required size for main window
730 RECT r = {0, 0, width, height};
george82e1169a12005-02-19 13:54:38 +0000731 AdjustWindowRectEx(&r, GetWindowLong(getFrameHandle(), GWL_STYLE), TRUE,
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000732 GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
733 r.bottom += CTRL_BAR_HEIGHT; // Include RfbPlayr's controls area
734 AdjustWindowRect(&r, GetWindowLong(getMainHandle(), GWL_STYLE), FALSE);
george822ff7a612005-02-19 17:05:24 +0000735 int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2);
736 int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2);
737 SetWindowPos(getMainHandle(), 0, x, y, r.right-r.left, r.bottom-r.top,
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000738 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
739
740 // Enable/disable scrollbars as appropriate
741 calculateScrollBars();
742}
743
744void RfbPlayer::calculateScrollBars() {
745 // Calculate the required size of window
746 DWORD current_style = GetWindowLong(getFrameHandle(), GWL_STYLE);
747 DWORD style = current_style & ~(WS_VSCROLL | WS_HSCROLL);
748 DWORD old_style;
749 RECT r;
750 SetRect(&r, 0, 0, buffer->width(), buffer->height());
751 AdjustWindowRectEx(&r, style, FALSE, GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
752 Rect reqd_size = Rect(r.left, r.top, r.right, r.bottom);
753
754 // Work out whether scroll bars are required
755 do {
756 old_style = style;
757
758 if (!(style & WS_HSCROLL) && (reqd_size.width() > window_size.width())) {
759 style |= WS_HSCROLL;
760 reqd_size.br.y += GetSystemMetrics(SM_CXHSCROLL);
761 }
762 if (!(style & WS_VSCROLL) && (reqd_size.height() > window_size.height())) {
763 style |= WS_VSCROLL;
764 reqd_size.br.x += GetSystemMetrics(SM_CXVSCROLL);
765 }
766 } while (style != old_style);
767
768 // Tell Windows to update the window style & cached settings
769 if (style != current_style) {
770 SetWindowLong(getFrameHandle(), GWL_STYLE, style);
771 SetWindowPos(getFrameHandle(), NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
772 }
773
774 // Update the scroll settings
775 SCROLLINFO si;
776 if (style & WS_VSCROLL) {
777 si.cbSize = sizeof(si);
778 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
779 si.nMin = 0;
780 si.nMax = buffer->height();
781 si.nPage = buffer->height() - (reqd_size.height() - window_size.height());
782 maxscrolloffset.y = max(0, si.nMax-si.nPage);
783 scrolloffset.y = min(maxscrolloffset.y, scrolloffset.y);
784 si.nPos = scrolloffset.y;
785 SetScrollInfo(getFrameHandle(), SB_VERT, &si, TRUE);
786 }
787 if (style & WS_HSCROLL) {
788 si.cbSize = sizeof(si);
789 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
790 si.nMin = 0;
791 si.nMax = buffer->width();
792 si.nPage = buffer->width() - (reqd_size.width() - window_size.width());
793 maxscrolloffset.x = max(0, si.nMax-si.nPage);
794 scrolloffset.x = min(maxscrolloffset.x, scrolloffset.x);
795 si.nPos = scrolloffset.x;
796 SetScrollInfo(getFrameHandle(), SB_HORZ, &si, TRUE);
797 }
george82a758a7a2005-03-15 16:34:57 +0000798
799 // Update the cached client size
800 GetClientRect(getFrameHandle(), &r);
801 client_size = Rect(r.left, r.top, r.right, r.bottom);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000802}
803
804bool RfbPlayer::setViewportOffset(const Point& tl) {
805/* ***
806 Point np = Point(max(0, min(maxscrolloffset.x, tl.x)),
807 max(0, min(maxscrolloffset.y, tl.y)));
808 */
809 Point np = Point(max(0, min(tl.x, buffer->width()-client_size.width())),
810 max(0, min(tl.y, buffer->height()-client_size.height())));
811 Point delta = np.translate(scrolloffset.negate());
812 if (!np.equals(scrolloffset)) {
813 scrolloffset = np;
814 ScrollWindowEx(getFrameHandle(), -delta.x, -delta.y, 0, 0, 0, 0, SW_INVALIDATE);
815 UpdateWindow(getFrameHandle());
816 return true;
817 }
818 return false;
819}
820
821void RfbPlayer::close(const char* reason) {
822 setVisible(false);
823 if (reason) {
824 vlog.info("closing - %s", reason);
825 MessageBox(NULL, TStr(reason), "RfbPlayer", MB_ICONINFORMATION | MB_OK);
826 }
827 SendMessage(getFrameHandle(), WM_CLOSE, 0, 0);
828}
829
830void RfbPlayer::blankBuffer() {
831 fillRect(buffer->getRect(), 0);
832}
833
834void RfbPlayer::rewind() {
george8223e08562005-01-31 15:16:42 +0000835 bool paused = isPaused();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000836 blankBuffer();
837 newSession(fileName);
838 skipHandshaking();
george825e7af742005-03-10 14:26:00 +0000839 is->setSpeed(options.playbackSpeed);
george828a471482005-02-06 07:15:53 +0000840 if (paused) is->pausePlayback();
841 else is->resumePlayback();
george8223e08562005-01-31 15:16:42 +0000842}
843
844void RfbPlayer::processMsg() {
george820d2e19d2005-03-03 15:47:55 +0000845 // Perform return if waitWhilePaused processed because
846 // rfbReader thread could receive the signal to close
847 if (waitWhilePaused()) return;
848
george8223e08562005-01-31 15:16:42 +0000849 static long update_time = GetTickCount();
850 try {
george828a471482005-02-06 07:15:53 +0000851 if ((!isSeeking()) && ((GetTickCount() - update_time) > 250)
852 && (!sliderDraging)) {
george8223e08562005-01-31 15:16:42 +0000853 // Update pos in the toolbar 4 times in 1 second
george828a471482005-02-06 07:15:53 +0000854 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000855 update_time = GetTickCount();
856 }
857 RfbProto::processMsg();
858 } catch (rdr::Exception e) {
859 if (strcmp(e.str(), "[End Of File]") == 0) {
860 rewind();
george825e7af742005-03-10 14:26:00 +0000861 setPaused(!options.loopPlayback);
george828a471482005-02-06 07:15:53 +0000862 updatePos(getTimeOffset());
george829403bee2005-02-06 11:14:39 +0000863 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george8223e08562005-01-31 15:16:42 +0000864 return;
865 }
866 // It's a special exception to perform backward seeking.
867 // We only rewind the stream and seek the offset
868 if (strcmp(e.str(), "[REWIND]") == 0) {
george821e846ff2005-02-24 13:13:33 +0000869 rewindFlag = true;
george82b95503e2005-02-21 17:02:34 +0000870 long seekOffset = max(getSeekOffset(), imageDataStartTime);
george8223e08562005-01-31 15:16:42 +0000871 rewind();
george820d2e19d2005-03-03 15:47:55 +0000872 if (!stopped) setPos(seekOffset);
873 else stopped = false;
george823104aec2005-02-21 13:20:56 +0000874 updatePos(seekOffset);
george821e846ff2005-02-24 13:13:33 +0000875 rewindFlag = false;
george822c7634b2005-03-10 18:03:27 +0000876 return;
877 }
878 // It's a special exception which is used to terminate the playback
879 if (strcmp(e.str(), "[TERMINATE]") == 0) {
880 sessionTerminateThread *terminate = new sessionTerminateThread(this);
881 terminate->start();
george8223e08562005-01-31 15:16:42 +0000882 } else {
george820e980cc2005-03-10 18:18:34 +0000883 // Show the exception message and close the session playback
884 is->pausePlayback();
885 char message[256] = "\0";
886 strcat(message, e.str());
887 strcat(message, "\nMaybe you force wrong the pixel format for this session");
888 MessageBox(getMainHandle(), message, e.type(), MB_OK | MB_ICONERROR);
889 sessionTerminateThread *terminate = new sessionTerminateThread(this);
890 terminate->start();
george8223e08562005-01-31 15:16:42 +0000891 return;
892 }
893 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000894}
895
george82c7e9f792005-03-20 12:52:46 +0000896long ChoosePixelFormatDialog::pfIndex = DEFAULT_PF_INDEX;
897bool ChoosePixelFormatDialog::bigEndian = false;
898
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000899void RfbPlayer::serverInit() {
900 RfbProto::serverInit();
901
george82b95503e2005-02-21 17:02:34 +0000902 // Save the image data start time
903 imageDataStartTime = is->getTimeOffset();
904
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000905 // Resize the backing buffer
906 buffer->setSize(cp.width, cp.height);
907
908 // Check on the true colour mode
909 if (!(cp.pf()).trueColour)
Peter Ã…strandc81a6522004-12-30 11:32:08 +0000910 throw rdr::Exception("This version plays only true color session!");
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000911
912 // Set the session pixel format
george825e7af742005-03-10 14:26:00 +0000913 if (options.askPixelFormat) {
george82c7e9f792005-03-20 12:52:46 +0000914 ChoosePixelFormatDialog choosePixelFormatDialog(&supportedPF);
george82d9957b72005-03-11 14:22:14 +0000915 if (choosePixelFormatDialog.showDialog(getMainHandle())) {
george82c7e9f792005-03-20 12:52:46 +0000916 long pixelFormatIndex = choosePixelFormatDialog.getPFIndex();
george825a6df072005-03-20 09:56:17 +0000917 if (pixelFormatIndex < 0) {
918 options.autoDetectPF = true;
919 options.setPF((PixelFormat *)&cp.pf());
920 } else {
921 options.autoDetectPF = false;
922 options.setPF(&supportedPF[pixelFormatIndex].PF);
george82c7e9f792005-03-20 12:52:46 +0000923 options.pixelFormat.bigEndian = choosePixelFormatDialog.isBigEndian();
george825a6df072005-03-20 09:56:17 +0000924 }
george822c7634b2005-03-10 18:03:27 +0000925 } else {
926 is->pausePlayback();
927 throw rdr::Exception("[TERMINATE]");
george825e7af742005-03-10 14:26:00 +0000928 }
929 } else {
george82dfb557b2005-03-21 18:26:50 +0000930 if (!options.commandLineParam) {
931 if (options.autoDetectPF) {
932 options.setPF((PixelFormat *)&cp.pf());
933 } else {
934 options.setPF(&supportedPF[options.pixelFormatIndex].PF);
935 options.pixelFormat.bigEndian = options.bigEndianFlag;
936 }
george825a6df072005-03-20 09:56:17 +0000937 }
george825e7af742005-03-10 14:26:00 +0000938 }
george825a6df072005-03-20 09:56:17 +0000939 cp.setPF(options.pixelFormat);
940 buffer->setPF(options.pixelFormat);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000941
942 // If the window is not maximised then resize it
943 if (!(GetWindowLong(getMainHandle(), GWL_STYLE) & WS_MAXIMIZE))
944 setFrameSize(cp.width, cp.height);
945
946 // Set the window title and show it
947 setTitle(cp.name());
george82006f2792005-02-05 07:40:47 +0000948
george82d4d69e62005-02-05 09:23:18 +0000949 // Calculate the full session time and update posTrackBar control
george828a471482005-02-06 07:15:53 +0000950 sessionTimeMs = calculateSessionTime(fileName);
951 sprintf(fullSessionTime, "%.2um:%.2us",
952 sessionTimeMs / 1000 / 60, sessionTimeMs / 1000 % 60);
george82d4d69e62005-02-05 09:23:18 +0000953 SendMessage(posTrackBar, TBM_SETRANGE,
george828a471482005-02-06 07:15:53 +0000954 TRUE, MAKELONG(0, min(sessionTimeMs / 1000, MAX_POS_TRACKBAR_RANGE)));
955 sliderStepMs = sessionTimeMs / SendMessage(posTrackBar, TBM_GETRANGEMAX, 0, 0);
george828a471482005-02-06 07:15:53 +0000956 updatePos(getTimeOffset());
george82d4d69e62005-02-05 09:23:18 +0000957
george825e7af742005-03-10 14:26:00 +0000958 setPaused(!options.autoPlay);
959 // Restore the parameters from registry,
960 // which was replaced by command-line parameters.
george82dfb557b2005-03-21 18:26:50 +0000961 if (options.commandLineParam) {
962 options.readFromRegistry();
963 options.commandLineParam = false;
964 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000965}
966
967void RfbPlayer::setColourMapEntries(int first, int count, U16* rgbs) {
968 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
969 throw rdr::Exception("Can't handle SetColourMapEntries message", "RfbPlayer");
970/* int i;
971 for (i=0;i<count;i++) {
972 buffer->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
973 }
974 // *** change to 0, 256?
975 refreshWindowPalette(first, count);
976 palette_changed = true;
977 InvalidateRect(getFrameHandle(), 0, FALSE);*/
978}
979
980void RfbPlayer::bell() {
george825e7af742005-03-10 14:26:00 +0000981 if (options.acceptBell)
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000982 MessageBeep(-1);
983}
984
985void RfbPlayer::serverCutText(const char* str, int len) {
986 if (cutText != NULL)
987 delete [] cutText;
988 cutText = new char[len + 1];
989 memcpy(cutText, str, len);
990 cutText[len] = '\0';
991}
992
993void RfbPlayer::frameBufferUpdateEnd() {
994};
995
996void RfbPlayer::beginRect(const Rect& r, unsigned int encoding) {
997}
998
999void RfbPlayer::endRect(const Rect& r, unsigned int encoding) {
1000}
1001
1002
1003void RfbPlayer::fillRect(const Rect& r, Pixel pix) {
1004 buffer->fillRect(r, pix);
1005 invalidateBufferRect(r);
1006}
1007
1008void RfbPlayer::imageRect(const Rect& r, void* pixels) {
1009 buffer->imageRect(r, pixels);
1010 invalidateBufferRect(r);
1011}
1012
1013void RfbPlayer::copyRect(const Rect& r, int srcX, int srcY) {
1014 buffer->copyRect(r, Point(r.tl.x-srcX, r.tl.y-srcY));
1015 invalidateBufferRect(r);
1016}
1017
1018bool RfbPlayer::invalidateBufferRect(const Rect& crect) {
1019 Rect rect = bufferToClient(crect);
1020 if (rect.intersect(client_size).is_empty()) return false;
1021 RECT invalid = {rect.tl.x, rect.tl.y, rect.br.x, rect.br.y};
1022 InvalidateRect(getFrameHandle(), &invalid, FALSE);
1023 return true;
1024}
1025
george820d2e19d2005-03-03 15:47:55 +00001026bool RfbPlayer::waitWhilePaused() {
1027 bool result = false;
1028 while(isPaused() && !isSeeking()) {
1029 Sleep(20);
1030 result = true;
1031 }
1032 return result;
1033}
1034
george8257f13522005-02-05 08:48:22 +00001035long RfbPlayer::calculateSessionTime(char *filename) {
1036 FbsInputStream sessionFile(filename);
george828a471482005-02-06 07:15:53 +00001037 sessionFile.setTimeOffset(100000000);
george8257f13522005-02-05 08:48:22 +00001038 try {
1039 while (TRUE) {
1040 sessionFile.skip(1024);
1041 }
1042 } catch (rdr::Exception e) {
1043 if (strcmp(e.str(), "[End Of File]") == 0) {
george828a471482005-02-06 07:15:53 +00001044 return sessionFile.getTimeOffset();
george8257f13522005-02-05 08:48:22 +00001045 } else {
1046 MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
1047 return 0;
1048 }
1049 }
1050 return 0;
1051}
1052
george826b87aff2005-02-13 10:48:21 +00001053void RfbPlayer::closeSessionFile() {
1054 char speedStr[10];
george820bdb2842005-02-19 13:17:58 +00001055 DWORD dwStyle;
george826b87aff2005-02-13 10:48:21 +00001056 RECT r;
1057
1058 // Uncheck all toolbar buttons
1059 if (tb.getHandle()) {
1060 tb.checkButton(ID_PLAY, false);
1061 tb.checkButton(ID_PAUSE, false);
1062 tb.checkButton(ID_STOP, false);
1063 }
1064
1065 // Stop playback and update the player state
1066 disableTBandMenuItems();
1067 if (rfbReader) {
1068 delete rfbReader->join();
1069 rfbReader = 0;
1070 delete [] fileName;
1071 fileName = 0;
1072 }
1073 blankBuffer();
1074 setTitle("None");
george827009c892005-02-19 12:49:42 +00001075 SetWindowText(timeStatic,"00m:00s (00m:00s)");
george825e7af742005-03-10 14:26:00 +00001076 options.playbackSpeed = 1.0;
george826b87aff2005-02-13 10:48:21 +00001077 SendMessage(speedUpDown, UDM_SETPOS,
george825e7af742005-03-10 14:26:00 +00001078 0, MAKELONG((short)(options.playbackSpeed / 0.5), 0));
1079 sprintf(speedStr, "%.2f", options.playbackSpeed);
george826b87aff2005-02-13 10:48:21 +00001080 SetWindowText(speedEdit, speedStr);
1081 SendMessage(posTrackBar, TBM_SETRANGE, TRUE, MAKELONG(0, 0));
1082
1083 // Change the player window size and frame size to default
george820bdb2842005-02-19 13:17:58 +00001084 if ((dwStyle = GetWindowLong(getMainHandle(), GWL_STYLE)) & WS_MAXIMIZE) {
1085 dwStyle &= ~WS_MAXIMIZE;
1086 SetWindowLong(getMainHandle(), GWL_STYLE, dwStyle);
1087 }
george822ff7a612005-02-19 17:05:24 +00001088 int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - DEFAULT_PLAYER_WIDTH) / 2);
1089 int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - DEFAULT_PLAYER_HEIGHT) / 2);
1090 SetWindowPos(getMainHandle(), 0, x, y,
george826b87aff2005-02-13 10:48:21 +00001091 DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT,
george822ff7a612005-02-19 17:05:24 +00001092 SWP_NOZORDER | SWP_FRAMECHANGED);
george826b87aff2005-02-13 10:48:21 +00001093 buffer->setSize(32, 32);
1094 calculateScrollBars();
1095
1096 // Update the cached sizing information and repaint the frame window
1097 GetWindowRect(getFrameHandle(), &r);
1098 window_size = Rect(r.left, r.top, r.right, r.bottom);
1099 GetClientRect(getFrameHandle(), &r);
1100 client_size = Rect(r.left, r.top, r.right, r.bottom);
1101 InvalidateRect(getFrameHandle(), 0, TRUE);
1102 UpdateWindow(getFrameHandle());
1103}
1104
george8217e92cb2005-01-31 16:01:02 +00001105void RfbPlayer::openSessionFile(char *_fileName) {
1106 fileName = strDup(_fileName);
1107
1108 // Close the previous reading thread
1109 if (rfbReader) {
george8217e92cb2005-01-31 16:01:02 +00001110 delete rfbReader->join();
george82b4f969b2005-02-09 16:34:51 +00001111 rfbReader = 0;
george8217e92cb2005-01-31 16:01:02 +00001112 }
1113 blankBuffer();
1114 newSession(fileName);
george825e7af742005-03-10 14:26:00 +00001115 setSpeed(options.playbackSpeed);
george8217e92cb2005-01-31 16:01:02 +00001116 rfbReader = new rfbSessionReader(this);
1117 rfbReader->start();
george826e51fcc2005-02-06 13:30:49 +00001118 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george8263ebbcc2005-02-12 12:09:13 +00001119 enableTBandMenuItems();
george8217e92cb2005-01-31 16:01:02 +00001120}
1121
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001122void RfbPlayer::setPaused(bool paused) {
1123 if (paused) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001124 is->pausePlayback();
george82006f2792005-02-05 07:40:47 +00001125 tb.checkButton(ID_PAUSE, true);
1126 tb.checkButton(ID_PLAY, false);
1127 tb.checkButton(ID_STOP, false);
1128 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
1129 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001130 } else {
george825beb62a2005-02-09 13:04:32 +00001131 if (is) is->resumePlayback();
george82006f2792005-02-05 07:40:47 +00001132 tb.checkButton(ID_PLAY, true);
1133 tb.checkButton(ID_STOP, false);
1134 tb.checkButton(ID_PAUSE, false);
1135 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
1136 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001137 }
1138}
1139
george82006f2792005-02-05 07:40:47 +00001140void RfbPlayer::stopPlayback() {
george820d2e19d2005-03-03 15:47:55 +00001141 stopped = true;
george820d2e19d2005-03-03 15:47:55 +00001142 setPos(0);
george828edfb7a2005-03-03 16:36:10 +00001143 if (is) {
1144 is->pausePlayback();
1145 is->interruptFrameDelay();
1146 }
george82006f2792005-02-05 07:40:47 +00001147 tb.checkButton(ID_STOP, true);
1148 tb.checkButton(ID_PLAY, false);
1149 tb.checkButton(ID_PAUSE, false);
1150 CheckMenuItem(hMenu, ID_STOP, MF_CHECKED);
1151 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_UNCHECKED);
george826da02d72005-02-06 17:02:34 +00001152 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george82006f2792005-02-05 07:40:47 +00001153}
1154
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001155void RfbPlayer::setSpeed(double speed) {
george825f326fe2005-02-20 08:01:01 +00001156 if (speed > 0) {
1157 char speedStr[20] = "\0";
1158 double newSpeed = min(speed, MAX_SPEED);
george825f326fe2005-02-20 08:01:01 +00001159 is->setSpeed(newSpeed);
george825e7af742005-03-10 14:26:00 +00001160 options.playbackSpeed = newSpeed;
george825f326fe2005-02-20 08:01:01 +00001161 SendMessage(speedUpDown, UDM_SETPOS,
1162 0, MAKELONG((short)(newSpeed / 0.5), 0));
1163 sprintf(speedStr, "%.2f", newSpeed);
1164 SetWindowText(speedEdit, speedStr);
1165 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001166}
1167
1168double RfbPlayer::getSpeed() {
1169 return is->getSpeed();
1170}
1171
1172void RfbPlayer::setPos(long pos) {
george82b95503e2005-02-21 17:02:34 +00001173 is->setTimeOffset(max(pos, imageDataStartTime));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001174}
1175
1176long RfbPlayer::getSeekOffset() {
1177 return is->getSeekOffset();
1178}
1179
1180bool RfbPlayer::isSeeking() {
george825beb62a2005-02-09 13:04:32 +00001181 if (is) return is->isSeeking();
1182 else return false;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001183}
1184
1185bool RfbPlayer::isSeekMode() {
1186 return seekMode;
1187}
1188
1189bool RfbPlayer::isPaused() {
1190 return is->isPaused();
1191}
1192
1193long RfbPlayer::getTimeOffset() {
george828a471482005-02-06 07:15:53 +00001194 return max(is->getTimeOffset(), is->getSeekOffset());
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001195}
1196
george828a471482005-02-06 07:15:53 +00001197void RfbPlayer::updatePos(long newPos) {
1198 // Update time pos in static control
george823c8fbbf2005-01-24 11:09:08 +00001199 char timePos[30] = "\0";
george825457d412005-02-19 06:43:09 +00001200 long time = newPos / 1000;
1201 sprintf(timePos, "%.2um:%.2us (%s)", time/60, time%60, fullSessionTime);
george823c8fbbf2005-01-24 11:09:08 +00001202 SetWindowText(timeStatic, timePos);
george828a471482005-02-06 07:15:53 +00001203
1204 // Update the position of slider
1205 if (!sliderDraging) {
george825457d412005-02-19 06:43:09 +00001206 double error = SendMessage(posTrackBar, TBM_GETPOS, 0, 0) *
1207 sliderStepMs / double(newPos);
1208 if (!((error > 1 - CALCULATION_ERROR) && (error <= 1 + CALCULATION_ERROR))) {
1209 SendMessage(posTrackBar, TBM_SETPOS, TRUE, newPos / sliderStepMs);
1210 }
george828a471482005-02-06 07:15:53 +00001211 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001212}
1213
1214void RfbPlayer::skipHandshaking() {
1215 int skipBytes = 12 + 4 + 24 + strlen(cp.name());
1216 is->skip(skipBytes);
1217 state_ = RFBSTATE_NORMAL;
1218}
1219
1220void programInfo() {
1221 win32::FileVersionInfo inf;
1222 _tprintf(_T("%s - %s, Version %s\n"),
1223 inf.getVerString(_T("ProductName")),
1224 inf.getVerString(_T("FileDescription")),
1225 inf.getVerString(_T("FileVersion")));
1226 printf("%s\n", buildTime);
1227 _tprintf(_T("%s\n\n"), inf.getVerString(_T("LegalCopyright")));
1228}
1229
1230void programUsage() {
george82e6883de2005-02-08 14:42:12 +00001231 MessageBox(0, usage_msg, "RfbPlayer", MB_OK | MB_ICONINFORMATION);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001232}
1233
george825beb62a2005-02-09 13:04:32 +00001234char *fileName = 0;
george825e7af742005-03-10 14:26:00 +00001235
1236// playerOptions is the player options with default parameters values,
1237// it is used only for run the player with command-line parameters
1238PlayerOptions playerOptions;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001239bool print_usage = false;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001240
1241bool processParams(int argc, char* argv[]) {
george82dfb557b2005-03-21 18:26:50 +00001242 playerOptions.commandLineParam = true;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001243 for (int i = 1; i < argc; i++) {
1244 if ((strcasecmp(argv[i], "-help") == 0) ||
1245 (strcasecmp(argv[i], "--help") == 0) ||
1246 (strcasecmp(argv[i], "/help") == 0) ||
1247 (strcasecmp(argv[i], "-h") == 0) ||
1248 (strcasecmp(argv[i], "/h") == 0) ||
george82e6883de2005-02-08 14:42:12 +00001249 (strcasecmp(argv[i], "/?") == 0) ||
1250 (strcasecmp(argv[i], "-?") == 0)) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001251 print_usage = true;
1252 return true;
1253 }
1254
george825caee412005-03-09 09:52:10 +00001255 if ((strcasecmp(argv[i], "-pf") == 0) ||
1256 (strcasecmp(argv[i], "/pf") == 0) && (i < argc-1)) {
george82dfb557b2005-03-21 18:26:50 +00001257 char *pf = argv[++i];
1258 char rgb_order[4] = "\0";
1259 int order = RGB_ORDER;
1260 int r = -1, g = -1, b = -1;
1261 bool big_endian = false;
1262 if (strlen(pf) < 6) return false;
1263 while (strlen(pf)) {
1264 if ((pf[0] == 'r') || (pf[0] == 'R')) {
1265 if (r >=0 ) return false;
1266 r = atoi(++pf);
1267 strcat(rgb_order, "r");
1268 continue;
1269 }
1270 if ((pf[0] == 'g') || (pf[0] == 'G')) {
1271 if (g >=0 ) return false;
1272 g = atoi(++pf);
1273 strcat(rgb_order, "g");
1274 continue;
1275 }
1276 if (((pf[0] == 'b') || (pf[0] == 'B')) &&
1277 (pf[1] != 'e') && (pf[1] != 'E')) {
1278 if (b >=0 ) return false;
1279 b = atoi(++pf);
1280 strcat(rgb_order, "b");
1281 continue;
1282 }
1283 if ((pf[0] == 'l') || (pf[0] == 'L') ||
1284 (pf[0] == 'b') || (pf[0] == 'B')) {
1285 if (strcasecmp(pf, "le") == 0) break;
1286 if (strcasecmp(pf, "be") == 0) { big_endian = true; break;}
1287 return false;
1288 }
1289 pf++;
george82193d8e42005-02-20 16:47:01 +00001290 }
george82888b8fb2005-03-22 15:02:39 +00001291 if ((r < 0) || (g < 0) || (b < 0) || (r + g + b > 32)) return false;
george82dfb557b2005-03-21 18:26:50 +00001292 if (strcasecmp(rgb_order, "rgb") == 0) { order = RGB_ORDER; }
1293 else if (strcasecmp(rgb_order, "rbg") == 0) { order = RBG_ORDER; }
1294 else if (strcasecmp(rgb_order, "grb") == 0) { order = GRB_ORDER; }
1295 else if (strcasecmp(rgb_order, "gbr") == 0) { order = GBR_ORDER; }
1296 else if (strcasecmp(rgb_order, "bgr") == 0) { order = BGR_ORDER; }
1297 else if (strcasecmp(rgb_order, "brg") == 0) { order = BRG_ORDER; }
1298 else return false;
1299 playerOptions.autoDetectPF = false;
1300 playerOptions.setPF(order, r, g, b, big_endian);
george82193d8e42005-02-20 16:47:01 +00001301 continue;
1302 }
1303
1304
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001305 if ((strcasecmp(argv[i], "-speed") == 0) ||
1306 (strcasecmp(argv[i], "/speed") == 0) && (i < argc-1)) {
george825e7af742005-03-10 14:26:00 +00001307 double playbackSpeed = atof(argv[++i]);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001308 if (playbackSpeed <= 0) {
1309 return false;
1310 }
george825e7af742005-03-10 14:26:00 +00001311 playerOptions.playbackSpeed = playbackSpeed;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001312 continue;
1313 }
1314
1315 if ((strcasecmp(argv[i], "-pos") == 0) ||
1316 (strcasecmp(argv[i], "/pos") == 0) && (i < argc-1)) {
george825e7af742005-03-10 14:26:00 +00001317 long initTime = atol(argv[++i]);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001318 if (initTime <= 0)
1319 return false;
george825e7af742005-03-10 14:26:00 +00001320 playerOptions.initTime = initTime;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001321 continue;
1322 }
1323
1324 if ((strcasecmp(argv[i], "-autoplay") == 0) ||
1325 (strcasecmp(argv[i], "/autoplay") == 0) && (i < argc-1)) {
george825e7af742005-03-10 14:26:00 +00001326 playerOptions.autoPlay = true;
george82e6883de2005-02-08 14:42:12 +00001327 continue;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001328 }
1329
1330 if (i != argc - 1)
1331 return false;
1332 }
1333
1334 fileName = strDup(argv[argc-1]);
1335 return true;
1336}
1337
1338//
1339// -=- WinMain
1340//
1341
1342int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, char* cmdLine, int cmdShow) {
1343
1344 // - Process the command-line
1345
1346 int argc = __argc;
1347 char** argv = __argv;
george82e6883de2005-02-08 14:42:12 +00001348 if ((argc > 1) && (!processParams(argc, argv))) {
1349 MessageBox(0, wrong_cmd_msg, "RfbPlayer", MB_OK | MB_ICONWARNING);
1350 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001351 }
george82e6883de2005-02-08 14:42:12 +00001352
1353 if (print_usage) {
1354 programUsage();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001355 return 0;
george8267cbcd02005-01-16 15:39:56 +00001356 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001357
george82e6883de2005-02-08 14:42:12 +00001358 // Create the player
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001359 RfbPlayer *player = NULL;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001360 try {
george825e7af742005-03-10 14:26:00 +00001361 player = new RfbPlayer(fileName, &playerOptions);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001362 } catch (rdr::Exception e) {
1363 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1364 delete player;
1365 return 0;
1366 }
1367
1368 // Run the player
george825bbd61b2004-12-09 17:47:37 +00001369 HACCEL hAccel = LoadAccelerators(inst, MAKEINTRESOURCE(IDR_ACCELERATOR));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001370 MSG msg;
1371 while (GetMessage(&msg, NULL, 0, 0) > 0) {
george825bbd61b2004-12-09 17:47:37 +00001372 if(!TranslateAccelerator(player->getMainHandle(), hAccel, &msg)) {
1373 TranslateMessage(&msg);
1374 DispatchMessage(&msg);
1375 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001376 }
1377
george82e6883de2005-02-08 14:42:12 +00001378 // Destroy the player
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001379 try{
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001380 if (player) delete player;
1381 } catch (rdr::Exception e) {
1382 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1383 }
1384
1385 return 0;
1386};