blob: a6bc5df4b38746c1c1348e8ae49e51de343c7817 [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(); }
99
100 // - Set the window fullscreen / determine whether it is fullscreen
101 void setFullscreen(bool fs);
102 bool isFullscreen() { return fullscreenActive; }
103
104 // - Set/get the toolbar's state
105 void setShowToolbar(bool st);
106 bool isToolbarEnabled() { return showToolbar; }
george8274ea5f32006-09-11 11:40:12 +0000107 void refreshToolbarButtons();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000108
109 // - Set whether to disable special Windows keys & pass them straight to server
110 void setDisableWinKeys(bool dwk);
111
112 // - Set/get which monitor the window should be displayed on
113 void setMonitor(const char* monitor);
114 char* getMonitor() const;
115
116 // - Set the local clipboard
117 void serverCutText(const char* str, int len);
118
119 // - Draw into the desktop buffer & update the window
120 void fillRect(const Rect& r, Pixel pix);
121 void imageRect(const Rect& r, void* pixels);
122 void copyRect(const Rect& r, int srcX, int srcY);
123
124 void invertRect(const Rect& r);
125
126 // - Update the window palette if the display is palette-based.
127 // Colours are pulled from the desktop buffer's ColourMap.
128 // Only the specified range of indexes is dealt with.
129 // After the update, the entire window is redrawn.
130 void refreshWindowPalette(int start, int count);
131
132 // Clipboard::Notifier interface
133 void notifyClipboardChanged(const char* text, int len);
134
135 // DesktopWindow Callback interface
136 class Callback : public InputHandler {
137 public:
138 virtual ~Callback() {}
139 virtual void displayChanged() = 0;
140 virtual void paintCompleted() = 0;
141 virtual bool sysCommand(WPARAM wParam, LPARAM lParam) = 0;
142 virtual void closeWindow() = 0;
143 virtual void refreshMenu(bool enableSysItems) = 0;
144 };
145
george82fd334ad2006-05-29 14:05:20 +0000146 Callback *getCallback() const { return callback; }
147
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000148 // Currently accessible so that the CConn can releaseAllKeys & check
149 // whether Ctrl and Alt are down...
150 rfb::win32::CKeyboard kbd;
151
152 protected:
153 // Routines to convert between Desktop and client (window) coordinates
154 Point desktopToClient(const Point& p) {
155 Point pos = p;
156 if (client_size.width() > buffer->width())
157 pos.x += (client_size.width() - buffer->width()) / 2;
158 else if (client_size.width() < buffer->width())
159 pos.x -= scrolloffset.x;
160 if (client_size.height() > buffer->height())
161 pos.y += (client_size.height() - buffer->height()) / 2;
162 else if (client_size.height() < buffer->height())
163 pos.y -= scrolloffset.y;
164 return pos;
165 }
166 Rect desktopToClient(const Rect& r) {
167 return Rect(desktopToClient(r.tl), desktopToClient(r.br));
168 }
169 Point clientToDesktop(const Point& p) {
170 Point pos = p;
171 if (client_size.width() > buffer->width())
172 pos.x -= (client_size.width() - buffer->width()) / 2;
173 else if (client_size.width() < buffer->width())
174 pos.x += scrolloffset.x;
175 if (client_size.height() > buffer->height())
176 pos.y -= (client_size.height() - buffer->height()) / 2;
177 else if (client_size.height() < buffer->height())
178 pos.y += scrolloffset.y;
179 return pos;
180 }
181 Rect clientToDesktop(const Rect& r) {
182 return Rect(clientToDesktop(r.tl), clientToDesktop(r.br));
183 }
184
185 // Internal routine used by the scrollbars & bump scroller to select
186 // the portion of the Desktop to display
187 bool setViewportOffset(const Point& tl);
188
189 // Bump scroll handling. Bump scrolling is used if the window is
190 // in fullscreen mode and the Desktop is larger than the window
191 bool processBumpScroll(const Point& cursorPos);
192 void setBumpScroll(bool on);
193 bool bumpScroll;
194 Point bumpScrollDelta;
195 IntervalTimer bumpScrollTimer;
196
197 // Locally-rendered VNC cursor
198 void hideLocalCursor();
199 void showLocalCursor();
200 void renderLocalCursor();
201
202 // The system-rendered cursor
203 void hideSystemCursor();
204 void showSystemCursor();
205
206 // cursorOutsideBuffer() is called whenever we detect that the mouse has
207 // moved outside the desktop. It restores the system arrow cursor.
208 void cursorOutsideBuffer();
209
210 // Returns true if part of the supplied rect is visible, false otherwise
211 bool invalidateDesktopRect(const Rect& crect, bool scaling=true);
212
213 // Determine whether or not we need to enable/disable scrollbars and set the
214 // window style accordingly
215 void calculateScrollBars();
216
george82858a4642007-01-27 15:32:27 +0000217 // Resizes the main window against the pixel buffer size
218 void resizeDesktopWindowToBuffer();
219
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000220 // Win32-specific input handling
221 rfb::win32::CPointer ptr;
222 Point oldpos;
223 rfb::win32::Clipboard clipboard;
224
225 // Palette handling
226 LogicalPalette windowPalette;
227 bool palette_changed;
228
229 // - Full-screen mode
230 RECT fullscreenOldRect;
231 DWORD fullscreenOldFlags;
232 bool fullscreenActive;
233 bool fullscreenRestore;
234
235 // Cursor handling
236 Cursor cursor;
237 bool systemCursorVisible; // Should system-cursor be drawn?
238 bool trackingMouseLeave;
239 bool cursorInBuffer; // Is cursor position within server buffer? (ONLY for LocalCursor)
240 bool cursorVisible; // Is cursor currently rendered?
241 bool cursorAvailable; // Is cursor available for rendering?
242 Point cursorPos;
243 ManagedPixelBuffer cursorBacking;
244 Rect cursorBackingRect;
245
246 // ToolBar handling
247 ViewerToolBar tb;
248 bool showToolbar;
249
george82e0569e42006-09-11 15:56:10 +0000250 // Remote desktop name
251 char desktopName[255];
252
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000253 // Local window state
254 win32::ScaledDIBSectionBuffer* buffer;
george823c68f5f2006-09-05 06:17:01 +0000255 double aspect_corr;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000256 bool has_focus;
george82ffc14a62006-09-05 06:51:41 +0000257 bool autoScaling;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000258 Rect window_size;
259 Rect client_size;
260 Point scrolloffset;
261 Point maxscrolloffset;
262 HWND handle;
263 HWND frameHandle;
264 rdr::U8 menuKey;
265
266 Callback* callback;
267 };
268
269 };
270
271};
272
273#endif // __RFB_WIN32_DESKTOP_WINDOW_H__
274
275