-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlu_Wrap_Group.h
196 lines (138 loc) · 6.2 KB
/
Flu_Wrap_Group.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// $Id: Flu_Wrap_Group.h,v 1.10 2004/01/27 21:44:21 jbryan Exp $
/***************************************************************
* FLU - FLTK Utility Widgets
* Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
*
* This file and its content is protected by a software license.
* You should have received a copy of this license with this file.
* If not, please contact the Ohio Supercomputer Center immediately:
* Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
*
***************************************************************/
#ifndef _FLU_WRAP_GROUP_H
#define _FLU_WRAP_GROUP_H
/* fltk includes */
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Scrollbar.H>
//#include "FLU/Flu_Enumerations.h"
#define FLU_EXPORT
//! This class provides an alternative to Fl_Group that automatically arranges the children either left to right and top to bottom (for type() == \c FL_VERTICAL), or top to bottom and left to right (for type() == \c FL_HORIZONTAL), within the available size of the group, with a scrollbar turning on if they don't all fit
/*! This class is a group with a scrollbar and an \b Fl_Group inside (both publicly exposed). The \b Fl_Group
contains the actual child widgets of this group.
Most of the \b Fl_Group member functions are reimplemented here in a pass-through fashion to the
internal group. This means that casual use of a descendent instance will be almost exactly the same
as for a regular \b Fl_Group, with any additional access provided directly through member \b group.
The goal of this class is to provide a group that dynamically and evenly distributes its children within
a fixed space, similar to those available in other GUI toolkits.
*/
class FLU_EXPORT Flu_Wrap_Group : public Fl_Group
{
public:
class Scrollbar : public Fl_Scrollbar
{
public:
Scrollbar( int x, int y, int w, int h, const char *l = 0 );
int handle( int event );
};
//! Normal FLTK constructor
Flu_Wrap_Group( int x, int y, int w, int h, const char *l = 0 );
//! \return the widget that is visibly above \b w in the group, or \c NULL if no such widget exists
Fl_Widget *above( Fl_Widget* w );
//! \return the widget that is visibly below \b w in the group, or \c NULL if no such widget exists
Fl_Widget *below( Fl_Widget* w );
//! Override of Fl_Group::draw()
void draw();
//! \return the widget that is visibly to the left of \b w in the group, or \c NULL if no such widget exists
Fl_Widget *left( Fl_Widget* w );
//! \return the widget that is logically after \b w in the groups order, or \c NULL if no such widget exists
Fl_Widget *next( Fl_Widget* w );
//! Set the offset for where the first child starts
inline void offset( int x, int y )
{ _offset[0] = x, _offset[1] = y; redraw(); }
//! \return the x offset for where the first child starts
inline int offset_x() const
{ return _offset[0]; }
//! \return the y offset for where the first child starts
inline int offset_y() const
{ return _offset[1]; }
//! \return the widget that is logically before \b w in the groups order, or \c NULL if no such widget exists
Fl_Widget *previous( Fl_Widget* w );
//! Override of Fl_Group::resize()
void resize( int x, int y, int w, int h );
//! \return the widget that is visibly to the right of \b w in the group, or \c NULL if no such widget exists
Fl_Widget *right( Fl_Widget* w );
//! Scroll the group so that the given widget is shown (usually aligned to the left/top)
void scroll_to( const Fl_Widget *w );
//! Scroll the group so that the given widget is shown (usually aligned to the left/top)
inline void scroll_to( const Fl_Widget& w )
{ scroll_to( &w ); }
//! Scroll the group to the beginning of the list
void scroll_to_beginning();
//! Scroll the group to the end of the list
void scroll_to_end();
//! Set the spacing between children
inline void spacing( int x, int y )
{ _spacing[0] = x, _spacing[1] = y; redraw(); }
//! \return the x spacing between children
inline int spacing_x() const
{ return _spacing[0]; }
//! \return the y spacing between children
inline int spacing_y() const
{ return _spacing[1]; }
//! Set the wrap type. Must be either \c FL_VERTICAL (children wrap according to the width, with a vertical scrollbar) or \c FL_HORIZONTAL (children wrap according to the height, with a horizontal scrollbar). Default is \c FL_HORIZONTAL
void type( int t );
//! Get the wrap type
inline int type() const
{ return _type; }
/*! \name Pass-through functions for the internal Fl_Group
* These are strictly for convenience. Only the most commonly called functions have been re-implemented.
* You can also explicitly access the group object for more control.
*/
//@{
inline Fl_Widget* const* array() const
{ return group.array(); }
inline int find( const Fl_Widget* w ) const
{ return group.find( w ); }
inline int find( const Fl_Widget& w ) const
{ return group.find( w ); }
inline void clear()
{ group.clear(); }
inline Fl_Widget *child(int n) const
{ return group.child(n); }
inline int children() const
{ return group.children(); }
inline void begin()
{ group.begin(); }
inline void end()
{ group.end(); Fl_Group::end(); }
inline void resizable(Fl_Widget *box)
{ group.resizable(box); }
inline void resizable(Fl_Widget &box)
{ group.resizable(box); }
inline Fl_Widget *resizable() const
{ return group.resizable(); }
inline void add( Fl_Widget &w )
{ group.add( w ); }
inline void add( Fl_Widget *w )
{ group.add( w ); }
inline void insert( Fl_Widget &w, int n )
{ group.insert( w, n ); }
inline void insert( Fl_Widget &w, Fl_Widget* beforethis )
{ group.insert( w, beforethis ); }
inline void remove( Fl_Widget &w )
{ group.remove( w ); }
inline void add_resizable( Fl_Widget &box )
{ group.add_resizable( box ); }
//@}
Scrollbar scrollbar;
Fl_Group group;
protected:
inline static void _scrollCB( Fl_Widget*, void *arg )
{ ((Flu_Wrap_Group*)arg)->redraw(); }
int layout( bool sbVisible, bool doScrollTo, int *measure = 0 );
const Fl_Widget *scrollTo;
int _offset[2], _spacing[2], _type;
};
#endif