1998-10-20 01:39:29 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Scroll header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2015-06-28 16:05:29 +03:00
|
|
|
// Copyright 1998-2015 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Scroll widget . */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef Fl_Scroll_H
|
|
|
|
#define Fl_Scroll_H
|
|
|
|
|
|
|
|
#include "Fl_Group.H"
|
|
|
|
#include "Fl_Scrollbar.H"
|
|
|
|
|
2008-09-15 12:41:54 +04:00
|
|
|
/**
|
|
|
|
This container widget lets you maneuver around a set of widgets much
|
2009-12-07 01:21:55 +03:00
|
|
|
larger than your window. If the child widgets are larger than the size
|
2008-09-15 12:41:54 +04:00
|
|
|
of this object then scrollbars will appear so that you can scroll over
|
|
|
|
to them:
|
2010-12-09 02:53:04 +03:00
|
|
|
\image html Fl_Scroll.png
|
|
|
|
\image latex Fl_Scroll.png "Fl_Scroll" width=4cm
|
2009-11-14 20:17:18 +03:00
|
|
|
|
|
|
|
If all of the child widgets are packed together into a solid
|
2008-09-15 12:41:54 +04:00
|
|
|
rectangle then you want to set box() to FL_NO_BOX or
|
|
|
|
one of the _FRAME types. This will result in the best output.
|
2009-11-14 20:17:18 +03:00
|
|
|
However, if the child widgets are a sparse arrangement you must
|
|
|
|
set box() to a real _BOX type. This can result in some
|
2015-06-28 16:05:29 +03:00
|
|
|
blinking during redrawing, but that can be solved by using a
|
2009-11-14 20:17:18 +03:00
|
|
|
Fl_Double_Window.
|
2008-09-15 12:41:54 +04:00
|
|
|
|
|
|
|
By default you can scroll in both directions, and the scrollbars
|
2015-06-28 16:05:29 +03:00
|
|
|
disappear if the data will fit in the area of the scroll.
|
2009-11-14 20:17:18 +03:00
|
|
|
|
|
|
|
Use Fl_Scroll::type() to change this as follows :
|
2015-06-28 16:05:29 +03:00
|
|
|
|
|
|
|
- 0 - No scrollbars
|
|
|
|
- Fl_Scroll::HORIZONTAL - Only a horizontal scrollbar.
|
|
|
|
- Fl_Scroll::VERTICAL - Only a vertical scrollbar.
|
|
|
|
- Fl_Scroll::BOTH - The default is both scrollbars.
|
|
|
|
- Fl_Scroll::HORIZONTAL_ALWAYS - Horizontal scrollbar always on, vertical always off.
|
|
|
|
- Fl_Scroll::VERTICAL_ALWAYS - Vertical scrollbar always on, horizontal always off.
|
|
|
|
- Fl_Scroll::BOTH_ALWAYS - Both always on.
|
2008-09-15 12:41:54 +04:00
|
|
|
|
2009-11-14 20:17:18 +03:00
|
|
|
Use <B> scrollbar.align(int) ( see void Fl_Widget::align(Fl_Align) ) :</B>
|
|
|
|
to change what side the scrollbars are drawn on.
|
|
|
|
|
|
|
|
If the FL_ALIGN_LEFT bit is on, the vertical scrollbar is on the left.
|
2008-09-15 12:41:54 +04:00
|
|
|
If the FL_ALIGN_TOP bit is on, the horizontal scrollbar is on
|
2015-06-28 16:05:29 +03:00
|
|
|
the top. Note that only the alignment flags in scrollbar are
|
2008-09-15 12:41:54 +04:00
|
|
|
considered. The flags in hscrollbar however are ignored.
|
|
|
|
|
2009-11-14 20:17:18 +03:00
|
|
|
This widget can also be used to pan around a single child widget
|
2015-06-28 16:05:29 +03:00
|
|
|
"canvas". This child widget should be of your own class, with a
|
2009-12-07 01:21:55 +03:00
|
|
|
draw() method that draws the contents. The scrolling is done by
|
2008-09-15 12:41:54 +04:00
|
|
|
changing the x() and y() of the widget, so this child
|
2009-11-14 20:17:18 +03:00
|
|
|
must use the x() and y() to position its drawing.
|
2015-06-28 16:05:29 +03:00
|
|
|
To speed up drawing it should test fl_not_clipped(int x,int y,int w,int h)
|
|
|
|
to find out if a particular area of the widget must be drawn.
|
2008-09-15 12:41:54 +04:00
|
|
|
|
2009-11-14 20:17:18 +03:00
|
|
|
Another very useful child is a single Fl_Pack, which is itself a group
|
|
|
|
that packs its children together and changes size to surround them.
|
|
|
|
Filling the Fl_Pack with Fl_Tabs groups (and then putting
|
2008-09-15 12:41:54 +04:00
|
|
|
normal widgets inside those) gives you a very powerful scrolling list
|
2009-11-14 20:17:18 +03:00
|
|
|
of individually-openable panels.
|
|
|
|
|
|
|
|
Fluid lets you create these, but you can only lay out objects that
|
2009-12-07 01:21:55 +03:00
|
|
|
fit inside the Fl_Scroll without scrolling. Be sure to leave
|
2009-11-14 20:17:18 +03:00
|
|
|
space for the scrollbars, as Fluid won't show these either.
|
2008-09-15 12:41:54 +04:00
|
|
|
|
2009-11-14 20:17:18 +03:00
|
|
|
<I>You cannot use Fl_Window as a child of this since the
|
2008-09-15 12:41:54 +04:00
|
|
|
clipping is not conveyed to it when drawn, and it will draw over the
|
|
|
|
scrollbars and neighboring objects.</I>
|
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
class FL_EXPORT Fl_Scroll : public Fl_Group {
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
int xposition_, yposition_;
|
|
|
|
int oldx, oldy;
|
2009-07-12 04:15:06 +04:00
|
|
|
int scrollbar_size_;
|
2002-08-14 20:49:38 +04:00
|
|
|
static void hscrollbar_cb(Fl_Widget*, void*);
|
|
|
|
static void scrollbar_cb(Fl_Widget*, void*);
|
|
|
|
void fix_scrollbar_order();
|
|
|
|
static void draw_clip(void*,int,int,int,int);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2016-01-27 21:11:20 +03:00
|
|
|
protected: // (STR#1895)
|
2014-07-16 07:32:14 +04:00
|
|
|
/**
|
|
|
|
Structure to manage scrollbar and widget interior sizes.
|
|
|
|
This is filled out by recalc_scrollbars() for use in calculations
|
|
|
|
that need to know the visible scroll area size, etc.
|
2016-01-27 21:11:20 +03:00
|
|
|
\note Availability in FL_ABI_VERSION 10303 or higher.
|
2014-07-16 07:32:14 +04:00
|
|
|
*/
|
2009-07-12 04:15:06 +04:00
|
|
|
typedef struct {
|
2014-07-16 07:32:14 +04:00
|
|
|
/// A local struct to manage a region defined by xywh
|
|
|
|
typedef struct { int x,y,w,h; } Fl_Region_XYWH;
|
2014-07-16 22:51:56 +04:00
|
|
|
/// A local struct to manage a region defined by left/right/top/bottom
|
|
|
|
typedef struct {
|
|
|
|
int l; ///< (l)eft "x" position, aka x1
|
|
|
|
int r; ///< (r)ight "x" position, aka x2
|
|
|
|
int t; ///< (t)op "y" position, aka y1
|
|
|
|
int b; ///< (b)ottom "y" position, aka y2
|
|
|
|
} Fl_Region_LRTB;
|
2014-07-16 07:32:14 +04:00
|
|
|
/// A local struct to manage a scrollbar's xywh region and tab values
|
|
|
|
typedef struct {
|
|
|
|
int x,y,w,h;
|
2014-07-16 22:51:56 +04:00
|
|
|
int pos; ///< scrollbar tab's "position of first line displayed"
|
|
|
|
int size; ///< scrollbar tab's "size of window in lines"
|
|
|
|
int first; ///< scrollbar tab's "number of first line"
|
|
|
|
int total; ///< scrollbar tab's "total number of lines"
|
2014-07-16 07:32:14 +04:00
|
|
|
} Fl_Scrollbar_Data;
|
|
|
|
int scrollsize; ///< the effective scrollbar thickness (local or global)
|
|
|
|
Fl_Region_XYWH innerbox; ///< widget's inner box, excluding scrollbars
|
|
|
|
Fl_Region_XYWH innerchild; ///< widget's inner box, including scrollbars
|
2014-07-16 22:51:56 +04:00
|
|
|
Fl_Region_LRTB child; ///< child bounding box: left/right/top/bottom
|
2014-07-16 07:32:14 +04:00
|
|
|
int hneeded; ///< horizontal scrollbar visibility
|
|
|
|
int vneeded; ///< vertical scrollbar visibility
|
|
|
|
Fl_Scrollbar_Data hscroll; ///< horizontal scrollbar region + values
|
|
|
|
Fl_Scrollbar_Data vscroll; ///< vertical scrollbar region + values
|
2009-07-12 04:15:06 +04:00
|
|
|
} ScrollInfo;
|
|
|
|
void recalc_scrollbars(ScrollInfo &si);
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
protected:
|
|
|
|
|
2007-01-18 22:23:24 +03:00
|
|
|
void bbox(int&,int&,int&,int&);
|
2002-08-14 20:49:38 +04:00
|
|
|
void draw();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Fl_Scrollbar scrollbar;
|
|
|
|
Fl_Scrollbar hscrollbar;
|
|
|
|
|
2015-06-28 16:05:29 +03:00
|
|
|
void resize(int X, int Y, int W, int H);
|
2002-08-14 20:49:38 +04:00
|
|
|
int handle(int);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
Fl_Scroll(int X,int Y,int W,int H,const char*l=0);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
enum { // values for type()
|
|
|
|
HORIZONTAL = 1,
|
|
|
|
VERTICAL = 2,
|
|
|
|
BOTH = 3,
|
|
|
|
ALWAYS_ON = 4,
|
|
|
|
HORIZONTAL_ALWAYS = 5,
|
|
|
|
VERTICAL_ALWAYS = 6,
|
|
|
|
BOTH_ALWAYS = 7
|
|
|
|
};
|
|
|
|
|
2008-09-15 12:41:54 +04:00
|
|
|
/** Gets the current horizontal scrolling position. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int xposition() const {return xposition_;}
|
2008-09-15 12:41:54 +04:00
|
|
|
/** Gets the current vertical scrolling position. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int yposition() const {return yposition_;}
|
2008-04-24 13:01:37 +04:00
|
|
|
void scroll_to(int, int);
|
2003-06-15 08:41:16 +04:00
|
|
|
void clear();
|
2009-07-12 04:15:06 +04:00
|
|
|
/**
|
|
|
|
Gets the current size of the scrollbars' troughs, in pixels.
|
|
|
|
|
2015-06-28 16:05:29 +03:00
|
|
|
If this value is zero (default), this widget will use the
|
2009-07-12 04:15:06 +04:00
|
|
|
Fl::scrollbar_size() value as the scrollbar's width.
|
2015-06-28 16:05:29 +03:00
|
|
|
|
2015-07-19 02:59:54 +03:00
|
|
|
\returns Scrollbar size in pixels, or 0 if the global Fl::scrollbar_size() is being used.
|
2009-07-12 04:15:06 +04:00
|
|
|
\see Fl::scrollbar_size(int)
|
|
|
|
*/
|
|
|
|
int scrollbar_size() const {
|
|
|
|
return(scrollbar_size_);
|
|
|
|
}
|
|
|
|
/**
|
2011-10-04 17:10:55 +04:00
|
|
|
Sets the pixel size of the scrollbars' troughs to \p newSize, in pixels.
|
2009-07-12 04:15:06 +04:00
|
|
|
|
|
|
|
Normally you should not need this method, and should use
|
2015-06-28 16:05:29 +03:00
|
|
|
Fl::scrollbar_size(int) instead to manage the size of ALL
|
|
|
|
your widgets' scrollbars. This ensures your application
|
2009-07-12 04:15:06 +04:00
|
|
|
has a consistent UI, is the default behavior, and is normally
|
|
|
|
what you want.
|
|
|
|
|
|
|
|
Only use THIS method if you really need to override the global
|
|
|
|
scrollbar size. The need for this should be rare.
|
2015-06-28 16:05:29 +03:00
|
|
|
|
2011-10-04 17:10:55 +04:00
|
|
|
Setting \p newSize to the special value of 0 causes the widget to
|
2009-07-12 04:15:06 +04:00
|
|
|
track the global Fl::scrollbar_size(), which is the default.
|
2015-06-28 16:05:29 +03:00
|
|
|
|
2011-10-04 17:10:55 +04:00
|
|
|
\param[in] newSize Sets the scrollbar size in pixels.\n
|
2009-07-12 04:15:06 +04:00
|
|
|
If 0 (default), scrollbar size tracks the global Fl::scrollbar_size()
|
|
|
|
\see Fl::scrollbar_size()
|
|
|
|
*/
|
2011-10-02 10:25:13 +04:00
|
|
|
void scrollbar_size(int newSize) {
|
|
|
|
if ( newSize != scrollbar_size_ ) redraw();
|
|
|
|
scrollbar_size_ = newSize;
|
2015-06-28 16:05:29 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
1998-10-20 01:39:29 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|