layout.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: layout.h
  3. // Purpose: interface of layout constraints classes
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. enum wxEdge
  8. {
  9. wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
  10. wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY
  11. };
  12. enum wxRelationship
  13. {
  14. wxUnconstrained,
  15. wxAsIs,
  16. wxPercentOf,
  17. wxAbove,
  18. wxBelow,
  19. wxLeftOf,
  20. wxRightOf,
  21. wxSameAs,
  22. wxAbsolute
  23. };
  24. const int wxLAYOUT_DEFAULT_MARGIN = 0;
  25. // ----------------------------------------------------------------------------
  26. // wxIndividualLayoutConstraint: a constraint on window position
  27. // ----------------------------------------------------------------------------
  28. class wxIndividualLayoutConstraint : public wxObject
  29. {
  30. public:
  31. wxIndividualLayoutConstraint();
  32. // note that default copy ctor and assignment operators are ok
  33. virtual ~wxIndividualLayoutConstraint();
  34. void Set(wxRelationship rel,
  35. wxWindow *otherW,
  36. wxEdge otherE,
  37. int val = 0,
  38. int margin = wxLAYOUT_DEFAULT_MARGIN);
  39. //
  40. // Sibling relationships
  41. //
  42. void LeftOf(wxWindow *sibling, int margin = wxLAYOUT_DEFAULT_MARGIN);
  43. void RightOf(wxWindow *sibling, int margin = wxLAYOUT_DEFAULT_MARGIN);
  44. void Above(wxWindow *sibling, int margin = wxLAYOUT_DEFAULT_MARGIN);
  45. void Below(wxWindow *sibling, int margin = wxLAYOUT_DEFAULT_MARGIN);
  46. //
  47. // 'Same edge' alignment
  48. //
  49. void SameAs(wxWindow *otherW, wxEdge edge, int margin = wxLAYOUT_DEFAULT_MARGIN);
  50. // The edge is a percentage of the other window's edge
  51. void PercentOf(wxWindow *otherW, wxEdge wh, int per);
  52. //
  53. // Edge has absolute value
  54. //
  55. void Absolute(int val);
  56. //
  57. // Dimension is unconstrained
  58. //
  59. void Unconstrained();
  60. //
  61. // Dimension is 'as is' (use current size settings)
  62. //
  63. void AsIs();
  64. //
  65. // Accessors
  66. //
  67. wxWindow *GetOtherWindow();
  68. wxEdge GetMyEdge() const;
  69. void SetEdge(wxEdge which);
  70. void SetValue(int v);
  71. int GetMargin();
  72. void SetMargin(int m);
  73. int GetValue() const;
  74. int GetPercent() const;
  75. int GetOtherEdge() const;
  76. bool GetDone() const;
  77. void SetDone(bool d);
  78. wxRelationship GetRelationship();
  79. void SetRelationship(wxRelationship r);
  80. // Reset constraint if it mentions otherWin
  81. bool ResetIfWin(wxWindow *otherW);
  82. // Try to satisfy constraint
  83. bool SatisfyConstraint(wxLayoutConstraints *constraints, wxWindow *win);
  84. // Get the value of this edge or dimension, or if this
  85. // is not determinable, -1.
  86. int GetEdge(wxEdge which, wxWindow *thisWin, wxWindow *other) const;
  87. };
  88. // ----------------------------------------------------------------------------
  89. // wxLayoutConstraints: the complete set of constraints for a window
  90. // ----------------------------------------------------------------------------
  91. class wxLayoutConstraints : public wxObject
  92. {
  93. public:
  94. // Edge constraints
  95. wxIndividualLayoutConstraint left;
  96. wxIndividualLayoutConstraint top;
  97. wxIndividualLayoutConstraint right;
  98. wxIndividualLayoutConstraint bottom;
  99. // Size constraints
  100. wxIndividualLayoutConstraint width;
  101. wxIndividualLayoutConstraint height;
  102. // Centre constraints
  103. wxIndividualLayoutConstraint centreX;
  104. wxIndividualLayoutConstraint centreY;
  105. wxLayoutConstraints();
  106. // note that default copy ctor and assignment operators are ok
  107. virtual ~wxLayoutConstraints();
  108. bool SatisfyConstraints(wxWindow *win, int *noChanges);
  109. bool AreSatisfied() const;
  110. };