blob: 3e9357df75264013166abb0fce0588b790e3fd73 [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
george825457d412005-02-19 06:43:09 +000068#define MAX_SPEED 10.00
69#define CALCULATION_ERROR MAX_SPEED / 1000
george82d4d69e62005-02-05 09:23:18 +000070#define MAX_POS_TRACKBAR_RANGE 50
george825e7af742005-03-10 14:26:00 +000071#define CTRL_BAR_HEIGHT 28
george8268d25142005-02-13 09:33:22 +000072#define DEFAULT_PLAYER_WIDTH 640
73#define DEFAULT_PLAYER_HEIGHT 480
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000074
george82d070c692005-01-19 16:44:04 +000075#define ID_TOOLBAR 500
76#define ID_PLAY 510
77#define ID_PAUSE 520
78#define ID_TIME_STATIC 530
79#define ID_SPEED_STATIC 540
80#define ID_SPEED_EDIT 550
81#define ID_POS_TRACKBAR 560
82#define ID_SPEED_UPDOWN 570
83
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000084//
george82357c9f52005-03-21 01:28:12 +000085// -=- AboutDialog global values
86//
87
88const WORD rfb::win32::AboutDialog::DialogId = IDD_ABOUT;
89const WORD rfb::win32::AboutDialog::Copyright = IDC_COPYRIGHT;
90const WORD rfb::win32::AboutDialog::Version = IDC_VERSION;
91const WORD rfb::win32::AboutDialog::BuildTime = IDC_BUILDTIME;
92const WORD rfb::win32::AboutDialog::Description = IDC_DESCRIPTION;
93
94//
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000095// -=- RfbPlayerClass
96
97//
98// Window class used as the basis for RfbPlayer instance
99//
100
101class RfbPlayerClass {
102public:
103 RfbPlayerClass();
104 ~RfbPlayerClass();
105 ATOM classAtom;
106 HINSTANCE instance;
107};
108
109LRESULT CALLBACK RfbPlayerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
110 LRESULT result;
111
112 if (msg == WM_CREATE)
113 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
114 else if (msg == WM_DESTROY) {
115 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000116 SetWindowLong(hwnd, GWL_USERDATA, 0);
117 }
118 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
119 if (!_this) {
120 vlog.info("null _this in %x, message %u", hwnd, msg);
121 return DefWindowProc(hwnd, msg, wParam, lParam);
122 }
123
124 try {
125 result = _this->processMainMessage(hwnd, msg, wParam, lParam);
126 } catch (rdr::Exception& e) {
127 vlog.error("untrapped: %s", e.str());
128 }
129
130 return result;
131};
132
133RfbPlayerClass::RfbPlayerClass() : classAtom(0) {
134 WNDCLASS wndClass;
135 wndClass.style = 0;
136 wndClass.lpfnWndProc = RfbPlayerProc;
137 wndClass.cbClsExtra = 0;
138 wndClass.cbWndExtra = 0;
139 wndClass.hInstance = instance = GetModuleHandle(0);
140 wndClass.hIcon = (HICON)LoadImage(GetModuleHandle(0),
george827214b822004-12-12 07:02:51 +0000141 MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_SHARED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000142 if (!wndClass.hIcon)
143 printf("unable to load icon:%ld", GetLastError());
144 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
145 wndClass.hbrBackground = HBRUSH(COLOR_WINDOW);
george82c2c691f2004-12-08 18:04:14 +0000146 wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000147 wndClass.lpszClassName = _T("RfbPlayerClass");
148 classAtom = RegisterClass(&wndClass);
149 if (!classAtom) {
150 throw rdr::SystemException("unable to register RfbPlayer window class",
151 GetLastError());
152 }
153}
154
155RfbPlayerClass::~RfbPlayerClass() {
156 if (classAtom) {
157 UnregisterClass((const TCHAR*)classAtom, instance);
158 }
159}
160
161RfbPlayerClass baseClass;
162
163//
164// -=- RfbFrameClass
165
166//
167// Window class used to displaying the rfb data
168//
169
170class RfbFrameClass {
171public:
172 RfbFrameClass();
173 ~RfbFrameClass();
174 ATOM classAtom;
175 HINSTANCE instance;
176};
177
178LRESULT CALLBACK FrameProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
179 LRESULT result;
180
181 if (msg == WM_CREATE)
182 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
183 else if (msg == WM_DESTROY)
184 SetWindowLong(hwnd, GWL_USERDATA, 0);
185 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
186 if (!_this) {
187 vlog.info("null _this in %x, message %u", hwnd, msg);
188 return DefWindowProc(hwnd, msg, wParam, lParam);
189 }
190
191 try {
192 result = _this->processFrameMessage(hwnd, msg, wParam, lParam);
193 } catch (rdr::Exception& e) {
194 vlog.error("untrapped: %s", e.str());
195 }
196
197 return result;
198}
199
200RfbFrameClass::RfbFrameClass() : classAtom(0) {
201 WNDCLASS wndClass;
202 wndClass.style = 0;
203 wndClass.lpfnWndProc = FrameProc;
204 wndClass.cbClsExtra = 0;
205 wndClass.cbWndExtra = 0;
206 wndClass.hInstance = instance = GetModuleHandle(0);
207 wndClass.hIcon = 0;
208 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
209 wndClass.hbrBackground = 0;
210 wndClass.lpszMenuName = 0;
211 wndClass.lpszClassName = _T("RfbPlayerClass1");
212 classAtom = RegisterClass(&wndClass);
213 if (!classAtom) {
214 throw rdr::SystemException("unable to register RfbPlayer window class",
215 GetLastError());
216 }
217}
218
219RfbFrameClass::~RfbFrameClass() {
220 if (classAtom) {
221 UnregisterClass((const TCHAR*)classAtom, instance);
222 }
223}
224
225RfbFrameClass frameClass;
226
227//
228// -=- RfbPlayer instance implementation
229//
230
george825e7af742005-03-10 14:26:00 +0000231RfbPlayer::RfbPlayer(char *_fileName, PlayerOptions *_options)
232: RfbProto(_fileName), fileName(_fileName), buffer(0), client_size(0, 0, 32, 32),
233 window_size(0, 0, 32, 32), cutText(0), seekMode(false), lastPos(0),
234 timeStatic(0), speedEdit(0), posTrackBar(0), speedUpDown(0),
george823104aec2005-02-21 13:20:56 +0000235 rfbReader(0), sessionTimeMs(0), sliderDraging(false), sliderStepMs(0),
george825e7af742005-03-10 14:26:00 +0000236 imageDataStartTime(0), rewindFlag(false), stopped(false) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000237
george825e7af742005-03-10 14:26:00 +0000238 // Save the player options
239 memcpy(&options, _options, sizeof(options));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000240
george823c8fbbf2005-01-24 11:09:08 +0000241 // Reset the full session time
242 strcpy(fullSessionTime, "00m:00s");
243
george820981b342005-03-19 11:19:00 +0000244 // Load the user defined pixel formats from the registry
245 supportedPF.readUserDefinedPF(HKEY_CURRENT_USER, UPF_REGISTRY_PATH);
246
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000247 // Create the main window
248 const TCHAR* name = _T("RfbPlayer");
george822ff7a612005-02-19 17:05:24 +0000249 int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - DEFAULT_PLAYER_WIDTH) / 2);
250 int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - DEFAULT_PLAYER_HEIGHT) / 2);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000251 mainHwnd = CreateWindow((const TCHAR*)baseClass.classAtom, name, WS_OVERLAPPEDWINDOW,
george822ff7a612005-02-19 17:05:24 +0000252 x, y, DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT, 0, 0, baseClass.instance, this);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000253 if (!mainHwnd) {
254 throw rdr::SystemException("unable to create WMNotifier window instance", GetLastError());
255 }
256 vlog.debug("created window \"%s\" (%x)", (const char*)CStr(name), getMainHandle());
257
258 // Create the backing buffer
259 buffer = new win32::DIBSectionBuffer(getFrameHandle());
george8210313102005-01-17 13:11:40 +0000260 setVisible(true);
george825beb62a2005-02-09 13:04:32 +0000261
george825e7af742005-03-10 14:26:00 +0000262 // If run with command-line parameters,
263 // open the session file with default settings, otherwise
264 // restore player settings from the registry
george8217e92cb2005-01-31 16:01:02 +0000265 if (fileName) {
266 openSessionFile(fileName);
george825e7af742005-03-10 14:26:00 +0000267 if (options.initTime > 0) setPos(options.initTime);
268 setSpeed(options.playbackSpeed);
george8263ebbcc2005-02-12 12:09:13 +0000269 } else {
george825e7af742005-03-10 14:26:00 +0000270 options.readFromRegistry();
george8263ebbcc2005-02-12 12:09:13 +0000271 disableTBandMenuItems();
george82f5302762005-02-13 12:31:03 +0000272 setTitle("None");
george8217e92cb2005-01-31 16:01:02 +0000273 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000274}
275
276RfbPlayer::~RfbPlayer() {
277 vlog.debug("~RfbPlayer");
george82ce8dc3a2005-01-31 13:06:54 +0000278 if (rfbReader) {
george82ce8dc3a2005-01-31 13:06:54 +0000279 delete rfbReader->join();
280 rfbReader = 0;
281 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000282 if (mainHwnd) {
283 setVisible(false);
284 DestroyWindow(mainHwnd);
285 mainHwnd = 0;
286 }
george825beb62a2005-02-09 13:04:32 +0000287 if (buffer) delete buffer;
288 if (cutText) delete [] cutText;
george827009c892005-02-19 12:49:42 +0000289 if (fileName) delete [] fileName;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000290 vlog.debug("~RfbPlayer done");
291}
292
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000293LRESULT
294RfbPlayer::processMainMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
295 switch (msg) {
296
297 // -=- Process standard window messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000298
299 case WM_CREATE:
300 {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000301 // Create the frame window
302 frameHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, (const TCHAR*)frameClass.classAtom,
303 0, WS_CHILD | WS_VISIBLE, 0, CTRL_BAR_HEIGHT, 10, CTRL_BAR_HEIGHT + 10,
304 hwnd, 0, frameClass.instance, this);
305
george82d070c692005-01-19 16:44:04 +0000306 createToolBar(hwnd);
307
george82006f2792005-02-05 07:40:47 +0000308 hMenu = GetMenu(hwnd);
george825c13c662005-01-27 14:48:23 +0000309
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000310 return 0;
311 }
312
george827214b822004-12-12 07:02:51 +0000313 // Process the main menu and toolbar's messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000314
315 case WM_COMMAND:
george825c13c662005-01-27 14:48:23 +0000316 switch (LOWORD(wParam)) {
george826e51fcc2005-02-06 13:30:49 +0000317 case ID_OPENFILE:
318 {
319 char curDir[_MAX_DIR];
320 static char filename[_MAX_PATH];
321 OPENFILENAME ofn;
322 memset((void *) &ofn, 0, sizeof(OPENFILENAME));
323 GetCurrentDirectory(sizeof(curDir), curDir);
324
325 ofn.lStructSize = sizeof(OPENFILENAME);
326 ofn.hwndOwner = getMainHandle();
327 ofn.lpstrFile = filename;
328 ofn.nMaxFile = sizeof(filename);
329 ofn.lpstrInitialDir = curDir;
330 ofn.lpstrFilter = "Rfb Session files (*.rfb)\0*.rfb\0" \
331 "All files (*.*)\0*.*\0";
332 ofn.lpstrDefExt = "rfb";
333 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
george829d5129a2005-02-21 13:32:39 +0000334 if (GetOpenFileName(&ofn)) {
george826e51fcc2005-02-06 13:30:49 +0000335 openSessionFile(filename);
george829d5129a2005-02-21 13:32:39 +0000336 }
george826e51fcc2005-02-06 13:30:49 +0000337 }
338 break;
george8271ca1772005-02-13 10:50:46 +0000339 case ID_CLOSEFILE:
340 closeSessionFile();
341 break;
george825c13c662005-01-27 14:48:23 +0000342 case ID_PLAY:
343 setPaused(false);
george825c13c662005-01-27 14:48:23 +0000344 break;
345 case ID_PAUSE:
346 setPaused(true);
george825c13c662005-01-27 14:48:23 +0000347 break;
348 case ID_STOP:
349 if (getTimeOffset() != 0) {
george82006f2792005-02-05 07:40:47 +0000350 stopPlayback();
george825c13c662005-01-27 14:48:23 +0000351 }
george825c13c662005-01-27 14:48:23 +0000352 break;
353 case ID_PLAYPAUSE:
george82bc999f42005-03-19 11:48:19 +0000354 if (rfbReader) {
355 if (isPaused()) {
356 setPaused(false);
357 } else {
358 setPaused(true);
359 }
george825c13c662005-01-27 14:48:23 +0000360 }
george825c13c662005-01-27 14:48:23 +0000361 break;
george827549df42005-02-08 16:31:02 +0000362 case ID_GOTO:
363 {
364 GotoPosDialog gotoPosDlg;
george82d9957b72005-03-11 14:22:14 +0000365 if (gotoPosDlg.showDialog(getMainHandle())) {
george821d5d40d2005-02-20 03:25:47 +0000366 long gotoTime = min(gotoPosDlg.getPos(), sessionTimeMs);
367 setPos(gotoTime);
368 updatePos(gotoTime);
george82a6900d72005-02-21 17:24:26 +0000369 setPaused(isPaused());;
george827549df42005-02-08 16:31:02 +0000370 }
371 }
372 break;
george825c13c662005-01-27 14:48:23 +0000373 case ID_FULLSCREEN:
374 MessageBox(getMainHandle(), "It is not working yet!", "RfbPlayer", MB_OK);
375 break;
george8231a36332005-02-06 17:27:34 +0000376 case ID_LOOP:
george825e7af742005-03-10 14:26:00 +0000377 options.loopPlayback = !options.loopPlayback;
378 if (options.loopPlayback) CheckMenuItem(hMenu, ID_LOOP, MF_CHECKED);
george8231a36332005-02-06 17:27:34 +0000379 else CheckMenuItem(hMenu, ID_LOOP, MF_UNCHECKED);
380 break;
george824ea27f62005-01-29 15:03:06 +0000381 case ID_RETURN:
382 // Update the speed if return pressed in speedEdit
383 if (speedEdit == GetFocus()) {
384 char speedStr[20], *stopStr;
385 GetWindowText(speedEdit, speedStr, sizeof(speedStr));
386 double speed = strtod(speedStr, &stopStr);
387 if (speed > 0) {
388 speed = min(MAX_SPEED, speed);
george824ea27f62005-01-29 15:03:06 +0000389 } else {
390 speed = getSpeed();
391 }
392 setSpeed(speed);
george824ea27f62005-01-29 15:03:06 +0000393 }
394 break;
george825e7af742005-03-10 14:26:00 +0000395 case ID_OPTIONS:
396 {
george825a6df072005-03-20 09:56:17 +0000397 OptionsDialog optionsDialog(&options, &supportedPF);
george82d9957b72005-03-11 14:22:14 +0000398 optionsDialog.showDialog(getMainHandle());
george825e7af742005-03-10 14:26:00 +0000399 }
400 break;
george8201aa6732005-02-06 17:13:03 +0000401 case ID_EXIT:
george8201aa6732005-02-06 17:13:03 +0000402 PostQuitMessage(0);
403 break;
george82ef5f7262005-02-08 15:09:26 +0000404 case ID_HELP_COMMANDLINESWITCHES:
george8259f84532005-02-08 15:01:39 +0000405 MessageBox(getMainHandle(),
406 usage_msg, "RfbPlayer", MB_OK | MB_ICONINFORMATION);
407 break;
george82357c9f52005-03-21 01:28:12 +0000408 case ID_ABOUT:
409 AboutDialog::instance.showDialog();
410 break;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000411 }
412 break;
413
414 // Update frame's window size and add scrollbars if required
415
416 case WM_SIZE:
417 {
george82d070c692005-01-19 16:44:04 +0000418
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000419 Point old_offset = bufferToClient(Point(0, 0));
420
421 // Update the cached sizing information
422 RECT r;
423 GetClientRect(getMainHandle(), &r);
424 MoveWindow(getFrameHandle(), 0, CTRL_BAR_HEIGHT, r.right - r.left,
425 r.bottom - r.top - CTRL_BAR_HEIGHT, TRUE);
426
427 GetWindowRect(getFrameHandle(), &r);
428 window_size = Rect(r.left, r.top, r.right, r.bottom);
429 GetClientRect(getFrameHandle(), &r);
430 client_size = Rect(r.left, r.top, r.right, r.bottom);
431
432 // Determine whether scrollbars are required
433 calculateScrollBars();
george82d070c692005-01-19 16:44:04 +0000434
435 // Resize the ToolBar
436 tb.autoSize();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000437
438 // Redraw if required
439 if (!old_offset.equals(bufferToClient(Point(0, 0))))
440 InvalidateRect(getFrameHandle(), 0, TRUE);
441 }
442 break;
george828a471482005-02-06 07:15:53 +0000443
444 // Process messages from posTrackBar
445
446 case WM_HSCROLL:
447 {
448 long Pos = SendMessage(posTrackBar, TBM_GETPOS, 0, 0);
449 Pos *= sliderStepMs;
450
451 switch (LOWORD(wParam)) {
452 case TB_PAGEUP:
453 case TB_PAGEDOWN:
454 case TB_LINEUP:
455 case TB_LINEDOWN:
456 case TB_THUMBTRACK:
457 sliderDraging = true;
458 updatePos(Pos);
459 return 0;
george82bcc129b2005-03-15 17:11:40 +0000460 case TB_THUMBPOSITION:
george828a471482005-02-06 07:15:53 +0000461 case TB_ENDTRACK:
462 setPos(Pos);
george82a6900d72005-02-21 17:24:26 +0000463 setPaused(isPaused());;
george82bcc129b2005-03-15 17:11:40 +0000464 updatePos(Pos);
george828a471482005-02-06 07:15:53 +0000465 sliderDraging = false;
466 return 0;
467 default:
468 break;
469 }
470 }
471 break;
george829e6e6cc2005-01-29 13:12:05 +0000472
473 case WM_NOTIFY:
474 switch (((NMHDR*)lParam)->code) {
475 case UDN_DELTAPOS:
476 if ((int)wParam == ID_SPEED_UPDOWN) {
george824ea27f62005-01-29 15:03:06 +0000477 BOOL lResult = FALSE;
george829e6e6cc2005-01-29 13:12:05 +0000478 char speedStr[20] = "\0";
479 DWORD speedRange = SendMessage(speedUpDown, UDM_GETRANGE, 0, 0);
480 LPNM_UPDOWN upDown = (LPNM_UPDOWN)lParam;
481 double speed;
482
george824ea27f62005-01-29 15:03:06 +0000483 // The out of range checking
george829e6e6cc2005-01-29 13:12:05 +0000484 if (upDown->iDelta > 0) {
485 speed = min(upDown->iPos + upDown->iDelta, LOWORD(speedRange)) * 0.5;
486 } else {
george824ea27f62005-01-29 15:03:06 +0000487 // It's need to round the UpDown position
488 if ((upDown->iPos * 0.5) != getSpeed()) {
489 upDown->iDelta = 0;
490 lResult = TRUE;
491 }
george829e6e6cc2005-01-29 13:12:05 +0000492 speed = max(upDown->iPos + upDown->iDelta, HIWORD(speedRange)) * 0.5;
493 }
george829e6e6cc2005-01-29 13:12:05 +0000494 sprintf(speedStr, "%.2f", speed);
495 SetWindowText(speedEdit, speedStr);
george825f326fe2005-02-20 08:01:01 +0000496 is->setSpeed(speed);
george825e7af742005-03-10 14:26:00 +0000497 options.playbackSpeed = speed;
george824ea27f62005-01-29 15:03:06 +0000498 return lResult;
george829e6e6cc2005-01-29 13:12:05 +0000499 }
george824ea27f62005-01-29 15:03:06 +0000500 }
george829e6e6cc2005-01-29 13:12:05 +0000501 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000502
503 case WM_CLOSE:
504 vlog.debug("WM_CLOSE %x", getMainHandle());
505 PostQuitMessage(0);
506 break;
507 }
508
509 return rfb::win32::SafeDefWindowProc(getMainHandle(), msg, wParam, lParam);
510}
511
512LRESULT RfbPlayer::processFrameMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
513 switch (msg) {
514
515 case WM_PAINT:
516 {
george821e846ff2005-02-24 13:13:33 +0000517 if (isSeeking() || rewindFlag) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000518 seekMode = true;
519 return 0;
520 } else {
521 if (seekMode) {
522 seekMode = false;
523 InvalidateRect(getFrameHandle(), 0, true);
524 UpdateWindow(getFrameHandle());
525 return 0;
526 }
527 }
528
529 PAINTSTRUCT ps;
530 HDC paintDC = BeginPaint(getFrameHandle(), &ps);
531 if (!paintDC)
532 throw SystemException("unable to BeginPaint", GetLastError());
533 Rect pr = Rect(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
534
535 if (!pr.is_empty()) {
536
537 if (buffer->bitmap) {
538
539 // Get device context
540 BitmapDC bitmapDC(paintDC, buffer->bitmap);
541
542 // Blit the border if required
543 Rect bufpos = bufferToClient(buffer->getRect());
544 if (!pr.enclosed_by(bufpos)) {
545 vlog.debug("draw border");
546 HBRUSH black = (HBRUSH) GetStockObject(BLACK_BRUSH);
547 RECT r;
548 SetRect(&r, 0, 0, bufpos.tl.x, client_size.height()); FillRect(paintDC, &r, black);
549 SetRect(&r, bufpos.tl.x, 0, bufpos.br.x, bufpos.tl.y); FillRect(paintDC, &r, black);
550 SetRect(&r, bufpos.br.x, 0, client_size.width(), client_size.height()); FillRect(paintDC, &r, black);
551 SetRect(&r, bufpos.tl.x, bufpos.br.y, bufpos.br.x, client_size.height()); FillRect(paintDC, &r, black);
552 }
553
554 // Do the blit
555 Point buf_pos = clientToBuffer(pr.tl);
556 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
557 bitmapDC, buf_pos.x, buf_pos.y, SRCCOPY))
558 throw SystemException("unable to BitBlt to window", GetLastError());
559
560 } else {
561 // Blit a load of black
562 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
563 0, 0, 0, BLACKNESS))
564 throw SystemException("unable to BitBlt to blank window", GetLastError());
565 }
566 }
567 EndPaint(getFrameHandle(), &ps);
568 }
569 return 0;
george8203c01da2005-03-16 12:36:53 +0000570
george82aff63ab2005-03-16 13:48:59 +0000571 // Process play/pause by the left mouse button
572 case WM_LBUTTONDOWN:
george8203c01da2005-03-16 12:36:53 +0000573 SendMessage(getMainHandle(), WM_COMMAND, ID_PLAYPAUSE, 0);
574 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000575
576 case WM_VSCROLL:
577 case WM_HSCROLL:
578 {
579 Point delta;
580 int newpos = (msg == WM_VSCROLL) ? scrolloffset.y : scrolloffset.x;
581
582 switch (LOWORD(wParam)) {
583 case SB_PAGEUP: newpos -= 50; break;
584 case SB_PAGEDOWN: newpos += 50; break;
585 case SB_LINEUP: newpos -= 5; break;
586 case SB_LINEDOWN: newpos += 5; break;
587 case SB_THUMBTRACK:
588 case SB_THUMBPOSITION: newpos = HIWORD(wParam); break;
589 default: vlog.info("received unknown scroll message");
590 };
591
592 if (msg == WM_HSCROLL)
593 setViewportOffset(Point(newpos, scrolloffset.y));
594 else
595 setViewportOffset(Point(scrolloffset.x, newpos));
596
597 SCROLLINFO si;
598 si.cbSize = sizeof(si);
599 si.fMask = SIF_POS;
600 si.nPos = newpos;
601 SetScrollInfo(getFrameHandle(), (msg == WM_VSCROLL) ? SB_VERT : SB_HORZ, &si, TRUE);
602 }
603 break;
604 }
605
606 return DefWindowProc(hwnd, msg, wParam, lParam);
607}
608
george82d070c692005-01-19 16:44:04 +0000609void RfbPlayer::createToolBar(HWND parentHwnd) {
610 RECT tRect;
611 InitCommonControls();
612
613 tb.create(ID_TOOLBAR, parentHwnd);
614 tb.addBitmap(4, IDB_TOOLBAR);
615
616 // Create the control buttons
617 tb.addButton(0, ID_PLAY);
618 tb.addButton(1, ID_PAUSE);
619 tb.addButton(2, ID_STOP);
620 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
621 tb.addButton(3, ID_FULLSCREEN);
622 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
623
624 // Create the static control for the time output
625 tb.addButton(125, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
626 tb.getButtonRect(6, &tRect);
627 timeStatic = CreateWindowEx(0, "Static", "00m:00s (00m:00s)",
628 WS_CHILD | WS_VISIBLE, tRect.left, tRect.top+2, tRect.right-tRect.left,
629 tRect.bottom-tRect.top, tb.getHandle(), (HMENU)ID_TIME_STATIC,
630 GetModuleHandle(0), 0);
631 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
632
633 // Create the trackbar control for the time position
634 tb.addButton(200, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
635 tb.getButtonRect(8, &tRect);
george82d4d69e62005-02-05 09:23:18 +0000636 posTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, "Trackbar Control",
george82d070c692005-01-19 16:44:04 +0000637 WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS | TBS_ENABLESELRANGE,
638 tRect.left, tRect.top, tRect.right-tRect.left, tRect.bottom-tRect.top,
639 parentHwnd, (HMENU)ID_POS_TRACKBAR, GetModuleHandle(0), 0);
640 // It's need to send notify messages to toolbar parent window
george82d4d69e62005-02-05 09:23:18 +0000641 SetParent(posTrackBar, tb.getHandle());
george82d070c692005-01-19 16:44:04 +0000642 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
643
644 // Create the label with "Speed:" caption
645 tb.addButton(50, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
646 tb.getButtonRect(10, &tRect);
647 CreateWindowEx(0, "Static", "Speed:", WS_CHILD | WS_VISIBLE,
648 tRect.left, tRect.top+2, tRect.right-tRect.left, tRect.bottom-tRect.top,
649 tb.getHandle(), (HMENU)ID_SPEED_STATIC, GetModuleHandle(0), 0);
650
651 // Create the edit control and the spin for the speed managing
652 tb.addButton(60, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
653 tb.getButtonRect(11, &tRect);
654 speedEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "1.00",
655 WS_CHILD | WS_VISIBLE | ES_RIGHT, tRect.left, tRect.top,
656 tRect.right-tRect.left, tRect.bottom-tRect.top, parentHwnd,
657 (HMENU)ID_SPEED_EDIT, GetModuleHandle(0), 0);
658 // It's need to send notify messages to toolbar parent window
659 SetParent(speedEdit, tb.getHandle());
660
661 speedUpDown = CreateUpDownControl(WS_CHILD | WS_VISIBLE
662 | WS_BORDER | UDS_ALIGNRIGHT, 0, 0, 0, 0, tb.getHandle(),
george829e6e6cc2005-01-29 13:12:05 +0000663 ID_SPEED_UPDOWN, GetModuleHandle(0), speedEdit, 20, 1, 2);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000664}
665
george82a21d2952005-02-12 11:30:03 +0000666void RfbPlayer::disableTBandMenuItems() {
667 // Disable the menu items
668 EnableMenuItem(hMenu, ID_CLOSEFILE, MF_GRAYED | MF_BYCOMMAND);
669 EnableMenuItem(hMenu, ID_FULLSCREEN, MF_GRAYED | MF_BYCOMMAND);
670 EnableMenuItem(GetSubMenu(hMenu, 1), 1, MF_GRAYED | MF_BYPOSITION);
671 EnableMenuItem(hMenu, ID_PLAYPAUSE, MF_GRAYED | MF_BYCOMMAND);
672 EnableMenuItem(hMenu, ID_STOP, MF_GRAYED | MF_BYCOMMAND);
673 EnableMenuItem(hMenu, ID_GOTO, MF_GRAYED | MF_BYCOMMAND);
674 EnableMenuItem(hMenu, ID_LOOP, MF_GRAYED | MF_BYCOMMAND);
675 EnableMenuItem(hMenu, ID_COPYTOCLIPBOARD, MF_GRAYED | MF_BYCOMMAND);
676 EnableMenuItem(hMenu, ID_FRAMEEXTRACT, MF_GRAYED | MF_BYCOMMAND);
677
678 // Disable the toolbar buttons and child controls
679 tb.enableButton(ID_PLAY, false);
680 tb.enableButton(ID_PAUSE, false);
681 tb.enableButton(ID_STOP, false);
682 tb.enableButton(ID_FULLSCREEN, false);
683 EnableWindow(posTrackBar, false);
684 EnableWindow(speedEdit, false);
george82e0a28ab2005-02-19 06:54:47 +0000685 EnableWindow(speedUpDown, false);
george82a21d2952005-02-12 11:30:03 +0000686}
687
george82f5043162005-02-12 11:37:18 +0000688void RfbPlayer::enableTBandMenuItems() {
689 // Enable the menu items
690 EnableMenuItem(hMenu, ID_CLOSEFILE, MF_ENABLED | MF_BYCOMMAND);
691 EnableMenuItem(hMenu, ID_FULLSCREEN, MF_ENABLED | MF_BYCOMMAND);
692 EnableMenuItem(GetSubMenu(hMenu, 1), 1, MF_ENABLED | MF_BYPOSITION);
693 EnableMenuItem(hMenu, ID_PLAYPAUSE, MF_ENABLED | MF_BYCOMMAND);
694 EnableMenuItem(hMenu, ID_STOP, MF_ENABLED | MF_BYCOMMAND);
695 EnableMenuItem(hMenu, ID_GOTO, MF_ENABLED | MF_BYCOMMAND);
696 EnableMenuItem(hMenu, ID_LOOP, MF_ENABLED | MF_BYCOMMAND);
697 EnableMenuItem(hMenu, ID_COPYTOCLIPBOARD, MF_ENABLED | MF_BYCOMMAND);
698 EnableMenuItem(hMenu, ID_FRAMEEXTRACT, MF_ENABLED | MF_BYCOMMAND);
699
700 // Enable the toolbar buttons and child controls
701 tb.enableButton(ID_PLAY, true);
702 tb.enableButton(ID_PAUSE, true);
703 tb.enableButton(ID_STOP, true);
704 tb.enableButton(ID_FULLSCREEN, true);
705 EnableWindow(posTrackBar, true);
706 EnableWindow(speedEdit, true);
george82e0a28ab2005-02-19 06:54:47 +0000707 EnableWindow(speedUpDown, true);
george82f5043162005-02-12 11:37:18 +0000708}
709
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000710void RfbPlayer::setVisible(bool visible) {
711 ShowWindow(getMainHandle(), visible ? SW_SHOW : SW_HIDE);
712 if (visible) {
713 // When the window becomes visible, make it active
714 SetForegroundWindow(getMainHandle());
715 SetActiveWindow(getMainHandle());
716 }
717}
718
719void RfbPlayer::setTitle(const char *title) {
720 char _title[256];
721 strcpy(_title, AppName);
722 strcat(_title, " - ");
723 strcat(_title, title);
724 SetWindowText(getMainHandle(), _title);
725}
726
727void RfbPlayer::setFrameSize(int width, int height) {
728 // Calculate and set required size for main window
729 RECT r = {0, 0, width, height};
george82e1169a12005-02-19 13:54:38 +0000730 AdjustWindowRectEx(&r, GetWindowLong(getFrameHandle(), GWL_STYLE), TRUE,
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000731 GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
732 r.bottom += CTRL_BAR_HEIGHT; // Include RfbPlayr's controls area
733 AdjustWindowRect(&r, GetWindowLong(getMainHandle(), GWL_STYLE), FALSE);
george822ff7a612005-02-19 17:05:24 +0000734 int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2);
735 int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2);
736 SetWindowPos(getMainHandle(), 0, x, y, r.right-r.left, r.bottom-r.top,
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000737 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
738
739 // Enable/disable scrollbars as appropriate
740 calculateScrollBars();
741}
742
743void RfbPlayer::calculateScrollBars() {
744 // Calculate the required size of window
745 DWORD current_style = GetWindowLong(getFrameHandle(), GWL_STYLE);
746 DWORD style = current_style & ~(WS_VSCROLL | WS_HSCROLL);
747 DWORD old_style;
748 RECT r;
749 SetRect(&r, 0, 0, buffer->width(), buffer->height());
750 AdjustWindowRectEx(&r, style, FALSE, GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
751 Rect reqd_size = Rect(r.left, r.top, r.right, r.bottom);
752
753 // Work out whether scroll bars are required
754 do {
755 old_style = style;
756
757 if (!(style & WS_HSCROLL) && (reqd_size.width() > window_size.width())) {
758 style |= WS_HSCROLL;
759 reqd_size.br.y += GetSystemMetrics(SM_CXHSCROLL);
760 }
761 if (!(style & WS_VSCROLL) && (reqd_size.height() > window_size.height())) {
762 style |= WS_VSCROLL;
763 reqd_size.br.x += GetSystemMetrics(SM_CXVSCROLL);
764 }
765 } while (style != old_style);
766
767 // Tell Windows to update the window style & cached settings
768 if (style != current_style) {
769 SetWindowLong(getFrameHandle(), GWL_STYLE, style);
770 SetWindowPos(getFrameHandle(), NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
771 }
772
773 // Update the scroll settings
774 SCROLLINFO si;
775 if (style & WS_VSCROLL) {
776 si.cbSize = sizeof(si);
777 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
778 si.nMin = 0;
779 si.nMax = buffer->height();
780 si.nPage = buffer->height() - (reqd_size.height() - window_size.height());
781 maxscrolloffset.y = max(0, si.nMax-si.nPage);
782 scrolloffset.y = min(maxscrolloffset.y, scrolloffset.y);
783 si.nPos = scrolloffset.y;
784 SetScrollInfo(getFrameHandle(), SB_VERT, &si, TRUE);
785 }
786 if (style & WS_HSCROLL) {
787 si.cbSize = sizeof(si);
788 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
789 si.nMin = 0;
790 si.nMax = buffer->width();
791 si.nPage = buffer->width() - (reqd_size.width() - window_size.width());
792 maxscrolloffset.x = max(0, si.nMax-si.nPage);
793 scrolloffset.x = min(maxscrolloffset.x, scrolloffset.x);
794 si.nPos = scrolloffset.x;
795 SetScrollInfo(getFrameHandle(), SB_HORZ, &si, TRUE);
796 }
george82a758a7a2005-03-15 16:34:57 +0000797
798 // Update the cached client size
799 GetClientRect(getFrameHandle(), &r);
800 client_size = Rect(r.left, r.top, r.right, r.bottom);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000801}
802
803bool RfbPlayer::setViewportOffset(const Point& tl) {
804/* ***
805 Point np = Point(max(0, min(maxscrolloffset.x, tl.x)),
806 max(0, min(maxscrolloffset.y, tl.y)));
807 */
808 Point np = Point(max(0, min(tl.x, buffer->width()-client_size.width())),
809 max(0, min(tl.y, buffer->height()-client_size.height())));
810 Point delta = np.translate(scrolloffset.negate());
811 if (!np.equals(scrolloffset)) {
812 scrolloffset = np;
813 ScrollWindowEx(getFrameHandle(), -delta.x, -delta.y, 0, 0, 0, 0, SW_INVALIDATE);
814 UpdateWindow(getFrameHandle());
815 return true;
816 }
817 return false;
818}
819
820void RfbPlayer::close(const char* reason) {
821 setVisible(false);
822 if (reason) {
823 vlog.info("closing - %s", reason);
824 MessageBox(NULL, TStr(reason), "RfbPlayer", MB_ICONINFORMATION | MB_OK);
825 }
826 SendMessage(getFrameHandle(), WM_CLOSE, 0, 0);
827}
828
829void RfbPlayer::blankBuffer() {
830 fillRect(buffer->getRect(), 0);
831}
832
833void RfbPlayer::rewind() {
george8223e08562005-01-31 15:16:42 +0000834 bool paused = isPaused();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000835 blankBuffer();
836 newSession(fileName);
837 skipHandshaking();
george825e7af742005-03-10 14:26:00 +0000838 is->setSpeed(options.playbackSpeed);
george828a471482005-02-06 07:15:53 +0000839 if (paused) is->pausePlayback();
840 else is->resumePlayback();
george8223e08562005-01-31 15:16:42 +0000841}
842
843void RfbPlayer::processMsg() {
george820d2e19d2005-03-03 15:47:55 +0000844 // Perform return if waitWhilePaused processed because
845 // rfbReader thread could receive the signal to close
846 if (waitWhilePaused()) return;
847
george8223e08562005-01-31 15:16:42 +0000848 static long update_time = GetTickCount();
849 try {
george828a471482005-02-06 07:15:53 +0000850 if ((!isSeeking()) && ((GetTickCount() - update_time) > 250)
851 && (!sliderDraging)) {
george8223e08562005-01-31 15:16:42 +0000852 // Update pos in the toolbar 4 times in 1 second
george828a471482005-02-06 07:15:53 +0000853 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000854 update_time = GetTickCount();
855 }
856 RfbProto::processMsg();
857 } catch (rdr::Exception e) {
858 if (strcmp(e.str(), "[End Of File]") == 0) {
859 rewind();
george825e7af742005-03-10 14:26:00 +0000860 setPaused(!options.loopPlayback);
george828a471482005-02-06 07:15:53 +0000861 updatePos(getTimeOffset());
george829403bee2005-02-06 11:14:39 +0000862 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george8223e08562005-01-31 15:16:42 +0000863 return;
864 }
865 // It's a special exception to perform backward seeking.
866 // We only rewind the stream and seek the offset
867 if (strcmp(e.str(), "[REWIND]") == 0) {
george821e846ff2005-02-24 13:13:33 +0000868 rewindFlag = true;
george82b95503e2005-02-21 17:02:34 +0000869 long seekOffset = max(getSeekOffset(), imageDataStartTime);
george8223e08562005-01-31 15:16:42 +0000870 rewind();
george820d2e19d2005-03-03 15:47:55 +0000871 if (!stopped) setPos(seekOffset);
872 else stopped = false;
george823104aec2005-02-21 13:20:56 +0000873 updatePos(seekOffset);
george821e846ff2005-02-24 13:13:33 +0000874 rewindFlag = false;
george822c7634b2005-03-10 18:03:27 +0000875 return;
876 }
877 // It's a special exception which is used to terminate the playback
878 if (strcmp(e.str(), "[TERMINATE]") == 0) {
879 sessionTerminateThread *terminate = new sessionTerminateThread(this);
880 terminate->start();
george8223e08562005-01-31 15:16:42 +0000881 } else {
george820e980cc2005-03-10 18:18:34 +0000882 // Show the exception message and close the session playback
883 is->pausePlayback();
884 char message[256] = "\0";
885 strcat(message, e.str());
886 strcat(message, "\nMaybe you force wrong the pixel format for this session");
887 MessageBox(getMainHandle(), message, e.type(), MB_OK | MB_ICONERROR);
888 sessionTerminateThread *terminate = new sessionTerminateThread(this);
889 terminate->start();
george8223e08562005-01-31 15:16:42 +0000890 return;
891 }
892 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000893}
894
george82c7e9f792005-03-20 12:52:46 +0000895long ChoosePixelFormatDialog::pfIndex = DEFAULT_PF_INDEX;
896bool ChoosePixelFormatDialog::bigEndian = false;
897
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000898void RfbPlayer::serverInit() {
899 RfbProto::serverInit();
900
george82b95503e2005-02-21 17:02:34 +0000901 // Save the image data start time
902 imageDataStartTime = is->getTimeOffset();
903
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000904 // Resize the backing buffer
905 buffer->setSize(cp.width, cp.height);
906
907 // Check on the true colour mode
908 if (!(cp.pf()).trueColour)
Peter Ã…strandc81a6522004-12-30 11:32:08 +0000909 throw rdr::Exception("This version plays only true color session!");
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000910
911 // Set the session pixel format
george825e7af742005-03-10 14:26:00 +0000912 if (options.askPixelFormat) {
george82c7e9f792005-03-20 12:52:46 +0000913 ChoosePixelFormatDialog choosePixelFormatDialog(&supportedPF);
george82d9957b72005-03-11 14:22:14 +0000914 if (choosePixelFormatDialog.showDialog(getMainHandle())) {
george82c7e9f792005-03-20 12:52:46 +0000915 long pixelFormatIndex = choosePixelFormatDialog.getPFIndex();
george825a6df072005-03-20 09:56:17 +0000916 if (pixelFormatIndex < 0) {
917 options.autoDetectPF = true;
918 options.setPF((PixelFormat *)&cp.pf());
919 } else {
920 options.autoDetectPF = false;
george8210326862005-03-28 12:07:31 +0000921 options.setPF(&supportedPF[pixelFormatIndex]->PF);
george82c7e9f792005-03-20 12:52:46 +0000922 options.pixelFormat.bigEndian = choosePixelFormatDialog.isBigEndian();
george825a6df072005-03-20 09:56:17 +0000923 }
george822c7634b2005-03-10 18:03:27 +0000924 } else {
925 is->pausePlayback();
926 throw rdr::Exception("[TERMINATE]");
george825e7af742005-03-10 14:26:00 +0000927 }
928 } else {
george82dfb557b2005-03-21 18:26:50 +0000929 if (!options.commandLineParam) {
930 if (options.autoDetectPF) {
931 options.setPF((PixelFormat *)&cp.pf());
932 } else {
george8210326862005-03-28 12:07:31 +0000933 options.setPF(&supportedPF[options.pixelFormatIndex]->PF);
george82dfb557b2005-03-21 18:26:50 +0000934 options.pixelFormat.bigEndian = options.bigEndianFlag;
935 }
george825a6df072005-03-20 09:56:17 +0000936 }
george825e7af742005-03-10 14:26:00 +0000937 }
george825a6df072005-03-20 09:56:17 +0000938 cp.setPF(options.pixelFormat);
939 buffer->setPF(options.pixelFormat);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000940
941 // If the window is not maximised then resize it
942 if (!(GetWindowLong(getMainHandle(), GWL_STYLE) & WS_MAXIMIZE))
943 setFrameSize(cp.width, cp.height);
944
945 // Set the window title and show it
946 setTitle(cp.name());
george82006f2792005-02-05 07:40:47 +0000947
george82d4d69e62005-02-05 09:23:18 +0000948 // Calculate the full session time and update posTrackBar control
george828a471482005-02-06 07:15:53 +0000949 sessionTimeMs = calculateSessionTime(fileName);
950 sprintf(fullSessionTime, "%.2um:%.2us",
951 sessionTimeMs / 1000 / 60, sessionTimeMs / 1000 % 60);
george82d4d69e62005-02-05 09:23:18 +0000952 SendMessage(posTrackBar, TBM_SETRANGE,
george828a471482005-02-06 07:15:53 +0000953 TRUE, MAKELONG(0, min(sessionTimeMs / 1000, MAX_POS_TRACKBAR_RANGE)));
954 sliderStepMs = sessionTimeMs / SendMessage(posTrackBar, TBM_GETRANGEMAX, 0, 0);
george828a471482005-02-06 07:15:53 +0000955 updatePos(getTimeOffset());
george82d4d69e62005-02-05 09:23:18 +0000956
george825e7af742005-03-10 14:26:00 +0000957 setPaused(!options.autoPlay);
958 // Restore the parameters from registry,
959 // which was replaced by command-line parameters.
george82dfb557b2005-03-21 18:26:50 +0000960 if (options.commandLineParam) {
961 options.readFromRegistry();
962 options.commandLineParam = false;
963 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000964}
965
966void RfbPlayer::setColourMapEntries(int first, int count, U16* rgbs) {
967 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
968 throw rdr::Exception("Can't handle SetColourMapEntries message", "RfbPlayer");
969/* int i;
970 for (i=0;i<count;i++) {
971 buffer->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
972 }
973 // *** change to 0, 256?
974 refreshWindowPalette(first, count);
975 palette_changed = true;
976 InvalidateRect(getFrameHandle(), 0, FALSE);*/
977}
978
979void RfbPlayer::bell() {
george825e7af742005-03-10 14:26:00 +0000980 if (options.acceptBell)
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000981 MessageBeep(-1);
982}
983
984void RfbPlayer::serverCutText(const char* str, int len) {
985 if (cutText != NULL)
986 delete [] cutText;
987 cutText = new char[len + 1];
988 memcpy(cutText, str, len);
989 cutText[len] = '\0';
990}
991
992void RfbPlayer::frameBufferUpdateEnd() {
993};
994
995void RfbPlayer::beginRect(const Rect& r, unsigned int encoding) {
996}
997
998void RfbPlayer::endRect(const Rect& r, unsigned int encoding) {
999}
1000
1001
1002void RfbPlayer::fillRect(const Rect& r, Pixel pix) {
1003 buffer->fillRect(r, pix);
1004 invalidateBufferRect(r);
1005}
1006
1007void RfbPlayer::imageRect(const Rect& r, void* pixels) {
1008 buffer->imageRect(r, pixels);
1009 invalidateBufferRect(r);
1010}
1011
1012void RfbPlayer::copyRect(const Rect& r, int srcX, int srcY) {
1013 buffer->copyRect(r, Point(r.tl.x-srcX, r.tl.y-srcY));
1014 invalidateBufferRect(r);
1015}
1016
1017bool RfbPlayer::invalidateBufferRect(const Rect& crect) {
1018 Rect rect = bufferToClient(crect);
1019 if (rect.intersect(client_size).is_empty()) return false;
1020 RECT invalid = {rect.tl.x, rect.tl.y, rect.br.x, rect.br.y};
1021 InvalidateRect(getFrameHandle(), &invalid, FALSE);
1022 return true;
1023}
1024
george820d2e19d2005-03-03 15:47:55 +00001025bool RfbPlayer::waitWhilePaused() {
1026 bool result = false;
1027 while(isPaused() && !isSeeking()) {
1028 Sleep(20);
1029 result = true;
1030 }
1031 return result;
1032}
1033
george8257f13522005-02-05 08:48:22 +00001034long RfbPlayer::calculateSessionTime(char *filename) {
1035 FbsInputStream sessionFile(filename);
george828a471482005-02-06 07:15:53 +00001036 sessionFile.setTimeOffset(100000000);
george8257f13522005-02-05 08:48:22 +00001037 try {
1038 while (TRUE) {
1039 sessionFile.skip(1024);
1040 }
1041 } catch (rdr::Exception e) {
1042 if (strcmp(e.str(), "[End Of File]") == 0) {
george828a471482005-02-06 07:15:53 +00001043 return sessionFile.getTimeOffset();
george8257f13522005-02-05 08:48:22 +00001044 } else {
1045 MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
1046 return 0;
1047 }
1048 }
1049 return 0;
1050}
1051
george826b87aff2005-02-13 10:48:21 +00001052void RfbPlayer::closeSessionFile() {
1053 char speedStr[10];
george820bdb2842005-02-19 13:17:58 +00001054 DWORD dwStyle;
george826b87aff2005-02-13 10:48:21 +00001055 RECT r;
1056
1057 // Uncheck all toolbar buttons
1058 if (tb.getHandle()) {
1059 tb.checkButton(ID_PLAY, false);
1060 tb.checkButton(ID_PAUSE, false);
1061 tb.checkButton(ID_STOP, false);
1062 }
1063
1064 // Stop playback and update the player state
1065 disableTBandMenuItems();
1066 if (rfbReader) {
1067 delete rfbReader->join();
1068 rfbReader = 0;
1069 delete [] fileName;
1070 fileName = 0;
1071 }
1072 blankBuffer();
1073 setTitle("None");
george827009c892005-02-19 12:49:42 +00001074 SetWindowText(timeStatic,"00m:00s (00m:00s)");
george825e7af742005-03-10 14:26:00 +00001075 options.playbackSpeed = 1.0;
george826b87aff2005-02-13 10:48:21 +00001076 SendMessage(speedUpDown, UDM_SETPOS,
george825e7af742005-03-10 14:26:00 +00001077 0, MAKELONG((short)(options.playbackSpeed / 0.5), 0));
1078 sprintf(speedStr, "%.2f", options.playbackSpeed);
george826b87aff2005-02-13 10:48:21 +00001079 SetWindowText(speedEdit, speedStr);
1080 SendMessage(posTrackBar, TBM_SETRANGE, TRUE, MAKELONG(0, 0));
1081
1082 // Change the player window size and frame size to default
george820bdb2842005-02-19 13:17:58 +00001083 if ((dwStyle = GetWindowLong(getMainHandle(), GWL_STYLE)) & WS_MAXIMIZE) {
1084 dwStyle &= ~WS_MAXIMIZE;
1085 SetWindowLong(getMainHandle(), GWL_STYLE, dwStyle);
1086 }
george822ff7a612005-02-19 17:05:24 +00001087 int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - DEFAULT_PLAYER_WIDTH) / 2);
1088 int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - DEFAULT_PLAYER_HEIGHT) / 2);
1089 SetWindowPos(getMainHandle(), 0, x, y,
george826b87aff2005-02-13 10:48:21 +00001090 DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT,
george822ff7a612005-02-19 17:05:24 +00001091 SWP_NOZORDER | SWP_FRAMECHANGED);
george826b87aff2005-02-13 10:48:21 +00001092 buffer->setSize(32, 32);
1093 calculateScrollBars();
1094
1095 // Update the cached sizing information and repaint the frame window
1096 GetWindowRect(getFrameHandle(), &r);
1097 window_size = Rect(r.left, r.top, r.right, r.bottom);
1098 GetClientRect(getFrameHandle(), &r);
1099 client_size = Rect(r.left, r.top, r.right, r.bottom);
1100 InvalidateRect(getFrameHandle(), 0, TRUE);
1101 UpdateWindow(getFrameHandle());
1102}
1103
george8217e92cb2005-01-31 16:01:02 +00001104void RfbPlayer::openSessionFile(char *_fileName) {
1105 fileName = strDup(_fileName);
1106
1107 // Close the previous reading thread
1108 if (rfbReader) {
george8217e92cb2005-01-31 16:01:02 +00001109 delete rfbReader->join();
george82b4f969b2005-02-09 16:34:51 +00001110 rfbReader = 0;
george8217e92cb2005-01-31 16:01:02 +00001111 }
1112 blankBuffer();
1113 newSession(fileName);
george825e7af742005-03-10 14:26:00 +00001114 setSpeed(options.playbackSpeed);
george8217e92cb2005-01-31 16:01:02 +00001115 rfbReader = new rfbSessionReader(this);
1116 rfbReader->start();
george826e51fcc2005-02-06 13:30:49 +00001117 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george8263ebbcc2005-02-12 12:09:13 +00001118 enableTBandMenuItems();
george8217e92cb2005-01-31 16:01:02 +00001119}
1120
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001121void RfbPlayer::setPaused(bool paused) {
1122 if (paused) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001123 is->pausePlayback();
george82006f2792005-02-05 07:40:47 +00001124 tb.checkButton(ID_PAUSE, true);
1125 tb.checkButton(ID_PLAY, false);
1126 tb.checkButton(ID_STOP, false);
1127 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
1128 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001129 } else {
george825beb62a2005-02-09 13:04:32 +00001130 if (is) is->resumePlayback();
george82006f2792005-02-05 07:40:47 +00001131 tb.checkButton(ID_PLAY, true);
1132 tb.checkButton(ID_STOP, false);
1133 tb.checkButton(ID_PAUSE, false);
1134 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
1135 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001136 }
1137}
1138
george82006f2792005-02-05 07:40:47 +00001139void RfbPlayer::stopPlayback() {
george820d2e19d2005-03-03 15:47:55 +00001140 stopped = true;
george820d2e19d2005-03-03 15:47:55 +00001141 setPos(0);
george828edfb7a2005-03-03 16:36:10 +00001142 if (is) {
1143 is->pausePlayback();
1144 is->interruptFrameDelay();
1145 }
george82006f2792005-02-05 07:40:47 +00001146 tb.checkButton(ID_STOP, true);
1147 tb.checkButton(ID_PLAY, false);
1148 tb.checkButton(ID_PAUSE, false);
1149 CheckMenuItem(hMenu, ID_STOP, MF_CHECKED);
1150 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_UNCHECKED);
george826da02d72005-02-06 17:02:34 +00001151 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george82006f2792005-02-05 07:40:47 +00001152}
1153
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001154void RfbPlayer::setSpeed(double speed) {
george825f326fe2005-02-20 08:01:01 +00001155 if (speed > 0) {
1156 char speedStr[20] = "\0";
1157 double newSpeed = min(speed, MAX_SPEED);
george825f326fe2005-02-20 08:01:01 +00001158 is->setSpeed(newSpeed);
george825e7af742005-03-10 14:26:00 +00001159 options.playbackSpeed = newSpeed;
george825f326fe2005-02-20 08:01:01 +00001160 SendMessage(speedUpDown, UDM_SETPOS,
1161 0, MAKELONG((short)(newSpeed / 0.5), 0));
1162 sprintf(speedStr, "%.2f", newSpeed);
1163 SetWindowText(speedEdit, speedStr);
1164 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001165}
1166
1167double RfbPlayer::getSpeed() {
1168 return is->getSpeed();
1169}
1170
1171void RfbPlayer::setPos(long pos) {
george82b95503e2005-02-21 17:02:34 +00001172 is->setTimeOffset(max(pos, imageDataStartTime));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001173}
1174
1175long RfbPlayer::getSeekOffset() {
1176 return is->getSeekOffset();
1177}
1178
1179bool RfbPlayer::isSeeking() {
george825beb62a2005-02-09 13:04:32 +00001180 if (is) return is->isSeeking();
1181 else return false;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001182}
1183
1184bool RfbPlayer::isSeekMode() {
1185 return seekMode;
1186}
1187
1188bool RfbPlayer::isPaused() {
1189 return is->isPaused();
1190}
1191
1192long RfbPlayer::getTimeOffset() {
george828a471482005-02-06 07:15:53 +00001193 return max(is->getTimeOffset(), is->getSeekOffset());
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001194}
1195
george828a471482005-02-06 07:15:53 +00001196void RfbPlayer::updatePos(long newPos) {
1197 // Update time pos in static control
george823c8fbbf2005-01-24 11:09:08 +00001198 char timePos[30] = "\0";
george825457d412005-02-19 06:43:09 +00001199 long time = newPos / 1000;
1200 sprintf(timePos, "%.2um:%.2us (%s)", time/60, time%60, fullSessionTime);
george823c8fbbf2005-01-24 11:09:08 +00001201 SetWindowText(timeStatic, timePos);
george828a471482005-02-06 07:15:53 +00001202
1203 // Update the position of slider
1204 if (!sliderDraging) {
george825457d412005-02-19 06:43:09 +00001205 double error = SendMessage(posTrackBar, TBM_GETPOS, 0, 0) *
1206 sliderStepMs / double(newPos);
1207 if (!((error > 1 - CALCULATION_ERROR) && (error <= 1 + CALCULATION_ERROR))) {
1208 SendMessage(posTrackBar, TBM_SETPOS, TRUE, newPos / sliderStepMs);
1209 }
george828a471482005-02-06 07:15:53 +00001210 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001211}
1212
1213void RfbPlayer::skipHandshaking() {
1214 int skipBytes = 12 + 4 + 24 + strlen(cp.name());
1215 is->skip(skipBytes);
1216 state_ = RFBSTATE_NORMAL;
1217}
1218
1219void programInfo() {
1220 win32::FileVersionInfo inf;
1221 _tprintf(_T("%s - %s, Version %s\n"),
1222 inf.getVerString(_T("ProductName")),
1223 inf.getVerString(_T("FileDescription")),
1224 inf.getVerString(_T("FileVersion")));
1225 printf("%s\n", buildTime);
1226 _tprintf(_T("%s\n\n"), inf.getVerString(_T("LegalCopyright")));
1227}
1228
1229void programUsage() {
george82e6883de2005-02-08 14:42:12 +00001230 MessageBox(0, usage_msg, "RfbPlayer", MB_OK | MB_ICONINFORMATION);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001231}
1232
george825beb62a2005-02-09 13:04:32 +00001233char *fileName = 0;
george825e7af742005-03-10 14:26:00 +00001234
1235// playerOptions is the player options with default parameters values,
1236// it is used only for run the player with command-line parameters
1237PlayerOptions playerOptions;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001238bool print_usage = false;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001239
1240bool processParams(int argc, char* argv[]) {
george82dfb557b2005-03-21 18:26:50 +00001241 playerOptions.commandLineParam = true;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001242 for (int i = 1; i < argc; i++) {
1243 if ((strcasecmp(argv[i], "-help") == 0) ||
1244 (strcasecmp(argv[i], "--help") == 0) ||
1245 (strcasecmp(argv[i], "/help") == 0) ||
1246 (strcasecmp(argv[i], "-h") == 0) ||
1247 (strcasecmp(argv[i], "/h") == 0) ||
george82e6883de2005-02-08 14:42:12 +00001248 (strcasecmp(argv[i], "/?") == 0) ||
1249 (strcasecmp(argv[i], "-?") == 0)) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001250 print_usage = true;
1251 return true;
1252 }
1253
george825caee412005-03-09 09:52:10 +00001254 if ((strcasecmp(argv[i], "-pf") == 0) ||
1255 (strcasecmp(argv[i], "/pf") == 0) && (i < argc-1)) {
george82dfb557b2005-03-21 18:26:50 +00001256 char *pf = argv[++i];
1257 char rgb_order[4] = "\0";
1258 int order = RGB_ORDER;
1259 int r = -1, g = -1, b = -1;
1260 bool big_endian = false;
1261 if (strlen(pf) < 6) return false;
1262 while (strlen(pf)) {
1263 if ((pf[0] == 'r') || (pf[0] == 'R')) {
1264 if (r >=0 ) return false;
1265 r = atoi(++pf);
1266 strcat(rgb_order, "r");
1267 continue;
1268 }
1269 if ((pf[0] == 'g') || (pf[0] == 'G')) {
1270 if (g >=0 ) return false;
1271 g = atoi(++pf);
1272 strcat(rgb_order, "g");
1273 continue;
1274 }
1275 if (((pf[0] == 'b') || (pf[0] == 'B')) &&
1276 (pf[1] != 'e') && (pf[1] != 'E')) {
1277 if (b >=0 ) return false;
1278 b = atoi(++pf);
1279 strcat(rgb_order, "b");
1280 continue;
1281 }
1282 if ((pf[0] == 'l') || (pf[0] == 'L') ||
1283 (pf[0] == 'b') || (pf[0] == 'B')) {
1284 if (strcasecmp(pf, "le") == 0) break;
1285 if (strcasecmp(pf, "be") == 0) { big_endian = true; break;}
1286 return false;
1287 }
1288 pf++;
george82193d8e42005-02-20 16:47:01 +00001289 }
george82888b8fb2005-03-22 15:02:39 +00001290 if ((r < 0) || (g < 0) || (b < 0) || (r + g + b > 32)) return false;
george82dfb557b2005-03-21 18:26:50 +00001291 if (strcasecmp(rgb_order, "rgb") == 0) { order = RGB_ORDER; }
1292 else if (strcasecmp(rgb_order, "rbg") == 0) { order = RBG_ORDER; }
1293 else if (strcasecmp(rgb_order, "grb") == 0) { order = GRB_ORDER; }
1294 else if (strcasecmp(rgb_order, "gbr") == 0) { order = GBR_ORDER; }
1295 else if (strcasecmp(rgb_order, "bgr") == 0) { order = BGR_ORDER; }
1296 else if (strcasecmp(rgb_order, "brg") == 0) { order = BRG_ORDER; }
1297 else return false;
1298 playerOptions.autoDetectPF = false;
1299 playerOptions.setPF(order, r, g, b, big_endian);
george82193d8e42005-02-20 16:47:01 +00001300 continue;
1301 }
1302
1303
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001304 if ((strcasecmp(argv[i], "-speed") == 0) ||
1305 (strcasecmp(argv[i], "/speed") == 0) && (i < argc-1)) {
george825e7af742005-03-10 14:26:00 +00001306 double playbackSpeed = atof(argv[++i]);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001307 if (playbackSpeed <= 0) {
1308 return false;
1309 }
george825e7af742005-03-10 14:26:00 +00001310 playerOptions.playbackSpeed = playbackSpeed;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001311 continue;
1312 }
1313
1314 if ((strcasecmp(argv[i], "-pos") == 0) ||
1315 (strcasecmp(argv[i], "/pos") == 0) && (i < argc-1)) {
george825e7af742005-03-10 14:26:00 +00001316 long initTime = atol(argv[++i]);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001317 if (initTime <= 0)
1318 return false;
george825e7af742005-03-10 14:26:00 +00001319 playerOptions.initTime = initTime;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001320 continue;
1321 }
1322
1323 if ((strcasecmp(argv[i], "-autoplay") == 0) ||
1324 (strcasecmp(argv[i], "/autoplay") == 0) && (i < argc-1)) {
george825e7af742005-03-10 14:26:00 +00001325 playerOptions.autoPlay = true;
george82e6883de2005-02-08 14:42:12 +00001326 continue;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001327 }
1328
1329 if (i != argc - 1)
1330 return false;
1331 }
1332
1333 fileName = strDup(argv[argc-1]);
1334 return true;
1335}
1336
1337//
1338// -=- WinMain
1339//
1340
1341int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, char* cmdLine, int cmdShow) {
1342
1343 // - Process the command-line
1344
1345 int argc = __argc;
1346 char** argv = __argv;
george82e6883de2005-02-08 14:42:12 +00001347 if ((argc > 1) && (!processParams(argc, argv))) {
1348 MessageBox(0, wrong_cmd_msg, "RfbPlayer", MB_OK | MB_ICONWARNING);
1349 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001350 }
george82e6883de2005-02-08 14:42:12 +00001351
1352 if (print_usage) {
1353 programUsage();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001354 return 0;
george8267cbcd02005-01-16 15:39:56 +00001355 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001356
george82e6883de2005-02-08 14:42:12 +00001357 // Create the player
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001358 RfbPlayer *player = NULL;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001359 try {
george825e7af742005-03-10 14:26:00 +00001360 player = new RfbPlayer(fileName, &playerOptions);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001361 } catch (rdr::Exception e) {
1362 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1363 delete player;
1364 return 0;
1365 }
1366
1367 // Run the player
george825bbd61b2004-12-09 17:47:37 +00001368 HACCEL hAccel = LoadAccelerators(inst, MAKEINTRESOURCE(IDR_ACCELERATOR));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001369 MSG msg;
1370 while (GetMessage(&msg, NULL, 0, 0) > 0) {
george825bbd61b2004-12-09 17:47:37 +00001371 if(!TranslateAccelerator(player->getMainHandle(), hAccel, &msg)) {
1372 TranslateMessage(&msg);
1373 DispatchMessage(&msg);
1374 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001375 }
1376
george82e6883de2005-02-08 14:42:12 +00001377 // Destroy the player
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001378 try{
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001379 if (player) delete player;
1380 } catch (rdr::Exception e) {
1381 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1382 }
1383
1384 return 0;
1385};