blob: 24d0f3c057ae0b32355364f03599ff29a5926c67 [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
82 void draw();
83 int handle(int event);
84
85private:
86
87 void damageRect(const rfb::Rect& r) {
88 damage.assign_union(rfb::Region(r));
89 if (!Fl::has_timeout(handleUpdateTimeout, this))
90 Fl::add_timeout(0.100, handleUpdateTimeout, this);
91 };
92
93 static void handleUpdateTimeout(void *data);
94 static void handleColourMap(void *data);
95
Pierre Ossman4a6be4a2011-05-19 14:49:18 +000096 static void handleClipboardChange(int source, void *data);
97
Pierre Ossmand50b3d12011-04-15 07:46:56 +000098 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
99 static void handlePointerTimeout(void *data);
100
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000101 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
102 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000103
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000104 void initContextMenu();
105 void popupContextMenu();
106
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000107private:
108 CConn* cc;
109
110 rfb::ManagedPixelBuffer* frameBuffer;
111
112 rfb::PixelTransformer *pixelTrans;
113 rfb::SimpleColourMap colourMap;
114
115 rfb::Region damage;
116
117 rfb::Point lastPointerPos;
118 int lastButtonMask;
119
120 typedef std::map<int, rdr::U32> DownMap;
121 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000122
123 Fl_Menu_Button *contextMenu;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000124};
125
126#endif