blob: bf54c211dad3bf4ac73b7c44df9d7dd3bdadc682 [file] [log] [blame]
Pierre Ossman5156d5e2011-03-09 09:42:34 +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 __DESKTOPWINDOW_H__
21#define __DESKTOPWINDOW_H__
22
Pierre Ossmand7c5b042011-04-14 14:05:13 +000023#include <map>
24
Pierre Ossman5156d5e2011-03-09 09:42:34 +000025#include <FL/Fl.H>
26#include <FL/Fl_Window.H>
27
28#include <rfb/Rect.h>
29#include <rfb/Region.h>
30#include <rfb/Timer.h>
31#include <rfb/PixelBuffer.h>
32#include <rfb/PixelTransformer.h>
33
34class CConn;
35
36class DesktopWindow : public Fl_Window {
37public:
38
39 DesktopWindow(int w, int h, const char *name,
40 const rfb::PixelFormat& serverPF, CConn* cc_);
41 ~DesktopWindow();
42
43 // PixelFormat of incoming write operations
44 void setServerPF(const rfb::PixelFormat& pf);
45 // Most efficient format (from DesktopWindow's point of view)
46 const rfb::PixelFormat &getPreferredPF();
47
48 // setCursor() sets the shape of the local cursor
49 void setCursor(int width, int height, const rfb::Point& hotspot,
50 void* data, void* mask);
51
52 // Flush updates to screen
53 void updateWindow();
54
55 // Methods forwarded from CConn
56 void setName(const char *name);
57
58 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
59
60 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
61 if (pixelTrans) {
62 rfb::Pixel pix2;
63 pixelTrans->translatePixels(&pix, &pix2, 1);
64 pix = pix2;
65 }
66
67 frameBuffer->fillRect(r, pix);
68 damageRect(r);
69 }
70 void imageRect(const rfb::Rect& r, void* pixels) {
71 if (pixelTrans)
72 pixelTrans->translateRect(pixels, r.width(),
73 rfb::Rect(0, 0, r.width(), r.height()),
74 frameBuffer->data, frameBuffer->getStride(),
75 r.tl);
76 else
77 frameBuffer->imageRect(r, pixels);
78 damageRect(r);
79 }
80 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
81 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
82 damageRect(r);
83 }
84
85 // Fl_Window callback methods
86 void draw();
Pierre Ossmanc266e5a2011-03-09 10:24:12 +000087 int handle(int event);
Pierre Ossman5156d5e2011-03-09 09:42:34 +000088
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
100 static void handleClose(Fl_Widget *wnd, void *data);
101
Pierre Ossmanc266e5a2011-03-09 10:24:12 +0000102 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
103 static void handlePointerTimeout(void *data);
104
Pierre Ossman98486c12011-03-10 11:39:42 +0000105 rdr::U32 translateKeyEvent(int keyCode, const char *keyText);
Pierre Ossmand014d052011-03-09 13:28:12 +0000106 void handleKeyEvent(int keyCode, const char *keyText, bool down);
107
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000108private:
109 CConn* cc;
110
111 rfb::ManagedPixelBuffer* frameBuffer;
112
113 rfb::PixelTransformer *pixelTrans;
114 rfb::SimpleColourMap colourMap;
115
116 rfb::Region damage;
Pierre Ossmanc266e5a2011-03-09 10:24:12 +0000117
118 rfb::Point lastPointerPos;
119 int lastButtonMask;
Pierre Ossmand014d052011-03-09 13:28:12 +0000120
Pierre Ossmand7c5b042011-04-14 14:05:13 +0000121 typedef std::map<int, rdr::U32> DownMap;
122 DownMap downKeySym;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000123};
124
125#endif