blob: d9d73a8ef7a693353354689f0f2330e20d22e431 [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 Ossman59da99f2016-02-05 10:43:12 +010025#include <rfb/Rect.h>
26
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 Ossmand50b3d12011-04-15 07:46:56 +000032class CConn;
Pierre Ossman947b48d2014-01-27 16:52:35 +010033class PlatformPixelBuffer;
Pierre Ossman3d74d882017-01-02 19:49:52 +010034class Surface;
Pierre Ossmand50b3d12011-04-15 07:46:56 +000035
36class Viewport : public Fl_Widget {
37public:
38
39 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
40 ~Viewport();
41
Pierre Ossmand50b3d12011-04-15 07:46:56 +000042 // Most efficient format (from Viewport's point of view)
43 const rfb::PixelFormat &getPreferredPF();
44
45 // Flush updates to screen
46 void updateWindow();
47
Pierre Ossman4c204232018-03-26 13:32:49 +020048 // Incoming clipboard from server
49 void serverCutText(const char* str, rdr::U32 len);
50
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020051 // New image for the locally rendered cursor
Pierre Ossman835b4ef2011-06-08 17:02:36 +000052 void setCursor(int width, int height, const rfb::Point& hotspot,
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010053 const rdr::U8* data);
Pierre Ossman835b4ef2011-06-08 17:02:36 +000054
Pierre Ossman2fa63f82016-12-05 15:26:21 +010055 // Change client LED state
56 void setLEDState(unsigned int state);
57
Pierre Ossman3d74d882017-01-02 19:49:52 +010058 void draw(Surface* dst);
59
Pierre Ossmand50b3d12011-04-15 07:46:56 +000060 // Fl_Widget callback methods
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000061
Pierre Ossmand50b3d12011-04-15 07:46:56 +000062 void draw();
Pierre Ossmane00f0aa2011-06-01 09:31:53 +000063
64 void resize(int x, int y, int w, int h);
65
Pierre Ossmand50b3d12011-04-15 07:46:56 +000066 int handle(int event);
67
68private:
Pierre Ossman9a747322018-03-26 14:16:43 +020069 bool hasFocus();
Pierre Ossmand50b3d12011-04-15 07:46:56 +000070
Pierre Ossman2fa63f82016-12-05 15:26:21 +010071 unsigned int getModifierMask(unsigned int keysym);
72
Pierre Ossman4a6be4a2011-05-19 14:49:18 +000073 static void handleClipboardChange(int source, void *data);
74
Pierre Ossmanbe6909b2018-03-26 14:17:04 +020075 void clearPendingClipboard();
76 void flushPendingClipboard();
77
Pierre Ossmand50b3d12011-04-15 07:46:56 +000078 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
79 static void handlePointerTimeout(void *data);
80
Pierre Ossman25188c42014-07-21 16:30:08 +020081 void handleKeyPress(int keyCode, rdr::U32 keySym);
82 void handleKeyRelease(int keyCode);
83
Pierre Ossman64ff1ca2014-09-11 10:48:29 +020084 static int handleSystemEvent(void *event, void *data);
Pierre Ossman4f3ac692014-08-22 15:10:22 +020085
Pierre Ossman51249782018-03-08 14:05:39 +010086#ifdef WIN32
87 static void handleAltGrTimeout(void *data);
88#endif
89
Pierre Ossman78236292018-03-26 14:15:40 +020090 void pushLEDState();
91
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +000092 void initContextMenu();
93 void popupContextMenu();
94
Pierre Ossman4e7271e2011-05-24 12:47:12 +000095 void setMenuKey();
96
97 static void handleOptions(void *data);
98
Pierre Ossmand50b3d12011-04-15 07:46:56 +000099private:
100 CConn* cc;
101
Pierre Ossman132b3d02011-06-13 11:19:32 +0000102 PlatformPixelBuffer* frameBuffer;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000103
104 rfb::Point lastPointerPos;
105 int lastButtonMask;
106
107 typedef std::map<int, rdr::U32> DownMap;
108 DownMap downKeySym;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000109
Pierre Ossman51249782018-03-08 14:05:39 +0100110#ifdef WIN32
111 bool altGrArmed;
112 unsigned int altGrCtrlTime;
113#endif
114
Pierre Ossmanbe6909b2018-03-26 14:17:04 +0200115 const char* pendingServerCutText;
116 const char* pendingClientCutText;
117
Pierre Ossman25188c42014-07-21 16:30:08 +0200118 rdr::U32 menuKeySym;
Pierre Ossman0c158662017-07-13 15:54:11 +0200119 int menuKeyCode, menuKeyFLTK;
Pierre Ossmanc7bfaac2011-04-29 11:08:11 +0000120 Fl_Menu_Button *contextMenu;
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000121
Henrik Anderssonabd70ce2011-09-14 06:31:06 +0000122 bool menuCtrlKey;
123 bool menuAltKey;
124
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000125 Fl_RGB_Image *cursor;
126 rfb::Point cursorHotspot;
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000127};
128
129#endif