blob: b8f1a78968da3bb3040b89a449622f45b6120e2d [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>
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000027#include <FL/Fl_Menu_Button.H>
Pierre Ossman835b4ef2011-06-08 17:02:36 +000028#include <FL/Fl_RGB_Image.H>
Pierre Ossmand50b3d12011-04-15 07:46:56 +000029
30#include <rfb/Rect.h>
31#include <rfb/Region.h>
32#include <rfb/Timer.h>
33#include <rfb/PixelBuffer.h>
34#include <rfb/PixelTransformer.h>
35
36class CConn;
37
38class Viewport : public Fl_Widget {
39public:
40
41 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
42 ~Viewport();
43
44 // PixelFormat of incoming write operations
45 void setServerPF(const rfb::PixelFormat& pf);
46 // Most efficient format (from Viewport's point of view)
47 const rfb::PixelFormat &getPreferredPF();
48
49 // Flush updates to screen
50 void updateWindow();
51
52 // Methods forwarded from CConn
53 void setName(const char *name);
54
55 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
56
57 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
58 if (pixelTrans) {
59 rfb::Pixel pix2;
60 pixelTrans->translatePixels(&pix, &pix2, 1);
61 pix = pix2;
62 }
63
64 frameBuffer->fillRect(r, pix);
65 damageRect(r);
66 }
67 void imageRect(const rfb::Rect& r, void* pixels) {
68 if (pixelTrans)
69 pixelTrans->translateRect(pixels, r.width(),
70 rfb::Rect(0, 0, r.width(), r.height()),
71 frameBuffer->data, frameBuffer->getStride(),
72 r.tl);
73 else
74 frameBuffer->imageRect(r, pixels);
75 damageRect(r);
76 }
77 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
78 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
79 damageRect(r);
80 }
81
Pierre Ossman835b4ef2011-06-08 17:02:36 +000082 void setCursor(int width, int height, const rfb::Point& hotspot,
83 void* data, void* mask);
84
Pierre Ossmand50b3d12011-04-15 07:46:56 +000085 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000086
Pierre Ossmand50b3d12011-04-15 07:46:56 +000087 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000088
89 void resize(int x, int y, int w, int h);
90
Pierre Ossmand50b3d12011-04-15 07:46:56 +000091 int handle(int event);
92
93private:
94
95 void damageRect(const rfb::Rect& r) {
96 damage.assign_union(rfb::Region(r));
97 if (!Fl::has_timeout(handleUpdateTimeout, this))
98 Fl::add_timeout(0.100, handleUpdateTimeout, this);
99 };
100
101 static void handleUpdateTimeout(void *data);
102 static void handleColourMap(void *data);
103
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000104 static void handleClipboardChange(int source, void *data);
105
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000106 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
107 static void handlePointerTimeout(void *data);
108
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000109 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
110 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000111
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000112 void initContextMenu();
113 void popupContextMenu();
114
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000115 void setMenuKey();
116
117 static void handleOptions(void *data);
118
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000119private:
120 CConn* cc;
121
122 rfb::ManagedPixelBuffer* frameBuffer;
123
124 rfb::PixelTransformer *pixelTrans;
125 rfb::SimpleColourMap colourMap;
126
127 rfb::Region damage;
128
129 rfb::Point lastPointerPos;
130 int lastButtonMask;
131
132 typedef std::map<int, rdr::U32> DownMap;
133 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000134
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000135 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000136 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000137
138 Fl_RGB_Image *cursor;
139 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000140};
141
142#endif