Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.7KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2009 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #pragma once
  19. #include <FL/Fl_Group.H>
  20. class Fl_Flowpack : public Fl_Group
  21. {
  22. int _hspacing;
  23. int _vspacing;
  24. int _max_width;
  25. bool _flow;
  26. public:
  27. Fl_Flowpack ( int X, int Y, int W, int H, const char *L = 0 )
  28. : Fl_Group( X, Y, W, H, L )
  29. {
  30. resizable( 0 );
  31. _max_width = _hspacing = _vspacing = 0;
  32. _flow = true;
  33. }
  34. virtual ~Fl_Flowpack ( )
  35. {
  36. }
  37. int max_width ( void ) const { return _max_width; }
  38. void vspacing ( int v ) { _vspacing = v; }
  39. int vspacing ( void ) const { return _vspacing; };
  40. void hspacing ( int h ) { _hspacing = h; }
  41. int hspacing ( void ) const { return _hspacing; };
  42. bool flow ( void ) const { return _flow; }
  43. void flow ( bool v ) { _flow = v; }
  44. void
  45. add ( Fl_Widget *w )
  46. {
  47. Fl_Group::add( w );
  48. dolayout();
  49. }
  50. void
  51. remove ( Fl_Widget *w )
  52. {
  53. Fl_Group::remove( w );
  54. dolayout();
  55. }
  56. void
  57. resize ( int X, int Y, int W, int )
  58. {
  59. Fl_Group::resize( X, Y, W, layout( W ) );
  60. }
  61. void
  62. draw ( void )
  63. {
  64. dolayout();
  65. Fl_Group::draw();
  66. }
  67. void dolayout ( void )
  68. {
  69. int new_h = layout( w() );
  70. if ( new_h != h() )
  71. size( w(), new_h );
  72. }
  73. int
  74. layout ( int W )
  75. {
  76. resizable( 0 );
  77. int X = 0;
  78. int Y = 0;
  79. int H = 0;
  80. _max_width = 0;
  81. for ( int i = 0; i < children(); ++i )
  82. {
  83. Fl_Widget *o = child( i );
  84. if ( ! o->visible() )
  85. continue;
  86. H = o->h() > H ? o->h() : H;
  87. if ( _flow && X + o->w() >= W )
  88. {
  89. Y += H + _vspacing;
  90. H = o->h();
  91. X = 0;
  92. }
  93. /* avoid bothering the control with lots of resize() calls */
  94. if ( ! ( o->x() == x() + X &&
  95. o->y() == y() + Y ) )
  96. o->position( x() + X, y() + Y );
  97. X += o->w() + _hspacing;
  98. if ( X > _max_width )
  99. _max_width = X;
  100. }
  101. return Y + H;
  102. }
  103. };