Fl_Scroll.H 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // "$Id: Fl_Scroll.H 11692 2016-04-24 19:39:27Z manolo $"
  3. //
  4. // Scroll header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2015 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_Scroll widget . */
  20. #ifndef Fl_Scroll_H
  21. #define Fl_Scroll_H
  22. #include "Fl_Group.H"
  23. #include "Fl_Scrollbar.H"
  24. /**
  25. This container widget lets you maneuver around a set of widgets much
  26. larger than your window. If the child widgets are larger than the size
  27. of this object then scrollbars will appear so that you can scroll over
  28. to them:
  29. \image html Fl_Scroll.png
  30. \image latex Fl_Scroll.png "Fl_Scroll" width=4cm
  31. If all of the child widgets are packed together into a solid
  32. rectangle then you want to set box() to FL_NO_BOX or
  33. one of the _FRAME types. This will result in the best output.
  34. However, if the child widgets are a sparse arrangement you must
  35. set box() to a real _BOX type. This can result in some
  36. blinking during redrawing, but that can be solved by using a
  37. Fl_Double_Window.
  38. By default you can scroll in both directions, and the scrollbars
  39. disappear if the data will fit in the area of the scroll.
  40. Use Fl_Scroll::type() to change this as follows :
  41. - 0 - No scrollbars
  42. - Fl_Scroll::HORIZONTAL - Only a horizontal scrollbar.
  43. - Fl_Scroll::VERTICAL - Only a vertical scrollbar.
  44. - Fl_Scroll::BOTH - The default is both scrollbars.
  45. - Fl_Scroll::HORIZONTAL_ALWAYS - Horizontal scrollbar always on, vertical always off.
  46. - Fl_Scroll::VERTICAL_ALWAYS - Vertical scrollbar always on, horizontal always off.
  47. - Fl_Scroll::BOTH_ALWAYS - Both always on.
  48. Use <B> scrollbar.align(int) ( see void Fl_Widget::align(Fl_Align) ) :</B>
  49. to change what side the scrollbars are drawn on.
  50. If the FL_ALIGN_LEFT bit is on, the vertical scrollbar is on the left.
  51. If the FL_ALIGN_TOP bit is on, the horizontal scrollbar is on
  52. the top. Note that only the alignment flags in scrollbar are
  53. considered. The flags in hscrollbar however are ignored.
  54. This widget can also be used to pan around a single child widget
  55. "canvas". This child widget should be of your own class, with a
  56. draw() method that draws the contents. The scrolling is done by
  57. changing the x() and y() of the widget, so this child
  58. must use the x() and y() to position its drawing.
  59. To speed up drawing it should test fl_not_clipped(int x,int y,int w,int h)
  60. to find out if a particular area of the widget must be drawn.
  61. Another very useful child is a single Fl_Pack, which is itself a group
  62. that packs its children together and changes size to surround them.
  63. Filling the Fl_Pack with Fl_Tabs groups (and then putting
  64. normal widgets inside those) gives you a very powerful scrolling list
  65. of individually-openable panels.
  66. Fluid lets you create these, but you can only lay out objects that
  67. fit inside the Fl_Scroll without scrolling. Be sure to leave
  68. space for the scrollbars, as Fluid won't show these either.
  69. <I>You cannot use Fl_Window as a child of this since the
  70. clipping is not conveyed to it when drawn, and it will draw over the
  71. scrollbars and neighboring objects.</I>
  72. */
  73. class FL_EXPORT Fl_Scroll : public Fl_Group {
  74. int xposition_, yposition_;
  75. int oldx, oldy;
  76. int scrollbar_size_;
  77. static void hscrollbar_cb(Fl_Widget*, void*);
  78. static void scrollbar_cb(Fl_Widget*, void*);
  79. void fix_scrollbar_order();
  80. static void draw_clip(void*,int,int,int,int);
  81. protected: // (STR#1895)
  82. /**
  83. Structure to manage scrollbar and widget interior sizes.
  84. This is filled out by recalc_scrollbars() for use in calculations
  85. that need to know the visible scroll area size, etc.
  86. \version 1.3.3
  87. */
  88. typedef struct {
  89. /// A local struct to manage a region defined by xywh
  90. typedef struct { int x,y,w,h; } Fl_Region_XYWH;
  91. /// A local struct to manage a region defined by left/right/top/bottom
  92. typedef struct {
  93. int l; ///< (l)eft "x" position, aka x1
  94. int r; ///< (r)ight "x" position, aka x2
  95. int t; ///< (t)op "y" position, aka y1
  96. int b; ///< (b)ottom "y" position, aka y2
  97. } Fl_Region_LRTB;
  98. /// A local struct to manage a scrollbar's xywh region and tab values
  99. typedef struct {
  100. int x,y,w,h;
  101. int pos; ///< scrollbar tab's "position of first line displayed"
  102. int size; ///< scrollbar tab's "size of window in lines"
  103. int first; ///< scrollbar tab's "number of first line"
  104. int total; ///< scrollbar tab's "total number of lines"
  105. } Fl_Scrollbar_Data;
  106. int scrollsize; ///< the effective scrollbar thickness (local or global)
  107. Fl_Region_XYWH innerbox; ///< widget's inner box, excluding scrollbars
  108. Fl_Region_XYWH innerchild; ///< widget's inner box, including scrollbars
  109. Fl_Region_LRTB child; ///< child bounding box: left/right/top/bottom
  110. int hneeded; ///< horizontal scrollbar visibility
  111. int vneeded; ///< vertical scrollbar visibility
  112. Fl_Scrollbar_Data hscroll; ///< horizontal scrollbar region + values
  113. Fl_Scrollbar_Data vscroll; ///< vertical scrollbar region + values
  114. } ScrollInfo;
  115. void recalc_scrollbars(ScrollInfo &si);
  116. protected:
  117. void bbox(int&,int&,int&,int&);
  118. void draw();
  119. public:
  120. Fl_Scrollbar scrollbar;
  121. Fl_Scrollbar hscrollbar;
  122. void resize(int X, int Y, int W, int H);
  123. int handle(int);
  124. Fl_Scroll(int X,int Y,int W,int H,const char*l=0);
  125. enum { // values for type()
  126. HORIZONTAL = 1,
  127. VERTICAL = 2,
  128. BOTH = 3,
  129. ALWAYS_ON = 4,
  130. HORIZONTAL_ALWAYS = 5,
  131. VERTICAL_ALWAYS = 6,
  132. BOTH_ALWAYS = 7
  133. };
  134. /** Gets the current horizontal scrolling position. */
  135. int xposition() const {return xposition_;}
  136. /** Gets the current vertical scrolling position. */
  137. int yposition() const {return yposition_;}
  138. void scroll_to(int, int);
  139. void clear();
  140. /**
  141. Gets the current size of the scrollbars' troughs, in pixels.
  142. If this value is zero (default), this widget will use the
  143. Fl::scrollbar_size() value as the scrollbar's width.
  144. \returns Scrollbar size in pixels, or 0 if the global Fl::scrollbar_size() is being used.
  145. \see Fl::scrollbar_size(int)
  146. */
  147. int scrollbar_size() const {
  148. return(scrollbar_size_);
  149. }
  150. /**
  151. Sets the pixel size of the scrollbars' troughs to \p newSize, in pixels.
  152. Normally you should not need this method, and should use
  153. Fl::scrollbar_size(int) instead to manage the size of ALL
  154. your widgets' scrollbars. This ensures your application
  155. has a consistent UI, is the default behavior, and is normally
  156. what you want.
  157. Only use THIS method if you really need to override the global
  158. scrollbar size. The need for this should be rare.
  159. Setting \p newSize to the special value of 0 causes the widget to
  160. track the global Fl::scrollbar_size(), which is the default.
  161. \param[in] newSize Sets the scrollbar size in pixels.\n
  162. If 0 (default), scrollbar size tracks the global Fl::scrollbar_size()
  163. \see Fl::scrollbar_size()
  164. */
  165. void scrollbar_size(int newSize) {
  166. if ( newSize != scrollbar_size_ ) redraw();
  167. scrollbar_size_ = newSize;
  168. }
  169. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Scroll, Fl_Group)
  170. };
  171. #endif
  172. //
  173. // End of "$Id: Fl_Scroll.H 11692 2016-04-24 19:39:27Z manolo $".
  174. //