Flu_Collapsable_Group.H 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // $Id: Flu_Collapsable_Group.h,v 1.8 2003/09/24 21:13:47 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #ifndef _FLU_COLLAPSABLE_GROUP_H
  13. #define _FLU_COLLAPSABLE_GROUP_H
  14. #include <stdio.h>
  15. #include <string.h>
  16. /* fltk includes */
  17. #include <FL/Fl.H>
  18. #include <FL/fl_draw.H>
  19. #include <FL/Fl_Group.H>
  20. #include <FL/Fl_Box.H>
  21. #include "FLU/FluSimpleString.H"
  22. #include "FLU/Flu_Button.H"
  23. //! This widget implements a collapsable group with a configurable framerate
  24. /*! This class is a group with a button and an \b Fl_Group inside (both publicly exposed). The \b Fl_Group
  25. contains the actual child widgets of this group.
  26. Most of the \b Fl_Group member functions are reimplemented here in a pass-through fashion to the
  27. internal group. This means that casual use of a descendent instance will be almost exactly the same
  28. as for a regular \b Fl_Group, with any additional access provided directly through member \b group.
  29. The goal of this class is to provide a dynamically collapsable group similar to those available in
  30. other GUI toolkits.
  31. The callback is invoked whenever the button is pressed to open/close the group.
  32. */
  33. class FLU_EXPORT Flu_Collapsable_Group : public Fl_Group
  34. {
  35. public:
  36. //! Normal FLTK constructor
  37. Flu_Collapsable_Group( int x, int y, int w, int h, const char *l = 0 );
  38. //! Get the amount of time to take when animating a collapse
  39. inline float collapse_time() const
  40. { return _collapseTime; }
  41. //! Set the amount of time to take when animating a collapse
  42. inline void collapse_time( float t )
  43. { _collapseTime = t; }
  44. //! Get the frame rate to aim for during a collapse animation
  45. inline float frame_rate() const
  46. { return _fps; }
  47. //! Set the frame rate to aim for during a collapse animation
  48. inline void frame_rate( float f )
  49. { _fps = f; }
  50. //! Set the position of the controller widget along the top edge of the group. This only has an effect if fit() is not set. Default value is \c FL_ALIGN_LEFT
  51. /*! Accepted values are \c FL_ALIGN_LEFT, \c FL_ALIGN_CENTER, and \c FL_ALIGN_RIGHT */
  52. inline void align( unsigned char a )
  53. { _align = a; }
  54. //! Get the position of the controller widget along the top edge of the group
  55. inline unsigned char align() const
  56. { return _align; }
  57. //! Pass \c true to force the button to be the same width as the group, \c false to leave it its default size. Default value is \c false
  58. inline void fit( bool b )
  59. { _fit = b; }
  60. //! Get whether the button is being forced to fit the width of the group
  61. inline bool fit() const
  62. { return _fit; }
  63. //! Get whether the group is closed or open (i.e. collapsed or not)
  64. inline bool open() const
  65. { return _open; }
  66. //! Set whether the group is closed or open (i.e. collapsed or not). Default is \c true
  67. void open( bool o );
  68. //! Get whether the group is closed or open (i.e. collapsed or not)
  69. inline bool closed() const
  70. { return !_open; }
  71. //! Get whether the group is in the process of opening or closing
  72. inline bool changing() const
  73. { return _changing; }
  74. //! Override of Fl_Group::resize()
  75. void resize( int x, int y, int w, int h );
  76. //! Override of Fl_Group::label()
  77. inline void label( const char *l )
  78. { if( l ) _label = l; else _label = ""; }
  79. //! Override of Fl_Group::label()
  80. inline const char *label()
  81. { return _label.c_str(); }
  82. //////////////////////
  83. /*! \name Pass-through functions for the internal Fl_Group
  84. * These are strictly for convenience. Only the most commonly called functions have been re-implemented.
  85. * You can also explicitly access the group object for more control.
  86. */
  87. //@{
  88. inline void clear()
  89. { group.clear(); }
  90. inline Fl_Widget *child(int n) const
  91. { return group.child(n); }
  92. inline int children() const
  93. { return group.children(); }
  94. inline void begin()
  95. { group.begin(); }
  96. inline void end()
  97. { group.end(); Fl_Group::end(); }
  98. inline void resizable(Fl_Widget *box)
  99. { group.resizable(box); }
  100. inline void resizable(Fl_Widget &box)
  101. { group.resizable(box); }
  102. inline Fl_Widget *resizable() const
  103. { return group.resizable(); }
  104. inline void add( Fl_Widget &w )
  105. { group.add( w ); }
  106. inline void add( Fl_Widget *w )
  107. { group.add( w ); }
  108. inline void insert( Fl_Widget &w, int n )
  109. { group.insert( w, n ); }
  110. inline void insert( Fl_Widget &w, Fl_Widget* beforethis )
  111. { group.insert( w, beforethis ); }
  112. inline void remove( Fl_Widget &w )
  113. { group.remove( w ); }
  114. inline void add_resizable( Fl_Widget &box )
  115. { group.add_resizable( box ); }
  116. //@}
  117. Flu_Button button;
  118. Fl_Group group;
  119. DECLARE_CLASS_CHEAP_RTTI_2(Flu_Collapsable_Group, Fl_Group)
  120. protected:
  121. //////////////////////////
  122. void draw();
  123. inline static void _collapseCB( Fl_Widget* w, void* arg )
  124. { ((Flu_Collapsable_Group*)arg)->open( !((Flu_Collapsable_Group*)arg)->open() ); }
  125. inline static void _updateCB( void *arg )
  126. { ((Flu_Collapsable_Group*)arg)->updateCB(); }
  127. void updateCB();
  128. void (*_callback)(Fl_Widget*,void*);
  129. void *_callbackData;
  130. void (*_collapseCallback)(void*);
  131. void *_collapseCallbackData;
  132. int _originalHeight, _newHeight;
  133. float _deltaHeight, _currentHeight, _collapseTime, _timeout, _fps;
  134. Fl_Widget *_oldResizable;
  135. bool _open, _changing, _fit;
  136. unsigned char _align;
  137. FluSimpleString _label;
  138. };
  139. #endif