blob: 59839dcbf900b80f0a099cd17c55ac96f85433e0 [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
25#include <FL/Fl.H>
26#include <FL/Fl_Widget.H>
27
Pierre Ossmand50b3d12011-04-15 07:46:56 +000028#include <rfb/Region.h>
Pierre Ossmand50b3d12011-04-15 07:46:56 +000029#include <rfb/PixelTransformer.h>
30
Pierre Ossman132b3d02011-06-13 11:19:32 +000031#if defined(WIN32)
Pierre Ossmanb4cb8762011-06-13 13:24:29 +000032#include "Win32PixelBuffer.h"
Pierre Ossman132b3d02011-06-13 11:19:32 +000033#elif defined(__APPLE__)
Pierre Ossmanc18753c2011-06-17 07:35:56 +000034#include "OSXPixelBuffer.h"
Pierre Ossman132b3d02011-06-13 11:19:32 +000035#else
Pierre Ossman13500692011-06-13 11:23:08 +000036#include "X11PixelBuffer.h"
Pierre Ossman132b3d02011-06-13 11:19:32 +000037#endif
38
Pierre Ossmanc18753c2011-06-17 07:35:56 +000039// We also have a generic version of the above, using pure FLTK:
40//
41// #include "PlatformPixelBuffer.h"
42//
43
Pierre Ossman769963f2014-01-20 14:43:52 +010044class Fl_Menu_Button;
45class Fl_RGB_Image;
46
Pierre Ossmand50b3d12011-04-15 07:46:56 +000047class CConn;
48
49class Viewport : public Fl_Widget {
50public:
51
52 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
53 ~Viewport();
54
55 // PixelFormat of incoming write operations
56 void setServerPF(const rfb::PixelFormat& pf);
57 // Most efficient format (from Viewport's point of view)
58 const rfb::PixelFormat &getPreferredPF();
59
60 // Flush updates to screen
61 void updateWindow();
62
63 // Methods forwarded from CConn
Pierre Ossmand50b3d12011-04-15 07:46:56 +000064
65 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
66
67 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
68 if (pixelTrans) {
69 rfb::Pixel pix2;
Pierre Ossmanf3505452011-07-15 08:11:55 +000070 if (colourMapChange)
71 commitColourMap();
Pierre Ossmand50b3d12011-04-15 07:46:56 +000072 pixelTrans->translatePixels(&pix, &pix2, 1);
73 pix = pix2;
74 }
75
76 frameBuffer->fillRect(r, pix);
77 damageRect(r);
78 }
79 void imageRect(const rfb::Rect& r, void* pixels) {
Pierre Ossmanf3505452011-07-15 08:11:55 +000080 if (pixelTrans) {
81 if (colourMapChange)
82 commitColourMap();
Pierre Ossmand50b3d12011-04-15 07:46:56 +000083 pixelTrans->translateRect(pixels, r.width(),
84 rfb::Rect(0, 0, r.width(), r.height()),
85 frameBuffer->data, frameBuffer->getStride(),
86 r.tl);
Pierre Ossmanf3505452011-07-15 08:11:55 +000087 } else {
Pierre Ossmand50b3d12011-04-15 07:46:56 +000088 frameBuffer->imageRect(r, pixels);
Pierre Ossmanf3505452011-07-15 08:11:55 +000089 }
Pierre Ossmand50b3d12011-04-15 07:46:56 +000090 damageRect(r);
91 }
92 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
93 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
94 damageRect(r);
95 }
96
Pierre Ossman945cdda2014-01-28 14:13:12 +010097 rdr::U8* getBufferRW(const rfb::Rect& r, int* stride) {
98 return frameBuffer->getBufferRW(r, stride);
DRC33c15e32011-11-03 18:49:21 +000099 }
100
101 void damageRect(const rfb::Rect& r) {
102 damage.assign_union(rfb::Region(r));
103 if (!Fl::has_timeout(handleUpdateTimeout, this))
104 Fl::add_timeout(0.500, handleUpdateTimeout, this);
105 };
106
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000107 void setCursor(int width, int height, const rfb::Point& hotspot,
108 void* data, void* mask);
109
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000110 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000111
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000112 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000113
114 void resize(int x, int y, int w, int h);
115
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000116 int handle(int event);
117
118private:
119
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000120 static void handleUpdateTimeout(void *data);
Pierre Ossmanf3505452011-07-15 08:11:55 +0000121
122 void commitColourMap();
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000123
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000124 static void handleClipboardChange(int source, void *data);
125
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000126 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
127 static void handlePointerTimeout(void *data);
128
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000129 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
130 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000131
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000132 void initContextMenu();
133 void popupContextMenu();
134
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000135 void setMenuKey();
136
137 static void handleOptions(void *data);
138
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000139private:
140 CConn* cc;
141
Pierre Ossman132b3d02011-06-13 11:19:32 +0000142 PlatformPixelBuffer* frameBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000143
144 rfb::PixelTransformer *pixelTrans;
145 rfb::SimpleColourMap colourMap;
Pierre Ossmanf3505452011-07-15 08:11:55 +0000146 bool colourMapChange;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000147
148 rfb::Region damage;
149
150 rfb::Point lastPointerPos;
151 int lastButtonMask;
152
153 typedef std::map<int, rdr::U32> DownMap;
154 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000155
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000156 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000157 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000158
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000159 bool menuCtrlKey;
160 bool menuAltKey;
161
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000162 Fl_RGB_Image *cursor;
163 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000164};
165
166#endif