blob: 293eb93b26c9d892ff7169146ead9290a61aef9b [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 Ossmand50b3d12011-04-15 07:46:56 +000028
29#include <rfb/Rect.h>
30#include <rfb/Region.h>
31#include <rfb/Timer.h>
32#include <rfb/PixelBuffer.h>
33#include <rfb/PixelTransformer.h>
34
35class CConn;
36
37class Viewport : public Fl_Widget {
38public:
39
40 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
41 ~Viewport();
42
43 // PixelFormat of incoming write operations
44 void setServerPF(const rfb::PixelFormat& pf);
45 // Most efficient format (from Viewport's point of view)
46 const rfb::PixelFormat &getPreferredPF();
47
48 // Flush updates to screen
49 void updateWindow();
50
51 // Methods forwarded from CConn
52 void setName(const char *name);
53
54 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
55
56 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
57 if (pixelTrans) {
58 rfb::Pixel pix2;
59 pixelTrans->translatePixels(&pix, &pix2, 1);
60 pix = pix2;
61 }
62
63 frameBuffer->fillRect(r, pix);
64 damageRect(r);
65 }
66 void imageRect(const rfb::Rect& r, void* pixels) {
67 if (pixelTrans)
68 pixelTrans->translateRect(pixels, r.width(),
69 rfb::Rect(0, 0, r.width(), r.height()),
70 frameBuffer->data, frameBuffer->getStride(),
71 r.tl);
72 else
73 frameBuffer->imageRect(r, pixels);
74 damageRect(r);
75 }
76 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
77 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
78 damageRect(r);
79 }
80
81 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000082
Pierre Ossmand50b3d12011-04-15 07:46:56 +000083 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000084
85 void resize(int x, int y, int w, int h);
86
Pierre Ossmand50b3d12011-04-15 07:46:56 +000087 int handle(int event);
88
89private:
90
91 void damageRect(const rfb::Rect& r) {
92 damage.assign_union(rfb::Region(r));
93 if (!Fl::has_timeout(handleUpdateTimeout, this))
94 Fl::add_timeout(0.100, handleUpdateTimeout, this);
95 };
96
97 static void handleUpdateTimeout(void *data);
98 static void handleColourMap(void *data);
99
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000100 static void handleClipboardChange(int source, void *data);
101
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000102 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
103 static void handlePointerTimeout(void *data);
104
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000105 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
106 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000107
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000108 void initContextMenu();
109 void popupContextMenu();
110
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000111 void setMenuKey();
112
113 static void handleOptions(void *data);
114
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000115private:
116 CConn* cc;
117
118 rfb::ManagedPixelBuffer* frameBuffer;
119
120 rfb::PixelTransformer *pixelTrans;
121 rfb::SimpleColourMap colourMap;
122
123 rfb::Region damage;
124
125 rfb::Point lastPointerPos;
126 int lastButtonMask;
127
128 typedef std::map<int, rdr::U32> DownMap;
129 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000130
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000131 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000132 Fl_Menu_Button *contextMenu;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000133};
134
135#endif