|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: Fl_Pack.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Packing widget for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 // Based on code by Curtis Edwards 00029 // Group that compresses all it's children together and resizes to surround 00030 // them on each redraw (only if box() is zero) 00031 // Bugs: ? 00032 00033 #include <FL/Fl.H> 00034 #include <FL/Fl_Pack.H> 00035 #include <FL/fl_draw.H> 00036 00047 Fl_Pack::Fl_Pack(int X, int Y, int W, int H,const char *l) 00048 : Fl_Group(X, Y, W, H, l) { 00049 resizable(0); 00050 spacing_ = 0; 00051 // type(VERTICAL); // already set like this 00052 } 00053 00054 void Fl_Pack::draw() { 00055 int tx = x()+Fl::box_dx(box()); 00056 int ty = y()+Fl::box_dy(box()); 00057 int tw = w()-Fl::box_dw(box()); 00058 int th = h()-Fl::box_dh(box()); 00059 int rw, rh; 00060 int current_position = horizontal() ? tx : ty; 00061 int maximum_position = current_position; 00062 uchar d = damage(); 00063 Fl_Widget*const* a = array(); 00064 if (horizontal()) { 00065 rw = -spacing_; 00066 rh = th; 00067 00068 for (int i = children(); i--;) 00069 if (child(i)->visible()) { 00070 if (child(i) != this->resizable()) rw += child(i)->w(); 00071 rw += spacing_; 00072 } 00073 } else { 00074 rw = tw; 00075 rh = -spacing_; 00076 00077 for (int i = children(); i--;) 00078 if (child(i)->visible()) { 00079 if (child(i) != this->resizable()) rh += child(i)->h(); 00080 rh += spacing_; 00081 } 00082 } 00083 for (int i = children(); i--;) { 00084 Fl_Widget* o = *a++; 00085 if (o->visible()) { 00086 int X,Y,W,H; 00087 if (horizontal()) { 00088 X = current_position; 00089 W = o->w(); 00090 Y = ty; 00091 H = th; 00092 } else { 00093 X = tx; 00094 W = tw; 00095 Y = current_position; 00096 H = o->h(); 00097 } 00098 // Last child, if resizable, takes all remaining room 00099 if(i == 0 && o == this->resizable()) { 00100 if(horizontal()) 00101 W = tw - rw; 00102 else 00103 H = th - rh; 00104 } 00105 if (spacing_ && current_position>maximum_position && box() && 00106 (X != o->x() || Y != o->y() || d&FL_DAMAGE_ALL)) { 00107 fl_color(color()); 00108 if (horizontal()) 00109 fl_rectf(maximum_position, ty, spacing_, th); 00110 else 00111 fl_rectf(tx, maximum_position, tw, spacing_); 00112 } 00113 if (X != o->x() || Y != o->y() || W != o->w() || H != o->h()) { 00114 o->resize(X,Y,W,H); 00115 o->clear_damage(FL_DAMAGE_ALL); 00116 } 00117 if (d&FL_DAMAGE_ALL) { 00118 draw_child(*o); 00119 draw_outside_label(*o); 00120 } else update_child(*o); 00121 // child's draw() can change it's size, so use new size: 00122 current_position += (horizontal() ? o->w() : o->h()); 00123 if (current_position > maximum_position) 00124 maximum_position = current_position; 00125 current_position += spacing_; 00126 } 00127 } 00128 00129 if (horizontal()) { 00130 if (maximum_position < tx+tw && box()) { 00131 fl_color(color()); 00132 fl_rectf(maximum_position, ty, tx+tw-maximum_position, th); 00133 } 00134 tw = maximum_position-tx; 00135 } else { 00136 if (maximum_position < ty+th && box()) { 00137 fl_color(color()); 00138 fl_rectf(tx, maximum_position, tw, ty+th-maximum_position); 00139 } 00140 th = maximum_position-ty; 00141 } 00142 00143 tw += Fl::box_dw(box()); if (tw <= 0) tw = 1; 00144 th += Fl::box_dh(box()); if (th <= 0) th = 1; 00145 if (tw != w() || th != h()) { 00146 Fl_Widget::resize(x(),y(),tw,th); 00147 d = FL_DAMAGE_ALL; 00148 } 00149 if (d&FL_DAMAGE_ALL) { 00150 draw_box(); 00151 draw_label(); 00152 } 00153 } 00154 00155 // 00156 // End of "$Id: Fl_Pack.cxx 7903 2010-11-28 21:06:39Z matt $". 00157 //