home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / BUTTONGA.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  4.3 KB  |  139 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992, 1993 by Borland International
  3. //   include\owl\buttonga.h
  4. //   Base class TButtonGadget.
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_BUTTONGA_H)
  7. #define __OWL_BUTTONGA_H
  8.  
  9. #if !defined(__OWL_GADGET_H)
  10.   #include "owl\gadget.h"
  11. #endif
  12. class _OWLCLASS TCelArray;
  13.  
  14. //
  15. //  class TButtonGadget
  16. //  ----- -------------
  17. //
  18. //  buttons begin highlighting and do a capture when pressed (the mouse down
  19. //  occurs). they cancel highlighting when the mouse exits, but begin
  20. //  highlighting again when the mouse re-enters. when the mouse goes up the
  21. //  capture is released
  22. //
  23. //  there are two basic type of buttons: commands and settings (attribute
  24. //  buttons). Settings can be exclusive (like a radio button) or non-exclusive
  25. //  (like a check box)
  26. //
  27. //  there are three normal button states: up, down, and indeterminate. in
  28. //  addition the button can be highlighting (pressed) in all three states
  29. //
  30. //  commands can only be in the "up" state. settings can be in all three states
  31. //
  32. class _OWLCLASS TButtonGadget : public TGadget {
  33.   public:
  34.     enum TState {Up, Down, Indeterminate};
  35.     enum TType {Command, Exclusive, NonExclusive};
  36.     enum TShadowStyle {SingleShadow = 1, DoubleShadow = 2};
  37.  
  38.     TButtonGadget(TResId bmpResId,
  39.                   int    id,
  40.                   TType  type = Command,
  41.                   BOOL   enabled = FALSE, // initial state before cmd enabling
  42.                   TState state = Up,
  43.                   BOOL   repeat = FALSE);
  44.    ~TButtonGadget();
  45.  
  46.     void          SetButtonState(TState);
  47.     TState        GetButtonState() {return State;}
  48.  
  49.     TType         GetButtonType() {return Type;}
  50.  
  51.     //
  52.     // a couple of button style options
  53.     //
  54.     void          SetNotchCorners(BOOL notchCorners=TRUE)
  55.                     {NotchCorners = notchCorners;}
  56.     void          SetShadowStyle(TShadowStyle style=DoubleShadow);
  57.     void          SetAntialiasEdges(BOOL anti=TRUE) {AntialiasEdges=anti;}
  58.  
  59.     //
  60.     // override and initiate a WM_COMMAND_ENABLE message
  61.     //
  62.     void          CommandEnable();
  63.  
  64.     void          SysColorChange();
  65.  
  66.   protected:
  67.     TResId        ResId;
  68.     TCelArray*    CelArray;
  69.     TPoint        BitmapOrigin;
  70.     TState        State          : 4;
  71.     TType         Type           : 4;
  72.     TShadowStyle  ShadowStyle    : 4;
  73.     BOOL          Repeat         : 1;
  74.     BOOL          NotchCorners   : 1;
  75.     BOOL          Pressed        : 1;
  76.     BOOL          AntialiasEdges : 1;
  77.  
  78.     //
  79.     // overrive basic TGadget member functions
  80.     //
  81.     void          GetDesiredSize(TSize& size);
  82.     void          Paint(TDC& dc);
  83.     void          Invalidate();
  84.     void          SetBounds(TRect& r);
  85.  
  86.     //
  87.     // override TGadget member functions and respond to user fiddling with the
  88.     // button by self-sending button protocol messages
  89.     //
  90.     void          LButtonDown(UINT modKeys, TPoint& p);
  91.     void          MouseMove(UINT modKeys, TPoint& p);
  92.     void          MouseEnter(UINT modKeys, TPoint& p);
  93.     void          MouseLeave(UINT modKeys, TPoint& p);
  94.     void          LButtonUp(UINT modKeys, TPoint& p);
  95.  
  96.     enum {
  97.       //CelMask,
  98.       CelNormal,
  99.       CelDisabled,
  100.       CelIndeterm,
  101.       CelDown,
  102.       CelsTotal
  103.     };
  104.     virtual TDib* GetGlyphDib();
  105.     virtual void  ReleaseGlyphDib(TDib* glyph);
  106.     virtual void  BuildCelArray();
  107.     
  108.     //
  109.     // button protocol
  110.     // ------ --------
  111.     //
  112.  
  113.     //
  114.     // invoked by mouse-down & mouse enter events. sets member data "Pressed"
  115.     // to TRUE and highlights the button
  116.     //
  117.     virtual void  BeginPressed(TPoint& p);
  118.  
  119.     //
  120.     // invoked by mouse exit events. sets member data "Pressed" to FALSE and
  121.     // paints the button in its current state
  122.     //
  123.     virtual void  CancelPressed(TPoint& p);
  124.  
  125.     //
  126.     // invoked by mouse-up event inside the Gadget. sets member data "Pressed"
  127.     // to FALSE, changes state for attribute buttons, and paints the button
  128.     // in its current state
  129.     //
  130.     // generates WM_COMMAND
  131.     //
  132.     virtual void  Activate(TPoint& p);
  133.  
  134.   private:
  135.     void          CheckExclusively();
  136. };
  137.  
  138. #endif  // __OWL_BUTTONGA_H
  139.