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.

179 lines
5.0KB

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