1 /********************************************************************************
2 *                                                                               *
3 *                       S c r o l l A r e a   W i d g e t                       *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXScrollArea.h 3297 2015-12-14 20:30:04Z arthurcnorman $                      *
23 ********************************************************************************/
24 #ifndef FXSCROLLAREA_H
25 #define FXSCROLLAREA_H
26 
27 #ifndef FXCOMPOSITE_H
28 #include "FXComposite.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// Scrollbar options
35 enum {
36   SCROLLERS_NORMAL     = 0,                                 /// Show the scrollbars when needed
37   HSCROLLER_ALWAYS     = 0x00008000,                        /// Always show horizontal scrollers
38   HSCROLLER_NEVER      = 0x00010000,                        /// Never show horizontal scrollers
39   VSCROLLER_ALWAYS     = 0x00020000,                        /// Always show vertical scrollers
40   VSCROLLER_NEVER      = 0x00040000,                        /// Never show vertical scrollers
41   HSCROLLING_ON        = 0,                                 /// Horizontal scrolling turned on (default)
42   HSCROLLING_OFF       = HSCROLLER_NEVER|HSCROLLER_ALWAYS,  /// Horizontal scrolling turned off
43   VSCROLLING_ON        = 0,                                 /// Vertical scrolling turned on (default)
44   VSCROLLING_OFF       = VSCROLLER_NEVER|VSCROLLER_ALWAYS,  /// Vertical scrolling turned off
45   SCROLLERS_TRACK      = 0,                                 /// Scrollers track continuously for smooth scrolling
46   SCROLLERS_DONT_TRACK = 0x00080000                         /// Scrollers don't track continuously
47   };
48 
49 
50 class FXScrollBar;
51 class FXScrollCorner;
52 
53 
54 /**
55 * The scroll area widget manages a content area and a viewport
56 * area through which the content is viewed.  When the content area
57 * becomes larger than the viewport area, scrollbars are placed to
58 * permit viewing of the entire content by scrolling the content.
59 * Depending on the mode, scrollbars may be displayed on an as-needed
60 * basis, always, or never.
61 * Normally, the scroll area's size and the content's size are independent;
62 * however, it is possible to disable scrolling in the horizontal
63 * (vertical) direction.  In this case, the content width (height)
64 * will influence the width (height) of the scroll area widget.
65 * For content which is time-consuming to repaint, continuous
66 * scrolling may be turned off.
67 */
68 class FXAPI FXScrollArea : public FXComposite {
69   FXDECLARE(FXScrollArea)
70 protected:
71   FXScrollBar    *horizontal;   // Horizontal scroll bar
72   FXScrollBar    *vertical;     // Vertical scroll bar
73   FXScrollCorner *corner;       // Scroll corner
74   FXint           viewport_w;   // Viewport width
75   FXint           viewport_h;   // Viewport height
76   FXint           pos_x;        // X scroll position (pos_x<=0)
77   FXint           pos_y;        // Y scroll position (pos_y<=0)
78 protected:
79   FXScrollArea();
80   FXbool startAutoScroll(FXEvent *event,FXbool onlywheninside=FALSE);
81   void stopAutoScroll();
82   FXScrollArea(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h);
83   virtual void moveContents(FXint x,FXint y);
84 private:
85   FXScrollArea(const FXScrollArea&);
86   FXScrollArea &operator=(const FXScrollArea&);
87 public:
88   long onHMouseWheel(FXObject*,FXSelector,void*);
89   long onVMouseWheel(FXObject*,FXSelector,void*);
90   long onHScrollerChanged(FXObject*,FXSelector,void*);
91   long onVScrollerChanged(FXObject*,FXSelector,void*);
92   long onHScrollerDragged(FXObject*,FXSelector,void*);
93   long onVScrollerDragged(FXObject*,FXSelector,void*);
94   long onAutoScroll(FXObject*,FXSelector,void*);
95 public:
96 
97   /// Return default width
98   virtual FXint getDefaultWidth();
99 
100   /// Return default height
101   virtual FXint getDefaultHeight();
102 
103   /// Perform layout
104   virtual void layout();
105 
106   /// Return viewport height
107   virtual FXint getViewportHeight();
108 
109   /// Return viewport width
110   virtual FXint getViewportWidth();
111 
112   /// Return content width
113   virtual FXint getContentWidth();
114 
115   /// Return content height
116   virtual FXint getContentHeight();
117 
118   /// Change scroll style
119   void setScrollStyle(FXuint style);
120 
121   /// Return scroll style
122   FXuint getScrollStyle() const;
123 
124   /// Return TRUE if horizontally scrollable
125   FXbool isHorizontalScrollable() const;
126 
127   /// Return TRUE if vertically scrollable
128   FXbool isVerticalScrollable() const;
129 
130   /// Return a pointer to the horizontal scrollbar
horizontalScrollBar()131   FXScrollBar* horizontalScrollBar() const { return horizontal; }
132 
133   /// Return a pointer to the vertical scrollbar
verticalScrollBar()134   FXScrollBar* verticalScrollBar() const { return vertical; }
135 
136   /// Return the current x-position
getXPosition()137   FXint getXPosition() const { return pos_x; }
138 
139   /// Return the current y-position
getYPosition()140   FXint getYPosition() const { return pos_y; }
141 
142   /// Set the current position
143   void setPosition(FXint x,FXint y);
144 
145   /// Get the current position
getPosition(FXint & x,FXint & y)146   void getPosition(FXint& x,FXint& y) const { x=pos_x; y=pos_y; }
147 
148   /// Destructor
149   virtual ~FXScrollArea();
150   };
151 
152 }
153 
154 #endif
155