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