Flu_Wrap_Group.H 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // $Id: Flu_Wrap_Group.h,v 1.10 2004/01/27 21:44:21 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_WRAP_GROUP_H
  13. #define _FLU_WRAP_GROUP_H
  14. /* fltk includes */
  15. #include <FL/Fl.H>
  16. #include <FL/fl_draw.H>
  17. #include <FL/Fl_Group.H>
  18. #include <FL/Fl_Scrollbar.H>
  19. #include "FLU/Flu_Enumerations.H"
  20. //! This class provides an alternative to Fl_Group that automatically arranges the children either left to right and top to bottom (for type() == \c FL_VERTICAL), or top to bottom and left to right (for type() == \c FL_HORIZONTAL), within the available size of the group, with a scrollbar turning on if they don't all fit
  21. /*! This class is a group with a scrollbar and an \b Fl_Group inside (both publicly exposed). The \b Fl_Group
  22. contains the actual child widgets of this group.
  23. Most of the \b Fl_Group member functions are reimplemented here in a pass-through fashion to the
  24. internal group. This means that casual use of a descendent instance will be almost exactly the same
  25. as for a regular \b Fl_Group, with any additional access provided directly through member \b group.
  26. The goal of this class is to provide a group that dynamically and evenly distributes its children within
  27. a fixed space, similar to those available in other GUI toolkits.
  28. */
  29. class FLU_EXPORT Flu_Wrap_Group : public Fl_Group
  30. {
  31. DECLARE_CLASS_CHEAP_RTTI_2(Flu_Wrap_Group, Fl_Group)
  32. public:
  33. class Scrollbar : public Fl_Scrollbar
  34. {
  35. public:
  36. Scrollbar( int x, int y, int w, int h, const char *l = 0 );
  37. int handle( int event );
  38. };
  39. //! Normal FLTK constructor
  40. Flu_Wrap_Group( int x, int y, int w, int h, const char *l = 0 );
  41. //! \return the widget that is visibly above \b w in the group, or \c NULL if no such widget exists
  42. Fl_Widget *above( Fl_Widget* w );
  43. //! \return the widget that is visibly below \b w in the group, or \c NULL if no such widget exists
  44. Fl_Widget *below( Fl_Widget* w );
  45. //! Override of Fl_Group::draw()
  46. void draw();
  47. //! \return the widget that is visibly to the left of \b w in the group, or \c NULL if no such widget exists
  48. Fl_Widget *left( Fl_Widget* w );
  49. //! \return the widget that is logically after \b w in the groups order, or \c NULL if no such widget exists
  50. Fl_Widget *next( Fl_Widget* w );
  51. //! Set the offset for where the first child starts
  52. inline void offset( int x, int y )
  53. { _offset[0] = x, _offset[1] = y; redraw(); }
  54. //! \return the x offset for where the first child starts
  55. inline int offset_x() const
  56. { return _offset[0]; }
  57. //! \return the y offset for where the first child starts
  58. inline int offset_y() const
  59. { return _offset[1]; }
  60. //! \return the widget that is logically before \b w in the groups order, or \c NULL if no such widget exists
  61. Fl_Widget *previous( Fl_Widget* w );
  62. //! Override of Fl_Group::resize()
  63. void resize( int x, int y, int w, int h );
  64. //! \return the widget that is visibly to the right of \b w in the group, or \c NULL if no such widget exists
  65. Fl_Widget *right( Fl_Widget* w );
  66. //! Scroll the group so that the given widget is shown (usually aligned to the left/top)
  67. void scroll_to( const Fl_Widget *w );
  68. //! Scroll the group so that the given widget is shown (usually aligned to the left/top)
  69. inline void scroll_to( const Fl_Widget& w )
  70. { scroll_to( &w ); }
  71. //! Scroll the group to the beginning of the list
  72. void scroll_to_beginning();
  73. //! Scroll the group to the end of the list
  74. void scroll_to_end();
  75. //! Set the spacing between children
  76. inline void spacing( int x, int y )
  77. { _spacing[0] = x, _spacing[1] = y; redraw(); }
  78. //! \return the x spacing between children
  79. inline int spacing_x() const
  80. { return _spacing[0]; }
  81. //! \return the y spacing between children
  82. inline int spacing_y() const
  83. { return _spacing[1]; }
  84. //! Set the wrap type. Must be either \c FL_VERTICAL (children wrap according to the width, with a vertical scrollbar) or \c FL_HORIZONTAL (children wrap according to the height, with a horizontal scrollbar). Default is \c FL_HORIZONTAL
  85. void type( int t );
  86. //! Get the wrap type
  87. inline int type() const
  88. { return _type; }
  89. /*! \name Pass-through functions for the internal Fl_Group
  90. * These are strictly for convenience. Only the most commonly called functions have been re-implemented.
  91. * You can also explicitly access the group object for more control.
  92. */
  93. //@{
  94. inline Fl_Widget* const* array() const
  95. { return group.array(); }
  96. inline int find( const Fl_Widget* w ) const
  97. { return group.find( w ); }
  98. inline int find( const Fl_Widget& w ) const
  99. { return group.find( w ); }
  100. inline void clear()
  101. { group.clear(); }
  102. inline Fl_Widget *child(int n) const
  103. { return group.child(n); }
  104. inline int children() const
  105. { return group.children(); }
  106. inline void begin()
  107. { group.begin(); }
  108. inline void end()
  109. { group.end(); Fl_Group::end(); }
  110. inline void resizable(Fl_Widget *box)
  111. { group.resizable(box); }
  112. inline void resizable(Fl_Widget &box)
  113. { group.resizable(box); }
  114. inline Fl_Widget *resizable() const
  115. { return group.resizable(); }
  116. inline void add( Fl_Widget &w )
  117. { group.add( w ); }
  118. inline void add( Fl_Widget *w )
  119. { group.add( w ); }
  120. inline void insert( Fl_Widget &w, int n )
  121. { group.insert( w, n ); }
  122. inline void insert( Fl_Widget &w, Fl_Widget* beforethis )
  123. { group.insert( w, beforethis ); }
  124. inline void remove( Fl_Widget &w )
  125. { group.remove( w ); }
  126. inline void add_resizable( Fl_Widget &box )
  127. { group.add_resizable( box ); }
  128. //@}
  129. Scrollbar scrollbar;
  130. Fl_Group group;
  131. protected:
  132. inline static void _scrollCB( Fl_Widget*, void *arg )
  133. { ((Flu_Wrap_Group*)arg)->redraw(); }
  134. int layout( bool sbVisible, bool doScrollTo, int *measure = 0 );
  135. const Fl_Widget *scrollTo;
  136. int _offset[2], _spacing[2], _type;
  137. };
  138. #endif