X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7631a29204a5a6a14c3ab6697455c48928ba6600..bae41ce1922f02b8af69b4fffbf3b6a2183f9ba7:/src/common/wincmn.cpp diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 582ea1e9bb..bf4921ff5a 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; @@ -304,44 +314,27 @@ void wxWindowBase::Centre(int direction) int width, height; GetSize(&width, &height); - int new_x = -1, - new_y = -1; + int xNew = -1, + yNew = -1; if ( direction & wxHORIZONTAL ) - new_x = (widthParent - width)/2; + xNew = (widthParent - width)/2; if ( direction & wxVERTICAL ) - new_y = (heightParent - height)/2; + yNew = (heightParent - height)/2; - Move(new_x, new_y); -} + // controls are always centered on their parent because it doesn't make + // sense to centre them on the screen + if ( (direction & wxCENTER_FRAME) || wxDynamicCast(this, wxControl) ) + { + // adjust to the parents client area origin + wxPoint posParent = parent->ClientToScreen(wxPoint(0, 0)); -// 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; + xNew += posParent.x; + yNew += posParent.y; } - 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); + Move(xNew, yNew); } // fits the window around the children @@ -350,8 +343,9 @@ 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() ) @@ -368,8 +362,6 @@ void wxWindowBase::Fit() maxX = wx + ww; if ( wy + wh > maxY ) maxY = wy + wh; - - node = node->GetNext(); } // leave a margin @@ -1241,9 +1233,11 @@ wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) { int charWidth = GetCharWidth(); int charHeight = GetCharHeight(); - wxPoint pt2; - pt2.x = (int) ((pt.x * 4) / charWidth) ; - pt2.y = (int) ((pt.y * 8) / charHeight) ; + wxPoint pt2(-1, -1); + if (pt.x != -1) + pt2.x = (int) ((pt.x * 4) / charWidth) ; + if (pt.y != -1) + pt2.y = (int) ((pt.y * 8) / charHeight) ; return pt2; } @@ -1252,9 +1246,11 @@ wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) { int charWidth = GetCharWidth(); int charHeight = GetCharHeight(); - wxPoint pt2; - pt2.x = (int) ((pt.x * charWidth) / 4) ; - pt2.y = (int) ((pt.y * charHeight) / 8) ; + wxPoint pt2(-1, -1); + if (pt.x != -1) + pt2.x = (int) ((pt.x * charWidth) / 4) ; + if (pt.y != -1) + pt2.y = (int) ((pt.y * charHeight) / 8) ; return pt2; }