home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / ISCROLL.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  18KB  |  322 lines

  1. #ifndef _ISCROLL_
  2.   #define _ISCROLL_
  3. /*******************************************************************************
  4. * FILE NAME: iscroll.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *    IScrollBar - This class creates and manages the scroll bar control.       *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _ICONTROL_
  19.   #include <icontrol.hpp>
  20. #endif
  21. #ifndef _IRECT_
  22.   #include <irect.hpp>
  23. #endif
  24.  
  25. /*----------------------------------------------------------------------------*/
  26. /* Align classes on four byte boundary.                                       */
  27. /*----------------------------------------------------------------------------*/
  28. #pragma pack(4)
  29.  
  30. // Forward declarations for other classes:
  31. class IRange;
  32. class IWindowHandle;
  33. struct _SBCDATA;
  34. struct _WNDPARAMS;
  35.  
  36.  
  37. class IScrollBar : public IControl  {
  38. typedef IControl
  39.   Inherited;
  40. /*******************************************************************************
  41. * The IScrollBar class creates and manages the scroll bar control window.      *
  42. *                                                                              *
  43. * Example:                                                                     *
  44. * To create a horizontal scroll bar:                                           *
  45. *    IScrollBar* pvsb = new IScrollBar(ID_MYHORZSCROLL,                        *
  46. *                                      this, this,                             *
  47. *                                      IRange(1, 20),                          *
  48. *                                      5, 1,                                   *
  49. *                                      IRectangle(50, 20, 200, 40),            *
  50. *                                      IWindow::visible |                      *
  51. *                                        IScrollBar::horizontal);              *
  52. *                                                                              *
  53. * Then to catch the scroll messages, add:                                      *
  54. *    MyScrollHandler* psbh = new MyScrollHandler();                            *
  55. *    psbh->handleEventsFor(this);                                              *
  56. *                                                                              *
  57. * Finally, to process the scroll messages:                                     *
  58. *    Boolean  MyScrollHandler::pageUp(IScrollEvent& evt)                       *
  59. *    {                                                                         *
  60. *       // Scroll the information in the related window                        *
  61. *       ...                                                                    *
  62. *       moveScrollBox(evt);  // default processing to position scroll box      *
  63. *       return true;                                                           *
  64. *    }                                                                         *
  65. *******************************************************************************/
  66. public:
  67. class Style;                  // forward declaration for nested class
  68.  
  69. /*------------------------- Constructors/Destructor ----------------------------
  70. | You can construct instances of this class in the following ways:             |
  71. |    - From a control ID, parent and owner windows, rectangle, and style.      |
  72. |      This creates the specified scroll bar control and an object for it.     |
  73. |      The range of items is defaulted to (1, 100), the number of visible      |
  74. |      items to 25, and the scroll box position to 1.                          |
  75. |    - From a control ID, parent and owner windows, rectangle, range of all    |
  76. |      scrollable items, number of items that are displayed, scroll box        |
  77. |      position, and style.  This creates the specified scroll bar control     |
  78. |      and an object for it.                                                   |
  79. |    - From the ID of a scroll bar control on a dialog window.  This creates   |
  80. |      the object for the specified scroll bar control.                        |
  81. |    - From the window handle of an existing scroll bar control.  This         |
  82. |      creates the object for the specified scroll bar control.                |
  83. ------------------------------------------------------------------------------*/
  84.   IScrollBar ( unsigned long windowId,
  85.                IWindow* parent,
  86.                IWindow* owner,
  87.                const IRectangle& initial = IRectangle(),
  88.                const Style& style = defaultStyle() );
  89.  
  90.   IScrollBar ( unsigned long windowId,
  91.                IWindow* parent,
  92.                IWindow* owner,
  93.                const IRange& scrollableItems,
  94.                unsigned long visibleItemCount,
  95.                unsigned long scrollBoxPosition = 1,
  96.                const IRectangle& initial = IRectangle(),
  97.                const Style& style = defaultStyle() );
  98.  
  99.   IScrollBar ( unsigned long windowId, IWindow* parent );
  100.   IScrollBar ( const IWindowHandle& handle );
  101.  
  102. virtual
  103.  ~IScrollBar ( );
  104.  
  105. /*---------------------------------- Style -------------------------------------
  106.   The following functions provide a means to set and query scroll bar styles:
  107.  
  108.     Style - Nested class that provides static members that define the set of
  109.             valid scroll bar styles.  These styles can be used in
  110.             conjunction with the styles defined by the nested classes
  111.             IWindow::Style and IControl::Style.  For example, you could
  112.             define an instance of the IScrollBar::Style class and initialize
  113.             it like:
  114.               IScrollBar::Style
  115.                 style = IScrollBar::horizontal | IWindow::visible;
  116.             An object of this type is provided when the scroll bar is
  117.             created.  A customizable default is used if no styles are
  118.             specified.  Once the object is constructed, IScrollBar, IWindow,
  119.             and IControl member functions can be used to set or query the
  120.             object's style.
  121.  
  122.             The declaration of the IScrollBar::Style nested class is
  123.             generated by the INESTEDBITFLAGCLASSDEF2 macro.
  124.  
  125.   The valid scroll bar styles are:
  126.     horizontal        - Causes a horizontal scroll bar to be created.  This
  127.                         style is ignored if it is used with vertical.
  128.     vertical          - Causes a vertical scroll bar to be created.  This
  129.                         style is used if both it and horizontal are specified.
  130.     autoSize          - Causes automatic sizing of the scroll bar to occur.
  131.                         For a vertical scroll bar, the width is determined.
  132.                         For a horizontal scroll bar, the height is determined.
  133.     classDefaultStyle - Original default style for this class, which is
  134.                         IWindow::visible | vertical.
  135. ------------------------------------------------------------------------------*/
  136. INESTEDBITFLAGCLASSDEF2(Style, IScrollBar, IWindow, IControl);
  137. static const Style
  138.   horizontal,
  139.   vertical,
  140.   autoSize,
  141.   classDefaultStyle;
  142.  
  143. /*------------------------------ Default Style ---------------------------------
  144. | These functions provide a means of getting and setting the default style     |
  145. | attributes of instances of this class:                                       |
  146. |   defaultStyle    - Returns the current default style.  This is the same as  |
  147. |                     classDefaultStyle unless setDefaultStyle has been        |
  148. |                     called.                                                  |
  149. |   setDefaultStyle - Sets the default style for all subsequent scroll bars.   |
  150. ------------------------------------------------------------------------------*/
  151. static Style
  152.   defaultStyle        ( );
  153. static void
  154.   setDefaultStyle     ( const Style& style );
  155.  
  156. /*------------------------------ System Values ---------------------------------
  157. | The following static functions return various system sizes.  For the below   |
  158. | functions, length refers to the size in the direction of a scroll bar's      |
  159. | orientation (that is, in the X-direction for a horizontal scroll bar, in the |
  160. | Y-direction for a vertical scroll bar).  Width refers to the size in the     |
  161. | direction perpendicular to the scroll bar's orientation (that is, in the     |
  162. | Y-direction for a horizontal scroll bar, in the X-direction for a vertical   |
  163. | scroll bar).                                                                 |
  164. |   systemScrollBarWidth     - Returns the system width of a vertical or       |
  165. |                              horizontal scroll bar.                          |
  166. |   systemScrollBoxLength    - Returns the system length of a scroll box for   |
  167. |                              a vertical or horizontal scroll bar.            |
  168. |   systemScrollButtonLength - Returns the system length of a scroll button    |
  169. |                              for a vertical or horizontal scroll bar.        |
  170. ------------------------------------------------------------------------------*/
  171. static unsigned long
  172.   systemScrollBarWidth     ( Boolean verticalScrollBar = true ),
  173.   systemScrollBoxLength    ( Boolean verticalScrollBar = true ),
  174.   systemScrollButtonLength ( Boolean verticalScrollBar = true );
  175.  
  176. /*-------------------- Query, Enable, and Disable Styles -----------------------
  177. | These functions provide a means of getting and setting the scroll bar        |
  178. | styles:                                                                      |
  179. |   isHorizontal - Returns true if the scroll bar is horizontal.               |
  180. |   isVertical   - Returns true if the scroll bar is vertical.                 |
  181. ------------------------------------------------------------------------------*/
  182. Boolean
  183.   isHorizontal        ( ) const,
  184.   isVertical          ( ) const;
  185.  
  186. /*------------------------- Manipulation Operations ----------------------------
  187. | These functions change and query how the scroll bar operates:                |
  188. |   setScrollableRange - Sets the range of all items to which the scroll bar   |
  189. |                        can scroll.                                           |
  190. |   setVisibleCount    - Defines the amount of the scrollable range that is    |
  191. |                        displayed.  This is used to determine the length of   |
  192. |                        the scroll box, and the default value of the page     |
  193. |                        scrolling increment.                                  |
  194. |   setScrollBar       - Sets the range of all items and the number of items   |
  195. |                        that are displayed.  This is functionally equivalent  |
  196. |                        to calling both setScrollableRange and                |
  197. |                        setVisibleCount.                                      |
  198. |   moveScrollBoxTo    - Moves the scroll box to the position given.           |
  199. |   scrollableRange    - Returns the range that the scroll bar represents.     |
  200. |   scrollBoxRange     - Returns the range in which the scroll box can be      |
  201. |                        positioned.  This is defined to be:                   |
  202. |                          IRange(scrollableRange().lowerBound(),              |
  203. |                                 scrollableRange().upperBound() -             |
  204. |                                   visibleCount())                            |
  205. |   visibleCount       - Returns the amount of the scrollable range that is    |
  206. |                        displayed.  This is used to determine the length of   |
  207. |                        the scroll box, and the default value of the page     |
  208. |                        scrolling increment.                                  |
  209. |   scrollBoxPosition  - Returns the current position of the scroll box.       |
  210. ------------------------------------------------------------------------------*/
  211. IScrollBar
  212.  &setScrollableRange  ( const IRange& minMax ),
  213.  &setVisibleCount     ( unsigned long scrollableRangeUnits ),
  214.  &setScrollBar        ( const IRange& scrollableRange,
  215.                         unsigned long visibleCount ),
  216.  &moveScrollBoxTo     ( unsigned long firstItem = 1 );
  217. IRange
  218.   scrollableRange     ( ) const,
  219.   scrollBoxRange      ( ) const;
  220. unsigned long
  221.   visibleCount        ( ) const,
  222.   scrollBoxPosition   ( ) const;
  223.  
  224. /*--------------------------- Scrolling Increment ------------------------------
  225. | These functions query and set the scrolling increments for the scroll bar.   |
  226. | These values are used to determine the scroll amounts stored in              |
  227. | IScrollEvent objects.                                                        |
  228. |   minScrollIncrement     - Returns the amount of the scrollable range that   |
  229. |                            is scrolled by selecting the scroll buttons.      |
  230. |   pageScrollIncrement    - Returns the amount of the scrollable range that   |
  231. |                            is scrolled by selecting the scroll shaft.        |
  232. |   setMinScrollIncrement  - Sets the amount of the scrollable range that is   |
  233. |                            scrolled by selecting the scroll buttons.         |
  234. |   setPageScrollIncrement - Sets the amount of the scrollable range that is   |
  235. |                            scrolled by selecting the scroll shaft.           |
  236. |                            Specifying a value of 0 means to use the visible  |
  237. |                            count minus the minimum scrolling increment.      |
  238. |                            This is the default value.  (If the visible       |
  239. |                            count minus the minimum scrolling increment is    |
  240. |                            equal to 0, the minimum scrolling increment is    |
  241. |                            used).                                            |
  242. ------------------------------------------------------------------------------*/
  243. unsigned long
  244.   minScrollIncrement     ( ) const,
  245.   pageScrollIncrement    ( ) const;
  246. IScrollBar
  247.  &setMinScrollIncrement  ( unsigned long scrollableRangeUnits = 1 ),
  248.  &setPageScrollIncrement ( unsigned long scrollableRangeUnits = 0 );
  249.  
  250. /*-------------------------- Color Area Enumerators ----------------------------
  251. | ColorArea  - Identifies parts of a scroll bar whose color can be changed.    |
  252. |              Values are:                                                     |
  253. |              shaft     - The portion of the scroll bar not occupied by the   |
  254. |                          scroll box or the scroll buttons.                   |
  255. |              scrollBox - The portion of a scroll bar that represents the     |
  256. |                          visible part of the information being scrolled.     |
  257. |              border    - The color of the border that surrounds the scroll   |
  258. |                          bar window.                                         |
  259. ------------------------------------------------------------------------------*/
  260. enum ColorArea {
  261.   shaft,
  262.   scrollBox,
  263.   border
  264. };
  265.  
  266. /*---------------------------------- Color -------------------------------------
  267. |  setColor - Changes the color of the specified portion of the scroll bar.    |
  268. |  color    - Returns the color of the specified portion of the scroll bar.    |
  269. ------------------------------------------------------------------------------*/
  270. IScrollBar
  271.  &setColor              ( ColorArea area, const IColor& color );
  272. IColor
  273.   color                 ( ColorArea value ) const;
  274.  
  275. protected:
  276. /*--------------------------- Protected Overrides ------------------------------
  277. | This class overrides the following inherited protected functions:            |
  278. |   calcMinimumSize - Returns the recommended minimum size of this scroll bar  |
  279. |                     control.                                                 |
  280. ------------------------------------------------------------------------------*/
  281. virtual ISize
  282.   calcMinimumSize       ( ) const;
  283.  
  284. private:
  285. /*--------------------------------- Private ----------------------------------*/
  286.   IScrollBar            ( const IScrollBar& );
  287. IScrollBar
  288.  &operator=             ( const IScrollBar& );
  289. void
  290.   initialize            ( unsigned long windowId,
  291.                           IWindow* parent,
  292.                           IWindow* owner,
  293.                           const IRectangle& initial,
  294.                           const IRange& scrollableItems,
  295.                           unsigned long visibleItemCount,
  296.                           unsigned long scrollBoxPosition,
  297.                           const Style& style ),
  298.   initializeControlData ( const IRange& scrollableItems,
  299.                           unsigned long visibleItemCount,
  300.                           struct _SBCDATA* controlData ),
  301.   windowData            ( struct _WNDPARAMS* windowData ) const;
  302.  
  303. static Style
  304.   currentDefaultStyle;
  305. unsigned long
  306.   ulClMinScrollIncrement,
  307.   ulClPageScrollIncrement;
  308. }; // IScrollBar
  309.  
  310. INESTEDBITFLAGCLASSFUNCS(Style, IScrollBar);
  311.  
  312. /*----------------------------------------------------------------------------*/
  313. /* Resume compiler default packing.                                           */
  314. /*----------------------------------------------------------------------------*/
  315. #pragma pack()
  316.  
  317. /*----------------------------- Inline Functions -----------------------------*/
  318. #ifndef I_NO_INLINES
  319.   #include <iscroll.inl>
  320. #endif
  321. #endif /* _ISCROLL_ */
  322.