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.

194 lines
5.2KB

  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. #include <FL/Fl_Pack.H>
  21. class Fl_Flowpack : public Fl_Group
  22. {
  23. int _hspacing;
  24. int _vspacing;
  25. int _max_width;
  26. bool _flow;
  27. bool _flowdown;
  28. public:
  29. Fl_Flowpack ( int X, int Y, int W, int H, const char *L = 0 )
  30. : Fl_Group( X, Y, W, H, L )
  31. {
  32. resizable( 0 );
  33. _max_width = _hspacing = _vspacing = 0;
  34. _flow = true;
  35. _flowdown = false;
  36. }
  37. virtual ~Fl_Flowpack ( )
  38. {
  39. }
  40. int max_width ( void ) const { return _max_width; }
  41. void vspacing ( int v ) { _vspacing = v; }
  42. int vspacing ( void ) const { return _vspacing; };
  43. void hspacing ( int h ) { _hspacing = h; }
  44. int hspacing ( void ) const { return _hspacing; };
  45. bool flow ( void ) const { return _flow; }
  46. void flow ( bool v ) { _flow = v; }
  47. bool flowdown ( void ) const { return _flowdown; }
  48. void flowdown ( bool v ) { _flowdown = v; }
  49. void
  50. add ( Fl_Widget *w )
  51. {
  52. Fl_Group::add( w );
  53. dolayout();
  54. }
  55. void
  56. remove ( Fl_Widget *w )
  57. {
  58. Fl_Group::remove( w );
  59. dolayout();
  60. }
  61. void
  62. resize ( int X, int Y, int W, int H )
  63. {
  64. int NW = W;
  65. int NH = H;
  66. layout( NW, NH );
  67. Fl_Group::resize( X, Y, NW, NH );
  68. }
  69. void
  70. draw ( void )
  71. {
  72. dolayout();
  73. Fl_Group::draw();
  74. }
  75. void dolayout ( void )
  76. {
  77. int H = h();
  78. int W = w();
  79. layout( W, H );
  80. if ( H != h() || W != w() )
  81. size( W, H );
  82. }
  83. void
  84. layout ( int &W, int &H )
  85. {
  86. resizable( 0 );
  87. int X = 0;
  88. int Y = 0;
  89. H = 0;
  90. /* int H = 0; */
  91. _max_width = 0;
  92. int LW = 0;
  93. int LH = 0;
  94. int LX = 0;
  95. int LY = 0;
  96. int RH = 0;
  97. for ( int i = 0; i < children(); ++i )
  98. {
  99. Fl_Widget *o = child( i );
  100. if ( ! o->visible() )
  101. continue;
  102. if ( _flow )
  103. {
  104. if ( _flowdown && Y + o->h() < RH )
  105. {
  106. /* if it'll fit in this column, put it below the previous widget */
  107. X = LX;
  108. }
  109. else if ( X + o->w() >= W )
  110. {
  111. /* maybe wrap to the next row */
  112. H += RH + _vspacing;
  113. RH = 0;
  114. X = 0;
  115. }
  116. else
  117. {
  118. /* otherwise, put it in the next column */
  119. Y = H;
  120. }
  121. }
  122. RH = o->h() > RH ? o->h() : RH;
  123. LW = o->w();
  124. LH = o->h();
  125. /* avoid bothering the control with lots of resize() calls */
  126. LX = X;
  127. LY = Y;
  128. if ( ! ( o->x() == x() + LX &&
  129. o->y() == y() + LY ) )
  130. o->position( x() + LX, y() + LY );
  131. if ( _flow )
  132. {
  133. Y += LH + _vspacing;
  134. X += LW + _hspacing;
  135. }
  136. else
  137. {
  138. if ( type() == Fl_Pack::HORIZONTAL )
  139. {
  140. X += LW + _hspacing;
  141. }
  142. else
  143. {
  144. Y += LH + _vspacing;
  145. }
  146. }
  147. if ( X > _max_width )
  148. _max_width = X;
  149. }
  150. H += RH;
  151. if ( ! _flow )
  152. W = X;
  153. }
  154. };