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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992, 1993 by Borland International
  3. //   include\owl\layoutco.h
  4. //   Declaration of class TLayoutConstraint.
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_LAYOUTCO_H)
  7. #define __OWL_LAYOUTCO_H
  8.  
  9. #if !defined(__OWL_OWLDEFS_H)
  10.   #include <owl\owldefs.h>
  11. #endif
  12. class _OWLCLASS TWindow;
  13.  
  14. #define lmParent    0
  15.  
  16. enum TEdge {lmLeft, lmTop, lmRight, lmBottom, lmCenter};
  17. enum TWidthHeight {lmWidth = lmCenter + 1, lmHeight};
  18.  
  19. enum TMeasurementUnits {lmPixels, lmLayoutUnits};
  20.  
  21. enum TRelationship {lmAsIs      = 0,
  22.                     lmPercentOf = 1,
  23.                     lmAbove     = 2, lmLeftOf = lmAbove,
  24.                     lmBelow     = 3, lmRightOf = lmBelow,
  25.                     lmSameAs    = 4,
  26.                     lmAbsolute  = 5};
  27.  
  28. //
  29. //  struct TLayoutConstraint
  30. //  ------ -----------------
  31. //
  32. //  layout constraints are specified as a relationship between an edge/size
  33. //  of one window and an edge/size of one of the window's siblings or parent
  34. //
  35. //  it is acceptable for a window to have one of its sizes depend on the
  36. //  size of the opposite dimension (e.g. width is twice height)
  37. //
  38. //  distances can be specified in either pixels or layout units
  39. //
  40. //  a layout unit is defined by dividing the font "em" quad into 8 vertical
  41. //  and 8 horizontal segments. we get the font by self-sending WM_GETFONT
  42. //  (we use the system font if WM_GETFONT returns 0)
  43. //
  44. //  "lmAbove", "lmBelow", "lmLeftOf", and "lmRightOf" are only used with edge
  45. //  constraints. they place the window 1 pixel to the indicated side(i.e.
  46. //  adjacent to the other window) and then adjust it by "Margin"(e.g. above
  47. //  window "A" by 6)
  48. //
  49. //  NOTE: "Margin" is either added to ("lmAbove" and "lmLeftOf") or subtracted
  50. //        from("lmBelow" and "lmRightOf") depending on the relationship
  51. //
  52. //  "lmSameAs" can be used with either edges or sizes, and it doesn't offset
  53. //  by 1 pixel like the above four relationships did. it also uses "Value"
  54. //  (e.g. same width as window "A" plus 10)
  55. //
  56. //  NOTE: "Value" is always *added*. use a negative number if you want the
  57. //        effect to be subtractive
  58. //
  59. struct TLayoutConstraint {
  60.   TWindow*           RelWin;            // relative window, lmParent for parent
  61.  
  62.   UINT               MyEdge       : 4;  // edge or size (width/height)
  63.   TRelationship      Relationship : 4;
  64.   TMeasurementUnits  Units        : 4;
  65.   UINT               OtherEdge    : 4;  // edge or size (width/height)
  66.  
  67.   //
  68.   // this union is just for naming convenience
  69.   //
  70.   union {
  71.     int  Margin;   // used for "lmAbove", "lmBelow", "lmLeftOf", "lmRightOf"
  72.     int  Value;    // used for "lmSameAs" and "lmAbsolute"
  73.     int  Percent;  // used for "lmPercentOf"
  74.   };
  75. };
  76.  
  77. //
  78. //  struct TEdgeConstraint
  79. //  ------ ---------------
  80. //
  81. //  adds member functions for setting edge constraints
  82. //
  83. struct TEdgeConstraint : public TLayoutConstraint {
  84.   //
  85.   // for setting arbitrary edge constraints. use it like this:
  86.   //   metrics->X.Set(lmLeft, lmRightOf, lmParent, lmLeft, 10);
  87.   //
  88.   void    Set(TEdge edge,      TRelationship rel, TWindow* otherWin,
  89.               TEdge otherEdge, int value = 0)
  90.             {RelWin = otherWin; MyEdge = edge; Relationship = rel;
  91.              OtherEdge = otherEdge; Value = value;}
  92.  
  93.   //
  94.   // these four member functions can be used to position your window with
  95.   // respective to a sibling window. you specify the sibling window and an
  96.   // optional margin between the two windows
  97.   //
  98.   void    LeftOf(TWindow* sibling, int margin = 0)
  99.             {Set(lmRight, lmLeftOf, sibling, lmLeft, margin);}
  100.   void    RightOf(TWindow* sibling, int margin = 0)
  101.             {Set(lmLeft, lmRightOf, sibling, lmRight, margin);}
  102.   void    Above(TWindow* sibling, int margin = 0)
  103.             {Set(lmBottom, lmAbove, sibling, lmTop, margin);}
  104.   void    Below(TWindow* sibling, int margin = 0)
  105.             {Set(lmTop, lmBelow, sibling, lmBottom, margin);}
  106.  
  107.   //
  108.   // these two work on the same edge, e.g. "SameAs(win, lmLeft)" means
  109.   // that your left edge should be the same as the left edge of "otherWin"
  110.   //
  111.   void    SameAs(TWindow* otherWin, TEdge edge)
  112.             {Set(edge, lmSameAs, otherWin, edge, 0);}
  113.   void    PercentOf(TWindow* otherWin, TEdge edge, int percent)
  114.             {Set(edge, lmPercentOf, otherWin, edge, percent);}
  115.  
  116.   //
  117.   // setting an edge to a fixed value
  118.   //
  119.   void    Absolute(TEdge edge, int value)
  120.             {MyEdge = edge; Value = value; Relationship = lmAbsolute;}
  121. };
  122.  
  123. //
  124. //  struct TEdgeOrSizeConstraint
  125. //  ------ ---------------------
  126. //
  127. template<int widthOrHeight>
  128. struct TEdgeOrSizeConstraint : public TEdgeConstraint {
  129.   //
  130.   // percent of another window's width/height (defaults to being the same
  131.   // dimension but could be the opposite dimension, e.g. make my width 50%
  132.   // of my parent's height)
  133.   //
  134.   void    PercentOf(TWindow*     otherWin,
  135.                     int          percent,
  136.                     TWidthHeight otherWidthHeight = widthOrHeight)
  137.             {RelWin = otherWin; MyEdge = widthOrHeight;
  138.              Relationship = lmPercentOf; OtherEdge = otherWidthHeight;
  139.              Percent = percent;}
  140.  
  141.   //
  142.   // same as another window's width/height(defaults to being the same
  143.   // dimension but could be the opposite dimension, e.g. make my width
  144.   // the same as my height)
  145.   //
  146.   void    SameAs(TWindow*     otherWin,
  147.                  TWidthHeight otherWidthHeight = widthOrHeight,
  148.                  int          value = 0)
  149.             {RelWin = otherWin; MyEdge = widthOrHeight;
  150.              Relationship = lmSameAs; OtherEdge = otherWidthHeight;
  151.              Value = value;}
  152.  
  153.   //
  154.   // setting a width/height to a fixed value
  155.   //
  156.   void    Absolute(int value)
  157.             {MyEdge = widthOrHeight; Value = value; Relationship = lmAbsolute;}
  158.  
  159.   //
  160.   // redefine member functions defined by TEdgeConstraint that are hidden by
  161.   // TEdgeOrSizeConstraint
  162.   //
  163.   void    Absolute(TEdge edge, int value)
  164.             {TEdgeConstraint::Absolute(edge, value);}
  165.   void    PercentOf(TWindow* otherWin, TEdge edge, int percent)
  166.             {TEdgeConstraint::PercentOf(otherWin, edge, percent);}
  167.   void    SameAs(TWindow* otherWin, TEdge edge)
  168.             {TEdgeConstraint::SameAs(otherWin, edge);}
  169. };
  170.  
  171. typedef TEdgeOrSizeConstraint<lmWidth>   TEdgeOrWidthConstraint;
  172. typedef TEdgeOrSizeConstraint<lmHeight>  TEdgeOrHeightConstraint;
  173.  
  174. #endif  // __OWL_LAYOUTCO_H
  175.