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.

190 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. for ( int i = 0; i < children(); ++i )
  97. {
  98. Fl_Widget *o = child( i );
  99. if ( ! o->visible() )
  100. continue;
  101. H = o->h() > H ? o->h() : H;
  102. if ( _flow )
  103. {
  104. if ( _flowdown && Y + o->h() < H )
  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 += o->h();
  113. X = 0;
  114. }
  115. else
  116. {
  117. /* otherwise, put it in the next column */
  118. Y = 0;
  119. }
  120. }
  121. LW = o->w();
  122. LH = o->h();
  123. /* avoid bothering the control with lots of resize() calls */
  124. LX = X;
  125. LY = Y;
  126. if ( ! ( o->x() == x() + LX &&
  127. o->y() == y() + LY ) )
  128. o->position( x() + LX, y() + LY );
  129. if ( _flow )
  130. {
  131. Y += LH + _vspacing;
  132. X += LW + _hspacing;
  133. }
  134. else
  135. {
  136. if ( type() == Fl_Pack::HORIZONTAL )
  137. {
  138. X += LW + _hspacing;
  139. }
  140. else
  141. {
  142. Y += LH + _vspacing;
  143. }
  144. }
  145. if ( X > _max_width )
  146. _max_width = X;
  147. }
  148. if ( ! _flow )
  149. W = X;
  150. }
  151. };