Fl_Group.H 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // "$Id: Fl_Group.H 12302 2017-07-07 19:16:40Z AlbrechtS $"
  3. //
  4. // Group header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2017 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /* \file
  19. Fl_Group, Fl_End classes . */
  20. #ifndef Fl_Group_H
  21. #define Fl_Group_H
  22. #include "Fl_Widget.H"
  23. //#include "Fl_Rect.H"
  24. typedef int (*Fl_User_Event_Handler)(Fl_Widget *w, int event);
  25. struct st_widget_sizes {
  26. int x,y,w,h;
  27. Fl_Fontsize labelsize, textsize;
  28. };
  29. /**
  30. The Fl_Group class is the FLTK container widget. It maintains
  31. an array of child widgets. These children can themselves be any widget
  32. including Fl_Group. The most important subclass of Fl_Group
  33. is Fl_Window, however groups can also be used to control radio buttons
  34. or to enforce resize behavior.
  35. The tab and arrow keys are used to move the focus between widgets of
  36. this group, and to other groups. The only modifier grabbed is shift
  37. (for shift-tab), so that ctrl-tab, alt-up, and such are free
  38. for the app to use as shortcuts.
  39. */
  40. class FL_EXPORT Fl_Group : public Fl_Widget {
  41. Fl_Widget** array_;
  42. Fl_Widget* savedfocus_;
  43. Fl_Widget* resizable_;
  44. int children_;
  45. st_widget_sizes *sizes_; // remembered initial sizes of children
  46. int navigation(int);
  47. static Fl_Group *current_;
  48. Fl_User_Event_Handler user_handler_;
  49. // unimplemented copy ctor and assignment operator
  50. Fl_Group(const Fl_Group&);
  51. Fl_Group& operator=(const Fl_Group&);
  52. public:
  53. void draw();
  54. protected:
  55. void draw_child(Fl_Widget& widget) const;
  56. void draw_children();
  57. void draw_outside_label(const Fl_Widget& widget) const ;
  58. void update_child(Fl_Widget& widget) const;
  59. st_widget_sizes *sizes();
  60. public:
  61. int handle(int);
  62. void user_handler(Fl_User_Event_Handler uh) {user_handler_ = uh;};
  63. Fl_User_Event_Handler user_handler() {return user_handler_;};
  64. void begin();
  65. void end();
  66. static Fl_Group *current();
  67. static void current(Fl_Group *g);
  68. /**
  69. Returns how many child widgets the group has.
  70. */
  71. int children() const {return children_;}
  72. /**
  73. Returns array()[n]. <i>No range checking is done!</i>
  74. */
  75. Fl_Widget* child(int n) const {return array()[n];}
  76. int find(const Fl_Widget*) const;
  77. /**
  78. See int Fl_Group::find(const Fl_Widget *w) const
  79. */
  80. int find(const Fl_Widget& o) const {return find(&o);}
  81. Fl_Widget* const* array() const;
  82. void resize(int,int,int,int);
  83. /**
  84. Creates a new Fl_Group widget using the given position, size,
  85. and label string. The default boxtype is FL_NO_BOX.
  86. */
  87. Fl_Group(int,int,int,int, const char * = 0);
  88. virtual ~Fl_Group();
  89. void add(Fl_Widget&);
  90. /**
  91. See void Fl_Group::add(Fl_Widget &w)
  92. */
  93. void add(Fl_Widget* o) {add(*o);}
  94. void insert(Fl_Widget&, int i);
  95. /**
  96. This does insert(w, find(before)). This will append the
  97. widget if \p before is not in the group.
  98. */
  99. void insert(Fl_Widget& o, Fl_Widget* before) {insert(o,find(before));}
  100. void remove(int index);
  101. void remove(Fl_Widget&);
  102. /**
  103. Removes the widget \p o from the group.
  104. \sa void remove(Fl_Widget&)
  105. */
  106. void remove(Fl_Widget* o) {remove(*o);}
  107. virtual void clear(); //make it virtual so derived classes will work properly when casted to Fl_Group
  108. /**
  109. See void Fl_Group::resizable(Fl_Widget *box)
  110. */
  111. void resizable(Fl_Widget& o) {resizable_ = &o;}
  112. /**
  113. The resizable widget defines the resizing box for the group. When the
  114. group is resized it calculates a new size and position for all of its
  115. children. Widgets that are horizontally or vertically inside the
  116. dimensions of the box are scaled to the new size. Widgets outside the
  117. box are moved.
  118. In these examples the gray area is the resizable:
  119. \image html resizebox1.png
  120. <br>
  121. \image html resizebox2.png
  122. \image latex resizebox1.png "before resize" width=4cm
  123. \image latex resizebox2.png "after resize" width=4.85cm
  124. The resizable may be set to the group itself, in which case all the
  125. contents are resized. This is the default value for Fl_Group,
  126. although NULL is the default for Fl_Window and Fl_Pack.
  127. If the resizable is NULL then all widgets remain a fixed size
  128. and distance from the top-left corner.
  129. It is possible to achieve any type of resize behavior by using an
  130. invisible Fl_Box as the resizable and/or by using a hierarchy
  131. of child Fl_Group's.
  132. */
  133. void resizable(Fl_Widget* o) {resizable_ = o;}
  134. /**
  135. See void Fl_Group::resizable(Fl_Widget *box)
  136. */
  137. Fl_Widget* resizable() const {return resizable_;}
  138. /**
  139. Adds a widget to the group and makes it the resizable widget.
  140. */
  141. void add_resizable(Fl_Widget& o) {resizable_ = &o; add(o);}
  142. void init_sizes();
  143. /**
  144. Controls whether the group widget clips the drawing of
  145. child widgets to its bounding box.
  146. Set \p c to 1 if you want to clip the child widgets to the
  147. bounding box.
  148. The default is to not clip (0) the drawing of child widgets.
  149. */
  150. void clip_children(int c) { if (c) set_flag(CLIP_CHILDREN); else clear_flag(CLIP_CHILDREN); }
  151. /**
  152. Returns the current clipping mode.
  153. \return true, if clipping is enabled, false otherwise.
  154. \see void Fl_Group::clip_children(int c)
  155. */
  156. unsigned int clip_children() { return (flags() & CLIP_CHILDREN) != 0; }
  157. // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
  158. virtual Fl_Group* as_group() { return this; }
  159. // back compatibility functions:
  160. /**
  161. \deprecated This is for backwards compatibility only. You should use
  162. \e W->%take_focus() instead.
  163. \sa Fl_Widget::take_focus();
  164. */
  165. void focus(Fl_Widget* W) {W->take_focus();}
  166. /** This is for forms compatibility only */
  167. Fl_Widget* & _ddfdesign_kludge() {return resizable_;}
  168. /** This is for forms compatibility only */
  169. void forms_end();
  170. /** Resize the label and font size of its children */
  171. void resizefont(float font_scale);
  172. protected:
  173. /*!
  174. Inner implementation of layout(). The child widgets are resized
  175. and positioned so that the area that was initially surrounded by this
  176. widget now fits inside the rectangle.
  177. \a r is a rectangle, in the coordinate system of this Fl_Group (ie 0,0
  178. is the top-left corner of the Fl_Group).
  179. \a layout_damage controls what is done. If FL_LAYOUT_W or FL_LAYOUT_H are
  180. off then no resizing or moving of widgets in that direction is done.
  181. This is used by Fl_Scroll to resize the widgets to fit inside the
  182. scrollbars.
  183. */
  184. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Group, Fl_Widget)
  185. };
  186. // dummy class used to end child groups in constructors for complex
  187. // subclasses of Fl_Group:
  188. /**
  189. This is a dummy class that allows you to end a Fl_Group in a constructor list of a
  190. class:
  191. \code
  192. class MyClass {
  193. Fl_Group group;
  194. Fl_Button button_in_group;
  195. Fl_End end;
  196. Fl_Button button_outside_group;
  197. MyClass();
  198. };
  199. MyClass::MyClass() :
  200. group(10,10,100,100),
  201. button_in_group(20,20,60,30),
  202. end(),
  203. button_outside_group(10,120,60,30)
  204. {}
  205. \endcode
  206. */
  207. class FL_EXPORT Fl_End {
  208. public:
  209. /** All it does is calling Fl_Group::current()->end() */
  210. Fl_End() {Fl_Group::current()->end();}
  211. };
  212. #endif
  213. //
  214. // End of "$Id: Fl_Group.H 12302 2017-07-07 19:16:40Z AlbrechtS $".
  215. //