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