create greyed image for wxBitmapButton in MSW automatically, as in wxGTK (replaces patch 1734018)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47483 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
e63807a8a4
commit
5f1f21d2a5
@ -36,15 +36,15 @@ public:
|
||||
}
|
||||
|
||||
// set the bitmaps
|
||||
void SetBitmapLabel(const wxBitmap& bitmap)
|
||||
virtual void SetBitmapLabel(const wxBitmap& bitmap)
|
||||
{ m_bmpNormal = bitmap; OnSetBitmap(); }
|
||||
void SetBitmapSelected(const wxBitmap& sel)
|
||||
virtual void SetBitmapSelected(const wxBitmap& sel)
|
||||
{ m_bmpSelected = sel; OnSetBitmap(); }
|
||||
void SetBitmapFocus(const wxBitmap& focus)
|
||||
virtual void SetBitmapFocus(const wxBitmap& focus)
|
||||
{ m_bmpFocus = focus; OnSetBitmap(); }
|
||||
void SetBitmapDisabled(const wxBitmap& disabled)
|
||||
virtual void SetBitmapDisabled(const wxBitmap& disabled)
|
||||
{ m_bmpDisabled = disabled; OnSetBitmap(); }
|
||||
void SetBitmapHover(const wxBitmap& hover)
|
||||
virtual void SetBitmapHover(const wxBitmap& hover)
|
||||
{ m_bmpHover = hover; OnSetBitmap(); }
|
||||
|
||||
// retrieve the bitmaps
|
||||
|
@ -19,7 +19,7 @@
|
||||
class WXDLLEXPORT wxBitmapButton : public wxBitmapButtonBase
|
||||
{
|
||||
public:
|
||||
wxBitmapButton() { }
|
||||
wxBitmapButton() { Init(); }
|
||||
|
||||
wxBitmapButton(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
@ -30,6 +30,8 @@ public:
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxButtonNameStr)
|
||||
{
|
||||
Init();
|
||||
|
||||
Create(parent, id, bitmap, pos, size, style, validator, name);
|
||||
}
|
||||
|
||||
@ -42,6 +44,13 @@ public:
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxButtonNameStr);
|
||||
|
||||
// override some base class methods to automatically synthesize the
|
||||
// disabled bitmap if it wasn't set by the user
|
||||
virtual void SetBitmapLabel(const wxBitmap& bitmap);
|
||||
virtual void SetBitmapFocus(const wxBitmap& focus);
|
||||
virtual void SetBitmapDisabled(const wxBitmap& disabled);
|
||||
virtual void SetBitmapHover(const wxBitmap& hover);
|
||||
|
||||
// Implementation
|
||||
virtual bool SetBackgroundColour(const wxColour& colour);
|
||||
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
|
||||
@ -50,9 +59,15 @@ public:
|
||||
virtual void DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg );
|
||||
|
||||
protected:
|
||||
// common part of all ctors
|
||||
void Init()
|
||||
{
|
||||
m_disabledSetByUser =
|
||||
m_hoverSetByUser = false;
|
||||
}
|
||||
|
||||
// reimplement some base class virtuals
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
virtual void OnSetBitmap();
|
||||
|
||||
// invalidate m_brushDisabled when system colours change
|
||||
void OnSysColourChanged(wxSysColourChangedEvent& event);
|
||||
@ -64,6 +79,13 @@ protected:
|
||||
// the brush we use to draw disabled buttons
|
||||
wxBrush m_brushDisabled;
|
||||
|
||||
// true if m_bmpDisabled was set by user, false if we created it ourselves
|
||||
// from m_bmpNormal
|
||||
bool m_disabledSetByUser;
|
||||
|
||||
// true if m_bmpHover was set by user, false if it was set from m_bmpFocus
|
||||
bool m_hoverSetByUser;
|
||||
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxBitmapButton)
|
||||
|
@ -130,7 +130,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
|
||||
const wxValidator& wxVALIDATOR_PARAM(validator),
|
||||
const wxString& name)
|
||||
{
|
||||
m_bmpNormal = bitmap;
|
||||
SetBitmapLabel(bitmap);
|
||||
SetName(name);
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
@ -224,7 +224,19 @@ void wxBitmapButton::OnMouseEnterOrLeave(wxMouseEvent& event)
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void wxBitmapButton::OnSetBitmap()
|
||||
void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
|
||||
{
|
||||
#if wxUSE_IMAGE
|
||||
if ( !HasFlag(wxBU_AUTODRAW) && !m_disabledSetByUser )
|
||||
{
|
||||
m_bmpDisabled = wxBitmap(bitmap.ConvertToImage().ConvertToGreyscale());
|
||||
}
|
||||
#endif // wxUSE_IMAGE
|
||||
|
||||
wxBitmapButtonBase::SetBitmapLabel(bitmap);
|
||||
}
|
||||
|
||||
void wxBitmapButton::SetBitmapFocus(const wxBitmap& focus)
|
||||
{
|
||||
// if the focus bitmap is specified but hover one isn't, use the focus
|
||||
// bitmap for hovering as well if this is consistent with the current
|
||||
@ -233,15 +245,26 @@ void wxBitmapButton::OnSetBitmap()
|
||||
// rationale: this is compatible with the old wxGTK behaviour and also
|
||||
// makes it much easier to do "the right thing" for all platforms (some of
|
||||
// them, such as Windows XP, have "hot" buttons while others don't)
|
||||
if ( !m_bmpHover.Ok() &&
|
||||
m_bmpFocus.Ok() &&
|
||||
wxUxThemeEngine::GetIfActive() )
|
||||
{
|
||||
if ( focus.Ok() && !m_hoverSetByUser )
|
||||
m_bmpHover = m_bmpFocus;
|
||||
}
|
||||
|
||||
// this will redraw us
|
||||
wxBitmapButtonBase::OnSetBitmap();
|
||||
wxBitmapButtonBase::SetBitmapFocus(focus);
|
||||
}
|
||||
|
||||
void wxBitmapButton::SetBitmapDisabled(const wxBitmap& disabled)
|
||||
{
|
||||
if ( disabled.IsOk() )
|
||||
m_disabledSetByUser = true;
|
||||
|
||||
wxBitmapButtonBase::SetBitmapDisabled(disabled);
|
||||
}
|
||||
|
||||
void wxBitmapButton::SetBitmapHover(const wxBitmap& hover)
|
||||
{
|
||||
if ( hover.IsOk() )
|
||||
m_hoverSetByUser = true;
|
||||
|
||||
wxBitmapButtonBase::SetBitmapHover(hover);
|
||||
}
|
||||
|
||||
#if wxUSE_UXTHEME
|
||||
|
Loading…
Reference in New Issue
Block a user