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(); |
Pierre Ossman | 3f6c4d0 | 2011-04-15 14:09:09 +0000 | [diff] [blame^] | 60 | |
| 61 | // The window manager might give us an initial window size that is different |
| 62 | // than the one we requested, and in those cases we need to manually adjust |
| 63 | // the scroll widget for things to behave sanely. |
| 64 | if ((w != this->w()) || (h != this->h())) |
| 65 | scroll->size(this->w(), this->h()); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | |
| 69 | DesktopWindow::~DesktopWindow() |
| 70 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 71 | // FLTK automatically deletes all child widgets, so we shouldn't touch |
| 72 | // them ourselves here |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
| 76 | void DesktopWindow::setServerPF(const rfb::PixelFormat& pf) |
| 77 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 78 | viewport->setServerPF(pf); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
| 82 | const rfb::PixelFormat &DesktopWindow::getPreferredPF() |
| 83 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 84 | return viewport->getPreferredPF(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | |
| 88 | // Cursor stuff |
| 89 | |
| 90 | void DesktopWindow::setCursor(int width, int height, const Point& hotspot, |
| 91 | void* data, void* mask) |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | |
| 96 | void DesktopWindow::setName(const char *name) |
| 97 | { |
| 98 | CharArray windowNameStr; |
| 99 | windowNameStr.replaceBuf(new char[256]); |
| 100 | |
| 101 | snprintf(windowNameStr.buf, 256, _("TigerVNC: %.240s"), name); |
| 102 | |
| 103 | copy_label(windowNameStr.buf); |
| 104 | } |
| 105 | |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 106 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 107 | void DesktopWindow::setColourMapEntries(int firstColour, int nColours, |
| 108 | rdr::U16* rgbs) |
| 109 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 110 | viewport->setColourMapEntries(firstColour, nColours, rgbs); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
| 114 | // Copy the areas of the framebuffer that have been changed (damaged) |
| 115 | // to the displayed window. |
| 116 | |
| 117 | void DesktopWindow::updateWindow() |
| 118 | { |
Pierre Ossman | d50b3d1 | 2011-04-15 07:46:56 +0000 | [diff] [blame] | 119 | viewport->updateWindow(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | |
Pierre Ossman | 4ae229f | 2011-04-15 12:58:31 +0000 | [diff] [blame] | 123 | void DesktopWindow::resize(int x, int y, int w, int h) |
| 124 | { |
| 125 | // Deal with some scrolling corner cases: |
| 126 | // |
| 127 | // a) If the window is larger then the viewport, center the viewport. |
| 128 | // b) If the window is smaller than the viewport, make sure there is |
| 129 | // no wasted space on the sides. |
| 130 | // |
| 131 | // FIXME: Doesn't compensate for scroll widget size properly. |
| 132 | if (w > viewport->w()) |
| 133 | viewport->position((w - viewport->w()) / 2, viewport->y()); |
| 134 | else { |
| 135 | if (viewport->x() > 0) |
| 136 | viewport->position(0, viewport->y()); |
| 137 | else if (w > (viewport->x() + viewport->w())) |
| 138 | viewport->position(w - viewport->w(), viewport->y()); |
| 139 | } |
| 140 | |
| 141 | // Same thing for y axis |
| 142 | if (h > viewport->h()) |
| 143 | viewport->position(viewport->x(), (h - viewport->h()) / 2); |
| 144 | else { |
| 145 | if (viewport->y() > 0) |
| 146 | viewport->position(viewport->x(), 0); |
| 147 | else if (h > (viewport->y() + viewport->h())) |
| 148 | viewport->position(viewport->x(), h - viewport->h()); |
| 149 | } |
| 150 | |
| 151 | Fl_Window::resize(x, y, w, h); |
| 152 | } |
| 153 | |
| 154 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 155 | void DesktopWindow::handleClose(Fl_Widget *wnd, void *data) |
| 156 | { |
| 157 | exit_vncviewer(); |
| 158 | } |