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

  1. #ifndef _ICANVAS_
  2.   #define _ICANVAS_
  3. /*******************************************************************************
  4. * FILE NAME: icanvas.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     ICanvas  - This class can be used as a client area object, and is also   *
  9. *                the base class for all other canvas classes.                  *
  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. * CHANGE ACTIVITY:                                                             *
  19. *******************************************************************************/
  20. #ifndef _ICONTROL_
  21.   #include <icontrol.hpp>
  22. #endif
  23.  
  24. #ifndef _IBITFLAG_
  25.   #include <ibitflag.hpp>
  26. #endif
  27. #ifndef _IPOINT_
  28.   #include <ipoint.hpp>
  29. #endif
  30. #ifndef _IRECT_
  31.   #include <irect.hpp>
  32. #endif
  33.  
  34. /*----------------------------------------------------------------------------*/
  35. /* Align classes on four byte boundary.                                       */
  36. /*----------------------------------------------------------------------------*/
  37. #pragma pack(4)
  38.  
  39. // Forward declarations for other classes:
  40. class ICanvasHandler;
  41. class IColor;
  42. class IKeyboardEvent;
  43. class IResourceId;
  44. class IWindowPosBuffer;
  45.  
  46.  
  47. class ICanvas : public IControl {
  48. typedef IControl
  49.   Inherited;
  50. friend class ICanvasHandler;
  51. /*******************************************************************************
  52. * The ICanvas class can be used as a client area object.  A client area        *
  53. * object is an intermediate window between an IFrameWindow and its controls    *
  54. * and other child windows.  The client area for an IFrameWindow is specified   *
  55. * using IFrameWindow::setClient.  Unlike other canvas classes, ICanvas does    *
  56. * not alter the size or position of its child windows.  However, its use as a  *
  57. * client area or as the parent window of controls that can accept the input    *
  58. * focus will provide the following support that can be missing if another      *
  59. * class (such as IStaticText) or no window at all is used in its place:        *
  60. *                                                                              *
  61. *   - Handling of the tab and cursor movement keys.                            *
  62. *   - Handling of focus change events.                                         *
  63. *   - Allows the client area window or the frame window (if a canvas is not    *
  64. *     the client area window) to be the control point to perform command       *
  65. *     processing.                                                              *
  66. *   - Allows the frame window to change the appearance of the mouse pointer.   *
  67. *   - Prevents the border of the frame window from being overwritten.          *
  68. *                                                                              *
  69. * Additionally, this class is the base class for all other canvas classes, and *
  70. * provides the above behavior for all derived classes.  These derived classes  *
  71. * provide special layout rules for sizing and positioning their child windows. *
  72. *                                                                              *
  73. * Example:                                                                     *
  74. *   ICanvas cvPushButtons(0, parent, owner, IRectangle(0, 0, 435, 50));        *
  75. *       // add controls to the canvas by making them child windows             *
  76. *   IPushButton pbApply(ID_APPLY, &cvPushButtons, &cvPushButtons,              *
  77. *                       IRectangle(10, 10, 110, 40),                           *
  78. *                       IPushButton::classDefaultStyle |                       *
  79. *                         IPushButton::defaultButton |                         *
  80. *                         IControl::group | IControl::tabStop);                *
  81. *   IPushButton pbReset(ID_RESET, &cvPushButtons, &cvPushButtons,              *
  82. *                       IRectangle(115, 10, 215, 40));                         *
  83. *   IPushButton pbUndo(ID_UNDO, &cvPushButtons, &cvPushButtons,                *
  84. *                      IRectangle(220, 10, 320, 40));                          *
  85. *   IPushButton pbCancel(SC_CLOSE, &cvPushButtons, &cvPushButtons,             *
  86. *                        IRectangle(325, 10, 425, 40),                         *
  87. *                        IPushButton::classDefaultStyle |                      *
  88. *                          IPushButton::systemCommand);                        *
  89. *******************************************************************************/
  90. public:
  91. class Style;                  // forward declaration for nested class
  92. /*------------------------------- Constructor ----------------------------------
  93. | The only way to construct an instance of this class is to create a canvas    |
  94. | window with the specified window ID, parent window, owner window, rectangle, |
  95. | and style.                                                                   |
  96. ------------------------------------------------------------------------------*/
  97.   ICanvas  ( unsigned long windowId,
  98.              IWindow* parent,
  99.              IWindow* owner,
  100.              const IRectangle& initial = IRectangle(),
  101.              const Style& style = defaultStyle() );
  102. virtual
  103.   ~ICanvas ( );
  104.  
  105. /*---------------------------------- Style -------------------------------------
  106. | The following functions provide a means to set and query canvas styles:      |
  107. |                                                                              |
  108. |   Style - Nested class that provides static members that define the set      |
  109. |           of valid canvas styles.  These styles can be used in conjunction   |
  110. |           with the styles defined by the IWindow::Style nested class. For    |
  111. |           example, you could define an instance of the ICanvas::Style        |
  112. |           class and initialize it like:                                      |
  113. |             ICanvas::Style                                                   |
  114. |               style = ICanvas::classDefaultStyle |                           |
  115. |                       IWindow::saveBits;                                     |
  116. |           An object of this type is provided when the canvas is created.  A  |
  117. |           customizable default is used if no styles are specified.  Once     |
  118. |           the object is constructed, ICanvas and IWindow member functions    |
  119. |           can be used to set or query the object's style.                    |
  120. |                                                                              |
  121. |           The declaration of the ICanvas::Style nested class is generated    |
  122. |           by the INESTEDBITFLAGCLASSDEF1 macro.                              |
  123. |                                                                              |
  124. | The valid canvas style is:                                                   |
  125. |   classDefaultStyle - The original default style for this class, which is    |
  126. |                       IWindow::visible.                                      |
  127. |                                                                              |
  128. | The following functions provide a means of getting and setting the default   |
  129. | style for new objects of this class:                                         |
  130. |   defaultStyle    - Returns the current default style, which is the same as  |
  131. |                     classDefaultStyle unless setDefaultStyle has been        |
  132. |                     called.                                                  |
  133. |   setDefaultStyle - Sets the default style for all subsequent canvases.      |
  134. ------------------------------------------------------------------------------*/
  135. INESTEDBITFLAGCLASSDEF1(Style, ICanvas, IWindow);
  136.                                   // style class definition
  137. static const Style
  138.   classDefaultStyle;
  139. static Style
  140.   defaultStyle        ( );
  141. static void
  142.   setDefaultStyle     ( const Style& style );
  143.  
  144. /*------------------------------- Enumerations ---------------------------------
  145. | The following enumerations are defined:                                      |
  146. |   ColorArea - Used to specify an area of the canvas that can be affected     |
  147. |               with color:                                                    |
  148. |                 background - The background of the canvas (the portion       |
  149. |                              not occupied by child windows).                 |
  150. ------------------------------------------------------------------------------*/
  151. enum ColorArea {
  152.   background
  153. };
  154.  
  155. /*---------------------------------- Color -------------------------------------
  156. | These functions set and query the color of the canvas:                       |
  157. |   setColor  - Sets the specified color of the canvas.                        |
  158. |   color     - Returns the specified color of the canvas.                     |
  159. ------------------------------------------------------------------------------*/
  160. ICanvas
  161.  &setColor            ( ColorArea area, const IColor& color );
  162. IColor
  163.   color               ( ColorArea area ) const;
  164.  
  165. /*------------------------- Dialog Behavior Support ----------------------------
  166. | This function returns information used to provide dialog-like keyboard       |
  167. | support for the canvas classes:                                              |
  168. |   origDefaultButtonHandle - Returns the push button originally identified as |
  169. |                             being the default.                               |
  170. ------------------------------------------------------------------------------*/
  171. IWindowHandle
  172.   origDefaultButtonHandle ( ) const;
  173.  
  174. /*-------------------------------- Overrides -----------------------------------
  175. | This class overrides the following inherited functions:                      |
  176. |   isTabStop          - Returns true if the canvas can be tabbed to based on  |
  177. |                        whether any of its child windows can be tabbed to.    |
  178. |   defaultPushButton  - Returns the first child window that is a default push |
  179. |                        button, if one exists.                                |
  180. |   matchForMnemonic   - Returns the first child window that uses the          |
  181. |                        specified character as a mnemonic.                    |
  182. |   setLayoutDistorted - Provides common canvas processing.                    |
  183. ------------------------------------------------------------------------------*/
  184. virtual Boolean
  185.   isTabStop           ( ) const;
  186. virtual IWindowHandle
  187.   defaultPushButton   ( ) const,
  188.   matchForMnemonic    ( unsigned short character ) const;
  189. virtual ICanvas
  190.  &setLayoutDistorted ( unsigned long layoutAttributeOn,
  191.                        unsigned long layoutAttributeOff );
  192.  
  193. protected:
  194. /*--------------------------- Protected Overrides ------------------------------
  195. | This class overrides the following inherited protected function:             |
  196. |   calcMinimumSize - Returns the minimum screen size this control can occupy, |
  197. |                     based on the size and positions of its child windows.    |
  198. ------------------------------------------------------------------------------*/
  199. virtual ISize
  200.   calcMinimumSize     ( ) const;
  201.  
  202. /*---------------------------------- Layout ------------------------------------
  203. | The following functions provide the major functionality of this class:       |
  204. |   layout              - This function is overridden by derived classes to    |
  205. |                         size and position child windows.                     |
  206. |   layoutSize          - Returns the size needed to show all child windows.   |
  207. |   setLayoutSize       - Sets the size needed to show all child windows.      |
  208. |   fixupChildren       - Generates a list of all child windows, determines    |
  209. |                         whether any can be tabbed to, and allows for         |
  210. |                         reversing the order in which they are iterated.      |
  211. |   areChildrenReversed - States whether the order in which child windows are  |
  212. |                         returned by the IWindow::ChildCursor class has been  |
  213. |                         changed to the order of the child windows'           |
  214. |                         construction.                                        |
  215. ------------------------------------------------------------------------------*/
  216. virtual ICanvas
  217.  &layout              ( );
  218. const ISize
  219.  &layoutSize          ( ) const;
  220. ICanvas
  221.  &setLayoutSize       ( const ISize& size );
  222. IWindowPosBuffer
  223.   fixupChildren       ( );
  224. Boolean
  225.   areChildrenReversed ( ) const;
  226.  
  227. private:
  228. /*--------------------------------- Private ----------------------------------*/
  229.   ICanvas             ( const ICanvas& );
  230. ICanvas
  231.  &operator=           ( const ICanvas& );
  232.  
  233. static Style
  234.   currentDefaultStyle;
  235. ISize
  236.   sizClLayout;
  237. IWindowHandle
  238.   hwndClDefaultButton;
  239. Boolean
  240.   bClChildrenReversed,
  241.   bClDefaultHandlerAdded;
  242. };
  243.  
  244. INESTEDBITFLAGCLASSFUNCS(Style, ICanvas);
  245.  
  246. /*----------------------------------------------------------------------------*/
  247. /* Resume compiler default packing.                                           */
  248. /*----------------------------------------------------------------------------*/
  249. #pragma pack()
  250.  
  251. /*----------------------------- Inline Functions -----------------------------*/
  252. #ifndef I_NO_INLINES
  253.   #include <icanvas.inl>
  254. #endif
  255.  
  256. #endif /* _ICANVAS_ */
  257.