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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Declarations of classes TLayoutMetrics & TLayoutWindow
  6. //----------------------------------------------------------------------------
  7. #if !defined(OWL_LAYOUTWI_H)
  8. #define OWL_LAYOUTWI_H
  9.  
  10. #if !defined(OWL_WINDOW_H)
  11. # include <owl/window.h>
  12. #endif
  13. #if !defined(OWL_LAYOUTCO_H)
  14. # include <owl/layoutco.h>
  15. #endif
  16.  
  17. //
  18. //  class TLayoutMetrics
  19. //  ----- --------------
  20. //
  21. //  when specifying the layout metrics for a window you specify four layout
  22. //  constraints
  23. //
  24. class _OWLCLASS TLayoutMetrics {
  25.   public:
  26.     TEdgeConstraint         X;      // Horz1 can be lmLeft, lmCenter, lmRight
  27.     TEdgeConstraint         Y;      // Vert1 can be lmTop, lmCenter, lmBottom
  28.     TEdgeOrWidthConstraint  Width;  // Horz2 can be lmWidth, lmCenter, lmRight
  29.     TEdgeOrHeightConstraint Height; // Vert2 can be lmHeight, lmCenter, lmBottom
  30.  
  31.     //
  32.     // defaults each co: RelWin=0, MyEdge=(1st from above), Relationship=AsIs
  33.     //
  34.     TLayoutMetrics();
  35.   
  36.     void SetMeasurementUnits(TMeasurementUnits units);
  37. };
  38.  
  39. //
  40. // private structs used by TLayoutWindow
  41. //
  42. struct TChildMetrics;
  43. struct TConstraint;
  44. struct TVariable;
  45.  
  46. //
  47. //  class TLayoutWindow
  48. //  ----- -------------
  49. //
  50. // when specifying the layout metrics for a window, there are several options:
  51. //   e.g. in the horizontal direction,
  52. //
  53. //   Two Edge Constraints in X and Width
  54. //    1. left edge and right edge
  55. //    2. center edge and right edge
  56. //    3. left edge and center edge
  57. //
  58. //   Edge Constraint and Size constraint in X and Width
  59. //    4. left edge and size
  60. //    5. right edge and size
  61. //    6. center edge and size
  62. //
  63. // the same holds true in the vertical direction for Y and Height
  64. //
  65. // it is also possible to specify "lmAsIs" in which case we use the windows
  66. // current value
  67. //
  68. // specifying "lmAbsolute" means that we will use whatever is in data member
  69. // "Value"
  70. //
  71. // we just name the fields "X" and "Width" and "Y" and "Height",
  72. // although its okay to place a right or center edge constraint in the
  73. // "Width" field and its also okay to place a right edge constraint in
  74. // the "X" field (i.e. option #3)
  75. //
  76. // however, it's NOT okay to place a width constraint in the "X" or
  77. // "Height" fields or a height constraint in the "Y" or "Width" fields.
  78. //
  79. class _OWLCLASS TLayoutWindow : virtual public TWindow {
  80.   public:
  81.     TLayoutWindow(TWindow*        parent,
  82.                   const char far* title = 0,
  83.                   TModule*        module = 0);
  84.  
  85.    ~TLayoutWindow();
  86.  
  87.     //
  88.     // causes the receiver to size/position its children according to the
  89.     // specified layout metrics
  90.     //
  91.     // if you change the layout metrics for a child window call Layout()
  92.     // to have the changes take effect
  93.     //
  94.     void            Layout();
  95.  
  96.     void            SetChildLayoutMetrics(TWindow& child, TLayoutMetrics& metrics);
  97.     bool            GetChildLayoutMetrics(TWindow& child, TLayoutMetrics& metrics);
  98.     bool            RemoveChildLayoutMetrics(TWindow& child);
  99.  
  100.   protected:
  101.     TSize           ClientSize;
  102.  
  103.     //
  104.     // responds to a change in size by calling Layout()
  105.     //
  106.     void            EvSize(uint sizeType, TSize& size);
  107.  
  108.     //
  109.     // Override TWindow virtuals
  110.     //
  111.     void            RemoveChild(TWindow* child);
  112.  
  113.   private:
  114.     enum TWhichConstraint {XConstraint,     YConstraint,
  115.                            WidthConstraint, HeightConstraint};
  116.  
  117.     TChildMetrics*  ChildMetrics;
  118.     TConstraint*    Constraints;
  119.     TConstraint*    Plan;
  120.     TVariable*      Variables;
  121.     bool            PlanIsDirty;
  122.     int             NumChildMetrics;
  123.     int             FontHeight;
  124.  
  125.     TChildMetrics*  GetChildMetrics(TWindow& child);
  126.  
  127.     void            AddConstraint(TChildMetrics&     metrics,
  128.                                   TLayoutConstraint* c,
  129.                                   TWhichConstraint   whichContraint);
  130.     void            BuildConstraints(TChildMetrics& childMetrics);
  131.     void            RemoveConstraints(TChildMetrics& childMetrics);
  132.  
  133.     void            BuildPlan();
  134.     void            ExecutePlan();
  135.     void            ClearPlan();
  136.  
  137.     int             LayoutUnitsToPixels(int);
  138.     void            GetFontHeight();
  139.  
  140.     //
  141.     // hidden to prevent accidental copying or assignment
  142.     //
  143.     TLayoutWindow(const TLayoutWindow&);
  144.     TLayoutWindow& operator =(const TLayoutWindow&);
  145.  
  146.   DECLARE_RESPONSE_TABLE(TLayoutWindow);
  147.   DECLARE_CASTABLE;
  148. };
  149.  
  150. #endif  // OWL_LAYOUTWIN_H
  151.