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>
|
2013-03-19 06:54:28 +01:00
|
|
|
#include <FL/Fl_Pack.H>
|
2009-12-25 01:23:54 +01:00
|
|
|
|
|
|
|
class Fl_Flowpack : public Fl_Group
|
|
|
|
{
|
|
|
|
int _hspacing;
|
|
|
|
int _vspacing;
|
2010-01-27 05:28:39 +01:00
|
|
|
bool _flow;
|
2013-02-22 03:19:44 +01:00
|
|
|
bool _flowdown;
|
2013-09-08 01:58:16 +02:00
|
|
|
int _initial_height;
|
|
|
|
int _initial_width;
|
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 );
|
2013-09-08 01:58:16 +02:00
|
|
|
_hspacing = _vspacing = 0;
|
|
|
|
_initial_width = W;
|
|
|
|
_initial_height = H;
|
2010-02-01 02:27:00 +01:00
|
|
|
_flow = true;
|
2013-02-22 03:19:44 +01:00
|
|
|
_flowdown = false;
|
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
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2013-02-22 03:19:44 +01:00
|
|
|
bool flowdown ( void ) const { return _flowdown; }
|
|
|
|
void flowdown ( bool v ) { _flowdown = 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
|
2013-03-19 06:28:01 +01:00
|
|
|
resize ( int X, int Y, int W, int H )
|
2009-12-25 01:23:54 +01:00
|
|
|
{
|
2013-09-08 01:58:16 +02:00
|
|
|
_initial_width = W;
|
|
|
|
_initial_height = H;
|
2013-03-19 06:28:01 +01:00
|
|
|
|
2013-09-08 01:58:16 +02:00
|
|
|
layout();
|
2013-03-19 06:28:01 +01:00
|
|
|
|
2013-09-08 01:58:16 +02:00
|
|
|
Fl_Group::resize( X, Y, w(), h() );
|
2009-12-25 01:23:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
draw ( void )
|
|
|
|
{
|
2013-09-08 01:58:16 +02:00
|
|
|
layout();
|
2009-12-25 01:23:54 +01:00
|
|
|
Fl_Group::draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dolayout ( void )
|
|
|
|
{
|
2013-09-08 01:58:16 +02:00
|
|
|
layout();
|
2009-12-25 01:23:54 +01:00
|
|
|
}
|
|
|
|
|
2013-03-19 06:28:01 +01:00
|
|
|
void
|
2013-09-08 01:58:16 +02:00
|
|
|
layout ( void )
|
2009-12-25 01:23:54 +01:00
|
|
|
{
|
|
|
|
resizable( 0 );
|
|
|
|
|
2013-09-08 01:58:16 +02:00
|
|
|
int W;
|
|
|
|
int H;
|
2009-12-25 01:23:54 +01:00
|
|
|
int X = 0;
|
|
|
|
int Y = 0;
|
2013-02-13 01:49:35 +01:00
|
|
|
int LW = 0;
|
|
|
|
int LH = 0;
|
2013-02-22 03:19:44 +01:00
|
|
|
int LX = 0;
|
|
|
|
int LY = 0;
|
2013-04-11 02:22:04 +02:00
|
|
|
int RH = 0;
|
2013-09-15 06:05:41 +02:00
|
|
|
// int RY = 0;
|
|
|
|
int CW = 0;
|
2013-09-08 01:58:16 +02:00
|
|
|
|
|
|
|
if ( _flow )
|
|
|
|
{
|
|
|
|
H = 0;
|
|
|
|
W = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
H = _initial_height;
|
|
|
|
W = _initial_width;
|
|
|
|
}
|
2013-04-11 02:22:04 +02:00
|
|
|
|
2009-12-25 01:23:54 +01:00
|
|
|
for ( int i = 0; i < children(); ++i )
|
|
|
|
{
|
|
|
|
Fl_Widget *o = child( i );
|
|
|
|
|
|
|
|
if ( ! o->visible() )
|
|
|
|
continue;
|
2013-04-11 02:22:04 +02:00
|
|
|
|
2013-02-13 01:49:35 +01:00
|
|
|
if ( _flow )
|
2009-12-25 01:23:54 +01:00
|
|
|
{
|
2013-09-08 01:58:16 +02:00
|
|
|
if ( _flowdown )
|
2013-02-13 01:49:35 +01:00
|
|
|
{
|
2013-09-15 06:05:41 +02:00
|
|
|
if ( Y + o->h() <= _initial_height )
|
2013-09-08 01:58:16 +02:00
|
|
|
{
|
|
|
|
/* if it'll fit in this column, put it below the previous widget */
|
|
|
|
X = LX;
|
|
|
|
}
|
|
|
|
else
|
2013-09-15 06:05:41 +02:00
|
|
|
{
|
|
|
|
Y = H;
|
|
|
|
CW = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CW = o->w() > CW ? o->w() : CW;
|
|
|
|
RH = Y + o->h() > RH ? Y + o->h() : RH;
|
2013-02-13 01:49:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-15 06:05:41 +02:00
|
|
|
if ( X + o->w() >= _initial_width )
|
|
|
|
{
|
|
|
|
/* maybe wrap to the next row */
|
|
|
|
H += RH + _vspacing;
|
|
|
|
// RY = Y;
|
|
|
|
RH = 0;
|
|
|
|
if ( X > W )
|
|
|
|
W = X;
|
|
|
|
|
|
|
|
X = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* otherwise, put it in the next column */
|
|
|
|
Y = H;
|
2013-02-13 01:49:35 +01:00
|
|
|
|
2013-09-15 06:05:41 +02:00
|
|
|
}
|
2009-12-25 01:23:54 +01:00
|
|
|
|
2013-09-15 06:05:41 +02:00
|
|
|
RH = o->h() > RH ? o->h() : RH;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-04-11 02:22:04 +02:00
|
|
|
|
2013-02-22 03:19:44 +01:00
|
|
|
LW = o->w();
|
|
|
|
LH = o->h();
|
|
|
|
|
|
|
|
LX = X;
|
|
|
|
LY = Y;
|
|
|
|
|
|
|
|
if ( _flow )
|
|
|
|
{
|
2013-09-02 20:35:32 +02:00
|
|
|
if ( _flowdown )
|
2013-09-15 06:05:41 +02:00
|
|
|
{
|
2013-09-02 20:35:32 +02:00
|
|
|
Y += LH + _vspacing;
|
2013-09-15 06:05:41 +02:00
|
|
|
X += CW + _hspacing;
|
|
|
|
}
|
2013-09-02 20:35:32 +02:00
|
|
|
else
|
2013-09-15 06:05:41 +02:00
|
|
|
{
|
2013-09-02 20:35:32 +02:00
|
|
|
Y += RH + _vspacing;
|
2013-09-15 06:05:41 +02:00
|
|
|
X += LW + _hspacing;
|
|
|
|
}
|
2013-02-22 03:19:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( type() == Fl_Pack::HORIZONTAL )
|
|
|
|
{
|
|
|
|
X += LW + _hspacing;
|
2013-09-08 01:58:16 +02:00
|
|
|
LH = _initial_height;
|
|
|
|
W = X;
|
2013-02-22 03:19:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Y += LH + _vspacing;
|
2013-09-08 01:58:16 +02:00
|
|
|
LW = _initial_width;
|
|
|
|
H = Y;
|
2013-02-22 03:19:44 +01:00
|
|
|
}
|
|
|
|
}
|
2009-12-25 01:23:54 +01:00
|
|
|
|
2013-09-08 01:58:16 +02:00
|
|
|
|
|
|
|
if ( ! ( o->x() == x() + LX &&
|
|
|
|
o->y() == y() + LY &&
|
|
|
|
o->w() == LW &&
|
|
|
|
o->h() == LH ) )
|
|
|
|
o->resize( x() + LX,
|
|
|
|
y() + LY,
|
|
|
|
LW,
|
|
|
|
LH);
|
2009-12-25 01:23:54 +01:00
|
|
|
}
|
|
|
|
|
2013-09-08 01:58:16 +02:00
|
|
|
if ( _flow )
|
|
|
|
{
|
|
|
|
H += RH;
|
|
|
|
if ( X > W )
|
|
|
|
W = X;
|
2013-04-11 02:22:04 +02:00
|
|
|
|
2013-09-15 06:05:41 +02:00
|
|
|
/* if ( _flowdown ) */
|
|
|
|
/* H = _initial_height; */
|
|
|
|
}
|
|
|
|
|
2013-09-08 01:58:16 +02:00
|
|
|
Fl_Group::resize( x(), y(), W, H );
|
2009-12-25 01:23:54 +01:00
|
|
|
}
|
|
|
|
};
|