X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cef55d6485619c56fb7af4c2cc23e8bbcb86b74f..efb27c04d3045a6db679ec14c6a88b1d2276665d:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index afb5670992..13f270d4c5 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -36,6 +36,7 @@ #include "wx/settings.h" #include "wx/dcscreen.h" #include "wx/dcclient.h" + #include "wx/toplevel.h" #endif #include "wx/stockitem.h" @@ -197,6 +198,11 @@ bool wxButton::Create(wxWindow *parent, wxButton::~wxButton() { + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw && tlw->GetTmpDefaultItem() == this ) + { + UnsetTmpDefault(); + } } // ---------------------------------------------------------------------------- @@ -248,7 +254,7 @@ wxSize wxButton::DoGetBestSize() const wxCoord wBtn, hBtn; - dc.GetMultiLineTextExtent(wxStripMenuCodes(GetLabel()), &wBtn, &hBtn); + dc.GetMultiLineTextExtent(GetLabelText(), &wBtn, &hBtn); // add a margin -- the button is wider than just its label wBtn += 3*GetCharWidth(); @@ -339,12 +345,12 @@ wxSize wxButtonBase::GetDefaultSize() // set this button as the (permanently) default one in its panel void wxButton::SetDefault() { - wxWindow *parent = GetParent(); + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - wxCHECK_RET( parent, _T("button without parent?") ); + wxCHECK_RET( tlw, _T("button without top level window?") ); // set this one as the default button both for wxWidgets ... - wxWindow *winOldDefault = parent->SetDefaultItem(this); + wxWindow *winOldDefault = tlw->SetDefaultItem(this); // ... and Windows SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false); @@ -354,12 +360,12 @@ void wxButton::SetDefault() // set this button as being currently default void wxButton::SetTmpDefault() { - wxWindow *parent = GetParent(); + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - wxCHECK_RET( parent, _T("button without parent?") ); + wxCHECK_RET( tlw, _T("button without top level window?") ); - wxWindow *winOldDefault = parent->GetDefaultItem(); - parent->SetTmpDefaultItem(this); + wxWindow *winOldDefault = tlw->GetDefaultItem(); + tlw->SetTmpDefaultItem(this); SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false); SetDefaultStyle(this, true); @@ -368,13 +374,13 @@ void wxButton::SetTmpDefault() // unset this button as currently default, it may still stay permanent default void wxButton::UnsetTmpDefault() { - wxWindow *parent = GetParent(); + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - wxCHECK_RET( parent, _T("button without parent?") ); + wxCHECK_RET( tlw, _T("button without top level window?") ); - parent->SetTmpDefaultItem(NULL); + tlw->SetTmpDefaultItem(NULL); - wxWindow *winOldDefault = parent->GetDefaultItem(); + wxWindow *winOldDefault = tlw->GetDefaultItem(); SetDefaultStyle(this, false); SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), true); @@ -397,10 +403,10 @@ wxButton::SetDefaultStyle(wxButton *btn, bool on) if ( !wxTheApp->IsActive() ) return; - wxWindow * const parent = btn->GetParent(); - wxCHECK_RET( parent, _T("button without parent?") ); + wxWindow * const tlw = wxGetTopLevelParent(btn); + wxCHECK_RET( tlw, _T("button without top level window?") ); - ::SendMessage(GetHwndOf(parent), DM_SETDEFID, btn->GetId(), 0L); + ::SendMessage(GetHwndOf(tlw), DM_SETDEFID, btn->GetId(), 0L); // sending DM_SETDEFID also changes the button style to // BS_DEFPUSHBUTTON so there is nothing more to do @@ -812,10 +818,10 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) bool selected = (state & ODS_SELECTED) != 0; if ( !selected ) { - wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); - if ( panel ) + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw ) { - selected = panel->GetDefaultItem() == this; + selected = tlw->GetDefaultItem() == this; } } bool pushed = (SendMessage(GetHwnd(), BM_GETSTATE, 0, 0) & BST_PUSHED) != 0; @@ -843,11 +849,10 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) } COLORREF colFg = wxColourToRGB(GetForegroundColour()); - DrawButtonText(hdc, &rectBtn, - (state & ODS_NOACCEL ? wxStripMenuCodes(GetLabel()) - : GetLabel()), - state & ODS_DISABLED ? GetSysColor(COLOR_GRAYTEXT) - : colFg); + if ( state & ODS_DISABLED ) colFg = GetSysColor(COLOR_GRAYTEXT) ; + wxString label = GetLabel(); + if ( state & ODS_NOACCEL ) label = GetLabelText() ; + DrawButtonText(hdc, &rectBtn, label, colFg); return true; }