home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctlcpp.zip / IABSWIN.HPP < prev    next >
C/C++ Source or Header  |  1994-06-06  |  6KB  |  150 lines

  1. #ifndef _IABSWIN_
  2.    #define _IABSWIN_
  3. /***************************************************************/
  4. /* Filename: iabswin.hpp                                       */
  5. /*                                                             */
  6. /* Purpose: Declaration of classes IAbstractWindow and         */
  7. /*          IAbsWinHandler.                                    */
  8. /*                                                             */
  9. /* Program name: cppctl.exe     Title: C++ PM Control Test App */
  10. /* OS/2 Developer Magazine, Issue: Sept. '94, page             */
  11. /* Article title: Writing OS/2 PM Controls in C++              */
  12. /* Authors: Eric Snell and Lori Ruffing                        */
  13. /*                                                             */
  14. /* Description: This example shows how to implement an OS/2 PM */
  15. /*              control window in C++.                         */
  16. /*                                                             */
  17. /* Program Requirements: This example requires the IBM C Set++ */
  18. /*                       compiler and libraries.               */
  19. /***************************************************************/
  20.  
  21. #ifndef _ICONTROL_
  22.    #include <icontrol.hpp>
  23. #endif
  24.  
  25. #ifndef _ISTRING_
  26.    #include <istring.hpp>
  27. #endif
  28.  
  29. #ifndef _IPAINHDR_
  30.    #include <ipainhdr.hpp>
  31. #endif
  32.  
  33. #ifndef _ISIZEHDR_
  34.    #include <isizehdr.hpp>
  35. #endif
  36.  
  37. #ifndef _IMMOVHDR_
  38.    #include "immovhdr.hpp"
  39. #endif
  40.  
  41. // Align classes on 4 byte boundary
  42. #pragma pack(4)
  43.  
  44. // We need a handler for various messages we want to handle. To
  45. // split the msgs out into various handlers is really more work
  46. // than we want to do and we don't see much reuse outside of
  47. // IAbstractWindow.
  48. class IAbsWinHandler : public IHandler
  49.    {
  50.    public:
  51.       IAbsWinHandler();
  52.       virtual ~IAbsWinHandler();
  53.  
  54.    protected:
  55.       virtual Boolean dispatchHandlerEvent(IEvent& evt);
  56.       virtual Boolean presParamChanged(IEvent& evt) = 0;
  57.       virtual Boolean eraseBackground(IEvent& evt) = 0;
  58.       virtual Boolean gainingFocus(IEvent &evt) = 0;
  59.       virtual Boolean losingFocus(IEvent &evt) = 0;
  60.    };
  61.  
  62.  
  63. //---------------------------------------------------------------------------
  64. // IAbstractWindow
  65. //
  66. // This class is an abstract class which should be used as the base of
  67. // new PM controls. This class handles the registration of the PM class
  68. // and alleviates some of the problems associated with inheriting from
  69. // a preexisting control such as ICanvas.
  70. //
  71. // The constructor of this class is protected since users should not create
  72. // an instance of the class, but subclasses do need to invoke the
  73. // constructor.
  74. //---------------------------------------------------------------------------
  75. class IAbstractWindow : public IControl,
  76.                         protected IPaintHandler,
  77.                         protected IResizeHandler,
  78.                         protected IMouseMoveHandler,
  79.                         protected IAbsWinHandler
  80.    {
  81.    public:
  82. //------------------------------- Contructor --------------------------------
  83. // The constructor for this class accepts a class name, class styles, and
  84. // the amount of extra bytes that should be allocated for each window
  85. // of this class (please see WinRegisterClass in the OS/2 toolkit for more
  86. // information). The constructor also accepts the parameters usually
  87. // associated with window construction in ICLUI (see IWindow::create and
  88. // WinCreateWindow for more info).
  89. //
  90. // This constructor will register the window class with PM if the class
  91. // has not already been registered. A ??? exception is thrown if window
  92. // class registration fails.
  93. //---------------------------------------------------------------------------
  94.       IAbstractWindow(const IString& windowClassName,
  95.                       unsigned long windowClassStyles,
  96.                       unsigned long extraDataBytes,
  97.                       unsigned long id,
  98.                       IWindow* parent,
  99.                       IWindow* owner,
  100.                       const IRectangle& initial = IRectangle(),
  101.                       unsigned long style = 0);
  102.  
  103.       virtual ~IAbstractWindow();
  104.  
  105. //--------------------------- Class Information -----------------------------
  106. // windowClass       - Returns the window class name passed on construction.
  107. // windowClassStyle  - Returns the window class style passed on contruction.
  108. // windowDataBytes   - Returns the number of data bytes requested during
  109. //                     construction, plus the minimumWindowData(). The
  110. //                     data bytes are commonly referred to as "window words".
  111. // minimumWindowData - Returns the minimum amount of "window words"
  112. //                     (in bytes) that are allocated for windows of this
  113. //                     class. These window words are meant for user use
  114. //                     and should not be used by subclasses of this class.
  115. //
  116. // Notes:
  117. //   Window words can be set/retrieved using the IWindow methods
  118. //   windowUShort, windowULong, and setWindowData.
  119. //---------------------------------------------------------------------------
  120.       virtual IString windowClass() const;
  121.       virtual unsigned long windowClassStyle() const;
  122.       virtual unsigned long windowDataBytes() const;
  123.       static unsigned long minimumWindowData();
  124.  
  125.    protected:
  126.       virtual Boolean paintWindow(IPaintEvent& evt);
  127.       virtual Boolean mouseMove(IMouseMoveEvent &evt);
  128.       virtual Boolean windowResize(IResizeEvent& evt);
  129.       virtual Boolean presParamChanged(IEvent& evt);
  130.       virtual Boolean eraseBackground(IEvent& evt);
  131.       virtual Boolean gainingFocus(IEvent &evt);
  132.       virtual Boolean losingFocus(IEvent &evt);
  133.  
  134.    private:
  135.       IAbstractWindow(const IAbstractWindow&);
  136.       IAbstractWindow& operator = (const IAbstractWindow&);
  137.  
  138.       static Boolean       hasBeenRegistered;
  139.       static unsigned long minWindowData;
  140.  
  141.       IString       clsName;
  142.       unsigned long clsStyle;
  143.       unsigned long exData;
  144.    };
  145.  
  146. // Resume compiler default packing
  147. #pragma pack()
  148.  
  149. #endif //#ifndef _IABSWIN_
  150.