X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/789367e10d91dff77ed0069c4f5079eb7a00db09..ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 08361d58b6..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,8 +198,8 @@ bool wxButton::Create(wxWindow *parent, wxButton::~wxButton() { - wxWindow *parent = GetParent(); - if ( parent && parent->GetTmpDefaultItem() == this ) + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw && tlw->GetTmpDefaultItem() == this ) { UnsetTmpDefault(); } @@ -253,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(); @@ -344,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); @@ -359,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); @@ -373,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); @@ -402,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 @@ -817,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; @@ -848,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; }