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