blob: c8ff8fc9ecf3abb1dc859d9c7faa69cb5d824fec [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
21#include <conio.h>
22
23#include <rfb/LogWriter.h>
24#include <rfb/Exception.h>
25#include <rfb/Threading.h>
26
27#include <rfb_win32/Win32Util.h>
28#include <rfb_win32/WMShatter.h>
29
30#include <rfbplayer/rfbplayer.h>
31#include <rfbplayer/utils.h>
32#include <rfbplayer/resource.h>
33
34using namespace rfb;
35using namespace rfb::win32;
36
37// -=- Variables & consts
38
39static LogWriter vlog("RfbPlayer");
40
41TStr rfb::win32::AppName("RfbPlayer");
42extern const char* buildTime;
43
44// -=- RfbPlayer's defines
45
46#define strcasecmp _stricmp
george824ea27f62005-01-29 15:03:06 +000047#define MAX_SPEED 10
george82d4d69e62005-02-05 09:23:18 +000048#define MAX_POS_TRACKBAR_RANGE 50
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000049
george82d070c692005-01-19 16:44:04 +000050#define ID_TOOLBAR 500
51#define ID_PLAY 510
52#define ID_PAUSE 520
53#define ID_TIME_STATIC 530
54#define ID_SPEED_STATIC 540
55#define ID_SPEED_EDIT 550
56#define ID_POS_TRACKBAR 560
57#define ID_SPEED_UPDOWN 570
58
59
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000060//
61// -=- RfbPlayerClass
62
63//
64// Window class used as the basis for RfbPlayer instance
65//
66
67class RfbPlayerClass {
68public:
69 RfbPlayerClass();
70 ~RfbPlayerClass();
71 ATOM classAtom;
72 HINSTANCE instance;
73};
74
75LRESULT CALLBACK RfbPlayerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
76 LRESULT result;
77
78 if (msg == WM_CREATE)
79 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
80 else if (msg == WM_DESTROY) {
81 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000082
83 // Resume playback (It's need to quit from FbsInputStream::waitWhilePaused())
84 _this->setPaused(false);
85 SetWindowLong(hwnd, GWL_USERDATA, 0);
86 }
87 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
88 if (!_this) {
89 vlog.info("null _this in %x, message %u", hwnd, msg);
90 return DefWindowProc(hwnd, msg, wParam, lParam);
91 }
92
93 try {
94 result = _this->processMainMessage(hwnd, msg, wParam, lParam);
95 } catch (rdr::Exception& e) {
96 vlog.error("untrapped: %s", e.str());
97 }
98
99 return result;
100};
101
102RfbPlayerClass::RfbPlayerClass() : classAtom(0) {
103 WNDCLASS wndClass;
104 wndClass.style = 0;
105 wndClass.lpfnWndProc = RfbPlayerProc;
106 wndClass.cbClsExtra = 0;
107 wndClass.cbWndExtra = 0;
108 wndClass.hInstance = instance = GetModuleHandle(0);
109 wndClass.hIcon = (HICON)LoadImage(GetModuleHandle(0),
george827214b822004-12-12 07:02:51 +0000110 MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_SHARED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000111 if (!wndClass.hIcon)
112 printf("unable to load icon:%ld", GetLastError());
113 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
114 wndClass.hbrBackground = HBRUSH(COLOR_WINDOW);
george82c2c691f2004-12-08 18:04:14 +0000115 wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000116 wndClass.lpszClassName = _T("RfbPlayerClass");
117 classAtom = RegisterClass(&wndClass);
118 if (!classAtom) {
119 throw rdr::SystemException("unable to register RfbPlayer window class",
120 GetLastError());
121 }
122}
123
124RfbPlayerClass::~RfbPlayerClass() {
125 if (classAtom) {
126 UnregisterClass((const TCHAR*)classAtom, instance);
127 }
128}
129
130RfbPlayerClass baseClass;
131
132//
133// -=- RfbFrameClass
134
135//
136// Window class used to displaying the rfb data
137//
138
139class RfbFrameClass {
140public:
141 RfbFrameClass();
142 ~RfbFrameClass();
143 ATOM classAtom;
144 HINSTANCE instance;
145};
146
147LRESULT CALLBACK FrameProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
148 LRESULT result;
149
150 if (msg == WM_CREATE)
151 SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
152 else if (msg == WM_DESTROY)
153 SetWindowLong(hwnd, GWL_USERDATA, 0);
154 RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
155 if (!_this) {
156 vlog.info("null _this in %x, message %u", hwnd, msg);
157 return DefWindowProc(hwnd, msg, wParam, lParam);
158 }
159
160 try {
161 result = _this->processFrameMessage(hwnd, msg, wParam, lParam);
162 } catch (rdr::Exception& e) {
163 vlog.error("untrapped: %s", e.str());
164 }
165
166 return result;
167}
168
169RfbFrameClass::RfbFrameClass() : classAtom(0) {
170 WNDCLASS wndClass;
171 wndClass.style = 0;
172 wndClass.lpfnWndProc = FrameProc;
173 wndClass.cbClsExtra = 0;
174 wndClass.cbWndExtra = 0;
175 wndClass.hInstance = instance = GetModuleHandle(0);
176 wndClass.hIcon = 0;
177 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
178 wndClass.hbrBackground = 0;
179 wndClass.lpszMenuName = 0;
180 wndClass.lpszClassName = _T("RfbPlayerClass1");
181 classAtom = RegisterClass(&wndClass);
182 if (!classAtom) {
183 throw rdr::SystemException("unable to register RfbPlayer window class",
184 GetLastError());
185 }
186}
187
188RfbFrameClass::~RfbFrameClass() {
189 if (classAtom) {
190 UnregisterClass((const TCHAR*)classAtom, instance);
191 }
192}
193
194RfbFrameClass frameClass;
195
196//
197// -=- RfbPlayer instance implementation
198//
199
200RfbPlayer::RfbPlayer(char *_fileName, long _initTime = 0, double _playbackSpeed = 1.0,
201 bool _autoplay = false, bool _showControls = true,
202 bool _acceptBell = false)
203: RfbProto(_fileName), initTime(_initTime), playbackSpeed(_playbackSpeed),
204 autoplay(_autoplay), showControls(_showControls), buffer(0), client_size(0, 0, 32, 32),
george82b4915432005-01-30 17:10:57 +0000205 window_size(0, 0, 32, 32), cutText(0), seekMode(false), fileName(_fileName),
george82d4d69e62005-02-05 09:23:18 +0000206 serverInitTime(0), lastPos(0), timeStatic(0), speedEdit(0), posTrackBar(0),
george828a471482005-02-06 07:15:53 +0000207 speedUpDown(0), acceptBell(_acceptBell), rfbReader(0), sessionTimeMs(0),
208 sliderDraging(false), sliderStepMs(0) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000209
210 if (showControls)
george82d070c692005-01-19 16:44:04 +0000211 CTRL_BAR_HEIGHT = 28;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000212 else
213 CTRL_BAR_HEIGHT = 0;
214
george823c8fbbf2005-01-24 11:09:08 +0000215 // Reset the full session time
216 strcpy(fullSessionTime, "00m:00s");
217
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000218 // Create the main window
219 const TCHAR* name = _T("RfbPlayer");
220 mainHwnd = CreateWindow((const TCHAR*)baseClass.classAtom, name, WS_OVERLAPPEDWINDOW,
george8210313102005-01-17 13:11:40 +0000221 0, 0, 640, 480, 0, 0, baseClass.instance, this);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000222 if (!mainHwnd) {
223 throw rdr::SystemException("unable to create WMNotifier window instance", GetLastError());
224 }
225 vlog.debug("created window \"%s\" (%x)", (const char*)CStr(name), getMainHandle());
226
227 // Create the backing buffer
228 buffer = new win32::DIBSectionBuffer(getFrameHandle());
george8210313102005-01-17 13:11:40 +0000229 setVisible(true);
george8217e92cb2005-01-31 16:01:02 +0000230
231 // Open the session file
232 if (fileName) {
233 openSessionFile(fileName);
234 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000235}
236
237RfbPlayer::~RfbPlayer() {
238 vlog.debug("~RfbPlayer");
george82ce8dc3a2005-01-31 13:06:54 +0000239 if (rfbReader) {
george82ce8dc3a2005-01-31 13:06:54 +0000240 delete rfbReader->join();
241 rfbReader = 0;
242 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000243 if (mainHwnd) {
244 setVisible(false);
245 DestroyWindow(mainHwnd);
246 mainHwnd = 0;
247 }
248 delete buffer;
249 delete cutText;
250 vlog.debug("~RfbPlayer done");
251}
252
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000253LRESULT
254RfbPlayer::processMainMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
255 switch (msg) {
256
257 // -=- Process standard window messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000258
259 case WM_CREATE:
260 {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000261 // Create the frame window
262 frameHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, (const TCHAR*)frameClass.classAtom,
263 0, WS_CHILD | WS_VISIBLE, 0, CTRL_BAR_HEIGHT, 10, CTRL_BAR_HEIGHT + 10,
264 hwnd, 0, frameClass.instance, this);
265
george82d070c692005-01-19 16:44:04 +0000266 createToolBar(hwnd);
267
george82006f2792005-02-05 07:40:47 +0000268 hMenu = GetMenu(hwnd);
george825c13c662005-01-27 14:48:23 +0000269
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000270 return 0;
271 }
272
george827214b822004-12-12 07:02:51 +0000273 // Process the main menu and toolbar's messages
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000274
275 case WM_COMMAND:
george825c13c662005-01-27 14:48:23 +0000276 switch (LOWORD(wParam)) {
george826e51fcc2005-02-06 13:30:49 +0000277 case ID_OPENFILE:
278 {
279 char curDir[_MAX_DIR];
280 static char filename[_MAX_PATH];
281 OPENFILENAME ofn;
282 memset((void *) &ofn, 0, sizeof(OPENFILENAME));
283 GetCurrentDirectory(sizeof(curDir), curDir);
284
285 ofn.lStructSize = sizeof(OPENFILENAME);
286 ofn.hwndOwner = getMainHandle();
287 ofn.lpstrFile = filename;
288 ofn.nMaxFile = sizeof(filename);
289 ofn.lpstrInitialDir = curDir;
290 ofn.lpstrFilter = "Rfb Session files (*.rfb)\0*.rfb\0" \
291 "All files (*.*)\0*.*\0";
292 ofn.lpstrDefExt = "rfb";
293 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
294 if (GetOpenFileName(&ofn))
295 openSessionFile(filename);
296 }
297 break;
george825c13c662005-01-27 14:48:23 +0000298 case ID_PLAY:
299 setPaused(false);
george825c13c662005-01-27 14:48:23 +0000300 break;
301 case ID_PAUSE:
302 setPaused(true);
george825c13c662005-01-27 14:48:23 +0000303 break;
304 case ID_STOP:
305 if (getTimeOffset() != 0) {
george82006f2792005-02-05 07:40:47 +0000306 stopPlayback();
george825c13c662005-01-27 14:48:23 +0000307 }
george825c13c662005-01-27 14:48:23 +0000308 break;
309 case ID_PLAYPAUSE:
310 if (isPaused()) {
311 setPaused(false);
george825c13c662005-01-27 14:48:23 +0000312 } else {
313 setPaused(true);
george825c13c662005-01-27 14:48:23 +0000314 }
george825c13c662005-01-27 14:48:23 +0000315 break;
316 case ID_FULLSCREEN:
317 MessageBox(getMainHandle(), "It is not working yet!", "RfbPlayer", MB_OK);
318 break;
george824ea27f62005-01-29 15:03:06 +0000319 case ID_RETURN:
320 // Update the speed if return pressed in speedEdit
321 if (speedEdit == GetFocus()) {
322 char speedStr[20], *stopStr;
323 GetWindowText(speedEdit, speedStr, sizeof(speedStr));
324 double speed = strtod(speedStr, &stopStr);
325 if (speed > 0) {
326 speed = min(MAX_SPEED, speed);
327 // Update speedUpDown position
328 SendMessage(speedUpDown, UDM_SETPOS,
329 0, MAKELONG((short)(speed / 0.5), 0));
330 } else {
331 speed = getSpeed();
332 }
333 setSpeed(speed);
334 sprintf(speedStr, "%.2f", speed);
335 SetWindowText(speedEdit, speedStr);
336 }
337 break;
george8201aa6732005-02-06 17:13:03 +0000338 case ID_EXIT:
339 is->resumePlayback();
340 PostQuitMessage(0);
341 break;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000342 }
343 break;
344
345 // Update frame's window size and add scrollbars if required
346
347 case WM_SIZE:
348 {
george82d070c692005-01-19 16:44:04 +0000349
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000350 Point old_offset = bufferToClient(Point(0, 0));
351
352 // Update the cached sizing information
353 RECT r;
354 GetClientRect(getMainHandle(), &r);
355 MoveWindow(getFrameHandle(), 0, CTRL_BAR_HEIGHT, r.right - r.left,
356 r.bottom - r.top - CTRL_BAR_HEIGHT, TRUE);
357
358 GetWindowRect(getFrameHandle(), &r);
359 window_size = Rect(r.left, r.top, r.right, r.bottom);
360 GetClientRect(getFrameHandle(), &r);
361 client_size = Rect(r.left, r.top, r.right, r.bottom);
362
363 // Determine whether scrollbars are required
364 calculateScrollBars();
george82d070c692005-01-19 16:44:04 +0000365
366 // Resize the ToolBar
367 tb.autoSize();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000368
369 // Redraw if required
370 if (!old_offset.equals(bufferToClient(Point(0, 0))))
371 InvalidateRect(getFrameHandle(), 0, TRUE);
372 }
373 break;
george828a471482005-02-06 07:15:53 +0000374
375 // Process messages from posTrackBar
376
377 case WM_HSCROLL:
378 {
379 long Pos = SendMessage(posTrackBar, TBM_GETPOS, 0, 0);
380 Pos *= sliderStepMs;
381
382 switch (LOWORD(wParam)) {
383 case TB_PAGEUP:
384 case TB_PAGEDOWN:
385 case TB_LINEUP:
386 case TB_LINEDOWN:
387 case TB_THUMBTRACK:
388 sliderDraging = true;
389 updatePos(Pos);
390 return 0;
391 case TB_ENDTRACK:
392 setPos(Pos);
george828a471482005-02-06 07:15:53 +0000393 sliderDraging = false;
394 return 0;
395 default:
396 break;
397 }
398 }
399 break;
george829e6e6cc2005-01-29 13:12:05 +0000400
401 case WM_NOTIFY:
402 switch (((NMHDR*)lParam)->code) {
403 case UDN_DELTAPOS:
404 if ((int)wParam == ID_SPEED_UPDOWN) {
george824ea27f62005-01-29 15:03:06 +0000405 BOOL lResult = FALSE;
george829e6e6cc2005-01-29 13:12:05 +0000406 char speedStr[20] = "\0";
407 DWORD speedRange = SendMessage(speedUpDown, UDM_GETRANGE, 0, 0);
408 LPNM_UPDOWN upDown = (LPNM_UPDOWN)lParam;
409 double speed;
410
george824ea27f62005-01-29 15:03:06 +0000411 // The out of range checking
george829e6e6cc2005-01-29 13:12:05 +0000412 if (upDown->iDelta > 0) {
413 speed = min(upDown->iPos + upDown->iDelta, LOWORD(speedRange)) * 0.5;
414 } else {
george824ea27f62005-01-29 15:03:06 +0000415 // It's need to round the UpDown position
416 if ((upDown->iPos * 0.5) != getSpeed()) {
417 upDown->iDelta = 0;
418 lResult = TRUE;
419 }
george829e6e6cc2005-01-29 13:12:05 +0000420 speed = max(upDown->iPos + upDown->iDelta, HIWORD(speedRange)) * 0.5;
421 }
422 _gcvt(speed, 5, speedStr);
423 sprintf(speedStr, "%.2f", speed);
424 SetWindowText(speedEdit, speedStr);
425 setSpeed(speed);
george824ea27f62005-01-29 15:03:06 +0000426 return lResult;
george829e6e6cc2005-01-29 13:12:05 +0000427 }
george824ea27f62005-01-29 15:03:06 +0000428 }
george829e6e6cc2005-01-29 13:12:05 +0000429 return 0;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000430
431 case WM_CLOSE:
432 vlog.debug("WM_CLOSE %x", getMainHandle());
433 PostQuitMessage(0);
434 break;
435 }
436
437 return rfb::win32::SafeDefWindowProc(getMainHandle(), msg, wParam, lParam);
438}
439
440LRESULT RfbPlayer::processFrameMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
441 switch (msg) {
442
443 case WM_PAINT:
444 {
445 if (is->isSeeking()) {
446 seekMode = true;
447 return 0;
448 } else {
449 if (seekMode) {
450 seekMode = false;
451 InvalidateRect(getFrameHandle(), 0, true);
452 UpdateWindow(getFrameHandle());
453 return 0;
454 }
455 }
456
457 PAINTSTRUCT ps;
458 HDC paintDC = BeginPaint(getFrameHandle(), &ps);
459 if (!paintDC)
460 throw SystemException("unable to BeginPaint", GetLastError());
461 Rect pr = Rect(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
462
463 if (!pr.is_empty()) {
464
465 if (buffer->bitmap) {
466
467 // Get device context
468 BitmapDC bitmapDC(paintDC, buffer->bitmap);
469
470 // Blit the border if required
471 Rect bufpos = bufferToClient(buffer->getRect());
472 if (!pr.enclosed_by(bufpos)) {
473 vlog.debug("draw border");
474 HBRUSH black = (HBRUSH) GetStockObject(BLACK_BRUSH);
475 RECT r;
476 SetRect(&r, 0, 0, bufpos.tl.x, client_size.height()); FillRect(paintDC, &r, black);
477 SetRect(&r, bufpos.tl.x, 0, bufpos.br.x, bufpos.tl.y); FillRect(paintDC, &r, black);
478 SetRect(&r, bufpos.br.x, 0, client_size.width(), client_size.height()); FillRect(paintDC, &r, black);
479 SetRect(&r, bufpos.tl.x, bufpos.br.y, bufpos.br.x, client_size.height()); FillRect(paintDC, &r, black);
480 }
481
482 // Do the blit
483 Point buf_pos = clientToBuffer(pr.tl);
484 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
485 bitmapDC, buf_pos.x, buf_pos.y, SRCCOPY))
486 throw SystemException("unable to BitBlt to window", GetLastError());
487
488 } else {
489 // Blit a load of black
490 if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(),
491 0, 0, 0, BLACKNESS))
492 throw SystemException("unable to BitBlt to blank window", GetLastError());
493 }
494 }
495 EndPaint(getFrameHandle(), &ps);
496 }
497 return 0;
498
499 case WM_VSCROLL:
500 case WM_HSCROLL:
501 {
502 Point delta;
503 int newpos = (msg == WM_VSCROLL) ? scrolloffset.y : scrolloffset.x;
504
505 switch (LOWORD(wParam)) {
506 case SB_PAGEUP: newpos -= 50; break;
507 case SB_PAGEDOWN: newpos += 50; break;
508 case SB_LINEUP: newpos -= 5; break;
509 case SB_LINEDOWN: newpos += 5; break;
510 case SB_THUMBTRACK:
511 case SB_THUMBPOSITION: newpos = HIWORD(wParam); break;
512 default: vlog.info("received unknown scroll message");
513 };
514
515 if (msg == WM_HSCROLL)
516 setViewportOffset(Point(newpos, scrolloffset.y));
517 else
518 setViewportOffset(Point(scrolloffset.x, newpos));
519
520 SCROLLINFO si;
521 si.cbSize = sizeof(si);
522 si.fMask = SIF_POS;
523 si.nPos = newpos;
524 SetScrollInfo(getFrameHandle(), (msg == WM_VSCROLL) ? SB_VERT : SB_HORZ, &si, TRUE);
525 }
526 break;
527 }
528
529 return DefWindowProc(hwnd, msg, wParam, lParam);
530}
531
532void RfbPlayer::setOptions(long _initTime = 0, double _playbackSpeed = 1.0,
533 bool _autoplay = false, bool _showControls = true) {
534 showControls = _showControls;
535 autoplay = _autoplay;
536 playbackSpeed = _playbackSpeed;
537 initTime = _initTime;
538}
539
540void RfbPlayer::applyOptions() {
541 if (initTime >= 0)
542 setPos(initTime);
543 setSpeed(playbackSpeed);
544 setPaused(!autoplay);
george82d070c692005-01-19 16:44:04 +0000545}
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000546
george82d070c692005-01-19 16:44:04 +0000547void RfbPlayer::createToolBar(HWND parentHwnd) {
548 RECT tRect;
549 InitCommonControls();
550
551 tb.create(ID_TOOLBAR, parentHwnd);
552 tb.addBitmap(4, IDB_TOOLBAR);
553
554 // Create the control buttons
555 tb.addButton(0, ID_PLAY);
556 tb.addButton(1, ID_PAUSE);
557 tb.addButton(2, ID_STOP);
558 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
559 tb.addButton(3, ID_FULLSCREEN);
560 tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
561
562 // Create the static control for the time output
563 tb.addButton(125, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
564 tb.getButtonRect(6, &tRect);
565 timeStatic = CreateWindowEx(0, "Static", "00m:00s (00m:00s)",
566 WS_CHILD | WS_VISIBLE, tRect.left, tRect.top+2, tRect.right-tRect.left,
567 tRect.bottom-tRect.top, tb.getHandle(), (HMENU)ID_TIME_STATIC,
568 GetModuleHandle(0), 0);
569 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
570
571 // Create the trackbar control for the time position
572 tb.addButton(200, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
573 tb.getButtonRect(8, &tRect);
george82d4d69e62005-02-05 09:23:18 +0000574 posTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, "Trackbar Control",
george82d070c692005-01-19 16:44:04 +0000575 WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS | TBS_ENABLESELRANGE,
576 tRect.left, tRect.top, tRect.right-tRect.left, tRect.bottom-tRect.top,
577 parentHwnd, (HMENU)ID_POS_TRACKBAR, GetModuleHandle(0), 0);
578 // It's need to send notify messages to toolbar parent window
george82d4d69e62005-02-05 09:23:18 +0000579 SetParent(posTrackBar, tb.getHandle());
george82d070c692005-01-19 16:44:04 +0000580 tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP);
581
582 // Create the label with "Speed:" caption
583 tb.addButton(50, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
584 tb.getButtonRect(10, &tRect);
585 CreateWindowEx(0, "Static", "Speed:", WS_CHILD | WS_VISIBLE,
586 tRect.left, tRect.top+2, tRect.right-tRect.left, tRect.bottom-tRect.top,
587 tb.getHandle(), (HMENU)ID_SPEED_STATIC, GetModuleHandle(0), 0);
588
589 // Create the edit control and the spin for the speed managing
590 tb.addButton(60, 0, TBSTATE_ENABLED, TBSTYLE_SEP);
591 tb.getButtonRect(11, &tRect);
592 speedEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "1.00",
593 WS_CHILD | WS_VISIBLE | ES_RIGHT, tRect.left, tRect.top,
594 tRect.right-tRect.left, tRect.bottom-tRect.top, parentHwnd,
595 (HMENU)ID_SPEED_EDIT, GetModuleHandle(0), 0);
596 // It's need to send notify messages to toolbar parent window
597 SetParent(speedEdit, tb.getHandle());
598
599 speedUpDown = CreateUpDownControl(WS_CHILD | WS_VISIBLE
600 | WS_BORDER | UDS_ALIGNRIGHT, 0, 0, 0, 0, tb.getHandle(),
george829e6e6cc2005-01-29 13:12:05 +0000601 ID_SPEED_UPDOWN, GetModuleHandle(0), speedEdit, 20, 1, 2);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000602}
603
604void RfbPlayer::setVisible(bool visible) {
605 ShowWindow(getMainHandle(), visible ? SW_SHOW : SW_HIDE);
606 if (visible) {
607 // When the window becomes visible, make it active
608 SetForegroundWindow(getMainHandle());
609 SetActiveWindow(getMainHandle());
610 }
611}
612
613void RfbPlayer::setTitle(const char *title) {
614 char _title[256];
615 strcpy(_title, AppName);
616 strcat(_title, " - ");
617 strcat(_title, title);
618 SetWindowText(getMainHandle(), _title);
619}
620
621void RfbPlayer::setFrameSize(int width, int height) {
622 // Calculate and set required size for main window
623 RECT r = {0, 0, width, height};
624 AdjustWindowRectEx(&r, GetWindowLong(getFrameHandle(), GWL_STYLE), FALSE,
625 GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
626 r.bottom += CTRL_BAR_HEIGHT; // Include RfbPlayr's controls area
627 AdjustWindowRect(&r, GetWindowLong(getMainHandle(), GWL_STYLE), FALSE);
628 SetWindowPos(getMainHandle(), 0, 0, 0, r.right-r.left, r.bottom-r.top,
629 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
630
631 // Enable/disable scrollbars as appropriate
632 calculateScrollBars();
633}
634
635void RfbPlayer::calculateScrollBars() {
636 // Calculate the required size of window
637 DWORD current_style = GetWindowLong(getFrameHandle(), GWL_STYLE);
638 DWORD style = current_style & ~(WS_VSCROLL | WS_HSCROLL);
639 DWORD old_style;
640 RECT r;
641 SetRect(&r, 0, 0, buffer->width(), buffer->height());
642 AdjustWindowRectEx(&r, style, FALSE, GetWindowLong(getFrameHandle(), GWL_EXSTYLE));
643 Rect reqd_size = Rect(r.left, r.top, r.right, r.bottom);
644
645 // Work out whether scroll bars are required
646 do {
647 old_style = style;
648
649 if (!(style & WS_HSCROLL) && (reqd_size.width() > window_size.width())) {
650 style |= WS_HSCROLL;
651 reqd_size.br.y += GetSystemMetrics(SM_CXHSCROLL);
652 }
653 if (!(style & WS_VSCROLL) && (reqd_size.height() > window_size.height())) {
654 style |= WS_VSCROLL;
655 reqd_size.br.x += GetSystemMetrics(SM_CXVSCROLL);
656 }
657 } while (style != old_style);
658
659 // Tell Windows to update the window style & cached settings
660 if (style != current_style) {
661 SetWindowLong(getFrameHandle(), GWL_STYLE, style);
662 SetWindowPos(getFrameHandle(), NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
663 }
664
665 // Update the scroll settings
666 SCROLLINFO si;
667 if (style & WS_VSCROLL) {
668 si.cbSize = sizeof(si);
669 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
670 si.nMin = 0;
671 si.nMax = buffer->height();
672 si.nPage = buffer->height() - (reqd_size.height() - window_size.height());
673 maxscrolloffset.y = max(0, si.nMax-si.nPage);
674 scrolloffset.y = min(maxscrolloffset.y, scrolloffset.y);
675 si.nPos = scrolloffset.y;
676 SetScrollInfo(getFrameHandle(), SB_VERT, &si, TRUE);
677 }
678 if (style & WS_HSCROLL) {
679 si.cbSize = sizeof(si);
680 si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
681 si.nMin = 0;
682 si.nMax = buffer->width();
683 si.nPage = buffer->width() - (reqd_size.width() - window_size.width());
684 maxscrolloffset.x = max(0, si.nMax-si.nPage);
685 scrolloffset.x = min(maxscrolloffset.x, scrolloffset.x);
686 si.nPos = scrolloffset.x;
687 SetScrollInfo(getFrameHandle(), SB_HORZ, &si, TRUE);
688 }
689}
690
691bool RfbPlayer::setViewportOffset(const Point& tl) {
692/* ***
693 Point np = Point(max(0, min(maxscrolloffset.x, tl.x)),
694 max(0, min(maxscrolloffset.y, tl.y)));
695 */
696 Point np = Point(max(0, min(tl.x, buffer->width()-client_size.width())),
697 max(0, min(tl.y, buffer->height()-client_size.height())));
698 Point delta = np.translate(scrolloffset.negate());
699 if (!np.equals(scrolloffset)) {
700 scrolloffset = np;
701 ScrollWindowEx(getFrameHandle(), -delta.x, -delta.y, 0, 0, 0, 0, SW_INVALIDATE);
702 UpdateWindow(getFrameHandle());
703 return true;
704 }
705 return false;
706}
707
708void RfbPlayer::close(const char* reason) {
709 setVisible(false);
710 if (reason) {
711 vlog.info("closing - %s", reason);
712 MessageBox(NULL, TStr(reason), "RfbPlayer", MB_ICONINFORMATION | MB_OK);
713 }
714 SendMessage(getFrameHandle(), WM_CLOSE, 0, 0);
715}
716
717void RfbPlayer::blankBuffer() {
718 fillRect(buffer->getRect(), 0);
719}
720
721void RfbPlayer::rewind() {
george8223e08562005-01-31 15:16:42 +0000722 bool paused = isPaused();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000723 blankBuffer();
724 newSession(fileName);
725 skipHandshaking();
george8223e08562005-01-31 15:16:42 +0000726 setSpeed(playbackSpeed);
george828a471482005-02-06 07:15:53 +0000727 if (paused) is->pausePlayback();
728 else is->resumePlayback();
george8223e08562005-01-31 15:16:42 +0000729}
730
731void RfbPlayer::processMsg() {
732 static long update_time = GetTickCount();
733 try {
george828a471482005-02-06 07:15:53 +0000734 if ((!isSeeking()) && ((GetTickCount() - update_time) > 250)
735 && (!sliderDraging)) {
george8223e08562005-01-31 15:16:42 +0000736 // Update pos in the toolbar 4 times in 1 second
george828a471482005-02-06 07:15:53 +0000737 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000738 update_time = GetTickCount();
739 }
740 RfbProto::processMsg();
741 } catch (rdr::Exception e) {
742 if (strcmp(e.str(), "[End Of File]") == 0) {
743 rewind();
744 setPaused(true);
george828a471482005-02-06 07:15:53 +0000745 updatePos(getTimeOffset());
george829403bee2005-02-06 11:14:39 +0000746 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george8223e08562005-01-31 15:16:42 +0000747 return;
748 }
749 // It's a special exception to perform backward seeking.
750 // We only rewind the stream and seek the offset
751 if (strcmp(e.str(), "[REWIND]") == 0) {
752 long initTime = getSeekOffset();
753 rewind();
754 setPos(initTime);
george828a471482005-02-06 07:15:53 +0000755 updatePos(getTimeOffset());
george8223e08562005-01-31 15:16:42 +0000756 } else {
757 MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
758 return;
759 }
760 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000761}
762
763void RfbPlayer::serverInit() {
764 RfbProto::serverInit();
765
766 // Save the server init time for using in setPos()
767 serverInitTime = getTimeOffset() / getSpeed();
768
769 // Resize the backing buffer
770 buffer->setSize(cp.width, cp.height);
771
772 // Check on the true colour mode
773 if (!(cp.pf()).trueColour)
Peter Ã…strandc81a6522004-12-30 11:32:08 +0000774 throw rdr::Exception("This version plays only true color session!");
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000775
776 // Set the session pixel format
777 buffer->setPF(cp.pf());
778
779 // If the window is not maximised then resize it
780 if (!(GetWindowLong(getMainHandle(), GWL_STYLE) & WS_MAXIMIZE))
781 setFrameSize(cp.width, cp.height);
782
783 // Set the window title and show it
784 setTitle(cp.name());
george82006f2792005-02-05 07:40:47 +0000785
george82d4d69e62005-02-05 09:23:18 +0000786 // Calculate the full session time and update posTrackBar control
george828a471482005-02-06 07:15:53 +0000787 sessionTimeMs = calculateSessionTime(fileName);
788 sprintf(fullSessionTime, "%.2um:%.2us",
789 sessionTimeMs / 1000 / 60, sessionTimeMs / 1000 % 60);
george82d4d69e62005-02-05 09:23:18 +0000790 SendMessage(posTrackBar, TBM_SETRANGE,
george828a471482005-02-06 07:15:53 +0000791 TRUE, MAKELONG(0, min(sessionTimeMs / 1000, MAX_POS_TRACKBAR_RANGE)));
792 sliderStepMs = sessionTimeMs / SendMessage(posTrackBar, TBM_GETRANGEMAX, 0, 0);
george828a471482005-02-06 07:15:53 +0000793 updatePos(getTimeOffset());
george82d4d69e62005-02-05 09:23:18 +0000794
george82006f2792005-02-05 07:40:47 +0000795 setPaused(!autoplay);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000796}
797
798void RfbPlayer::setColourMapEntries(int first, int count, U16* rgbs) {
799 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
800 throw rdr::Exception("Can't handle SetColourMapEntries message", "RfbPlayer");
801/* int i;
802 for (i=0;i<count;i++) {
803 buffer->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
804 }
805 // *** change to 0, 256?
806 refreshWindowPalette(first, count);
807 palette_changed = true;
808 InvalidateRect(getFrameHandle(), 0, FALSE);*/
809}
810
811void RfbPlayer::bell() {
812 if (acceptBell)
813 MessageBeep(-1);
814}
815
816void RfbPlayer::serverCutText(const char* str, int len) {
817 if (cutText != NULL)
818 delete [] cutText;
819 cutText = new char[len + 1];
820 memcpy(cutText, str, len);
821 cutText[len] = '\0';
822}
823
824void RfbPlayer::frameBufferUpdateEnd() {
825};
826
827void RfbPlayer::beginRect(const Rect& r, unsigned int encoding) {
828}
829
830void RfbPlayer::endRect(const Rect& r, unsigned int encoding) {
831}
832
833
834void RfbPlayer::fillRect(const Rect& r, Pixel pix) {
835 buffer->fillRect(r, pix);
836 invalidateBufferRect(r);
837}
838
839void RfbPlayer::imageRect(const Rect& r, void* pixels) {
840 buffer->imageRect(r, pixels);
841 invalidateBufferRect(r);
842}
843
844void RfbPlayer::copyRect(const Rect& r, int srcX, int srcY) {
845 buffer->copyRect(r, Point(r.tl.x-srcX, r.tl.y-srcY));
846 invalidateBufferRect(r);
847}
848
849bool RfbPlayer::invalidateBufferRect(const Rect& crect) {
850 Rect rect = bufferToClient(crect);
851 if (rect.intersect(client_size).is_empty()) return false;
852 RECT invalid = {rect.tl.x, rect.tl.y, rect.br.x, rect.br.y};
853 InvalidateRect(getFrameHandle(), &invalid, FALSE);
854 return true;
855}
856
george8257f13522005-02-05 08:48:22 +0000857long RfbPlayer::calculateSessionTime(char *filename) {
858 FbsInputStream sessionFile(filename);
george828a471482005-02-06 07:15:53 +0000859 sessionFile.setTimeOffset(100000000);
george8257f13522005-02-05 08:48:22 +0000860 try {
861 while (TRUE) {
862 sessionFile.skip(1024);
863 }
864 } catch (rdr::Exception e) {
865 if (strcmp(e.str(), "[End Of File]") == 0) {
george828a471482005-02-06 07:15:53 +0000866 return sessionFile.getTimeOffset();
george8257f13522005-02-05 08:48:22 +0000867 } else {
868 MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
869 return 0;
870 }
871 }
872 return 0;
873}
874
george8217e92cb2005-01-31 16:01:02 +0000875void RfbPlayer::openSessionFile(char *_fileName) {
876 fileName = strDup(_fileName);
877
878 // Close the previous reading thread
879 if (rfbReader) {
george826e51fcc2005-02-06 13:30:49 +0000880 is->resumePlayback();
george8217e92cb2005-01-31 16:01:02 +0000881 delete rfbReader->join();
882 }
883 blankBuffer();
884 newSession(fileName);
885 setSpeed(playbackSpeed);
886 rfbReader = new rfbSessionReader(this);
887 rfbReader->start();
george826e51fcc2005-02-06 13:30:49 +0000888 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george8217e92cb2005-01-31 16:01:02 +0000889}
890
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000891void RfbPlayer::setPaused(bool paused) {
892 if (paused) {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000893 is->pausePlayback();
george82006f2792005-02-05 07:40:47 +0000894 tb.checkButton(ID_PAUSE, true);
895 tb.checkButton(ID_PLAY, false);
896 tb.checkButton(ID_STOP, false);
897 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
898 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000899 } else {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000900 is->resumePlayback();
george82006f2792005-02-05 07:40:47 +0000901 tb.checkButton(ID_PLAY, true);
902 tb.checkButton(ID_STOP, false);
903 tb.checkButton(ID_PAUSE, false);
904 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED);
905 CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000906 }
907}
908
george82006f2792005-02-05 07:40:47 +0000909void RfbPlayer::stopPlayback() {
910 setPos(0);
911 is->pausePlayback();
912 tb.checkButton(ID_STOP, true);
913 tb.checkButton(ID_PLAY, false);
914 tb.checkButton(ID_PAUSE, false);
915 CheckMenuItem(hMenu, ID_STOP, MF_CHECKED);
916 CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_UNCHECKED);
george826da02d72005-02-06 17:02:34 +0000917 SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0);
george82006f2792005-02-05 07:40:47 +0000918}
919
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000920void RfbPlayer::setSpeed(double speed) {
921 serverInitTime = serverInitTime * getSpeed() / speed;
922 is->setSpeed(speed);
george8223e08562005-01-31 15:16:42 +0000923 playbackSpeed = speed;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000924}
925
926double RfbPlayer::getSpeed() {
927 return is->getSpeed();
928}
929
930void RfbPlayer::setPos(long pos) {
931 is->setTimeOffset(max(pos, serverInitTime));
932}
933
934long RfbPlayer::getSeekOffset() {
935 return is->getSeekOffset();
936}
937
938bool RfbPlayer::isSeeking() {
939 return is->isSeeking();
940}
941
942bool RfbPlayer::isSeekMode() {
943 return seekMode;
944}
945
946bool RfbPlayer::isPaused() {
947 return is->isPaused();
948}
949
950long RfbPlayer::getTimeOffset() {
george828a471482005-02-06 07:15:53 +0000951 return max(is->getTimeOffset(), is->getSeekOffset());
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000952}
953
george828a471482005-02-06 07:15:53 +0000954void RfbPlayer::updatePos(long newPos) {
955 // Update time pos in static control
george823c8fbbf2005-01-24 11:09:08 +0000956 char timePos[30] = "\0";
george829403bee2005-02-06 11:14:39 +0000957 long sliderPos = newPos;
george828a471482005-02-06 07:15:53 +0000958 newPos /= 1000;
george8244325492005-02-06 07:29:51 +0000959 sprintf(timePos, "%.2um:%.2us (%s)", newPos/60, newPos%60, fullSessionTime);
george823c8fbbf2005-01-24 11:09:08 +0000960 SetWindowText(timeStatic, timePos);
george828a471482005-02-06 07:15:53 +0000961
962 // Update the position of slider
963 if (!sliderDraging) {
964 sliderPos /= sliderStepMs;
george829403bee2005-02-06 11:14:39 +0000965 if (sliderPos > SendMessage(posTrackBar, TBM_GETPOS, 0, 0))
966 SendMessage(posTrackBar, TBM_SETPOS, TRUE, sliderPos);
george828a471482005-02-06 07:15:53 +0000967 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000968}
969
970void RfbPlayer::skipHandshaking() {
971 int skipBytes = 12 + 4 + 24 + strlen(cp.name());
972 is->skip(skipBytes);
973 state_ = RFBSTATE_NORMAL;
974}
975
976void programInfo() {
977 win32::FileVersionInfo inf;
978 _tprintf(_T("%s - %s, Version %s\n"),
979 inf.getVerString(_T("ProductName")),
980 inf.getVerString(_T("FileDescription")),
981 inf.getVerString(_T("FileVersion")));
982 printf("%s\n", buildTime);
983 _tprintf(_T("%s\n\n"), inf.getVerString(_T("LegalCopyright")));
984}
985
986void programUsage() {
987 printf("usage: rfbplayer <options> <filename>\n");
988 printf("Command-line options:\n");
989 printf(" -help - Provide usage information.\n");
990 printf(" -speed <value> - Sets playback speed, where 1 is normal speed,\n");
991 printf(" 2 is double speed, 0.5 is half speed. Default: 1.0.\n");
992 printf(" -pos <ms> - Sets initial time position in the session file,\n");
993 printf(" in milliseconds. Default: 0.\n");
994 printf(" -autoplay <yes|no> - Runs the player in the playback mode. Default: \"no\".\n");
995 printf(" -controls <yes|no> - Shows the control panel at the top. Default: \"yes\".\n");
996 printf(" -bell <yes|no> - Accepts the bell. Default: \"no\".\n");
997}
998
999double playbackSpeed = 1.0;
1000long initTime = -1;
1001bool autoplay = false;
1002bool showControls = true;
1003char *fileName;
1004bool console = false;
1005bool wrong_param = false;
1006bool print_usage = false;
1007bool acceptBell = false;
1008
1009bool processParams(int argc, char* argv[]) {
1010 for (int i = 1; i < argc; i++) {
1011 if ((strcasecmp(argv[i], "-help") == 0) ||
1012 (strcasecmp(argv[i], "--help") == 0) ||
1013 (strcasecmp(argv[i], "/help") == 0) ||
1014 (strcasecmp(argv[i], "-h") == 0) ||
1015 (strcasecmp(argv[i], "/h") == 0) ||
1016 (strcasecmp(argv[i], "/?") == 0)) {
1017 print_usage = true;
1018 return true;
1019 }
1020
1021 if ((strcasecmp(argv[i], "-speed") == 0) ||
1022 (strcasecmp(argv[i], "/speed") == 0) && (i < argc-1)) {
1023 playbackSpeed = atof(argv[++i]);
1024 if (playbackSpeed <= 0) {
1025 return false;
1026 }
1027 continue;
1028 }
1029
1030 if ((strcasecmp(argv[i], "-pos") == 0) ||
1031 (strcasecmp(argv[i], "/pos") == 0) && (i < argc-1)) {
1032 initTime = atol(argv[++i]);
1033 if (initTime <= 0)
1034 return false;
1035 continue;
1036 }
1037
1038 if ((strcasecmp(argv[i], "-autoplay") == 0) ||
1039 (strcasecmp(argv[i], "/autoplay") == 0) && (i < argc-1)) {
1040 i++;
1041 if (strcasecmp(argv[i], "yes") == 0) {
1042 autoplay = true;
1043 continue;
1044 }
1045 if (strcasecmp(argv[i], "no") == 0) {
1046 autoplay = false;
1047 continue;
1048 }
1049 return false;
1050 }
1051
1052 if ((strcasecmp(argv[i], "-controls") == 0) ||
1053 (strcasecmp(argv[i], "/controls") == 0) && (i < argc-1)) {
1054 i++;
1055 if (strcasecmp(argv[i], "yes") == 0) {
1056 showControls = true;
1057 continue;
1058 }
1059 if (strcasecmp(argv[i], "no") == 0) {
1060 showControls = false;
1061 continue;
1062 }
1063 return false;
1064 }
1065
1066 if ((strcasecmp(argv[i], "-bell") == 0) ||
1067 (strcasecmp(argv[i], "/bell") == 0) && (i < argc-1)) {
1068 i++;
1069 if (strcasecmp(argv[i], "yes") == 0) {
1070 acceptBell = true;
1071 continue;
1072 }
1073 if (strcasecmp(argv[i], "no") == 0) {
1074 acceptBell = false;
1075 continue;
1076 }
1077 return false;
1078 }
1079
1080 if (i != argc - 1)
1081 return false;
1082 }
1083
1084 fileName = strDup(argv[argc-1]);
1085 return true;
1086}
1087
1088//
1089// -=- WinMain
1090//
1091
1092int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, char* cmdLine, int cmdShow) {
1093
1094 // - Process the command-line
1095
1096 int argc = __argc;
1097 char** argv = __argv;
1098 if (argc > 1) {
1099 wrong_param = !processParams(argc, argv);
1100 console = print_usage | wrong_param;
1101 } else {
1102 console = true;
1103 }
1104
1105 if (console) {
1106 AllocConsole();
1107 freopen("CONOUT$","wb",stdout);
1108
1109 programInfo();
1110 if (wrong_param)
1111 printf("Wrong a command line.\n");
1112 else
1113 programUsage();
1114
1115 printf("\nPress Enter/Return key to continue\n");
1116 char c = getch();
1117 FreeConsole();
1118
1119 return 0;
george8267cbcd02005-01-16 15:39:56 +00001120 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001121
1122 // Create the player and the thread which reading the rfb data
1123 RfbPlayer *player = NULL;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001124 try {
1125 player = new RfbPlayer(fileName, initTime, playbackSpeed, autoplay,
1126 showControls, acceptBell);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001127 } catch (rdr::Exception e) {
1128 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1129 delete player;
1130 return 0;
1131 }
1132
1133 // Run the player
george825bbd61b2004-12-09 17:47:37 +00001134 HACCEL hAccel = LoadAccelerators(inst, MAKEINTRESOURCE(IDR_ACCELERATOR));
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001135 MSG msg;
1136 while (GetMessage(&msg, NULL, 0, 0) > 0) {
george825bbd61b2004-12-09 17:47:37 +00001137 if(!TranslateAccelerator(player->getMainHandle(), hAccel, &msg)) {
1138 TranslateMessage(&msg);
1139 DispatchMessage(&msg);
1140 }
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001141 }
1142
1143 // Wait while the thread destroying and then destroy the player
1144 try{
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001145 if (player) delete player;
1146 } catch (rdr::Exception e) {
1147 MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
1148 }
1149
1150 return 0;
1151};