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

  1. #ifndef _NEWCTL_
  2.    #define _NEWCTL_
  3.  
  4. /***************************************************************/
  5. /* Filename: newctl.hpp                                        */
  6. /*                                                             */
  7. /* Purpose: Contains declaration of NewControl class which is  */
  8. /*          the client area of the main window.                */
  9. /*                                                             */
  10. /* Program name: cppctl.exe     Title: C++ PM Control Test App */
  11. /* OS/2 Developer Magazine, Issue: Sept. '94, page             */
  12. /* Article title: Writing OS/2 PM Controls in C++              */
  13. /* Authors: Eric Snell and Lori Ruffing                        */
  14. /*                                                             */
  15. /* Description: This example shows how to implement an OS/2 PM */
  16. /*              control window in C++.                         */
  17. /*                                                             */
  18. /* Program Requirements: This example requires the IBM C Set++ */
  19. /*                       compiler and libraries.               */
  20. /***************************************************************/
  21.  
  22. #ifndef _IABSWIN_
  23.    #include "iabswin.hpp"
  24. #endif
  25.  
  26. #ifndef _ICOLOR_
  27.    #include "icolor.hpp"
  28. #endif
  29.  
  30. #ifndef _IMCHDR_
  31.    #include <imchdr.hpp>
  32. #endif
  33.  
  34. // Align classes on 4 byte boundary
  35. #pragma pack(4)
  36.  
  37. class NewControl : public IAbstractWindow,
  38.                    public IMouseClickHandler
  39.    {
  40.    friend class NewControlHandler;
  41.  
  42.    public:
  43.       class Style;   // forward declaration for nested class
  44.  
  45.       NewControl(unsigned long id,
  46.                  IWindow* parent,
  47.                  IWindow* owner,
  48.                  const IRectangle& initial = IRectangle(),
  49.                  const Style& style = defaultStyle());
  50.  
  51.       virtual ~NewControl();
  52.  
  53. /*---------------------------------- Style -------------------------------------
  54. | The following functions provide a means to set and query NewControl styles:  |
  55. |                                                                              |
  56. |   Style - Nested class that provides static members that define the set      |
  57. |           of valid control styles.  These styles can be used in conjunction  |
  58. |           with the styles defined by the IControl::Style nested class. For   |
  59. |           example, you could define an instance of the NewControl::Style     |
  60. |           class and initialize it like:                                      |
  61. |             NewControl::Style                                                |
  62. |               style = NewControl::classDefaultStyle |                        |
  63. |                       IWindow::saveBits;                                     |
  64. |           An object of this type is provided when NewControl is created.  A  |
  65. |           customizable default is used if no styles are specified.  Once     |
  66. |           the object is constructed, NewControl and IWindow member functions |
  67. |           can be used to set or query the object's style.                    |
  68. |                                                                              |
  69. |           The declaration of the Style nested class is generated             |
  70. |           by the INESTEDBITFLAGCLASSDEF2 macro.                              |
  71. |                                                                              |
  72. | The valid NewControl style is:                                               |
  73. |   classDefaultStyle - The original default style for this class, which is    |
  74. |                       IWindow::visible                                       |
  75. |                                                                              |
  76. | The following functions provide a means of getting and setting the default   |
  77. | style for new objects of this class:                                         |
  78. |   defaultStyle    - Returns the current default style, which is the same as  |
  79. |                     classDefaultStyle unless setDefaultStyle has been        |
  80. |                     called.                                                  |
  81. |   setDefaultStyle - Sets the default style for all subsequent NewControls.   |
  82. ------------------------------------------------------------------------------*/
  83.       // Name the nested class "Style" and combine IControl and IWindow
  84.       // styles with NewControl.
  85.       INESTEDBITFLAGCLASSDEF2(Style, NewControl, IControl, IWindow);
  86.  
  87.       static const Style notifyMB1;
  88.       static const Style notifyMB2;
  89.  
  90.       static const Style classDefaultStyle;
  91.  
  92.       static Style defaultStyle();
  93.  
  94.       static void setDefaultStyle(const Style& style);
  95.  
  96.  
  97. /*------------------------------- Enumerations ---------------------------------
  98. | The following enumerations are defined:                                      |
  99. |   ColorArea - Used to specify an area of the control that can be affected    |
  100. |               with color:                                                    |
  101. |                 background - The background color.                           |
  102. |                 foreground - The text color.                                 |
  103. |                 hilite     - The color of the hilited portion of the text    |
  104. ------------------------------------------------------------------------------*/
  105.       enum ColorArea
  106.          {
  107.          background     = 3,   // PP_BACKGROUNDCOLOR
  108.          foreground     = 1,   // PP_FOREGROUNDCOLOR
  109.          hilite         = 5    // PP_HILITEFOREGROUNDCOLOR
  110.          };
  111.  
  112. /*---------------------------------- Color -------------------------------------
  113. | These functions set and query the color of the control:                      |
  114. |   setColor  - Sets the specified color of the control.                       |
  115. |   color     - Returns the specified color of the control.                    |
  116. ------------------------------------------------------------------------------*/
  117.       NewControl &setColor(ColorArea area, const IColor& color);
  118.  
  119.       IColor color(ColorArea area) const;
  120.  
  121.    protected:
  122.       virtual Boolean paintWindow(IPaintEvent& evt);
  123.       virtual Boolean windowResize(IResizeEvent& evt);
  124.       virtual Boolean gainingFocus(IEvent& evt);
  125.       virtual Boolean losingFocus(IEvent& evt);
  126.       virtual Boolean mouseClicked(IMouseClickEvent& evt);
  127.  
  128.    private:
  129.       NewControl& establishColor(IColor& clr,
  130.                                  NewControl::ColorArea clrArea,
  131.                                  const IColor& defClr);
  132.  
  133.       static Style currentDefaultStyle;
  134.  
  135.       static const char* newControlClass;
  136.       static const unsigned long newControlClassStyle;
  137.  
  138.       static const char* dummyText;
  139.  
  140.       static const IColor defclrBackground;
  141.       static const IColor defclrForeground;
  142.       static const IColor defclrHilite;
  143.  
  144.       long clicks;            // number of MB1 clicks in control
  145.       long cx;                // control width in pels
  146.       long cy;                // control height in pels
  147.    };
  148.  
  149. INESTEDBITFLAGCLASSFUNCS(Style, NewControl);
  150.  
  151. // Resume compiler default packing
  152. #pragma pack()
  153.  
  154. #endif //#ifndef _NEWCTL_
  155.