blob: 4bc7b7a790ae3463d8f238de9a9411c4da524eff [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(); }
george82c4eb6262007-03-20 10:54:38 +000093 void setDesktopScaleFilter(unsigned int scaleFilterID);
94 unsigned int getDesktopScaleFilterID() const { return buffer->getScaleFilterID(); }
george823c68f5f2006-09-05 06:17:01 +000095 void fitBufferToWindow(bool repaint = true);
george82770bbbc2007-03-12 10:48:09 +000096 void printScale();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000097
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(); }
george824880eec2007-03-19 10:55:13 +0000101 void convertCursorToBuffer();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000102
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; }
george8274ea5f32006-09-11 11:40:12 +0000110 void refreshToolbarButtons();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000111
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 Tkacacf6c6b2009-02-13 12:42:05 +0000120 void serverCutText(const char* str, rdr::U32 len);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000121
Pierre Ossmanb2ff1602009-03-25 12:13:28 +0000122 // - Completion of one FramebufferUpdate
123 void framebufferUpdateEnd();
124
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000125 // - 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
george82fd334ad2006-05-29 14:05:20 +0000152 Callback *getCallback() const { return callback; }
153
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000154 // 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 Ossmanb2ff1602009-03-25 12:13:28 +0000203 // Track modified areas of the framebuffer
204 void updateWindow();
205
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000206 // 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
george82858a4642007-01-27 15:32:27 +0000226 // Resizes the main window against the pixel buffer size
227 void resizeDesktopWindowToBuffer();
228
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000229 // 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 Ossmanb2ff1602009-03-25 12:13:28 +0000244 // Damage tracking
245 rfb::Region damage;
246 IntervalTimer updateTimer;
247
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000248 // 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?
george824880eec2007-03-19 10:55:13 +0000255 bool internalSetCursor;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000256 Point cursorPos;
257 ManagedPixelBuffer cursorBacking;
258 Rect cursorBackingRect;
george824880eec2007-03-19 10:55:13 +0000259 U8 *cursorImage;
260 U8 *cursorMask;
261 int cursorWidth;
262 int cursorHeight;
263 Point cursorHotspot;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000264
265 // ToolBar handling
266 ViewerToolBar tb;
267 bool showToolbar;
268
george82e0569e42006-09-11 15:56:10 +0000269 // Remote desktop name
270 char desktopName[255];
271
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000272 // Local window state
273 win32::ScaledDIBSectionBuffer* buffer;
george823c68f5f2006-09-05 06:17:01 +0000274 double aspect_corr;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000275 bool has_focus;
george82ffc14a62006-09-05 06:51:41 +0000276 bool autoScaling;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000277 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