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

  1. #ifndef _ISLIDER_
  2. #define _ISLIDER_
  3. /*******************************************************************************
  4. * FILE NAME: islider.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the classes:                                                *
  8. *     ISlider            - Creates and manages a slider control.               *
  9. *     IProgressIndicator - Creates and manages a progress indicator control.   *
  10. *                                                                              *
  11. * COPYRIGHT:                                                                   *
  12. *   Licensed Materials - Property of IBM                                       *
  13. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  14. *   All Rights Reserved                                                        *
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #ifndef _ICONTROL_
  20.   #include <icontrol.hpp>
  21. #endif
  22. #ifndef _IBITFLAG_
  23.   #include <ibitflag.hpp>
  24. #endif
  25.  
  26. // Forward declarations for other classes:
  27. class IPoint;
  28. class ISize;
  29. class IString;
  30. class IRectangle;
  31. class IColor;
  32. class IWindowHandle;
  33. class IResourceId;
  34.  
  35. /*----------------------------------------------------------------------------*/
  36. /* Align classes on four byte boundary.                                       */
  37. /*----------------------------------------------------------------------------*/
  38. #pragma pack(4)
  39.  
  40. class IProgressIndicator : public IControl  {
  41. typedef IControl
  42.   Inherited;
  43. /*******************************************************************************
  44. * The IProgressIndicator class is a read-only version of the slider control.   *
  45. * (See the ISlider class for a complete description of the slider control.)    *
  46. *                                                                              *
  47. * A typical use of a progress indicator is to display the percentage of a      *
  48. * task that has been completed, by filling in its shaft as the task            *
  49. * progresses.                                                                  *
  50. *                                                                              *
  51. *                   Progress Indicator Window                                  *
  52. *                                |                                             *
  53. *                                V                                             *
  54. *  +-----------------------------------------+                                 *
  55. *  |                                         |                                 *
  56. *  |   0    10   20   30   40   50<-------------Tick Text                      *
  57. *  |   :    :    :    :    :    :<--------------Tick Mark                      *
  58. *  |   +--------***--------------------+     |                                 *
  59. *  |   |        | |                    |     |                                 *
  60. *  |   +--------***--------------------+     |                                 *
  61. *  |             A          A                |                                 *
  62. *  |             |          |                |                                 *
  63. *  |             |     Slider Shaft          |                                 *
  64. *  |       Slider Arm                        |                                 *
  65. *  +-----------------------------------------+                                 *
  66. *                                                                              *
  67. *  Slider Shaft - A track for the slider arm to move along.                    *
  68. *  Tick Mark    - A mark that indicates an incremental value in the slider's   *
  69. *                 scale.                                                       *
  70. *  Tick Text    - A label that indicates the value the tick mark represents.   *
  71. *  Slider Arm   - The slider arm shows the current level of progress along     *
  72. *                 the slider shaft.  For the progress indicator, the arm is    *
  73. *                 barely visible and cannot be moved by the user.  The         *
  74. *                 slider arm's position can only be changed programatically.   *
  75. *                                                                              *
  76. * By default, the progress indicator is created horizontally and centered in   *
  77. * the window with its ticks and text above it.  The arm is based on the left   *
  78. * edge and the shaft fills with color as the arm moves to the right.  It can   *
  79. * also be constructed with the ticks and text below the shaft, at various      *
  80. * positions in the window, and based on the right edge.  If the progress       *
  81. * indicator is constructed vertically, all the related options are still       *
  82. * available.                                                                   *
  83. *                                                                              *
  84. * Example:                                                                     *
  85. *                                                                              *
  86. * The following example creates a progress indicator in the constructor of a   *
  87. * subclass of IFrameWindow, and therefore uses "this" for its parent and       *
  88. * owner.  The tick lengths are then set and numbered.                          *
  89. *                                                                              *
  90. *    IRectangle rectangle(60,60,440,240);                                      *
  91. *    unsigned long numberOfTicks = 15;                                         *
  92. *                                                                              *
  93. *    myIndicator = new IProgressIndicator( (unsigned long)ID_PROGIND,          *
  94. *                                          this, this,                         *
  95. *                                          rectangle,                          *
  96. *                                          numberOfTicks );                    *
  97. *    myIndicator->setTickLength(10);                                           *
  98. *    for (unsigned long z=0; z<15; z++)                                        *
  99. *         myIndicator->setTickText(z, (char*)(IString(z)));                    *
  100. *                                                                              *
  101. *******************************************************************************/
  102. public:
  103. class Style;    // forward declaration
  104.  
  105. /*------------------------- Constructors ---------------------------------------
  106. | You can construct instances of this class in the following ways:             |
  107. |   -- By using the primary constructor.  This constructor takes seven         |
  108. |      arguments, five of which are required:                                  |
  109. |      - A unique ID for the control.                                          |
  110. |      - A parent window.                                                      |
  111. |      - An owner window.                                                      |
  112. |      - A rectangle that defines the size and placement of the control        |
  113. |        window.                                                               |
  114. |      - The number of ticks to be placed on the primary scale of the          |
  115. |        progress indicator.                                                   |
  116. |      - The number of pixels between ticks.  This defaults to 0, which        |
  117. |        causes the control to evenly space the ticks on the shaft.  If this   |
  118. |        argument is specified, the length of the slider shaft will be         |
  119. |        determined based on this number and the number of ticks specified.    |
  120. |        NOTE: The arm position is not set to the same tick position when the  |
  121. |              progress indicator control window is resized.  This typically   |
  122. |              occurs when the control is on a canvas and the default for      |
  123. |              tick spacing is taken on the constructor.  The arm is           |
  124. |              positioned at the same pixel offset, instead of at the same     |
  125. |              relative position from home.                                    |
  126. |      - The style of the control.                                             |
  127. |   -- By specifying the number of ticks and spacing for both scale1 and       |
  128. |      scale2.                                                                 |
  129. |      NOTE: Various repaint problems can occur when the progress indicator    |
  130. |            control is resized with IWindow::sizeTo or IWindow::moveSizeTo.   |
  131. |            The problems occur when the width of the window is less than the  |
  132. |            width of the entire control.  This typically happens when tick    |
  133. |            spacing has been specified on the constructor; otherwise, the     |
  134. |            control is able to resize itself.                                 |
  135. |   -- From a parent window.  This constructor requires two arguments:         |
  136. |      - A unique ID for the control.                                          |
  137. |      - A parent window.                                                      |
  138. |   -- From a window handle.  This constructor requires one argument: the      |
  139. |      window handle of the control.                                           |
  140. ------------------------------------------------------------------------------*/
  141.   IProgressIndicator  ( unsigned long        windowId,
  142.                         IWindow*             parent,
  143.                         IWindow*             owner,
  144.                         const IRectangle&    initial,
  145.                         unsigned long        numberOfTicks,
  146.                         unsigned long        tickSpacing = 0,
  147.                         const Style&         style = defaultStyle() );
  148.   IProgressIndicator  ( unsigned long        windowId,
  149.                         IWindow*             parent,
  150.                         IWindow*             owner,
  151.                         const IRectangle&    initial,
  152.                         unsigned long        scale1NumberOfTicks,
  153.                         unsigned long        scale1TickSpacing,
  154.                         unsigned long        scale2NumberOfTicks,
  155.                         unsigned long        scale2TickSpacing = 0,
  156.                         const Style&         style = defaultStyle() );
  157.   IProgressIndicator  ( unsigned long        windowId,
  158.                         IWindow*             parent );
  159.   IProgressIndicator  ( const IWindowHandle& handle );
  160.  
  161. virtual
  162.   ~IProgressIndicator ( );
  163.  
  164. /*---------------------------------- Style -------------------------------------
  165. | The following functions provide a means to set and query progress indicator  |
  166. | styles:                                                                      |
  167. |                                                                              |
  168. |   Style - Nested class that provides static members that define the set of   |
  169. |           valid progress indicator styles.  These styles can be used in      |
  170. |           conjunction with the styles defined by the nested classes          |
  171. |           IWindow::Style and IControl::Style.  For example, you could        |
  172. |           define an instance of the IProgressIndicator::Style class and      |
  173. |           initialize it like:                                                |
  174. |              IProgressIndicator::Style                                       |
  175. |                style = IProgressIndicator::vertical |                        |
  176. |                        IWindow::visible;                                     |
  177. |           An object of this type is provided when the progress indicator     |
  178. |           is created.  A customizable default is used if no styles are       |
  179. |           specified.                                                         |
  180. |                                                                              |
  181. |           The declaration of the IProgressIndicator::Style nested class is   |
  182. |           generated by the INESTEDBITFLAGCLASSDEF2 macro.                    |
  183. |                                                                              |
  184. | The valid progress indicator styles are:                                     |
  185. |   classDefaultStyle - Original default style for this class, which is        |
  186. |                       IWindow::visible | horizontal | alignCentered |        |
  187. |                       homeLeft | ribbonStrip | primaryScale1.                |
  188. |   horizontal        - Specifies that the progress indicator be built         |
  189. |                       horizontally.                                          |
  190. |   vertical          - Specifies that the progress indicator be built         |
  191. |                       vertically.                                            |
  192. |   alignCentered     - Progress indicator is centered in the window.          |
  193. |   alignTop          - Progress indicator is at the top of the window.        |
  194. |   alignBottom       - Progress indicator is at the bottom of the window.     |
  195. |   alignLeft         - Progress indicator is at the left of the window.       |
  196. |   alignRight        - Progress indicator is at the right of the window.      |
  197. |   homeTop           - Specifies that the progress indicator's arm and scale  |
  198. |                       start at the top.                                      |
  199. |   homeBottom        - Specifies that the progress indicator's arm and scale  |
  200. |                       start at the bottom.                                   |
  201. |   homeLeft          - Specifies that the progress indicator's arm and scale  |
  202. |                       start at the left.                                     |
  203. |   homeRight         - Specifies that the progress indicator's arm and scale  |
  204. |                       start at the right.                                    |
  205. |   primaryScale1     - The progress indicator's scale1 is used for            |
  206. |                       positioning the arm, and is located above or right of  |
  207. |                       the progress indicator.                                |
  208. |   primaryScale2     - The progress indicator's scale2 is used for            |
  209. |                       positioning the arm, and is located below or left of   |
  210. |                       the progress indicator.                                |
  211. |   snapToTickMark    - Specifies that the progress indicator's arm snap to    |
  212. |                       the nearest tick when moved between two ticks.         |
  213. |   ribbonStrip       - The progress indicator's shaft fills with color        |
  214. |                       between the arm and home position when the arm is      |
  215. |                       moved.                                                 |
  216. |   handleDrawItem    - An ISliderDrawItemEvent is dispatched to the control   |
  217. |                       whenever the shaft, ribbon strip, arm, and background  |
  218. |                       are to be drawn.                                       |
  219. |                                                                              |
  220. | The following functions provide a means of getting and setting the default   |
  221. | style for this class:                                                        |
  222. |   defaultStyle    - Returns the current default style.  This is the same as  |
  223. |                     classDefaultStyle unless setDefaultStyle has been        |
  224. |                     called.                                                  |
  225. |   setDefaultStyle - Sets the default style for all subsequent progress       |
  226. |                     indicators.                                              |
  227. ------------------------------------------------------------------------------*/
  228. INESTEDBITFLAGCLASSDEF2(Style, IProgressIndicator, IWindow, IControl);
  229.                      // style class definitions
  230. static const Style
  231.   classDefaultStyle,
  232.   horizontal,
  233.   vertical,
  234.   alignCentered,
  235.   alignTop,
  236.   alignBottom,
  237.   alignLeft,
  238.   alignRight,
  239.   homeTop,
  240.   homeBottom,
  241.   homeLeft,
  242.   homeRight,
  243.   primaryScale1,
  244.   primaryScale2,
  245.   snapToTickMark,
  246.   ribbonStrip,
  247.   handleDrawItem;
  248.  
  249. static Style
  250.   defaultStyle ( );
  251. static void
  252.   setDefaultStyle ( const Style& style );
  253.  
  254. /*------------------------------ Related Types ---------------------------------
  255. | The following enumeration types are defined to pass "modes" to various       |
  256. | implementation functions:                                                    |
  257. |   Alignment    - An enumeration used to determine the placement of the       |
  258. |                  progress indicator.  The allowable values are:              |
  259. |                  topRight   - A vertical progress indicator is aligned to    |
  260. |                               the right of the control window; a horizontal  |
  261. |                               progress indicator is aligned to the top.      |
  262. |                  bottomLeft - A vertical progress indicator is aligned to    |
  263. |                               the left of the control window; a horizontal   |
  264. |                               progress indicator is aligned to the bottom.   |
  265. |                  centered   - The progress indicator is center aligned.      |
  266. |   HomePosition - An enumeration that specifies the home position of the      |
  267. |                  progress indicator.  The allowable values are:              |
  268. |                  homeBottomLeft - Home position is at the bottom for a       |
  269. |                                   vertical progress indicator and at the     |
  270. |                                   left for a horizontal progress indicator.  |
  271. |                  homeTopRight   - Home position is at the top for a          |
  272. |                                   vertical progress indicator and at the     |
  273. |                                   right for a horizontal progress indicator. |
  274. |   Scale        - An enumeration used to specify which scale is being         |
  275. |                  referred to.  The allowable values are:                     |
  276. |                  scale1 - Scale 1 is above a horizontal progress indicator,  |
  277. |                           and to the right of a vertical progress indicator. |
  278. |                  scale2 - Scale 2 is below a horizontal progress indicator,  |
  279. |                           and to the left of a vertical progress indicator.  |
  280. |   ColorArea    - An enumeration that specifies the area of the progress      |
  281. |                  indicator being referred to in a color operation.  The      |
  282. |                  allowable values are:                                       |
  283. |                  background - The background of the progress indicator       |
  284. |                               control window.                                |
  285. |                  foreground - The text and bit maps used for the progress    |
  286. |                               indicator.                                     |
  287. |                  border     - The color of the border that surrounds the     |
  288. |                               progress indicator.                            |
  289. ------------------------------------------------------------------------------*/
  290. enum Alignment    { topRight, bottomLeft, centered };
  291. enum HomePosition { homeTopRight, homeBottomLeft };
  292. enum Scale        { scale1, scale2 };
  293. enum ColorArea    { background, foreground, border };
  294.  
  295. /*----------------------------- Style Functions --------------------------------
  296. | The following functions provide a means for getting and setting the styles   |
  297. | of instances of this class:                                                  |
  298. |   alignment            - Returns the alignment of the progress indicator as  |
  299. |                          one of the values of the Alignment enumeration.     |
  300. |   homePosition         - Returns the home position of the progress           |
  301. |                          indicator as one of the values of the HomePosition  |
  302. |                          enumeration.                                        |
  303. |   primaryScale         - Returns the primary scale of the progress           |
  304. |                          indicator as one of the values of the Scale         |
  305. |                          enumeration.                                        |
  306. |   isVertical           - If the progress indicator is oriented vertically,   |
  307. |                          true is returned.  If it is oriented horizontally,  |
  308. |                          false is returned.                                  |
  309. |   isRibbonStripEnabled - Returns true if the ribbonStrip style is set.       |
  310. |   isDrawItemEnabled    - Returns true if the handleDrawItem style is set.    |
  311. |   isSnapToTickEnabled  - Returns true if the snapToTickMark style is set.    |
  312. |   setHomePosition      - Sets the home position of the progress indicator    |
  313. |                          to one of the values of the HomePosition            |
  314. |                          enumeration.                                        |
  315. |   setPrimaryScale      - Sets the primary scale of the progress indicator    |
  316. |                          to one of the values of the Scale enumeration.      |
  317. |   enableSnapToTick     - Sets the snapToTickMark style on if the             |
  318. |                          snapToTickOn argument is true; otherwise, the       |
  319. |                          style is set off.                                   |
  320. |   disableSnapToTick    - Sets the snapToTickMark style off.                  |
  321. |   enableRibbonStrip    - Sets the ribbonStrip style on if the ribbonStripOn  |
  322. |                          argument is true; otherwise, the style is set off.  |
  323. |   disableRibbonStrip   - Sets the ribbonStrip style off.                     |
  324. |   enableDrawItem       - Sets the handleDrawItem style on if the drawItemOn  |
  325. |                          argument is true; otherwise, the style is set off.  |
  326. |   disableDrawItem      - Sets the handleDrawItem style off.                  |
  327. ------------------------------------------------------------------------------*/
  328. Alignment
  329.   alignment ( ) const;
  330.  
  331. HomePosition
  332.   homePosition ( ) const;
  333.  
  334. Scale
  335.   primaryScale ( ) const;
  336.  
  337. Boolean
  338.   isVertical           ( ) const,
  339.   isRibbonStripEnabled ( ) const,
  340.   isDrawItemEnabled    ( ) const,
  341.   isSnapToTickEnabled  ( ) const;
  342.  
  343. IProgressIndicator
  344.  &setHomePosition    ( HomePosition home ),
  345.  &setPrimaryScale    ( Scale        primaryScale ),
  346.  &enableSnapToTick   ( Boolean      snapToTickOn = true ),
  347.  &disableSnapToTick  ( ),
  348.  &enableRibbonStrip  ( Boolean      ribbonStripOn = true ),
  349.  &disableRibbonStrip ( ),
  350.  &enableDrawItem     ( Boolean      drawItemOn = true ),
  351.  &disableDrawItem    ( );
  352.  
  353. /*----------------------------- Tick Operations --------------------------------
  354. | The following functions provide a means for setting and getting attributes   |
  355. | of ticks:                                                                    |
  356. |   tickText      - Returns the text associated with the tick at the           |
  357. |                   specified index.  Ticks are numbered starting with 0.      |
  358. |   tickPosition  - Returns the pixel position of the tick at the specified    |
  359. |                   index.  Ticks are numbered starting with 0.                |
  360. |   tickLength    - Returns the length of the tick at the specified index, in  |
  361. |                   pixels.                                                    |
  362. |   tickSpacing   - Returns the number of pixels between ticks for the         |
  363. |                   specified scale.                                           |
  364. |   numberOfTicks - Returns the number of ticks for the specified scale.       |
  365. |   setTickLength - Sets the length of a tick, or all ticks, on the progress   |
  366. |                   indicator scale depending on which version of the          |
  367. |                   overloaded function is used.  Ticks are created with 0     |
  368. |                   length and are thus initially invisible.                   |
  369. |   setTicks      - Sets the number of ticks and number of pixels between      |
  370. |                   ticks for one or both scales, depending on which version   |
  371. |                   of the overloaded function is used.                        |
  372. |   setTickText   - Sets the text associated with the tick at the specified    |
  373. |                   index.  A tick need not be visible to have text            |
  374. |                   associated with it.  This function is overloaded so the    |
  375. |                   text can be passed in as a character string or loaded      |
  376. |                   from a resource using a passed in IResourceId.             |
  377. ------------------------------------------------------------------------------*/
  378. IString
  379.   tickText ( unsigned long tickNumber ) const;
  380.  
  381. IPoint
  382.   tickPosition ( unsigned long tickNumber ) const;
  383.  
  384. unsigned long
  385.   tickLength    ( unsigned long tickNumber ) const,
  386.   tickSpacing   ( Scale         scale ) const,
  387.   numberOfTicks ( Scale         scale ) const;
  388.  
  389. IProgressIndicator
  390.  &setTickLength ( unsigned long      tickNumber,
  391.                   unsigned long      length ),
  392.  &setTickLength ( unsigned long      length ),
  393.  &setTicks      ( unsigned long      scale1NumberOfTicks,
  394.                   unsigned long      scale2NumberOfTicks,
  395.                   unsigned long      scale1TickSpacing = 0,
  396.                   unsigned long      scale2TickSpacing = 0 ),
  397.  &setTicks      ( Scale              scale,
  398.                   unsigned long      numberOfTicks,
  399.                   unsigned long      tickSpacing = 0 ),
  400.  &setTickText   ( unsigned long      tickNumber,
  401.                   const char*        text ),
  402.  &setTickText   ( unsigned long      tickNumber,
  403.                   const IResourceId& text );
  404.  
  405. /*----------------------------- Shaft Operations -------------------------------
  406. | The following functions provide a means for setting and getting attributes   |
  407. | of the progress indicator shaft:                                             |
  408. |   shaftPosition    - Returns the lower left point of the shaft relative to   |
  409. |                      the lower left corner of the control window.            |
  410. |   shaftSize        - Returns the size of the shaft, in pixels.               |
  411. |   setShaftPosition - Sets the position of the lower left point of the        |
  412. |                      shaft, in pixels.  The position of the shaft is         |
  413. |                      relative to the lower left corner of the control        |
  414. |                      window.                                                 |
  415. |   setShaftBreadth  - Sets the width for vertical progress indicators, or     |
  416. |                      height for horizontal progress indicators, of the       |
  417. |                      shaft, in pixels.                                       |
  418. ------------------------------------------------------------------------------*/
  419. IPoint
  420.   shaftPosition ( ) const;
  421.  
  422. ISize
  423.   shaftSize ( ) const;
  424.  
  425. IProgressIndicator
  426.  &setShaftPosition ( const IPoint& lowerLeft ),
  427.  &setShaftBreadth  ( unsigned long breadth );
  428.  
  429. /*------------------------------ Arm Operations --------------------------------
  430. | The following functions provide a means for setting and getting attributes   |
  431. | of the progress indicator arm:                                               |
  432. |   armRange       - Returns the number of pixels over which the arm can be    |
  433. |                    moved.                                                    |
  434. |   armPixelOffset - Returns the offset of the arm from the home position, in  |
  435. |                    pixels.                                                   |
  436. |   armTickOffset  - Returns the position of the arm as a tick number.  Ticks  |
  437. |                    are numbered starting at 0.                               |
  438. |   moveArmToTick  - Moves the arm to a tick.  Ticks are numbered starting at  |
  439. |                    0.  Using this function can cause an exception if the     |
  440. |                    control window has no size and if tick spacing has been   |
  441. |                    specified on the constructor.                             |
  442. |   moveArmToPixel - Moves the arm to a pixel offset relative to the home      |
  443. |                    position.                                                 |
  444. ------------------------------------------------------------------------------*/
  445. unsigned long
  446.   armRange       ( ) const,
  447.   armPixelOffset ( ) const,
  448.   armTickOffset  ( ) const;
  449.  
  450. IProgressIndicator
  451.  &moveArmToTick  ( unsigned long tickNumber ),
  452.  &moveArmToPixel ( unsigned long armOffset );
  453.  
  454. /*----------------------------- Color Operations -------------------------------
  455. | The following functions provide a means for setting and getting the color of |
  456. | the foreground or background of the progress indicator control window:       |
  457. |   setColor - Sets the color to be used for the portion of the progress       |
  458. |              indicator control window specified by the value argument.  It   |
  459. |              must be one of the values of the ColorArea enumeration.         |
  460. |   color    - Returns the color used for the portion of the progress          |
  461. |              indicator control window specified by the value argument.  It   |
  462. |              must be one of the values specified by the ColorArea            |
  463. |              enumeration.                                                    |
  464. ------------------------------------------------------------------------------*/
  465. IColor
  466.   color ( ColorArea value ) const;
  467.  
  468. IProgressIndicator
  469.  &setColor ( ColorArea     value,
  470.              const IColor& color );
  471.  
  472. protected:
  473. /*------------------------------ Implementation --------------------------------
  474. | The following functions are provided for use by this class and any of its    |
  475. | subclasses:                                                                  |
  476. |   calcMinimumSize - Returns an ISize that indicates the minimum size that    |
  477. |                     the progress indicator can be.  This is used by the      |
  478. |                     ICanvas hierarchy of classes.                            |
  479. |   initialize      - Used by several of the constructors to create a          |
  480. |                     progress indicator or slider control.                    |
  481. ------------------------------------------------------------------------------*/
  482. virtual ISize
  483.   calcMinimumSize ( ) const;
  484.  
  485. void
  486.   initialize ( unsigned long     windowId,
  487.                unsigned long     parent,
  488.                unsigned long     owner,
  489.                unsigned long     style,
  490.                const IRectangle& initial,
  491.                void *            sliderData );
  492.  
  493. /*-------------------------- Protected Constructor -----------------------------
  494. |   IProgressIndicator - Constructor used by the ISlider class to allow it to  |
  495. |                        control the creation of the slider.                   |
  496. ------------------------------------------------------------------------------*/
  497.   IProgressIndicator ( );
  498.  
  499. private:
  500. /*--------------------------------- PRIVATE ----------------------------------*/
  501.   IProgressIndicator ( const IProgressIndicator& anIndicator);
  502. IProgressIndicator&
  503.   operator= ( const IProgressIndicator& anIndicator);
  504. char*
  505.   getTickText ( unsigned long tickNumber,
  506.                 char*         buffer = 0,
  507.                 unsigned long bufferLength = 0 ) const;
  508. unsigned long
  509.   tickTextLength ( unsigned long tickNumber ) const;
  510.  
  511. static Style
  512.   currentDefaultStyle;
  513.  
  514. };  // IProgressIndicator
  515.  
  516. INESTEDBITFLAGCLASSFUNCS(Style, IProgressIndicator);
  517.                                   // global style functions
  518.  
  519.  
  520. class ISlider : public IProgressIndicator  {
  521. typedef IProgressIndicator
  522.   Inherited;
  523. /*******************************************************************************
  524. * The ISlider class is a full implementation of the Presentation Manager       *
  525. * Extension slider control, whose purpose is to allow a user to set, display,  *
  526. * or modify a value by moving the slider arm along the slider shaft.           *
  527. *                                                                              *
  528. *                          Slider Window                                       *
  529. *                                |                                             *
  530. *                                V                                             *
  531. *  +----------------------------------------+                                  *
  532. *  |                                        |                                  *
  533. *  |   0    10   20   30   40   50<------------Tick Text                       *
  534. *  |   :  v :    :    :    :    :<-------------Tick Mark                       *
  535. *  |   +--A-----***--------------------+-+-+|                                  *
  536. *  |   |  |     | |                    |<|>||                                  *
  537. *  |   +--|-----***--------------------+-+-+|                                  *
  538. *  |      |      A          A            A  |                                  *
  539. *  |  Detent     |          |            |  |                                  *
  540. *  |             |     Slider Shaft     Slider Buttons                         *
  541. *  |       Slider Arm                       |                                  *
  542. *  +----------------------------------------+                                  *
  543. *                                                                              *
  544. *  Slider Arm     - An arm that the user can move along the shaft to set       *
  545. *                   slider values.  The slider arm shows the current value by  *
  546. *                   its position on the slider shaft and can be changed        *
  547. *                   programatically, as well as by the user.                   *
  548. *  Slider Shaft   - A track for the slider arm to move along.                  *
  549. *  Slider Buttons - Buttons that move the slider arm one incremental position  *
  550. *                   in the indicated direction.                                *
  551. *  Detent         - A user-selectable mark that can be placed anywhere along   *
  552. *                   the slider's scale.                                        *
  553. *  Tick Text      - A label that indicates the value the tick mark represents. *
  554. *  Tick Mark      - A mark that indicates an incremental value in the          *
  555. *                   slider's scale.  Tick marks are evenly spaced along the    *
  556. *                   shaft.                                                     *
  557. *                                                                              *
  558. * Sliders typically allow a user to set values that have familiar increments,  *
  559. * such as feet or degrees.  They can also be used for other purposes, such as  *
  560. * blending colors or showing the percentage of a task that has been completed. *
  561. * Since the slider is interactive, detents and buttons are provided and the    *
  562. * slider arm is larger so it can be easily dragged by the user.                *
  563. *                                                                              *
  564. * By default, the slider is created horizontally in the center of the control  *
  565. * window, with the slider arm based on the left side, and the ticks and text   *
  566. * above the shaft.  The horizontal slider has several alternative              *
  567. * construction styles:                                                         *
  568. *   - The ticks and text can be placed below the shaft.                        *
  569. *   - The slider can be placed at the top or bottom of the control window.     *
  570. *   - The arm can be based on either the right or left side.                   *
  571. *                                                                              *
  572. * A related set of options is available for creating a vertical slider:        *
  573. *   - The ticks and text can be placed either left or right of the shaft.      *
  574. *   - The slider can be placed at the left or right of the control window.     *
  575. *   - The arm can be based on either the top or the bottom.                    *
  576. *                                                                              *
  577. * Other style options include incremental-movement buttons at either end of    *
  578. * the slider and having the slider shaft fill with color as the arm moves.     *
  579. *                                                                              *
  580. * Example:                                                                     *
  581. *                                                                              *
  582. * The following example creates a slider in the constructor of a subclass of   *
  583. * IFrameWindow, and therefore uses "this" for its parent and owner.  The tick  *
  584. * lengths are then set and numbered.                                           *
  585. *                                                                              *
  586. *                                                                              *
  587. *    IRectangle rectangle(60,60,440,240);                                      *
  588. *    unsigned long numberOfTicks = 15;                                         *
  589. *                                                                              *
  590. *    mySlider = new ISlider( (unsigned long)ID_SLIDER,                         *
  591. *                            this, this,                                       *
  592. *                            rectangle,                                        *
  593. *                            numberOfTicks );                                  *
  594. *    mySlider->setTickLength(10);                                              *
  595. *    for (unsigned long z=0; z<15; z++)                                        *
  596. *         mySlider->setTickText(z, (char*)(IString(z)));                       *
  597. *                                                                              *
  598. *******************************************************************************/
  599. public:
  600. class Style;     // forward declaration
  601.  
  602. /*------------------------- Constructors ---------------------------------------
  603. | You can construct instances of this class in the following ways:             |
  604. |    - By using the primary constructor.  This constructor takes seven         |
  605. |      arguments, five of which are required:                                  |
  606. |       - A unique ID for the control.                                         |
  607. |       - A parent window.                                                     |
  608. |       - An owner window.                                                     |
  609. |       - A rectangle that defines the size and placement of the control       |
  610. |         window.                                                              |
  611. |       - The number of ticks to be placed on the primary scale of the slider. |
  612. |       - The number of pixels between ticks.  This defaults to 0, which       |
  613. |         causes the control to evenly space the ticks on the shaft.  If this  |
  614. |         argument is specified, the length of the slider shaft will be        |
  615. |         determined based on this number and the number of ticks specified.   |
  616. |       - The style of the control.                                            |
  617. |    - By constructing with the number of ticks and spacing for both scale1    |
  618. |      and scale2.                                                             |
  619. |    - By constructing from a parent window.  This constructor requires two    |
  620. |      arguments:                                                              |
  621. |       - A unique ID for the control.                                         |
  622. |       - A parent window.                                                     |
  623. |    - By constructing from a window handle.  This constructor requires one    |
  624. |      argument: the window handle of the control.                             |
  625. ------------------------------------------------------------------------------*/
  626.   ISlider  ( unsigned long         windowId,
  627.              IWindow*              parent,
  628.              IWindow*              owner,
  629.              const IRectangle&     initial,
  630.              unsigned long         numberOfTicks,
  631.              unsigned long         tickSpacing = 0,
  632.              const Style&          style = defaultStyle() );
  633.   ISlider  ( unsigned long         windowId,
  634.              IWindow*              parent,
  635.              IWindow*              owner,
  636.              const IRectangle&     initial,
  637.              unsigned long         scale1NumberOfTicks,
  638.              unsigned long         scale1TickSpacing,
  639.              unsigned long         scale2NumberOfTicks,
  640.              unsigned long         scale2TickSpacing = 0,
  641.              const Style&          style = defaultStyle() );
  642.   ISlider  ( unsigned long         windowId,
  643.              IWindow*              parent );
  644.   ISlider  ( const IWindowHandle&  handle );
  645.  
  646. virtual
  647.   ~ISlider ( );
  648.  
  649. /*---------------------------------- Style -------------------------------------
  650. | The following functions provide a means to set and query slider styles:      |
  651. |                                                                              |
  652. |   Style - Nested class that provides static members that define the set of   |
  653. |           valid slider styles.  These styles can be used in conjunction      |
  654. |           with the styles defined by the nested classes IWindow::Style,      |
  655. |           IControl::Style, and IProgressIndicator::Style.  For example,      |
  656. |           you could define an instance of the ISlider::Style class and       |
  657. |           initialize it like:                                                |
  658. |              ISlider::Style                                                  |
  659. |                style = IProgressIndicator::vertical |                        |
  660. |                        ISlider::buttonsTop | IWindow::visible;               |
  661. |           An object of this type is provided when the slider is created.     |
  662. |           A customizable default is used if no styles are specified.         |
  663. |                                                                              |
  664. |           The declaration of the ISlider::Style nested class is generated    |
  665. |           by the INESTEDBITFLAGCLASSDEF3 macro.                              |
  666. |                                                                              |
  667. | The valid slider styles are:                                                 |
  668. |   classDefaultStyle - Original default style for this class, which is        |
  669. |                       IWindow::visible | IProgressIndicator::horizontal |    |
  670. |                       IProgressIndicator::alignCentered |                    |
  671. |                       IProgressIndicator::homeLeft |                         |
  672. |                       IProgressIndicator::primaryScale1 | buttonsLeft.       |
  673. |   buttonsTop        - The slider's buttons are placed above the slider       |
  674. |                       shaft.                                                 |
  675. |   buttonsBottom     - The slider's buttons are placed below the slider       |
  676. |                       shaft.                                                 |
  677. |   buttonsLeft       - The slider's buttons are placed to the left of the     |
  678. |                       slider shaft.                                          |
  679. |   buttonsRight      - The slider's buttons are placed to the right of the    |
  680. |                       slider shaft.                                          |
  681. |                                                                              |
  682. | The following functions provide a means of getting and setting the default   |
  683. | style for this class:                                                        |
  684. |   defaultStyle    - Returns the current default style.  This is the same as  |
  685. |                     classDefaultStyle unless setDefaultStyle has been        |
  686. |                     called.                                                  |
  687. |   setDefaultStyle - Sets the default style for all subsequent sliders.       |
  688. ------------------------------------------------------------------------------*/
  689. INESTEDBITFLAGCLASSDEF3(Style, ISlider, IWindow, IControl, IProgressIndicator);
  690.                                             // style class definition
  691. static const Style
  692.   classDefaultStyle,
  693.   buttonsTop,
  694.   buttonsBottom,
  695.   buttonsLeft,
  696.   buttonsRight;
  697.  
  698. static Style
  699.    defaultStyle ( );
  700. static void
  701.    setDefaultStyle ( const Style& style );
  702.  
  703. /*------------------------------ Related Types ---------------------------------
  704. | The following enumeration type is defined to return "modes" in the           |
  705. | buttonsPosition function:                                                    |
  706. |  ButtonsPosition - Enumeration used to determine the placement of the        |
  707. |                    slider's buttons.  The buttons are used to move the       |
  708. |                    slider arm one tick in the direction that is selected.    |
  709. |                    The allowable values are:                                 |
  710. |                      top    - The slider's buttons are placed above the      |
  711. |                               slider shaft.                                  |
  712. |                      bottom - The slider's buttons are placed below the      |
  713. |                               slider shaft.                                  |
  714. |                      left   - The slider's buttons are placed to the left    |
  715. |                               of the slider shaft.                           |
  716. |                      right  - The slider's buttons are placed to the right   |
  717. |                               of the slider shaft.                           |
  718. |                      none   - The slider's buttons are removed.              |
  719. ------------------------------------------------------------------------------*/
  720. enum ButtonsPosition { top, bottom,
  721.                        left, right, none };
  722.  
  723. /*----------------------------- Style Functions --------------------------------
  724. | The following function provides a means for getting and setting the styles   |
  725. | of instances of this class:                                                  |
  726. |   buttonsPosition - Returns the position of the slider's buttons as a value  |
  727. |                     of the ButtonsPosition enumeration.                      |
  728. ------------------------------------------------------------------------------*/
  729. ButtonsPosition
  730.   buttonsPosition ( ) const;
  731.  
  732. /*---------------------------- Detent Operations -------------------------------
  733. | The following functions provide a means for getting and setting attributes   |
  734. | for a slider's detents:                                                      |
  735. |   detentPosition - Returns the offset of a detent from the home position,    |
  736. |                    in pixels.  The ID of the detent must be specified.       |
  737. |   addDetent      - Adds a detent to the slider at the pixel offset from the  |
  738. |                    home position specified.  Returns a unique ID, which is   |
  739. |                    required for removing a detent or querying its position.  |
  740. |   removeDetent   - Removes the detent with the specified ID from the slider. |
  741. ------------------------------------------------------------------------------*/
  742. unsigned long
  743.   detentPosition ( unsigned long detentId ) const,  // in pixels
  744.   addDetent      ( unsigned long offset );
  745.  
  746. ISlider
  747.  &removeDetent ( unsigned long detentId );
  748.  
  749. /*------------------------------ Arm Operations --------------------------------
  750. | The following functions provide a means for setting and getting attributes   |
  751. | of the slider arm:                                                           |
  752. |   armSize    - Returns the size of the arm, in pixels.                       |
  753. |   setArmSize - Sets the size of the arm, in pixels.                          |
  754. ------------------------------------------------------------------------------*/
  755. ISize
  756.   armSize   ( ) const;
  757.  
  758. ISlider
  759.  &setArmSize     ( const ISize&  sliderArm );
  760.  
  761. private:
  762. /*--------------------------------- PRIVATE ----------------------------------*/
  763.   ISlider ( const ISlider& aSlider );
  764. ISlider&
  765.   operator= ( const ISlider& aSlider );
  766.  
  767. static Style
  768.   currentDefaultStyle;
  769.  
  770. }; // ISlider
  771.  
  772. INESTEDBITFLAGCLASSFUNCS(Style, ISlider);
  773.                                   // global style functions
  774.  
  775. /*----------------------------------------------------------------------------*/
  776. /* Resume compiler default packing.                                           */
  777. /*----------------------------------------------------------------------------*/
  778. #pragma pack()
  779.  
  780. /*--------------------------------- INLINES ----------------------------------*/
  781. #ifndef I_NO_INLINES
  782.   #include <islider.inl>
  783. #endif
  784.  
  785. #endif /* _ISLIDER_ */
  786.