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

  1. #ifndef _ISPLITCV_
  2.   #define _ISPLITCV_
  3. /*******************************************************************************
  4. * FILE NAME: isplitcv.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     ISplitCanvas - This canvas class places its children controls in a       *
  9. *                    vertical or horizontal stack with split-bar between       *
  10. *                    them.                                                     *
  11. *                                                                              *
  12. * COPYRIGHT:                                                                   *
  13. *   Licensed Materials - Property of IBM                                       *
  14. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  15. *   All Rights Reserved                                                        *
  16. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  17. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  18. *                                                                              *
  19. * CHANGE HISTORY:                                                              *
  20. *******************************************************************************/
  21. #ifndef _ICANVAS_
  22.   #include <icanvas.hpp>
  23. #endif
  24. #ifndef _ICOLOR_
  25.   #include <icolor.hpp>
  26. #endif
  27. #ifndef _IRECT_
  28.   #include <irect.hpp>
  29. #endif
  30.  
  31. /*----------------------------------------------------------------------------*/
  32. /* Align classes on four byte boundary.                                       */
  33. /*----------------------------------------------------------------------------*/
  34. #pragma pack(4)
  35.  
  36. // Forward declarations for other classes:
  37. class ISplitCanvasHandler;
  38. class ISplitPercentageSet;
  39. class ISplitPercentage;
  40.  
  41.  
  42. class ISplitCanvas : public ICanvas {
  43. typedef ICanvas
  44.   Inherited;
  45. /*******************************************************************************
  46. * The ISplitCanvas class is a control class that gives you a way to split a    *
  47. * window into two or more window panes by simply creating and adding controls. *
  48. * The number of controls that you add determines the number of panes in the    *
  49. * split canvas.  The window panes can be separated by split bars, which is     *
  50. * the default style.  By dragging the split bars, a user can dynamically       *
  51. * change the visible amount of each control.  You can stack the controls       *
  52. * either vertically (the default) or horizontally.                             *
  53. *                                                                              *
  54. * EXAMPLE:                                                                     *
  55. *                                                                              *
  56. *  void  main(int argc,char **argv)                                            *
  57. *  {                                                                           *
  58. *    MyFrame* myFrame = new IFrameWindow();                                    *
  59. *    ISplitCanvas* mySplitCV = new ISplitCanvas(ID_CANVAS, myFrame, myFrame,   *
  60. *                                               IRectangle (),                 *
  61. *                                               IWindow::visible |             *
  62. *                                               ISplitCanvas::horizontal);     *
  63. *    myFrame->setClient(mySplitCV);                                            *
  64. *    IStaticText* txt1 = new IStaticText(ID_STATIC1, mySplitCV, mySplitCV);    *
  65. *    IListBox*    lbx1 = new IEntryField(ID_ENTRY1,  mySplitCV, mySplitCV,     *
  66. *                                        IRectangle(),                         *
  67. *                                        IWindow::visible |                    *
  68. *                                        IListBox::noAdjustPosition);          *
  69. *                                                                              *
  70. *    txt1->setText("Ford Tempo Pricing Details - 1993");                       *
  71. *    lbx1->addAsFirst("$12,500");                                              *
  72. *    lbx1->addAsFirst("$11,500");                                              *
  73. *    lbx1->addAsFirst("$10,500");                                              *
  74. *                                                                              *
  75. *    mySplitCV->setSplitWindowPercentage(txt1, 20);                            *
  76. *    mySplitCV->setSplitWindowPercentage(ent1, 20);                            *
  77. *    mySplitCV->setSplitWindowPercentage(ent2, 20);                            *
  78. *    mySplitCV->setSplitWindowPercentage(lbx1, 40);                            *
  79. *                                                                              *
  80. *    show();                                                                   *
  81. *                                                                              *
  82. *  }                                                                           *
  83. *                                                                              *
  84. *******************************************************************************/
  85. public:
  86. /*-------------------------------- Style ----------------------------------
  87.   The following functions provide a means to set and query split canvas
  88.   styles:
  89.  
  90.     Style - Nested class that provides static members that define the set of
  91.             valid split canvas styles.  These styles can be used in
  92.             conjunction with the styles defined by the nested classes
  93.             ICanvas::Style and IWindow::Style.  For example, you could
  94.             define an instance of the ISplitCanvas::Style class and
  95.             initialize it like:
  96.               ISplitCanvas::Style
  97.                 style = ISplitCanvas::horizontal | IWindow::visible;
  98.             An object of this type is provided when the split canvas is
  99.             created.  A customizable default is used if no styles are
  100.             specified.  Once the object is constructed, ISplitCanvas,
  101.             ICanvas, and IWindow member functions can be used to set or
  102.             query the object's style.
  103.  
  104.             The declaration of the ISplitCanvas::Style nested class is
  105.             generated by the INESTEDBITFLAGCLASSDEF2 macro.
  106.  
  107.   The valid split canvas styles are:
  108.     classDefaultStyle - Original default style for this class, which is
  109.                         vertical | IWindow::visible.
  110.     horizontal        - The split bar will be drawn horizontally. The
  111.                         panes will be placed top to bottom. This
  112.                         style cannot be specified with vertical.
  113.     vertical          - The split bar will be drawn vertically.  The panes
  114.                         will be placed left to right.  This style is the
  115.                         default.  It cannot be specified with horizontal.
  116.     noSplitBars       - The canvas will not have any split bars.
  117.  
  118.   The following functions provide a means of getting and setting the default
  119.   style for this class:
  120.     defaultStyle    - Returns the current default style.  This is the same as
  121.                       classDefaultStyle unless setDefaultStyle has been
  122.                       called.
  123.     setDefaultStyle - Sets the default style for all subsequent split
  124.                       canvases.
  125. -------------------------------------------------------------------------*/
  126. INESTEDBITFLAGCLASSDEF2(Style, ISplitCanvas, ICanvas, IWindow);
  127.                                   // style class definition
  128. static const Style
  129.   horizontal,
  130.   vertical,
  131.   noSplitBars,
  132.   classDefaultStyle;
  133.  
  134. static Style
  135.   defaultStyle    ( );
  136. static void
  137.   setDefaultStyle ( const Style& style );
  138.  
  139. /*-------------------------- Constructor/Destructor ----------------------------
  140. | You can construct instances of this class from a window ID, parent window,   |
  141. | owner window, rectangle, and style.  This creates the specified split        |
  142. | canvas window.                                                               |
  143. ------------------------------------------------------------------------------*/
  144.   ISplitCanvas    ( unsigned long windowId,
  145.                     IWindow* parent,
  146.                     IWindow* owner,
  147.                     const IRectangle& initialSize = IRectangle(),
  148.                     const Style& style = defaultStyle() );
  149.  
  150. virtual
  151.  ~ISplitCanvas    ( );
  152.  
  153. /*------------------------------- Enumerators ----------------------------------
  154. | The following enumerations are defined for this class:                       |
  155. |   Orientation  - Enumeration that specifies the direction of the split bar.  |
  156. |                  Values are:                                                 |
  157. |                    horizontalSplit - The split bar is drawn horizontally.    |
  158. |                                      The panes are placed top to bottom.     |
  159. |                    verticalSplit   - The split bar is drawn vertically.      |
  160. |                                      The panes are placed left to right.     |
  161. |                                                                              |
  162. |   SplitBarArea - Enumeration that specifies the area of the split bar        |
  163. |                  referred to in an operation.  Values are:                   |
  164. |                    splitBarEdge    - The top and bottom edges of a           |
  165. |                                      horizontal split bar or the left and    |
  166. |                                      right edges of a vertical split bar.    |
  167. |                    splitBarMiddle  - The middle of the split bar.            |
  168. ------------------------------------------------------------------------------*/
  169. enum Orientation  { horizontalSplit, verticalSplit };
  170.  
  171. enum SplitBarArea { splitBarEdge, splitBarMiddle};
  172.  
  173. /*---------------------------- Style Manipulation ------------------------------
  174. | These functions are used to set and query the default style for new objects  |
  175. | of this class or the styles of an existing instance:                         |
  176. |   orientation    - Returns the direction in which the split-bar is drawn.    |
  177. |   setOrientation - Sets the direction in which the split-bar is drawn.       |
  178. ------------------------------------------------------------------------------*/
  179. Orientation
  180.   orientation     ( ) const;
  181.  
  182. ISplitCanvas
  183.  &setOrientation  ( Orientation value );
  184.  
  185. /*-------------------------------- Accessors -----------------------------------
  186. | These functions provide a means of getting and setting accessible            |
  187. | attributes of instances of this class:                                       |
  188. |   setSplitWindowPercentage - Sets the percentage of the canvas to be         |
  189. |                              occupied by the specified window.               |
  190. |                              NOTE: This function does not cause the split    |
  191. |                                    canvas to be immediately updated if it    |
  192. |                                    is already being shown.  You must call    |
  193. |                                    the IWindow::refresh function to update   |
  194. |                                    the appearance of the canvas.             |
  195. |   splitWindowPercentage    - Gets the percentage of the canvas currently     |
  196. |                              occupied by the specified window.               |
  197. |   setSplitBarThickness     - Sets the thickness of the specified portion of  |
  198. |                              the split bar.  It must be one the values of    |
  199. |                              the SplitBarArea enumeration.                   |
  200. |   splitBarThickness        - Gets the thickness of the specified portion of  |
  201. |                              the split bar.  It must be one the values of    |
  202. |                              the SplitBarArea enumeration.                   |
  203. ------------------------------------------------------------------------------*/
  204. ISplitCanvas
  205.  &setSplitWindowPercentage ( IWindow* window,
  206.                              unsigned long percentage );
  207.  
  208. unsigned long
  209.   splitWindowPercentage    ( IWindow* window );
  210.  
  211. ISplitCanvas
  212.  &setSplitBarThickness     ( SplitBarArea  value,
  213.                              unsigned long thickness );
  214.  
  215. unsigned long
  216.   splitBarThickness        ( SplitBarArea  value );
  217.  
  218. /*----------------------------- Color Operations -------------------------------
  219. | The following functions provide a means for setting and getting the color    |
  220. | of the middle or edge of a split bar:                                        |
  221. |   setColor - Sets the color to be used for the specified portion of the      |
  222. |              split bar.  It must be one of the values of the SplitBarArea    |
  223. |              enumeration.                                                    |
  224. |   color    - Returns the color used for the specified portion of the split   |
  225. |              bar.  It must be one of the values of the SplitBarArea          |
  226. |              enumeration.                                                    |
  227. ------------------------------------------------------------------------------*/
  228. IColor
  229.   color                 ( SplitBarArea value ) const;
  230.  
  231. ISplitCanvas
  232.  &setColor              ( SplitBarArea value,
  233.                           const IColor& color );
  234.  
  235. /*-------------------------------- Overrides -----------------------------------
  236. | This class overrides the following inherited functions:                      |
  237. |   setLayoutDistorted - Treats a size change like a layout change.            |
  238. ------------------------------------------------------------------------------*/
  239. virtual ISplitCanvas
  240.  &setLayoutDistorted    ( unsigned long layoutAttributeOn,
  241.                           unsigned long layoutAttributeOff );
  242.  
  243. protected:
  244. /*------------------------------ Implementation --------------------------------
  245. | These functions implement the canvas layout algorithm:                       |
  246. |   layout              - Computes the position and size of all child          |
  247. |                         controls.                                            |
  248. ------------------------------------------------------------------------------*/
  249. virtual ISplitCanvas
  250.  &layout                ( );
  251.  
  252. private:
  253. /*--------------------------------- Private ----------------------------------*/
  254.   ISplitCanvas          ( const ISplitCanvas& );
  255.  
  256. static Style
  257.   currentDefaultStyle;
  258.  
  259. ISplitCanvas
  260.  &operator=             ( const ISplitCanvas& );
  261.  
  262. void
  263.   resolveRatios         ( );
  264.  
  265. ISplitCanvas
  266.  &setResolvedPercentage ( IWindow* window,
  267.                           unsigned long percentage );
  268.  
  269. unsigned long
  270.   resolvedPercentage    ( IWindow* window );
  271.  
  272. Boolean
  273.   bClVertical,
  274.   bClRatiosNotResolved,
  275.   bClNoSplitBars;
  276.  
  277. unsigned long
  278.   ulClMiddleThickness,
  279.   ulClEdgeThickness,
  280.   ulClChildCount;
  281.  
  282. IColor
  283.   clrClMiddleColor,
  284.   clrClEdgeColor;
  285.  
  286. ISize
  287.   sizClCanvasSize;
  288.  
  289. ISplitPercentageSet
  290.  *pClSplitPercentageSet;
  291.  
  292. ISplitCanvasHandler
  293.  *pClSplitCanvasHandler;
  294.  
  295. friend class ISplitCanvasHandler;
  296.  
  297. friend Boolean
  298.   ISplitPercentageDeleter ( ISplitPercentage* const& splitPercentageObj,
  299.                             void*   anything );
  300. }; // ISplitCanvas
  301.  
  302. INESTEDBITFLAGCLASSFUNCS(Style, ISplitCanvas);
  303.                                   // global style functions
  304.  
  305. /*----------------------------------------------------------------------------*/
  306. /* Resume compiler default packing.                                           */
  307. /*----------------------------------------------------------------------------*/
  308. #pragma pack()
  309.  
  310. /*----------------------------- Inline Functions -----------------------------*/
  311. #ifndef I_NO_INLINES
  312.   #include <isplitcv.inl>
  313. #endif
  314.  
  315. #endif /* _ISPLITCV_ */
  316.