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