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