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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992, 1993 by Borland International
  3. //   include\owl\gadget.h
  4. //   Base class TGadget and helper class TSeparatorGadget.
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_GADGET_H)
  7. #define __OWL_GADGET_H
  8.  
  9. #if !defined(__OWL_WINDOW_H)
  10.   #include "owl\window.h"
  11. #endif
  12. #if !defined(__OWL_DC_H)
  13.   #include "owl\dc.h"
  14. #endif
  15.  
  16. class _OWLCLASS TGadgetWindow;
  17.  
  18. //
  19. //  struct TMargins
  20. //  ------ --------
  21. //
  22. //  Used by class TGadgetWindow and class TGadget.
  23. //
  24. struct TMargins {
  25.   enum TUnits {Pixels, LayoutUnits, BorderUnits};
  26.  
  27.   TUnits  Units;
  28.  
  29.   int  Left   : 8;
  30.   int  Right  : 8;
  31.   int  Top    : 8;
  32.   int  Bottom : 8;
  33.  
  34.   TMargins() {Units = LayoutUnits; Left = Right = Top = Bottom = 0;}
  35. };
  36.  
  37. //
  38. //  class TGadget
  39. //  ----- -------
  40. //
  41. //  gadgets have borders and margins, belong to a gadget window, and have
  42. //  their own coordinate system
  43. //
  44. //  margins are the same as for TGadgetWindow and borders are always in
  45. //  border units
  46. //
  47. //  default behavior for gadgets is to shrink wrap to "fit" around their contents
  48. //  you can control this by setting "ShrinkWrapWidth" and "ShrinkWrapHeight"
  49. //
  50. class _OWLCLASS TGadget {
  51.   public:
  52.     enum TBorderStyle {None, Plain, Raised, Recessed, Embossed};
  53.  
  54.     TGadget(int id = 0, TBorderStyle = None);
  55.     virtual ~TGadget();
  56.  
  57.     struct TBorders {
  58.       unsigned  Left   : 4;
  59.       unsigned  Right  : 4;
  60.       unsigned  Top    : 4;
  61.       unsigned  Bottom : 4;
  62.  
  63.       TBorders() {Left = Right = Top = Bottom = 0;}
  64.     };
  65.  
  66.     int            GetId () {return Id;}
  67.  
  68.     //
  69.     // typically you would either choose a border style (which automatically
  70.     // sets the individual border edges) or set the borders and then override
  71.     // member function PaintBorder() to create a custom look
  72.     //
  73.     // NOTE: changing the borders, margins, or border style all end up invoking
  74.     //       the gadget window's GadgetChangedSize() member function
  75.     //
  76.     void           SetBorders(TBorders& borders);
  77.     TBorders      &GetBorders() {return Borders;}
  78.  
  79.     void           SetMargins(TMargins& margins);
  80.     TMargins      &GetMargins() {return Margins;}
  81.  
  82.     void           SetBorderStyle(TBorderStyle);
  83.     TBorderStyle   GetBorderStyle() {return BorderStyle;}
  84.  
  85.     TRect         &GetBounds() {return Bounds;}
  86.  
  87.     virtual void   SetEnabled(BOOL);
  88.     BOOL           GetEnabled() {return Enabled;}
  89.  
  90.     //
  91.     // simply sets the corresponding member data. call the gadget window's
  92.     // GadgetChangedSize() member function if you want to affect a change in size
  93.     //
  94.     void           SetShrinkWrap(BOOL shrinkWrapWidth, BOOL shrinkWrapHeight);
  95.  
  96.     //
  97.     // directly alters the size of the gadget. calls the gadget window's
  98.     // GadgetChangedSize() member function for the size change to take affect
  99.     //
  100.     // you would only use this member function if you turned off shrink wrapping
  101.     // in one or both dimension; otherwise the GetDesiredSize() member function
  102.     // will return the fitted size which will be different
  103.     //
  104.     void           SetSize(TSize& size);
  105.  
  106.     //
  107.     // message send by the gadget window to query the gadget's size.
  108.     // if shrink wrapping was requested just returns the size needed to
  109.     // accomodate the borders and margins; otherwise the current width/height
  110.     // are returned
  111.     //
  112.     // if you requested "WideAsPossible" then "size.cx" is ignored
  113.     //
  114.     virtual void   GetDesiredSize(TSize& size);
  115.  
  116.     //
  117.     // returns the amount of space in pixels taken up by the borders and margins
  118.     //
  119.     void           GetOuterSizes(int& left, int& right, int& top, int& bottom);
  120.  
  121.     //
  122.     // sent by the gadget window to inform the gadget of a change in its
  123.     // bounding rectangle. default behavior just updates instance variable
  124.     // "Bounds" but derived classes might override this method to update
  125.     // internal state
  126.     //
  127.     virtual void   SetBounds(TRect& rect);
  128.  
  129.     virtual void   CommandEnable();
  130.     virtual void   SysColorChange();
  131.  
  132.     TGadget       *NextGadget() {return Next;}
  133.  
  134.   protected:
  135.     //
  136.     // Virtuals called after inserting into window & before removing to allow
  137.     // gadget a change to initialize or clean up.
  138.     //
  139.     virtual void   Inserted();
  140.     virtual void   Removed();
  141.     
  142.     void           Invalidate(BOOL erase = TRUE);
  143.     void           InvalidateRect(const TRect& rect,  // receiver's coord system
  144.                                   BOOL  erase = TRUE);
  145.     void           Update();  // Paint now if possible
  146.  
  147.     //
  148.     // default behavior returns TRUE if the point is within the receiver's
  149.     // bounding rect. "point" is in the receiver's coordinate system
  150.     //
  151.     virtual BOOL   PtIn(TPoint& point);
  152.  
  153.     virtual void   Paint(TDC& dc);
  154.  
  155.     //
  156.     // self sent by method Paint(). override this is if you want to
  157.     // implement a border style that isn't supported
  158.     //
  159.     virtual void   PaintBorder(TDC& dc);
  160.  
  161.     //
  162.     // computes the area excluding the borders and margins
  163.     //
  164.     void           GetInnerRect(TRect& rect);
  165.  
  166.     //
  167.     // "point" is in the receiver's coordinate system. MouseMove is only 
  168.     // called if the mouse is captured.
  169.     //
  170.     virtual void   MouseMove(UINT modKeys, TPoint& point);
  171.     virtual void   MouseEnter(UINT modKeys, TPoint& point);
  172.     virtual void   MouseLeave(UINT modKeys, TPoint& point);
  173.  
  174.     //
  175.     // captures the mouse if "TrackMouse" is set. "point" is in the receiver's
  176.     // coordinate system
  177.     //
  178.     virtual void   LButtonDown(UINT modKeys, TPoint& point);
  179.  
  180.     //
  181.     // releases the mouse capture if "TrackMouse" is set. "point" is in the
  182.     // receiver's coordinate system
  183.     //
  184.     virtual void   LButtonUp(UINT modKeys, TPoint& point);
  185.  
  186.   public:
  187.     BOOL             Clip;            // FALSE
  188.     BOOL             WideAsPossible;  // FALSE
  189.  
  190.   protected:
  191.     TGadgetWindow*   Window;
  192.     TRect            Bounds;
  193.     TBorderStyle     BorderStyle;
  194.     TBorders         Borders;
  195.     TMargins         Margins;
  196.     BOOL             ShrinkWrapWidth;
  197.     BOOL             ShrinkWrapHeight;
  198.     BOOL             TrackMouse;      // FALSE
  199.     int              Id;
  200.  
  201.   private:
  202.     TGadget*         Next;
  203.     BOOL             Enabled;
  204.  
  205.     friend class _OWLCLASS TGadgetWindow;
  206.  
  207.     //
  208.     // hidden to prevent accidental copying or assignment
  209.     //
  210.     TGadget(const TGadget&);
  211.     TGadget& operator =(const TGadget&);
  212. };
  213.  
  214. //
  215. //  class TSeparatorGadget
  216. //  ----- ----------------
  217. //
  218. //  simple helper class that you can use when you want a separator between
  219. //  gadgets. you specify the size of the separator (in units of SM_CXBORDER
  220. //  and SM_CYBORDER) and the separator disables itself and turns off shrink
  221. //  wrapping
  222. //
  223. //  "size" is used for both the width and the height
  224. //
  225. class _OWLCLASS TSeparatorGadget : public TGadget {
  226.   public:
  227.     TSeparatorGadget(int size = 6);
  228. };
  229.  
  230. #endif  // __OWL_GADGET_H
  231.