Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1 | /* 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 Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 21 | #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> |
george82 | 357c9f5 | 2005-03-21 01:28:12 +0000 | [diff] [blame] | 27 | #include <rfb_win32/AboutDialog.h> |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 28 | |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame] | 29 | #include <rfbplayer/PixelFormatList.h> |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 30 | #include <rfbplayer/rfbplayer.h> |
george82 | 357c9f5 | 2005-03-21 01:28:12 +0000 | [diff] [blame] | 31 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 32 | using namespace rfb; |
| 33 | using namespace rfb::win32; |
| 34 | |
| 35 | // -=- Variables & consts |
| 36 | |
| 37 | static LogWriter vlog("RfbPlayer"); |
| 38 | |
| 39 | TStr rfb::win32::AppName("RfbPlayer"); |
| 40 | extern const char* buildTime; |
| 41 | |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 42 | char wrong_cmd_msg[] = |
| 43 | "Wrong command-line parameters!\n" |
| 44 | "Use for help: rfbplayer -help"; |
| 45 | |
| 46 | char usage_msg[] = |
| 47 | "usage: rfbplayer <options> <filename>\n" |
| 48 | "Command-line options:\n" |
| 49 | " -help \t- Provide usage information.\n" |
george82 | 5caee41 | 2005-03-09 09:52:10 +0000 | [diff] [blame] | 50 | " -pf <mode> \t- Forces the pixel format for the session.\n" |
george82 | dfb557b | 2005-03-21 18:26:50 +0000 | [diff] [blame] | 51 | " \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" |
george82 | 05d8623 | 2005-03-28 12:16:08 +0000 | [diff] [blame^] | 59 | " -upf <name> \t- Forces the user defined pixel format for\n" |
| 60 | " \t the session. If <name> is empty then application\n" |
| 61 | " \t shows the list of user defined pixel formats.\n" |
| 62 | " \t Don't use this option with -pf.\n" |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 63 | " -speed <value>\t- Sets playback speed, where 1 is normal speed,\n" |
| 64 | " \t is double speed, 0.5 is half speed. Default: 1.0.\n" |
| 65 | " -pos <ms> \t- Sets initial time position in the session file,\n" |
| 66 | " \t in milliseconds. Default: 0.\n" |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 67 | " -autoplay \t- Runs the player in the playback mode.\n"; |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 68 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 69 | // -=- RfbPlayer's defines |
| 70 | |
| 71 | #define strcasecmp _stricmp |
george82 | 5457d41 | 2005-02-19 06:43:09 +0000 | [diff] [blame] | 72 | #define MAX_SPEED 10.00 |
| 73 | #define CALCULATION_ERROR MAX_SPEED / 1000 |
george82 | d4d69e6 | 2005-02-05 09:23:18 +0000 | [diff] [blame] | 74 | #define MAX_POS_TRACKBAR_RANGE 50 |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 75 | #define CTRL_BAR_HEIGHT 28 |
george82 | 68d2514 | 2005-02-13 09:33:22 +0000 | [diff] [blame] | 76 | #define DEFAULT_PLAYER_WIDTH 640 |
| 77 | #define DEFAULT_PLAYER_HEIGHT 480 |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 78 | |
george82 | d070c69 | 2005-01-19 16:44:04 +0000 | [diff] [blame] | 79 | #define ID_TOOLBAR 500 |
| 80 | #define ID_PLAY 510 |
| 81 | #define ID_PAUSE 520 |
| 82 | #define ID_TIME_STATIC 530 |
| 83 | #define ID_SPEED_STATIC 540 |
| 84 | #define ID_SPEED_EDIT 550 |
| 85 | #define ID_POS_TRACKBAR 560 |
| 86 | #define ID_SPEED_UPDOWN 570 |
| 87 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 88 | // |
george82 | 357c9f5 | 2005-03-21 01:28:12 +0000 | [diff] [blame] | 89 | // -=- AboutDialog global values |
| 90 | // |
| 91 | |
| 92 | const WORD rfb::win32::AboutDialog::DialogId = IDD_ABOUT; |
| 93 | const WORD rfb::win32::AboutDialog::Copyright = IDC_COPYRIGHT; |
| 94 | const WORD rfb::win32::AboutDialog::Version = IDC_VERSION; |
| 95 | const WORD rfb::win32::AboutDialog::BuildTime = IDC_BUILDTIME; |
| 96 | const WORD rfb::win32::AboutDialog::Description = IDC_DESCRIPTION; |
| 97 | |
| 98 | // |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 99 | // -=- RfbPlayerClass |
| 100 | |
| 101 | // |
| 102 | // Window class used as the basis for RfbPlayer instance |
| 103 | // |
| 104 | |
| 105 | class RfbPlayerClass { |
| 106 | public: |
| 107 | RfbPlayerClass(); |
| 108 | ~RfbPlayerClass(); |
| 109 | ATOM classAtom; |
| 110 | HINSTANCE instance; |
| 111 | }; |
| 112 | |
| 113 | LRESULT CALLBACK RfbPlayerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 114 | LRESULT result; |
| 115 | |
| 116 | if (msg == WM_CREATE) |
| 117 | SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams); |
| 118 | else if (msg == WM_DESTROY) { |
| 119 | RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 120 | SetWindowLong(hwnd, GWL_USERDATA, 0); |
| 121 | } |
| 122 | RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA); |
| 123 | if (!_this) { |
| 124 | vlog.info("null _this in %x, message %u", hwnd, msg); |
| 125 | return DefWindowProc(hwnd, msg, wParam, lParam); |
| 126 | } |
| 127 | |
| 128 | try { |
| 129 | result = _this->processMainMessage(hwnd, msg, wParam, lParam); |
| 130 | } catch (rdr::Exception& e) { |
| 131 | vlog.error("untrapped: %s", e.str()); |
| 132 | } |
| 133 | |
| 134 | return result; |
| 135 | }; |
| 136 | |
| 137 | RfbPlayerClass::RfbPlayerClass() : classAtom(0) { |
| 138 | WNDCLASS wndClass; |
| 139 | wndClass.style = 0; |
| 140 | wndClass.lpfnWndProc = RfbPlayerProc; |
| 141 | wndClass.cbClsExtra = 0; |
| 142 | wndClass.cbWndExtra = 0; |
| 143 | wndClass.hInstance = instance = GetModuleHandle(0); |
| 144 | wndClass.hIcon = (HICON)LoadImage(GetModuleHandle(0), |
george82 | 7214b82 | 2004-12-12 07:02:51 +0000 | [diff] [blame] | 145 | MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_SHARED); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 146 | if (!wndClass.hIcon) |
| 147 | printf("unable to load icon:%ld", GetLastError()); |
| 148 | wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 149 | wndClass.hbrBackground = HBRUSH(COLOR_WINDOW); |
george82 | c2c691f | 2004-12-08 18:04:14 +0000 | [diff] [blame] | 150 | wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 151 | wndClass.lpszClassName = _T("RfbPlayerClass"); |
| 152 | classAtom = RegisterClass(&wndClass); |
| 153 | if (!classAtom) { |
| 154 | throw rdr::SystemException("unable to register RfbPlayer window class", |
| 155 | GetLastError()); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | RfbPlayerClass::~RfbPlayerClass() { |
| 160 | if (classAtom) { |
| 161 | UnregisterClass((const TCHAR*)classAtom, instance); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | RfbPlayerClass baseClass; |
| 166 | |
| 167 | // |
| 168 | // -=- RfbFrameClass |
| 169 | |
| 170 | // |
| 171 | // Window class used to displaying the rfb data |
| 172 | // |
| 173 | |
| 174 | class RfbFrameClass { |
| 175 | public: |
| 176 | RfbFrameClass(); |
| 177 | ~RfbFrameClass(); |
| 178 | ATOM classAtom; |
| 179 | HINSTANCE instance; |
| 180 | }; |
| 181 | |
| 182 | LRESULT CALLBACK FrameProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 183 | LRESULT result; |
| 184 | |
| 185 | if (msg == WM_CREATE) |
| 186 | SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams); |
| 187 | else if (msg == WM_DESTROY) |
| 188 | SetWindowLong(hwnd, GWL_USERDATA, 0); |
| 189 | RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA); |
| 190 | if (!_this) { |
| 191 | vlog.info("null _this in %x, message %u", hwnd, msg); |
| 192 | return DefWindowProc(hwnd, msg, wParam, lParam); |
| 193 | } |
| 194 | |
| 195 | try { |
| 196 | result = _this->processFrameMessage(hwnd, msg, wParam, lParam); |
| 197 | } catch (rdr::Exception& e) { |
| 198 | vlog.error("untrapped: %s", e.str()); |
| 199 | } |
| 200 | |
| 201 | return result; |
| 202 | } |
| 203 | |
| 204 | RfbFrameClass::RfbFrameClass() : classAtom(0) { |
| 205 | WNDCLASS wndClass; |
| 206 | wndClass.style = 0; |
| 207 | wndClass.lpfnWndProc = FrameProc; |
| 208 | wndClass.cbClsExtra = 0; |
| 209 | wndClass.cbWndExtra = 0; |
| 210 | wndClass.hInstance = instance = GetModuleHandle(0); |
| 211 | wndClass.hIcon = 0; |
| 212 | wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 213 | wndClass.hbrBackground = 0; |
| 214 | wndClass.lpszMenuName = 0; |
| 215 | wndClass.lpszClassName = _T("RfbPlayerClass1"); |
| 216 | classAtom = RegisterClass(&wndClass); |
| 217 | if (!classAtom) { |
| 218 | throw rdr::SystemException("unable to register RfbPlayer window class", |
| 219 | GetLastError()); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | RfbFrameClass::~RfbFrameClass() { |
| 224 | if (classAtom) { |
| 225 | UnregisterClass((const TCHAR*)classAtom, instance); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | RfbFrameClass frameClass; |
| 230 | |
| 231 | // |
| 232 | // -=- RfbPlayer instance implementation |
| 233 | // |
| 234 | |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 235 | RfbPlayer::RfbPlayer(char *_fileName, PlayerOptions *_options) |
| 236 | : RfbProto(_fileName), fileName(_fileName), buffer(0), client_size(0, 0, 32, 32), |
| 237 | window_size(0, 0, 32, 32), cutText(0), seekMode(false), lastPos(0), |
| 238 | timeStatic(0), speedEdit(0), posTrackBar(0), speedUpDown(0), |
george82 | 3104aec | 2005-02-21 13:20:56 +0000 | [diff] [blame] | 239 | rfbReader(0), sessionTimeMs(0), sliderDraging(false), sliderStepMs(0), |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 240 | imageDataStartTime(0), rewindFlag(false), stopped(false) { |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 241 | |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 242 | // Save the player options |
| 243 | memcpy(&options, _options, sizeof(options)); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 244 | |
george82 | 3c8fbbf | 2005-01-24 11:09:08 +0000 | [diff] [blame] | 245 | // Reset the full session time |
| 246 | strcpy(fullSessionTime, "00m:00s"); |
| 247 | |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame] | 248 | // Load the user defined pixel formats from the registry |
| 249 | supportedPF.readUserDefinedPF(HKEY_CURRENT_USER, UPF_REGISTRY_PATH); |
| 250 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 251 | // Create the main window |
| 252 | const TCHAR* name = _T("RfbPlayer"); |
george82 | 2ff7a61 | 2005-02-19 17:05:24 +0000 | [diff] [blame] | 253 | int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - DEFAULT_PLAYER_WIDTH) / 2); |
| 254 | int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - DEFAULT_PLAYER_HEIGHT) / 2); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 255 | mainHwnd = CreateWindow((const TCHAR*)baseClass.classAtom, name, WS_OVERLAPPEDWINDOW, |
george82 | 2ff7a61 | 2005-02-19 17:05:24 +0000 | [diff] [blame] | 256 | x, y, DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT, 0, 0, baseClass.instance, this); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 257 | if (!mainHwnd) { |
| 258 | throw rdr::SystemException("unable to create WMNotifier window instance", GetLastError()); |
| 259 | } |
| 260 | vlog.debug("created window \"%s\" (%x)", (const char*)CStr(name), getMainHandle()); |
| 261 | |
| 262 | // Create the backing buffer |
| 263 | buffer = new win32::DIBSectionBuffer(getFrameHandle()); |
george82 | 1031310 | 2005-01-17 13:11:40 +0000 | [diff] [blame] | 264 | setVisible(true); |
george82 | 5beb62a | 2005-02-09 13:04:32 +0000 | [diff] [blame] | 265 | |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 266 | // If run with command-line parameters, |
| 267 | // open the session file with default settings, otherwise |
| 268 | // restore player settings from the registry |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 269 | if (fileName) { |
| 270 | openSessionFile(fileName); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 271 | if (options.initTime > 0) setPos(options.initTime); |
| 272 | setSpeed(options.playbackSpeed); |
george82 | 63ebbcc | 2005-02-12 12:09:13 +0000 | [diff] [blame] | 273 | } else { |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 274 | options.readFromRegistry(); |
george82 | 63ebbcc | 2005-02-12 12:09:13 +0000 | [diff] [blame] | 275 | disableTBandMenuItems(); |
george82 | f530276 | 2005-02-13 12:31:03 +0000 | [diff] [blame] | 276 | setTitle("None"); |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 277 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | RfbPlayer::~RfbPlayer() { |
| 281 | vlog.debug("~RfbPlayer"); |
george82 | ce8dc3a | 2005-01-31 13:06:54 +0000 | [diff] [blame] | 282 | if (rfbReader) { |
george82 | ce8dc3a | 2005-01-31 13:06:54 +0000 | [diff] [blame] | 283 | delete rfbReader->join(); |
| 284 | rfbReader = 0; |
| 285 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 286 | if (mainHwnd) { |
| 287 | setVisible(false); |
| 288 | DestroyWindow(mainHwnd); |
| 289 | mainHwnd = 0; |
| 290 | } |
george82 | 5beb62a | 2005-02-09 13:04:32 +0000 | [diff] [blame] | 291 | if (buffer) delete buffer; |
| 292 | if (cutText) delete [] cutText; |
george82 | 7009c89 | 2005-02-19 12:49:42 +0000 | [diff] [blame] | 293 | if (fileName) delete [] fileName; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 294 | vlog.debug("~RfbPlayer done"); |
| 295 | } |
| 296 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 297 | LRESULT |
| 298 | RfbPlayer::processMainMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 299 | switch (msg) { |
| 300 | |
| 301 | // -=- Process standard window messages |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 302 | |
| 303 | case WM_CREATE: |
| 304 | { |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 305 | // Create the frame window |
| 306 | frameHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, (const TCHAR*)frameClass.classAtom, |
| 307 | 0, WS_CHILD | WS_VISIBLE, 0, CTRL_BAR_HEIGHT, 10, CTRL_BAR_HEIGHT + 10, |
| 308 | hwnd, 0, frameClass.instance, this); |
| 309 | |
george82 | d070c69 | 2005-01-19 16:44:04 +0000 | [diff] [blame] | 310 | createToolBar(hwnd); |
| 311 | |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 312 | hMenu = GetMenu(hwnd); |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 313 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 314 | return 0; |
| 315 | } |
| 316 | |
george82 | 7214b82 | 2004-12-12 07:02:51 +0000 | [diff] [blame] | 317 | // Process the main menu and toolbar's messages |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 318 | |
| 319 | case WM_COMMAND: |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 320 | switch (LOWORD(wParam)) { |
george82 | 6e51fcc | 2005-02-06 13:30:49 +0000 | [diff] [blame] | 321 | case ID_OPENFILE: |
| 322 | { |
| 323 | char curDir[_MAX_DIR]; |
| 324 | static char filename[_MAX_PATH]; |
| 325 | OPENFILENAME ofn; |
| 326 | memset((void *) &ofn, 0, sizeof(OPENFILENAME)); |
| 327 | GetCurrentDirectory(sizeof(curDir), curDir); |
| 328 | |
| 329 | ofn.lStructSize = sizeof(OPENFILENAME); |
| 330 | ofn.hwndOwner = getMainHandle(); |
| 331 | ofn.lpstrFile = filename; |
| 332 | ofn.nMaxFile = sizeof(filename); |
| 333 | ofn.lpstrInitialDir = curDir; |
| 334 | ofn.lpstrFilter = "Rfb Session files (*.rfb)\0*.rfb\0" \ |
| 335 | "All files (*.*)\0*.*\0"; |
| 336 | ofn.lpstrDefExt = "rfb"; |
| 337 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; |
george82 | 9d5129a | 2005-02-21 13:32:39 +0000 | [diff] [blame] | 338 | if (GetOpenFileName(&ofn)) { |
george82 | 6e51fcc | 2005-02-06 13:30:49 +0000 | [diff] [blame] | 339 | openSessionFile(filename); |
george82 | 9d5129a | 2005-02-21 13:32:39 +0000 | [diff] [blame] | 340 | } |
george82 | 6e51fcc | 2005-02-06 13:30:49 +0000 | [diff] [blame] | 341 | } |
| 342 | break; |
george82 | 71ca177 | 2005-02-13 10:50:46 +0000 | [diff] [blame] | 343 | case ID_CLOSEFILE: |
| 344 | closeSessionFile(); |
| 345 | break; |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 346 | case ID_PLAY: |
| 347 | setPaused(false); |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 348 | break; |
| 349 | case ID_PAUSE: |
| 350 | setPaused(true); |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 351 | break; |
| 352 | case ID_STOP: |
| 353 | if (getTimeOffset() != 0) { |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 354 | stopPlayback(); |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 355 | } |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 356 | break; |
| 357 | case ID_PLAYPAUSE: |
george82 | bc999f4 | 2005-03-19 11:48:19 +0000 | [diff] [blame] | 358 | if (rfbReader) { |
| 359 | if (isPaused()) { |
| 360 | setPaused(false); |
| 361 | } else { |
| 362 | setPaused(true); |
| 363 | } |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 364 | } |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 365 | break; |
george82 | 7549df4 | 2005-02-08 16:31:02 +0000 | [diff] [blame] | 366 | case ID_GOTO: |
| 367 | { |
| 368 | GotoPosDialog gotoPosDlg; |
george82 | d9957b7 | 2005-03-11 14:22:14 +0000 | [diff] [blame] | 369 | if (gotoPosDlg.showDialog(getMainHandle())) { |
george82 | 1d5d40d | 2005-02-20 03:25:47 +0000 | [diff] [blame] | 370 | long gotoTime = min(gotoPosDlg.getPos(), sessionTimeMs); |
| 371 | setPos(gotoTime); |
| 372 | updatePos(gotoTime); |
george82 | a6900d7 | 2005-02-21 17:24:26 +0000 | [diff] [blame] | 373 | setPaused(isPaused());; |
george82 | 7549df4 | 2005-02-08 16:31:02 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | break; |
george82 | 5c13c66 | 2005-01-27 14:48:23 +0000 | [diff] [blame] | 377 | case ID_FULLSCREEN: |
| 378 | MessageBox(getMainHandle(), "It is not working yet!", "RfbPlayer", MB_OK); |
| 379 | break; |
george82 | 31a3633 | 2005-02-06 17:27:34 +0000 | [diff] [blame] | 380 | case ID_LOOP: |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 381 | options.loopPlayback = !options.loopPlayback; |
| 382 | if (options.loopPlayback) CheckMenuItem(hMenu, ID_LOOP, MF_CHECKED); |
george82 | 31a3633 | 2005-02-06 17:27:34 +0000 | [diff] [blame] | 383 | else CheckMenuItem(hMenu, ID_LOOP, MF_UNCHECKED); |
| 384 | break; |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 385 | case ID_RETURN: |
| 386 | // Update the speed if return pressed in speedEdit |
| 387 | if (speedEdit == GetFocus()) { |
| 388 | char speedStr[20], *stopStr; |
| 389 | GetWindowText(speedEdit, speedStr, sizeof(speedStr)); |
| 390 | double speed = strtod(speedStr, &stopStr); |
| 391 | if (speed > 0) { |
| 392 | speed = min(MAX_SPEED, speed); |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 393 | } else { |
| 394 | speed = getSpeed(); |
| 395 | } |
| 396 | setSpeed(speed); |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 397 | } |
| 398 | break; |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 399 | case ID_OPTIONS: |
| 400 | { |
george82 | 5a6df07 | 2005-03-20 09:56:17 +0000 | [diff] [blame] | 401 | OptionsDialog optionsDialog(&options, &supportedPF); |
george82 | d9957b7 | 2005-03-11 14:22:14 +0000 | [diff] [blame] | 402 | optionsDialog.showDialog(getMainHandle()); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 403 | } |
| 404 | break; |
george82 | 01aa673 | 2005-02-06 17:13:03 +0000 | [diff] [blame] | 405 | case ID_EXIT: |
george82 | 01aa673 | 2005-02-06 17:13:03 +0000 | [diff] [blame] | 406 | PostQuitMessage(0); |
| 407 | break; |
george82 | ef5f726 | 2005-02-08 15:09:26 +0000 | [diff] [blame] | 408 | case ID_HELP_COMMANDLINESWITCHES: |
george82 | 59f8453 | 2005-02-08 15:01:39 +0000 | [diff] [blame] | 409 | MessageBox(getMainHandle(), |
| 410 | usage_msg, "RfbPlayer", MB_OK | MB_ICONINFORMATION); |
| 411 | break; |
george82 | 357c9f5 | 2005-03-21 01:28:12 +0000 | [diff] [blame] | 412 | case ID_ABOUT: |
| 413 | AboutDialog::instance.showDialog(); |
| 414 | break; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 415 | } |
| 416 | break; |
| 417 | |
| 418 | // Update frame's window size and add scrollbars if required |
| 419 | |
| 420 | case WM_SIZE: |
| 421 | { |
george82 | d070c69 | 2005-01-19 16:44:04 +0000 | [diff] [blame] | 422 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 423 | Point old_offset = bufferToClient(Point(0, 0)); |
| 424 | |
| 425 | // Update the cached sizing information |
| 426 | RECT r; |
| 427 | GetClientRect(getMainHandle(), &r); |
| 428 | MoveWindow(getFrameHandle(), 0, CTRL_BAR_HEIGHT, r.right - r.left, |
| 429 | r.bottom - r.top - CTRL_BAR_HEIGHT, TRUE); |
| 430 | |
| 431 | GetWindowRect(getFrameHandle(), &r); |
| 432 | window_size = Rect(r.left, r.top, r.right, r.bottom); |
| 433 | GetClientRect(getFrameHandle(), &r); |
| 434 | client_size = Rect(r.left, r.top, r.right, r.bottom); |
| 435 | |
| 436 | // Determine whether scrollbars are required |
| 437 | calculateScrollBars(); |
george82 | d070c69 | 2005-01-19 16:44:04 +0000 | [diff] [blame] | 438 | |
| 439 | // Resize the ToolBar |
| 440 | tb.autoSize(); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 441 | |
| 442 | // Redraw if required |
| 443 | if (!old_offset.equals(bufferToClient(Point(0, 0)))) |
| 444 | InvalidateRect(getFrameHandle(), 0, TRUE); |
| 445 | } |
| 446 | break; |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 447 | |
| 448 | // Process messages from posTrackBar |
| 449 | |
| 450 | case WM_HSCROLL: |
| 451 | { |
| 452 | long Pos = SendMessage(posTrackBar, TBM_GETPOS, 0, 0); |
| 453 | Pos *= sliderStepMs; |
| 454 | |
| 455 | switch (LOWORD(wParam)) { |
| 456 | case TB_PAGEUP: |
| 457 | case TB_PAGEDOWN: |
| 458 | case TB_LINEUP: |
| 459 | case TB_LINEDOWN: |
| 460 | case TB_THUMBTRACK: |
| 461 | sliderDraging = true; |
| 462 | updatePos(Pos); |
| 463 | return 0; |
george82 | bcc129b | 2005-03-15 17:11:40 +0000 | [diff] [blame] | 464 | case TB_THUMBPOSITION: |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 465 | case TB_ENDTRACK: |
| 466 | setPos(Pos); |
george82 | a6900d7 | 2005-02-21 17:24:26 +0000 | [diff] [blame] | 467 | setPaused(isPaused());; |
george82 | bcc129b | 2005-03-15 17:11:40 +0000 | [diff] [blame] | 468 | updatePos(Pos); |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 469 | sliderDraging = false; |
| 470 | return 0; |
| 471 | default: |
| 472 | break; |
| 473 | } |
| 474 | } |
| 475 | break; |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 476 | |
| 477 | case WM_NOTIFY: |
| 478 | switch (((NMHDR*)lParam)->code) { |
| 479 | case UDN_DELTAPOS: |
| 480 | if ((int)wParam == ID_SPEED_UPDOWN) { |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 481 | BOOL lResult = FALSE; |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 482 | char speedStr[20] = "\0"; |
| 483 | DWORD speedRange = SendMessage(speedUpDown, UDM_GETRANGE, 0, 0); |
| 484 | LPNM_UPDOWN upDown = (LPNM_UPDOWN)lParam; |
| 485 | double speed; |
| 486 | |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 487 | // The out of range checking |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 488 | if (upDown->iDelta > 0) { |
| 489 | speed = min(upDown->iPos + upDown->iDelta, LOWORD(speedRange)) * 0.5; |
| 490 | } else { |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 491 | // It's need to round the UpDown position |
| 492 | if ((upDown->iPos * 0.5) != getSpeed()) { |
| 493 | upDown->iDelta = 0; |
| 494 | lResult = TRUE; |
| 495 | } |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 496 | speed = max(upDown->iPos + upDown->iDelta, HIWORD(speedRange)) * 0.5; |
| 497 | } |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 498 | sprintf(speedStr, "%.2f", speed); |
| 499 | SetWindowText(speedEdit, speedStr); |
george82 | 5f326fe | 2005-02-20 08:01:01 +0000 | [diff] [blame] | 500 | is->setSpeed(speed); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 501 | options.playbackSpeed = speed; |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 502 | return lResult; |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 503 | } |
george82 | 4ea27f6 | 2005-01-29 15:03:06 +0000 | [diff] [blame] | 504 | } |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 505 | return 0; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 506 | |
| 507 | case WM_CLOSE: |
| 508 | vlog.debug("WM_CLOSE %x", getMainHandle()); |
| 509 | PostQuitMessage(0); |
| 510 | break; |
| 511 | } |
| 512 | |
| 513 | return rfb::win32::SafeDefWindowProc(getMainHandle(), msg, wParam, lParam); |
| 514 | } |
| 515 | |
| 516 | LRESULT RfbPlayer::processFrameMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 517 | switch (msg) { |
| 518 | |
| 519 | case WM_PAINT: |
| 520 | { |
george82 | 1e846ff | 2005-02-24 13:13:33 +0000 | [diff] [blame] | 521 | if (isSeeking() || rewindFlag) { |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 522 | seekMode = true; |
| 523 | return 0; |
| 524 | } else { |
| 525 | if (seekMode) { |
| 526 | seekMode = false; |
| 527 | InvalidateRect(getFrameHandle(), 0, true); |
| 528 | UpdateWindow(getFrameHandle()); |
| 529 | return 0; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | PAINTSTRUCT ps; |
| 534 | HDC paintDC = BeginPaint(getFrameHandle(), &ps); |
| 535 | if (!paintDC) |
| 536 | throw SystemException("unable to BeginPaint", GetLastError()); |
| 537 | Rect pr = Rect(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom); |
| 538 | |
| 539 | if (!pr.is_empty()) { |
| 540 | |
| 541 | if (buffer->bitmap) { |
| 542 | |
| 543 | // Get device context |
| 544 | BitmapDC bitmapDC(paintDC, buffer->bitmap); |
| 545 | |
| 546 | // Blit the border if required |
| 547 | Rect bufpos = bufferToClient(buffer->getRect()); |
| 548 | if (!pr.enclosed_by(bufpos)) { |
| 549 | vlog.debug("draw border"); |
| 550 | HBRUSH black = (HBRUSH) GetStockObject(BLACK_BRUSH); |
| 551 | RECT r; |
| 552 | SetRect(&r, 0, 0, bufpos.tl.x, client_size.height()); FillRect(paintDC, &r, black); |
| 553 | SetRect(&r, bufpos.tl.x, 0, bufpos.br.x, bufpos.tl.y); FillRect(paintDC, &r, black); |
| 554 | SetRect(&r, bufpos.br.x, 0, client_size.width(), client_size.height()); FillRect(paintDC, &r, black); |
| 555 | SetRect(&r, bufpos.tl.x, bufpos.br.y, bufpos.br.x, client_size.height()); FillRect(paintDC, &r, black); |
| 556 | } |
| 557 | |
| 558 | // Do the blit |
| 559 | Point buf_pos = clientToBuffer(pr.tl); |
| 560 | if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(), |
| 561 | bitmapDC, buf_pos.x, buf_pos.y, SRCCOPY)) |
| 562 | throw SystemException("unable to BitBlt to window", GetLastError()); |
| 563 | |
| 564 | } else { |
| 565 | // Blit a load of black |
| 566 | if (!BitBlt(paintDC, pr.tl.x, pr.tl.y, pr.width(), pr.height(), |
| 567 | 0, 0, 0, BLACKNESS)) |
| 568 | throw SystemException("unable to BitBlt to blank window", GetLastError()); |
| 569 | } |
| 570 | } |
| 571 | EndPaint(getFrameHandle(), &ps); |
| 572 | } |
| 573 | return 0; |
george82 | 03c01da | 2005-03-16 12:36:53 +0000 | [diff] [blame] | 574 | |
george82 | aff63ab | 2005-03-16 13:48:59 +0000 | [diff] [blame] | 575 | // Process play/pause by the left mouse button |
| 576 | case WM_LBUTTONDOWN: |
george82 | 03c01da | 2005-03-16 12:36:53 +0000 | [diff] [blame] | 577 | SendMessage(getMainHandle(), WM_COMMAND, ID_PLAYPAUSE, 0); |
| 578 | return 0; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 579 | |
| 580 | case WM_VSCROLL: |
| 581 | case WM_HSCROLL: |
| 582 | { |
| 583 | Point delta; |
| 584 | int newpos = (msg == WM_VSCROLL) ? scrolloffset.y : scrolloffset.x; |
| 585 | |
| 586 | switch (LOWORD(wParam)) { |
| 587 | case SB_PAGEUP: newpos -= 50; break; |
| 588 | case SB_PAGEDOWN: newpos += 50; break; |
| 589 | case SB_LINEUP: newpos -= 5; break; |
| 590 | case SB_LINEDOWN: newpos += 5; break; |
| 591 | case SB_THUMBTRACK: |
| 592 | case SB_THUMBPOSITION: newpos = HIWORD(wParam); break; |
| 593 | default: vlog.info("received unknown scroll message"); |
| 594 | }; |
| 595 | |
| 596 | if (msg == WM_HSCROLL) |
| 597 | setViewportOffset(Point(newpos, scrolloffset.y)); |
| 598 | else |
| 599 | setViewportOffset(Point(scrolloffset.x, newpos)); |
| 600 | |
| 601 | SCROLLINFO si; |
| 602 | si.cbSize = sizeof(si); |
| 603 | si.fMask = SIF_POS; |
| 604 | si.nPos = newpos; |
| 605 | SetScrollInfo(getFrameHandle(), (msg == WM_VSCROLL) ? SB_VERT : SB_HORZ, &si, TRUE); |
| 606 | } |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | return DefWindowProc(hwnd, msg, wParam, lParam); |
| 611 | } |
| 612 | |
george82 | d070c69 | 2005-01-19 16:44:04 +0000 | [diff] [blame] | 613 | void RfbPlayer::createToolBar(HWND parentHwnd) { |
| 614 | RECT tRect; |
| 615 | InitCommonControls(); |
| 616 | |
| 617 | tb.create(ID_TOOLBAR, parentHwnd); |
| 618 | tb.addBitmap(4, IDB_TOOLBAR); |
| 619 | |
| 620 | // Create the control buttons |
| 621 | tb.addButton(0, ID_PLAY); |
| 622 | tb.addButton(1, ID_PAUSE); |
| 623 | tb.addButton(2, ID_STOP); |
| 624 | tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 625 | tb.addButton(3, ID_FULLSCREEN); |
| 626 | tb.addButton(0, 0, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 627 | |
| 628 | // Create the static control for the time output |
| 629 | tb.addButton(125, 0, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 630 | tb.getButtonRect(6, &tRect); |
| 631 | timeStatic = CreateWindowEx(0, "Static", "00m:00s (00m:00s)", |
| 632 | WS_CHILD | WS_VISIBLE, tRect.left, tRect.top+2, tRect.right-tRect.left, |
| 633 | tRect.bottom-tRect.top, tb.getHandle(), (HMENU)ID_TIME_STATIC, |
| 634 | GetModuleHandle(0), 0); |
| 635 | tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 636 | |
| 637 | // Create the trackbar control for the time position |
| 638 | tb.addButton(200, 0, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 639 | tb.getButtonRect(8, &tRect); |
george82 | d4d69e6 | 2005-02-05 09:23:18 +0000 | [diff] [blame] | 640 | posTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, "Trackbar Control", |
george82 | d070c69 | 2005-01-19 16:44:04 +0000 | [diff] [blame] | 641 | WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS | TBS_ENABLESELRANGE, |
| 642 | tRect.left, tRect.top, tRect.right-tRect.left, tRect.bottom-tRect.top, |
| 643 | parentHwnd, (HMENU)ID_POS_TRACKBAR, GetModuleHandle(0), 0); |
| 644 | // It's need to send notify messages to toolbar parent window |
george82 | d4d69e6 | 2005-02-05 09:23:18 +0000 | [diff] [blame] | 645 | SetParent(posTrackBar, tb.getHandle()); |
george82 | d070c69 | 2005-01-19 16:44:04 +0000 | [diff] [blame] | 646 | tb.addButton(0, 10, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 647 | |
| 648 | // Create the label with "Speed:" caption |
| 649 | tb.addButton(50, 0, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 650 | tb.getButtonRect(10, &tRect); |
| 651 | CreateWindowEx(0, "Static", "Speed:", WS_CHILD | WS_VISIBLE, |
| 652 | tRect.left, tRect.top+2, tRect.right-tRect.left, tRect.bottom-tRect.top, |
| 653 | tb.getHandle(), (HMENU)ID_SPEED_STATIC, GetModuleHandle(0), 0); |
| 654 | |
| 655 | // Create the edit control and the spin for the speed managing |
| 656 | tb.addButton(60, 0, TBSTATE_ENABLED, TBSTYLE_SEP); |
| 657 | tb.getButtonRect(11, &tRect); |
| 658 | speedEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "1.00", |
| 659 | WS_CHILD | WS_VISIBLE | ES_RIGHT, tRect.left, tRect.top, |
| 660 | tRect.right-tRect.left, tRect.bottom-tRect.top, parentHwnd, |
| 661 | (HMENU)ID_SPEED_EDIT, GetModuleHandle(0), 0); |
| 662 | // It's need to send notify messages to toolbar parent window |
| 663 | SetParent(speedEdit, tb.getHandle()); |
| 664 | |
| 665 | speedUpDown = CreateUpDownControl(WS_CHILD | WS_VISIBLE |
| 666 | | WS_BORDER | UDS_ALIGNRIGHT, 0, 0, 0, 0, tb.getHandle(), |
george82 | 9e6e6cc | 2005-01-29 13:12:05 +0000 | [diff] [blame] | 667 | ID_SPEED_UPDOWN, GetModuleHandle(0), speedEdit, 20, 1, 2); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 668 | } |
| 669 | |
george82 | a21d295 | 2005-02-12 11:30:03 +0000 | [diff] [blame] | 670 | void RfbPlayer::disableTBandMenuItems() { |
| 671 | // Disable the menu items |
| 672 | EnableMenuItem(hMenu, ID_CLOSEFILE, MF_GRAYED | MF_BYCOMMAND); |
| 673 | EnableMenuItem(hMenu, ID_FULLSCREEN, MF_GRAYED | MF_BYCOMMAND); |
| 674 | EnableMenuItem(GetSubMenu(hMenu, 1), 1, MF_GRAYED | MF_BYPOSITION); |
| 675 | EnableMenuItem(hMenu, ID_PLAYPAUSE, MF_GRAYED | MF_BYCOMMAND); |
| 676 | EnableMenuItem(hMenu, ID_STOP, MF_GRAYED | MF_BYCOMMAND); |
| 677 | EnableMenuItem(hMenu, ID_GOTO, MF_GRAYED | MF_BYCOMMAND); |
| 678 | EnableMenuItem(hMenu, ID_LOOP, MF_GRAYED | MF_BYCOMMAND); |
| 679 | EnableMenuItem(hMenu, ID_COPYTOCLIPBOARD, MF_GRAYED | MF_BYCOMMAND); |
| 680 | EnableMenuItem(hMenu, ID_FRAMEEXTRACT, MF_GRAYED | MF_BYCOMMAND); |
| 681 | |
| 682 | // Disable the toolbar buttons and child controls |
| 683 | tb.enableButton(ID_PLAY, false); |
| 684 | tb.enableButton(ID_PAUSE, false); |
| 685 | tb.enableButton(ID_STOP, false); |
| 686 | tb.enableButton(ID_FULLSCREEN, false); |
| 687 | EnableWindow(posTrackBar, false); |
| 688 | EnableWindow(speedEdit, false); |
george82 | e0a28ab | 2005-02-19 06:54:47 +0000 | [diff] [blame] | 689 | EnableWindow(speedUpDown, false); |
george82 | a21d295 | 2005-02-12 11:30:03 +0000 | [diff] [blame] | 690 | } |
| 691 | |
george82 | f504316 | 2005-02-12 11:37:18 +0000 | [diff] [blame] | 692 | void RfbPlayer::enableTBandMenuItems() { |
| 693 | // Enable the menu items |
| 694 | EnableMenuItem(hMenu, ID_CLOSEFILE, MF_ENABLED | MF_BYCOMMAND); |
| 695 | EnableMenuItem(hMenu, ID_FULLSCREEN, MF_ENABLED | MF_BYCOMMAND); |
| 696 | EnableMenuItem(GetSubMenu(hMenu, 1), 1, MF_ENABLED | MF_BYPOSITION); |
| 697 | EnableMenuItem(hMenu, ID_PLAYPAUSE, MF_ENABLED | MF_BYCOMMAND); |
| 698 | EnableMenuItem(hMenu, ID_STOP, MF_ENABLED | MF_BYCOMMAND); |
| 699 | EnableMenuItem(hMenu, ID_GOTO, MF_ENABLED | MF_BYCOMMAND); |
| 700 | EnableMenuItem(hMenu, ID_LOOP, MF_ENABLED | MF_BYCOMMAND); |
| 701 | EnableMenuItem(hMenu, ID_COPYTOCLIPBOARD, MF_ENABLED | MF_BYCOMMAND); |
| 702 | EnableMenuItem(hMenu, ID_FRAMEEXTRACT, MF_ENABLED | MF_BYCOMMAND); |
| 703 | |
| 704 | // Enable the toolbar buttons and child controls |
| 705 | tb.enableButton(ID_PLAY, true); |
| 706 | tb.enableButton(ID_PAUSE, true); |
| 707 | tb.enableButton(ID_STOP, true); |
| 708 | tb.enableButton(ID_FULLSCREEN, true); |
| 709 | EnableWindow(posTrackBar, true); |
| 710 | EnableWindow(speedEdit, true); |
george82 | e0a28ab | 2005-02-19 06:54:47 +0000 | [diff] [blame] | 711 | EnableWindow(speedUpDown, true); |
george82 | f504316 | 2005-02-12 11:37:18 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 714 | void RfbPlayer::setVisible(bool visible) { |
| 715 | ShowWindow(getMainHandle(), visible ? SW_SHOW : SW_HIDE); |
| 716 | if (visible) { |
| 717 | // When the window becomes visible, make it active |
| 718 | SetForegroundWindow(getMainHandle()); |
| 719 | SetActiveWindow(getMainHandle()); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | void RfbPlayer::setTitle(const char *title) { |
| 724 | char _title[256]; |
| 725 | strcpy(_title, AppName); |
| 726 | strcat(_title, " - "); |
| 727 | strcat(_title, title); |
| 728 | SetWindowText(getMainHandle(), _title); |
| 729 | } |
| 730 | |
| 731 | void RfbPlayer::setFrameSize(int width, int height) { |
| 732 | // Calculate and set required size for main window |
| 733 | RECT r = {0, 0, width, height}; |
george82 | e1169a1 | 2005-02-19 13:54:38 +0000 | [diff] [blame] | 734 | AdjustWindowRectEx(&r, GetWindowLong(getFrameHandle(), GWL_STYLE), TRUE, |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 735 | GetWindowLong(getFrameHandle(), GWL_EXSTYLE)); |
| 736 | r.bottom += CTRL_BAR_HEIGHT; // Include RfbPlayr's controls area |
| 737 | AdjustWindowRect(&r, GetWindowLong(getMainHandle(), GWL_STYLE), FALSE); |
george82 | 2ff7a61 | 2005-02-19 17:05:24 +0000 | [diff] [blame] | 738 | int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2); |
| 739 | int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2); |
| 740 | SetWindowPos(getMainHandle(), 0, x, y, r.right-r.left, r.bottom-r.top, |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 741 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER); |
| 742 | |
| 743 | // Enable/disable scrollbars as appropriate |
| 744 | calculateScrollBars(); |
| 745 | } |
| 746 | |
| 747 | void RfbPlayer::calculateScrollBars() { |
| 748 | // Calculate the required size of window |
| 749 | DWORD current_style = GetWindowLong(getFrameHandle(), GWL_STYLE); |
| 750 | DWORD style = current_style & ~(WS_VSCROLL | WS_HSCROLL); |
| 751 | DWORD old_style; |
| 752 | RECT r; |
| 753 | SetRect(&r, 0, 0, buffer->width(), buffer->height()); |
| 754 | AdjustWindowRectEx(&r, style, FALSE, GetWindowLong(getFrameHandle(), GWL_EXSTYLE)); |
| 755 | Rect reqd_size = Rect(r.left, r.top, r.right, r.bottom); |
| 756 | |
| 757 | // Work out whether scroll bars are required |
| 758 | do { |
| 759 | old_style = style; |
| 760 | |
| 761 | if (!(style & WS_HSCROLL) && (reqd_size.width() > window_size.width())) { |
| 762 | style |= WS_HSCROLL; |
| 763 | reqd_size.br.y += GetSystemMetrics(SM_CXHSCROLL); |
| 764 | } |
| 765 | if (!(style & WS_VSCROLL) && (reqd_size.height() > window_size.height())) { |
| 766 | style |= WS_VSCROLL; |
| 767 | reqd_size.br.x += GetSystemMetrics(SM_CXVSCROLL); |
| 768 | } |
| 769 | } while (style != old_style); |
| 770 | |
| 771 | // Tell Windows to update the window style & cached settings |
| 772 | if (style != current_style) { |
| 773 | SetWindowLong(getFrameHandle(), GWL_STYLE, style); |
| 774 | SetWindowPos(getFrameHandle(), NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); |
| 775 | } |
| 776 | |
| 777 | // Update the scroll settings |
| 778 | SCROLLINFO si; |
| 779 | if (style & WS_VSCROLL) { |
| 780 | si.cbSize = sizeof(si); |
| 781 | si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; |
| 782 | si.nMin = 0; |
| 783 | si.nMax = buffer->height(); |
| 784 | si.nPage = buffer->height() - (reqd_size.height() - window_size.height()); |
| 785 | maxscrolloffset.y = max(0, si.nMax-si.nPage); |
| 786 | scrolloffset.y = min(maxscrolloffset.y, scrolloffset.y); |
| 787 | si.nPos = scrolloffset.y; |
| 788 | SetScrollInfo(getFrameHandle(), SB_VERT, &si, TRUE); |
| 789 | } |
| 790 | if (style & WS_HSCROLL) { |
| 791 | si.cbSize = sizeof(si); |
| 792 | si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; |
| 793 | si.nMin = 0; |
| 794 | si.nMax = buffer->width(); |
| 795 | si.nPage = buffer->width() - (reqd_size.width() - window_size.width()); |
| 796 | maxscrolloffset.x = max(0, si.nMax-si.nPage); |
| 797 | scrolloffset.x = min(maxscrolloffset.x, scrolloffset.x); |
| 798 | si.nPos = scrolloffset.x; |
| 799 | SetScrollInfo(getFrameHandle(), SB_HORZ, &si, TRUE); |
| 800 | } |
george82 | a758a7a | 2005-03-15 16:34:57 +0000 | [diff] [blame] | 801 | |
| 802 | // Update the cached client size |
| 803 | GetClientRect(getFrameHandle(), &r); |
| 804 | client_size = Rect(r.left, r.top, r.right, r.bottom); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | bool RfbPlayer::setViewportOffset(const Point& tl) { |
| 808 | /* *** |
| 809 | Point np = Point(max(0, min(maxscrolloffset.x, tl.x)), |
| 810 | max(0, min(maxscrolloffset.y, tl.y))); |
| 811 | */ |
| 812 | Point np = Point(max(0, min(tl.x, buffer->width()-client_size.width())), |
| 813 | max(0, min(tl.y, buffer->height()-client_size.height()))); |
| 814 | Point delta = np.translate(scrolloffset.negate()); |
| 815 | if (!np.equals(scrolloffset)) { |
| 816 | scrolloffset = np; |
| 817 | ScrollWindowEx(getFrameHandle(), -delta.x, -delta.y, 0, 0, 0, 0, SW_INVALIDATE); |
| 818 | UpdateWindow(getFrameHandle()); |
| 819 | return true; |
| 820 | } |
| 821 | return false; |
| 822 | } |
| 823 | |
| 824 | void RfbPlayer::close(const char* reason) { |
| 825 | setVisible(false); |
| 826 | if (reason) { |
| 827 | vlog.info("closing - %s", reason); |
| 828 | MessageBox(NULL, TStr(reason), "RfbPlayer", MB_ICONINFORMATION | MB_OK); |
| 829 | } |
| 830 | SendMessage(getFrameHandle(), WM_CLOSE, 0, 0); |
| 831 | } |
| 832 | |
| 833 | void RfbPlayer::blankBuffer() { |
| 834 | fillRect(buffer->getRect(), 0); |
| 835 | } |
| 836 | |
| 837 | void RfbPlayer::rewind() { |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 838 | bool paused = isPaused(); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 839 | blankBuffer(); |
| 840 | newSession(fileName); |
| 841 | skipHandshaking(); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 842 | is->setSpeed(options.playbackSpeed); |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 843 | if (paused) is->pausePlayback(); |
| 844 | else is->resumePlayback(); |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | void RfbPlayer::processMsg() { |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 848 | // Perform return if waitWhilePaused processed because |
| 849 | // rfbReader thread could receive the signal to close |
| 850 | if (waitWhilePaused()) return; |
| 851 | |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 852 | static long update_time = GetTickCount(); |
| 853 | try { |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 854 | if ((!isSeeking()) && ((GetTickCount() - update_time) > 250) |
| 855 | && (!sliderDraging)) { |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 856 | // Update pos in the toolbar 4 times in 1 second |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 857 | updatePos(getTimeOffset()); |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 858 | update_time = GetTickCount(); |
| 859 | } |
| 860 | RfbProto::processMsg(); |
| 861 | } catch (rdr::Exception e) { |
| 862 | if (strcmp(e.str(), "[End Of File]") == 0) { |
| 863 | rewind(); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 864 | setPaused(!options.loopPlayback); |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 865 | updatePos(getTimeOffset()); |
george82 | 9403bee | 2005-02-06 11:14:39 +0000 | [diff] [blame] | 866 | SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0); |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 867 | return; |
| 868 | } |
| 869 | // It's a special exception to perform backward seeking. |
| 870 | // We only rewind the stream and seek the offset |
| 871 | if (strcmp(e.str(), "[REWIND]") == 0) { |
george82 | 1e846ff | 2005-02-24 13:13:33 +0000 | [diff] [blame] | 872 | rewindFlag = true; |
george82 | b95503e | 2005-02-21 17:02:34 +0000 | [diff] [blame] | 873 | long seekOffset = max(getSeekOffset(), imageDataStartTime); |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 874 | rewind(); |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 875 | if (!stopped) setPos(seekOffset); |
| 876 | else stopped = false; |
george82 | 3104aec | 2005-02-21 13:20:56 +0000 | [diff] [blame] | 877 | updatePos(seekOffset); |
george82 | 1e846ff | 2005-02-24 13:13:33 +0000 | [diff] [blame] | 878 | rewindFlag = false; |
george82 | 2c7634b | 2005-03-10 18:03:27 +0000 | [diff] [blame] | 879 | return; |
| 880 | } |
| 881 | // It's a special exception which is used to terminate the playback |
| 882 | if (strcmp(e.str(), "[TERMINATE]") == 0) { |
| 883 | sessionTerminateThread *terminate = new sessionTerminateThread(this); |
| 884 | terminate->start(); |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 885 | } else { |
george82 | 0e980cc | 2005-03-10 18:18:34 +0000 | [diff] [blame] | 886 | // Show the exception message and close the session playback |
| 887 | is->pausePlayback(); |
| 888 | char message[256] = "\0"; |
| 889 | strcat(message, e.str()); |
| 890 | strcat(message, "\nMaybe you force wrong the pixel format for this session"); |
| 891 | MessageBox(getMainHandle(), message, e.type(), MB_OK | MB_ICONERROR); |
| 892 | sessionTerminateThread *terminate = new sessionTerminateThread(this); |
| 893 | terminate->start(); |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 894 | return; |
| 895 | } |
| 896 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 897 | } |
| 898 | |
george82 | c7e9f79 | 2005-03-20 12:52:46 +0000 | [diff] [blame] | 899 | long ChoosePixelFormatDialog::pfIndex = DEFAULT_PF_INDEX; |
| 900 | bool ChoosePixelFormatDialog::bigEndian = false; |
| 901 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 902 | void RfbPlayer::serverInit() { |
| 903 | RfbProto::serverInit(); |
| 904 | |
george82 | b95503e | 2005-02-21 17:02:34 +0000 | [diff] [blame] | 905 | // Save the image data start time |
| 906 | imageDataStartTime = is->getTimeOffset(); |
| 907 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 908 | // Resize the backing buffer |
| 909 | buffer->setSize(cp.width, cp.height); |
| 910 | |
| 911 | // Check on the true colour mode |
| 912 | if (!(cp.pf()).trueColour) |
Peter Ã…strand | c81a652 | 2004-12-30 11:32:08 +0000 | [diff] [blame] | 913 | throw rdr::Exception("This version plays only true color session!"); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 914 | |
| 915 | // Set the session pixel format |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 916 | if (options.askPixelFormat) { |
george82 | c7e9f79 | 2005-03-20 12:52:46 +0000 | [diff] [blame] | 917 | ChoosePixelFormatDialog choosePixelFormatDialog(&supportedPF); |
george82 | d9957b7 | 2005-03-11 14:22:14 +0000 | [diff] [blame] | 918 | if (choosePixelFormatDialog.showDialog(getMainHandle())) { |
george82 | c7e9f79 | 2005-03-20 12:52:46 +0000 | [diff] [blame] | 919 | long pixelFormatIndex = choosePixelFormatDialog.getPFIndex(); |
george82 | 5a6df07 | 2005-03-20 09:56:17 +0000 | [diff] [blame] | 920 | if (pixelFormatIndex < 0) { |
| 921 | options.autoDetectPF = true; |
| 922 | options.setPF((PixelFormat *)&cp.pf()); |
| 923 | } else { |
| 924 | options.autoDetectPF = false; |
george82 | 1032686 | 2005-03-28 12:07:31 +0000 | [diff] [blame] | 925 | options.setPF(&supportedPF[pixelFormatIndex]->PF); |
george82 | c7e9f79 | 2005-03-20 12:52:46 +0000 | [diff] [blame] | 926 | options.pixelFormat.bigEndian = choosePixelFormatDialog.isBigEndian(); |
george82 | 5a6df07 | 2005-03-20 09:56:17 +0000 | [diff] [blame] | 927 | } |
george82 | 2c7634b | 2005-03-10 18:03:27 +0000 | [diff] [blame] | 928 | } else { |
| 929 | is->pausePlayback(); |
| 930 | throw rdr::Exception("[TERMINATE]"); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 931 | } |
| 932 | } else { |
george82 | dfb557b | 2005-03-21 18:26:50 +0000 | [diff] [blame] | 933 | if (!options.commandLineParam) { |
| 934 | if (options.autoDetectPF) { |
| 935 | options.setPF((PixelFormat *)&cp.pf()); |
| 936 | } else { |
george82 | 1032686 | 2005-03-28 12:07:31 +0000 | [diff] [blame] | 937 | options.setPF(&supportedPF[options.pixelFormatIndex]->PF); |
george82 | dfb557b | 2005-03-21 18:26:50 +0000 | [diff] [blame] | 938 | options.pixelFormat.bigEndian = options.bigEndianFlag; |
| 939 | } |
george82 | 5a6df07 | 2005-03-20 09:56:17 +0000 | [diff] [blame] | 940 | } |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 941 | } |
george82 | 5a6df07 | 2005-03-20 09:56:17 +0000 | [diff] [blame] | 942 | cp.setPF(options.pixelFormat); |
| 943 | buffer->setPF(options.pixelFormat); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 944 | |
| 945 | // If the window is not maximised then resize it |
| 946 | if (!(GetWindowLong(getMainHandle(), GWL_STYLE) & WS_MAXIMIZE)) |
| 947 | setFrameSize(cp.width, cp.height); |
| 948 | |
| 949 | // Set the window title and show it |
| 950 | setTitle(cp.name()); |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 951 | |
george82 | d4d69e6 | 2005-02-05 09:23:18 +0000 | [diff] [blame] | 952 | // Calculate the full session time and update posTrackBar control |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 953 | sessionTimeMs = calculateSessionTime(fileName); |
| 954 | sprintf(fullSessionTime, "%.2um:%.2us", |
| 955 | sessionTimeMs / 1000 / 60, sessionTimeMs / 1000 % 60); |
george82 | d4d69e6 | 2005-02-05 09:23:18 +0000 | [diff] [blame] | 956 | SendMessage(posTrackBar, TBM_SETRANGE, |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 957 | TRUE, MAKELONG(0, min(sessionTimeMs / 1000, MAX_POS_TRACKBAR_RANGE))); |
| 958 | sliderStepMs = sessionTimeMs / SendMessage(posTrackBar, TBM_GETRANGEMAX, 0, 0); |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 959 | updatePos(getTimeOffset()); |
george82 | d4d69e6 | 2005-02-05 09:23:18 +0000 | [diff] [blame] | 960 | |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 961 | setPaused(!options.autoPlay); |
| 962 | // Restore the parameters from registry, |
| 963 | // which was replaced by command-line parameters. |
george82 | dfb557b | 2005-03-21 18:26:50 +0000 | [diff] [blame] | 964 | if (options.commandLineParam) { |
| 965 | options.readFromRegistry(); |
| 966 | options.commandLineParam = false; |
| 967 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | void RfbPlayer::setColourMapEntries(int first, int count, U16* rgbs) { |
| 971 | vlog.debug("setColourMapEntries: first=%d, count=%d", first, count); |
| 972 | throw rdr::Exception("Can't handle SetColourMapEntries message", "RfbPlayer"); |
| 973 | /* int i; |
| 974 | for (i=0;i<count;i++) { |
| 975 | buffer->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]); |
| 976 | } |
| 977 | // *** change to 0, 256? |
| 978 | refreshWindowPalette(first, count); |
| 979 | palette_changed = true; |
| 980 | InvalidateRect(getFrameHandle(), 0, FALSE);*/ |
| 981 | } |
| 982 | |
| 983 | void RfbPlayer::bell() { |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 984 | if (options.acceptBell) |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 985 | MessageBeep(-1); |
| 986 | } |
| 987 | |
| 988 | void RfbPlayer::serverCutText(const char* str, int len) { |
| 989 | if (cutText != NULL) |
| 990 | delete [] cutText; |
| 991 | cutText = new char[len + 1]; |
| 992 | memcpy(cutText, str, len); |
| 993 | cutText[len] = '\0'; |
| 994 | } |
| 995 | |
| 996 | void RfbPlayer::frameBufferUpdateEnd() { |
| 997 | }; |
| 998 | |
| 999 | void RfbPlayer::beginRect(const Rect& r, unsigned int encoding) { |
| 1000 | } |
| 1001 | |
| 1002 | void RfbPlayer::endRect(const Rect& r, unsigned int encoding) { |
| 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | void RfbPlayer::fillRect(const Rect& r, Pixel pix) { |
| 1007 | buffer->fillRect(r, pix); |
| 1008 | invalidateBufferRect(r); |
| 1009 | } |
| 1010 | |
| 1011 | void RfbPlayer::imageRect(const Rect& r, void* pixels) { |
| 1012 | buffer->imageRect(r, pixels); |
| 1013 | invalidateBufferRect(r); |
| 1014 | } |
| 1015 | |
| 1016 | void RfbPlayer::copyRect(const Rect& r, int srcX, int srcY) { |
| 1017 | buffer->copyRect(r, Point(r.tl.x-srcX, r.tl.y-srcY)); |
| 1018 | invalidateBufferRect(r); |
| 1019 | } |
| 1020 | |
| 1021 | bool RfbPlayer::invalidateBufferRect(const Rect& crect) { |
| 1022 | Rect rect = bufferToClient(crect); |
| 1023 | if (rect.intersect(client_size).is_empty()) return false; |
| 1024 | RECT invalid = {rect.tl.x, rect.tl.y, rect.br.x, rect.br.y}; |
| 1025 | InvalidateRect(getFrameHandle(), &invalid, FALSE); |
| 1026 | return true; |
| 1027 | } |
| 1028 | |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 1029 | bool RfbPlayer::waitWhilePaused() { |
| 1030 | bool result = false; |
| 1031 | while(isPaused() && !isSeeking()) { |
| 1032 | Sleep(20); |
| 1033 | result = true; |
| 1034 | } |
| 1035 | return result; |
| 1036 | } |
| 1037 | |
george82 | 57f1352 | 2005-02-05 08:48:22 +0000 | [diff] [blame] | 1038 | long RfbPlayer::calculateSessionTime(char *filename) { |
| 1039 | FbsInputStream sessionFile(filename); |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 1040 | sessionFile.setTimeOffset(100000000); |
george82 | 57f1352 | 2005-02-05 08:48:22 +0000 | [diff] [blame] | 1041 | try { |
| 1042 | while (TRUE) { |
| 1043 | sessionFile.skip(1024); |
| 1044 | } |
| 1045 | } catch (rdr::Exception e) { |
| 1046 | if (strcmp(e.str(), "[End Of File]") == 0) { |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 1047 | return sessionFile.getTimeOffset(); |
george82 | 57f1352 | 2005-02-05 08:48:22 +0000 | [diff] [blame] | 1048 | } else { |
| 1049 | MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR); |
| 1050 | return 0; |
| 1051 | } |
| 1052 | } |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
george82 | 6b87aff | 2005-02-13 10:48:21 +0000 | [diff] [blame] | 1056 | void RfbPlayer::closeSessionFile() { |
| 1057 | char speedStr[10]; |
george82 | 0bdb284 | 2005-02-19 13:17:58 +0000 | [diff] [blame] | 1058 | DWORD dwStyle; |
george82 | 6b87aff | 2005-02-13 10:48:21 +0000 | [diff] [blame] | 1059 | RECT r; |
| 1060 | |
| 1061 | // Uncheck all toolbar buttons |
| 1062 | if (tb.getHandle()) { |
| 1063 | tb.checkButton(ID_PLAY, false); |
| 1064 | tb.checkButton(ID_PAUSE, false); |
| 1065 | tb.checkButton(ID_STOP, false); |
| 1066 | } |
| 1067 | |
| 1068 | // Stop playback and update the player state |
| 1069 | disableTBandMenuItems(); |
| 1070 | if (rfbReader) { |
| 1071 | delete rfbReader->join(); |
| 1072 | rfbReader = 0; |
| 1073 | delete [] fileName; |
| 1074 | fileName = 0; |
| 1075 | } |
| 1076 | blankBuffer(); |
| 1077 | setTitle("None"); |
george82 | 7009c89 | 2005-02-19 12:49:42 +0000 | [diff] [blame] | 1078 | SetWindowText(timeStatic,"00m:00s (00m:00s)"); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1079 | options.playbackSpeed = 1.0; |
george82 | 6b87aff | 2005-02-13 10:48:21 +0000 | [diff] [blame] | 1080 | SendMessage(speedUpDown, UDM_SETPOS, |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1081 | 0, MAKELONG((short)(options.playbackSpeed / 0.5), 0)); |
| 1082 | sprintf(speedStr, "%.2f", options.playbackSpeed); |
george82 | 6b87aff | 2005-02-13 10:48:21 +0000 | [diff] [blame] | 1083 | SetWindowText(speedEdit, speedStr); |
| 1084 | SendMessage(posTrackBar, TBM_SETRANGE, TRUE, MAKELONG(0, 0)); |
| 1085 | |
| 1086 | // Change the player window size and frame size to default |
george82 | 0bdb284 | 2005-02-19 13:17:58 +0000 | [diff] [blame] | 1087 | if ((dwStyle = GetWindowLong(getMainHandle(), GWL_STYLE)) & WS_MAXIMIZE) { |
| 1088 | dwStyle &= ~WS_MAXIMIZE; |
| 1089 | SetWindowLong(getMainHandle(), GWL_STYLE, dwStyle); |
| 1090 | } |
george82 | 2ff7a61 | 2005-02-19 17:05:24 +0000 | [diff] [blame] | 1091 | int x = max(0, (GetSystemMetrics(SM_CXSCREEN) - DEFAULT_PLAYER_WIDTH) / 2); |
| 1092 | int y = max(0, (GetSystemMetrics(SM_CYSCREEN) - DEFAULT_PLAYER_HEIGHT) / 2); |
| 1093 | SetWindowPos(getMainHandle(), 0, x, y, |
george82 | 6b87aff | 2005-02-13 10:48:21 +0000 | [diff] [blame] | 1094 | DEFAULT_PLAYER_WIDTH, DEFAULT_PLAYER_HEIGHT, |
george82 | 2ff7a61 | 2005-02-19 17:05:24 +0000 | [diff] [blame] | 1095 | SWP_NOZORDER | SWP_FRAMECHANGED); |
george82 | 6b87aff | 2005-02-13 10:48:21 +0000 | [diff] [blame] | 1096 | buffer->setSize(32, 32); |
| 1097 | calculateScrollBars(); |
| 1098 | |
| 1099 | // Update the cached sizing information and repaint the frame window |
| 1100 | GetWindowRect(getFrameHandle(), &r); |
| 1101 | window_size = Rect(r.left, r.top, r.right, r.bottom); |
| 1102 | GetClientRect(getFrameHandle(), &r); |
| 1103 | client_size = Rect(r.left, r.top, r.right, r.bottom); |
| 1104 | InvalidateRect(getFrameHandle(), 0, TRUE); |
| 1105 | UpdateWindow(getFrameHandle()); |
| 1106 | } |
| 1107 | |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 1108 | void RfbPlayer::openSessionFile(char *_fileName) { |
| 1109 | fileName = strDup(_fileName); |
| 1110 | |
| 1111 | // Close the previous reading thread |
| 1112 | if (rfbReader) { |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 1113 | delete rfbReader->join(); |
george82 | b4f969b | 2005-02-09 16:34:51 +0000 | [diff] [blame] | 1114 | rfbReader = 0; |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 1115 | } |
| 1116 | blankBuffer(); |
| 1117 | newSession(fileName); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1118 | setSpeed(options.playbackSpeed); |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 1119 | rfbReader = new rfbSessionReader(this); |
| 1120 | rfbReader->start(); |
george82 | 6e51fcc | 2005-02-06 13:30:49 +0000 | [diff] [blame] | 1121 | SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0); |
george82 | 63ebbcc | 2005-02-12 12:09:13 +0000 | [diff] [blame] | 1122 | enableTBandMenuItems(); |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1125 | void RfbPlayer::setPaused(bool paused) { |
| 1126 | if (paused) { |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1127 | is->pausePlayback(); |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 1128 | tb.checkButton(ID_PAUSE, true); |
| 1129 | tb.checkButton(ID_PLAY, false); |
| 1130 | tb.checkButton(ID_STOP, false); |
| 1131 | CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED); |
| 1132 | CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1133 | } else { |
george82 | 5beb62a | 2005-02-09 13:04:32 +0000 | [diff] [blame] | 1134 | if (is) is->resumePlayback(); |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 1135 | tb.checkButton(ID_PLAY, true); |
| 1136 | tb.checkButton(ID_STOP, false); |
| 1137 | tb.checkButton(ID_PAUSE, false); |
| 1138 | CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_CHECKED); |
| 1139 | CheckMenuItem(hMenu, ID_STOP, MF_UNCHECKED); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 1143 | void RfbPlayer::stopPlayback() { |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 1144 | stopped = true; |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 1145 | setPos(0); |
george82 | 8edfb7a | 2005-03-03 16:36:10 +0000 | [diff] [blame] | 1146 | if (is) { |
| 1147 | is->pausePlayback(); |
| 1148 | is->interruptFrameDelay(); |
| 1149 | } |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 1150 | tb.checkButton(ID_STOP, true); |
| 1151 | tb.checkButton(ID_PLAY, false); |
| 1152 | tb.checkButton(ID_PAUSE, false); |
| 1153 | CheckMenuItem(hMenu, ID_STOP, MF_CHECKED); |
| 1154 | CheckMenuItem(hMenu, ID_PLAYPAUSE, MF_UNCHECKED); |
george82 | 6da02d7 | 2005-02-06 17:02:34 +0000 | [diff] [blame] | 1155 | SendMessage(posTrackBar, TBM_SETPOS, TRUE, 0); |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1158 | void RfbPlayer::setSpeed(double speed) { |
george82 | 5f326fe | 2005-02-20 08:01:01 +0000 | [diff] [blame] | 1159 | if (speed > 0) { |
| 1160 | char speedStr[20] = "\0"; |
| 1161 | double newSpeed = min(speed, MAX_SPEED); |
george82 | 5f326fe | 2005-02-20 08:01:01 +0000 | [diff] [blame] | 1162 | is->setSpeed(newSpeed); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1163 | options.playbackSpeed = newSpeed; |
george82 | 5f326fe | 2005-02-20 08:01:01 +0000 | [diff] [blame] | 1164 | SendMessage(speedUpDown, UDM_SETPOS, |
| 1165 | 0, MAKELONG((short)(newSpeed / 0.5), 0)); |
| 1166 | sprintf(speedStr, "%.2f", newSpeed); |
| 1167 | SetWindowText(speedEdit, speedStr); |
| 1168 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | double RfbPlayer::getSpeed() { |
| 1172 | return is->getSpeed(); |
| 1173 | } |
| 1174 | |
| 1175 | void RfbPlayer::setPos(long pos) { |
george82 | b95503e | 2005-02-21 17:02:34 +0000 | [diff] [blame] | 1176 | is->setTimeOffset(max(pos, imageDataStartTime)); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | long RfbPlayer::getSeekOffset() { |
| 1180 | return is->getSeekOffset(); |
| 1181 | } |
| 1182 | |
| 1183 | bool RfbPlayer::isSeeking() { |
george82 | 5beb62a | 2005-02-09 13:04:32 +0000 | [diff] [blame] | 1184 | if (is) return is->isSeeking(); |
| 1185 | else return false; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | bool RfbPlayer::isSeekMode() { |
| 1189 | return seekMode; |
| 1190 | } |
| 1191 | |
| 1192 | bool RfbPlayer::isPaused() { |
| 1193 | return is->isPaused(); |
| 1194 | } |
| 1195 | |
| 1196 | long RfbPlayer::getTimeOffset() { |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 1197 | return max(is->getTimeOffset(), is->getSeekOffset()); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 1200 | void RfbPlayer::updatePos(long newPos) { |
| 1201 | // Update time pos in static control |
george82 | 3c8fbbf | 2005-01-24 11:09:08 +0000 | [diff] [blame] | 1202 | char timePos[30] = "\0"; |
george82 | 5457d41 | 2005-02-19 06:43:09 +0000 | [diff] [blame] | 1203 | long time = newPos / 1000; |
| 1204 | sprintf(timePos, "%.2um:%.2us (%s)", time/60, time%60, fullSessionTime); |
george82 | 3c8fbbf | 2005-01-24 11:09:08 +0000 | [diff] [blame] | 1205 | SetWindowText(timeStatic, timePos); |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 1206 | |
| 1207 | // Update the position of slider |
| 1208 | if (!sliderDraging) { |
george82 | 5457d41 | 2005-02-19 06:43:09 +0000 | [diff] [blame] | 1209 | double error = SendMessage(posTrackBar, TBM_GETPOS, 0, 0) * |
| 1210 | sliderStepMs / double(newPos); |
| 1211 | if (!((error > 1 - CALCULATION_ERROR) && (error <= 1 + CALCULATION_ERROR))) { |
| 1212 | SendMessage(posTrackBar, TBM_SETPOS, TRUE, newPos / sliderStepMs); |
| 1213 | } |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 1214 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | void RfbPlayer::skipHandshaking() { |
| 1218 | int skipBytes = 12 + 4 + 24 + strlen(cp.name()); |
| 1219 | is->skip(skipBytes); |
| 1220 | state_ = RFBSTATE_NORMAL; |
| 1221 | } |
| 1222 | |
| 1223 | void programInfo() { |
| 1224 | win32::FileVersionInfo inf; |
| 1225 | _tprintf(_T("%s - %s, Version %s\n"), |
| 1226 | inf.getVerString(_T("ProductName")), |
| 1227 | inf.getVerString(_T("FileDescription")), |
| 1228 | inf.getVerString(_T("FileVersion"))); |
| 1229 | printf("%s\n", buildTime); |
| 1230 | _tprintf(_T("%s\n\n"), inf.getVerString(_T("LegalCopyright"))); |
| 1231 | } |
| 1232 | |
| 1233 | void programUsage() { |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 1234 | MessageBox(0, usage_msg, "RfbPlayer", MB_OK | MB_ICONINFORMATION); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
george82 | 5beb62a | 2005-02-09 13:04:32 +0000 | [diff] [blame] | 1237 | char *fileName = 0; |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1238 | |
| 1239 | // playerOptions is the player options with default parameters values, |
| 1240 | // it is used only for run the player with command-line parameters |
| 1241 | PlayerOptions playerOptions; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1242 | bool print_usage = false; |
george82 | 05d8623 | 2005-03-28 12:16:08 +0000 | [diff] [blame^] | 1243 | bool print_upf_list = false; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1244 | |
| 1245 | bool processParams(int argc, char* argv[]) { |
george82 | dfb557b | 2005-03-21 18:26:50 +0000 | [diff] [blame] | 1246 | playerOptions.commandLineParam = true; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1247 | for (int i = 1; i < argc; i++) { |
| 1248 | if ((strcasecmp(argv[i], "-help") == 0) || |
| 1249 | (strcasecmp(argv[i], "--help") == 0) || |
| 1250 | (strcasecmp(argv[i], "/help") == 0) || |
| 1251 | (strcasecmp(argv[i], "-h") == 0) || |
| 1252 | (strcasecmp(argv[i], "/h") == 0) || |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 1253 | (strcasecmp(argv[i], "/?") == 0) || |
| 1254 | (strcasecmp(argv[i], "-?") == 0)) { |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1255 | print_usage = true; |
| 1256 | return true; |
| 1257 | } |
| 1258 | |
george82 | 5caee41 | 2005-03-09 09:52:10 +0000 | [diff] [blame] | 1259 | if ((strcasecmp(argv[i], "-pf") == 0) || |
| 1260 | (strcasecmp(argv[i], "/pf") == 0) && (i < argc-1)) { |
george82 | dfb557b | 2005-03-21 18:26:50 +0000 | [diff] [blame] | 1261 | char *pf = argv[++i]; |
| 1262 | char rgb_order[4] = "\0"; |
| 1263 | int order = RGB_ORDER; |
| 1264 | int r = -1, g = -1, b = -1; |
| 1265 | bool big_endian = false; |
| 1266 | if (strlen(pf) < 6) return false; |
| 1267 | while (strlen(pf)) { |
| 1268 | if ((pf[0] == 'r') || (pf[0] == 'R')) { |
| 1269 | if (r >=0 ) return false; |
| 1270 | r = atoi(++pf); |
| 1271 | strcat(rgb_order, "r"); |
| 1272 | continue; |
| 1273 | } |
| 1274 | if ((pf[0] == 'g') || (pf[0] == 'G')) { |
| 1275 | if (g >=0 ) return false; |
| 1276 | g = atoi(++pf); |
| 1277 | strcat(rgb_order, "g"); |
| 1278 | continue; |
| 1279 | } |
| 1280 | if (((pf[0] == 'b') || (pf[0] == 'B')) && |
| 1281 | (pf[1] != 'e') && (pf[1] != 'E')) { |
| 1282 | if (b >=0 ) return false; |
| 1283 | b = atoi(++pf); |
| 1284 | strcat(rgb_order, "b"); |
| 1285 | continue; |
| 1286 | } |
| 1287 | if ((pf[0] == 'l') || (pf[0] == 'L') || |
| 1288 | (pf[0] == 'b') || (pf[0] == 'B')) { |
| 1289 | if (strcasecmp(pf, "le") == 0) break; |
| 1290 | if (strcasecmp(pf, "be") == 0) { big_endian = true; break;} |
| 1291 | return false; |
| 1292 | } |
| 1293 | pf++; |
george82 | 193d8e4 | 2005-02-20 16:47:01 +0000 | [diff] [blame] | 1294 | } |
george82 | 888b8fb | 2005-03-22 15:02:39 +0000 | [diff] [blame] | 1295 | if ((r < 0) || (g < 0) || (b < 0) || (r + g + b > 32)) return false; |
george82 | dfb557b | 2005-03-21 18:26:50 +0000 | [diff] [blame] | 1296 | if (strcasecmp(rgb_order, "rgb") == 0) { order = RGB_ORDER; } |
| 1297 | else if (strcasecmp(rgb_order, "rbg") == 0) { order = RBG_ORDER; } |
| 1298 | else if (strcasecmp(rgb_order, "grb") == 0) { order = GRB_ORDER; } |
| 1299 | else if (strcasecmp(rgb_order, "gbr") == 0) { order = GBR_ORDER; } |
| 1300 | else if (strcasecmp(rgb_order, "bgr") == 0) { order = BGR_ORDER; } |
| 1301 | else if (strcasecmp(rgb_order, "brg") == 0) { order = BRG_ORDER; } |
| 1302 | else return false; |
| 1303 | playerOptions.autoDetectPF = false; |
| 1304 | playerOptions.setPF(order, r, g, b, big_endian); |
george82 | 193d8e4 | 2005-02-20 16:47:01 +0000 | [diff] [blame] | 1305 | continue; |
| 1306 | } |
| 1307 | |
george82 | 05d8623 | 2005-03-28 12:16:08 +0000 | [diff] [blame^] | 1308 | if ((strcasecmp(argv[i], "-upf") == 0) || |
| 1309 | (strcasecmp(argv[i], "/upf") == 0) && (i < argc-1)) { |
| 1310 | if ((i == argc - 1) || (argv[++i][0] == '-')) { |
| 1311 | print_upf_list = true; |
| 1312 | return true; |
| 1313 | } |
| 1314 | PixelFormatList userPfList; |
| 1315 | userPfList.readUserDefinedPF(HKEY_CURRENT_USER, UPF_REGISTRY_PATH); |
| 1316 | int index = userPfList.getIndexByPFName(argv[i]); |
| 1317 | if (index > 0) { |
| 1318 | playerOptions.autoDetectPF = false; |
| 1319 | playerOptions.setPF(&userPfList[index]->PF); |
| 1320 | } else { |
| 1321 | return false; |
| 1322 | } |
| 1323 | continue; |
| 1324 | } |
george82 | 193d8e4 | 2005-02-20 16:47:01 +0000 | [diff] [blame] | 1325 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1326 | if ((strcasecmp(argv[i], "-speed") == 0) || |
| 1327 | (strcasecmp(argv[i], "/speed") == 0) && (i < argc-1)) { |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1328 | double playbackSpeed = atof(argv[++i]); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1329 | if (playbackSpeed <= 0) { |
| 1330 | return false; |
| 1331 | } |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1332 | playerOptions.playbackSpeed = playbackSpeed; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1333 | continue; |
| 1334 | } |
| 1335 | |
| 1336 | if ((strcasecmp(argv[i], "-pos") == 0) || |
| 1337 | (strcasecmp(argv[i], "/pos") == 0) && (i < argc-1)) { |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1338 | long initTime = atol(argv[++i]); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1339 | if (initTime <= 0) |
| 1340 | return false; |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1341 | playerOptions.initTime = initTime; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1342 | continue; |
| 1343 | } |
| 1344 | |
| 1345 | if ((strcasecmp(argv[i], "-autoplay") == 0) || |
| 1346 | (strcasecmp(argv[i], "/autoplay") == 0) && (i < argc-1)) { |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1347 | playerOptions.autoPlay = true; |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 1348 | continue; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | if (i != argc - 1) |
| 1352 | return false; |
| 1353 | } |
| 1354 | |
| 1355 | fileName = strDup(argv[argc-1]); |
| 1356 | return true; |
| 1357 | } |
| 1358 | |
| 1359 | // |
| 1360 | // -=- WinMain |
| 1361 | // |
| 1362 | |
| 1363 | int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, char* cmdLine, int cmdShow) { |
| 1364 | |
| 1365 | // - Process the command-line |
| 1366 | |
| 1367 | int argc = __argc; |
| 1368 | char** argv = __argv; |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 1369 | if ((argc > 1) && (!processParams(argc, argv))) { |
| 1370 | MessageBox(0, wrong_cmd_msg, "RfbPlayer", MB_OK | MB_ICONWARNING); |
| 1371 | return 0; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1372 | } |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 1373 | |
| 1374 | if (print_usage) { |
| 1375 | programUsage(); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1376 | return 0; |
george82 | 67cbcd0 | 2005-01-16 15:39:56 +0000 | [diff] [blame] | 1377 | } |
george82 | 05d8623 | 2005-03-28 12:16:08 +0000 | [diff] [blame^] | 1378 | // Show the user defined pixel formats if required |
| 1379 | if (print_upf_list) { |
| 1380 | int list_size = 45; |
| 1381 | char *upf_list = new char[list_size]; |
| 1382 | PixelFormatList userPfList; |
| 1383 | userPfList.readUserDefinedPF(HKEY_CURRENT_USER, UPF_REGISTRY_PATH); |
| 1384 | strcpy(upf_list, "The list of the user defined pixel formats:\n"); |
| 1385 | for (int i = userPfList.getDefaultPFCount(); i < userPfList.count(); i++) { |
| 1386 | if ((list_size - strlen(upf_list) - 1) < |
| 1387 | (strlen(userPfList[i]->format_name) + 2)) { |
| 1388 | char *tmpStr = new char[list_size = |
| 1389 | list_size + strlen(userPfList[i]->format_name) + 2]; |
| 1390 | strcpy(tmpStr, upf_list); |
| 1391 | delete [] upf_list; |
| 1392 | upf_list = new char[list_size]; |
| 1393 | strcpy(upf_list, tmpStr); |
| 1394 | delete [] tmpStr; |
| 1395 | } |
| 1396 | strcat(upf_list, userPfList[i]->format_name); |
| 1397 | strcat(upf_list, "\n"); |
| 1398 | } |
| 1399 | MessageBox(0, upf_list, "RfbPlayer", MB_OK | MB_ICONINFORMATION); |
| 1400 | delete [] upf_list; |
| 1401 | return 0; |
| 1402 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1403 | |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 1404 | // Create the player |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1405 | RfbPlayer *player = NULL; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1406 | try { |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1407 | player = new RfbPlayer(fileName, &playerOptions); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1408 | } catch (rdr::Exception e) { |
| 1409 | MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR); |
| 1410 | delete player; |
| 1411 | return 0; |
| 1412 | } |
| 1413 | |
| 1414 | // Run the player |
george82 | 5bbd61b | 2004-12-09 17:47:37 +0000 | [diff] [blame] | 1415 | HACCEL hAccel = LoadAccelerators(inst, MAKEINTRESOURCE(IDR_ACCELERATOR)); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1416 | MSG msg; |
| 1417 | while (GetMessage(&msg, NULL, 0, 0) > 0) { |
george82 | 5bbd61b | 2004-12-09 17:47:37 +0000 | [diff] [blame] | 1418 | if(!TranslateAccelerator(player->getMainHandle(), hAccel, &msg)) { |
| 1419 | TranslateMessage(&msg); |
| 1420 | DispatchMessage(&msg); |
| 1421 | } |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
george82 | e6883de | 2005-02-08 14:42:12 +0000 | [diff] [blame] | 1424 | // Destroy the player |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1425 | try{ |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1426 | if (player) delete player; |
| 1427 | } catch (rdr::Exception e) { |
| 1428 | MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR); |
| 1429 | } |
| 1430 | |
| 1431 | return 0; |
| 1432 | }; |