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