blob: 7ce36b4fe8ee2e828ccb24878e376dff403cb8af [file] [log] [blame]
Pierre Ossman5156d5e2011-03-09 09:42:34 +00001/* 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 Ossman4ae229f2011-04-15 12:58:31 +000024#include <FL/Fl_Scroll.H>
25
Pierre Ossman5156d5e2011-03-09 09:42:34 +000026#include <rfb/LogWriter.h>
27
28#include "DesktopWindow.h"
Pierre Ossman5156d5e2011-03-09 09:42:34 +000029#include "i18n.h"
Pierre Ossman89f868a2011-04-11 11:59:31 +000030
Pierre Ossman5156d5e2011-03-09 09:42:34 +000031using namespace rfb;
32
33extern void exit_vncviewer();
34
35static rfb::LogWriter vlog("DesktopWindow");
36
37DesktopWindow::DesktopWindow(int w, int h, const char *name,
38 const rfb::PixelFormat& serverPF,
39 CConn* cc_)
Pierre Ossmand50b3d12011-04-15 07:46:56 +000040 : Fl_Window(w, h)
Pierre Ossman5156d5e2011-03-09 09:42:34 +000041{
Pierre Ossman4ae229f2011-04-15 12:58:31 +000042 // Allow resize
Pierre Ossman343e2e02011-04-15 13:00:12 +000043 size_range(100, 100, w, h);
Pierre Ossman4ae229f2011-04-15 12:58:31 +000044
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 Ossmand50b3d12011-04-15 07:46:56 +000051 viewport = new Viewport(w, h, serverPF, cc_);
52
Pierre Ossman4ae229f2011-04-15 12:58:31 +000053 scroll->end();
54
Pierre Ossman5156d5e2011-03-09 09:42:34 +000055 callback(handleClose, this);
56
57 setName(name);
58
Pierre Ossman5156d5e2011-03-09 09:42:34 +000059 show();
60}
61
62
63DesktopWindow::~DesktopWindow()
64{
Pierre Ossmand50b3d12011-04-15 07:46:56 +000065 // FLTK automatically deletes all child widgets, so we shouldn't touch
66 // them ourselves here
Pierre Ossman5156d5e2011-03-09 09:42:34 +000067}
68
69
70void DesktopWindow::setServerPF(const rfb::PixelFormat& pf)
71{
Pierre Ossmand50b3d12011-04-15 07:46:56 +000072 viewport->setServerPF(pf);
Pierre Ossman5156d5e2011-03-09 09:42:34 +000073}
74
75
76const rfb::PixelFormat &DesktopWindow::getPreferredPF()
77{
Pierre Ossmand50b3d12011-04-15 07:46:56 +000078 return viewport->getPreferredPF();
Pierre Ossman5156d5e2011-03-09 09:42:34 +000079}
80
81
82// Cursor stuff
83
84void DesktopWindow::setCursor(int width, int height, const Point& hotspot,
85 void* data, void* mask)
86{
87}
88
89
90void 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 Ossmand50b3d12011-04-15 07:46:56 +0000100
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000101void DesktopWindow::setColourMapEntries(int firstColour, int nColours,
102 rdr::U16* rgbs)
103{
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000104 viewport->setColourMapEntries(firstColour, nColours, rgbs);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000105}
106
107
108// Copy the areas of the framebuffer that have been changed (damaged)
109// to the displayed window.
110
111void DesktopWindow::updateWindow()
112{
Pierre Ossmand50b3d12011-04-15 07:46:56 +0000113 viewport->updateWindow();
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000114}
115
116
Pierre Ossman4ae229f2011-04-15 12:58:31 +0000117void 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 Ossman5156d5e2011-03-09 09:42:34 +0000149void DesktopWindow::handleClose(Fl_Widget *wnd, void *data)
150{
151 exit_vncviewer();
152}