X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/772507f1f474d4ceee03e8e10f3628364aa33219..36cc39686ab0774ac2049ccfdea39e3fcfecafb2:/src/common/wincmn.cpp?ds=sidebyside diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 9cad968ed4..dd3822251d 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -159,11 +159,7 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent, const wxSize& WXUNUSED(size), long style, #if wxUSE_VALIDATORS -# if defined(__VISAGECPP__) - const wxValidator* validator, -# else const wxValidator& validator, -# endif #endif const wxString& name) { @@ -302,7 +298,7 @@ bool wxWindowBase::DestroyChildren() } // ---------------------------------------------------------------------------- -// centre/fit the window +// size/position related methods // ---------------------------------------------------------------------------- // centre the window with respect to its parent in either (or both) directions @@ -354,44 +350,62 @@ void wxWindowBase::Centre(int direction) yNew += posParent.y; } - // move the centre of this window to this position (not the upper left - // corner as it was done before) - Move(xNew - width / 2, yNew - height / 2); + // move the centre of this window to this position + Move(xNew, yNew); } // fits the window around the children void wxWindowBase::Fit() { - int maxX = 0, - maxY = 0; + if ( GetChildren().GetCount() > 0 ) + { + SetClientSize(DoGetBestSize()); + } + //else: do nothing if we have no children +} - for ( wxWindowList::Node *node = GetChildren().GetFirst(); - node; - node = node->GetNext() ) +// return the size best suited for the current window +wxSize wxWindowBase::DoGetBestSize() const +{ + if ( GetChildren().GetCount() > 0 ) { - wxWindow *win = node->GetData(); - if ( win->IsTopLevel() ) + // our minimal acceptable size is such that all our windows fit inside + int maxX = 0, + maxY = 0; + + for ( wxWindowList::Node *node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) { - // dialogs and frames lie in different top level windows - don't - // deal with them here - continue; + wxWindow *win = node->GetData(); + if ( win->IsTopLevel() ) + { + // dialogs and frames lie in different top level windows - + // don't deal with them here + continue; + } + + int wx, wy, ww, wh; + win->GetPosition(&wx, &wy); + win->GetSize(&ww, &wh); + if ( wx + ww > maxX ) + maxX = wx + ww; + if ( wy + wh > maxY ) + maxY = wy + wh; } - int wx, wy, ww, wh; - win->GetPosition(&wx, &wy); - win->GetSize(&ww, &wh); - if ( wx + ww > maxX ) - maxX = wx + ww; - if ( wy + wh > maxY ) - maxY = wy + wh; + // leave a margin + return wxSize(maxX + 7, maxY + 14); + } + else + { + // for a generic window there is no natural best size - just use the + // current one + return GetSize(); } - - // leave a margin - SetClientSize(maxX + 7, maxY + 14); } // set the min/max size of the window - void wxWindowBase::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) @@ -601,18 +615,6 @@ void wxWindowBase::SetCaret(wxCaret *caret) // validators // ---------------------------------------------------------------------------- -# if defined(__VISAGECPP__) -void wxWindowBase::SetValidator(const wxValidator* validator) -{ - if ( m_windowValidator ) - delete m_windowValidator; - - m_windowValidator = (wxValidator *)validator->Clone(); - - if ( m_windowValidator ) - m_windowValidator->SetWindow(this) ; -} -# else void wxWindowBase::SetValidator(const wxValidator& validator) { if ( m_windowValidator ) @@ -623,7 +625,6 @@ void wxWindowBase::SetValidator(const wxValidator& validator) if ( m_windowValidator ) m_windowValidator->SetWindow(this) ; } -# endif // __VISAGECPP__ #endif // wxUSE_VALIDATORS // ----------------------------------------------------------------------------