summaryrefslogtreecommitdiffstats
path: root/unix/tx/TXViewport.h
blob: 823d67af19c091a819b7b0fbc9f6ecf2dd618681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */
//
// TXViewport.h
//
// A TXViewport allows a large window to be viewed by adding scrollbars to the
// right and bottom if necessary.  It also has a bump-scroll mode where there
// are no scrollbars, and scrolling is achieved by bumping up against the edge
// of the screen instead.  Note that this only works when the viewport fills
// the entire screen.  If the child window is smaller than the viewport, it is
// always positioned centrally in the viewport.

#ifndef __TXVIEWPORT_H__
#define __TXVIEWPORT_H__

#include <rfb/Timer.h>
#include "TXWindow.h"
#include "TXScrollbar.h"

class TXViewport : public TXWindow, public TXScrollbarCallback,
                   public rfb::Timer::Callback {
public:
  TXViewport(Display* dpy_, int width, int height, TXWindow* parent_=0);
  virtual ~TXViewport();

  // setChild() sets the child window which is to be viewed in the viewport.
  void setChild(TXWindow* child_);

  // setOffset() sets the position of the child in the viewport.  Note that the
  // offsets are negative.  For example when the offset is (-100,-30), position
  // (100,30) in the child window is at the top-left of the viewport.  The
  // offsets given are clipped to keep the child window filling the viewport
  // (except where the child window is smaller than the viewport, in which case
  // it is always positioned centrally in the viewport).  It returns true if
  // the child was repositioned.
  bool setOffset(int x, int y);

  // setBumpScroll() puts the viewport in bump-scroll mode.
  void setBumpScroll(bool b);

  // bumpScrollEvent() can be called with a MotionNotify event which may
  // potentially be against the edge of the screen.  It returns true if the
  // event was used for bump-scrolling, false if it should be processed
  // normally.
  bool bumpScrollEvent(XMotionEvent* ev);

private:
  virtual void resizeNotify();
  virtual void scrollbarPos(int x, int y, TXScrollbar* sb);
  virtual bool handleTimeout(rfb::Timer* timer);
  TXWindow* clipper;
  TXWindow* child;
  TXScrollbar* hScrollbar;
  TXScrollbar* vScrollbar;
  const int scrollbarSize;
  int xOff, yOff;
  rfb::Timer bumpScrollTimer;
  bool bumpScroll;
  bool needXScrollbar;
  bool needYScrollbar;
  int bumpScrollX, bumpScrollY;
};
#endif