2 // "$Id: Fl_Pack.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Packing widget for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // Based on code by Curtis Edwards
29 // Group that compresses all it's children together and resizes to surround
30 // them on each redraw (only if box() is zero)
34 #include <FL/Fl_Pack.H>
35 #include <FL/fl_draw.H>
38 Creates a new Fl_Pack widget using the given position, size,
39 and label string. The default boxtype is FL_NO_BOX.
40 <P>The destructor <I>also deletes all the children</I>. This allows a
41 whole tree to be deleted at once, without having to keep a pointer to
42 all the children in the user code. A kludge has been done so the
43 Fl_Pack and all of it's children can be automatic (local)
44 variables, but you must declare the Fl_Pack<I>first</I>, so
45 that it is destroyed last.
47 Fl_Pack::Fl_Pack(int X
, int Y
, int W
, int H
,const char *l
)
48 : Fl_Group(X
, Y
, W
, H
, l
) {
51 // type(VERTICAL); // already set like this
54 void Fl_Pack::draw() {
55 int tx
= x()+Fl::box_dx(box());
56 int ty
= y()+Fl::box_dy(box());
57 int tw
= w()-Fl::box_dw(box());
58 int th
= h()-Fl::box_dh(box());
60 int current_position
= horizontal() ? tx
: ty
;
61 int maximum_position
= current_position
;
62 fl_damage_t d
= damage();
63 Fl_Widget
*const* a
= array();
68 for (int i
= children(); i
--;)
69 if (child(i
)->visible()) {
70 if (child(i
) != this->resizable()) rw
+= child(i
)->w();
77 for (int i
= children(); i
--;)
78 if (child(i
)->visible()) {
79 if (child(i
) != this->resizable()) rh
+= child(i
)->h();
83 for (int i
= children(); i
--;) {
98 // Last child, if resizable, takes all remaining room
99 if(i
== 0 && o
== this->resizable()) {
105 if (spacing_
&& current_position
>maximum_position
&& box() &&
106 (X
!= o
->x() || Y
!= o
->y() || d
&FL_DAMAGE_ALL
)) {
109 fl_rectf(maximum_position
, ty
, spacing_
, th
);
111 fl_rectf(tx
, maximum_position
, tw
, spacing_
);
113 if (X
!= o
->x() || Y
!= o
->y() || W
!= o
->w() || H
!= o
->h()) {
115 o
->clear_damage(FL_DAMAGE_ALL
);
117 if (d
&FL_DAMAGE_ALL
) {
119 draw_outside_label(*o
);
120 } else update_child(*o
);
121 // child's draw() can change it's size, so use new size:
122 current_position
+= (horizontal() ? o
->w() : o
->h());
123 if (current_position
> maximum_position
)
124 maximum_position
= current_position
;
125 current_position
+= spacing_
;
130 if (maximum_position
< tx
+tw
&& box()) {
132 fl_rectf(maximum_position
, ty
, tx
+tw
-maximum_position
, th
);
134 tw
= maximum_position
-tx
;
136 if (maximum_position
< ty
+th
&& box()) {
138 fl_rectf(tx
, maximum_position
, tw
, ty
+th
-maximum_position
);
140 th
= maximum_position
-ty
;
143 tw
+= Fl::box_dw(box()); if (tw
<= 0) tw
= 1;
144 th
+= Fl::box_dh(box()); if (th
<= 0) th
= 1;
145 if (tw
!= w() || th
!= h()) {
146 Fl_Widget::resize(x(),y(),tw
,th
);
149 if (d
&FL_DAMAGE_ALL
) {
156 // End of "$Id: Fl_Pack.cxx 7903 2010-11-28 21:06:39Z matt $".