blob: e83a14ba5f55910b59e6fcb5ab9eb1901186a96f [file] [log] [blame]
Pierre Ossmand50b3d12011-04-15 07:46:56 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
3 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20#ifndef __VIEWPORT_H__
21#define __VIEWPORT_H__
22
23#include <map>
24
Pierre Ossmand50b3d12011-04-15 07:46:56 +000025#include <FL/Fl_Widget.H>
26
Pierre Ossmand50b3d12011-04-15 07:46:56 +000027#include <rfb/Region.h>
Pierre Ossman947b48d2014-01-27 16:52:35 +010028#include <rfb/Pixel.h>
29#include <rfb/ColourMap.h>
Pierre Ossmanc18753c2011-06-17 07:35:56 +000030
Pierre Ossman769963f2014-01-20 14:43:52 +010031class Fl_Menu_Button;
32class Fl_RGB_Image;
33
Pierre Ossman947b48d2014-01-27 16:52:35 +010034namespace rfb { class PixelTransformer; }
35
Pierre Ossmand50b3d12011-04-15 07:46:56 +000036class CConn;
Pierre Ossman947b48d2014-01-27 16:52:35 +010037class PlatformPixelBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +000038
39class Viewport : public Fl_Widget {
40public:
41
42 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
43 ~Viewport();
44
45 // PixelFormat of incoming write operations
46 void setServerPF(const rfb::PixelFormat& pf);
47 // Most efficient format (from Viewport's point of view)
48 const rfb::PixelFormat &getPreferredPF();
49
50 // Flush updates to screen
51 void updateWindow();
52
53 // Methods forwarded from CConn
Pierre Ossmand50b3d12011-04-15 07:46:56 +000054
55 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
56
Pierre Ossman947b48d2014-01-27 16:52:35 +010057 void fillRect(const rfb::Rect& r, rfb::Pixel pix);
58 void imageRect(const rfb::Rect& r, void* pixels);
59 void copyRect(const rfb::Rect& r, int srcX, int srcY);
Pierre Ossmand50b3d12011-04-15 07:46:56 +000060
Pierre Ossman947b48d2014-01-27 16:52:35 +010061 rdr::U8* getBufferRW(const rfb::Rect& r, int* stride);
Pierre Ossmand50b3d12011-04-15 07:46:56 +000062
Pierre Ossman947b48d2014-01-27 16:52:35 +010063 void damageRect(const rfb::Rect& r);
DRC33c15e32011-11-03 18:49:21 +000064
Pierre Ossman835b4ef2011-06-08 17:02:36 +000065 void setCursor(int width, int height, const rfb::Point& hotspot,
66 void* data, void* mask);
67
Pierre Ossmand50b3d12011-04-15 07:46:56 +000068 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000069
Pierre Ossmand50b3d12011-04-15 07:46:56 +000070 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000071
72 void resize(int x, int y, int w, int h);
73
Pierre Ossmand50b3d12011-04-15 07:46:56 +000074 int handle(int event);
75
76private:
77
Pierre Ossmand50b3d12011-04-15 07:46:56 +000078 static void handleUpdateTimeout(void *data);
Pierre Ossmanf3505452011-07-15 08:11:55 +000079
80 void commitColourMap();
Pierre Ossmand50b3d12011-04-15 07:46:56 +000081
Pierre Ossman4a6be4a2011-05-19 14:49:18 +000082 static void handleClipboardChange(int source, void *data);
83
Pierre Ossmand50b3d12011-04-15 07:46:56 +000084 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
85 static void handlePointerTimeout(void *data);
86
Pierre Ossmancd6ddef2011-05-20 12:05:20 +000087 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
88 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +000089
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000090 void initContextMenu();
91 void popupContextMenu();
92
Pierre Ossman4e7271e2011-05-24 12:47:12 +000093 void setMenuKey();
94
95 static void handleOptions(void *data);
96
Pierre Ossmand50b3d12011-04-15 07:46:56 +000097private:
98 CConn* cc;
99
Pierre Ossman132b3d02011-06-13 11:19:32 +0000100 PlatformPixelBuffer* frameBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000101
102 rfb::PixelTransformer *pixelTrans;
103 rfb::SimpleColourMap colourMap;
Pierre Ossmanf3505452011-07-15 08:11:55 +0000104 bool colourMapChange;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000105
106 rfb::Region damage;
107
108 rfb::Point lastPointerPos;
109 int lastButtonMask;
110
111 typedef std::map<int, rdr::U32> DownMap;
112 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000113
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000114 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000115 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000116
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000117 bool menuCtrlKey;
118 bool menuAltKey;
119
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000120 Fl_RGB_Image *cursor;
121 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000122};
123
124#endif