layout.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/layout.h
  3. // Purpose: OBSOLETE layout constraint classes, use sizers instead
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 29/01/98
  7. // Copyright: (c) 1998 Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_LAYOUT_H_
  11. #define _WX_LAYOUT_H_
  12. // ----------------------------------------------------------------------------
  13. // headers
  14. // ----------------------------------------------------------------------------
  15. #include "wx/object.h"
  16. // X stupidly defines these in X.h
  17. #ifdef Above
  18. #undef Above
  19. #endif
  20. #ifdef Below
  21. #undef Below
  22. #endif
  23. #if wxUSE_CONSTRAINTS
  24. // ----------------------------------------------------------------------------
  25. // forward declrations
  26. // ----------------------------------------------------------------------------
  27. class WXDLLIMPEXP_FWD_CORE wxWindowBase;
  28. class WXDLLIMPEXP_FWD_CORE wxLayoutConstraints;
  29. // ----------------------------------------------------------------------------
  30. // constants
  31. // ----------------------------------------------------------------------------
  32. #define wxLAYOUT_DEFAULT_MARGIN 0
  33. enum wxEdge
  34. {
  35. wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
  36. wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY
  37. };
  38. enum wxRelationship
  39. {
  40. wxUnconstrained = 0,
  41. wxAsIs,
  42. wxPercentOf,
  43. wxAbove,
  44. wxBelow,
  45. wxLeftOf,
  46. wxRightOf,
  47. wxSameAs,
  48. wxAbsolute
  49. };
  50. // ----------------------------------------------------------------------------
  51. // wxIndividualLayoutConstraint: a constraint on window position
  52. // ----------------------------------------------------------------------------
  53. class WXDLLIMPEXP_CORE wxIndividualLayoutConstraint : public wxObject
  54. {
  55. public:
  56. wxIndividualLayoutConstraint();
  57. // note that default copy ctor and assignment operators are ok
  58. virtual ~wxIndividualLayoutConstraint(){}
  59. void Set(wxRelationship rel, wxWindowBase *otherW, wxEdge otherE, int val = 0, int marg = wxLAYOUT_DEFAULT_MARGIN);
  60. //
  61. // Sibling relationships
  62. //
  63. void LeftOf(wxWindowBase *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
  64. void RightOf(wxWindowBase *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
  65. void Above(wxWindowBase *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
  66. void Below(wxWindowBase *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
  67. //
  68. // 'Same edge' alignment
  69. //
  70. void SameAs(wxWindowBase *otherW, wxEdge edge, int marg = wxLAYOUT_DEFAULT_MARGIN);
  71. // The edge is a percentage of the other window's edge
  72. void PercentOf(wxWindowBase *otherW, wxEdge wh, int per);
  73. //
  74. // Edge has absolute value
  75. //
  76. void Absolute(int val);
  77. //
  78. // Dimension is unconstrained
  79. //
  80. void Unconstrained() { relationship = wxUnconstrained; }
  81. //
  82. // Dimension is 'as is' (use current size settings)
  83. //
  84. void AsIs() { relationship = wxAsIs; }
  85. //
  86. // Accessors
  87. //
  88. wxWindowBase *GetOtherWindow() { return otherWin; }
  89. wxEdge GetMyEdge() const { return myEdge; }
  90. void SetEdge(wxEdge which) { myEdge = which; }
  91. void SetValue(int v) { value = v; }
  92. int GetMargin() { return margin; }
  93. void SetMargin(int m) { margin = m; }
  94. int GetValue() const { return value; }
  95. int GetPercent() const { return percent; }
  96. int GetOtherEdge() const { return otherEdge; }
  97. bool GetDone() const { return done; }
  98. void SetDone(bool d) { done = d; }
  99. wxRelationship GetRelationship() { return relationship; }
  100. void SetRelationship(wxRelationship r) { relationship = r; }
  101. // Reset constraint if it mentions otherWin
  102. bool ResetIfWin(wxWindowBase *otherW);
  103. // Try to satisfy constraint
  104. bool SatisfyConstraint(wxLayoutConstraints *constraints, wxWindowBase *win);
  105. // Get the value of this edge or dimension, or if this
  106. // is not determinable, -1.
  107. int GetEdge(wxEdge which, wxWindowBase *thisWin, wxWindowBase *other) const;
  108. protected:
  109. // To be allowed to modify the internal variables
  110. friend class wxIndividualLayoutConstraint_Serialize;
  111. // 'This' window is the parent or sibling of otherWin
  112. wxWindowBase *otherWin;
  113. wxEdge myEdge;
  114. wxRelationship relationship;
  115. int margin;
  116. int value;
  117. int percent;
  118. wxEdge otherEdge;
  119. bool done;
  120. DECLARE_DYNAMIC_CLASS(wxIndividualLayoutConstraint)
  121. };
  122. // ----------------------------------------------------------------------------
  123. // wxLayoutConstraints: the complete set of constraints for a window
  124. // ----------------------------------------------------------------------------
  125. class WXDLLIMPEXP_CORE wxLayoutConstraints : public wxObject
  126. {
  127. public:
  128. // Edge constraints
  129. wxIndividualLayoutConstraint left;
  130. wxIndividualLayoutConstraint top;
  131. wxIndividualLayoutConstraint right;
  132. wxIndividualLayoutConstraint bottom;
  133. // Size constraints
  134. wxIndividualLayoutConstraint width;
  135. wxIndividualLayoutConstraint height;
  136. // Centre constraints
  137. wxIndividualLayoutConstraint centreX;
  138. wxIndividualLayoutConstraint centreY;
  139. wxLayoutConstraints();
  140. // note that default copy ctor and assignment operators are ok
  141. virtual ~wxLayoutConstraints(){}
  142. bool SatisfyConstraints(wxWindowBase *win, int *noChanges);
  143. bool AreSatisfied() const
  144. {
  145. return left.GetDone() && top.GetDone() &&
  146. width.GetDone() && height.GetDone();
  147. }
  148. DECLARE_DYNAMIC_CLASS(wxLayoutConstraints)
  149. };
  150. #endif // wxUSE_CONSTRAINTS
  151. #endif // _WX_LAYOUT_H_