blob: 0410fb8a6f541589564a6c0503b9aec8c90b00a5 [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
64 void setName(const char *name);
65
66 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
67
68 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
69 if (pixelTrans) {
70 rfb::Pixel pix2;
Pierre Ossmanf3505452011-07-15 08:11:55 +000071 if (colourMapChange)
72 commitColourMap();
Pierre Ossmand50b3d12011-04-15 07:46:56 +000073 pixelTrans->translatePixels(&pix, &pix2, 1);
74 pix = pix2;
75 }
76
77 frameBuffer->fillRect(r, pix);
78 damageRect(r);
79 }
80 void imageRect(const rfb::Rect& r, void* pixels) {
Pierre Ossmanf3505452011-07-15 08:11:55 +000081 if (pixelTrans) {
82 if (colourMapChange)
83 commitColourMap();
Pierre Ossmand50b3d12011-04-15 07:46:56 +000084 pixelTrans->translateRect(pixels, r.width(),
85 rfb::Rect(0, 0, r.width(), r.height()),
86 frameBuffer->data, frameBuffer->getStride(),
87 r.tl);
Pierre Ossmanf3505452011-07-15 08:11:55 +000088 } else {
Pierre Ossmand50b3d12011-04-15 07:46:56 +000089 frameBuffer->imageRect(r, pixels);
Pierre Ossmanf3505452011-07-15 08:11:55 +000090 }
Pierre Ossmand50b3d12011-04-15 07:46:56 +000091 damageRect(r);
92 }
93 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
94 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
95 damageRect(r);
96 }
97
DRC33c15e32011-11-03 18:49:21 +000098 rdr::U8* getPixelsRW(const rfb::Rect& r, int* stride) {
99 return frameBuffer->getPixelsRW(r, stride);
100 }
101
102 void damageRect(const rfb::Rect& r) {
103 damage.assign_union(rfb::Region(r));
104 if (!Fl::has_timeout(handleUpdateTimeout, this))
105 Fl::add_timeout(0.500, handleUpdateTimeout, this);
106 };
107
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000108 void setCursor(int width, int height, const rfb::Point& hotspot,
109 void* data, void* mask);
110
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000111 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000112
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000113 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000114
115 void resize(int x, int y, int w, int h);
116
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000117 int handle(int event);
118
119private:
120
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000121 static void handleUpdateTimeout(void *data);
Pierre Ossmanf3505452011-07-15 08:11:55 +0000122
123 void commitColourMap();
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000124
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000125 static void handleClipboardChange(int source, void *data);
126
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000127 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
128 static void handlePointerTimeout(void *data);
129
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000130 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
131 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000132
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000133 void initContextMenu();
134 void popupContextMenu();
135
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000136 void setMenuKey();
137
138 static void handleOptions(void *data);
139
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000140private:
141 CConn* cc;
142
Pierre Ossman132b3d02011-06-13 11:19:32 +0000143 PlatformPixelBuffer* frameBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000144
145 rfb::PixelTransformer *pixelTrans;
146 rfb::SimpleColourMap colourMap;
Pierre Ossmanf3505452011-07-15 08:11:55 +0000147 bool colourMapChange;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000148
149 rfb::Region damage;
150
151 rfb::Point lastPointerPos;
152 int lastButtonMask;
153
154 typedef std::map<int, rdr::U32> DownMap;
155 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000156
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000157 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000158 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000159
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000160 bool menuCtrlKey;
161 bool menuAltKey;
162
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000163 Fl_RGB_Image *cursor;
164 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000165};
166
167#endif