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

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