// ... and Windows
SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false);
SetDefaultStyle(this, true);
+
+ return winOldDefault;
+}
+
+// special version of wxGetTopLevelParent() which is safe to call when the
+// parent is being destroyed: wxGetTopLevelParent() would just return NULL in
+// this case because wxWindow version of IsTopLevel() is used when it's called
+// during window destruction instead of wxTLW one, but we want to distinguish
+// between these cases
+static wxTopLevelWindow *GetTLWParentIfNotBeingDeleted(wxWindow *win)
+{
+ for ( ; win; win = win->GetParent() )
+ {
+ if ( win->IsBeingDeleted() )
+ return NULL;
+
+ if ( win->IsTopLevel() )
+ break;
+ }
+
+ wxASSERT_MSG( win, _T("button without top level parent?") );
+
+ return wxDynamicCast(win, wxTopLevelWindow);
}
// set this button as being currently default
void wxButton::SetTmpDefault()
{
- wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
-
- wxCHECK_RET( tlw, _T("button without top level window?") );
+ wxTopLevelWindow * const tlw = GetTLWParentIfNotBeingDeleted(GetParent());
+ if ( !tlw )
+ return;
wxWindow *winOldDefault = tlw->GetDefaultItem();
tlw->SetTmpDefaultItem(this);
// unset this button as currently default, it may still stay permanent default
void wxButton::UnsetTmpDefault()
{
- wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
-
- wxCHECK_RET( tlw, _T("button without top level window?") );
+ wxTopLevelWindow * const tlw = GetTLWParentIfNotBeingDeleted(GetParent());
+ if ( !tlw )
+ return;
tlw->SetTmpDefaultItem(NULL);
// first we need to compute its bounding rect
RECT rc;
::CopyRect(&rc, pRect);
- ::DrawText(hdc, text, text.length(), &rc, DT_CENTER | DT_CALCRECT);
+ ::DrawText(hdc, text.wx_str(), text.length(), &rc,
+ DT_CENTER | DT_CALCRECT);
// now center this rect inside the entire button area
const LONG w = rc.right - rc.left;
rc.top = (pRect->bottom - pRect->top)/2 - h/2;
rc.bottom = rc.top+h;
- ::DrawText(hdc, text, text.length(), &rc, DT_CENTER);
+ ::DrawText(hdc, text.wx_str(), text.length(), &rc, DT_CENTER);
}
else // single line label
{
// Note: we must have DT_SINGLELINE for DT_VCENTER to work.
- ::DrawText(hdc, text, text.length(), pRect,
+ ::DrawText(hdc, text.wx_str(), text.length(), pRect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}