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