Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. 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 | // -=- DesktopWindow.h |
| 20 | |
| 21 | // Each VNC connection instance (CConn) creates a DesktopWindow the |
| 22 | // server initialisation message has been received. The CConn is |
| 23 | // responsible for all RFB-specific and network issues. The |
| 24 | // DesktopWindow is responsible for all GUI management issues. |
| 25 | // |
| 26 | // DesktopWindow provides a FullFramePixelBuffer interface for the |
| 27 | // CConn to render updates into. It also requires a callback object |
| 28 | // to be supplied, which will be notified when various events occur. |
| 29 | |
| 30 | #ifndef __RFB_WIN32_DESKTOP_WINDOW_H__ |
| 31 | #define __RFB_WIN32_DESKTOP_WINDOW_H__ |
| 32 | |
| 33 | #include <rfb/Cursor.h> |
| 34 | #include <rfb_win32/CKeyboard.h> |
| 35 | #include <rfb_win32/CPointer.h> |
| 36 | #include <rfb_win32/Clipboard.h> |
| 37 | #include <rfb_win32/ScaledDIBSectionBuffer.h> |
| 38 | #include <rfb_win32/LogicalPalette.h> |
| 39 | #include <vncviewer/ViewerToolBar.h> |
| 40 | |
| 41 | |
| 42 | namespace rfb { |
| 43 | |
| 44 | namespace win32 { |
| 45 | |
| 46 | class DesktopWindow : rfb::win32::Clipboard::Notifier { |
| 47 | public: |
| 48 | class Callback; |
| 49 | |
| 50 | DesktopWindow(Callback* cb_); |
| 51 | ~DesktopWindow(); |
| 52 | |
| 53 | // - Window message handling procedure |
| 54 | LRESULT processMessage(UINT msg, WPARAM wParam, LPARAM lParam); |
| 55 | |
| 56 | // - Window message handling procedure for the framebuffer window |
| 57 | LRESULT processFrameMessage(UINT msg, WPARAM wParam, LPARAM lParam); |
| 58 | |
Constantin Kaplinsky | d5f5927 | 2006-09-14 05:14:43 +0000 | [diff] [blame] | 59 | // - Separate message handling procedure for mouse events |
| 60 | // It's called from both processMessage() and processFrameMessage() |
| 61 | void processMouseMessage(UINT msg, WPARAM wParam, LPARAM lParam); |
| 62 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 63 | // - Determine the native pixel format of the window |
| 64 | // This can (and often will) differ from the PixelBuffer format |
| 65 | PixelFormat getNativePF() const; |
| 66 | |
| 67 | // - Get the underlying window handle |
| 68 | // This is used by F8Menu to modify the window's menu |
| 69 | HWND getHandle() const {return handle;} |
| 70 | |
| 71 | // - Get the framebuffer window handle |
| 72 | HWND getFrameHandle() const {return frameHandle;} |
| 73 | |
| 74 | // - Set the window title |
| 75 | void setName(const char* name); |
| 76 | |
| 77 | // - Set the key that causes the system/F8 menu to be displayed |
| 78 | void setMenuKey(rdr::U8 key) { menuKey = key; } |
| 79 | |
| 80 | // - Pointer event handling |
| 81 | void setEmulate3(bool em3) { ptr.enableEmulate3(em3); } |
| 82 | void setPointerEventInterval(int interval) { ptr.enableInterval(interval); } |
| 83 | |
| 84 | // - Set the pixel format, size etc of the underlying PixelBuffer |
| 85 | void setPF(const PixelFormat& pf); |
george82 | 7c721cc | 2006-09-23 07:09:37 +0000 | [diff] [blame] | 86 | PixelFormat getPF() const { return buffer->getPixelFormat(); } |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 87 | void setSize(int w, int h); |
| 88 | void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);} |
george82 | 74ea5f3 | 2006-09-11 11:40:12 +0000 | [diff] [blame] | 89 | void setAutoScaling(bool as); |
george82 | ffc14a6 | 2006-09-05 06:51:41 +0000 | [diff] [blame] | 90 | bool isAutoScaling() const { return autoScaling; } |
george82 | 2446ed0 | 2007-03-10 08:55:35 +0000 | [diff] [blame] | 91 | void setDesktopScale(int scale); |
george82 | b6d87aa | 2006-09-11 07:00:59 +0000 | [diff] [blame] | 92 | int getDesktopScale() const { return buffer->getScale(); } |
george82 | c4eb626 | 2007-03-20 10:54:38 +0000 | [diff] [blame] | 93 | void setDesktopScaleFilter(unsigned int scaleFilterID); |
| 94 | unsigned int getDesktopScaleFilterID() const { return buffer->getScaleFilterID(); } |
george82 | 3c68f5f | 2006-09-05 06:17:01 +0000 | [diff] [blame] | 95 | void fitBufferToWindow(bool repaint = true); |
george82 | 770bbbc | 2007-03-12 10:48:09 +0000 | [diff] [blame] | 96 | void printScale(); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 97 | |
| 98 | // - Set the cursor to render when the pointer is within the desktop buffer |
| 99 | void setCursor(int w, int h, const Point& hotspot, void* data, void* mask); |
| 100 | void showCursor() { showLocalCursor(); } |
george82 | 4880eec | 2007-03-19 10:55:13 +0000 | [diff] [blame] | 101 | void convertCursorToBuffer(); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 102 | |
| 103 | // - Set the window fullscreen / determine whether it is fullscreen |
| 104 | void setFullscreen(bool fs); |
| 105 | bool isFullscreen() { return fullscreenActive; } |
| 106 | |
| 107 | // - Set/get the toolbar's state |
| 108 | void setShowToolbar(bool st); |
| 109 | bool isToolbarEnabled() { return showToolbar; } |
george82 | 74ea5f3 | 2006-09-11 11:40:12 +0000 | [diff] [blame] | 110 | void refreshToolbarButtons(); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 111 | |
| 112 | // - Set whether to disable special Windows keys & pass them straight to server |
| 113 | void setDisableWinKeys(bool dwk); |
| 114 | |
| 115 | // - Set/get which monitor the window should be displayed on |
| 116 | void setMonitor(const char* monitor); |
| 117 | char* getMonitor() const; |
| 118 | |
| 119 | // - Set the local clipboard |
Adam Tkac | acf6c6b | 2009-02-13 12:42:05 +0000 | [diff] [blame] | 120 | void serverCutText(const char* str, rdr::U32 len); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 121 | |
Pierre Ossman | b2ff160 | 2009-03-25 12:13:28 +0000 | [diff] [blame] | 122 | // - Completion of one FramebufferUpdate |
| 123 | void framebufferUpdateEnd(); |
| 124 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 125 | // - Draw into the desktop buffer & update the window |
| 126 | void fillRect(const Rect& r, Pixel pix); |
| 127 | void imageRect(const Rect& r, void* pixels); |
| 128 | void copyRect(const Rect& r, int srcX, int srcY); |
| 129 | |
| 130 | void invertRect(const Rect& r); |
| 131 | |
| 132 | // - Update the window palette if the display is palette-based. |
| 133 | // Colours are pulled from the desktop buffer's ColourMap. |
| 134 | // Only the specified range of indexes is dealt with. |
| 135 | // After the update, the entire window is redrawn. |
| 136 | void refreshWindowPalette(int start, int count); |
| 137 | |
| 138 | // Clipboard::Notifier interface |
| 139 | void notifyClipboardChanged(const char* text, int len); |
| 140 | |
| 141 | // DesktopWindow Callback interface |
| 142 | class Callback : public InputHandler { |
| 143 | public: |
| 144 | virtual ~Callback() {} |
| 145 | virtual void displayChanged() = 0; |
| 146 | virtual void paintCompleted() = 0; |
| 147 | virtual bool sysCommand(WPARAM wParam, LPARAM lParam) = 0; |
| 148 | virtual void closeWindow() = 0; |
| 149 | virtual void refreshMenu(bool enableSysItems) = 0; |
| 150 | }; |
| 151 | |
george82 | fd334ad | 2006-05-29 14:05:20 +0000 | [diff] [blame] | 152 | Callback *getCallback() const { return callback; } |
| 153 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 154 | // Currently accessible so that the CConn can releaseAllKeys & check |
| 155 | // whether Ctrl and Alt are down... |
| 156 | rfb::win32::CKeyboard kbd; |
| 157 | |
| 158 | protected: |
| 159 | // Routines to convert between Desktop and client (window) coordinates |
| 160 | Point desktopToClient(const Point& p) { |
| 161 | Point pos = p; |
| 162 | if (client_size.width() > buffer->width()) |
| 163 | pos.x += (client_size.width() - buffer->width()) / 2; |
| 164 | else if (client_size.width() < buffer->width()) |
| 165 | pos.x -= scrolloffset.x; |
| 166 | if (client_size.height() > buffer->height()) |
| 167 | pos.y += (client_size.height() - buffer->height()) / 2; |
| 168 | else if (client_size.height() < buffer->height()) |
| 169 | pos.y -= scrolloffset.y; |
| 170 | return pos; |
| 171 | } |
| 172 | Rect desktopToClient(const Rect& r) { |
| 173 | return Rect(desktopToClient(r.tl), desktopToClient(r.br)); |
| 174 | } |
| 175 | Point clientToDesktop(const Point& p) { |
| 176 | Point pos = p; |
| 177 | if (client_size.width() > buffer->width()) |
| 178 | pos.x -= (client_size.width() - buffer->width()) / 2; |
| 179 | else if (client_size.width() < buffer->width()) |
| 180 | pos.x += scrolloffset.x; |
| 181 | if (client_size.height() > buffer->height()) |
| 182 | pos.y -= (client_size.height() - buffer->height()) / 2; |
| 183 | else if (client_size.height() < buffer->height()) |
| 184 | pos.y += scrolloffset.y; |
| 185 | return pos; |
| 186 | } |
| 187 | Rect clientToDesktop(const Rect& r) { |
| 188 | return Rect(clientToDesktop(r.tl), clientToDesktop(r.br)); |
| 189 | } |
| 190 | |
| 191 | // Internal routine used by the scrollbars & bump scroller to select |
| 192 | // the portion of the Desktop to display |
| 193 | bool setViewportOffset(const Point& tl); |
| 194 | |
| 195 | // Bump scroll handling. Bump scrolling is used if the window is |
| 196 | // in fullscreen mode and the Desktop is larger than the window |
| 197 | bool processBumpScroll(const Point& cursorPos); |
| 198 | void setBumpScroll(bool on); |
| 199 | bool bumpScroll; |
| 200 | Point bumpScrollDelta; |
| 201 | IntervalTimer bumpScrollTimer; |
| 202 | |
Pierre Ossman | b2ff160 | 2009-03-25 12:13:28 +0000 | [diff] [blame] | 203 | // Track modified areas of the framebuffer |
| 204 | void updateWindow(); |
| 205 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 206 | // Locally-rendered VNC cursor |
| 207 | void hideLocalCursor(); |
| 208 | void showLocalCursor(); |
| 209 | void renderLocalCursor(); |
| 210 | |
| 211 | // The system-rendered cursor |
| 212 | void hideSystemCursor(); |
| 213 | void showSystemCursor(); |
| 214 | |
| 215 | // cursorOutsideBuffer() is called whenever we detect that the mouse has |
| 216 | // moved outside the desktop. It restores the system arrow cursor. |
| 217 | void cursorOutsideBuffer(); |
| 218 | |
| 219 | // Returns true if part of the supplied rect is visible, false otherwise |
| 220 | bool invalidateDesktopRect(const Rect& crect, bool scaling=true); |
| 221 | |
| 222 | // Determine whether or not we need to enable/disable scrollbars and set the |
| 223 | // window style accordingly |
| 224 | void calculateScrollBars(); |
| 225 | |
george82 | 858a464 | 2007-01-27 15:32:27 +0000 | [diff] [blame] | 226 | // Resizes the main window against the pixel buffer size |
| 227 | void resizeDesktopWindowToBuffer(); |
| 228 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 229 | // Win32-specific input handling |
| 230 | rfb::win32::CPointer ptr; |
| 231 | Point oldpos; |
| 232 | rfb::win32::Clipboard clipboard; |
| 233 | |
| 234 | // Palette handling |
| 235 | LogicalPalette windowPalette; |
| 236 | bool palette_changed; |
| 237 | |
| 238 | // - Full-screen mode |
| 239 | RECT fullscreenOldRect; |
| 240 | DWORD fullscreenOldFlags; |
| 241 | bool fullscreenActive; |
| 242 | bool fullscreenRestore; |
| 243 | |
Pierre Ossman | b2ff160 | 2009-03-25 12:13:28 +0000 | [diff] [blame] | 244 | // Damage tracking |
| 245 | rfb::Region damage; |
| 246 | IntervalTimer updateTimer; |
| 247 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 248 | // Cursor handling |
| 249 | Cursor cursor; |
| 250 | bool systemCursorVisible; // Should system-cursor be drawn? |
| 251 | bool trackingMouseLeave; |
| 252 | bool cursorInBuffer; // Is cursor position within server buffer? (ONLY for LocalCursor) |
| 253 | bool cursorVisible; // Is cursor currently rendered? |
| 254 | bool cursorAvailable; // Is cursor available for rendering? |
george82 | 4880eec | 2007-03-19 10:55:13 +0000 | [diff] [blame] | 255 | bool internalSetCursor; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 256 | Point cursorPos; |
| 257 | ManagedPixelBuffer cursorBacking; |
| 258 | Rect cursorBackingRect; |
george82 | 4880eec | 2007-03-19 10:55:13 +0000 | [diff] [blame] | 259 | U8 *cursorImage; |
| 260 | U8 *cursorMask; |
| 261 | int cursorWidth; |
| 262 | int cursorHeight; |
| 263 | Point cursorHotspot; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 264 | |
| 265 | // ToolBar handling |
| 266 | ViewerToolBar tb; |
| 267 | bool showToolbar; |
| 268 | |
george82 | e0569e4 | 2006-09-11 15:56:10 +0000 | [diff] [blame] | 269 | // Remote desktop name |
| 270 | char desktopName[255]; |
| 271 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 272 | // Local window state |
| 273 | win32::ScaledDIBSectionBuffer* buffer; |
george82 | 3c68f5f | 2006-09-05 06:17:01 +0000 | [diff] [blame] | 274 | double aspect_corr; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 275 | bool has_focus; |
george82 | ffc14a6 | 2006-09-05 06:51:41 +0000 | [diff] [blame] | 276 | bool autoScaling; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 277 | Rect window_size; |
| 278 | Rect client_size; |
| 279 | Point scrolloffset; |
| 280 | Point maxscrolloffset; |
| 281 | HWND handle; |
| 282 | HWND frameHandle; |
| 283 | rdr::U8 menuKey; |
| 284 | |
| 285 | Callback* callback; |
| 286 | }; |
| 287 | |
| 288 | }; |
| 289 | |
| 290 | }; |
| 291 | |
| 292 | #endif // __RFB_WIN32_DESKTOP_WINDOW_H__ |
| 293 | |
| 294 | |