home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / GADGET.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  7KB  |  233 lines

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