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

  1. #ifndef _IWINDOW_
  2. #define _IWINDOW_
  3. /*******************************************************************************
  4. * FILE NAME: iwindow.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IWindow -  Abstract base class for all GUI window classes.               *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _IVBASE_
  19.   #include <ivbase.hpp>
  20. #endif
  21.  
  22. // Forward declarations for other classes:
  23. class IColor;
  24. class IException;
  25. class IHandler;
  26. class IHandlerList;
  27. class IRectangle;
  28. class IString;
  29. class IDMItemProvider;
  30.  
  31. #ifndef  _IBITFLAG_
  32.   #include <ibitflag.hpp>
  33. #endif
  34.  
  35. #ifndef _IEVENT_
  36.   #include <ievent.hpp>
  37. #endif
  38.  
  39. #ifndef  _IHANDLE_
  40.   #include <ihandle.hpp>
  41. #endif
  42.  
  43. #ifndef _IPOINT_
  44.   #include <ipoint.hpp>
  45. #endif
  46.  
  47. /*----------------------------------------------------------------------------*/
  48. /* Align classes on four byte boundary.                                       */
  49. /*----------------------------------------------------------------------------*/
  50. #pragma pack(4)
  51.  
  52.  
  53. class IWindow : public IVBase {
  54. typedef IVBase
  55.   Inherited;
  56. /*******************************************************************************
  57. * The IWindow class is the base window class and provides behavior common to   *
  58. * all windows.  While this class contains behavior that requires the           *
  59. * existence of a presentation window, the presentation window itself must be   *
  60. * constructed by the subclass.                                                 *
  61. *                                                                              *
  62. *                                                                              *
  63. * Example:                                                                     *
  64. *                                                                              *
  65. *  The following example demonstrates the required behavior of the constructor *
  66. *  of an IWindow subclass. This particular example might be used to extend     *
  67. *  the behavior of a typical static text field.                                *
  68. *                                                                              *
  69. *  //                                                                          *
  70. *  // Constructor to create a super control                                    *
  71. *  //                                                                          *
  72. *  SuperControl::SuperControl(unsigned long ulId,                              *
  73. *                             IWindow* pwndParent,                             *
  74. *                             IWindow* pwndOwner,                              *
  75. *                             const IRectangle& rectInit,                      *
  76. *                             Style efsStyle)                                  *
  77. *  {                                                                           *
  78. *  // Create the control using a call to IWindow::create                       *
  79. *    IWindowHandle whSuperControl =                                            *
  80. *       create(pwndParent->handle(),                                           *
  81. *                       WC_STATIC, 0,                                          *
  82. *                       efsStyle.asUnsignedLong(),                             *
  83. *                       rectInit.left(), rectInit.bottom(),                    *
  84. *                       rectInit.width(), rectInit.height(),                   *
  85. *                       (pwndOwner==0)?0:pwndOwner->handle(),                  *
  86. *                       HWND_TOP, ulId, 0, 0);                                 *
  87. *                                                                              *
  88. *    if (whSuperControl == 0)                                                  *
  89. *    {                                                                         *
  90. *       // indicates an error so throw an exception                            *
  91. *    }                                                                         *
  92. *    // tell IWindow to start processing events for the window                 *
  93. *    startHandlingEventsFor(whSuperControl);                                   *
  94. *  }                                                                           *
  95. *                                                                              *
  96. *******************************************************************************/
  97. public:
  98.  
  99. /*------------------------- Constructors/Destructor ----------------------------
  100. | There are two ways to construct an IWindow.  Both constructors exist so      |
  101. | that you can create a user interface "wrapper" instance for a window of      |
  102. | unknown type, such as any window in the client area.                         |
  103. |                                                                              |
  104. | You can construct an IWindow from:                                           |
  105. |    - A control on a loaded dialog template                                   |
  106. |    - An existing window's window handle.                                     |
  107. |                                                                              |
  108. | Both constructors are implemented by calling:                                |
  109. |    - The setAutoDestroyWindow(false) function to ensure that the window is   |
  110. |      not destroyed when the IWindow is destructed.                           |
  111. |    - The startHandlingEventsFor function, which results in the window being  |
  112. |      subclassed and added to the window list for full event processing.      |
  113. ------------------------------------------------------------------------------*/
  114.   IWindow     ( unsigned long        id,
  115.                 IWindow*             parentDialog);
  116.   IWindow     ( const IWindowHandle& handle);
  117.  
  118. virtual
  119.  ~IWindow     ( );
  120.  
  121. /*---------------------------------- Style -------------------------------------
  122. |  The following functions provide a means to set and query window styles:     |
  123. |                                                                              |
  124. |    Style - Nested class that provides static members that define the set of  |
  125. |            valid window styles.  For example, you could define an instance   |
  126. |            of the IWindow::Style class and initialize it like:               |
  127. |              IWindow::Style                                                  |
  128. |                style = visible | clipChildren | saveBits;                    |
  129. |            An object of this type is provided when the window is created. A  |
  130. |            customizable default is used if no styles are specified.  Once    |
  131. |            the object is constructed, you can use IWindow member functions   |
  132. |            to set or query the object's style.                               |
  133. |                                                                              |
  134. |            The declaration of the IWindow::Style nested class is generated   |
  135. |            by the INESTEDBITFLAGCLASSDEF0 macro.                             |
  136. |                                                                              |
  137. |  The valid window styles are:                                                |
  138. |    noStyle      - Sets all styles off.                                       |
  139. |    visible      - Causes the window to be visible.  In general, controls     |
  140. |                   are constructed as visible and frame windows as invisible. |
  141. |    disabled     - Specifies that keyboard and mouse input are no longer      |
  142. |                   dispatched to the window, preventing the window from       |
  143. |                   being used.                                                |
  144. |    clipChildren - Excludes the area occupied by the children of the window   |
  145. |                   when drawing in the window.  Child windows are always      |
  146. |                   "clipped" to their parent window.  When a parent window    |
  147. |                   is painted, the clipChildren style controls whether the    |
  148. |                   invalidated region of the parent window includes the area  |
  149. |                   occupied by its children, thus preventing a window from    |
  150. |                   painting over its child windows.                           |
  151. |    clipSiblings - Controls which sibling window is displayed on top when     |
  152. |                   multiple siblings are displayed.  Sibling windows are      |
  153. |                   windows that share the same parent window.  Assign the     |
  154. |                   clipSiblings style to the sibling window that should be    |
  155. |                   displayed on top of the other siblings, in Z-order.        |
  156. |    clipToParent - Allows a window to paint outside of its window boundary up |
  157. |                   to the window boundary of its parent.                      |
  158. |    saveBits     - Optimizes the painting of a window by saving the screen    |
  159. |                   image of the area under the window as a bit map, and then  |
  160. |                   using the bit map to redraw the window when necessary.     |
  161. |    synchPaint   - Synchronously repaints the window.  Without this style,    |
  162. |                   painting only occurs if there are no other events waiting  |
  163. |                   to be processed.                                           |
  164. ------------------------------------------------------------------------------*/
  165. INESTEDBITFLAGCLASSDEF0(Style, IWindow);
  166. static const Style
  167.   noStyle,
  168.   visible,
  169.   disabled,
  170.   clipChildren,
  171.   clipSiblings,
  172.   clipToParent,
  173.   saveBits,
  174.   synchPaint;
  175.  
  176. /*------------------------------ Related Types ---------------------------------
  177. | The following enumeration is defined:                                        |
  178. |   EventType - Enumeration that specifies windowing system message            |
  179. |               identifiers.  Valid values are:                                |
  180. |                 command       - The event type is user command.              |
  181. |                 systemCommand - The event type is system command.            |
  182. |                 help          - The event type is help.                      |
  183. |                 character     - The event type is key character.             |
  184. ------------------------------------------------------------------------------*/
  185. enum EventType { command=1, systemCommand, help, character };
  186.  
  187. /*---------------------------- Window Positioning ------------------------------
  188. | These functions are used to set and query the size and position of windows:  |
  189. |   moveTo                 - Changes the position of the window.               |
  190. |   sizeTo                 - Changes the size of the window.                   |
  191. |   moveSizeTo             - Changes the position and size of the window.      |
  192. |   position               - Returns the window position.                      |
  193. |   size                   - Returns the size of the window in window          |
  194. |                            coordinates.                                      |
  195. |                            NOTE: This function returns ISize(0,0) for a      |
  196. |                                  frame window if it is constructed using     |
  197. |                                  the shell position and the window has not   |
  198. |                                  been shown.                                 |
  199. |   rect                   - Returns a rectangle that represents the position  |
  200. |                            and size of the window.                           |
  201. |                            NOTE: This function returns IRectangle(0,0,0,0)   |
  202. |                                  for a frame window if it is constructed     |
  203. |                                  using the shell position and the window     |
  204. |                                  has not been shown.                         |
  205. ------------------------------------------------------------------------------*/
  206. virtual IWindow
  207.  &moveTo                 ( const IPoint& aPoint ),
  208.  &sizeTo                 ( const ISize& newSize ),
  209.  &moveSizeTo             ( const IRectangle& aRectangle );
  210.  
  211. IPoint
  212.   position       ( ) const;
  213.  
  214. ISize
  215.   size           ( ) const;
  216.  
  217. IRectangle
  218.   rect           ( ) const;
  219.  
  220. /*-------------------------------- Accessors -----------------------------------
  221. | These functions provide a means of getting and setting the accessible        |
  222. | attributes of instances of this class:                                       |
  223. |   enable           - Enables the window to accept keyboard and mouse input.  |
  224. |   disable          - Prevents keyboard and mouse input from being sent to    |
  225. |                      the window.                                             |
  226. |   isDisabled       - Returns true if the window is not sent mouse and        |
  227. |                      keyboard input.                                         |
  228. |   setFocus         - Sets the input focus to the window.                     |
  229. |   hasFocus         - Returns true if the window has the input focus.         |
  230. |   setParent        - Changes the window parent.                              |
  231. |   parent           - Returns the window's parent.                            |
  232. |   setOwner         - Changes the window owner.                               |
  233. |   owner            - Returns the window's owner.                             |
  234. |   isValid          - Returns true if this object represents a valid          |
  235. |                      Presentation Manager window.  It returns false if the   |
  236. |                      window has yet to be created or has already been        |
  237. |                      destroyed.                                              |
  238. |   isFrameWindow    - Returns true if this object represents a frame window.  |
  239. |   desktopWindow    - Returns the instance of the object that represents the  |
  240. |                      system desktop window.                                  |
  241. |   objectWindow     - Returns the instance of the object that represents the  |
  242. |                      system object.                                          |
  243. |   handle           - Returns the window handle.                              |
  244. |   windowWithHandle - Static function to return the IWindow instance in the   |
  245. |                      current thread for the passed window handle.            |
  246. |   windowWithId     - Static function to return the IWindow instance in the   |
  247. |                      current thread for the ID and owner.                    |
  248. |   handleWithId     - Static function to return the window handle for the     |
  249. |                      passed ID and owner.                                    |
  250. |   id               - Returns the window ID.                                  |
  251. |   messageQueue     - Returns the handle for the window's message queue.      |
  252. ------------------------------------------------------------------------------*/
  253. virtual IWindow
  254.  &enable             ( Boolean        enableWindow=true ),
  255.  &disable            ( ),
  256.  &setFocus           ( ),
  257.  &setParent          ( const IWindow* newParent ),
  258.  &setOwner           ( const IWindow*  newOwner );
  259.  
  260. IWindow
  261.  *parent             ( ) const,
  262.  *owner              ( ) const;
  263.  
  264. Boolean
  265.   isDisabled         ( ) const,
  266.   hasFocus           ( ) const,
  267.   isValid            ( ) const,
  268.   isFrameWindow      ( ) const;
  269.  
  270. static IWindow
  271.  *desktopWindow      ( ),
  272.  *objectWindow       ( );
  273.  
  274. virtual IWindowHandle
  275.   handle             ( ) const;
  276.  
  277. static IWindow
  278.  *windowWithHandle   ( const IWindowHandle& windowHandle ),
  279.  *windowWithId       ( unsigned long        id,
  280.                        const IWindow*       owner );
  281.  
  282. static IWindowHandle
  283.   handleWithId       ( unsigned long        id,
  284.                        const IWindowHandle& parent );
  285.  
  286. unsigned long
  287.   id                 ( ) const;
  288.  
  289. IMessageQueueHandle
  290.   messageQueue       ( ) const;
  291.  
  292. /*------------------------- Sibling Order Enumeration --------------------------
  293. | SiblingOrder - Enumeration that is used to specify the sibling order of      |
  294. |                newly created windows. The valid values are:                  |
  295. |                  onTopOfSiblings   - New windows are created on top of their |
  296. |                                   sibling windows.                           |
  297. |                  behindSiblings    - New windows are created behind their    |
  298. |                                   sibling windows.                           |
  299. ------------------------------------------------------------------------------*/
  300. enum SiblingOrder {
  301.   onTopOfSiblings,
  302.   behindSiblings };
  303.  
  304. /*------------------------- Sibling Order --------------------------------------
  305. | These functions affect the ordering of windows with their siblings. The      |
  306. | window order (or Z Order) is used when tabbing or painting sibling windows.  |
  307. | Window painting starts from the bottom sibling and proceeds to the top       |
  308. | window.  Cursor tabbing occurs from the top sibling and proceeds             |
  309. | to the bottom window.                                                        |
  310. |   positionBehindSiblings - Puts this window in the order behind all its      |
  311. |                            sibling windows.                                  |
  312. |   positionOnSiblings     - Puts this window in the order on top of all       |
  313. |                            its sibling windows.                              |
  314. |   positionBehindSibling  - Puts this window in the order behind the          |
  315. |                            argument sibling window.                          |
  316. |   setDefaultOrdering      - Determines whether new windows are created on    |
  317. |                             top of their sibling windows or behind them. By  |
  318. |                             default, windows are created behind their        |
  319. |                             other siblings.  If this function is called      |
  320. |                             with a value of IWindow::onTopOfSiblings, new    |
  321. |                             windows will be created on top of their siblings.|
  322. |   defaultOrdering         - Returns the order in which new windows will be   |
  323. |                             created relative to their sibling windows.       |
  324. ------------------------------------------------------------------------------*/
  325. virtual IWindow
  326.  &positionBehindSiblings ( ),
  327.  &positionOnSiblings     ( ),
  328.  &positionBehindSibling  ( const IWindowHandle& siblingWindow);
  329.  
  330. static void
  331.  setDefaultOrdering     ( SiblingOrder          order);
  332. static SiblingOrder
  333.  defaultOrdering        ( );
  334.  
  335. /*----------------------------- Event Send/Post --------------------------------
  336. | These functions provide a simplified means of sending or posting an IEvent   |
  337. | to a window:                                                                 |
  338. |   postEvent - Posts an event constructed from the arguments to the window.   |
  339. |               If an EventType is used, an event will be constructed with     |
  340. |               the appropriate message identifier.                            |
  341. |   sendEvent - Sends an event constructed from the arguments to the window.   |
  342. |               If an EventType is used, an event will be constructed with     |
  343. |               the appropriate message identifier.                            |
  344. ------------------------------------------------------------------------------*/
  345. void
  346.   postEvent ( unsigned long           eventId,
  347.               const IEventParameter1 &parm1 = 0,
  348.               const IEventParameter2 &parm2 = 0 ) const,
  349.   postEvent ( const IEvent&           event )     const,
  350.   postEvent ( EventType               eventType,
  351.               const IEventParameter1 &parm1 = 0,
  352.               const IEventParameter2 &parm2 = 0 ) const;
  353.  
  354. IEventResult
  355.   sendEvent ( unsigned long           eventId,
  356.               const IEventParameter1 &parm1 = 0,
  357.               const IEventParameter2 &parm2 = 0 ) const,
  358.   sendEvent ( const IEvent&           event )     const,
  359.   sendEvent ( EventType               eventType,
  360.               const IEventParameter1 &parm1 = 0,
  361.               const IEventParameter2 &parm2 = 0 ) const;
  362.  
  363. /*----------------------------- Window Painting --------------------------------
  364. | These functions are used in displaying a window and determining the          |
  365. | visibility of a window.                                                      |
  366. |   show               - Makes the window visible.                             |
  367. |   hide               - Hides the window.                                     |
  368. |   disableUpdate      - Prevents changes to a window from being drawn on the  |
  369. |                        screen.  This function is typically used to make a    |
  370. |                        series of changes to a window without displaying      |
  371. |                        each change as it is made.  Call the show function    |
  372. |                        to cause changes to be drawn on the screen.  Do not   |
  373. |                        destroy a window while it is in the update-disabled   |
  374. |                        state; if you do, the destroyed window is not         |
  375. |                        removed from the screen.                              |
  376. |   enableUpdate       - Reverts the window from an update-disabled state to   |
  377. |                        a state in which changes are drawn on the screen.     |
  378. |   refresh            - Has the following implementations:                    |
  379. |                          - Invalidates and redraws the entire window.  If    |
  380. |                            the refreshChildren argument is true, the         |
  381. |                            children are updated as well.                     |
  382. |                          - Invalidates and redraws a given window rectangle. |
  383. |   showSourceEmphasis - Called by a pop-up menu handler to notify the window  |
  384. |                        to draw pop-up menu emphasis.  The default behavior   |
  385. |                        of IWindow is to do nothing.                          |
  386. |   hideSourceEmphasis - Called by a pop-up menu handler to notify the window  |
  387. |                        to remove pop-up menu emphasis.  The default          |
  388. |                        behavior of IWindow is to do nothing.                 |
  389. |   isVisible          - Returns true if the windows style is visible.         |
  390. |                        NOTE: A window can have a style of visible and yet    |
  391. |                              not be showing if it is covered by another      |
  392. |                              window.                                         |
  393. |   isShowing          - Returns true if any part of the window is showing.    |
  394. |                        NOTE: A window can be visible and yet not be showing  |
  395. |                              if it is covered by another window.             |
  396. |   presSpace          - Acquires and returns the presentation space handle    |
  397. |                        for the window.                                       |
  398. |   releasePresSpace   - Releases the window's presentation space handle.      |
  399. |   setLayoutDistorted - Indicates that changes have occurred in the window    |
  400. |                        that will cause the layout of the window in a canvas  |
  401. |                        to be updated.                                        |
  402. |   isLayoutDistorted  - Determines whether changes have been made in a        |
  403. |                        window that will require updating the layout of the   |
  404. |                        window in a canvas.                                   |
  405. |   setMinimumSize     - Sets the minimum allowable size of the window.  In    |
  406. |                        the library, this applies to windows on a canvas      |
  407. |                        only.                                                 |
  408. |   minimumSize        - Returns the minimum allowable size set by the user's  |
  409. |                        class.                                                |
  410. ------------------------------------------------------------------------------*/
  411. virtual IWindow
  412.  &show                     ( Boolean           showWindow=true ),
  413.  &hide                     ( ),
  414.  &enableUpdate             ( Boolean           enableWindow=true ),
  415.  &disableUpdate            ( ),
  416.  &refresh                  ( Boolean           refreshChildren=false ),
  417.  &refresh                  ( const IRectangle& invalidRectangle ),
  418.  &showSourceEmphasis       ( Boolean           show=true ),
  419.  &hideSourceEmphasis       ( );
  420.  
  421. Boolean
  422.   isVisible                ( ) const,
  423.   isShowing                ( ) const;
  424.  
  425. IPresSpaceHandle
  426.   presSpace                ( ) const;
  427.  
  428. void
  429.   releasePresSpace         ( const IPresSpaceHandle& aPresentationSpaceHandle ) const;
  430.  
  431. enum Layout { windowCreated=1, colorChanged=2, sizeChanged=4,
  432.               minimumSizeChanged=8, childMinimumSizeChanged=16,
  433.               fontChanged=32, fontPropogated=64, layoutChanged=128,
  434.               immediateUpdate=256, childWindowCreated=512,
  435.               windowDestroyed=1024, childWindowDestroyed=2048 };
  436. virtual IWindow
  437.  &setLayoutDistorted       ( unsigned long layoutAttributeOn,
  438.                              unsigned long layoutAttributeOff );
  439.  
  440. virtual Boolean
  441.   isLayoutDistorted        ( unsigned long layoutAttribute ) const;
  442.  
  443. IWindow
  444.  &setMinimumSize           ( const ISize& sizMin );
  445. ISize
  446.   minimumSize              ( ) const;
  447.  
  448. /*------------------------- Object Deletion ------------------------------------
  449. | These functions provide a means of managing the window object:               |
  450. |   setAutoDeleteObject  - Determines whether the IWindow instance should be   |
  451. |                          deleted when the presentation window is destroyed.  |
  452. |                          The deletion will occur when the Presentation       |
  453. |                          Manager dispatches a destroy event to the window.   |
  454. |                          By default, the instance is not deleted.            |
  455. |   setAutoDestroyWindow - Determines whether the presentation window should   |
  456. |                          be destroyed when the IWindow instance is deleted.  |
  457. |                          This is used in cases where an IWindow is a         |
  458. |                          wrapper for a presentation window whose creation    |
  459. |                          and destruction are handled outside the C++ object. |
  460. |   isAutoDeleteObject   - Returns true if the window instance will be         |
  461. |                          deleted when a destroy event is dispatched to the   |
  462. |                          window.                                             |
  463. |   isAutoDestroyWindow  - Returns true if the presentation window will be     |
  464. |                          destroyed when the window instance is deleted.      |
  465. ------------------------------------------------------------------------------*/
  466. IWindow
  467.  &setAutoDeleteObject      ( Boolean autoDelete=true ),
  468.  &setAutoDestroyWindow     ( Boolean autoDestroy=false );
  469.  
  470. Boolean
  471.   isAutoDeleteObject       ( ) const,
  472.   isAutoDestroyWindow      ( ) const;
  473.  
  474. /*------------------------------ Drag/Drop Support -----------------------------
  475. | These functions provide means of getting and setting the accessible          |
  476. | attributes of instances of this class:                                       |
  477. |   itemProvider    - Returns pointer to drag item provider for this window    |
  478. |   setItemProvider - Sets pointer to drag item provider for this window.      |
  479. ------------------------------------------------------------------------------*/
  480. IDMItemProvider
  481.  *itemProvider ( ) const;
  482.  
  483. IWindow
  484.  &setItemProvider ( IDMItemProvider *dragProvider );
  485.  
  486. class ChildCursor : public IVBase {
  487. /*******************************************************************************
  488. * The IWindow::ChildCursor class is a nested cursor class used to iterate      *
  489. * over the children of any window.  The children are accessed in Z-order,      *
  490. * from top to bottom.                                                          *
  491. *                                                                              *
  492. * Example:                                                                     *
  493. *   // Iterate over children of frame...                                       *
  494. *   IFrameWindow                                                               *
  495. *     frame;                                                                   *
  496. *   IFrameWindow::ChildCursor                                                  *
  497. *     cursor ( frame );                                                        *
  498. *   for ( cursor.setToFirst(); cursor.isValid(); cursor.setToNext() )          *
  499. *     { // Do something with each child...                                     *
  500. *     IWindowHandle                                                            *
  501. *       child = frame.childAt( cursor );                                       *
  502. *     ...                                                                      *
  503. *     }                                                                        *
  504. *******************************************************************************/
  505. public:
  506. /*-------------------------- Constructor/Destructor ----------------------------
  507. | You can construct objects of this class from a reference to the window       |
  508. | whose child windows will be iterated over.                                   |
  509. ------------------------------------------------------------------------------*/
  510.   ChildCursor ( IWindow &parent );
  511.  
  512.  ~ChildCursor ( );
  513.  
  514. /*-------------------------------- Overrides -----------------------------------
  515. | The nested ChildCursor class overrides the following functions to            |
  516. | provide the appropriate cursor behavior:                                     |
  517. |   setToFirst - Resets the cursor position to the first child window (in      |
  518. |                Z-order).                                                     |
  519. |   setToNext  - Advances the cursor position to the next child window (in     |
  520. |                Z-order).                                                     |
  521. |   isValid    - Returns true if the cursor is in a valid area.                |
  522. |   invalidate - Marks the cursor as invalid.                                  |
  523. ------------------------------------------------------------------------------*/
  524. virtual Boolean
  525.   setToFirst ( ),
  526.   setToNext  ( ),
  527.   isValid    ( ) const;
  528.  
  529. virtual void
  530.   invalidate ( );
  531.  
  532. private:
  533. /*--------------------------------- Private ----------------------------------*/
  534. friend class IWindow;
  535. IEnumHandle
  536.   enumHandle;
  537. IWindowHandle
  538.   windowHandle,
  539.   parentHandle;
  540. ChildCursor
  541.  &operator =  ( const ChildCursor & );
  542.   ChildCursor ( const ChildCursor & );
  543. }; // IWindow::ChildCursor
  544.  
  545. /*------------------------------ ChildCursor Support ---------------------------
  546. |   childAt - Returns the window handle of the child window at the current     |
  547. |             position of the argument cursor.                                 |
  548. ------------------------------------------------------------------------------*/
  549. IWindowHandle
  550.   childAt ( const ChildCursor &aCursor ) const;
  551.  
  552. /*------------------------------ Canvas Support --------------------------------
  553. | These functions are used by the canvas classes to provide dialog-like        |
  554. | behavior (minimal implementations are provided here):                        |
  555. |   isTabStop         - Returns true if the user can tab to the window.        |
  556. |   defaultPushButton - Returns the first child window that is a default push  |
  557. |                       button, if one exists.                                 |
  558. |   matchForMnemonic  - Returns the first child window that uses the           |
  559. |                       specified character as a mnemonic.                     |
  560. ------------------------------------------------------------------------------*/
  561. virtual Boolean
  562.   isTabStop          ( ) const;
  563.  
  564. virtual IWindowHandle
  565.   defaultPushButton  ( ) const,
  566.   matchForMnemonic   ( unsigned short character ) const;
  567.  
  568. /*------------------------------ Miscellaneous ---------------------------------
  569. | This function is used to map coordinates from one window to another:         |
  570. |   mapPoint - Static function to map a point from one window's coordinate     |
  571. |              space to another's, such as mapping from screen coordinates to  |
  572. |              window coordinates.                                             |
  573. ------------------------------------------------------------------------------*/
  574. static IPoint
  575.   mapPoint ( const IPoint        &aPoint,
  576.              const IWindowHandle &from,
  577.              const IWindowHandle &to    );
  578.  
  579. /*------------------------------- Diagnostics ----------------------------------
  580. | The following functions are used to output information for the window:       |
  581. |   asString    - Returns a string that contains the window handle and ID.     |
  582. |   asDebugInfo - Returns a string that contains detailed information about    |
  583. |                 the window, including the information provided by asString.  |
  584. ------------------------------------------------------------------------------*/
  585. virtual IString
  586.   asString    ( ) const,
  587.   asDebugInfo ( ) const;
  588.  
  589.  
  590. class ExceptionFn : public IVBase {
  591. typedef IVBase
  592.   Inherited;
  593. /*******************************************************************************
  594. * The IWindow::ExceptionFn nested class is used to process exceptions that     *
  595. * occur when events are dispatched by the IWindow dispatcher.                  *
  596. *                                                                              *
  597. * Example:                                                                     *
  598. *                                                                              *
  599. * class MyFrameWindow : public IFrameWindow, public IWindow::ExceptionFn {     *
  600. * virtual Boolean                                                              *
  601. *   handleException (IException& exception, IEvent& event) {                   *
  602. *      return true;     // ignore the exception and continue dispatching       *
  603. * };                                                                           *
  604. *                                                                              *
  605. * MyFrameWindow :: MyFrameWindow () {                                          *
  606. *   setExceptionFunction(this);                                                *
  607. *                                                                              *
  608. *                                                                              *
  609. *******************************************************************************/
  610. public:
  611.  ~ExceptionFn ( );
  612. /*--------------------------- Exception Processing -----------------------------
  613. | The following function is used to process C++ exceptions in the IWindow      |
  614. | dispatcher:                                                                  |
  615. |   handleException - If an exception object is registered with IWindow, this  |
  616. |                     function will be called when an uncaught exception       |
  617. |                     occurs while dispatching events.  This function should   |
  618. |                     return true if the exception situation was handled and   |
  619. |                     it is safe to continue dispatching events.  If false is  |
  620. |                     returned, the exception will be thrown again.            |
  621. ------------------------------------------------------------------------------*/
  622. virtual Boolean
  623.   handleException         ( IException& dispatcherException,
  624.                             IEvent&     exceptionEvent     ) = 0;
  625. }; // IWindow::ExceptionFn
  626.  
  627.  
  628. /*----------------------------- Exception Processing ---------------------------
  629. | The following functions are used to process C++ exceptions in the IWindow    |
  630. | dispatcher:                                                                  |
  631. |   setExceptionFunction - Stores an IWindow::ExceptionFn object to be called  |
  632. |                          when an uncaught exception is detected while        |
  633. |                          dispatching window events.  If an object has        |
  634. |                          already been registered, it is returned;            |
  635. |                          otherwise, 0 is returned.                           |
  636. |   exceptionFunction    - Returns a pointer to the current exception          |
  637. |                          function, or 0 if one has not been registered.      |
  638. |   handleException      - Called when an exception is detected during the     |
  639. |                          dispatch of an event.  The default behavior is to   |
  640. |                          determine if an IWindow::ExceptionFn object has     |
  641. |                          been registered and call it.  Otherwise, false is   |
  642. |                          returned and the exception is thrown again.         |
  643. ------------------------------------------------------------------------------*/
  644. static IWindow::ExceptionFn
  645.  *setExceptionFunction    ( IWindow::ExceptionFn* exceptionObject ),
  646.  *exceptionFunction       ( );
  647.  
  648. virtual Boolean
  649.   handleException         ( IException& dispatcherException,
  650.                             IEvent&     exceptionEvent     );
  651.  
  652. protected:
  653. /*------------------------------ Implementation --------------------------------
  654. | This function provides utilities used to implement this class:               |
  655. |   create          - Calls the graphical presentation system to create an     |
  656. |                     instance of a window.                                    |
  657. |   addHandler      - Adds an instance of a handler class to the window.       |
  658. |   removeHandler   - Removes a previously added handler.                      |
  659. |   setColor        - Sets the window area to the indicated color.  The        |
  660. |                     window area is identified by a system-defined            |
  661. |                     presentation parameter value.                            |
  662. |   setStyle        - Sets the window style using the masking bits defined by  |
  663. |                     the OS/2 Presentation Manager Toolkit.                   |
  664. |   color           - Returns the color value of the window area, or the       |
  665. |                     passed default if no color for the area has been set.    |
  666. |                     The window area is identified by a system-defined        |
  667. |                     presentation parameter value.                            |
  668. |   style           - Returns an unsigned long representing the window's       |
  669. |                     style, as defined by the OS/2 Presentation Manager       |
  670. |                     Toolkit.                                                 |
  671. |   isPrimaryWindow - Returns true if this window has no owner and the parent  |
  672. |                     is the desktop window.                                   |
  673. |   windowUShort    - Returns the given window word (as an unsigned short).    |
  674. |   windowULong     - Returns the given window word (as an unsigned long).     |
  675. |   setWindowData   - Sets the given window word (as an unsigned short or      |
  676. |                     unsigned long).  The result indicates whether it was     |
  677. |                     successful.                                              |
  678. ------------------------------------------------------------------------------*/
  679. virtual IWindowHandle
  680.  create           ( unsigned long         id,
  681.                     const char*           text,
  682.                     unsigned long         style,
  683.                     const char*           windowClass,
  684.                     const IWindowHandle&  parent,
  685.                     const IWindowHandle&  owner,
  686.                     const IRectangle&     initRect,
  687.                     const void*           ctlData,
  688.                     const void*           presParams,
  689.                     IWindow::SiblingOrder ordering = defaultOrdering());
  690.  
  691. IWindow
  692.  &addHandler      ( IHandler* newHandler ),
  693.  &removeHandler   ( IHandler* oldHandler );
  694.  
  695. IWindow
  696.  &setColor        ( unsigned long colorArea,
  697.                     const IColor& color    );
  698.  
  699. virtual IWindow
  700.  &setStyle        ( unsigned long style );
  701.  
  702. IColor
  703.   color           ( unsigned long colorArea ) const,
  704.   color           ( unsigned long colorArea,
  705.                     const IColor& defaultColor ) const;
  706.  
  707. unsigned long
  708.   style           ( ) const;
  709.  
  710. Boolean
  711.   isPrimaryWindow ( ) const;
  712.  
  713. unsigned short
  714.   windowUShort    ( long index ) const;
  715.  
  716. unsigned long
  717.   windowULong     ( long index ) const;
  718.  
  719. IWindow
  720.  &setWindowData   ( long index, unsigned short ushort ),
  721.  &setWindowData   ( long index, unsigned long  ulong  );
  722.  
  723. /*------------------------------- Constructor ----------------------------------
  724. | Constructor used by subclasses wishing control over window creation.         |
  725. ------------------------------------------------------------------------------*/
  726.   IWindow  ( );
  727.  
  728. /*---------------------------------- Layout ------------------------------------
  729. | The following function is used return the layout size:                       |
  730. |   calcMinimumSize - Returns the recommended minimum size for this IWindow    |
  731. |                     object.  This size is used by the canvas layout routine. |
  732. |                     A default operation returns the minimum size set by      |
  733. |                     users.  The size is based on the text and the current    |
  734. |                     font setting.                                            |
  735. ------------------------------------------------------------------------------*/
  736. virtual ISize
  737.   calcMinimumSize    ( ) const;
  738.  
  739. /*---------------------- Event Handling Implementation -------------------------
  740. | These functions provide the implementation of the event handling mechanism:  |
  741. |   startHandlingEventsFor - Starts processing events for the window.  This is |
  742. |                            a combination of subclassing the window procedure |
  743. |                            and storing the window in the current thread's    |
  744. |                            collection of windows.  You can only invoke this  |
  745. |                            function once per window, typically during        |
  746. |                            construction of the window.                       |
  747. |   addToWindowSet         - Adds a window to the current thread's collection  |
  748. |                            of windows.  A valid window handle must be        |
  749. |                            provided.                                         |
  750. |   removeFromWindowSet    - Removes a window from the current thread's        |
  751. |                            collection of windows.                            |
  752. |   dispatch               - Dispatches events to the handlers associated with |
  753. |                            a window.  If the event is not processed by a     |
  754. |                            handler or no handlers exist for the window,      |
  755. |                            defaultProcedure is called to process the event.  |
  756. |   defaultProcedure       - Provides default processing behavior for a window |
  757. |                            event.  This function calls the window procedure  |
  758. |                            that was returned from the window subclass during |
  759. |                            the call to startHandlingEventsFor.               |
  760. |   deleteIsInProcess      - Returns true if either the IWindow instance       |
  761. |                            destructor has been called or the presentation    |
  762. |                            window is being destroyed.                        |
  763. ------------------------------------------------------------------------------*/
  764. IWindow
  765.  &startHandlingEventsFor ( const IWindowHandle& windowHandle ),
  766.  &startHandlingEventsFor ( unsigned long        id,
  767.                          IWindow*             parentDialog);
  768. static void
  769.   addToWindowSet         ( IWindow*             window,
  770.                            const IWindowHandle& windowHandle ),
  771.   removeFromWindowSet    ( IWindow*             window );
  772.  
  773. Boolean
  774.   dispatch               ( IEvent& event );
  775.  
  776. IWindow
  777.  &defaultProcedure       ( IEvent& event );
  778.  
  779. Boolean
  780.   deleteIsInProcess      ( ) const;
  781.  
  782. private:
  783. /*--------------------------------- Private ----------------------------------*/
  784. /* IWindow Flags */
  785. enum  State { autoDeleteObject=1, autoDestroyWindow=2, deleteInProcess=4,
  786.               primaryWindow=8, addedToList=16, dispatchInProcess=32,
  787.               needsDelete=64};
  788. IWindow
  789.  &setDeleteInProcess  ( ),
  790.  &cleanUp             ( );
  791.  
  792. // setDefaultProcedure() is used by IFileDialog and IFontDialog
  793. // since they can't use startHandlingEventsFor().
  794. // These two classes are granted friendship below.
  795.  
  796. IWinProc
  797.  *setDefaultProcedure ( IWinProc *newDefProc );
  798.  
  799. static void
  800.   cleanUpHandler      ( IHandler & );
  801.  
  802. IWindow               ( const IWindow& );
  803. IWindow
  804.  &operator=           ( const IWindow& );
  805.  
  806. IWinProc
  807.  *pClDefWinProc;
  808. unsigned long
  809.   wndhCl,
  810.   ulClId,
  811.   ulClState,
  812.   ulClLayoutChange;
  813. IHandlerList*
  814.   pcolHandler;
  815. ISize
  816.   sizClMin;
  817.  
  818. static IWindow::ExceptionFn
  819.  *pexcClCurrent;
  820.  
  821. static IWindow::SiblingOrder
  822.   siblingCreateOrder;
  823.  
  824. /* friend functions */
  825. friend void* _System _pfnwpICWinProc ( unsigned long hwnd, unsigned long ulMsg, void* mp1, void* mp2 );
  826. friend unsigned long const& key ( IWindow* const& pwin );
  827.  
  828. /* friend classes */
  829. friend class IHandler;
  830. friend class IFileDialog;
  831. friend class IFontDialog;
  832.  
  833.  
  834. };
  835.  
  836. /*----------------------------------------------------------------------------*/
  837. /* Resume compiler default packing.                                           */
  838. /*----------------------------------------------------------------------------*/
  839. #pragma pack()
  840.  
  841. /*----------------------------- Inline Functions -----------------------------*/
  842. #ifndef I_NO_INLINES
  843.   #include <iwindow.inl>
  844. #endif
  845.  
  846. #endif /* _IWINDOW_ */
  847.