]> git.saurik.com Git - wxWidgets.git/blame - src/common/layout.cpp
correct to int32 for range comparison
[wxWidgets.git] / src / common / layout.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: layout.cpp
3// Purpose: Constraint layout system classes
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
55d99c7a 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
f03fc89f
VZ
12// =============================================================================
13// declarations
14// =============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
d427503c 19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
f03fc89f 21 #pragma implementation "layout.h"
c801d85f
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
ce4169a4 28 #pragma hdrstop
c801d85f
KB
29#endif
30
ce4169a4
RR
31#ifndef WX_PRECOMP
32 #include "wx/defs.h"
33#endif
c801d85f 34
d427503c
VZ
35#if wxUSE_CONSTRAINTS
36
c801d85f 37#ifndef WX_PRECOMP
ce4169a4
RR
38 #include "wx/window.h"
39 #include "wx/utils.h"
40 #include "wx/dialog.h"
41 #include "wx/msgdlg.h"
42 #include "wx/intl.h"
c801d85f
KB
43#endif
44
45#include "wx/layout.h"
46
f03fc89f
VZ
47 IMPLEMENT_DYNAMIC_CLASS(wxIndividualLayoutConstraint, wxObject)
48 IMPLEMENT_DYNAMIC_CLASS(wxLayoutConstraints, wxObject)
c801d85f 49
c801d85f 50
a3622daa 51wxIndividualLayoutConstraint::wxIndividualLayoutConstraint()
c801d85f 52{
f03fc89f
VZ
53 myEdge = wxTop;
54 relationship = wxUnconstrained;
55 margin = 0;
56 value = 0;
57 percent = 0;
58 otherEdge = wxTop;
f644b28c 59 done = false;
f03fc89f 60 otherWin = (wxWindowBase *) NULL;
c801d85f
KB
61}
62
f03fc89f 63void wxIndividualLayoutConstraint::Set(wxRelationship rel, wxWindowBase *otherW, wxEdge otherE, int val, int marg)
c801d85f 64{
844a4451
RD
65 if (rel == wxSameAs)
66 {
67 // If Set is called by the user with wxSameAs then call SameAs to do
68 // it since it will actually use wxPercent instead.
69 SameAs(otherW, otherE, marg);
70 return;
71 }
72
4e00f541
VZ
73 relationship = rel;
74 otherWin = otherW;
75 otherEdge = otherE;
76
77 if ( rel == wxPercentOf )
78 {
6e50d0eb 79 percent = val;
4e00f541
VZ
80 }
81 else
82 {
83 value = val;
84 }
85
86 margin = marg;
c801d85f
KB
87}
88
f03fc89f
VZ
89void wxIndividualLayoutConstraint::LeftOf(wxWindowBase *sibling, int marg)
90{
91 Set(wxLeftOf, sibling, wxLeft, 0, marg);
92}
c801d85f 93
f03fc89f
VZ
94void wxIndividualLayoutConstraint::RightOf(wxWindowBase *sibling, int marg)
95{
96 Set(wxRightOf, sibling, wxRight, 0, marg);
97}
c801d85f 98
f03fc89f
VZ
99void wxIndividualLayoutConstraint::Above(wxWindowBase *sibling, int marg)
100{
101 Set(wxAbove, sibling, wxTop, 0, marg);
102}
c801d85f 103
f03fc89f
VZ
104void wxIndividualLayoutConstraint::Below(wxWindowBase *sibling, int marg)
105{
106 Set(wxBelow, sibling, wxBottom, 0, marg);
107}
c801d85f
KB
108
109//
110// 'Same edge' alignment
111//
f03fc89f 112void wxIndividualLayoutConstraint::SameAs(wxWindowBase *otherW, wxEdge edge, int marg)
844a4451 113{
4e00f541 114 Set(wxPercentOf, otherW, edge, 100, marg);
f03fc89f 115}
c801d85f
KB
116
117// The edge is a percentage of the other window's edge
f03fc89f 118void wxIndividualLayoutConstraint::PercentOf(wxWindowBase *otherW, wxEdge wh, int per)
844a4451 119{
4e00f541 120 Set(wxPercentOf, otherW, wh, per);
c801d85f
KB
121}
122
123//
124// Edge has absolute value
125//
126void wxIndividualLayoutConstraint::Absolute(int val)
f03fc89f 127{
6e50d0eb
VZ
128 value = val;
129 relationship = wxAbsolute;
f03fc89f 130}
c801d85f
KB
131
132// Reset constraint if it mentions otherWin
f03fc89f 133bool wxIndividualLayoutConstraint::ResetIfWin(wxWindowBase *otherW)
c801d85f 134{
f03fc89f
VZ
135 if (otherW == otherWin)
136 {
137 myEdge = wxTop;
138 relationship = wxAsIs;
139 margin = 0;
140 value = 0;
141 percent = 0;
142 otherEdge = wxTop;
143 otherWin = (wxWindowBase *) NULL;
f644b28c 144 return true;
f03fc89f 145 }
6e50d0eb 146
f644b28c 147 return false;
c801d85f
KB
148}
149
150// Try to satisfy constraint
f03fc89f 151bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constraints, wxWindowBase *win)
c801d85f 152{
f03fc89f 153 if (relationship == wxAbsolute)
c801d85f 154 {
f644b28c
WS
155 done = true;
156 return true;
c801d85f 157 }
f03fc89f
VZ
158
159 switch (myEdge)
c801d85f 160 {
f03fc89f 161 case wxLeft:
c801d85f 162 {
f03fc89f
VZ
163 switch (relationship)
164 {
165 case wxLeftOf:
166 {
167 // We can know this edge if: otherWin is win's
168 // parent, or otherWin has a satisfied constraint,
169 // or otherWin has no constraint.
170 int edgePos = GetEdge(otherEdge, win, otherWin);
171 if (edgePos != -1)
172 {
173 value = edgePos - margin;
f644b28c
WS
174 done = true;
175 return true;
f03fc89f
VZ
176 }
177 else
f644b28c 178 return false;
f03fc89f
VZ
179 }
180 case wxRightOf:
181 {
182 int edgePos = GetEdge(otherEdge, win, otherWin);
183 if (edgePos != -1)
184 {
185 value = edgePos + margin;
f644b28c
WS
186 done = true;
187 return true;
f03fc89f
VZ
188 }
189 else
f644b28c 190 return false;
f03fc89f
VZ
191 }
192 case wxPercentOf:
193 {
194 int edgePos = GetEdge(otherEdge, win, otherWin);
195 if (edgePos != -1)
196 {
197 value = (int)(edgePos*(((float)percent)*0.01) + margin);
f644b28c
WS
198 done = true;
199 return true;
f03fc89f
VZ
200 }
201 else
f644b28c 202 return false;
f03fc89f
VZ
203 }
204 case wxUnconstrained:
205 {
206 // We know the left-hand edge position if we know
207 // the right-hand edge and we know the width; OR if
208 // we know the centre and the width.
209 if (constraints->right.GetDone() && constraints->width.GetDone())
210 {
211 value = (constraints->right.GetValue() - constraints->width.GetValue() + margin);
f644b28c
WS
212 done = true;
213 return true;
f03fc89f
VZ
214 }
215 else if (constraints->centreX.GetDone() && constraints->width.GetDone())
216 {
217 value = (int)(constraints->centreX.GetValue() - (constraints->width.GetValue()/2) + margin);
f644b28c
WS
218 done = true;
219 return true;
f03fc89f
VZ
220 }
221 else
f644b28c 222 return false;
f03fc89f
VZ
223 }
224 case wxAsIs:
225 {
226 int y;
227 win->GetPosition(&value, &y);
f644b28c
WS
228 done = true;
229 return true;
f03fc89f
VZ
230 }
231 default:
232 break;
233 }
234 break;
c801d85f 235 }
f03fc89f 236 case wxRight:
c801d85f 237 {
f03fc89f
VZ
238 switch (relationship)
239 {
240 case wxLeftOf:
241 {
242 // We can know this edge if: otherWin is win's
243 // parent, or otherWin has a satisfied constraint,
244 // or otherWin has no constraint.
245 int edgePos = GetEdge(otherEdge, win, otherWin);
246 if (edgePos != -1)
247 {
248 value = edgePos - margin;
f644b28c
WS
249 done = true;
250 return true;
f03fc89f
VZ
251 }
252 else
f644b28c 253 return false;
f03fc89f
VZ
254 }
255 case wxRightOf:
256 {
257 int edgePos = GetEdge(otherEdge, win, otherWin);
258 if (edgePos != -1)
259 {
260 value = edgePos + margin;
f644b28c
WS
261 done = true;
262 return true;
f03fc89f
VZ
263 }
264 else
f644b28c 265 return false;
f03fc89f
VZ
266 }
267 case wxPercentOf:
268 {
269 int edgePos = GetEdge(otherEdge, win, otherWin);
270 if (edgePos != -1)
271 {
272 value = (int)(edgePos*(((float)percent)*0.01) - margin);
f644b28c
WS
273 done = true;
274 return true;
f03fc89f
VZ
275 }
276 else
f644b28c 277 return false;
f03fc89f
VZ
278 }
279 case wxUnconstrained:
280 {
281 // We know the right-hand edge position if we know the
282 // left-hand edge and we know the width, OR if we know the
283 // centre edge and the width.
284 if (constraints->left.GetDone() && constraints->width.GetDone())
285 {
286 value = (constraints->left.GetValue() + constraints->width.GetValue() - margin);
f644b28c
WS
287 done = true;
288 return true;
f03fc89f
VZ
289 }
290 else if (constraints->centreX.GetDone() && constraints->width.GetDone())
291 {
292 value = (int)(constraints->centreX.GetValue() + (constraints->width.GetValue()/2) - margin);
f644b28c
WS
293 done = true;
294 return true;
f03fc89f
VZ
295 }
296 else
f644b28c 297 return false;
f03fc89f
VZ
298 }
299 case wxAsIs:
300 {
301 int x, y;
302 int w, h;
7de8edde 303 win->GetBestSize(&w, &h);
f03fc89f
VZ
304 win->GetPosition(&x, &y);
305 value = x + w;
f644b28c
WS
306 done = true;
307 return true;
f03fc89f
VZ
308 }
309 default:
310 break;
311 }
312 break;
c801d85f 313 }
f03fc89f 314 case wxTop:
c801d85f 315 {
f03fc89f
VZ
316 switch (relationship)
317 {
318 case wxAbove:
319 {
320 // We can know this edge if: otherWin is win's
321 // parent, or otherWin has a satisfied constraint,
322 // or otherWin has no constraint.
323 int edgePos = GetEdge(otherEdge, win, otherWin);
324 if (edgePos != -1)
325 {
326 value = edgePos - margin;
f644b28c
WS
327 done = true;
328 return true;
f03fc89f
VZ
329 }
330 else
f644b28c 331 return false;
f03fc89f
VZ
332 }
333 case wxBelow:
334 {
335 int edgePos = GetEdge(otherEdge, win, otherWin);
336 if (edgePos != -1)
337 {
338 value = edgePos + margin;
f644b28c
WS
339 done = true;
340 return true;
f03fc89f
VZ
341 }
342 else
f644b28c 343 return false;
f03fc89f
VZ
344 }
345 case wxPercentOf:
346 {
347 int edgePos = GetEdge(otherEdge, win, otherWin);
348 if (edgePos != -1)
349 {
350 value = (int)(edgePos*(((float)percent)*0.01) + margin);
f644b28c
WS
351 done = true;
352 return true;
f03fc89f
VZ
353 }
354 else
f644b28c 355 return false;
f03fc89f
VZ
356 }
357 case wxUnconstrained:
358 {
359 // We know the top edge position if we know the bottom edge
360 // and we know the height; OR if we know the centre edge and
361 // the height.
362 if (constraints->bottom.GetDone() && constraints->height.GetDone())
363 {
364 value = (constraints->bottom.GetValue() - constraints->height.GetValue() + margin);
f644b28c
WS
365 done = true;
366 return true;
f03fc89f
VZ
367 }
368 else if (constraints->centreY.GetDone() && constraints->height.GetDone())
369 {
370 value = (constraints->centreY.GetValue() - (constraints->height.GetValue()/2) + margin);
f644b28c
WS
371 done = true;
372 return true;
f03fc89f
VZ
373 }
374 else
f644b28c 375 return false;
f03fc89f
VZ
376 }
377 case wxAsIs:
378 {
379 int x;
380 win->GetPosition(&x, &value);
f644b28c
WS
381 done = true;
382 return true;
f03fc89f
VZ
383 }
384 default:
385 break;
386 }
387 break;
c801d85f 388 }
f03fc89f 389 case wxBottom:
c801d85f 390 {
f03fc89f
VZ
391 switch (relationship)
392 {
393 case wxAbove:
394 {
395 // We can know this edge if: otherWin is win's parent,
396 // or otherWin has a satisfied constraint, or
397 // otherWin has no constraint.
398 int edgePos = GetEdge(otherEdge, win, otherWin);
399 if (edgePos != -1)
400 {
401 value = edgePos + margin;
f644b28c
WS
402 done = true;
403 return true;
f03fc89f
VZ
404 }
405 else
f644b28c 406 return false;
f03fc89f
VZ
407 }
408 case wxBelow:
409 {
410 int edgePos = GetEdge(otherEdge, win, otherWin);
411 if (edgePos != -1)
412 {
413 value = edgePos - margin;
f644b28c
WS
414 done = true;
415 return true;
f03fc89f
VZ
416 }
417 else
f644b28c 418 return false;
f03fc89f
VZ
419 }
420 case wxPercentOf:
421 {
422 int edgePos = GetEdge(otherEdge, win, otherWin);
423 if (edgePos != -1)
424 {
425 value = (int)(edgePos*(((float)percent)*0.01) - margin);
f644b28c
WS
426 done = true;
427 return true;
f03fc89f
VZ
428 }
429 else
f644b28c 430 return false;
f03fc89f
VZ
431 }
432 case wxUnconstrained:
433 {
434 // We know the bottom edge position if we know the top edge
435 // and we know the height; OR if we know the centre edge and
436 // the height.
437 if (constraints->top.GetDone() && constraints->height.GetDone())
438 {
439 value = (constraints->top.GetValue() + constraints->height.GetValue() - margin);
f644b28c
WS
440 done = true;
441 return true;
f03fc89f
VZ
442 }
443 else if (constraints->centreY.GetDone() && constraints->height.GetDone())
444 {
445 value = (constraints->centreY.GetValue() + (constraints->height.GetValue()/2) - margin);
f644b28c
WS
446 done = true;
447 return true;
f03fc89f
VZ
448 }
449 else
f644b28c 450 return false;
f03fc89f
VZ
451 }
452 case wxAsIs:
453 {
454 int x, y;
455 int w, h;
7de8edde 456 win->GetBestSize(&w, &h);
f03fc89f
VZ
457 win->GetPosition(&x, &y);
458 value = h + y;
f644b28c
WS
459 done = true;
460 return true;
f03fc89f
VZ
461 }
462 default:
463 break;
464 }
465 break;
c801d85f 466 }
f03fc89f 467 case wxCentreX:
c801d85f 468 {
f03fc89f
VZ
469 switch (relationship)
470 {
471 case wxLeftOf:
472 {
473 // We can know this edge if: otherWin is win's parent, or
474 // otherWin has a satisfied constraint, or otherWin has no
475 // constraint.
476 int edgePos = GetEdge(otherEdge, win, otherWin);
477 if (edgePos != -1)
478 {
479 value = edgePos - margin;
f644b28c
WS
480 done = true;
481 return true;
f03fc89f
VZ
482 }
483 else
f644b28c 484 return false;
f03fc89f
VZ
485 }
486 case wxRightOf:
487 {
488 int edgePos = GetEdge(otherEdge, win, otherWin);
489 if (edgePos != -1)
490 {
491 value = edgePos + margin;
f644b28c
WS
492 done = true;
493 return true;
f03fc89f
VZ
494 }
495 else
f644b28c 496 return false;
f03fc89f
VZ
497 }
498 case wxPercentOf:
499 {
500 int edgePos = GetEdge(otherEdge, win, otherWin);
501 if (edgePos != -1)
502 {
503 value = (int)(edgePos*(((float)percent)*0.01) + margin);
f644b28c
WS
504 done = true;
505 return true;
f03fc89f
VZ
506 }
507 else
f644b28c 508 return false;
f03fc89f
VZ
509 }
510 case wxUnconstrained:
511 {
512 // We know the centre position if we know
513 // the left-hand edge and we know the width, OR
514 // the right-hand edge and the width
515 if (constraints->left.GetDone() && constraints->width.GetDone())
516 {
517 value = (int)(constraints->left.GetValue() + (constraints->width.GetValue()/2) + margin);
f644b28c
WS
518 done = true;
519 return true;
f03fc89f
VZ
520 }
521 else if (constraints->right.GetDone() && constraints->width.GetDone())
522 {
523 value = (int)(constraints->left.GetValue() - (constraints->width.GetValue()/2) + margin);
f644b28c
WS
524 done = true;
525 return true;
f03fc89f
VZ
526 }
527 else
f644b28c 528 return false;
f03fc89f
VZ
529 }
530 default:
531 break;
532 }
533 break;
c801d85f 534 }
f03fc89f 535 case wxCentreY:
c801d85f 536 {
f03fc89f
VZ
537 switch (relationship)
538 {
539 case wxAbove:
540 {
541 // We can know this edge if: otherWin is win's parent,
542 // or otherWin has a satisfied constraint, or otherWin
543 // has no constraint.
544 int edgePos = GetEdge(otherEdge, win, otherWin);
545 if (edgePos != -1)
546 {
547 value = edgePos - margin;
f644b28c
WS
548 done = true;
549 return true;
f03fc89f
VZ
550 }
551 else
f644b28c 552 return false;
f03fc89f
VZ
553 }
554 case wxBelow:
555 {
556 int edgePos = GetEdge(otherEdge, win, otherWin);
557 if (edgePos != -1)
558 {
559 value = edgePos + margin;
f644b28c
WS
560 done = true;
561 return true;
f03fc89f
VZ
562 }
563 else
f644b28c 564 return false;
f03fc89f
VZ
565 }
566 case wxPercentOf:
567 {
568 int edgePos = GetEdge(otherEdge, win, otherWin);
569 if (edgePos != -1)
570 {
571 value = (int)(edgePos*(((float)percent)*0.01) + margin);
f644b28c
WS
572 done = true;
573 return true;
f03fc89f
VZ
574 }
575 else
f644b28c 576 return false;
f03fc89f
VZ
577 }
578 case wxUnconstrained:
579 {
580 // We know the centre position if we know
581 // the top edge and we know the height, OR
582 // the bottom edge and the height.
583 if (constraints->bottom.GetDone() && constraints->height.GetDone())
584 {
585 value = (int)(constraints->bottom.GetValue() - (constraints->height.GetValue()/2) + margin);
f644b28c
WS
586 done = true;
587 return true;
f03fc89f
VZ
588 }
589 else if (constraints->top.GetDone() && constraints->height.GetDone())
590 {
591 value = (int)(constraints->top.GetValue() + (constraints->height.GetValue()/2) + margin);
f644b28c
WS
592 done = true;
593 return true;
f03fc89f
VZ
594 }
595 else
f644b28c 596 return false;
f03fc89f
VZ
597 }
598 default:
599 break;
600 }
601 break;
c801d85f 602 }
f03fc89f 603 case wxWidth:
c801d85f 604 {
f03fc89f
VZ
605 switch (relationship)
606 {
607 case wxPercentOf:
608 {
609 int edgePos = GetEdge(otherEdge, win, otherWin);
610 if (edgePos != -1)
611 {
612 value = (int)(edgePos*(((float)percent)*0.01));
f644b28c
WS
613 done = true;
614 return true;
f03fc89f
VZ
615 }
616 else
f644b28c 617 return false;
f03fc89f
VZ
618 }
619 case wxAsIs:
620 {
621 if (win)
622 {
623 int h;
7de8edde 624 win->GetBestSize(&value, &h);
f644b28c
WS
625 done = true;
626 return true;
f03fc89f 627 }
f644b28c 628 else return false;
f03fc89f
VZ
629 }
630 case wxUnconstrained:
631 {
632 // We know the width if we know the left edge and the right edge, OR
633 // if we know the left edge and the centre, OR
634 // if we know the right edge and the centre
635 if (constraints->left.GetDone() && constraints->right.GetDone())
636 {
637 value = constraints->right.GetValue() - constraints->left.GetValue();
f644b28c
WS
638 done = true;
639 return true;
f03fc89f
VZ
640 }
641 else if (constraints->centreX.GetDone() && constraints->left.GetDone())
642 {
643 value = (int)(2*(constraints->centreX.GetValue() - constraints->left.GetValue()));
f644b28c
WS
644 done = true;
645 return true;
f03fc89f
VZ
646 }
647 else if (constraints->centreX.GetDone() && constraints->right.GetDone())
648 {
649 value = (int)(2*(constraints->right.GetValue() - constraints->centreX.GetValue()));
f644b28c
WS
650 done = true;
651 return true;
f03fc89f
VZ
652 }
653 else
f644b28c 654 return false;
f03fc89f
VZ
655 }
656 default:
657 break;
658 }
659 break;
c801d85f 660 }
f03fc89f 661 case wxHeight:
c801d85f 662 {
f03fc89f
VZ
663 switch (relationship)
664 {
665 case wxPercentOf:
666 {
667 int edgePos = GetEdge(otherEdge, win, otherWin);
668 if (edgePos != -1)
669 {
670 value = (int)(edgePos*(((float)percent)*0.01));
f644b28c
WS
671 done = true;
672 return true;
f03fc89f
VZ
673 }
674 else
f644b28c 675 return false;
f03fc89f
VZ
676 }
677 case wxAsIs:
678 {
679 if (win)
680 {
681 int w;
7de8edde 682 win->GetBestSize(&w, &value);
f644b28c
WS
683 done = true;
684 return true;
f03fc89f 685 }
f644b28c 686 else return false;
f03fc89f
VZ
687 }
688 case wxUnconstrained:
689 {
690 // We know the height if we know the top edge and the bottom edge, OR
691 // if we know the top edge and the centre, OR
692 // if we know the bottom edge and the centre
693 if (constraints->top.GetDone() && constraints->bottom.GetDone())
694 {
695 value = constraints->bottom.GetValue() - constraints->top.GetValue();
f644b28c
WS
696 done = true;
697 return true;
f03fc89f
VZ
698 }
699 else if (constraints->top.GetDone() && constraints->centreY.GetDone())
700 {
701 value = (int)(2*(constraints->centreY.GetValue() - constraints->top.GetValue()));
f644b28c
WS
702 done = true;
703 return true;
f03fc89f
VZ
704 }
705 else if (constraints->bottom.GetDone() && constraints->centreY.GetDone())
706 {
707 value = (int)(2*(constraints->bottom.GetValue() - constraints->centreY.GetValue()));
f644b28c
WS
708 done = true;
709 return true;
f03fc89f
VZ
710 }
711 else
f644b28c 712 return false;
f03fc89f
VZ
713 }
714 default:
715 break;
716 }
717 break;
c801d85f
KB
718 }
719 default:
f03fc89f 720 break;
c801d85f 721 }
f644b28c 722 return false;
c801d85f
KB
723}
724
f03fc89f 725// Get the value of this edge or dimension, or if this is not determinable, -1.
a3622daa 726int wxIndividualLayoutConstraint::GetEdge(wxEdge which,
f03fc89f
VZ
727 wxWindowBase *thisWin,
728 wxWindowBase *other) const
c801d85f 729{
f03fc89f
VZ
730 // If the edge or dimension belongs to the parent, then we know the
731 // dimension is obtainable immediately. E.g. a wxExpandSizer may contain a
732 // button (but the button's true parent is a panel, not the sizer)
222ed1d6 733 if (other->GetChildren().Find((wxWindow*)thisWin))
c801d85f 734 {
f03fc89f
VZ
735 switch (which)
736 {
737 case wxLeft:
738 {
3417c2cd 739 return 0;
f03fc89f
VZ
740 }
741 case wxTop:
742 {
3417c2cd 743 return 0;
f03fc89f
VZ
744 }
745 case wxRight:
746 {
747 int w, h;
748 other->GetClientSizeConstraint(&w, &h);
3417c2cd 749 return w;
f03fc89f
VZ
750 }
751 case wxBottom:
752 {
753 int w, h;
754 other->GetClientSizeConstraint(&w, &h);
3417c2cd 755 return h;
f03fc89f
VZ
756 }
757 case wxWidth:
758 {
759 int w, h;
760 other->GetClientSizeConstraint(&w, &h);
3417c2cd 761 return w;
f03fc89f
VZ
762 }
763 case wxHeight:
764 {
765 int w, h;
766 other->GetClientSizeConstraint(&w, &h);
3417c2cd 767 return h;
f03fc89f
VZ
768 }
769 case wxCentreX:
770 case wxCentreY:
771 {
772 int w, h;
773 other->GetClientSizeConstraint(&w, &h);
774 if (which == wxCentreX)
775 return (int)(w/2);
776 else
777 return (int)(h/2);
778 }
779 default:
780 return -1;
781 }
c801d85f 782 }
f03fc89f 783 switch (which)
c801d85f 784 {
f03fc89f
VZ
785 case wxLeft:
786 {
787 wxLayoutConstraints *constr = other->GetConstraints();
788 // If no constraints, it means the window is not dependent
789 // on anything, and therefore we know its value immediately
790 if (constr)
791 {
792 if (constr->left.GetDone())
793 return constr->left.GetValue();
794 else
795 return -1;
796 }
797 else
798 {
799 int x, y;
800 other->GetPosition(&x, &y);
801 return x;
802 }
803 }
804 case wxTop:
805 {
806 wxLayoutConstraints *constr = other->GetConstraints();
807 // If no constraints, it means the window is not dependent
808 // on anything, and therefore we know its value immediately
809 if (constr)
810 {
811 if (constr->top.GetDone())
812 return constr->top.GetValue();
813 else
814 return -1;
815 }
816 else
817 {
818 int x, y;
819 other->GetPosition(&x, &y);
820 return y;
821 }
822 }
823 case wxRight:
824 {
825 wxLayoutConstraints *constr = other->GetConstraints();
826 // If no constraints, it means the window is not dependent
827 // on anything, and therefore we know its value immediately
828 if (constr)
829 {
830 if (constr->right.GetDone())
831 return constr->right.GetValue();
832 else
833 return -1;
834 }
835 else
836 {
837 int x, y, w, h;
838 other->GetPosition(&x, &y);
839 other->GetSize(&w, &h);
840 return (int)(x + w);
841 }
842 }
843 case wxBottom:
844 {
845 wxLayoutConstraints *constr = other->GetConstraints();
846 // If no constraints, it means the window is not dependent
847 // on anything, and therefore we know its value immediately
848 if (constr)
849 {
850 if (constr->bottom.GetDone())
851 return constr->bottom.GetValue();
852 else
853 return -1;
854 }
855 else
856 {
857 int x, y, w, h;
858 other->GetPosition(&x, &y);
859 other->GetSize(&w, &h);
860 return (int)(y + h);
861 }
862 }
863 case wxWidth:
864 {
865 wxLayoutConstraints *constr = other->GetConstraints();
866 // If no constraints, it means the window is not dependent
867 // on anything, and therefore we know its value immediately
868 if (constr)
869 {
870 if (constr->width.GetDone())
871 return constr->width.GetValue();
872 else
873 return -1;
874 }
875 else
876 {
877 int w, h;
878 other->GetSize(&w, &h);
879 return w;
880 }
881 }
882 case wxHeight:
883 {
884 wxLayoutConstraints *constr = other->GetConstraints();
885 // If no constraints, it means the window is not dependent
886 // on anything, and therefore we know its value immediately
887 if (constr)
888 {
889 if (constr->height.GetDone())
890 return constr->height.GetValue();
891 else
892 return -1;
893 }
894 else
895 {
896 int w, h;
897 other->GetSize(&w, &h);
898 return h;
899 }
900 }
901 case wxCentreX:
902 {
903 wxLayoutConstraints *constr = other->GetConstraints();
904 // If no constraints, it means the window is not dependent
905 // on anything, and therefore we know its value immediately
906 if (constr)
907 {
908 if (constr->centreX.GetDone())
909 return constr->centreX.GetValue();
910 else
911 return -1;
912 }
913 else
914 {
915 int x, y, w, h;
916 other->GetPosition(&x, &y);
917 other->GetSize(&w, &h);
918 return (int)(x + (w/2));
919 }
920 }
921 case wxCentreY:
922 {
923 wxLayoutConstraints *constr = other->GetConstraints();
924 // If no constraints, it means the window is not dependent
925 // on anything, and therefore we know its value immediately
926 if (constr)
927 {
928 if (constr->centreY.GetDone())
929 return constr->centreY.GetValue();
930 else
931 return -1;
932 }
933 else
934 {
935 int x, y, w, h;
936 other->GetPosition(&x, &y);
937 other->GetSize(&w, &h);
938 return (int)(y + (h/2));
939 }
940 }
941 default:
942 break;
c801d85f 943 }
f03fc89f 944 return -1;
c801d85f
KB
945}
946
a3622daa 947wxLayoutConstraints::wxLayoutConstraints()
c801d85f 948{
f03fc89f
VZ
949 left.SetEdge(wxLeft);
950 top.SetEdge(wxTop);
951 right.SetEdge(wxRight);
952 bottom.SetEdge(wxBottom);
953 centreX.SetEdge(wxCentreX);
954 centreY.SetEdge(wxCentreY);
955 width.SetEdge(wxWidth);
956 height.SetEdge(wxHeight);
c801d85f
KB
957}
958
f03fc89f 959bool wxLayoutConstraints::SatisfyConstraints(wxWindowBase *win, int *nChanges)
c801d85f 960{
f03fc89f
VZ
961 int noChanges = 0;
962
963 bool done = width.GetDone();
f644b28c 964 bool newDone = (done ? true : width.SatisfyConstraint(this, win));
f03fc89f
VZ
965 if (newDone != done)
966 noChanges ++;
967
968 done = height.GetDone();
f644b28c 969 newDone = (done ? true : height.SatisfyConstraint(this, win));
f03fc89f
VZ
970 if (newDone != done)
971 noChanges ++;
972
973 done = left.GetDone();
f644b28c 974 newDone = (done ? true : left.SatisfyConstraint(this, win));
f03fc89f
VZ
975 if (newDone != done)
976 noChanges ++;
977
978 done = top.GetDone();
f644b28c 979 newDone = (done ? true : top.SatisfyConstraint(this, win));
f03fc89f
VZ
980 if (newDone != done)
981 noChanges ++;
982
983 done = right.GetDone();
f644b28c 984 newDone = (done ? true : right.SatisfyConstraint(this, win));
f03fc89f
VZ
985 if (newDone != done)
986 noChanges ++;
987
988 done = bottom.GetDone();
f644b28c 989 newDone = (done ? true : bottom.SatisfyConstraint(this, win));
f03fc89f
VZ
990 if (newDone != done)
991 noChanges ++;
992
993 done = centreX.GetDone();
f644b28c 994 newDone = (done ? true : centreX.SatisfyConstraint(this, win));
f03fc89f
VZ
995 if (newDone != done)
996 noChanges ++;
997
998 done = centreY.GetDone();
f644b28c 999 newDone = (done ? true : centreY.SatisfyConstraint(this, win));
f03fc89f
VZ
1000 if (newDone != done)
1001 noChanges ++;
1002
1003 *nChanges = noChanges;
1004
1005 return AreSatisfied();
c801d85f
KB
1006}
1007
d427503c 1008#endif // wxUSE_CONSTRAINTS