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