Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* 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> |
| 29 | #include <rfb/UserPasswdGetter.h> |
| 30 | #include <rfb_win32/Registry.h> |
| 31 | #include <rfb_win32/Handle.h> |
| 32 | #include <vncviewer/InfoDialog.h> |
| 33 | #include <vncviewer/OptionsDialog.h> |
| 34 | #include <vncviewer/CConnOptions.h> |
| 35 | #include <vncviewer/DesktopWindow.h> |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 36 | #include <list> |
| 37 | |
| 38 | |
| 39 | namespace rfb { |
| 40 | |
| 41 | namespace win32 { |
| 42 | |
| 43 | class CConn : public CConnection, |
| 44 | UserPasswdGetter, |
| 45 | DesktopWindow::Callback, |
| 46 | rdr::FdInStreamBlockCallback |
| 47 | { |
| 48 | public: |
| 49 | CConn(); |
| 50 | ~CConn(); |
| 51 | |
| 52 | // - Start the VNC session on the supplied socket |
| 53 | // The socket must already be connected to a host |
| 54 | bool initialise(network::Socket* s, bool reverse=false); |
| 55 | |
| 56 | // - Set/get the session options |
| 57 | void applyOptions(CConnOptions& opt); |
| 58 | const CConnOptions& getOptions() const { return options; }; |
| 59 | |
| 60 | // - Show the options dialog for the connection |
| 61 | void showOptionsDialog(); |
| 62 | |
| 63 | // - Close the socket & set the reason for closure |
| 64 | void close(const char* reason=0); |
| 65 | bool isClosed() const { return isClosed_; } |
| 66 | const char* closeReason() const { return closeReason_.buf; } |
| 67 | |
| 68 | // - Last received encoding, for the Info dialog |
| 69 | int lastUsedEncoding() const { return lastUsedEncoding_; } |
| 70 | |
| 71 | // - Get at the DesktopWindow, if any |
| 72 | DesktopWindow* getWindow() { return window; } |
| 73 | |
| 74 | // - Get at the underlying Socket |
| 75 | network::Socket* getSocket() { return sock; } |
| 76 | |
| 77 | // - Get the server's preferred format |
| 78 | const PixelFormat& getServerDefaultPF() const { return serverDefaultPF; } |
| 79 | |
| 80 | // Global user-config registry key |
| 81 | static RegKey userConfigKey; |
| 82 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 83 | protected: |
| 84 | // InputHandler interface (via DesktopWindow::Callback) |
| 85 | void keyEvent(rdr::U32 key, bool down); |
| 86 | void pointerEvent(const Point& pos, int buttonMask); |
| 87 | void clientCutText(const char* str, int len); |
| 88 | |
| 89 | // DesktopWindow::Callback interface |
| 90 | void displayChanged(); |
| 91 | void paintCompleted(); |
| 92 | bool sysCommand(WPARAM wParam, LPARAM lParam); |
| 93 | void closeWindow(); |
| 94 | void refreshMenu(bool enableSysCommands); |
| 95 | |
| 96 | // CConnection interface |
| 97 | CSecurity* getCSecurity(int secType); |
| 98 | void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs); |
| 99 | void bell(); |
Adam Tkac | c184d95 | 2009-06-16 10:50:06 +0000 | [diff] [blame] | 100 | void framebufferUpdateStart() {} |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 101 | void framebufferUpdateEnd(); |
| 102 | void setDesktopSize(int w, int h); |
Pierre Ossman | d6d1994 | 2009-03-24 12:29:50 +0000 | [diff] [blame] | 103 | void setExtendedDesktopSize(int reason, int result, int w, int h, |
| 104 | const rfb::ScreenSet& layout); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 105 | void setCursor(int w, int h, const Point& hotspot, void* data, void* mask); |
| 106 | void setName(const char* name); |
| 107 | void serverInit(); |
Adam Tkac | acf6c6b | 2009-02-13 12:42:05 +0000 | [diff] [blame] | 108 | void serverCutText(const char* str, rdr::U32 len); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 109 | void beginRect(const Rect& r, unsigned int encoding); |
| 110 | void endRect(const Rect& r, unsigned int encoding); |
| 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 | // rdr::FdInStreamBlockCallback interface |
| 116 | void blockCallback(); |
| 117 | |
| 118 | // UserPasswdGetter interface |
| 119 | // (overridden to allow a pre-supplied username & password) |
| 120 | void getUserPasswd(char** user, char** password); |
| 121 | |
| 122 | // CConn-specific internal interface |
| 123 | void autoSelectFormatAndEncoding(); |
| 124 | void requestNewUpdate(); |
| 125 | void calculateFullColourPF(); |
| 126 | |
| 127 | // The desktop window |
| 128 | DesktopWindow* window; |
| 129 | |
| 130 | // Info and Options dialogs |
| 131 | OptionsDialog optionsDialog; |
| 132 | InfoDialog infoDialog; |
| 133 | |
| 134 | // VNC Viewer options |
| 135 | CConnOptions options; |
| 136 | |
| 137 | // Pixel format and encoding |
| 138 | PixelFormat serverDefaultPF; |
| 139 | PixelFormat fullColourPF; |
| 140 | bool sameMachine; |
| 141 | bool encodingChange; |
| 142 | bool formatChange; |
| 143 | int lastUsedEncoding_; |
| 144 | |
| 145 | // Networking and RFB protocol |
| 146 | network::Socket* sock; |
| 147 | Handle sockEvent; |
| 148 | bool reverseConnection; |
| 149 | bool requestUpdate; |
Pierre Ossman | d6d1994 | 2009-03-24 12:29:50 +0000 | [diff] [blame] | 150 | bool firstUpdate; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 151 | |
| 152 | // Debugging/logging |
| 153 | std::list<Rect> debugRects; |
| 154 | CharArray closeReason_; |
| 155 | bool isClosed_; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | }; |
| 159 | |
| 160 | }; |
| 161 | |
| 162 | #endif |
| 163 | |
| 164 | |