blob: d9eea353ba5548dda7c26c85b543d4accd0ec54a [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
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020025namespace rfb { class ModifiablePixelBuffer; }
Pierre Ossmand50b3d12011-04-15 07:46:56 +000026
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020027#include <FL/Fl_Widget.H>
Pierre Ossmanc18753c2011-06-17 07:35:56 +000028
Pierre Ossman769963f2014-01-20 14:43:52 +010029class Fl_Menu_Button;
30class Fl_RGB_Image;
31
Pierre Ossman947b48d2014-01-27 16:52:35 +010032namespace rfb { class PixelTransformer; }
33
Pierre Ossmand50b3d12011-04-15 07:46:56 +000034class CConn;
Pierre Ossman947b48d2014-01-27 16:52:35 +010035class PlatformPixelBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +000036
37class Viewport : public Fl_Widget {
38public:
39
40 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
41 ~Viewport();
42
Pierre Ossmand50b3d12011-04-15 07:46:56 +000043 // Most efficient format (from Viewport's point of view)
44 const rfb::PixelFormat &getPreferredPF();
45
46 // Flush updates to screen
47 void updateWindow();
48
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020049 // Return a pointer to the framebuffer for decoders to write into
50 rfb::ModifiablePixelBuffer* getFramebuffer(void);
Pierre Ossmand50b3d12011-04-15 07:46:56 +000051
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020052 // New image for the locally rendered cursor
Pierre Ossman835b4ef2011-06-08 17:02:36 +000053 void setCursor(int width, int height, const rfb::Point& hotspot,
54 void* data, void* mask);
55
Pierre Ossmand50b3d12011-04-15 07:46:56 +000056 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000057
Pierre Ossmand50b3d12011-04-15 07:46:56 +000058 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000059
60 void resize(int x, int y, int w, int h);
61
Pierre Ossmand50b3d12011-04-15 07:46:56 +000062 int handle(int event);
63
64private:
65
Pierre Ossmanac13abe2014-02-07 14:46:26 +010066 PlatformPixelBuffer* createFramebuffer(int w, int h);
67
Pierre Ossman4a6be4a2011-05-19 14:49:18 +000068 static void handleClipboardChange(int source, void *data);
69
Pierre Ossmand50b3d12011-04-15 07:46:56 +000070 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
71 static void handlePointerTimeout(void *data);
72
Pierre Ossman25188c42014-07-21 16:30:08 +020073 void handleKeyPress(int keyCode, rdr::U32 keySym);
74 void handleKeyRelease(int keyCode);
75
76 rdr::U32 translateKeyEvent(void);
77 void handleFLTKKeyPress(void);
Pierre Ossmand50b3d12011-04-15 07:46:56 +000078
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000079 void initContextMenu();
80 void popupContextMenu();
81
Pierre Ossman4e7271e2011-05-24 12:47:12 +000082 void setMenuKey();
83
84 static void handleOptions(void *data);
85
Pierre Ossmand50b3d12011-04-15 07:46:56 +000086private:
87 CConn* cc;
88
Pierre Ossman132b3d02011-06-13 11:19:32 +000089 PlatformPixelBuffer* frameBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +000090
91 rfb::Point lastPointerPos;
92 int lastButtonMask;
93
94 typedef std::map<int, rdr::U32> DownMap;
95 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000096
Pierre Ossman25188c42014-07-21 16:30:08 +020097 rdr::U32 menuKeySym;
Pierre Ossman4e7271e2011-05-24 12:47:12 +000098 int menuKeyCode;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000099 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000100
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000101 bool menuCtrlKey;
102 bool menuAltKey;
103
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000104 Fl_RGB_Image *cursor;
105 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000106};
107
108#endif