blob: 9eb3b73cbab35c4b53948ea58bb34f7fc41a2090 [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__)
Pierre Ossmanc18753c2011-06-17 07:35:56 +000039#include "OSXPixelBuffer.h"
Pierre Ossman132b3d02011-06-13 11:19:32 +000040#else
Pierre Ossman13500692011-06-13 11:23:08 +000041#include "X11PixelBuffer.h"
Pierre Ossman132b3d02011-06-13 11:19:32 +000042#endif
43
Pierre Ossmanc18753c2011-06-17 07:35:56 +000044// We also have a generic version of the above, using pure FLTK:
45//
46// #include "PlatformPixelBuffer.h"
47//
48
Pierre Ossmand50b3d12011-04-15 07:46:56 +000049class CConn;
50
51class Viewport : public Fl_Widget {
52public:
53
54 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
55 ~Viewport();
56
57 // PixelFormat of incoming write operations
58 void setServerPF(const rfb::PixelFormat& pf);
59 // Most efficient format (from Viewport's point of view)
60 const rfb::PixelFormat &getPreferredPF();
61
62 // Flush updates to screen
63 void updateWindow();
64
65 // Methods forwarded from CConn
66 void setName(const char *name);
67
68 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
69
70 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
71 if (pixelTrans) {
72 rfb::Pixel pix2;
73 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) {
81 if (pixelTrans)
82 pixelTrans->translateRect(pixels, r.width(),
83 rfb::Rect(0, 0, r.width(), r.height()),
84 frameBuffer->data, frameBuffer->getStride(),
85 r.tl);
86 else
87 frameBuffer->imageRect(r, pixels);
88 damageRect(r);
89 }
90 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
91 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
92 damageRect(r);
93 }
94
Pierre Ossman835b4ef2011-06-08 17:02:36 +000095 void setCursor(int width, int height, const rfb::Point& hotspot,
96 void* data, void* mask);
97
Pierre Ossmand50b3d12011-04-15 07:46:56 +000098 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000099
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000100 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +0000101
102 void resize(int x, int y, int w, int h);
103
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000104 int handle(int event);
105
106private:
107
108 void damageRect(const rfb::Rect& r) {
109 damage.assign_union(rfb::Region(r));
110 if (!Fl::has_timeout(handleUpdateTimeout, this))
Pierre Ossmandb7091c2011-06-13 15:08:35 +0000111 Fl::add_timeout(0.500, handleUpdateTimeout, this);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000112 };
113
114 static void handleUpdateTimeout(void *data);
115 static void handleColourMap(void *data);
116
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000117 static void handleClipboardChange(int source, void *data);
118
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000119 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
120 static void handlePointerTimeout(void *data);
121
Pierre Ossmancd6ddef2011-05-20 12:05:20 +0000122 rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
123 void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000124
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000125 void initContextMenu();
126 void popupContextMenu();
127
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000128 void setMenuKey();
129
130 static void handleOptions(void *data);
131
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000132private:
133 CConn* cc;
134
Pierre Ossman132b3d02011-06-13 11:19:32 +0000135 PlatformPixelBuffer* frameBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000136
137 rfb::PixelTransformer *pixelTrans;
138 rfb::SimpleColourMap colourMap;
139
140 rfb::Region damage;
141
142 rfb::Point lastPointerPos;
143 int lastButtonMask;
144
145 typedef std::map<int, rdr::U32> DownMap;
146 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000147
Pierre Ossman4e7271e2011-05-24 12:47:12 +0000148 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000149 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000150
151 Fl_RGB_Image *cursor;
152 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000153};
154
155#endif