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

  1. #ifndef _IPUSHBUT_
  2.   #define _IPUSHBUT_
  3. /*******************************************************************************
  4. * FILE NAME: ipushbut.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *    IPushbutton - This class creates and manages the pushbutton control window.*
  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 _IBUTTON_
  19.   #include <ibutton.hpp>
  20. #endif
  21.  
  22. // Forward declarations for other classes:
  23. class IRectangle;
  24. class ISize;
  25. class IWindowHandle;
  26. #ifndef _IRECT_
  27.   #include <irect.hpp>
  28. #endif
  29. #ifndef _IBITFLAG_
  30.   #include <ibitflag.hpp>
  31. #endif
  32.  
  33. /*----------------------------------------------------------------------------*/
  34. /* Align classes on four byte boundary.                                       */
  35. /*----------------------------------------------------------------------------*/
  36. #pragma pack(4)
  37.  
  38.  
  39. class IPushButton : public IButton  {
  40. typedef IButton Inherited;
  41. /*******************************************************************************
  42. * The IPushButton class creates and manages the push button control window.    *
  43. * The standard push button generates an ICommandEvent.  However, the           *
  44. * application can change the window style value to generate a help event or    *
  45. * system command event.  To change the push button event (message) processing, *
  46. * call the IPushButton::enableHelp and IPushButton::enableSystemCommand        *
  47. * functions.  These functions add or remove the IPushButton::help and          *
  48. * IPushButton::systemCommand styles, respectively.                             *                                   *
  49. *                                                                              *
  50. * If the push button was not created from a dialog template, then the          *
  51. * application is responsible for processing the Enter key and calling the      *
  52. * push button's inherited click function.                                      *
  53. *                                                                              *
  54. * EXAMPLE:                                                                     *
  55. *   IPushButton pbCancel(ID_CANCEL, this, this, IRectangle(10,10,80,22));      *
  56. *   pbCancel.setText("Cancel");                                                *
  57. *******************************************************************************/
  58. public:
  59. /*------------------- Style -----------------------------------------------
  60.   The following functions provide a means to set and query push button styles:
  61.  
  62.     Style - Nested class that provides static members that define the set of
  63.             valid push button styles.  These styles can be used in
  64.             conjunction with the styles defined by the nested classes
  65.             IWindow::Style, IControl::Style, and IButton::Style.  For
  66.             example, you could define an instance of the IPushButton::Style
  67.             class and initialize it like:
  68.               IPushButton::Style
  69.                 style = IPushButton::help | IControl::tabStop;
  70.             An object of this type is provided when the push button is
  71.             created.  A customizable default is used if no styles are
  72.             specified.  Once the object is constructed, IPushButton,
  73.             IWindow, IControl, and IButton member functions can be used to
  74.             set or query the object's style.
  75.  
  76.             The declaration of the IPushButton::Style nested class is
  77.             generated by the INESTEDBITFLAGCLASSDEF3 macro.
  78.  
  79.   The valid push button styles are:
  80.     classDefaultStyle - Original default style for this class, which is
  81.                         IWindow::visible.
  82.     help              - Causes a help event, instead of a command event, to
  83.                         be generated when the push button is pressed.
  84.     systemCommand     - Causes a system command event, instead of a command
  85.                         event, to be generated when the push button is
  86.                         pressed.
  87.     defaultButton     - Making a push button the default allows it to be
  88.                         selected with the Enter key without having the cursor
  89.                         on the push button.  Visually, a default push button
  90.                         has a darker and thicker border.
  91.     noBorder          - The push button will be displayed without a border
  92.                         around itself.
  93.  
  94.   The following functions provide a means of getting and setting the default
  95.   style for this class:
  96.     defaultStyle    - Returns the current default style.  This is the same as
  97.                       classDefaultStyle unless setDefaultStyle has been
  98.                       called.
  99.     setDefaultStyle - Sets the default style for all subsequent push buttons.
  100. -------------------------------------------------------------------------*/
  101. INESTEDBITFLAGCLASSDEF3(Style, IPushButton, IWindow,
  102.                         IControl, IButton);
  103.                                   // style class definition
  104. static const Style
  105.   classDefaultStyle,
  106.   help,
  107.   systemCommand,
  108.   defaultButton,
  109.   noBorder;
  110.  
  111. static Style
  112.   defaultStyle();
  113. static void
  114.   setDefaultStyle(Style style);
  115.  
  116. /*------------------------ Constructors ----------------------------------------
  117. | You can construct instances of this class in the following ways:             |
  118. |    - From a control ID, parent and owner windows, rectangle, and style.      |
  119. |      This creates the specified push button control and an object for it.    |
  120. |    - From the ID of a push button control on a dialog window.  This creates  |
  121. |      the object for the specified push button control.                       |
  122. |    - From the window handle of an existing push button control.  This        |
  123. |      creates the object for the specified push button control.               |
  124. ------------------------------------------------------------------------------*/
  125.   IPushButton(unsigned long id,
  126.               IWindow* parent,
  127.               IWindow* owner,
  128.               const IRectangle& initial= IRectangle(),
  129.               const Style& style = defaultStyle() );
  130.  
  131.   IPushButton(unsigned long id,
  132.               IWindow* parentDialog);
  133.  
  134.   IPushButton(const IWindowHandle& handle);
  135.  
  136.   virtual ~IPushButton();
  137.  
  138. /*-------------------------------- Style Functions -----------------------------
  139. | These functions provide a means of getting and setting the default style     |
  140. | attributes of instances of this class:                                       |
  141. |   isDefault            - Returns true if the defaultButton style is set.     |
  142. |   enableDefault        - Adds or removes the defaultButton style.            |
  143. |   disableDefault       - Removes the defaultButton style from the push       |
  144. |                          button.                                             |
  145. |   isHelp               - Returns true if the help style is set.              |
  146. |   enableHelp           - Adds or removes the help style.                     |
  147. |   disableHelp          - Removes the help style from the push button.        |
  148. |   isSystemCommand      - Returns true if the systemCommand style is set.     |
  149. |   enableSystemCommand  - Adds or removes the systemCommand style.            |
  150. |   disableSystemCommand - Removes the systemCommand style from the push       |
  151. |                          button.                                             |
  152. |   isBorder             - Returns true if the push button has a border.       |
  153. |   enableBorder         - Adds or removes the push button border.             |
  154. |   disableBorder        - Removes the border from the push button.  This also |
  155. |                          prevents the background of the push button from     |
  156. |                          being drawn with the color that is currently set    |
  157. |                          for background drawing.                             |
  158. ------------------------------------------------------------------------------*/
  159. Boolean
  160.   isDefault() const,
  161.   isHelp() const,
  162.   isSystemCommand() const,
  163.   isBorder() const;
  164. IPushButton
  165.   &enableDefault(Boolean enable=true),
  166.   &disableDefault(),
  167.   &enableHelp(Boolean enable=true),
  168.   &disableHelp(),
  169.   &enableSystemCommand(Boolean enable=true),
  170.   &disableSystemCommand(),
  171.   &enableBorder(Boolean enable=true),
  172.   &disableBorder();
  173.  
  174. protected:
  175. /*----------------------------- Layout Size ------------------------------------
  176. | calcMinimumSize - Returns the recommended minimum size of this push button   |
  177. |                   control.  The size is based on the text string length and  |
  178. |                   the current font.                                          |
  179. ------------------------------------------------------------------------------*/
  180. virtual ISize
  181.   calcMinimumSize() const;
  182.  
  183.  
  184. private:
  185. /*--------------------------------- PRIVATE ----------------------------------*/
  186.   IPushButton(const IPushButton&);
  187.   IPushButton& operator=(const IPushButton&);
  188. static Style
  189.   currentDefaultStyle;
  190. };  // class IPushButton
  191.  
  192. INESTEDBITFLAGCLASSFUNCS(Style, IPushButton);
  193.                                   // global style functions
  194.  
  195. /*----------------------------------------------------------------------------*/
  196. /* Resume compiler default packing.                                           */
  197. /*----------------------------------------------------------------------------*/
  198. #pragma pack()
  199.  
  200. #endif  // _IPUSHBUT_
  201.