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 |
| 120 | void serverCutText(const char* str, int len); |
| 121 | |
| 122 | // - Draw into the desktop buffer & update the window |
| 123 | void fillRect(const Rect& r, Pixel pix); |
| 124 | void imageRect(const Rect& r, void* pixels); |
| 125 | void copyRect(const Rect& r, int srcX, int srcY); |
| 126 | |
| 127 | void invertRect(const Rect& r); |
| 128 | |
| 129 | // - Update the window palette if the display is palette-based. |
| 130 | // Colours are pulled from the desktop buffer's ColourMap. |
| 131 | // Only the specified range of indexes is dealt with. |
| 132 | // After the update, the entire window is redrawn. |
| 133 | void refreshWindowPalette(int start, int count); |
| 134 | |
| 135 | // Clipboard::Notifier interface |
| 136 | void notifyClipboardChanged(const char* text, int len); |
| 137 | |
| 138 | // DesktopWindow Callback interface |
| 139 | class Callback : public InputHandler { |
| 140 | public: |
| 141 | virtual ~Callback() {} |
| 142 | virtual void displayChanged() = 0; |
| 143 | virtual void paintCompleted() = 0; |
| 144 | virtual bool sysCommand(WPARAM wParam, LPARAM lParam) = 0; |
| 145 | virtual void closeWindow() = 0; |
| 146 | virtual void refreshMenu(bool enableSysItems) = 0; |
| 147 | }; |
| 148 | |
george82 | fd334ad | 2006-05-29 14:05:20 +0000 | [diff] [blame] | 149 | Callback *getCallback() const { return callback; } |
| 150 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 151 | // Currently accessible so that the CConn can releaseAllKeys & check |
| 152 | // whether Ctrl and Alt are down... |
| 153 | rfb::win32::CKeyboard kbd; |
| 154 | |
| 155 | protected: |
| 156 | // Routines to convert between Desktop and client (window) coordinates |
| 157 | Point desktopToClient(const Point& p) { |
| 158 | Point pos = p; |
| 159 | if (client_size.width() > buffer->width()) |
| 160 | pos.x += (client_size.width() - buffer->width()) / 2; |
| 161 | else if (client_size.width() < buffer->width()) |
| 162 | pos.x -= scrolloffset.x; |
| 163 | if (client_size.height() > buffer->height()) |
| 164 | pos.y += (client_size.height() - buffer->height()) / 2; |
| 165 | else if (client_size.height() < buffer->height()) |
| 166 | pos.y -= scrolloffset.y; |
| 167 | return pos; |
| 168 | } |
| 169 | Rect desktopToClient(const Rect& r) { |
| 170 | return Rect(desktopToClient(r.tl), desktopToClient(r.br)); |
| 171 | } |
| 172 | Point clientToDesktop(const Point& p) { |
| 173 | Point pos = p; |
| 174 | if (client_size.width() > buffer->width()) |
| 175 | pos.x -= (client_size.width() - buffer->width()) / 2; |
| 176 | else if (client_size.width() < buffer->width()) |
| 177 | pos.x += scrolloffset.x; |
| 178 | if (client_size.height() > buffer->height()) |
| 179 | pos.y -= (client_size.height() - buffer->height()) / 2; |
| 180 | else if (client_size.height() < buffer->height()) |
| 181 | pos.y += scrolloffset.y; |
| 182 | return pos; |
| 183 | } |
| 184 | Rect clientToDesktop(const Rect& r) { |
| 185 | return Rect(clientToDesktop(r.tl), clientToDesktop(r.br)); |
| 186 | } |
| 187 | |
| 188 | // Internal routine used by the scrollbars & bump scroller to select |
| 189 | // the portion of the Desktop to display |
| 190 | bool setViewportOffset(const Point& tl); |
| 191 | |
| 192 | // Bump scroll handling. Bump scrolling is used if the window is |
| 193 | // in fullscreen mode and the Desktop is larger than the window |
| 194 | bool processBumpScroll(const Point& cursorPos); |
| 195 | void setBumpScroll(bool on); |
| 196 | bool bumpScroll; |
| 197 | Point bumpScrollDelta; |
| 198 | IntervalTimer bumpScrollTimer; |
| 199 | |
| 200 | // Locally-rendered VNC cursor |
| 201 | void hideLocalCursor(); |
| 202 | void showLocalCursor(); |
| 203 | void renderLocalCursor(); |
| 204 | |
| 205 | // The system-rendered cursor |
| 206 | void hideSystemCursor(); |
| 207 | void showSystemCursor(); |
| 208 | |
| 209 | // cursorOutsideBuffer() is called whenever we detect that the mouse has |
| 210 | // moved outside the desktop. It restores the system arrow cursor. |
| 211 | void cursorOutsideBuffer(); |
| 212 | |
| 213 | // Returns true if part of the supplied rect is visible, false otherwise |
| 214 | bool invalidateDesktopRect(const Rect& crect, bool scaling=true); |
| 215 | |
| 216 | // Determine whether or not we need to enable/disable scrollbars and set the |
| 217 | // window style accordingly |
| 218 | void calculateScrollBars(); |
| 219 | |
george82 | 858a464 | 2007-01-27 15:32:27 +0000 | [diff] [blame] | 220 | // Resizes the main window against the pixel buffer size |
| 221 | void resizeDesktopWindowToBuffer(); |
| 222 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 223 | // Win32-specific input handling |
| 224 | rfb::win32::CPointer ptr; |
| 225 | Point oldpos; |
| 226 | rfb::win32::Clipboard clipboard; |
| 227 | |
| 228 | // Palette handling |
| 229 | LogicalPalette windowPalette; |
| 230 | bool palette_changed; |
| 231 | |
| 232 | // - Full-screen mode |
| 233 | RECT fullscreenOldRect; |
| 234 | DWORD fullscreenOldFlags; |
| 235 | bool fullscreenActive; |
| 236 | bool fullscreenRestore; |
| 237 | |
| 238 | // Cursor handling |
| 239 | Cursor cursor; |
| 240 | bool systemCursorVisible; // Should system-cursor be drawn? |
| 241 | bool trackingMouseLeave; |
| 242 | bool cursorInBuffer; // Is cursor position within server buffer? (ONLY for LocalCursor) |
| 243 | bool cursorVisible; // Is cursor currently rendered? |
| 244 | bool cursorAvailable; // Is cursor available for rendering? |
george82 | 4880eec | 2007-03-19 10:55:13 +0000 | [diff] [blame] | 245 | bool internalSetCursor; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 246 | Point cursorPos; |
| 247 | ManagedPixelBuffer cursorBacking; |
| 248 | Rect cursorBackingRect; |
george82 | 4880eec | 2007-03-19 10:55:13 +0000 | [diff] [blame] | 249 | U8 *cursorImage; |
| 250 | U8 *cursorMask; |
| 251 | int cursorWidth; |
| 252 | int cursorHeight; |
| 253 | Point cursorHotspot; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 254 | |
| 255 | // ToolBar handling |
| 256 | ViewerToolBar tb; |
| 257 | bool showToolbar; |
| 258 | |
george82 | e0569e4 | 2006-09-11 15:56:10 +0000 | [diff] [blame] | 259 | // Remote desktop name |
| 260 | char desktopName[255]; |
| 261 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 262 | // Local window state |
| 263 | win32::ScaledDIBSectionBuffer* buffer; |
george82 | 3c68f5f | 2006-09-05 06:17:01 +0000 | [diff] [blame] | 264 | double aspect_corr; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 265 | bool has_focus; |
george82 | ffc14a6 | 2006-09-05 06:51:41 +0000 | [diff] [blame] | 266 | bool autoScaling; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 267 | Rect window_size; |
| 268 | Rect client_size; |
| 269 | Point scrolloffset; |
| 270 | Point maxscrolloffset; |
| 271 | HWND handle; |
| 272 | HWND frameHandle; |
| 273 | rdr::U8 menuKey; |
| 274 | |
| 275 | Callback* callback; |
| 276 | }; |
| 277 | |
| 278 | }; |
| 279 | |
| 280 | }; |
| 281 | |
| 282 | #endif // __RFB_WIN32_DESKTOP_WINDOW_H__ |
| 283 | |
| 284 | |