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