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 | #include <assert.h> |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
| 23 | |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 24 | #include <FL/Fl_Scroll.H> |
| 25 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 26 | #include <rfb/LogWriter.h> |
| 27 | |
| 28 | #include "DesktopWindow.h" |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 29 | #include "i18n.h" |
Pierre Ossman | 89f868a | 2011-04-11 11:59:31 +0000 | [diff] [blame] | 30 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 31 | using namespace rfb; |
| 32 | |
| 33 | extern void exit_vncviewer(); |
| 34 | |
| 35 | static rfb::LogWriter vlog("DesktopWindow"); |
| 36 | |
| 37 | DesktopWindow::DesktopWindow(int w, int h, const char *name, |
| 38 | const rfb::PixelFormat& serverPF, |
| 39 | CConn* cc_) |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 40 | : Fl_Window(w, h) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 41 | { |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 42 | // Allow resize |
Pierre Ossman | 343e2e0 | 2011-04-15 13:00:12 +0000 | [diff] [blame^] | 43 | size_range(100, 100, w, h); |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 44 | |
| 45 | Fl_Scroll *scroll = new Fl_Scroll(0, 0, w, h); |
| 46 | scroll->color(FL_BLACK); |
| 47 | |
| 48 | // Automatically adjust the scroll box to the window |
| 49 | resizable(scroll); |
| 50 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 51 | viewport = new Viewport(w, h, serverPF, cc_); |
| 52 | |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 53 | scroll->end(); |
| 54 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 55 | callback(handleClose, this); |
| 56 | |
| 57 | setName(name); |
| 58 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 59 | show(); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | DesktopWindow::~DesktopWindow() |
| 64 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 65 | // FLTK automatically deletes all child widgets, so we shouldn't touch |
| 66 | // them ourselves here |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
| 70 | void DesktopWindow::setServerPF(const rfb::PixelFormat& pf) |
| 71 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 72 | viewport->setServerPF(pf); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
| 76 | const rfb::PixelFormat &DesktopWindow::getPreferredPF() |
| 77 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 78 | return viewport->getPreferredPF(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
| 82 | // Cursor stuff |
| 83 | |
| 84 | void DesktopWindow::setCursor(int width, int height, const Point& hotspot, |
| 85 | void* data, void* mask) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | |
| 90 | void DesktopWindow::setName(const char *name) |
| 91 | { |
| 92 | CharArray windowNameStr; |
| 93 | windowNameStr.replaceBuf(new char[256]); |
| 94 | |
| 95 | snprintf(windowNameStr.buf, 256, _("TigerVNC: %.240s"), name); |
| 96 | |
| 97 | copy_label(windowNameStr.buf); |
| 98 | } |
| 99 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 100 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 101 | void DesktopWindow::setColourMapEntries(int firstColour, int nColours, |
| 102 | rdr::U16* rgbs) |
| 103 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 104 | viewport->setColourMapEntries(firstColour, nColours, rgbs); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | |
| 108 | // Copy the areas of the framebuffer that have been changed (damaged) |
| 109 | // to the displayed window. |
| 110 | |
| 111 | void DesktopWindow::updateWindow() |
| 112 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 113 | viewport->updateWindow(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 117 | void DesktopWindow::resize(int x, int y, int w, int h) |
| 118 | { |
| 119 | // Deal with some scrolling corner cases: |
| 120 | // |
| 121 | // a) If the window is larger then the viewport, center the viewport. |
| 122 | // b) If the window is smaller than the viewport, make sure there is |
| 123 | // no wasted space on the sides. |
| 124 | // |
| 125 | // FIXME: Doesn't compensate for scroll widget size properly. |
| 126 | if (w > viewport->w()) |
| 127 | viewport->position((w - viewport->w()) / 2, viewport->y()); |
| 128 | else { |
| 129 | if (viewport->x() > 0) |
| 130 | viewport->position(0, viewport->y()); |
| 131 | else if (w > (viewport->x() + viewport->w())) |
| 132 | viewport->position(w - viewport->w(), viewport->y()); |
| 133 | } |
| 134 | |
| 135 | // Same thing for y axis |
| 136 | if (h > viewport->h()) |
| 137 | viewport->position(viewport->x(), (h - viewport->h()) / 2); |
| 138 | else { |
| 139 | if (viewport->y() > 0) |
| 140 | viewport->position(viewport->x(), 0); |
| 141 | else if (h > (viewport->y() + viewport->h())) |
| 142 | viewport->position(viewport->x(), h - viewport->h()); |
| 143 | } |
| 144 | |
| 145 | Fl_Window::resize(x, y, w, h); |
| 146 | } |
| 147 | |
| 148 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 149 | void DesktopWindow::handleClose(Fl_Widget *wnd, void *data) |
| 150 | { |
| 151 | exit_vncviewer(); |
| 152 | } |