#include "wx/settings.h"
#include "wx/dcscreen.h"
#include "wx/dcclient.h"
+ #include "wx/toplevel.h"
#endif
#include "wx/stockitem.h"
wxButton::~wxButton()
{
- wxWindow *parent = GetParent();
- if ( parent && parent->GetTmpDefaultItem() == this )
+ wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+ if ( tlw && tlw->GetTmpDefaultItem() == this )
{
UnsetTmpDefault();
}
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();
// 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);
// 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);
// 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);
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
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;
}
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;
}