}
// 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
class WXDLLEXPORT wxBitmapButton : public wxBitmapButtonBase
{
public:
- wxBitmapButton() { }
+ wxBitmapButton() { Init(); }
wxBitmapButton(wxWindow *parent,
wxWindowID id,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxButtonNameStr)
{
+ Init();
+
Create(parent, id, bitmap, pos, size, style, validator, name);
}
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);
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);
// 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)
const wxValidator& wxVALIDATOR_PARAM(validator),
const wxString& name)
{
- m_bmpNormal = bitmap;
+ SetBitmapLabel(bitmap);
SetName(name);
#if wxUSE_VALIDATORS
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
// 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