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