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