implement wxBitmapButton as just a wrapper for wxButton under MSW

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61071 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-06-15 23:10:16 +00:00
parent 4e00b90802
commit a6fd73d33a
6 changed files with 130 additions and 508 deletions

View File

@@ -16,10 +16,14 @@
#if wxUSE_BMPBUTTON
#include "wx/bitmap.h"
#include "wx/button.h"
extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
// FIXME: right now only wxMSW implements bitmap support in wxButton
// itself, this shouldn't be used for the other platforms neither
// when all of them do it
#ifdef __WXMSW__
#define wxHAS_BUTTON_BITMAP
#endif
// ----------------------------------------------------------------------------
// wxBitmapButton: a button which shows bitmaps instead of the usual string.
@@ -31,18 +35,25 @@ class WXDLLIMPEXP_CORE wxBitmapButtonBase : public wxButton
public:
wxBitmapButtonBase()
{
#ifndef wxHAS_BUTTON_BITMAP
m_marginX =
m_marginY = 0;
#endif // wxHAS_BUTTON_BITMAP
}
// set/get the margins around the button
virtual void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
int GetMarginX() const { return m_marginX; }
int GetMarginY() const { return m_marginY; }
virtual void SetMargins(int x, int y)
{
DoSetBitmapMargins(x, y);
}
int GetMarginX() const { return DoGetBitmapMargins().x; }
int GetMarginY() const { return DoGetBitmapMargins().y; }
// deprecated synonym for SetBitmapLabel()
#if WXWIN_COMPATIBILITY_2_6
wxDEPRECATED( void SetLabel(const wxBitmap& bitmap) );
wxDEPRECATED_INLINE( void SetLabel(const wxBitmap& bitmap).
SetBitmapLabel(bitmap); );
// prevent virtual function hiding
virtual void SetLabel(const wxString& label)
@@ -50,6 +61,7 @@ public:
#endif // WXWIN_COMPATIBILITY_2_6
protected:
#ifndef wxHAS_BUTTON_BITMAP
// function called when any of the bitmaps changes
virtual void OnSetBitmap() { InvalidateBestSize(); Refresh(); }
@@ -57,24 +69,28 @@ protected:
virtual void DoSetBitmap(const wxBitmap& bitmap, State which)
{ m_bitmaps[which] = bitmap; OnSetBitmap(); }
virtual wxSize DoGetBitmapMargins() const
{
return wxSize(m_marginX, m_marginY);
}
virtual void DoSetBitmapMargins(int x, int y)
{
m_marginX = x;
m_marginY = y;
}
// the bitmaps for various states
wxBitmap m_bitmaps[State_Max];
// the margins around the bitmap
int m_marginX,
m_marginY;
#endif // !wxHAS_BUTTON_BITMAP
wxDECLARE_NO_COPY_CLASS(wxBitmapButtonBase);
};
#if WXWIN_COMPATIBILITY_2_6
inline void wxBitmapButtonBase::SetLabel(const wxBitmap& bitmap)
{
SetBitmapLabel(bitmap);
}
#endif // WXWIN_COMPATIBILITY_2_6
#if defined(__WXUNIVERSAL__)
#include "wx/univ/bmpbuttn.h"
#elif defined(__WXMSW__)

View File

@@ -155,8 +155,13 @@ protected:
virtual void DoSetBitmap(const wxBitmap& WXUNUSED(bitmap),
State WXUNUSED(which))
{ }
virtual wxSize DoGetBitmapMargins() const
{ return wxSize(0, 0); }
virtual void DoSetBitmapMargins(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
{ }
virtual void DoSetBitmapPosition(wxDirection WXUNUSED(dir))
{ }

View File

@@ -44,13 +44,6 @@ public:
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxButtonNameStr);
// Implementation
virtual bool SetBackgroundColour(const wxColour& colour);
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
virtual void DrawFace( WXHDC dc, int left, int top, int right, int bottom, bool sel );
virtual void DrawButtonFocus( WXHDC dc, int left, int top, int right, int bottom, bool sel );
virtual void DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg );
protected:
// common part of all ctors
void Init()
@@ -60,22 +53,8 @@ protected:
}
// reimplement some base class virtuals
virtual wxSize DoGetBestSize() const;
virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
// invalidate m_brushDisabled when system colours change
void OnSysColourChanged(wxSysColourChangedEvent& event);
// change the currently bitmap if we have a hover one
void OnMouseEnterOrLeave(wxMouseEvent& event);
// the brush we use to draw disabled buttons
wxBrush m_brushDisabled;
// true if disabled bitmap was set by user, false if we created it
// ourselves from the normal one
bool m_disabledSetByUser;

View File

@@ -82,6 +82,7 @@ protected:
virtual wxBitmap DoGetBitmap(State which) const;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
virtual wxSize DoGetBitmapMargins() const;
virtual void DoSetBitmapMargins(wxCoord x, wxCoord y);
virtual void DoSetBitmapPosition(wxDirection dir);