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 | |
| 59 | // - Determine the native pixel format of the window |
| 60 | // This can (and often will) differ from the PixelBuffer format |
| 61 | PixelFormat getNativePF() const; |
| 62 | |
| 63 | // - Get the underlying window handle |
| 64 | // This is used by F8Menu to modify the window's menu |
| 65 | HWND getHandle() const {return handle;} |
| 66 | |
| 67 | // - Get the framebuffer window handle |
| 68 | HWND getFrameHandle() const {return frameHandle;} |
| 69 | |
| 70 | // - Set the window title |
| 71 | void setName(const char* name); |
| 72 | |
| 73 | // - Set the key that causes the system/F8 menu to be displayed |
| 74 | void setMenuKey(rdr::U8 key) { menuKey = key; } |
| 75 | |
| 76 | // - Pointer event handling |
| 77 | void setEmulate3(bool em3) { ptr.enableEmulate3(em3); } |
| 78 | void setPointerEventInterval(int interval) { ptr.enableInterval(interval); } |
| 79 | |
| 80 | // - Set the pixel format, size etc of the underlying PixelBuffer |
| 81 | void setPF(const PixelFormat& pf); |
| 82 | PixelFormat getPF() const { return buffer->getPF(); } |
| 83 | void setSize(int w, int h); |
| 84 | void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);} |
george82 | ffc14a6 | 2006-09-05 06:51:41 +0000 | [diff] [blame] | 85 | void setAutoScaling(bool as) { |
| 86 | autoScaling = as; |
| 87 | if (as) fitBufferToWindow(); |
| 88 | } |
| 89 | bool isAutoScaling() const { return autoScaling; } |
george82 | 04a7771 | 2006-05-29 14:18:14 +0000 | [diff] [blame] | 90 | void setDesktopScale(int scale); |
george82 | b6d87aa | 2006-09-11 07:00:59 +0000 | [diff] [blame^] | 91 | int getDesktopScale() const { return buffer->getScale(); } |
george82 | 3c68f5f | 2006-09-05 06:17:01 +0000 | [diff] [blame] | 92 | void fitBufferToWindow(bool repaint = true); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 93 | |
| 94 | // - Set the cursor to render when the pointer is within the desktop buffer |
| 95 | void setCursor(int w, int h, const Point& hotspot, void* data, void* mask); |
| 96 | void showCursor() { showLocalCursor(); } |
| 97 | |
| 98 | // - Set the window fullscreen / determine whether it is fullscreen |
| 99 | void setFullscreen(bool fs); |
| 100 | bool isFullscreen() { return fullscreenActive; } |
| 101 | |
| 102 | // - Set/get the toolbar's state |
| 103 | void setShowToolbar(bool st); |
| 104 | bool isToolbarEnabled() { return showToolbar; } |
| 105 | |
| 106 | // - Set whether to disable special Windows keys & pass them straight to server |
| 107 | void setDisableWinKeys(bool dwk); |
| 108 | |
| 109 | // - Set/get which monitor the window should be displayed on |
| 110 | void setMonitor(const char* monitor); |
| 111 | char* getMonitor() const; |
| 112 | |
| 113 | // - Set the local clipboard |
| 114 | void serverCutText(const char* str, int len); |
| 115 | |
| 116 | // - Draw into the desktop buffer & update the window |
| 117 | void fillRect(const Rect& r, Pixel pix); |
| 118 | void imageRect(const Rect& r, void* pixels); |
| 119 | void copyRect(const Rect& r, int srcX, int srcY); |
| 120 | |
| 121 | void invertRect(const Rect& r); |
| 122 | |
| 123 | // - Update the window palette if the display is palette-based. |
| 124 | // Colours are pulled from the desktop buffer's ColourMap. |
| 125 | // Only the specified range of indexes is dealt with. |
| 126 | // After the update, the entire window is redrawn. |
| 127 | void refreshWindowPalette(int start, int count); |
| 128 | |
| 129 | // Clipboard::Notifier interface |
| 130 | void notifyClipboardChanged(const char* text, int len); |
| 131 | |
| 132 | // DesktopWindow Callback interface |
| 133 | class Callback : public InputHandler { |
| 134 | public: |
| 135 | virtual ~Callback() {} |
| 136 | virtual void displayChanged() = 0; |
| 137 | virtual void paintCompleted() = 0; |
| 138 | virtual bool sysCommand(WPARAM wParam, LPARAM lParam) = 0; |
| 139 | virtual void closeWindow() = 0; |
| 140 | virtual void refreshMenu(bool enableSysItems) = 0; |
| 141 | }; |
| 142 | |
george82 | fd334ad | 2006-05-29 14:05:20 +0000 | [diff] [blame] | 143 | Callback *getCallback() const { return callback; } |
| 144 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 145 | // Currently accessible so that the CConn can releaseAllKeys & check |
| 146 | // whether Ctrl and Alt are down... |
| 147 | rfb::win32::CKeyboard kbd; |
| 148 | |
| 149 | protected: |
| 150 | // Routines to convert between Desktop and client (window) coordinates |
| 151 | Point desktopToClient(const Point& p) { |
| 152 | Point pos = p; |
| 153 | if (client_size.width() > buffer->width()) |
| 154 | pos.x += (client_size.width() - buffer->width()) / 2; |
| 155 | else if (client_size.width() < buffer->width()) |
| 156 | pos.x -= scrolloffset.x; |
| 157 | if (client_size.height() > buffer->height()) |
| 158 | pos.y += (client_size.height() - buffer->height()) / 2; |
| 159 | else if (client_size.height() < buffer->height()) |
| 160 | pos.y -= scrolloffset.y; |
| 161 | return pos; |
| 162 | } |
| 163 | Rect desktopToClient(const Rect& r) { |
| 164 | return Rect(desktopToClient(r.tl), desktopToClient(r.br)); |
| 165 | } |
| 166 | Point clientToDesktop(const Point& p) { |
| 167 | Point pos = p; |
| 168 | if (client_size.width() > buffer->width()) |
| 169 | pos.x -= (client_size.width() - buffer->width()) / 2; |
| 170 | else if (client_size.width() < buffer->width()) |
| 171 | pos.x += scrolloffset.x; |
| 172 | if (client_size.height() > buffer->height()) |
| 173 | pos.y -= (client_size.height() - buffer->height()) / 2; |
| 174 | else if (client_size.height() < buffer->height()) |
| 175 | pos.y += scrolloffset.y; |
| 176 | return pos; |
| 177 | } |
| 178 | Rect clientToDesktop(const Rect& r) { |
| 179 | return Rect(clientToDesktop(r.tl), clientToDesktop(r.br)); |
| 180 | } |
| 181 | |
| 182 | // Internal routine used by the scrollbars & bump scroller to select |
| 183 | // the portion of the Desktop to display |
| 184 | bool setViewportOffset(const Point& tl); |
| 185 | |
| 186 | // Bump scroll handling. Bump scrolling is used if the window is |
| 187 | // in fullscreen mode and the Desktop is larger than the window |
| 188 | bool processBumpScroll(const Point& cursorPos); |
| 189 | void setBumpScroll(bool on); |
| 190 | bool bumpScroll; |
| 191 | Point bumpScrollDelta; |
| 192 | IntervalTimer bumpScrollTimer; |
| 193 | |
| 194 | // Locally-rendered VNC cursor |
| 195 | void hideLocalCursor(); |
| 196 | void showLocalCursor(); |
| 197 | void renderLocalCursor(); |
| 198 | |
| 199 | // The system-rendered cursor |
| 200 | void hideSystemCursor(); |
| 201 | void showSystemCursor(); |
| 202 | |
| 203 | // cursorOutsideBuffer() is called whenever we detect that the mouse has |
| 204 | // moved outside the desktop. It restores the system arrow cursor. |
| 205 | void cursorOutsideBuffer(); |
| 206 | |
| 207 | // Returns true if part of the supplied rect is visible, false otherwise |
| 208 | bool invalidateDesktopRect(const Rect& crect, bool scaling=true); |
| 209 | |
| 210 | // Determine whether or not we need to enable/disable scrollbars and set the |
| 211 | // window style accordingly |
| 212 | void calculateScrollBars(); |
| 213 | |
| 214 | // Win32-specific input handling |
| 215 | rfb::win32::CPointer ptr; |
| 216 | Point oldpos; |
| 217 | rfb::win32::Clipboard clipboard; |
| 218 | |
| 219 | // Palette handling |
| 220 | LogicalPalette windowPalette; |
| 221 | bool palette_changed; |
| 222 | |
| 223 | // - Full-screen mode |
| 224 | RECT fullscreenOldRect; |
| 225 | DWORD fullscreenOldFlags; |
| 226 | bool fullscreenActive; |
| 227 | bool fullscreenRestore; |
| 228 | |
| 229 | // Cursor handling |
| 230 | Cursor cursor; |
| 231 | bool systemCursorVisible; // Should system-cursor be drawn? |
| 232 | bool trackingMouseLeave; |
| 233 | bool cursorInBuffer; // Is cursor position within server buffer? (ONLY for LocalCursor) |
| 234 | bool cursorVisible; // Is cursor currently rendered? |
| 235 | bool cursorAvailable; // Is cursor available for rendering? |
| 236 | Point cursorPos; |
| 237 | ManagedPixelBuffer cursorBacking; |
| 238 | Rect cursorBackingRect; |
| 239 | |
| 240 | // ToolBar handling |
| 241 | ViewerToolBar tb; |
| 242 | bool showToolbar; |
| 243 | |
| 244 | // Local window state |
| 245 | win32::ScaledDIBSectionBuffer* buffer; |
george82 | 3c68f5f | 2006-09-05 06:17:01 +0000 | [diff] [blame] | 246 | double aspect_corr; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 247 | bool has_focus; |
george82 | ffc14a6 | 2006-09-05 06:51:41 +0000 | [diff] [blame] | 248 | bool autoScaling; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 249 | Rect window_size; |
| 250 | Rect client_size; |
| 251 | Point scrolloffset; |
| 252 | Point maxscrolloffset; |
| 253 | HWND handle; |
| 254 | HWND frameHandle; |
| 255 | rdr::U8 menuKey; |
| 256 | |
| 257 | Callback* callback; |
| 258 | }; |
| 259 | |
| 260 | }; |
| 261 | |
| 262 | }; |
| 263 | |
| 264 | #endif // __RFB_WIN32_DESKTOP_WINDOW_H__ |
| 265 | |
| 266 | |