blob: 19b95a3047a8b9116d9f563f7d62405e8ab9bb30 [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
Pierre Ossman132b3d02011-06-13 11:19:32 +000036#if defined(WIN32)
Pierre Ossmanb4cb8762011-06-13 13:24:29 +000037#include "Win32PixelBuffer.h"
Pierre Ossman132b3d02011-06-13 11:19:32 +000038#elif defined(__APPLE__)
39#include "PlatformPixelBuffer.h"
40#else
Pierre Ossman13500692011-06-13 11:23:08 +000041#include "X11PixelBuffer.h"
Pierre Ossman132b3d02011-06-13 11:19:32 +000042#endif
43
Pierre Ossmand50b3d12011-04-15 07:46:56 +000044class CConn;
45
46class Viewport : public Fl_Widget {
47public:
48
49 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
50 ~Viewport();
51
52 // PixelFormat of incoming write operations
53 void setServerPF(const rfb::PixelFormat& pf);
54 // Most efficient format (from Viewport's point of view)
55 const rfb::PixelFormat &getPreferredPF();
56
57 // Flush updates to screen
58 void updateWindow();
59
60 // Methods forwarded from CConn
61 void setName(const char *name);
62
63 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
64
65 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
66 if (pixelTrans) {
67 rfb::Pixel pix2;
68 pixelTrans->translatePixels(&pix, &pix2, 1);
69 pix = pix2;
70 }
71
72 frameBuffer->fillRect(r, pix);
73 damageRect(r);
74 }
75 void imageRect(const rfb::Rect& r, void* pixels) {
76 if (pixelTrans)
77 pixelTrans->translateRect(pixels, r.width(),
78 rfb::Rect(0, 0, r.width(), r.height()),
79 frameBuffer->data, frameBuffer->getStride(),
80 r.tl);
81 else
82 frameBuffer->imageRect(r, pixels);
83 damageRect(r);
84 }
85 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
86 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
87 damageRect(r);
88 }
89
Pierre Ossman835b4ef2011-06-08 17:02:36 +000090 void setCursor(int width, int height, const rfb::Point& hotspot,
91 void* data, void* mask);
92
Pierre Ossmand50b3d12011-04-15 07:46:56 +000093 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000094
Pierre Ossmand50b3d12011-04-15 07:46:56 +000095 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000096
97 void resize(int x, int y, int w, int h);
98
Pierre Ossmand50b3d12011-04-15 07:46:56 +000099 int handle(int event);
100
101private:
102
103 void damageRect(const rfb::Rect& r) {
104 damage.assign_union(rfb::Region(r));
105 if (!Fl::has_timeout(handleUpdateTimeout, this))
106 Fl::add_timeout(0.100, handleUpdateTimeout, this);
107 };
108
109 static void handleUpdateTimeout(void *data);
110 static void handleColourMap(void *data);
111
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000112 static void handleClipboardChange(int source, void *data);
113
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000114 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
115 static void handlePointerTimeout(void *data);
116
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000117 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
118 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000119
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000120 void initContextMenu();
121 void popupContextMenu();
122
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000123 void setMenuKey();
124
125 static void handleOptions(void *data);
126
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000127private:
128 CConn* cc;
129
Pierre Ossman132b3d02011-06-13 11:19:32 +0000130 PlatformPixelBuffer* frameBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000131
132 rfb::PixelTransformer *pixelTrans;
133 rfb::SimpleColourMap colourMap;
134
135 rfb::Region damage;
136
137 rfb::Point lastPointerPos;
138 int lastButtonMask;
139
140 typedef std::map<int, rdr::U32> DownMap;
141 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000142
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000143 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000144 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000145
146 Fl_RGB_Image *cursor;
147 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000148};
149
150#endif