Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 1 | /* 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 Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 27 | #include <FL/Fl_Menu_Button.H> |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 28 | #include <FL/Fl_RGB_Image.H> |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 29 | |
| 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 | |
| 36 | class CConn; |
| 37 | |
| 38 | class Viewport : public Fl_Widget { |
| 39 | public: |
| 40 | |
| 41 | Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_); |
| 42 | ~Viewport(); |
| 43 | |
| 44 | // PixelFormat of incoming write operations |
| 45 | void setServerPF(const rfb::PixelFormat& pf); |
| 46 | // Most efficient format (from Viewport's point of view) |
| 47 | const rfb::PixelFormat &getPreferredPF(); |
| 48 | |
| 49 | // Flush updates to screen |
| 50 | void updateWindow(); |
| 51 | |
| 52 | // Methods forwarded from CConn |
| 53 | void setName(const char *name); |
| 54 | |
| 55 | void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs); |
| 56 | |
| 57 | void fillRect(const rfb::Rect& r, rfb::Pixel pix) { |
| 58 | if (pixelTrans) { |
| 59 | rfb::Pixel pix2; |
| 60 | pixelTrans->translatePixels(&pix, &pix2, 1); |
| 61 | pix = pix2; |
| 62 | } |
| 63 | |
| 64 | frameBuffer->fillRect(r, pix); |
| 65 | damageRect(r); |
| 66 | } |
| 67 | void imageRect(const rfb::Rect& r, void* pixels) { |
| 68 | if (pixelTrans) |
| 69 | pixelTrans->translateRect(pixels, r.width(), |
| 70 | rfb::Rect(0, 0, r.width(), r.height()), |
| 71 | frameBuffer->data, frameBuffer->getStride(), |
| 72 | r.tl); |
| 73 | else |
| 74 | frameBuffer->imageRect(r, pixels); |
| 75 | damageRect(r); |
| 76 | } |
| 77 | void copyRect(const rfb::Rect& r, int srcX, int srcY) { |
| 78 | frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY)); |
| 79 | damageRect(r); |
| 80 | } |
| 81 | |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 82 | void setCursor(int width, int height, const rfb::Point& hotspot, |
| 83 | void* data, void* mask); |
| 84 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 85 | // Fl_Widget callback methods |
Pierre Ossman | e00f0aa | 2011-06-01 09:31:53 +0000 | [diff] [blame] | 86 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 87 | void draw(); |
Pierre Ossman | e00f0aa | 2011-06-01 09:31:53 +0000 | [diff] [blame] | 88 | |
| 89 | void resize(int x, int y, int w, int h); |
| 90 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 91 | int handle(int event); |
| 92 | |
| 93 | private: |
| 94 | |
| 95 | void damageRect(const rfb::Rect& r) { |
| 96 | damage.assign_union(rfb::Region(r)); |
| 97 | if (!Fl::has_timeout(handleUpdateTimeout, this)) |
| 98 | Fl::add_timeout(0.100, handleUpdateTimeout, this); |
| 99 | }; |
| 100 | |
| 101 | static void handleUpdateTimeout(void *data); |
| 102 | static void handleColourMap(void *data); |
| 103 | |
Pierre Ossman | 4a6be4a | 2011-05-19 14:49:18 +0000 | [diff] [blame] | 104 | static void handleClipboardChange(int source, void *data); |
| 105 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 106 | void handlePointerEvent(const rfb::Point& pos, int buttonMask); |
| 107 | static void handlePointerTimeout(void *data); |
| 108 | |
Pierre Ossman | cd6ddef | 2011-05-20 12:05:20 +0000 | [diff] [blame] | 109 | rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText); |
| 110 | void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down); |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 111 | |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 112 | void initContextMenu(); |
| 113 | void popupContextMenu(); |
| 114 | |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 115 | void setMenuKey(); |
| 116 | |
| 117 | static void handleOptions(void *data); |
| 118 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 119 | private: |
| 120 | CConn* cc; |
| 121 | |
| 122 | rfb::ManagedPixelBuffer* frameBuffer; |
| 123 | |
| 124 | rfb::PixelTransformer *pixelTrans; |
| 125 | rfb::SimpleColourMap colourMap; |
| 126 | |
| 127 | rfb::Region damage; |
| 128 | |
| 129 | rfb::Point lastPointerPos; |
| 130 | int lastButtonMask; |
| 131 | |
| 132 | typedef std::map<int, rdr::U32> DownMap; |
| 133 | DownMap downKeySym; |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 134 | |
Pierre Ossman | 4e7271e | 2011-05-24 12:47:12 +0000 | [diff] [blame] | 135 | int menuKeyCode; |
Pierre Ossman | c7bfaac | 2011-04-29 11:08:11 +0000 | [diff] [blame] | 136 | Fl_Menu_Button *contextMenu; |
Pierre Ossman | 835b4ef | 2011-06-08 17:02:36 +0000 | [diff] [blame^] | 137 | |
| 138 | Fl_RGB_Image *cursor; |
| 139 | rfb::Point cursorHotspot; |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | #endif |