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. public:
  32. class Scrollbar : public Fl_Scrollbar
  33. {
  34. public:
  35. Scrollbar( int x, int y, int w, int h, const char *l = 0 );
  36. int handle( int event );
  37. };
  38. //! Normal FLTK constructor
  39. Flu_Wrap_Group( int x, int y, int w, int h, const char *l = 0 );
  40. //! \return the widget that is visibly above \b w in the group, or \c NULL if no such widget exists
  41. Fl_Widget *above( Fl_Widget* w );
  42. //! \return the widget that is visibly below \b w in the group, or \c NULL if no such widget exists
  43. Fl_Widget *below( Fl_Widget* w );
  44. //! Override of Fl_Group::draw()
  45. void draw();
  46. //! \return the widget that is visibly to the left of \b w in the group, or \c NULL if no such widget exists
  47. Fl_Widget *left( Fl_Widget* w );
  48. //! \return the widget that is logically after \b w in the groups order, or \c NULL if no such widget exists
  49. Fl_Widget *next( Fl_Widget* w );
  50. //! Set the offset for where the first child starts
  51. inline void offset( int x, int y )
  52. { _offset[0] = x, _offset[1] = y; redraw(); }
  53. //! \return the x offset for where the first child starts
  54. inline int offset_x() const
  55. { return _offset[0]; }
  56. //! \return the y offset for where the first child starts
  57. inline int offset_y() const
  58. { return _offset[1]; }
  59. //! \return the widget that is logically before \b w in the groups order, or \c NULL if no such widget exists
  60. Fl_Widget *previous( Fl_Widget* w );
  61. //! Override of Fl_Group::resize()
  62. void resize( int x, int y, int w, int h );
  63. //! \return the widget that is visibly to the right of \b w in the group, or \c NULL if no such widget exists
  64. Fl_Widget *right( Fl_Widget* w );
  65. //! Scroll the group so that the given widget is shown (usually aligned to the left/top)
  66. void scroll_to( const Fl_Widget *w );
  67. //! Scroll the group so that the given widget is shown (usually aligned to the left/top)
  68. inline void scroll_to( const Fl_Widget& w )
  69. { scroll_to( &w ); }
  70. //! Scroll the group to the beginning of the list
  71. void scroll_to_beginning();
  72. //! Scroll the group to the end of the list
  73. void scroll_to_end();
  74. //! Set the spacing between children
  75. inline void spacing( int x, int y )
  76. { _spacing[0] = x, _spacing[1] = y; redraw(); }
  77. //! \return the x spacing between children
  78. inline int spacing_x() const
  79. { return _spacing[0]; }
  80. //! \return the y spacing between children
  81. inline int spacing_y() const
  82. { return _spacing[1]; }
  83. //! 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
  84. void type( int t );
  85. //! Get the wrap type
  86. inline int type() const
  87. { return _type; }
  88. /*! \name Pass-through functions for the internal Fl_Group
  89. * These are strictly for convenience. Only the most commonly called functions have been re-implemented.
  90. * You can also explicitly access the group object for more control.
  91. */
  92. //@{
  93. inline Fl_Widget* const* array() const
  94. { return group.array(); }
  95. inline int find( const Fl_Widget* w ) const
  96. { return group.find( w ); }
  97. inline int find( const Fl_Widget& w ) const
  98. { return group.find( w ); }
  99. inline void clear()
  100. { group.clear(); }
  101. inline Fl_Widget *child(int n) const
  102. { return group.child(n); }
  103. inline int children() const
  104. { return group.children(); }
  105. inline void begin()
  106. { group.begin(); }
  107. inline void end()
  108. { group.end(); Fl_Group::end(); }
  109. inline void resizable(Fl_Widget *box)
  110. { group.resizable(box); }
  111. inline void resizable(Fl_Widget &box)
  112. { group.resizable(box); }
  113. inline Fl_Widget *resizable() const
  114. { return group.resizable(); }
  115. inline void add( Fl_Widget &w )
  116. { group.add( w ); }
  117. inline void add( Fl_Widget *w )
  118. { group.add( w ); }
  119. inline void insert( Fl_Widget &w, int n )
  120. { group.insert( w, n ); }
  121. inline void insert( Fl_Widget &w, Fl_Widget* beforethis )
  122. { group.insert( w, beforethis ); }
  123. inline void remove( Fl_Widget &w )
  124. { group.remove( w ); }
  125. inline void add_resizable( Fl_Widget &box )
  126. { group.add_resizable( box ); }
  127. //@}
  128. Scrollbar scrollbar;
  129. Fl_Group group;
  130. protected:
  131. inline static void _scrollCB( Fl_Widget*, void *arg )
  132. { ((Flu_Wrap_Group*)arg)->redraw(); }
  133. int layout( bool sbVisible, bool doScrollTo, int *measure = 0 );
  134. const Fl_Widget *scrollTo;
  135. int _offset[2], _spacing[2], _type;
  136. };
  137. #endif