blob: f0db427518eaeb85f8a852f4203cad0698ef1f68 [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
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);}
george8204a77712006-05-29 14:18:14 +000085 void setDesktopScale(int scale);
george823c68f5f2006-09-05 06:17:01 +000086 void fitBufferToWindow(bool repaint = true);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000087
88 // - Set the cursor to render when the pointer is within the desktop buffer
89 void setCursor(int w, int h, const Point& hotspot, void* data, void* mask);
90 void showCursor() { showLocalCursor(); }
91
92 // - Set the window fullscreen / determine whether it is fullscreen
93 void setFullscreen(bool fs);
94 bool isFullscreen() { return fullscreenActive; }
95
96 // - Set/get the toolbar's state
97 void setShowToolbar(bool st);
98 bool isToolbarEnabled() { return showToolbar; }
99
100 // - Set whether to disable special Windows keys & pass them straight to server
101 void setDisableWinKeys(bool dwk);
102
103 // - Set/get which monitor the window should be displayed on
104 void setMonitor(const char* monitor);
105 char* getMonitor() const;
106
107 // - Set the local clipboard
108 void serverCutText(const char* str, int len);
109
110 // - Draw into the desktop buffer & update the window
111 void fillRect(const Rect& r, Pixel pix);
112 void imageRect(const Rect& r, void* pixels);
113 void copyRect(const Rect& r, int srcX, int srcY);
114
115 void invertRect(const Rect& r);
116
117 // - Update the window palette if the display is palette-based.
118 // Colours are pulled from the desktop buffer's ColourMap.
119 // Only the specified range of indexes is dealt with.
120 // After the update, the entire window is redrawn.
121 void refreshWindowPalette(int start, int count);
122
123 // Clipboard::Notifier interface
124 void notifyClipboardChanged(const char* text, int len);
125
126 // DesktopWindow Callback interface
127 class Callback : public InputHandler {
128 public:
129 virtual ~Callback() {}
130 virtual void displayChanged() = 0;
131 virtual void paintCompleted() = 0;
132 virtual bool sysCommand(WPARAM wParam, LPARAM lParam) = 0;
133 virtual void closeWindow() = 0;
134 virtual void refreshMenu(bool enableSysItems) = 0;
135 };
136
george82fd334ad2006-05-29 14:05:20 +0000137 Callback *getCallback() const { return callback; }
138
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000139 // Currently accessible so that the CConn can releaseAllKeys & check
140 // whether Ctrl and Alt are down...
141 rfb::win32::CKeyboard kbd;
142
143 protected:
144 // Routines to convert between Desktop and client (window) coordinates
145 Point desktopToClient(const Point& p) {
146 Point pos = p;
147 if (client_size.width() > buffer->width())
148 pos.x += (client_size.width() - buffer->width()) / 2;
149 else if (client_size.width() < buffer->width())
150 pos.x -= scrolloffset.x;
151 if (client_size.height() > buffer->height())
152 pos.y += (client_size.height() - buffer->height()) / 2;
153 else if (client_size.height() < buffer->height())
154 pos.y -= scrolloffset.y;
155 return pos;
156 }
157 Rect desktopToClient(const Rect& r) {
158 return Rect(desktopToClient(r.tl), desktopToClient(r.br));
159 }
160 Point clientToDesktop(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 clientToDesktop(const Rect& r) {
173 return Rect(clientToDesktop(r.tl), clientToDesktop(r.br));
174 }
175
176 // Internal routine used by the scrollbars & bump scroller to select
177 // the portion of the Desktop to display
178 bool setViewportOffset(const Point& tl);
179
180 // Bump scroll handling. Bump scrolling is used if the window is
181 // in fullscreen mode and the Desktop is larger than the window
182 bool processBumpScroll(const Point& cursorPos);
183 void setBumpScroll(bool on);
184 bool bumpScroll;
185 Point bumpScrollDelta;
186 IntervalTimer bumpScrollTimer;
187
188 // Locally-rendered VNC cursor
189 void hideLocalCursor();
190 void showLocalCursor();
191 void renderLocalCursor();
192
193 // The system-rendered cursor
194 void hideSystemCursor();
195 void showSystemCursor();
196
197 // cursorOutsideBuffer() is called whenever we detect that the mouse has
198 // moved outside the desktop. It restores the system arrow cursor.
199 void cursorOutsideBuffer();
200
201 // Returns true if part of the supplied rect is visible, false otherwise
202 bool invalidateDesktopRect(const Rect& crect, bool scaling=true);
203
204 // Determine whether or not we need to enable/disable scrollbars and set the
205 // window style accordingly
206 void calculateScrollBars();
207
208 // Win32-specific input handling
209 rfb::win32::CPointer ptr;
210 Point oldpos;
211 rfb::win32::Clipboard clipboard;
212
213 // Palette handling
214 LogicalPalette windowPalette;
215 bool palette_changed;
216
217 // - Full-screen mode
218 RECT fullscreenOldRect;
219 DWORD fullscreenOldFlags;
220 bool fullscreenActive;
221 bool fullscreenRestore;
222
223 // Cursor handling
224 Cursor cursor;
225 bool systemCursorVisible; // Should system-cursor be drawn?
226 bool trackingMouseLeave;
227 bool cursorInBuffer; // Is cursor position within server buffer? (ONLY for LocalCursor)
228 bool cursorVisible; // Is cursor currently rendered?
229 bool cursorAvailable; // Is cursor available for rendering?
230 Point cursorPos;
231 ManagedPixelBuffer cursorBacking;
232 Rect cursorBackingRect;
233
234 // ToolBar handling
235 ViewerToolBar tb;
236 bool showToolbar;
237
238 // Local window state
239 win32::ScaledDIBSectionBuffer* buffer;
george823c68f5f2006-09-05 06:17:01 +0000240 double aspect_corr;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000241 bool has_focus;
242 Rect window_size;
243 Rect client_size;
244 Point scrolloffset;
245 Point maxscrolloffset;
246 HWND handle;
247 HWND frameHandle;
248 rdr::U8 menuKey;
249
250 Callback* callback;
251 };
252
253 };
254
255};
256
257#endif // __RFB_WIN32_DESKTOP_WINDOW_H__
258
259