1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/* Copyright (C) 2002-2004 RealVNC Ltd. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// -=- CView.h
// An instance of the CView class is created for each VNC Viewer connection.
#ifndef __RFB_WIN32_CVIEW_H__
#define __RFB_WIN32_CVIEW_H__
#include <network/Socket.h>
#include <rfb/CConnection.h>
#include <rfb/Cursor.h>
#include <rfb/UserPasswdGetter.h>
#include <rfb_win32/Clipboard.h>
#include <rfb_win32/DIBSectionBuffer.h>
#include <rfb_win32/Win32Util.h>
#include <rfb_win32/Registry.h>
#include <rfb_win32/AboutDialog.h>
#include <rfb_win32/CKeyboard.h>
#include <rfb_win32/CPointer.h>
#include <vncviewer/InfoDialog.h>
#include <vncviewer/OptionsDialog.h>
#include <vncviewer/CViewOptions.h>
#include <vncviewer/CViewManager.h>
#include <list>
namespace rfb {
namespace win32 {
class CView : public CConnection,
public UserPasswdGetter,
rfb::win32::Clipboard::Notifier,
rdr::FdInStreamBlockCallback
{
public:
CView();
virtual ~CView();
bool initialise(network::Socket* s);
void setManager(CViewManager* m) {manager = m;}
void applyOptions(CViewOptions& opt);
const CViewOptions& getOptions() const {return options;};
// -=- Window Message handling
virtual LRESULT processMessage(UINT msg, WPARAM wParam, LPARAM lParam);
// -=- Socket blocking handling
// blockCallback will throw QuitMessage(result) when
// it processes a WM_QUIT message.
// The caller may catch that to cope gracefully with
// a request to quit.
class QuitMessage : public rdr::Exception {
public:
QuitMessage(WPARAM wp) : rdr::Exception("QuitMessage") {}
WPARAM wParam;
};
virtual void blockCallback();
// -=- Window interface
void postQuitOnDestroy(bool qod) {quit_on_destroy = qod;}
PixelFormat getNativePF() const;
void setVisible(bool visible);
void close(const char* reason=0);
HWND getHandle() const {return hwnd;}
void notifyClipboardChanged(const char* text, int len);
// -=- Coordinate conversions
inline Point bufferToClient(const Point& p) {
Point pos = p;
if (client_size.width() > buffer->width())
pos.x += (client_size.width() - buffer->width()) / 2;
else if (client_size.width() < buffer->width())
pos.x -= scrolloffset.x;
if (client_size.height() > buffer->height())
pos.y += (client_size.height() - buffer->height()) / 2;
else if (client_size.height() < buffer->height())
pos.y -= scrolloffset.y;
return pos;
}
inline Rect bufferToClient(const Rect& r) {
return Rect(bufferToClient(r.tl), bufferToClient(r.br));
}
inline Point clientToBuffer(const Point& p) {
Point pos = p;
if (client_size.width() > buffer->width())
pos.x -= (client_size.width() - buffer->width()) / 2;
else if (client_size.width() < buffer->width())
pos.x += scrolloffset.x;
if (client_size.height() > buffer->height())
pos.y -= (client_size.height() - buffer->height()) / 2;
else if (client_size.height() < buffer->height())
pos.y += scrolloffset.y;
return pos;
}
inline Rect clientToBuffer(const Rect& r) {
return Rect(clientToBuffer(r.tl), clientToBuffer(r.br));
}
void setFullscreen(bool fs);
bool setViewportOffset(const Point& tl);
bool processBumpScroll(const Point& cursorPos);
void setBumpScroll(bool on);
int lastUsedEncoding() const { return lastUsedEncoding_; }
// -=- CConnection interface overrides
virtual CSecurity* getCSecurity(int secType);
virtual void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
virtual void bell();
virtual void framebufferUpdateEnd();
virtual void setDesktopSize(int w, int h);
virtual void setCursor(const Point& hotspot, const Point& size, void* data, void* mask);
virtual void setName(const char* name);
virtual void serverInit();
virtual void serverCutText(const char* str, int len);
virtual void beginRect(const Rect& r, unsigned int encoding);
virtual void endRect(const Rect& r, unsigned int encoding);
virtual void fillRect(const Rect& r, Pixel pix);
virtual void imageRect(const Rect& r, void* pixels);
virtual void copyRect(const Rect& r, int srcX, int srcY);
void invertRect(const Rect& r);
// VNCviewer dialog objects
OptionsDialog optionsDialog;
friend class InfoDialog;
InfoDialog infoDialog;
// UserPasswdGetter overrides, used to support a pre-supplied VNC password
virtual bool getUserPasswd(char** user, char** password);
// Global user-config registry key
static RegKey userConfigKey;
protected:
// Locally-rendered VNC cursor
void hideLocalCursor();
void showLocalCursor();
void renderLocalCursor();
// The system-rendered cursor
void hideSystemCursor();
void showSystemCursor();
// cursorOutsideBuffer() is called whenever we detect that the mouse has
// moved outside the desktop. It restores the system arrow cursor.
void cursorOutsideBuffer();
// Returns true if part of the supplied rect is visible, false otherwise
bool invalidateBufferRect(const Rect& crect);
// Auto-encoding selector
void autoSelectFormatAndEncoding();
// Request an update with appropriate setPixelFormat and setEncodings calls
void requestNewUpdate();
// Update the window palette if the display is palette-based.
// Colours are pulled from the DIBSectionBuffer's ColourMap.
// Only the specified range of indexes is dealt with.
// After the update, the entire window is redrawn.
void refreshWindowPalette(int start, int count);
// Determine whether or not we need to enable/disable scrollbars and set the
// window style accordingly
void calculateScrollBars();
// Recalculate the most suitable full-colour pixel format
void calculateFullColourPF();
// Enable/disable/check/uncheck the F8 menu items as appropriate.
void updateF8Menu(bool hideSystemCommands);
// VNCviewer options
CViewOptions options;
// Input handling
void writeKeyEvent(rdr::U8 vkey, rdr::U32 flags, bool down);
void writePointerEvent(int x, int y, int buttonMask);
rfb::win32::CKeyboard kbd;
rfb::win32::CPointer ptr;
Point oldpos;
// Clipboard handling
rfb::win32::Clipboard clipboard;
// Pixel format and encoding
PixelFormat serverDefaultPF;
PixelFormat fullColourPF;
bool sameMachine;
bool encodingChange;
bool formatChange;
int lastUsedEncoding_;
// Networking and RFB protocol
network::Socket* sock;
bool readyToRead;
bool requestUpdate;
// Palette handling
LogicalPalette windowPalette;
bool palette_changed;
// - Full-screen mode
Rect fullScreenOldRect;
DWORD fullScreenOldFlags;
bool fullScreenActive;
// Bump-scrolling (used in full-screen mode)
bool bumpScroll;
Point bumpScrollDelta;
IntervalTimer bumpScrollTimer;
// Cursor handling
Cursor cursor;
bool systemCursorVisible; // Should system-cursor be drawn?
bool trackingMouseLeave;
bool cursorInBuffer; // Is cursor position within server buffer? (ONLY for LocalCursor)
bool cursorVisible; // Is cursor currently rendered?
bool cursorAvailable; // Is cursor available for rendering?
Point cursorPos;
ManagedPixelBuffer cursorBacking;
Rect cursorBackingRect;
// ** Debugging/logging
/*
int update_rect_count;
int update_pixel_count;
Rect update_extent;
*/
std::list<Rect> debugRects;
// Local window state
win32::DIBSectionBuffer* buffer;
bool has_focus;
bool quit_on_destroy;
Rect window_size;
Rect client_size;
Point scrolloffset;
Point maxscrolloffset;
HWND hwnd;
// Handle back to CViewManager instance, if any
CViewManager* manager;
};
};
};
#endif
|