Fl_Scroll.H 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // "$Id: Fl_Scroll.H 9126 2011-10-04 13:10:55Z manolo $"
  3. //
  4. // Scroll 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. 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. <UL>
  42. <LI>0 - No scrollbars </LI>
  43. <LI>Fl_Scroll::HORIZONTAL - Only a horizontal scrollbar. </LI>
  44. <LI>Fl_Scroll::VERTICAL - Only a vertical scrollbar. </LI>
  45. <LI>Fl_Scroll::BOTH - The default is both scrollbars. </LI>
  46. <LI>Fl_Scroll::HORIZONTAL_ALWAYS - Horizontal scrollbar always on, vertical always off. </LI>
  47. <LI>Fl_Scroll::VERTICAL_ALWAYS - Vertical scrollbar always on, horizontal always off. </LI>
  48. <LI>Fl_Scroll::BOTH_ALWAYS - Both always on. </LI>
  49. </UL>
  50. Use <B> scrollbar.align(int) ( see void Fl_Widget::align(Fl_Align) ) :</B>
  51. to change what side the scrollbars are drawn on.
  52. If the FL_ALIGN_LEFT bit is on, the vertical scrollbar is on the left.
  53. If the FL_ALIGN_TOP bit is on, the horizontal scrollbar is on
  54. the top. Note that only the alignment flags in scrollbar are
  55. considered. The flags in hscrollbar however are ignored.
  56. This widget can also be used to pan around a single child widget
  57. "canvas". This child widget should be of your own class, with a
  58. draw() method that draws the contents. The scrolling is done by
  59. changing the x() and y() of the widget, so this child
  60. must use the x() and y() to position its drawing.
  61. To speed up drawing it should test fl_push_clip().
  62. Another very useful child is a single Fl_Pack, which is itself a group
  63. that packs its children together and changes size to surround them.
  64. Filling the Fl_Pack with Fl_Tabs groups (and then putting
  65. normal widgets inside those) gives you a very powerful scrolling list
  66. of individually-openable panels.
  67. Fluid lets you create these, but you can only lay out objects that
  68. fit inside the Fl_Scroll without scrolling. Be sure to leave
  69. space for the scrollbars, as Fluid won't show these either.
  70. <I>You cannot use Fl_Window as a child of this since the
  71. clipping is not conveyed to it when drawn, and it will draw over the
  72. scrollbars and neighboring objects.</I>
  73. */
  74. class FL_EXPORT Fl_Scroll : public Fl_Group {
  75. int xposition_, yposition_;
  76. int oldx, oldy;
  77. int scrollbar_size_;
  78. static void hscrollbar_cb(Fl_Widget*, void*);
  79. static void scrollbar_cb(Fl_Widget*, void*);
  80. void fix_scrollbar_order();
  81. static void draw_clip(void*,int,int,int,int);
  82. private:
  83. //
  84. // Structure to manage scrollbar and widget interior sizes.
  85. //
  86. // Private for now -- we'd like to expose some of this at
  87. // some point to solve STR#1895.)
  88. //
  89. typedef struct {
  90. int scrollsize; // the scrollsize (global|local)
  91. int innerbox_x, innerbox_y, innerbox_w, innerbox_h; // widget's inner box (excludes scrollbars)
  92. int innerchild_x, innerchild_y, innerchild_w, innerchild_h; // widget's inner box including scrollbars
  93. int child_l, child_r, child_b, child_t; // child bounding box: left/right/bottom/top
  94. int hneeded, vneeded; // hor + ver scrollbar visibility
  95. int hscroll_x, hscroll_y, hscroll_w, hscroll_h; // hor scrollbar size/position
  96. int vscroll_x, vscroll_y, vscroll_w, vscroll_h; // ver scrollbar size/position
  97. int hpos, hsize, hfirst, htotal; // hor scrollbar values (pos/size/first/total)
  98. int vpos, vsize, vfirst, vtotal; // ver scrollbar values (pos/size/first/total)
  99. } ScrollInfo;
  100. void recalc_scrollbars(ScrollInfo &si);
  101. protected:
  102. void bbox(int&,int&,int&,int&);
  103. void draw();
  104. public:
  105. Fl_Scrollbar scrollbar;
  106. Fl_Scrollbar hscrollbar;
  107. void resize(int,int,int,int);
  108. int handle(int);
  109. Fl_Scroll(int X,int Y,int W,int H,const char*l=0);
  110. enum { // values for type()
  111. HORIZONTAL = 1,
  112. VERTICAL = 2,
  113. BOTH = 3,
  114. ALWAYS_ON = 4,
  115. HORIZONTAL_ALWAYS = 5,
  116. VERTICAL_ALWAYS = 6,
  117. BOTH_ALWAYS = 7
  118. };
  119. /** Gets the current horizontal scrolling position. */
  120. int xposition() const {return xposition_;}
  121. /** Gets the current vertical scrolling position. */
  122. int yposition() const {return yposition_;}
  123. void scroll_to(int, int);
  124. void clear();
  125. /**
  126. Gets the current size of the scrollbars' troughs, in pixels.
  127. If this value is zero (default), this widget will use the
  128. Fl::scrollbar_size() value as the scrollbar's width.
  129. \returns Scrollbar size in pixels, or 0 if the global Fl::scrollsize() is being used.
  130. \see Fl::scrollbar_size(int)
  131. */
  132. int scrollbar_size() const {
  133. return(scrollbar_size_);
  134. }
  135. /**
  136. Sets the pixel size of the scrollbars' troughs to \p newSize, in pixels.
  137. Normally you should not need this method, and should use
  138. Fl::scrollbar_size(int) instead to manage the size of ALL
  139. your widgets' scrollbars. This ensures your application
  140. has a consistent UI, is the default behavior, and is normally
  141. what you want.
  142. Only use THIS method if you really need to override the global
  143. scrollbar size. The need for this should be rare.
  144. Setting \p newSize to the special value of 0 causes the widget to
  145. track the global Fl::scrollbar_size(), which is the default.
  146. \param[in] newSize Sets the scrollbar size in pixels.\n
  147. If 0 (default), scrollbar size tracks the global Fl::scrollbar_size()
  148. \see Fl::scrollbar_size()
  149. */
  150. void scrollbar_size(int newSize) {
  151. if ( newSize != scrollbar_size_ ) redraw();
  152. scrollbar_size_ = newSize;
  153. }
  154. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Scroll, Fl_Group)
  155. };
  156. #endif
  157. //
  158. // End of "$Id: Fl_Scroll.H 9126 2011-10-04 13:10:55Z manolo $".
  159. //