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

  1. #ifndef _IGRAPHBT_
  2.   #define _IGRAPHBT_
  3. /*******************************************************************************
  4. * FILE NAME: igraphbt.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *    IGraphicPushButton - This class creates and manages the graphic push button*
  9. *                         control window.                                      *
  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. *******************************************************************************/
  19. #ifndef _IPUSHBUT_
  20.   #include <ipushbut.hpp>
  21. #endif
  22. #ifndef _IRECT_
  23.   #include <irect.hpp>
  24. #endif
  25. #ifndef _IBITFLAG_
  26.   #include <ibitflag.hpp>
  27. #endif
  28.  
  29. /*----------------------------------------------------------------------------*/
  30. /* Align classes on four byte boundary.                                       */
  31. /*----------------------------------------------------------------------------*/
  32. #pragma pack(4)
  33.  
  34.  
  35. // Forward declarations for other classes:
  36. class IRectangle;
  37. class ISize;
  38. class IWindowHandle;
  39. class IIconControl;
  40.  
  41.  
  42. class IGraphicPushButton : public IPushButton  {
  43. typedef IPushButton Inherited;
  44. /*******************************************************************************
  45. * The IGraphicPushButton class creates and manages the graphic push button     *
  46. * control window.  The standard push button generates an ICommandEvent.        *
  47. * However, the application can change the window style value to generate a     *
  48. * help event or system command event.  To change the push button event         *
  49. * (message) processing, call the IPushButton::enableHelp and                   *
  50. * IPushButton::enableSystemCommand functions.  These functions add or remove   *
  51. * the IPushButton::help and IPushButton::systemCommand styles, respectively.   *
  52. *                                                                              *
  53. * If the graphic push button is not created from a dialog template, the        *
  54. * application is responsible for processing the Enter key and calling the      *
  55. * push button's inherited IButton::click function.                             *
  56. *                                                                              *
  57. * EXAMPLE:                                                                     *
  58. *   IGraphicPushButton pbCancel(ID_CANCEL, this, this, ID_SOMEBMP,             *
  59. *                           IRectangle(10,10,80,22));                          *
  60. *******************************************************************************/
  61. public:
  62. /*------------------- Style -----------------------------------------------
  63.   The following functions provide a means to set and query graphic push button styles:
  64.  
  65.     Style - Nested class that provides static members that define the set of
  66.             valid graphic button styles.  These styles can be used in
  67.             conjunction with the styles defined by the nested classes
  68.             IWindow::Style, IControl::Style, IButton::Style, and
  69.             IPushButton::Style.  For example, you could define an instance
  70.             of the igraphbtton::Style class and initialize it like:
  71.               IGraphicPushButton::Style
  72.                 style = IGraphicPushButton::sizeToGraphic | IPushButton::help |
  73.                         IControl::tabStop;
  74.             An object of this type is provided when the graphic push button
  75.             is created.  A customizable default is used if no styles are
  76.             specified.  Once the object is constructed, igraphbtton,
  77.             IWindow, IControl, IButton, and IPushButton member functions
  78.             can be used to set or query the object's style.
  79.  
  80.             The declaration of the IGraphicPushButton::Style nested class is
  81.             generated by the INESTEDBITFLAGCLASSDEF4 macro.
  82.  
  83.   The valid push button styles are:
  84.     classDefaultStyle - Original default style for this class, which is
  85.                         IWindow::visible.
  86.     sizeToGraphic     - This style causes the graphic inside of the push
  87.                         button to be displayed using the graphic's actual
  88.                         size.  If the graphic is larger than the push button,
  89.                         it is clipped.  If the graphic is smaller than the
  90.                         push button, it is centered in the push button.
  91.                         If you do not use this style, the graphic is stretched
  92.                         to fill the push button up to its border.
  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 graphic push
  100.                       buttons.
  101. -------------------------------------------------------------------------*/
  102. INESTEDBITFLAGCLASSDEF4(Style, IGraphicPushButton, IWindow,
  103.                         IControl, IButton, IPushButton);
  104.                                   // style class definition
  105. static const Style
  106.   classDefaultStyle,
  107.   sizeToGraphic;
  108.  
  109. static Style
  110.   defaultStyle();
  111. static void
  112.   setDefaultStyle(Style style);
  113.  
  114. /*------------------------ Constructors ----------------------------------------
  115. | You can construct instances of this class in the following ways:             |
  116. |    - From a non-system icon or bit map.  This creates a graphic push button  |
  117. |      with the specified window ID, parent and owner windows, screen position |
  118. |      and size, resource library with its specified icon or bit map ID, and   |
  119. |      window style.  Use this constructor if you have not already loaded the  |
  120. |      bit map or icon and you want to load it from the .dll or .exe of your   |
  121. |      choice.                                                                 |
  122. |    - From a non-system icon or bit map.  This creates a graphic push button  |
  123. |      with the specified window ID, parent and owner windows, screen position |
  124. |      and size, default resource library with its specified icon or bit map   |
  125. |      ID, and window style.  Use this constructor if you have not already     |
  126. |      loaded the bit map or icon, and you want to load it from the default    |
  127. |      resource library, which would be from the .exe.                         |
  128. |    - From a non-system bit map.  This creates a graphic push button with the |
  129. |      specified window ID, parent and owner windows, screen position and      |
  130. |      size, bit map, and window style.  If you already have a bit map handle, |
  131. |      use this contructor to put it on the graphic push button.               |
  132. |    - From a non-system icon.  This creates a graphic push button with the    |
  133. |      specified window ID, parent and owner windows, screen position and      |
  134. |      size, icon, and window style.  If you already have an icon handle,      |
  135. |      use this constructor to put it on a graphic push button.                |
  136. |    - From a dialog template.  This creates a graphic push button object for  |
  137. |      the specified push button that has the icon or bit map style from the   |
  138. |      dialog control.                                                         |
  139. |    - From an existing icon control.  This creates a graphic push button      |
  140. |      object for the specified bit map or icon push button window handle.     |
  141. ------------------------------------------------------------------------------*/
  142.   IGraphicPushButton(unsigned long id,
  143.               IWindow* parent,
  144.               IWindow* owner,
  145.               const IResourceId& bitmapOrIconId,
  146.               const IRectangle& initial= IRectangle(),
  147.               const Style& style = defaultStyle() );
  148.  
  149.   IGraphicPushButton(unsigned long id,
  150.               IWindow* parent,
  151.               IWindow* owner,
  152.               unsigned long bitmapOrIconId,
  153.               const IRectangle& initial= IRectangle(),
  154.               const Style& style = defaultStyle() );
  155.  
  156.   IGraphicPushButton(unsigned long id,
  157.               IWindow* parent,
  158.               IWindow* owner,
  159.               const IBitmapHandle& bitmap = IBitmapHandle(),
  160.               const IRectangle& initial= IRectangle(),
  161.               const Style& style = defaultStyle() );
  162.  
  163.   IGraphicPushButton(unsigned long id,
  164.               IWindow* parent,
  165.               IWindow* owner,
  166.               const IPointerHandle& icon,
  167.               const IRectangle& initial= IRectangle(),
  168.               const Style& style = defaultStyle() );
  169.  
  170.   IGraphicPushButton(unsigned long id,
  171.               IWindow* parentDialog);
  172.  
  173.   IGraphicPushButton(const IWindowHandle& handle);
  174.  
  175.   virtual ~IGraphicPushButton();
  176.  
  177. /*------------------------------- Enumerations ---------------------------------
  178. | The following enumerations are defined:                                      |
  179. |   GraphicType - Used to query the current type of graphic set into the       |
  180. |                 graphic push button:                                         |
  181. |                 bitmapType - A bit map has been set into the graphic push    |
  182. |                              button.  This is the default value since an     |
  183. |                              IBitmapHandle is the default graphic if no      |
  184. |                              handle or resource ID was passed in.            |
  185. |                 iconType   - An icon has been set into the graphic push      |
  186. |                              button.                                         |
  187. ------------------------------------------------------------------------------*/
  188. enum GraphicType {
  189.   bitmapType,
  190.   iconType
  191. };
  192. /*-------------------------------- Query/Set Handle ----------------------------
  193. |   setGraphic         - Changes the stored graphic to the passed in value.    |
  194. |                        See the definitions of the constructors for           |
  195. |                        information about the passed in values.               |
  196. |   bitmap             - Returns the handle of the currently set bit map.  If  |
  197. |                        no bit map has been set into the graphic push button, |
  198. |                        this returns IBitmapHandle().                         |
  199. |   icon               - Returns the handle of the currently set icon.  If no  |
  200. |                        icon has been set into the graphic push button, this  |
  201. |                        returns IIconHandle().                                |
  202. |   currentGraphicType - Returns the enumerator for the current type of        |
  203. |                        graphic set into the graphic push button.             |
  204. |   graphicWindow      - Returns the IIconControl that is used for drawing the |
  205. |                        graphic.                                              |
  206. ------------------------------------------------------------------------------*/
  207. IGraphicPushButton
  208.   &setGraphic( unsigned long bitmapOrIconId ),
  209.   &setGraphic( const IResourceId&  bitmapOrIconId ),
  210.   &setGraphic( const IBitmapHandle& handle ),
  211.   &setGraphic( const IPointerHandle& handle);
  212. IPointerHandle
  213.   icon       ( ) const;
  214. IBitmapHandle
  215.   bitmap     ( ) const;
  216. GraphicType
  217.   currentGraphicType ( ) const;
  218. IIconControl&
  219.   graphicWindow() const;
  220.  
  221. /*-------------------------------- Style Functions -----------------------------
  222. |   enableSizeToGraphic  - Adds or removes the sizeToGraphic style.            |
  223. |   disableSizeToGraphic - Removes the sizeToGraphic style.                    |
  224. |   isSizeToGraphic      - Returns true if the sizeToGraphic style is set.     |
  225. ------------------------------------------------------------------------------*/
  226. IGraphicPushButton
  227.   &enableSizeToGraphic( Boolean enable = true),
  228.   &disableSizeToGraphic();
  229. Boolean
  230.   isSizeToGraphic() const;
  231.  
  232.  
  233. protected:
  234. /*----------------------------- Layout Size ------------------------------------
  235. | calcMinimumSize - The size is based on the actual size of the stored graphic.|
  236. ------------------------------------------------------------------------------*/
  237. virtual ISize
  238.   calcMinimumSize() const;
  239.  
  240.  
  241. private:
  242. /*--------------------------------- PRIVATE ----------------------------------*/
  243.   IGraphicPushButton(const IGraphicPushButton&);
  244.   IGraphicPushButton& operator=(const IGraphicPushButton&);
  245.  
  246. IGraphicPushButton
  247.   &initialize(const Style& style,
  248.               const IRectangle& initial),
  249.   &setControlData(IHandle handle);
  250.  
  251. static Style
  252.   currentDefaultStyle;
  253.  
  254. IIconControl*
  255.   aIcon;
  256. Boolean
  257.   bSizeTo,
  258.   returnBack;
  259. GraphicType
  260.   contains;
  261. };  // class IGraphicPushButton
  262.  
  263. INESTEDBITFLAGCLASSFUNCS(Style, IGraphicPushButton);
  264.                                   // global style functions
  265.  
  266. /*----------------------------------------------------------------------------*/
  267. /* Resume compiler default packing.                                           */
  268. /*----------------------------------------------------------------------------*/
  269. #pragma pack()
  270.  
  271. #endif  // _IGRAPHBT_
  272.