2 /*******************************************************************************/
3 /* Copyright (C) 2010 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
20 /* Scrolling group suitable for containing a single child (a
21 * pack). When the Fl_Packscroller is resized, the child will be resized
22 * too. No scrollbars are displayed, but the widget responds to
23 * FL_MOUSEWHEEL events. */
27 #include <FL/Fl_Group.H>
28 #include <FL/fl_draw.H>
31 /* FIXME: Optimize scroll */
33 class Fl_Packscroller : public Fl_Group
38 static const int sbh = 15; /* scroll button height */
42 Fl_Packscroller ( int X, int Y, int W, int H, const char *L = 0 ) : Fl_Group( X, Y, W, H, L )
50 int increment ( void ) const { return _increment; }
51 void increment ( int v ) { _increment = v; }
53 void yposition ( int v )
63 const int H = h() - (sbh * 2);
65 Fl_Widget *o = child( 0 );
70 else if ( o->h() < H )
73 if ( _yposition != Y )
77 damage( FL_DAMAGE_SCROLL );
81 int yposition ( void ) const
84 return child( 0 )->y() - (y() + sbh);
89 void bbox ( int &X, int &Y, int &W, int &H )
103 if ( ! fl_not_clipped( x(), y(), w(), h() ) )
108 Fl_Widget *o = child( 0 );
110 o->position( x(), y() + sbh + _yposition );
112 if ( damage() != FL_DAMAGE_CHILD )
114 fl_rectf( x(), y(), w(), h(), color() );
116 fl_font( FL_HELVETICA, 12 );
118 if ( o->y() != y() + sbh )
120 fl_draw_box( box(), x(), y(), w(), sbh, color() );
121 fl_color( FL_BLACK );
122 fl_draw( "@2<", x(), y(), w(), sbh, FL_ALIGN_CENTER );
125 if ( o->h() > h() - (sbh * 2) && o->y() + o->h() != y() + h() - sbh )
127 fl_draw_box( box(), x(), y() + h() - sbh, w(), sbh, color() );
128 fl_color( FL_BLACK );
129 fl_draw( "@2>", x(), y() + h() - sbh, w(), sbh, FL_ALIGN_CENTER );
134 fl_push_clip( x(), y() + sbh, w(), h() - (sbh * 2 ) );
144 if ( Fl_Group::handle( m ) )
151 if ( Fl::event_button1() )
153 if ( Fl::event_inside( x(), y(), w(), sbh ) )
155 yposition( yposition() + ( h() / 4 ) );
158 else if ( Fl::event_inside( x(), y() + h() - sbh, w(), sbh ) )
160 yposition( yposition() - (h() / 4 ) );
176 if ( Fl::event_key() == FL_Up )
178 yposition( yposition() + ( h() / 4 ) );
181 else if ( Fl::event_key() == FL_Down )
183 yposition( yposition() - (h() / 4 ) );
190 yposition( yposition() - ( Fl::event_dy() * _increment ) );