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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992, 1993 by Borland International
  3. //   include\owl\gadgetwi.h
  4. //   Basic behavior for a class owning tiled gadgets.
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_GADGETWI_H)
  7. #define __OWL_GADGETWI_H
  8.  
  9. #if !defined(__OWL_WINDOW_H)
  10.   #include "owl\window.h"
  11. #endif
  12. #if !defined(__OWL_GADGET_H)
  13.   #include "owl\gadget.h"
  14. #endif
  15. #if !defined(__OWL_GDIOBJEC_H)
  16.   #include "owl\gdiobjec.h"
  17. #endif
  18.  
  19. //
  20. //  class TGadgetWindowFont
  21. //  ----- -----------------
  22. //
  23. //  specify the point size of the font (not the size in pixels) and whether it
  24. //  is bold and/or italic. you get a variable width sans serif font(typically
  25. //  Helvetica)
  26. //
  27. class _OWLCLASS TGadgetWindowFont : public TFont {
  28.   public:
  29.     TGadgetWindowFont(int  pointSize = 10,
  30.                       BOOL bold = FALSE,
  31.                       BOOL italic = FALSE);
  32. };
  33.  
  34. //
  35. //  class TGadgetWindow
  36. //  ----- -------------
  37. //
  38. //  - maintains a list of tiled Gadgets
  39. //  - you specify whether the Gadgets are tiled horizontally or vertically
  40. //  - a font that the Gadgets should use
  41. //  - you can specify left, right, top, and bottom margins. the Gadgets are
  42. //    situated within the inner rectangle (area excluding borders and
  43. //    margins). margins can be specified in pixels, layout units (based on
  44. //    the window font), or border units (width or height of a thin window
  45. //    border)
  46. //  - you can specify that the Gadget window shrink wrap itself to "fit"
  47. //    around its Gadgets in either the width or height or both (default for
  48. //    horizontally tiled Gadgets is shrink wrap height and default for
  49. //    vertically tiled Gadgets is shrink wrap width)
  50. //
  51. class _OWLCLASS TGadgetWindow : public TWindow {
  52.   public:
  53.     enum TTileDirection {Horizontal, Vertical};
  54.  
  55.     TGadgetWindow(TWindow*        parent = 0,
  56.                   TTileDirection  direction = Horizontal,
  57.                   TFont*          font = new TGadgetWindowFont,
  58.                   TModule*        module = 0);
  59.  
  60.    ~TGadgetWindow();  // deletes the font
  61.  
  62.     //
  63.     // override TWindow member function and choose initial size if shrink
  64.     // wrapping was requested
  65.     //
  66.     BOOL          Create();
  67.  
  68.     //
  69.     // changes the margins and initiates a layout session
  70.     //
  71.     void          SetMargins(TMargins& margins);
  72.  
  73.     TTileDirection GetDirection() const {return Direction;}
  74.     virtual void  SetDirection(TTileDirection direction);
  75.   
  76.     TFont&        GetFont() {return *Font;}
  77.     UINT          GetFontHeight() const {return FontHeight;}
  78.  
  79.     //
  80.     // Gadgets always get notified when a left button down occurs within their
  81.     // bounding rectangle. if you want mouse drags and a mouse up then you
  82.     // need to capture the mouse
  83.     //
  84.     BOOL          GadgetSetCapture(TGadget& gadget);     // fails if already captured
  85.     void          GadgetReleaseCapture(TGadget& gadget); // ignores other gadgets
  86.  
  87.     //
  88.     // Hint mode settings & action used by contained gadgets
  89.     //
  90.     enum THintMode {NoHints, PressHints, EnterHints};
  91.     void          SetHintMode(THintMode hintMode)  // default is PressHints
  92.                     {HintMode = hintMode;}
  93.     THintMode     GetHintMode() {return HintMode;}
  94.  
  95.     void          SetHintCommand(int id);  // -1 to clear
  96.  
  97.     enum TPlacement {Before, After};
  98.  
  99.     //
  100.     // insert a Gadget. you can specify a sibling Gadget that the new Gadget
  101.     // is to be inserted before or after
  102.     //
  103.     // if "sibling" is 0 then the new Gadget is inserted at the beginning or
  104.     // the end. the default is to insert the new Gadget at the end
  105.     //
  106.     // caller needs to also call LayoutSession() after inserting gadgets if
  107.     // this window has already been created
  108.     //
  109.     virtual void  Insert(TGadget& gadget, TPlacement = After, TGadget* sibling = 0);
  110.  
  111.     //
  112.     // removes (unlinks) a gadget from the gadget window. The gadget is
  113.     // returned but not destroyed. returns 0 if gadget is not in window
  114.     //
  115.     // caller needs to also call LayoutSession() after removing gadgets if
  116.     // this gadget window has already been created
  117.     //
  118.     virtual TGadget*  Remove(TGadget& gadget);
  119.  
  120.     //
  121.     // iterates over the Gadgets invoking their CommandEnable() member function
  122.     //
  123.     BOOL          IdleAction(long idleCount);
  124.  
  125.     //
  126.     // sent by a Gadget when its size has changed. initiates a layout session
  127.     //
  128.     void          GadgetChangedSize(TGadget& gadget);
  129.  
  130.     //
  131.     // begins a layout session
  132.     //
  133.     // default behavior is just to tiles the Gadgets
  134.     //
  135.     // typically initiated by a change in margins, adding/deleting Gadgets,
  136.     // or a Gadget changing size
  137.     //
  138.     virtual void  LayoutSession();
  139.  
  140.     //
  141.     // simply sets the corresponding member data
  142.     //
  143.     void          SetShrinkWrap(BOOL shrinkWrapWidth, BOOL shrinkWrapHeight);
  144.  
  145.     TGadget*      FirstGadget() const {return Gadgets;}
  146.     TGadget*      NextGadget(TGadget& gadget) const {return gadget.Next;}
  147.     TGadget*      GadgetFromPoint(TPoint& point) const;
  148.     TGadget*      GadgetWithId(int id) const;
  149.  
  150.   protected:
  151.     TGadget*        Gadgets;        // Linked list of gadgets
  152.     TFont*          Font;           // Font used for size calculations
  153.     TBrush*         BkgndBrush;     // background brush
  154.     TGadget*        Capture;        // Gadget that has captured the mouse
  155.     TGadget*        AtMouse;        // Last Gadget at mouse position
  156.     TMargins        Margins;
  157.     UINT            NumGadgets       : 8;
  158.     UINT            FontHeight       : 8;
  159.     BOOL            ShrinkWrapWidth  : 8;
  160.     BOOL            ShrinkWrapHeight : 8;
  161.     BOOL            WideAsPossible   : 8;
  162.     BOOL            DirtyLayout      : 8;
  163.     TTileDirection  Direction        : 8;
  164.     THintMode       HintMode         : 8;
  165.  
  166.     //
  167.     // called by Paint(). iterates over the Gadgets and asks each one to draw
  168.     //
  169.     // override this to implement a specific look (e.g. separator line,
  170.     // raised, ...)
  171.     //
  172.     virtual void  PaintGadgets(TDC& dc, BOOL erase, TRect& rect);
  173.  
  174.     //
  175.     // if shrink wrapping was requested returns the size needed to accomodate
  176.     // the borders, margins, and the widest/highest Gadget; otherwise the
  177.     // current width/height are returned
  178.     //
  179.     // override this member function if you want to leave extra room for a
  180.     // specific look (e.g. separator line, raised, ...)
  181.     //
  182.     // if you override GetDesiredSize() you will probably also need to
  183.     // override GetInnerRect()
  184.     //
  185.     virtual void  GetDesiredSize(TSize& size);
  186.  
  187.     //
  188.     // computes the area inside of the borders and margins
  189.     //
  190.     // override this if you want to leave extra room for a specific look
  191.     // (e.g. separator line, raised, ...)
  192.     //
  193.     // if you override GetInnerRect() you will probably also need to override
  194.     // GetDesiredSize()
  195.     //
  196.     virtual void  GetInnerRect(TRect& rect);
  197.  
  198.     //
  199.     // a layout unit is defined by dividing the window font "em" into 8
  200.     // vertical and 8 horizontal segments
  201.     //
  202.     int           LayoutUnitsToPixels(int units);
  203.  
  204.     //
  205.     // returns the left, right, top, and bottom margins converted to pixels
  206.     //
  207.     void          GetMargins(TMargins& margins,
  208.                              int& left, int& right, int& top, int& bottom);
  209.  
  210.     //
  211.     // tiles the Gadgets in the direction requested (horizontal or vertical)
  212.     //
  213.     // calls member function PositionGadget() to allow derived classes an
  214.     // opportunity to adjust the spacing between Gadgets
  215.     //
  216.     virtual TRect TileGadgets();
  217.  
  218.     //
  219.     // selects the font into the DC and calls PaintGadgets()
  220.     //
  221.     void          Paint(TDC& dc, BOOL erase, TRect& rect);
  222.  
  223.     virtual void  PositionGadget(TGadget* previous, TGadget* next, TPoint& point);
  224.  
  225.     //
  226.     // message response functions
  227.     //
  228.     void          EvLButtonDown(UINT modKeys, TPoint& point);
  229.     void          EvLButtonUp(UINT modKeys, TPoint& point);
  230.     void          EvMouseMove(UINT modKeys, TPoint& point);
  231.     HBRUSH        EvCtlColor(HDC hDC, HWND /*hWndChild*/, UINT /*ctlType*/);
  232.     void          EvSize(UINT sizeType, TSize& size);
  233.     void          EvSysColorChange();
  234.  
  235.   private:
  236.     TRect         TileHorizontally();
  237.     TRect         TileVertically();
  238.  
  239.     friend class TGadget;
  240.  
  241.     //
  242.     // hidden to prevent accidental copying or assignment
  243.     //
  244.     TGadgetWindow(const TGadgetWindow&);
  245.     TGadgetWindow& operator =(const TGadgetWindow&);
  246.  
  247.   DECLARE_RESPONSE_TABLE(TGadgetWindow);
  248.   DECLARE_CASTABLE;
  249. };
  250.  
  251. #endif  // __OWL_GADGETWI_H
  252.