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