X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/34636400a0018eba4a1f63dda18cf32e944b959e..7b8bd8182ca5ec9ed42d531b80fda479c2a2d7a1:/src/common/wincmn.cpp?ds=sidebyside diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index cd92991e22..2665e8d0ec 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -191,6 +191,16 @@ wxWindowBase::~wxWindowBase() wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") ); + // make sure that there are no dangling pointers left pointing to us + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + if ( panel ) + { + if ( panel->GetLastFocus() == this ) + { + panel->SetLastFocus((wxWindow *)NULL); + } + } + #if wxUSE_CARET if ( m_caret ) delete m_caret; @@ -316,14 +326,43 @@ void wxWindowBase::Centre(int direction) Move(new_x, new_y); } +// Center TopLevel windows over thier parent instead of the whole screen +void wxWindowBase::CentreOnParent(int direction) +{ + wxPoint ppos; + wxSize psze; + wxSize wsze; + wxWindow* parent = GetParent(); + int x, y; + + if (!parent || !IsTopLevel()) { + Centre(direction); + return; + } + + psze = parent->GetSize(); + ppos = parent->ClientToScreen(wxPoint(0,0)); + wsze = GetSize(); + + x = y = -1; + + if (direction == wxBOTH || direction == wxHORIZONTAL) + x = ppos.x + (psze.x - wsze.x)/2; + if (direction == wxBOTH || direction == wxVERTICAL) + y = ppos.y + (psze.y - wsze.y)/2; + + Move(x, y); +} + // fits the window around the children void wxWindowBase::Fit() { int maxX = 0, maxY = 0; - wxWindowList::Node *node = GetChildren().GetFirst(); - while ( node ) + for ( wxWindowList::Node *node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) { wxWindow *win = node->GetData(); if ( win->IsTopLevel() ) @@ -340,8 +379,6 @@ void wxWindowBase::Fit() maxX = wx + ww; if ( wy + wh > maxY ) maxY = wy + wh; - - node = node->GetNext(); } // leave a margin @@ -549,7 +586,7 @@ void wxWindowBase::SetCaret(wxCaret *caret) if ( m_caret ) { wxASSERT_MSG( m_caret->GetWindow() == this, - "caret should be created associated to this window" ); + _T("caret should be created associated to this window") ); } } #endif // wxUSE_CARET