]> git.saurik.com Git - wxWidgets.git/blame - samples/layout/expt.cpp
Removed def files
[wxWidgets.git] / samples / layout / expt.cpp
CommitLineData
c801d85f
KB
1/*
2 * Experimental code to use operators for constraint specification.
3 * In the end, the syntax didn't look much clearer than
4 * the original, so abandoned.
5
6 Example:
7
8 wxConstrain(frame->panel,
9
10 ( leftOf (frame->panel) = leftOf (frame),
11 topOf (frame->panel) = topOf (frame),
12 rightOf (frame->panel) = rightOf (frame),
13 heightOf (frame->panel) = 50 % heightOf (frame)
14 )
15 );
16 */
17
18// Operator experiments
19#define wxCONSTRAINT_OP_REL 1
20#define wxCONSTRAINT_OP_PERCENT 2
21#define wxCONSTRAINT_OP_EDGE 3
22#define wxCONSTRAINT_OP_ABS 4
23#define wxCONSTRAINT_OP_AND 5
24
25class wxConstraintOp: public wxObject
26{
27 public:
28 int opType;
29 wxEdge edge;
30 wxRelationship relationship;
31 wxWindow *win;
32 int value;
33 int margin;
34 wxConstraintOp *lhs;
35 wxConstraintOp *rhs;
36 wxConstraintOp(int typ)
37 {
38 opType = typ;
39 edge = wxLeft;
40 win = NULL;
41 value = 0;
42 margin = 0;
43 relationship = wxSameAs;
44 lhs = 0; rhs = 0;
45 }
46 wxConstraintOp(const wxConstraintOp& op)
47 {
48 opType = op.opType;
49 edge = op.edge;
50 relationship = op.relationship;
51 win = op.win;
52 value = op.value;
53 margin = op.margin;
54 if (op.lhs)
55 lhs = new wxConstraintOp(*op.lhs);
56 else
57 lhs = NULL;
58 if (op.rhs)
59 rhs = new wxConstraintOp(*op.rhs);
60 else
61 rhs = NULL;
62 }
63 ~wxConstraintOp(void)
64 {
65 if (lhs)
66 delete lhs;
67 if (rhs)
68 delete rhs;
69 }
70
71 wxConstraintOp operator = (const wxConstraintOp& arg2);
72 wxConstraintOp operator = (const int value);
73
74 friend wxConstraintOp operator % (const int perCent, const wxConstraintOp& arg2);
75 friend wxConstraintOp operator + (wxConstraintOp& arg1, int margin);
76 friend wxConstraintOp operator - (wxConstraintOp& arg1, int margin);
77 friend wxConstraintOp operator , (const wxConstraintOp& arg1, const wxConstraintOp& arg2);
78};
79
80wxConstraintOp leftOf(wxWindow *win)
81{
82 wxConstraintOp thing(wxCONSTRAINT_OP_EDGE);
83 thing.win = win;
84 thing.edge = wxLeft;
85 return thing;
86}
87
88wxConstraintOp topOf(wxWindow *win)
89{
90 wxConstraintOp thing(wxCONSTRAINT_OP_EDGE);
91 thing.win = win;
92 thing.edge = wxTop;
93 return thing;
94}
95
96wxConstraintOp widthOf(wxWindow *win)
97{
98 wxConstraintOp thing(wxCONSTRAINT_OP_EDGE);
99 thing.win = win;
100 thing.edge = wxWidth;
101 return thing;
102}
103
104wxConstraintOp wxConstraintOp::operator = (const wxConstraintOp& arg2)
105{
106 wxConstraintOp op3(wxCONSTRAINT_OP_REL);
107 op3.relationship = wxPercentOf;
108 op3.value = 100;
109 if ((op3.relationship == wxPercentOf) && (op3.value > 0))
110 op3.value = this->value;
111 op3.lhs = new wxConstraintOp(*this);
112 op3.rhs = new wxConstraintOp(arg2);
113
114 return op3;
115}
116
117wxConstraintOp wxConstraintOp::operator = (const int value)
118{
119 wxConstraintOp op3(wxCONSTRAINT_OP_REL);
120 op3.relationship = wxAbsolute;
121
122 op3.lhs = new wxConstraintOp(*this);
123 op3.rhs = new wxConstraintOp(wxCONSTRAINT_OP_ABS);
124 op3.value = value;
125
126 return op3;
127}
128
129wxConstraintOp operator % (const int perCent, const wxConstraintOp& arg2)
130{
131 wxConstraintOp op3(arg2);
132 op3.opType = wxCONSTRAINT_OP_EDGE;
133 op3.value = perCent;
134 if (op3.value > 0)
135 op3.value = arg2.value;
136
137 return op3;
138}
139
140wxConstraintOp operator + (wxConstraintOp& arg1, int margin)
141{
142 wxConstraintOp op3(arg1);
143 op3.margin = margin;
144 return op3;
145}
146
147wxConstraintOp operator - (wxConstraintOp& arg1, int margin)
148{
149 wxConstraintOp op3(arg1);
150 op3.margin = - margin;
151 return op3;
152}
153
154wxConstraintOp operator , (const wxConstraintOp& arg1, const wxConstraintOp& arg2)
155{
156 wxConstraintOp op3(wxCONSTRAINT_OP_AND);
157 op3.lhs = new wxConstraintOp(arg1);
158 op3.rhs = new wxConstraintOp(arg2);
159
160 return op3;
161}