Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +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 __DESKTOPWINDOW_H__ |
| 21 | #define __DESKTOPWINDOW_H__ |
| 22 | |
| 23 | #include <FL/Fl.H> |
| 24 | #include <FL/Fl_Window.H> |
| 25 | |
| 26 | #include <rfb/Rect.h> |
| 27 | #include <rfb/Region.h> |
| 28 | #include <rfb/Timer.h> |
| 29 | #include <rfb/PixelBuffer.h> |
| 30 | #include <rfb/PixelTransformer.h> |
| 31 | |
| 32 | class CConn; |
| 33 | |
| 34 | class DesktopWindow : public Fl_Window { |
| 35 | public: |
| 36 | |
| 37 | DesktopWindow(int w, int h, const char *name, |
| 38 | const rfb::PixelFormat& serverPF, CConn* cc_); |
| 39 | ~DesktopWindow(); |
| 40 | |
| 41 | // PixelFormat of incoming write operations |
| 42 | void setServerPF(const rfb::PixelFormat& pf); |
| 43 | // Most efficient format (from DesktopWindow's point of view) |
| 44 | const rfb::PixelFormat &getPreferredPF(); |
| 45 | |
| 46 | // setCursor() sets the shape of the local cursor |
| 47 | void setCursor(int width, int height, const rfb::Point& hotspot, |
| 48 | void* data, void* mask); |
| 49 | |
| 50 | // Flush updates to screen |
| 51 | void updateWindow(); |
| 52 | |
| 53 | // Methods forwarded from CConn |
| 54 | void setName(const char *name); |
| 55 | |
| 56 | void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs); |
| 57 | |
| 58 | void fillRect(const rfb::Rect& r, rfb::Pixel pix) { |
| 59 | if (pixelTrans) { |
| 60 | rfb::Pixel pix2; |
| 61 | pixelTrans->translatePixels(&pix, &pix2, 1); |
| 62 | pix = pix2; |
| 63 | } |
| 64 | |
| 65 | frameBuffer->fillRect(r, pix); |
| 66 | damageRect(r); |
| 67 | } |
| 68 | void imageRect(const rfb::Rect& r, void* pixels) { |
| 69 | if (pixelTrans) |
| 70 | pixelTrans->translateRect(pixels, r.width(), |
| 71 | rfb::Rect(0, 0, r.width(), r.height()), |
| 72 | frameBuffer->data, frameBuffer->getStride(), |
| 73 | r.tl); |
| 74 | else |
| 75 | frameBuffer->imageRect(r, pixels); |
| 76 | damageRect(r); |
| 77 | } |
| 78 | void copyRect(const rfb::Rect& r, int srcX, int srcY) { |
| 79 | frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY)); |
| 80 | damageRect(r); |
| 81 | } |
| 82 | |
| 83 | // Fl_Window callback methods |
| 84 | void draw(); |
Pierre Ossman | c266e5a | 2011-03-09 10:24:12 +0000 | [diff] [blame] | 85 | int handle(int event); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | |
| 89 | void damageRect(const rfb::Rect& r) { |
| 90 | damage.assign_union(rfb::Region(r)); |
| 91 | if (!Fl::has_timeout(handleUpdateTimeout, this)) |
| 92 | Fl::add_timeout(0.100, handleUpdateTimeout, this); |
| 93 | }; |
| 94 | |
| 95 | static void handleUpdateTimeout(void *data); |
| 96 | static void handleColourMap(void *data); |
| 97 | |
| 98 | static void handleClose(Fl_Widget *wnd, void *data); |
| 99 | |
Pierre Ossman | c266e5a | 2011-03-09 10:24:12 +0000 | [diff] [blame] | 100 | void handlePointerEvent(const rfb::Point& pos, int buttonMask); |
| 101 | static void handlePointerTimeout(void *data); |
| 102 | |
Pierre Ossman | d014d05 | 2011-03-09 13:28:12 +0000 | [diff] [blame] | 103 | void handleKeyEvent(int keyCode, const char *keyText, bool down); |
| 104 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 105 | private: |
| 106 | CConn* cc; |
| 107 | |
| 108 | rfb::ManagedPixelBuffer* frameBuffer; |
| 109 | |
| 110 | rfb::PixelTransformer *pixelTrans; |
| 111 | rfb::SimpleColourMap colourMap; |
| 112 | |
| 113 | rfb::Region damage; |
Pierre Ossman | c266e5a | 2011-03-09 10:24:12 +0000 | [diff] [blame] | 114 | |
| 115 | rfb::Point lastPointerPos; |
| 116 | int lastButtonMask; |
Pierre Ossman | d014d05 | 2011-03-09 13:28:12 +0000 | [diff] [blame] | 117 | |
| 118 | rdr::U32 downKeySym[65536]; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | #endif |