blob: d3b3b20632faa42072253828787d29fcf6d55b39 [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// -=- CConn.h
20
21// Windows-specific implementation of CConnection
22
23#ifndef __RFB_WIN32_CCONN_H__
24#define __RFB_WIN32_CCONN_H__
25
26#include <network/Socket.h>
27#include <rfb/CConnection.h>
28#include <rfb/Cursor.h>
Adam Tkac243fd7c2010-12-08 13:47:41 +000029#include <rfb/UserMsgBox.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000030#include <rfb/UserPasswdGetter.h>
31#include <rfb_win32/Registry.h>
32#include <rfb_win32/Handle.h>
33#include <vncviewer/InfoDialog.h>
34#include <vncviewer/OptionsDialog.h>
35#include <vncviewer/CConnOptions.h>
36#include <vncviewer/DesktopWindow.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000037#include <list>
38
39
40namespace rfb {
41
42 namespace win32 {
43
44 class CConn : public CConnection,
45 UserPasswdGetter,
46 DesktopWindow::Callback,
Adam Tkac243fd7c2010-12-08 13:47:41 +000047 rdr::FdInStreamBlockCallback,
48 UserMsgBox
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000049 {
50 public:
51 CConn();
52 ~CConn();
53
54 // - Start the VNC session on the supplied socket
55 // The socket must already be connected to a host
56 bool initialise(network::Socket* s, bool reverse=false);
57
58 // - Set/get the session options
59 void applyOptions(CConnOptions& opt);
60 const CConnOptions& getOptions() const { return options; };
61
62 // - Show the options dialog for the connection
63 void showOptionsDialog();
64
65 // - Close the socket & set the reason for closure
66 void close(const char* reason=0);
67 bool isClosed() const { return isClosed_; }
68 const char* closeReason() const { return closeReason_.buf; }
69
70 // - Last received encoding, for the Info dialog
71 int lastUsedEncoding() const { return lastUsedEncoding_; }
72
73 // - Get at the DesktopWindow, if any
74 DesktopWindow* getWindow() { return window; }
75
76 // - Get at the underlying Socket
77 network::Socket* getSocket() { return sock; }
78
79 // - Get the server's preferred format
80 const PixelFormat& getServerDefaultPF() const { return serverDefaultPF; }
81
Adam Tkac243fd7c2010-12-08 13:47:41 +000082 // - Display message box
83 virtual bool showMsgBox(int flags, const char* title, const char* text);
84
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000085 // Global user-config registry key
86 static RegKey userConfigKey;
87
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000088 protected:
89 // InputHandler interface (via DesktopWindow::Callback)
90 void keyEvent(rdr::U32 key, bool down);
91 void pointerEvent(const Point& pos, int buttonMask);
92 void clientCutText(const char* str, int len);
93
94 // DesktopWindow::Callback interface
95 void displayChanged();
Adam Tkacf586b842011-04-27 11:20:18 +000096 void paintCompleted() {}
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000097 bool sysCommand(WPARAM wParam, LPARAM lParam);
98 void closeWindow();
99 void refreshMenu(bool enableSysCommands);
100
101 // CConnection interface
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000102 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
103 void bell();
Adam Tkacf586b842011-04-27 11:20:18 +0000104 void framebufferUpdateStart();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000105 void framebufferUpdateEnd();
106 void setDesktopSize(int w, int h);
Pierre Ossmand6d19942009-03-24 12:29:50 +0000107 void setExtendedDesktopSize(int reason, int result, int w, int h,
108 const rfb::ScreenSet& layout);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000109 void setCursor(int w, int h, const Point& hotspot, void* data, void* mask);
110 void setName(const char* name);
111 void serverInit();
Adam Tkacacf6c6b2009-02-13 12:42:05 +0000112 void serverCutText(const char* str, rdr::U32 len);
Peter Åstrand98fe98c2010-02-10 07:43:02 +0000113 void beginRect(const Rect& r, int encoding);
114 void endRect(const Rect& r, int encoding);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000115 void fillRect(const Rect& r, Pixel pix);
116 void imageRect(const Rect& r, void* pixels);
117 void copyRect(const Rect& r, int srcX, int srcY);
118
119 // rdr::FdInStreamBlockCallback interface
120 void blockCallback();
121
122 // UserPasswdGetter interface
123 // (overridden to allow a pre-supplied username & password)
124 void getUserPasswd(char** user, char** password);
125
126 // CConn-specific internal interface
127 void autoSelectFormatAndEncoding();
128 void requestNewUpdate();
129 void calculateFullColourPF();
130
131 // The desktop window
132 DesktopWindow* window;
133
134 // Info and Options dialogs
135 OptionsDialog optionsDialog;
136 InfoDialog infoDialog;
137
138 // VNC Viewer options
139 CConnOptions options;
140
141 // Pixel format and encoding
142 PixelFormat serverDefaultPF;
143 PixelFormat fullColourPF;
144 bool sameMachine;
145 bool encodingChange;
146 bool formatChange;
147 int lastUsedEncoding_;
148
149 // Networking and RFB protocol
150 network::Socket* sock;
151 Handle sockEvent;
152 bool reverseConnection;
153 bool requestUpdate;
Pierre Ossmand6d19942009-03-24 12:29:50 +0000154 bool firstUpdate;
Adam Tkacf586b842011-04-27 11:20:18 +0000155 bool pendingUpdate;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000156
157 // Debugging/logging
158 std::list<Rect> debugRects;
159 CharArray closeReason_;
160 bool isClosed_;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000161 };
162
163 };
164
165};
166
167#endif
168
169