blob: 94f361deef2daf3f2cad5e4996b9ca2103dce0b5 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* 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
42namespace 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 Kaplinskyd5f59272006-09-14 05:14:43 +000059 // - 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 Kaplinsky729598c2006-05-25 05:12:25 +000063 // - 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);
george827c721cc2006-09-23 07:09:37 +000086 PixelFormat getPF() const { return buffer->getPixelFormat(); }
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000087 void setSize(int w, int h);
88 void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);}
george8274ea5f32006-09-11 11:40:12 +000089 void setAutoScaling(bool as);
george82ffc14a62006-09-05 06:51:41 +000090 bool isAutoScaling() const { return autoScaling; }
george822446ed02007-03-10 08:55:35 +000091 void setDesktopScale(int scale);
george82b6d87aa2006-09-11 07:00:59 +000092 int getDesktopScale() const { return buffer->getScale(); }
george823c68f5f2006-09-05 06:17:01 +000093 void fitBufferToWindow(bool repaint = true);
george82770bbbc2007-03-12 10:48:09 +000094 void printScale();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000095
96 // - Set the cursor to render when the pointer is within the desktop buffer
97 void setCursor(int w, int h, const Point& hotspot, void* data, void* mask);
98 void showCursor() { showLocalCursor(); }
george824880eec2007-03-19 10:55:13 +000099 void convertCursorToBuffer();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000100
101 // - Set the window fullscreen / determine whether it is fullscreen
102 void setFullscreen(bool fs);
103 bool isFullscreen() { return fullscreenActive; }
104
105 // - Set/get the toolbar's state
106 void setShowToolbar(bool st);
107 bool isToolbarEnabled() { return showToolbar; }
george8274ea5f32006-09-11 11:40:12 +0000108 void refreshToolbarButtons();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000109
110 // - Set whether to disable special Windows keys & pass them straight to server
111 void setDisableWinKeys(bool dwk);
112
113 // - Set/get which monitor the window should be displayed on
114 void setMonitor(const char* monitor);
115 char* getMonitor() const;
116
117 // - Set the local clipboard
118 void serverCutText(const char* str, int len);
119
120 // - Draw into the desktop buffer & update the window
121 void fillRect(const Rect& r, Pixel pix);
122 void imageRect(const Rect& r, void* pixels);
123 void copyRect(const Rect& r, int srcX, int srcY);
124
125 void invertRect(const Rect& r);
126
127 // - Update the window palette if the display is palette-based.
128 // Colours are pulled from the desktop buffer's ColourMap.
129 // Only the specified range of indexes is dealt with.
130 // After the update, the entire window is redrawn.
131 void refreshWindowPalette(int start, int count);
132
133 // Clipboard::Notifier interface
134 void notifyClipboardChanged(const char* text, int len);
135
136 // DesktopWindow Callback interface
137 class Callback : public InputHandler {
138 public:
139 virtual ~Callback() {}
140 virtual void displayChanged() = 0;
141 virtual void paintCompleted() = 0;
142 virtual bool sysCommand(WPARAM wParam, LPARAM lParam) = 0;
143 virtual void closeWindow() = 0;
144 virtual void refreshMenu(bool enableSysItems) = 0;
145 };
146
george82fd334ad2006-05-29 14:05:20 +0000147 Callback *getCallback() const { return callback; }
148
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000149 // Currently accessible so that the CConn can releaseAllKeys & check
150 // whether Ctrl and Alt are down...
151 rfb::win32::CKeyboard kbd;
152
153 protected:
154 // Routines to convert between Desktop and client (window) coordinates
155 Point desktopToClient(const Point& p) {
156 Point pos = p;
157 if (client_size.width() > buffer->width())
158 pos.x += (client_size.width() - buffer->width()) / 2;
159 else if (client_size.width() < buffer->width())
160 pos.x -= scrolloffset.x;
161 if (client_size.height() > buffer->height())
162 pos.y += (client_size.height() - buffer->height()) / 2;
163 else if (client_size.height() < buffer->height())
164 pos.y -= scrolloffset.y;
165 return pos;
166 }
167 Rect desktopToClient(const Rect& r) {
168 return Rect(desktopToClient(r.tl), desktopToClient(r.br));
169 }
170 Point clientToDesktop(const Point& p) {
171 Point pos = p;
172 if (client_size.width() > buffer->width())
173 pos.x -= (client_size.width() - buffer->width()) / 2;
174 else if (client_size.width() < buffer->width())
175 pos.x += scrolloffset.x;
176 if (client_size.height() > buffer->height())
177 pos.y -= (client_size.height() - buffer->height()) / 2;
178 else if (client_size.height() < buffer->height())
179 pos.y += scrolloffset.y;
180 return pos;
181 }
182 Rect clientToDesktop(const Rect& r) {
183 return Rect(clientToDesktop(r.tl), clientToDesktop(r.br));
184 }
185
186 // Internal routine used by the scrollbars & bump scroller to select
187 // the portion of the Desktop to display
188 bool setViewportOffset(const Point& tl);
189
190 // Bump scroll handling. Bump scrolling is used if the window is
191 // in fullscreen mode and the Desktop is larger than the window
192 bool processBumpScroll(const Point& cursorPos);
193 void setBumpScroll(bool on);
194 bool bumpScroll;
195 Point bumpScrollDelta;
196 IntervalTimer bumpScrollTimer;
197
198 // Locally-rendered VNC cursor
199 void hideLocalCursor();
200 void showLocalCursor();
201 void renderLocalCursor();
202
203 // The system-rendered cursor
204 void hideSystemCursor();
205 void showSystemCursor();
206
207 // cursorOutsideBuffer() is called whenever we detect that the mouse has
208 // moved outside the desktop. It restores the system arrow cursor.
209 void cursorOutsideBuffer();
210
211 // Returns true if part of the supplied rect is visible, false otherwise
212 bool invalidateDesktopRect(const Rect& crect, bool scaling=true);
213
214 // Determine whether or not we need to enable/disable scrollbars and set the
215 // window style accordingly
216 void calculateScrollBars();
217
george82858a4642007-01-27 15:32:27 +0000218 // Resizes the main window against the pixel buffer size
219 void resizeDesktopWindowToBuffer();
220
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000221 // Win32-specific input handling
222 rfb::win32::CPointer ptr;
223 Point oldpos;
224 rfb::win32::Clipboard clipboard;
225
226 // Palette handling
227 LogicalPalette windowPalette;
228 bool palette_changed;
229
230 // - Full-screen mode
231 RECT fullscreenOldRect;
232 DWORD fullscreenOldFlags;
233 bool fullscreenActive;
234 bool fullscreenRestore;
235
236 // Cursor handling
237 Cursor cursor;
238 bool systemCursorVisible; // Should system-cursor be drawn?
239 bool trackingMouseLeave;
240 bool cursorInBuffer; // Is cursor position within server buffer? (ONLY for LocalCursor)
241 bool cursorVisible; // Is cursor currently rendered?
242 bool cursorAvailable; // Is cursor available for rendering?
george824880eec2007-03-19 10:55:13 +0000243 bool internalSetCursor;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000244 Point cursorPos;
245 ManagedPixelBuffer cursorBacking;
246 Rect cursorBackingRect;
george824880eec2007-03-19 10:55:13 +0000247 U8 *cursorImage;
248 U8 *cursorMask;
249 int cursorWidth;
250 int cursorHeight;
251 Point cursorHotspot;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000252
253 // ToolBar handling
254 ViewerToolBar tb;
255 bool showToolbar;
256
george82e0569e42006-09-11 15:56:10 +0000257 // Remote desktop name
258 char desktopName[255];
259
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000260 // Local window state
261 win32::ScaledDIBSectionBuffer* buffer;
george823c68f5f2006-09-05 06:17:01 +0000262 double aspect_corr;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000263 bool has_focus;
george82ffc14a62006-09-05 06:51:41 +0000264 bool autoScaling;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000265 Rect window_size;
266 Rect client_size;
267 Point scrolloffset;
268 Point maxscrolloffset;
269 HWND handle;
270 HWND frameHandle;
271 rdr::U8 menuKey;
272
273 Callback* callback;
274 };
275
276 };
277
278};
279
280#endif // __RFB_WIN32_DESKTOP_WINDOW_H__
281
282