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

  1. #ifndef _IMCELCV_
  2.   #define _IMCELCV_
  3. /*******************************************************************************
  4. * FILE NAME: imcelcv.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IMultiCellCanvas - This canvas class organizes its children window       *
  9. *                        into cells of a multi-cell canvas.                    *
  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 _ICANVAS_
  20.   #include <icanvas.hpp>
  21. #endif
  22.  
  23. #ifndef _IRECT_
  24.   #include <irect.hpp>
  25. #endif
  26.  
  27. /*----------------------------------------------------------------------------*/
  28. /* Align classes on four byte boundary.                                       */
  29. /*----------------------------------------------------------------------------*/
  30. #pragma pack(4)
  31.  
  32. class IMCCvCell;
  33. class IRCHeader;
  34. class IColor;
  35.  
  36. class IMultiCellCanvas : public ICanvas {
  37. typedef ICanvas
  38.   Inherited;
  39. /*******************************************************************************
  40. * The IMultiCellCanvas class is a control class that manages a collection of   *
  41. * child windows in a similar way that data is stored in a spread-sheet.  The   *
  42. * canvas is a two dimensional array of "cells" with an origin of (1, 1) in     *
  43. * the upper left corner.  Windows are added to the multiple-cell canvas by     *
  44. * specifying a starting cell and, optionally, a number of contiguous columns,  *
  45. * rows, or a combination thereof.  Here's an example.  See the User Interface  *
  46. * Class Library Reference for more information.                                *
  47. *                                                                              *
  48. * EXAMPLE:                                                                     *
  49. *                                                                              *
  50. *  void  main(int argc,char **argv)                                            *
  51. *  {                                                                           *
  52. *    MyFrame* myFrame = new IFrameWindow();                                    *
  53. *    IMultiCellCanvas* myMultiCell = new IMultiCellCanvas(ID_CANVAS, myFrame,  *
  54. *                                                         myFrame);            *
  55. *    myFrame->setClient(myMultiCell);                                          *
  56. *    IStaticText* txt1 = new IStaticText(ID_STATIC1, myMultiCell, myMultiCell);*
  57. *    IStaticText* txt2 = new IStaticText(ID_STATIC2, myMultiCell, myMultiCell);*
  58. *    IStaticText* txt3 = new IStaticText(ID_STATIC3, myMultiCell, myMultiCell);*
  59. *    IStaticText* txt4 = new IStaticText(ID_STATIC4, myMultiCell, myMultiCell);*
  60. *    IEntryField* ent5 = new IEntryField(ID_ENTRY5,  myMultiCell, myMultiCell);*
  61. *    IEntryField* ent6 = new IEntryField(ID_ENTRY6,  myMultiCell, myMultiCell);*
  62. *    IEntryField* ent7 = new IEntryField(ID_ENTRY7,  myMultiCell, myMultiCell);*
  63. *    IStaticText* txt8 = new IStaticText(ID_STATIC8, myMultiCell, myMultiCell);*
  64. *    IBitmapControl* bmp9 = new IBitmapControl(ID_BMP9, myMultiCell,           *
  65. *                                              myMultiCell, ID_BMP9);          *
  66. *                                                                              *
  67. *    txt1->setText("Ford Tempo Pricing Details - 1993");                       *
  68. *    txt2->setText("Suggested Retail");                                        *
  69. *    txt3->setText("Current Lot Price");                                       *
  70. *    txt4->setText("Current Financing Charges");                               *
  71. *    ent5->setText("$12,500");                                                 *
  72. *    ent6->setText("$10,500");                                                 *
  73. *    ent7->setText("$  ,500");                                                 *
  74. *    txt8->setText("Note: Data as of Jan 30, 1993");                           *
  75. *                                                                              *
  76. *    myMultiCell->addToCell(txt1, 2,1 ,5,1);                                   *
  77. *    myMultiCell->addToCell(txt2, 2,3);                                        *
  78. *    myMultiCell->addToCell(txt3, 2,4);                                        *
  79. *    myMultiCell->addToCell(txt4, 2,5);                                        *
  80. *    myMultiCell->addToCell(ent5, 4,3);                                        *
  81. *    myMultiCell->addToCell(ent6, 4,4);                                        *
  82. *    myMultiCell->addToCell(ent7, 4,5);                                        *
  83. *    myMultiCell->addToCell(txt8, 2,7 ,3,1);                                   *
  84. *    myMultiCell->addToCell(bmp9, 6,2 ,1,5);                                   *
  85. *    myMultiCell->setColumnWidth(5, 10);                                       *
  86. *    myMultiCell->setColumnWidth(7, 3);                                        *
  87. *                                                                              *
  88. *    myFrame->show();                                                          *
  89. *                                                                              *
  90. *    IApplication::current().run();                                            *
  91. *  }                                                                           *
  92. *                                                                              *
  93. *******************************************************************************/
  94. public:
  95. /*-------------------------------- Style ----------------------------------
  96.   The following functions provide a means to set and query multiple-cell
  97.   canvas styles:
  98.  
  99.     Style - Nested class that provides static members that define the set of
  100.             valid multiple-cell canvas styles.  These styles can be used in
  101.             conjunction with the styles defined by the nested classes
  102.             ICanvas::Style and IWindow::Style.  For example, you could
  103.             define an instance of the IMultiCellCanvas::Style class and
  104.             initialize it like:
  105.               IMultiCellCanvas::Style
  106.                 style = IWindow::visible;
  107.             An object of this type is provided when the multiple-cell
  108.             canvas is created.  A customizable default is used if no styles
  109.             are specified.  Once the object is constructed, IMultiCellCanvas,
  110.             ICanvas, and IWindow member functions can be used to set or
  111.             query the object's style.
  112.  
  113.             The declaration of the IMultiCellCanvas::Style nested class is
  114.             generated by the INESTEDBITFLAGCLASSDEF2 macro.
  115.  
  116.   The valid multiple-cell canvas styles are:
  117.     classDefaultStyle - Original default style for this class, which is
  118.                         IWindow::visible.
  119.     gridLines         - Causes the multiple-cell canvas to have grid lines
  120.                         between the rows and columns of the canvas.
  121.     dragLines         - Causes the multiple-cell canvas to have draggable
  122.                         grid lines between the rows and columns of the canvas.
  123.  
  124.   The following functions provide a means of getting and setting the default
  125.   style for this class:
  126.     defaultStyle    - Returns the current default style.  This is the same as
  127.                       classDefaultStyle unless setDefaultStyle has been
  128.                       called.
  129.     setDefaultStyle - Sets the default style for all subsequent multiple-cell
  130.                       canvases.
  131. -------------------------------------------------------------------------*/
  132.  
  133. INESTEDBITFLAGCLASSDEF2(Style, IMultiCellCanvas, ICanvas, IWindow);
  134.                                   // style class definition
  135. static const Style
  136.   classDefaultStyle,
  137.   dragLines,
  138.   gridLines;
  139.  
  140. static Style
  141.   defaultStyle    ( );
  142.  
  143. static void
  144.   setDefaultStyle ( const Style& style );
  145.  
  146. /*------------------------------- Constructor ----------------------------------
  147. | A multiple-cell canvas is constructed by providing a window identifier,      |
  148. | parent, owner, initial position and size, and style.                         |
  149. ------------------------------------------------------------------------------*/
  150.   IMultiCellCanvas ( unsigned long     windowIdentifier,
  151.                      IWindow*          parent,
  152.                      IWindow*          owner,
  153.                      const IRectangle& initialSize = IRectangle(),
  154.                      const Style&      style = defaultStyle() );
  155.  
  156. virtual
  157.  ~IMultiCellCanvas ( );
  158.  
  159.  
  160. /*------------------------------ Cell Contents ---------------------------------
  161. | These functions provide a means of placing child windows into the cells of   |
  162. | the multiple-cell canvas:                                                    |
  163. |   addToCell      - Specifies the starting cell into which a window should    |
  164. |                    be placed.  Optionally, the number of columns or rows     |
  165. |                    that the window occupies can be specified.  By default,   |
  166. |                    a multiple-cell canvas has no windows.  Therefore, this   |
  167. |                    function must be called to add windows to the canvas.     |
  168. |                    Note: This function does not cause the multiple-cell      |
  169. |                          canvas to be immediately updated if it is already   |
  170. |                          being shown.  You must call the IWindow::refresh    |
  171. |                          function to update the appearance of the canvas.    |
  172. |   removeFromCell - Removes a window from the canvas.  If the cell is         |
  173. |                    specified, the window that occupies that cell will be     |
  174. |                    removed.  If the window is specified, the canvas will be  |
  175. |                    searched to find the cell that contains the window.  If   |
  176. |                    the window is found, it will be removed; otherwise, 0 is  |
  177. |                    returned.                                                 |
  178. |                    Note: This function does not cause the multiple-cell      |
  179. |                          canvas to be immediately updated if it is already   |
  180. |                          being shown.  You must call the IWindow::refresh    |
  181. |                          function to update the appearance of the canvas.    |
  182. |   windowInCell   - Returns the child window that occupies the specified      |
  183. |                    cell.                                                     |
  184. ------------------------------------------------------------------------------*/
  185. virtual IMultiCellCanvas
  186.  &addToCell        ( IWindow*      childWindow,
  187.                      unsigned long startingColumn,
  188.                      unsigned long startingRow,
  189.                      unsigned long numberOfColumns = 1,
  190.                      unsigned long numberOfRows = 1 );
  191. virtual IWindow
  192.  *removeFromCell   ( const IWindow* childWindow ),
  193.  *removeFromCell   ( unsigned long  column,
  194.                      unsigned long  row );
  195. virtual IWindow
  196.  *windowInCell     ( unsigned long startingColumn,
  197.                      unsigned long startingRow     ) const;
  198.  
  199. /*------------------------- Row and Column Behavior ----------------------------
  200. | These functions provide a means of setting the width of columns and height   |
  201. | of rows in the canvas, as well as setting their ability to expand with the   |
  202. | canvas:                                                                      |
  203. |   setColumnWidth     - Defines a width value to be used to increase the      |
  204. |                        width of a column beyond the minimum width of the     |
  205. |                        windows contained in the column.  If the expandable   |
  206. |                        argument is set to true, windows in the column will   |
  207. |                        be expanded horizontally when the canvas expands      |
  208. |                        beyond the minimum canvas size.                       |
  209. |                        Note: This function does not cause the multiple-cell  |
  210. |                              canvas to be immediately updated if it is       |
  211. |                              already being shown.  You must call the         |
  212. |                              IWindow::refresh function to update the         |
  213. |                              appearance of the canvas.                       |
  214. |   setRowHeight       - Defines a height value to be used to increase the     |
  215. |                        height of a row beyond the minimum height of the      |
  216. |                        windows contained in the row.  If the expandable      |
  217. |                        argument is set to true, windows in the row will be   |
  218. |                        expanded vertically when the canvas expands beyond    |
  219. |                        the minimum canvas size.                              |
  220. |                        Note: This function does not cause the multiple-cell  |
  221. |                              canvas to be immediately updated if it is       |
  222. |                              already being shown.  You must call the         |
  223. |                              IWindow::refresh function to update the         |
  224. |                              appearance of the canvas.                       |
  225. |   columnWidth        - Returns the current width of the specified column,    |
  226. |                        in pixels.                                            |
  227. |   rowHeight          - Returns the current height of the specified row, in   |
  228. |                        pixels.                                               |
  229. |   setDefaultCell     - A static function that sets the default width for a   |
  230. |                        column and height for a row that does not contain a   |
  231. |                        window.  The initial default for both rows and        |
  232. |                        columns is 10 pixels.                                 |
  233. |   defaultCell        - Queries the current default cell size.  This is a     |
  234. |                        static function.                                      |
  235. |   isColumnExpandable - Returns true if the specified column can be expanded  |
  236. |                        when the canvas expands beyond the minimum canvas     |
  237. |                        size.                                                 |
  238. |   isRowExpandable    - Returns true if the specified row can be expanded     |
  239. |                        when the canvas expands beyond the minimum canvas     |
  240. |                        size.                                                 |
  241. ------------------------------------------------------------------------------*/
  242. IMultiCellCanvas
  243.  &setColumnWidth       ( unsigned long column,
  244.                          unsigned long widthInPixels,
  245.                          Boolean       expandable = false ),
  246.  &setRowHeight         ( unsigned long row,
  247.                          unsigned long heightInPixels,
  248.                          Boolean       expandable = false );
  249. unsigned long
  250.   columnWidth          ( unsigned long column ) const,
  251.   rowHeight            ( unsigned long row    ) const;
  252.  
  253. static void
  254.   setDefaultCell       ( const ISize& widthAndHeight );
  255.  
  256. static ISize
  257.   defaultCell          ( );
  258.  
  259. Boolean
  260.   isColumnExpandable   ( unsigned long column ) const,
  261.   isRowExpandable      ( unsigned long row    ) const;
  262.  
  263. /*----------------------------- Color Operations -------------------------------
  264. | The following functions provide a means for setting and getting the color    |
  265. | of the background of the multiple-cell canvas:                               |
  266. |   setColor - Sets the color to be used for the background of the canvas.     |
  267. |   color    - Returns the color used for the background of the canvas.        |
  268. ------------------------------------------------------------------------------*/
  269. IColor
  270.   color                ( ) const;
  271.  
  272. IMultiCellCanvas
  273.  &setColor             ( const IColor& color );
  274.  
  275. /*---------------------------- Style Manipulation ------------------------------
  276. | These functions are used to set and query the default style for new objects  |
  277. | of this class or the styles of an existing instance:                         |
  278. |   hasDragLines     - Returns true if the dragLines style is set.             |
  279. |   hasGridLines     - Returns true if the gridLines style is set.             |
  280. |   disableDragLines - Disables the dragLines style of the multiple-cell       |
  281. |                      canvas.                                                 |
  282. |   enableDragLines  - Enables the dragLines style of the multiple-cell        |
  283. |                      canvas.                                                 |
  284. |   disableGridLines - Disables the gridLines style of the multiple-cell       |
  285. |                      canvas.                                                 |
  286. |   enableGridLines  - Enables the gridLines style of the multiple-cell        |
  287. |                      canvas.                                                 |
  288. ------------------------------------------------------------------------------*/
  289. Boolean
  290.   hasDragLines         ( ) const,
  291.   hasGridLines         ( ) const;
  292.  
  293. IMultiCellCanvas
  294.  &disableDragLines     ( ),
  295.  &enableDragLines      ( Boolean enable = true ),
  296.  &disableGridLines     ( ),
  297.  &enableGridLines      ( Boolean enable = true );
  298.  
  299. /*-------------------------------- Overrides -----------------------------------
  300. | This class overrides the following inherited function:                       |
  301. |   setLayoutDistorted - Treats a size change like a layout change.            |
  302. ------------------------------------------------------------------------------*/
  303. virtual IMultiCellCanvas
  304.  &setLayoutDistorted   ( unsigned long layoutAttributeOn,
  305.                          unsigned long layoutAttributeOff );
  306.  
  307. protected:
  308. /*----------------------- Canvas Layout Implementation -------------------------
  309. | This function implements the canvas layout algorithm:                        |
  310. |   layout - Computes the child windows' positions and sizes based on the      |
  311. |            contents of the cells, the set size for rows and columns, and     |
  312. |            the expandability of rows and columns.                            |
  313. ------------------------------------------------------------------------------*/
  314. virtual IMultiCellCanvas
  315.  &layout               ( );
  316.  
  317. private:
  318. /*--------------------------------- Private ----------------------------------*/
  319.   IMultiCellCanvas        ( const IMultiCellCanvas& );
  320. IMultiCellCanvas
  321.  &operator=               ( const IMultiCellCanvas& );
  322.  
  323. IMultiCellCanvas
  324.  &pass1                   ( ),
  325.  &pass2                   ( ),
  326.  &pass3                   ( ),
  327.  &pass4                   ( ),
  328.  &computeExpandedRowsCols ( );
  329.  
  330. static Style
  331.   currentDefaultStyle;
  332.  
  333. static unsigned long
  334.   ulDefaultWidth,
  335.   ulDefaultHeight;
  336.  
  337. Boolean
  338.   fMulti,
  339.   fExpand,
  340.   bClDragLines,
  341.   bClGridLines;
  342.  
  343. friend class IRowColumnHeaderList;
  344. friend class IMultiCellCanvasList;
  345. friend class IMultiCellCanvasHandler;
  346.  
  347. IMultiCellCanvasList
  348.  *pCanvasList;
  349.  
  350. IRowColumnHeaderList
  351.  *pRowColHeaderList;
  352.  
  353. IMultiCellCanvasHandler
  354.  *pCanvasHandler;
  355.  
  356. friend Boolean IRowColHeaderInitializer ( IRCHeader* const& header,
  357.                                           void*   anything );
  358. friend Boolean IMultiCellCanvasDeleter  ( IMCCvCell* const& cell,
  359.                                           void*   anything );
  360. friend Boolean IRowColumnHeaderDeleter  ( IRCHeader* const& header,
  361.                                           void*   anything );
  362. }; // IMultiCellCanvas
  363.  
  364. INESTEDBITFLAGCLASSFUNCS(Style, IMultiCellCanvas);
  365.                                   // global style functions
  366.  
  367. /*----------------------------------------------------------------------------*/
  368. /* Resume compiler default packing.                                           */
  369. /*----------------------------------------------------------------------------*/
  370. #pragma pack()
  371.  
  372. #endif /* _IMCELCV_ */
  373.