X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4e00f54113a7d86b94a839b0f4c1a2fca54a3001..b6a20a20d010d643e52914f51aa0700df0da925f:/src/common/layout.cpp diff --git a/src/common/layout.cpp b/src/common/layout.cpp index 3b9ec73f6f..170ba303a0 100644 --- a/src/common/layout.cpp +++ b/src/common/layout.cpp @@ -5,8 +5,8 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================= @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "layout.h" #endif @@ -66,13 +66,21 @@ wxIndividualLayoutConstraint::~wxIndividualLayoutConstraint() void wxIndividualLayoutConstraint::Set(wxRelationship rel, wxWindowBase *otherW, wxEdge otherE, int val, int marg) { + if (rel == wxSameAs) + { + // If Set is called by the user with wxSameAs then call SameAs to do + // it since it will actually use wxPercent instead. + SameAs(otherW, otherE, marg); + return; + } + relationship = rel; otherWin = otherW; otherEdge = otherE; if ( rel == wxPercentOf ) { - percentage = val; + percent = val; } else { @@ -106,13 +114,13 @@ void wxIndividualLayoutConstraint::Below(wxWindowBase *sibling, int marg) // 'Same edge' alignment // void wxIndividualLayoutConstraint::SameAs(wxWindowBase *otherW, wxEdge edge, int marg) -{ +{ Set(wxPercentOf, otherW, edge, 100, marg); } // The edge is a percentage of the other window's edge void wxIndividualLayoutConstraint::PercentOf(wxWindowBase *otherW, wxEdge wh, int per) -{ +{ Set(wxPercentOf, otherW, wh, per); } @@ -121,7 +129,8 @@ void wxIndividualLayoutConstraint::PercentOf(wxWindowBase *otherW, wxEdge wh, in // void wxIndividualLayoutConstraint::Absolute(int val) { - value = val; relationship = wxAbsolute; + value = val; + relationship = wxAbsolute; } // Reset constraint if it mentions otherWin @@ -138,8 +147,8 @@ bool wxIndividualLayoutConstraint::ResetIfWin(wxWindowBase *otherW) otherWin = (wxWindowBase *) NULL; return TRUE; } - else - return FALSE; + + return FALSE; } // Try to satisfy constraint @@ -725,7 +734,7 @@ int wxIndividualLayoutConstraint::GetEdge(wxEdge which, // If the edge or dimension belongs to the parent, then we know the // dimension is obtainable immediately. E.g. a wxExpandSizer may contain a // button (but the button's true parent is a panel, not the sizer) - if (other->GetChildren().Find(thisWin)) + if (other->GetChildren().Find((wxWindow*)thisWin)) { switch (which) { @@ -1004,134 +1013,4 @@ bool wxLayoutConstraints::SatisfyConstraints(wxWindowBase *win, int *nChanges) return AreSatisfied(); } -/* - * Main constrained layout algorithm. Look at all the child - * windows, and their constraints (if any). - * The idea is to keep iterating through the constraints - * until all left, right, bottom and top edges, and widths and heights, - * are known (or no change occurs and we've failed to resolve all - * constraints). - * - * If the user has not specified a dimension or edge, it will be - * be calculated from the other known values. E.g. If we know - * the right hand edge and the left hand edge, we now know the width. - * The snag here is that this means we must specify absolute dimensions - * twice (in constructor and in constraint), if we wish to use the - * constraint notation to just set the position, for example. - * Otherwise, if we only set ONE edge and no dimension, it would never - * find the other edge. - * - * Algorithm: - - Mark all constraints as not done. - - iterations = 0; - until no change or iterations >= max iterations - For each child: - { - Calculate all constraints - } - iterations ++; - - For each child - Set each calculated position and size - - */ - -#if WXWIN_COMPATIBILITY -bool wxOldDoLayout(wxWindowBase *win) -{ - // Make sure this isn't called recursively from below - static wxList doneSoFar; - - if (doneSoFar.Member(win)) - return TRUE; - - doneSoFar.Append(win); - - wxNode *node = win->GetChildren().First(); - while (node) - { - wxWindowBase *child = (wxWindowBase *)node->Data(); - wxLayoutConstraints *constr = child->GetConstraints(); - if (constr) - { - constr->left.SetDone(FALSE); - constr->top.SetDone(FALSE); - constr->right.SetDone(FALSE); - constr->bottom.SetDone(FALSE); - constr->width.SetDone(FALSE); - constr->height.SetDone(FALSE); - constr->centreX.SetDone(FALSE); - constr->centreY.SetDone(FALSE); - } - node = node->Next(); - } - int noIterations = 0; - int maxIterations = 500; - int noChanges = 1; - - while ((noChanges > 0) && (noIterations < maxIterations)) - { - noChanges = 0; - wxNode *node = win->GetChildren().First(); - while (node) - { - wxWindowBase *child = (wxWindowBase *)node->Data(); - wxLayoutConstraints *constr = child->GetConstraints(); - if (constr) - { - int tempNoChanges = 0; - (void)constr->SatisfyConstraints(child, &tempNoChanges); - noChanges += tempNoChanges; - } - node = node->Next(); - } - noIterations ++; - } -/* - // Would be nice to have a test here to see _which_ constraint(s) - // failed, so we can print a specific diagnostic message. - if (noFailures > 0) - { - wxDebugMsg(_("wxWindowBase::Layout() failed.\n")); - } -*/ - // Now set the sizes and positions of the children, and - // recursively call Layout(). - node = win->GetChildren().First(); - while (node) - { - wxWindowBase *child = (wxWindowBase *)node->Data(); - wxLayoutConstraints *constr = child->GetConstraints(); - if (constr && constr->left.GetDone() && constr->right.GetDone() && - constr->width.GetDone() && constr->height.GetDone()) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - int w = constr->width.GetValue(); - int h = constr->height.GetValue(); - - // If we don't want to resize this window, just move it... - if ((constr->width.GetRelationship() != wxAsIs) || - (constr->height.GetRelationship() != wxAsIs)) - { - // _Should_ call Layout() recursively. - child->SetSize(x, y, w, h); - } - else - { - child->Move(x, y); - } - } - else - child->Layout(); - node = node->Next(); - } - doneSoFar.DeleteObject(win); - - return TRUE; -} -#endif // WXWIN_COMPATIBILITY - #endif // wxUSE_CONSTRAINTS