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

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