blob: 0056e103543213a1fb865e0044baa3ee4b1878ec [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_Group.H 8157 2011-01-01 14:01:53Z AlbrechtS $"
3//
4// Group header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 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// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library 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
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28/* \file
29 Fl_Group, Fl_End classes . */
30
31#ifndef Fl_Group_H
32#define Fl_Group_H
33
34#ifndef Fl_Widget_H
35#include "Fl_Widget.H"
36#endif
37
38/**
39 The Fl_Group class is the FLTK container widget. It maintains
40 an array of child widgets. These children can themselves be any widget
41 including Fl_Group. The most important subclass of Fl_Group
42 is Fl_Window, however groups can also be used to control radio buttons
43 or to enforce resize behavior.
44*/
45class FL_EXPORT Fl_Group : public Fl_Widget {
46
47 Fl_Widget** array_;
48 Fl_Widget* savedfocus_;
49 Fl_Widget* resizable_;
50 int children_;
51 int *sizes_; // remembered initial sizes of children
52
53 int navigation(int);
54 static Fl_Group *current_;
55
56 // unimplemented copy ctor and assignment operator
57 Fl_Group(const Fl_Group&);
58 Fl_Group& operator=(const Fl_Group&);
59
60protected:
61 void draw();
62 void draw_child(Fl_Widget& widget) const;
63 void draw_children();
64 void draw_outside_label(const Fl_Widget& widget) const ;
65 void update_child(Fl_Widget& widget) const;
66 int *sizes();
67
68public:
69
70 int handle(int);
71 void begin();
72 void end();
73 static Fl_Group *current();
74 static void current(Fl_Group *g);
75
76 /**
77 Returns how many child widgets the group has.
78 */
79 int children() const {return children_;}
80 /**
81 Returns array()[n]. <i>No range checking is done!</i>
82 */
83 Fl_Widget* child(int n) const {return array()[n];}
84 int find(const Fl_Widget*) const;
85 /**
86 See int Fl_Group::find(const Fl_Widget *w) const
87 */
88 int find(const Fl_Widget& o) const {return find(&o);}
89 Fl_Widget* const* array() const;
90
91 void resize(int,int,int,int);
92 /**
93 Creates a new Fl_Group widget using the given position, size,
94 and label string. The default boxtype is FL_NO_BOX.
95 */
96 Fl_Group(int,int,int,int, const char * = 0);
97 virtual ~Fl_Group();
98 void add(Fl_Widget&);
99 /**
100 See void Fl_Group::add(Fl_Widget &w)
101 */
102 void add(Fl_Widget* o) {add(*o);}
103 void insert(Fl_Widget&, int i);
104 /**
105 This does insert(w, find(before)). This will append the
106 widget if \p before is not in the group.
107 */
108 void insert(Fl_Widget& o, Fl_Widget* before) {insert(o,find(before));}
109 void remove(int index);
110 void remove(Fl_Widget&);
111 /**
112 Removes the widget \p o from the group.
113 \sa void remove(Fl_Widget&)
114 */
115 void remove(Fl_Widget* o) {remove(*o);}
116 void clear();
117
118 /**
119 See void Fl_Group::resizable(Fl_Widget *box)
120 */
121 void resizable(Fl_Widget& o) {resizable_ = &o;}
122 /**
123 The resizable widget defines the resizing box for the group. When the
124 group is resized it calculates a new size and position for all of its
125 children. Widgets that are horizontally or vertically inside the
126 dimensions of the box are scaled to the new size. Widgets outside the
127 box are moved.
128
129 In these examples the gray area is the resizable:
130
131 \image html resizebox1.png
132
133 \image html resizebox2.png
134
135 \image latex resizebox1.png "before resize" width=4cm
136
137 \image latex resizebox2.png "after resize" width=4cm
138
139 The resizable may be set to the group itself, in which case all the
140 contents are resized. This is the default value for Fl_Group,
141 although NULL is the default for Fl_Window and Fl_Pack.
142
143 If the resizable is NULL then all widgets remain a fixed size
144 and distance from the top-left corner.
145
146 It is possible to achieve any type of resize behavior by using an
147 invisible Fl_Box as the resizable and/or by using a hierarchy
148 of child Fl_Group's.
149 */
150 void resizable(Fl_Widget* o) {resizable_ = o;}
151 /**
152 See void Fl_Group::resizable(Fl_Widget *box)
153 */
154 Fl_Widget* resizable() const {return resizable_;}
155 /**
156 Adds a widget to the group and makes it the resizable widget.
157 */
158 void add_resizable(Fl_Widget& o) {resizable_ = &o; add(o);}
159 void init_sizes();
160
161 /**
162 Controls whether the group widget clips the drawing of
163 child widgets to its bounding box.
164
165 Set \p c to 1 if you want to clip the child widgets to the
166 bounding box.
167
168 The default is to not clip (0) the drawing of child widgets.
169 */
170 void clip_children(int c) { if (c) set_flag(CLIP_CHILDREN); else clear_flag(CLIP_CHILDREN); }
171 /**
172 Returns the current clipping mode.
173
174 \return true, if clipping is enabled, false otherwise.
175
176 \see void Fl_Group::clip_children(int c)
177 */
178 unsigned int clip_children() { return (flags() & CLIP_CHILDREN) != 0; }
179
180 // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
181 virtual Fl_Group* as_group() { return this; }
182
183 // back compatibility functions:
184
185 /**
186 \deprecated This is for backwards compatibility only. You should use
187 \e W->%take_focus() instead.
188 \sa Fl_Widget::take_focus();
189 */
190 void focus(Fl_Widget* W) {W->take_focus();}
191
192 /** This is for forms compatibility only */
193 Fl_Widget* & _ddfdesign_kludge() {return resizable_;}
194
195 /** This is for forms compatibility only */
196 void forms_end();
197};
198
199// dummy class used to end child groups in constructors for complex
200// subclasses of Fl_Group:
201/**
202 This is a dummy class that allows you to end a Fl_Group in a constructor list of a
203 class:
204 \code
205 class MyClass {
206 Fl_Group group;
207 Fl_Button button_in_group;
208 Fl_End end;
209 Fl_Button button_outside_group;
210 MyClass();
211 };
212 MyClass::MyClass() :
213 group(10,10,100,100),
214 button_in_group(20,20,60,30),
215 end(),
216 button_outside_group(10,120,60,30)
217 {}
218 \endcode
219*/
220class FL_EXPORT Fl_End {
221public:
222 /** All it does is calling Fl_Group::current()->end() */
223 Fl_End() {Fl_Group::current()->end();}
224};
225
226#endif
227
228//
229// End of "$Id: Fl_Group.H 8157 2011-01-01 14:01:53Z AlbrechtS $".
230//