2009-12-25 01:23:54 +01:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2009 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
/* option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
|
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
|
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
|
|
|
/* more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <FL/Fl_Group.H>
|
|
|
|
|
|
|
|
class Fl_Flowpack : public Fl_Group
|
|
|
|
{
|
|
|
|
int _hspacing;
|
|
|
|
int _vspacing;
|
|
|
|
int _max_width;
|
2010-01-27 05:28:39 +01:00
|
|
|
bool _flow;
|
2009-12-25 01:23:54 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Fl_Flowpack ( int X, int Y, int W, int H, const char *L = 0 )
|
|
|
|
: Fl_Group( X, Y, W, H, L )
|
|
|
|
{
|
|
|
|
resizable( 0 );
|
|
|
|
_max_width = _hspacing = _vspacing = 0;
|
2010-02-01 02:27:00 +01:00
|
|
|
_flow = true;
|
2009-12-25 01:23:54 +01:00
|
|
|
}
|
|
|
|
|
2010-01-23 19:22:33 +01:00
|
|
|
virtual ~Fl_Flowpack ( )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-25 01:23:54 +01:00
|
|
|
int max_width ( void ) const { return _max_width; }
|
|
|
|
|
|
|
|
void vspacing ( int v ) { _vspacing = v; }
|
|
|
|
int vspacing ( void ) const { return _vspacing; };
|
|
|
|
|
|
|
|
void hspacing ( int h ) { _hspacing = h; }
|
|
|
|
int hspacing ( void ) const { return _hspacing; };
|
|
|
|
|
2010-01-27 05:28:39 +01:00
|
|
|
bool flow ( void ) const { return _flow; }
|
|
|
|
void flow ( bool v ) { _flow = v; }
|
|
|
|
|
2009-12-25 01:23:54 +01:00
|
|
|
void
|
|
|
|
add ( Fl_Widget *w )
|
|
|
|
{
|
|
|
|
Fl_Group::add( w );
|
|
|
|
dolayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
remove ( Fl_Widget *w )
|
|
|
|
{
|
|
|
|
Fl_Group::remove( w );
|
|
|
|
dolayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
resize ( int X, int Y, int W, int )
|
|
|
|
{
|
|
|
|
Fl_Group::resize( X, Y, W, layout( W ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
draw ( void )
|
|
|
|
{
|
|
|
|
dolayout();
|
|
|
|
Fl_Group::draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dolayout ( void )
|
|
|
|
{
|
2012-03-03 07:53:21 +01:00
|
|
|
int new_h = layout( w() );
|
|
|
|
|
|
|
|
if ( new_h != h() )
|
|
|
|
size( w(), new_h );
|
2009-12-25 01:23:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
layout ( int W )
|
|
|
|
{
|
|
|
|
resizable( 0 );
|
|
|
|
|
|
|
|
int X = 0;
|
|
|
|
int Y = 0;
|
|
|
|
int H = 0;
|
|
|
|
|
|
|
|
_max_width = 0;
|
|
|
|
|
2013-02-13 01:49:35 +01:00
|
|
|
int LW = 0;
|
|
|
|
int LH = 0;
|
|
|
|
|
2009-12-25 01:23:54 +01:00
|
|
|
for ( int i = 0; i < children(); ++i )
|
|
|
|
{
|
|
|
|
Fl_Widget *o = child( i );
|
|
|
|
|
|
|
|
if ( ! o->visible() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
H = o->h() > H ? o->h() : H;
|
|
|
|
|
2013-02-13 01:49:35 +01:00
|
|
|
if ( _flow )
|
2009-12-25 01:23:54 +01:00
|
|
|
{
|
2013-02-13 01:49:35 +01:00
|
|
|
if ( Y + o->h() < H )
|
|
|
|
{
|
|
|
|
/* if it'll fit in this column, put it below the previous widget */
|
|
|
|
X -= LW + _hspacing;
|
|
|
|
}
|
|
|
|
else if ( X + o->w() >= W )
|
|
|
|
{
|
|
|
|
/* maybe wrap to the next row */
|
|
|
|
H += o->h();
|
|
|
|
|
|
|
|
X = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* otherwise, put it in the next column */
|
|
|
|
Y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LW = o->w();
|
|
|
|
LH = o->h();
|
2009-12-25 01:23:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-03 07:53:21 +01:00
|
|
|
/* avoid bothering the control with lots of resize() calls */
|
|
|
|
if ( ! ( o->x() == x() + X &&
|
|
|
|
o->y() == y() + Y ) )
|
|
|
|
o->position( x() + X, y() + Y );
|
2009-12-25 01:23:54 +01:00
|
|
|
|
2013-02-13 01:49:35 +01:00
|
|
|
Y += LH + _vspacing;
|
|
|
|
X += LW + _hspacing;
|
2009-12-25 01:23:54 +01:00
|
|
|
|
|
|
|
if ( X > _max_width )
|
|
|
|
_max_width = X;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Y + H;
|
|
|
|
}
|
|
|
|
};
|