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.

231 lines
6.5KB

  1. //
  2. // "$Id: Fl_Group.H 8157 2011-01-01 14:01:53Z AlbrechtS $"
  3. //
  4. // Group header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /* \file
  28. Fl_Group, Fl_End classes . */
  29. #ifndef Fl_Group_H
  30. #define Fl_Group_H
  31. #ifndef Fl_Widget_H
  32. #include "Fl_Widget.H"
  33. #endif
  34. /**
  35. The Fl_Group class is the FLTK container widget. It maintains
  36. an array of child widgets. These children can themselves be any widget
  37. including Fl_Group. The most important subclass of Fl_Group
  38. is Fl_Window, however groups can also be used to control radio buttons
  39. or to enforce resize behavior.
  40. */
  41. class FL_EXPORT Fl_Group : public Fl_Widget {
  42. Fl_Widget** array_;
  43. Fl_Widget* savedfocus_;
  44. Fl_Widget* resizable_;
  45. int children_;
  46. int *sizes_; // remembered initial sizes of children
  47. int navigation(int);
  48. static Fl_Group *current_;
  49. // unimplemented copy ctor and assignment operator
  50. Fl_Group(const Fl_Group&);
  51. Fl_Group& operator=(const Fl_Group&);
  52. protected:
  53. void draw();
  54. void draw_child(Fl_Widget& widget) const;
  55. void draw_children();
  56. void draw_outside_label(const Fl_Widget& widget) const ;
  57. void update_child(Fl_Widget& widget) const;
  58. int *sizes();
  59. public:
  60. int handle(int);
  61. void begin();
  62. void end();
  63. static Fl_Group *current();
  64. static void current(Fl_Group *g);
  65. /**
  66. Returns how many child widgets the group has.
  67. */
  68. int children() const {return children_;}
  69. /**
  70. Returns array()[n]. <i>No range checking is done!</i>
  71. */
  72. Fl_Widget* child(int n) const {return array()[n];}
  73. int find(const Fl_Widget*) const;
  74. /**
  75. See int Fl_Group::find(const Fl_Widget *w) const
  76. */
  77. int find(const Fl_Widget& o) const {return find(&o);}
  78. Fl_Widget* const* array() const;
  79. void resize(int,int,int,int);
  80. /**
  81. Creates a new Fl_Group widget using the given position, size,
  82. and label string. The default boxtype is FL_NO_BOX.
  83. */
  84. Fl_Group(int,int,int,int, const char * = 0);
  85. virtual ~Fl_Group();
  86. void add(Fl_Widget&);
  87. /**
  88. See void Fl_Group::add(Fl_Widget &w)
  89. */
  90. void add(Fl_Widget* o) {add(*o);}
  91. void insert(Fl_Widget&, int i);
  92. /**
  93. This does insert(w, find(before)). This will append the
  94. widget if \p before is not in the group.
  95. */
  96. void insert(Fl_Widget& o, Fl_Widget* before) {insert(o,find(before));}
  97. void remove(int index);
  98. void remove(Fl_Widget&);
  99. /**
  100. Removes the widget \p o from the group.
  101. \sa void remove(Fl_Widget&)
  102. */
  103. void remove(Fl_Widget* o) {remove(*o);}
  104. void clear();
  105. /**
  106. See void Fl_Group::resizable(Fl_Widget *box)
  107. */
  108. void resizable(Fl_Widget& o) {resizable_ = &o;}
  109. /**
  110. The resizable widget defines the resizing box for the group. When the
  111. group is resized it calculates a new size and position for all of its
  112. children. Widgets that are horizontally or vertically inside the
  113. dimensions of the box are scaled to the new size. Widgets outside the
  114. box are moved.
  115. In these examples the gray area is the resizable:
  116. \image html resizebox1.png
  117. \image html resizebox2.png
  118. \image latex resizebox1.png "before resize" width=4cm
  119. \image latex resizebox2.png "after resize" width=4cm
  120. The resizable may be set to the group itself, in which case all the
  121. contents are resized. This is the default value for Fl_Group,
  122. although NULL is the default for Fl_Window and Fl_Pack.
  123. If the resizable is NULL then all widgets remain a fixed size
  124. and distance from the top-left corner.
  125. It is possible to achieve any type of resize behavior by using an
  126. invisible Fl_Box as the resizable and/or by using a hierarchy
  127. of child Fl_Group's.
  128. */
  129. void resizable(Fl_Widget* o) {resizable_ = o;}
  130. /**
  131. See void Fl_Group::resizable(Fl_Widget *box)
  132. */
  133. Fl_Widget* resizable() const {return resizable_;}
  134. /**
  135. Adds a widget to the group and makes it the resizable widget.
  136. */
  137. void add_resizable(Fl_Widget& o) {resizable_ = &o; add(o);}
  138. void init_sizes();
  139. /**
  140. Controls whether the group widget clips the drawing of
  141. child widgets to its bounding box.
  142. Set \p c to 1 if you want to clip the child widgets to the
  143. bounding box.
  144. The default is to not clip (0) the drawing of child widgets.
  145. */
  146. void clip_children(int c) { if (c) set_flag(CLIP_CHILDREN); else clear_flag(CLIP_CHILDREN); }
  147. /**
  148. Returns the current clipping mode.
  149. \return true, if clipping is enabled, false otherwise.
  150. \see void Fl_Group::clip_children(int c)
  151. */
  152. unsigned int clip_children() { return (flags() & CLIP_CHILDREN) != 0; }
  153. // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
  154. virtual Fl_Group* as_group() { return this; }
  155. // back compatibility functions:
  156. /**
  157. \deprecated This is for backwards compatibility only. You should use
  158. \e W->%take_focus() instead.
  159. \sa Fl_Widget::take_focus();
  160. */
  161. void focus(Fl_Widget* W) {W->take_focus();}
  162. /** This is for forms compatibility only */
  163. Fl_Widget* & _ddfdesign_kludge() {return resizable_;}
  164. /** This is for forms compatibility only */
  165. void forms_end();
  166. };
  167. // dummy class used to end child groups in constructors for complex
  168. // subclasses of Fl_Group:
  169. /**
  170. This is a dummy class that allows you to end a Fl_Group in a constructor list of a
  171. class:
  172. \code
  173. class MyClass {
  174. Fl_Group group;
  175. Fl_Button button_in_group;
  176. Fl_End end;
  177. Fl_Button button_outside_group;
  178. MyClass();
  179. };
  180. MyClass::MyClass() :
  181. group(10,10,100,100),
  182. button_in_group(20,20,60,30),
  183. end(),
  184. button_outside_group(10,120,60,30)
  185. {}
  186. \endcode
  187. */
  188. class FL_EXPORT Fl_End {
  189. public:
  190. /** All it does is calling Fl_Group::current()->end() */
  191. Fl_End() {Fl_Group::current()->end();}
  192. };
  193. #endif
  194. //
  195. // End of "$Id: Fl_Group.H 8157 2011-01-01 14:01:53Z AlbrechtS $".
  196. //