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