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