Allow using wxBitmapBundle for wxButton bitmaps

Take wxBitmapBundle in wxButton::SetBitmapLabel() and related functions
in order to be able to associate several bitmaps to be used in different
resolutions with the button, instead of just a single bitmap.
This commit is contained in:
Vadim Zeitlin
2021-10-10 19:32:43 +01:00
parent 2910327ef3
commit 4e5d2d97e2
36 changed files with 223 additions and 175 deletions

View File

@@ -41,7 +41,7 @@
#define wxBU_NOTEXT 0x0002 #define wxBU_NOTEXT 0x0002
#include "wx/bitmap.h" #include "wx/bmpbndl.h"
#include "wx/control.h" #include "wx/control.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -55,7 +55,7 @@ public:
// show the image in the button in addition to the label: this method is // show the image in the button in addition to the label: this method is
// supported on all (major) platforms // supported on all (major) platforms
void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT) void SetBitmap(const wxBitmapBundle& bitmap, wxDirection dir = wxLEFT)
{ {
SetBitmapLabel(bitmap); SetBitmapLabel(bitmap);
SetBitmapPosition(dir); SetBitmapPosition(dir);
@@ -71,15 +71,15 @@ public:
// SetBitmapXXX() methods (except for SetBitmapLabel() which is a synonym // SetBitmapXXX() methods (except for SetBitmapLabel() which is a synonym
// for it anyhow) and that all bitmaps passed to these functions should be // for it anyhow) and that all bitmaps passed to these functions should be
// of the same size. // of the same size.
void SetBitmapLabel(const wxBitmap& bitmap) void SetBitmapLabel(const wxBitmapBundle& bitmap)
{ DoSetBitmap(bitmap, State_Normal); } { DoSetBitmap(bitmap, State_Normal); }
void SetBitmapPressed(const wxBitmap& bitmap) void SetBitmapPressed(const wxBitmapBundle& bitmap)
{ DoSetBitmap(bitmap, State_Pressed); } { DoSetBitmap(bitmap, State_Pressed); }
void SetBitmapDisabled(const wxBitmap& bitmap) void SetBitmapDisabled(const wxBitmapBundle& bitmap)
{ DoSetBitmap(bitmap, State_Disabled); } { DoSetBitmap(bitmap, State_Disabled); }
void SetBitmapCurrent(const wxBitmap& bitmap) void SetBitmapCurrent(const wxBitmapBundle& bitmap)
{ DoSetBitmap(bitmap, State_Current); } { DoSetBitmap(bitmap, State_Current); }
void SetBitmapFocus(const wxBitmap& bitmap) void SetBitmapFocus(const wxBitmapBundle& bitmap)
{ DoSetBitmap(bitmap, State_Focused); } { DoSetBitmap(bitmap, State_Focused); }
wxBitmap GetBitmapLabel() const { return DoGetBitmap(State_Normal); } wxBitmap GetBitmapLabel() const { return DoGetBitmap(State_Normal); }
@@ -113,6 +113,7 @@ public:
// backwards compatible names for pressed/current bitmaps: they're not // backwards compatible names for pressed/current bitmaps: they're not
// deprecated as there is nothing really wrong with using them and no real // deprecated as there is nothing really wrong with using them and no real
// advantage to using the new names but the new names are still preferred // advantage to using the new names but the new names are still preferred
// (and need to be used when using wxBitmapBundle and not just wxBitmap)
wxBitmap GetBitmapSelected() const { return GetBitmapPressed(); } wxBitmap GetBitmapSelected() const { return GetBitmapPressed(); }
wxBitmap GetBitmapHover() const { return GetBitmapCurrent(); } wxBitmap GetBitmapHover() const { return GetBitmapCurrent(); }
@@ -161,7 +162,7 @@ protected:
virtual wxBitmap DoGetBitmap(State WXUNUSED(which)) const virtual wxBitmap DoGetBitmap(State WXUNUSED(which)) const
{ return wxBitmap(); } { return wxBitmap(); }
virtual void DoSetBitmap(const wxBitmap& WXUNUSED(bitmap), virtual void DoSetBitmap(const wxBitmapBundle& WXUNUSED(bitmap),
State WXUNUSED(which)) State WXUNUSED(which))
{ } { }

View File

@@ -99,8 +99,9 @@ protected:
// function called when any of the bitmaps changes // function called when any of the bitmaps changes
virtual void OnSetBitmap() { InvalidateBestSize(); Refresh(); } virtual void OnSetBitmap() { InvalidateBestSize(); Refresh(); }
virtual wxBitmap DoGetBitmap(State which) const { return m_bitmaps[which]; } virtual wxBitmap DoGetBitmap(State which) const
virtual void DoSetBitmap(const wxBitmap& bitmap, State which) { return m_bitmaps[which].GetBitmap(wxDefaultSize); }
virtual void DoSetBitmap(const wxBitmapBundle& bitmap, State which)
{ m_bitmaps[which] = bitmap; OnSetBitmap(); } { m_bitmaps[which] = bitmap; OnSetBitmap(); }
virtual wxSize DoGetBitmapMargins() const virtual wxSize DoGetBitmapMargins() const
@@ -114,8 +115,8 @@ protected:
m_marginY = y; m_marginY = y;
} }
// the bitmaps for various states // the bitmap bundles for various states
wxBitmap m_bitmaps[State_Max]; wxBitmapBundle m_bitmaps[State_Max];
// the margins around the bitmap // the margins around the bitmap
int m_marginX, int m_marginX,

View File

@@ -42,7 +42,7 @@ protected:
virtual void DoEnable(bool enable) wxOVERRIDE; virtual void DoEnable(bool enable) wxOVERRIDE;
virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE; virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which) wxOVERRIDE; virtual void DoSetBitmap(const wxBitmapBundle& bitmap, State which) wxOVERRIDE;
virtual void DoSetBitmapPosition(wxDirection dir) wxOVERRIDE; virtual void DoSetBitmapPosition(wxDirection dir) wxOVERRIDE;
// update the bitmap to correspond to the current button state // update the bitmap to correspond to the current button state
@@ -60,13 +60,13 @@ private:
State GTKGetCurrentBitmapState() const; State GTKGetCurrentBitmapState() const;
// show the given bitmap (must be valid) // show the given bitmap (must be valid)
void GTKDoShowBitmap(const wxBitmap& bitmap); void GTKDoShowBitmap(const wxBitmapBundle& bitmap);
// the bitmaps for the different state of the buttons, all of them may be // the bitmaps for the different state of the buttons, all of them may be
// invalid and the button only shows a bitmap at all if State_Normal bitmap // invalid and the button only shows a bitmap at all if State_Normal bitmap
// is valid // is valid
wxBitmap m_bitmaps[State_Max]; wxBitmapBundle m_bitmaps[State_Max];
// true iff mouse is currently over the button // true iff mouse is currently over the button
bool m_isCurrent; bool m_isCurrent;

View File

@@ -20,7 +20,7 @@ public:
wxBitmapButton(wxWindow *parent, wxBitmapButton(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
@@ -32,7 +32,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,

View File

@@ -21,7 +21,7 @@ public:
wxBitmapButton(wxWindow *parent, wxBitmapButton(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
@@ -35,7 +35,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
@@ -47,7 +47,7 @@ public:
const wxString& name = wxString()); const wxString& name = wxString());
void SetLabel( const wxString &label ); void SetLabel( const wxString &label );
virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); } virtual void SetLabel( const wxBitmapBundle& bitmap ) { SetBitmapLabel(bitmap); }
virtual bool Enable(bool enable = TRUE); virtual bool Enable(bool enable = TRUE);

View File

@@ -20,7 +20,8 @@ class WXDLLIMPEXP_CORE wxBitmapButton: public wxBitmapButtonBase
public: public:
wxBitmapButton(); wxBitmapButton();
virtual ~wxBitmapButton(); virtual ~wxBitmapButton();
wxBitmapButton(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, wxBitmapButton(wxWindow *parent, wxWindowID id,
const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
@@ -29,7 +30,8 @@ public:
Create(parent, id, bitmap, pos, size, style, validator, name); Create(parent, id, bitmap, pos, size, style, validator, name);
} }
bool Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, bool Create(wxWindow *parent, wxWindowID id,
const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
@@ -44,12 +46,12 @@ public:
protected: protected:
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which); virtual void DoSetBitmap(const wxBitmapBundle& bitmap, State which);
virtual void OnSetBitmap(); virtual void OnSetBitmap();
// original bitmaps may be different from the ones we were initialized with // original bitmaps may be different from the ones we were initialized with
// if they were changed to reflect button background colour // if they were changed to reflect button background colour
wxBitmap m_bitmapsOriginal[State_Max]; wxBitmapBundle m_bitmapsOriginal[State_Max];
wxBitmapCache m_bitmapCache; wxBitmapCache m_bitmapCache;

View File

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

View File

@@ -22,7 +22,7 @@ public:
wxBitmapButton(wxWindow *parent, wxBitmapButton(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
@@ -34,7 +34,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,

View File

@@ -27,7 +27,7 @@ protected:
void OnLeaveWindow( wxMouseEvent& event); void OnLeaveWindow( wxMouseEvent& event);
virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE; virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which) wxOVERRIDE; virtual void DoSetBitmap(const wxBitmapBundle& bitmapBundle, State which) wxOVERRIDE;
virtual void DoSetBitmapPosition(wxDirection dir) wxOVERRIDE; virtual void DoSetBitmapPosition(wxDirection dir) wxOVERRIDE;
virtual void DoSetBitmapMargins(int x, int y) wxOVERRIDE virtual void DoSetBitmapMargins(int x, int y) wxOVERRIDE
@@ -49,7 +49,7 @@ protected:
// the bitmaps for the different state of the buttons, all of them may be // the bitmaps for the different state of the buttons, all of them may be
// invalid and the button only shows a bitmap at all if State_Normal bitmap // invalid and the button only shows a bitmap at all if State_Normal bitmap
// is valid // is valid
wxBitmap m_bitmaps[State_Max]; wxBitmapBundle m_bitmaps[State_Max];
wxDECLARE_NO_COPY_CLASS(wxAnyButton); wxDECLARE_NO_COPY_CLASS(wxAnyButton);
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();

View File

@@ -22,7 +22,7 @@ public:
{ {
} }
wxBitmapButton(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, wxBitmapButton(wxWindow *parent, wxWindowID id, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
@@ -31,7 +31,7 @@ public:
Create(parent, id, bitmap, pos, size, style, validator, name); Create(parent, id, bitmap, pos, size, style, validator, name);
} }
bool Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, bool Create(wxWindow *parent, wxWindowID id, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,

View File

@@ -140,7 +140,7 @@ public :
wxInt32 GetValue() const wxOVERRIDE; wxInt32 GetValue() const wxOVERRIDE;
void SetValue( wxInt32 v ) wxOVERRIDE; void SetValue( wxInt32 v ) wxOVERRIDE;
wxBitmap GetBitmap() const wxOVERRIDE; wxBitmap GetBitmap() const wxOVERRIDE;
void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE; void SetBitmap( const wxBitmapBundle& bitmap ) wxOVERRIDE;
void SetBitmapPosition( wxDirection dir ) wxOVERRIDE; void SetBitmapPosition( wxDirection dir ) wxOVERRIDE;
void SetupTabs( const wxNotebook &notebook ) wxOVERRIDE; void SetupTabs( const wxNotebook &notebook ) wxOVERRIDE;
void GetBestRect( wxRect *r ) const wxOVERRIDE; void GetBestRect( wxRect *r ) const wxOVERRIDE;
@@ -356,12 +356,12 @@ class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
{ {
public: public:
wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v); wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v);
virtual void SetBitmap(const wxBitmap& bitmap) wxOVERRIDE; virtual void SetBitmap(const wxBitmapBundle& bitmap) wxOVERRIDE;
#if wxUSE_MARKUP #if wxUSE_MARKUP
virtual void SetLabelMarkup(const wxString& markup) wxOVERRIDE; virtual void SetLabelMarkup(const wxString& markup) wxOVERRIDE;
#endif // wxUSE_MARKUP #endif // wxUSE_MARKUP
void SetPressedBitmap( const wxBitmap& bitmap ) wxOVERRIDE; void SetPressedBitmap( const wxBitmapBundle& bitmap ) wxOVERRIDE;
void GetLayoutInset(int &left, int &top, int &right, int &bottom) const wxOVERRIDE; void GetLayoutInset(int &left, int &top, int &right, int &bottom) const wxOVERRIDE;
void SetAcceleratorFromLabel(const wxString& label); void SetAcceleratorFromLabel(const wxString& label);

View File

@@ -74,7 +74,7 @@ WXDLLIMPEXP_BASE CFURLRef wxOSXCreateURLFromFileSystemPath( const wxString& path
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#endif #endif
#include "wx/bitmap.h" #include "wx/bmpbndl.h"
#include "wx/window.h" #include "wx/window.h"
class wxTextProofOptions; class wxTextProofOptions;
@@ -337,7 +337,7 @@ public :
virtual wxInt32 GetValue() const = 0; virtual wxInt32 GetValue() const = 0;
virtual void SetValue( wxInt32 v ) = 0; virtual void SetValue( wxInt32 v ) = 0;
virtual wxBitmap GetBitmap() const = 0; virtual wxBitmap GetBitmap() const = 0;
virtual void SetBitmap( const wxBitmap& bitmap ) = 0; virtual void SetBitmap( const wxBitmapBundle& bitmap ) = 0;
virtual void SetBitmapPosition( wxDirection dir ) = 0; virtual void SetBitmapPosition( wxDirection dir ) = 0;
virtual void SetupTabs( const wxNotebook& WXUNUSED(notebook) ) {} virtual void SetupTabs( const wxNotebook& WXUNUSED(notebook) ) {}
virtual int TabHitTest( const wxPoint & WXUNUSED(pt), long *flags ) {*flags=1; return -1;} virtual int TabHitTest( const wxPoint & WXUNUSED(pt), long *flags ) {*flags=1; return -1;}
@@ -491,7 +491,7 @@ public :
static wxWidgetImplType* CreateBitmapToggleButton( wxWindowMac* wxpeer, static wxWidgetImplType* CreateBitmapToggleButton( wxWindowMac* wxpeer,
wxWindowMac* parent, wxWindowMac* parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
@@ -500,7 +500,7 @@ public :
static wxWidgetImplType* CreateBitmapButton( wxWindowMac* wxpeer, static wxWidgetImplType* CreateBitmapButton( wxWindowMac* wxpeer,
wxWindowMac* parent, wxWindowMac* parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
@@ -828,7 +828,7 @@ class wxButtonImpl
wxButtonImpl(){} wxButtonImpl(){}
virtual ~wxButtonImpl(){} virtual ~wxButtonImpl(){}
virtual void SetPressedBitmap( const wxBitmap& bitmap ) = 0; virtual void SetPressedBitmap( const wxBitmapBundle& bitmap ) = 0;
} ; } ;
// //

View File

@@ -90,7 +90,7 @@ public :
void SetValue( wxInt32 v ); void SetValue( wxInt32 v );
virtual wxBitmap GetBitmap() const; virtual wxBitmap GetBitmap() const;
virtual void SetBitmap( const wxBitmap& bitmap ); virtual void SetBitmap( const wxBitmapBundle& bitmap );
virtual void SetBitmapPosition( wxDirection dir ); virtual void SetBitmapPosition( wxDirection dir );
void SetupTabs( const wxNotebook &notebook ); void SetupTabs( const wxNotebook &notebook );

View File

@@ -33,18 +33,18 @@ public:
protected: protected:
virtual wxBitmap DoGetBitmap(State state) const wxOVERRIDE; virtual wxBitmap DoGetBitmap(State state) const wxOVERRIDE;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which) wxOVERRIDE; virtual void DoSetBitmap(const wxBitmapBundle& bitmap, State which) wxOVERRIDE;
QPushButton *m_qtPushButton; QPushButton *m_qtPushButton;
void QtCreate(wxWindow *parent); void QtCreate(wxWindow *parent);
void QtSetBitmap( const wxBitmap &bitmap ); void QtSetBitmap( const wxBitmapBundle &bitmap );
private: private:
State QtGetCurrentState() const; State QtGetCurrentState() const;
typedef wxAnyButtonBase base_type; typedef wxAnyButtonBase base_type;
wxBitmap m_bitmaps[State_Max]; wxBitmapBundle m_bitmaps[State_Max];
wxDECLARE_NO_COPY_CLASS(wxAnyButton); wxDECLARE_NO_COPY_CLASS(wxAnyButton);
}; };

View File

@@ -15,7 +15,7 @@ public:
wxBitmapButton(wxWindow *parent, wxBitmapButton(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
@@ -24,7 +24,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,

View File

@@ -18,7 +18,7 @@ public:
wxBitmapButton(wxWindow *parent, wxBitmapButton(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
@@ -30,7 +30,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,

View File

@@ -11,8 +11,6 @@
#ifndef _WX_UNIV_BUTTON_H_ #ifndef _WX_UNIV_BUTTON_H_
#define _WX_UNIV_BUTTON_H_ #define _WX_UNIV_BUTTON_H_
#include "wx/bitmap.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// the actions supported by this control // the actions supported by this control
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -32,7 +30,7 @@ public:
wxButton() { Init(); } wxButton() { Init(); }
wxButton(wxWindow *parent, wxButton(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxString& label = wxEmptyString, const wxString& label = wxEmptyString,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
@@ -74,7 +72,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxString& label = wxEmptyString, const wxString& label = wxEmptyString,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
@@ -97,7 +95,7 @@ public:
protected: protected:
virtual void DoSetBitmap(const wxBitmap& bitmap, State which) wxOVERRIDE; virtual void DoSetBitmap(const wxBitmapBundle& bitmap, State which) wxOVERRIDE;
virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE; virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE;
virtual void DoSetBitmapMargins(wxCoord x, wxCoord y) wxOVERRIDE; virtual void DoSetBitmapMargins(wxCoord x, wxCoord y) wxOVERRIDE;

View File

@@ -105,8 +105,11 @@ public:
states. states.
@param bitmap @param bitmap
The bitmap to display in the button. If the bitmap is invalid, any The bitmap bundle containing the resolution-dependent bitmaps to
currently shown bitmaps are removed from the button. display in the button. At default DPI, the size of the bitmap is
determined by the default bundle size, i.e. the value returned from
wxBitmapBundle::GetDefaultSize(). If the bitmap bundle is invalid,
any currently shown bitmaps are removed from the button.
@param dir @param dir
The position of the bitmap inside the button. By default it is The position of the bitmap inside the button. By default it is
positioned to the left of the text, near to the left button border. positioned to the left of the text, near to the left button border.
@@ -116,7 +119,7 @@ public:
@since 2.9.1 @since 2.9.1
*/ */
void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT); void SetBitmap(const wxBitmapBundle& bitmap, wxDirection dir = wxLEFT);
/** /**
Sets the bitmap to be shown when the mouse is over the button. Sets the bitmap to be shown when the mouse is over the button.
@@ -129,7 +132,7 @@ public:
@since 2.9.1 (available as wxBitmapButton::SetBitmapHover() in previous @since 2.9.1 (available as wxBitmapButton::SetBitmapHover() in previous
versions) versions)
*/ */
void SetBitmapCurrent(const wxBitmap& bitmap); void SetBitmapCurrent(const wxBitmapBundle& bitmap);
/** /**
Sets the bitmap for the disabled button appearance. Sets the bitmap for the disabled button appearance.
@@ -145,7 +148,7 @@ public:
@since 2.9.1 (available in wxBitmapButton only in previous versions) @since 2.9.1 (available in wxBitmapButton only in previous versions)
*/ */
void SetBitmapDisabled(const wxBitmap& bitmap); void SetBitmapDisabled(const wxBitmapBundle& bitmap);
/** /**
Sets the bitmap for the button appearance when it has the keyboard Sets the bitmap for the button appearance when it has the keyboard
@@ -159,7 +162,7 @@ public:
@since 2.9.1 (available in wxBitmapButton only in previous versions) @since 2.9.1 (available in wxBitmapButton only in previous versions)
*/ */
void SetBitmapFocus(const wxBitmap& bitmap); void SetBitmapFocus(const wxBitmapBundle& bitmap);
/** /**
Sets the bitmap label for the button. Sets the bitmap label for the button.
@@ -171,7 +174,7 @@ public:
@since 2.9.1 (available in wxBitmapButton only in previous versions) @since 2.9.1 (available in wxBitmapButton only in previous versions)
*/ */
void SetBitmapLabel(const wxBitmap& bitmap); void SetBitmapLabel(const wxBitmapBundle& bitmap);
/** /**
Sets the bitmap for the selected (depressed) button appearance. Sets the bitmap for the selected (depressed) button appearance.
@@ -179,7 +182,7 @@ public:
@since 2.9.1 (available as wxBitmapButton::SetBitmapSelected() in @since 2.9.1 (available as wxBitmapButton::SetBitmapSelected() in
previous versions) previous versions)
*/ */
void SetBitmapPressed(const wxBitmap& bitmap); void SetBitmapPressed(const wxBitmapBundle& bitmap);
/** /**

View File

@@ -111,8 +111,8 @@ protected:
// (re)create the wxButton // (re)create the wxButton
void CreateButton(); void CreateButton();
// helper function: create a bitmap for wxBitmapButton // helper function: create a bitmap bundle for wxBitmapButton
wxBitmap CreateBitmap(const wxString& label, const wxArtID& type); wxBitmapBundle CreateBitmap(const wxString& label, const wxArtID& type);
// the controls // the controls
@@ -691,7 +691,8 @@ void ButtonWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event))
// bitmap button stuff // bitmap button stuff
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxBitmap ButtonWidgetsPage::CreateBitmap(const wxString& label, const wxArtID& type) wxBitmapBundle
ButtonWidgetsPage::CreateBitmap(const wxString& label, const wxArtID& type)
{ {
wxBitmap bmp(FromDIP(wxSize(180, 70))); // shouldn't hardcode but it's simpler like this wxBitmap bmp(FromDIP(wxSize(180, 70))); // shouldn't hardcode but it's simpler like this
wxMemoryDC dc; wxMemoryDC dc;
@@ -708,4 +709,3 @@ wxBitmap ButtonWidgetsPage::CreateBitmap(const wxString& label, const wxArtID& t
return bmp; return bmp;
} }

View File

@@ -182,7 +182,7 @@ void wxAnyButton::GTKUpdateBitmap()
} }
} }
void wxAnyButton::GTKDoShowBitmap(const wxBitmap& bitmap) void wxAnyButton::GTKDoShowBitmap(const wxBitmapBundle& bitmap)
{ {
wxCHECK_RET(bitmap.IsOk(), "invalid bitmap"); wxCHECK_RET(bitmap.IsOk(), "invalid bitmap");
@@ -197,10 +197,10 @@ void wxAnyButton::GTKDoShowBitmap(const wxBitmap& bitmap)
wxBitmap wxAnyButton::DoGetBitmap(State which) const wxBitmap wxAnyButton::DoGetBitmap(State which) const
{ {
return m_bitmaps[which]; return m_bitmaps[which].GetBitmap(wxDefaultSize);
} }
void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) void wxAnyButton::DoSetBitmap(const wxBitmapBundle& bitmap, State which)
{ {
switch ( which ) switch ( which )
{ {

View File

@@ -15,7 +15,7 @@
bool wxBitmapButton::Create(wxWindow *parent, bool wxBitmapButton::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,

View File

@@ -121,7 +121,7 @@ void wxBitmapButton::Init()
bool wxBitmapButton::Create( wxWindow *parent, bool wxBitmapButton::Create( wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
@@ -138,7 +138,7 @@ bool wxBitmapButton::Create( wxWindow *parent,
return false; return false;
} }
m_bitmaps[State_Normal] = bitmap; m_bitmaps[State_Normal] = bitmap.GetBitmap(wxDefaultSize);
m_widget = gtk_button_new(); m_widget = gtk_button_new();

View File

@@ -36,7 +36,7 @@ wxBitmapButton::wxBitmapButton()
} }
bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, long style, const wxSize& size, long style,
const wxValidator& validator, const wxValidator& validator,
@@ -103,7 +103,7 @@ wxBitmapButton::~wxBitmapButton()
(Pixmap) m_insensPixmap); (Pixmap) m_insensPixmap);
} }
void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which) void wxBitmapButton::DoSetBitmap(const wxBitmapBundle& bitmap, State which)
{ {
m_bitmapsOriginal[which] = bitmap; m_bitmapsOriginal[which] = bitmap;
@@ -114,7 +114,9 @@ void wxBitmapButton::OnSetBitmap()
{ {
wxBitmapButtonBase::OnSetBitmap(); wxBitmapButtonBase::OnSetBitmap();
if ( m_bitmapsOriginal[State_Normal].IsOk() ) wxBitmap
normalBitmap = m_bitmapsOriginal[State_Normal].GetBitmap(wxDefaultSize);
if ( normalBitmap.IsOk() )
{ {
Pixmap pixmap = 0; Pixmap pixmap = 0;
Pixmap insensPixmap = 0; Pixmap insensPixmap = 0;
@@ -122,7 +124,7 @@ void wxBitmapButton::OnSetBitmap()
// Must re-make the bitmap to have its transparent areas drawn // Must re-make the bitmap to have its transparent areas drawn
// in the current widget background colour. // in the current widget background colour.
if ( m_bitmapsOriginal[State_Normal].GetMask() ) if ( normalBitmap.GetMask() )
{ {
WXPixel backgroundPixel; WXPixel backgroundPixel;
XtVaGetValues((Widget) m_mainWidget, XtVaGetValues((Widget) m_mainWidget,
@@ -132,22 +134,23 @@ void wxBitmapButton::OnSetBitmap()
wxColour col; wxColour col;
col.SetPixel(backgroundPixel); col.SetPixel(backgroundPixel);
wxBitmap newBitmap = wxBitmap newBitmap = wxCreateMaskedBitmap(normalBitmap, col);
wxCreateMaskedBitmap(m_bitmapsOriginal[State_Normal], col);
m_bitmaps[State_Normal] = newBitmap; m_bitmaps[State_Normal] = newBitmap;
m_bitmapCache.SetBitmap( m_bitmaps[State_Normal] ); m_bitmapCache.SetBitmap( newBitmap );
pixmap = (Pixmap) m_bitmaps[State_Normal].GetDrawable(); pixmap = (Pixmap) newBitmap.GetDrawable();
} }
else else
{ {
m_bitmapCache.SetBitmap( m_bitmaps[State_Normal] ); m_bitmapCache.SetBitmap( normalBitmap );
pixmap = (Pixmap) m_bitmapCache.GetLabelPixmap(m_mainWidget); pixmap = (Pixmap) m_bitmapCache.GetLabelPixmap(m_mainWidget);
} }
if (m_bitmapsOriginal[State_Disabled].IsOk()) wxBitmap
disabledBitmap = m_bitmapsOriginal[State_Disabled].GetBitmap(wxDefaultSize);
if (disabledBitmap.IsOk())
{ {
if (m_bitmapsOriginal[State_Disabled].GetMask()) if (disabledBitmap.GetMask())
{ {
WXPixel backgroundPixel; WXPixel backgroundPixel;
XtVaGetValues((Widget) m_mainWidget, XtVaGetValues((Widget) m_mainWidget,
@@ -157,11 +160,10 @@ void wxBitmapButton::OnSetBitmap()
wxColour col; wxColour col;
col.SetPixel(backgroundPixel); col.SetPixel(backgroundPixel);
wxBitmap newBitmap = wxBitmap newBitmap = wxCreateMaskedBitmap(disabledBitmap, col);
wxCreateMaskedBitmap(m_bitmapsOriginal[State_Disabled], col);
m_bitmaps[State_Disabled] = newBitmap; m_bitmaps[State_Disabled] = newBitmap;
insensPixmap = (Pixmap) m_bitmaps[State_Disabled].GetDrawable(); insensPixmap = (Pixmap) newBitmap.GetDrawable();
} }
else else
insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget); insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget);
@@ -170,9 +172,11 @@ void wxBitmapButton::OnSetBitmap()
insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget); insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget);
// Now make the bitmap representing the armed state // Now make the bitmap representing the armed state
if (m_bitmapsOriginal[State_Pressed].IsOk()) wxBitmap
pressedBitmap = m_bitmapsOriginal[State_Pressed].GetBitmap(wxDefaultSize);
if (pressedBitmap.IsOk())
{ {
if (m_bitmapsOriginal[State_Pressed].GetMask()) if (pressedBitmap.GetMask())
{ {
WXPixel backgroundPixel; WXPixel backgroundPixel;
XtVaGetValues((Widget) m_mainWidget, XtVaGetValues((Widget) m_mainWidget,
@@ -182,11 +186,10 @@ void wxBitmapButton::OnSetBitmap()
wxColour col; wxColour col;
col.SetPixel(backgroundPixel); col.SetPixel(backgroundPixel);
wxBitmap newBitmap = wxBitmap newBitmap = wxCreateMaskedBitmap(pressedBitmap, col);
wxCreateMaskedBitmap(m_bitmapsOriginal[State_Pressed], col);
m_bitmaps[State_Pressed] = newBitmap; m_bitmaps[State_Pressed] = newBitmap;
armPixmap = (Pixmap) m_bitmaps[State_Pressed].GetDrawable(); armPixmap = (Pixmap) newBitmap.GetDrawable();
} }
else else
armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget); armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget);

View File

@@ -97,18 +97,17 @@ extern wxWindowMSW *wxWindowBeingErased; // From src/msw/window.cpp
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// we use different data classes for owner drawn buttons and for themed XP ones // we use different data classes for owner drawn buttons and for themed XP ones
//
// Each class stores the bitmap bundles possibly containing images of multiple
// sizes, but only stores bitmaps of the specific size used by the button right
// now.
class wxButtonImageData: public wxObject class wxButtonImageData: public wxObject
{ {
public: public:
wxButtonImageData() explicit wxButtonImageData(const wxSize& bitmapSize)
: m_bitmapSize(bitmapSize)
{ {
for ( int n = 0; n < wxAnyButton::State_Max; ++n )
{
// The normal bitmap is always set explicitly when the image data
// is created, but the others ones are not (yet).
m_bitmapSetExplicitly[n] = n == wxAnyButton::State_Normal;
}
} }
virtual ~wxButtonImageData() { } virtual ~wxButtonImageData() { }
@@ -117,30 +116,42 @@ public:
// is specified by the application, or implicitly, when the bitmap for some // is specified by the application, or implicitly, when the bitmap for some
// state is set as a side effect of setting another bitmap. // state is set as a side effect of setting another bitmap.
// //
// These functions check the flags stored in the base class remembering // When setting a bitmap explicitly, we update the entire bundle, while
// whether each bitmap is implicit or explicit and behave accordingly. // setting it implicitly only updates the currently used bitmap.
wxBitmap GetExplicitBitmap(wxAnyButton::State which) const wxBitmapBundle GetBitmapBundle(wxAnyButton::State which) const
{ {
return m_bitmapSetExplicitly[which] ? GetBitmap(which) : wxBitmap(); return m_bitmapBundles[which];
} }
void SetExplicitBitmap(const wxBitmap& bitmap, wxAnyButton::State which) void SetBitmapBundle(const wxBitmapBundle& bitmapBundle, wxAnyButton::State which)
{ {
SetBitmap(bitmap, which); m_bitmapBundles[which] = bitmapBundle;
m_bitmapSetExplicitly[which] = true;
SetBitmapFromBundle(bitmapBundle, which);
} }
wxBitmap GetImplicitBitmap(wxAnyButton::State which) const // Actually get or update the bitmap being currently used (even if it is
// used implicitly, i.e. as consequence of setting a bitmap for another
// state).
virtual wxBitmap GetBitmap(wxAnyButton::State which) const = 0;
virtual void SetBitmap(const wxBitmap& bitmap, wxAnyButton::State which) = 0;
// Helper: get the bitmap of the currently used size from the bundle.
wxBitmap GetBitmapFromBundle(const wxBitmapBundle& bitmapBundle) const
{ {
return GetBitmap(which); return bitmapBundle.GetBitmap(GetBitmapSize());
} }
void SetImplicitBitmap(const wxBitmap& bitmap, wxAnyButton::State which) // And another helper to call SetBitmap() with the result.
void SetBitmapFromBundle(const wxBitmapBundle& bitmapBundle, wxAnyButton::State which)
{ {
SetBitmap(bitmap, which); SetBitmap(GetBitmapFromBundle(bitmapBundle), which);
m_bitmapSetExplicitly[which] = false;
} }
// Return the currently used bitmap size.
wxSize GetBitmapSize() const { return m_bitmapSize; }
virtual wxSize GetBitmapMargins() const = 0; virtual wxSize GetBitmapMargins() const = 0;
virtual void SetBitmapMargins(wxCoord x, wxCoord y) = 0; virtual void SetBitmapMargins(wxCoord x, wxCoord y) = 0;
@@ -148,12 +159,9 @@ public:
virtual void SetBitmapPosition(wxDirection dir) = 0; virtual void SetBitmapPosition(wxDirection dir) = 0;
private: private:
// These functions are private to force using explicit/implicit versions of wxSize m_bitmapSize;
// them in the code to make it clear which bitmap is needed.
virtual wxBitmap GetBitmap(wxAnyButton::State which) const = 0;
virtual void SetBitmap(const wxBitmap& bitmap, wxAnyButton::State which) = 0;
bool m_bitmapSetExplicitly[wxAnyButton::State_Max]; wxBitmapBundle m_bitmapBundles[wxAnyButton::State_Max];
wxDECLARE_NO_COPY_CLASS(wxButtonImageData); wxDECLARE_NO_COPY_CLASS(wxButtonImageData);
}; };
@@ -168,11 +176,13 @@ const int OD_BUTTON_MARGIN = 4;
class wxODButtonImageData : public wxButtonImageData class wxODButtonImageData : public wxButtonImageData
{ {
public: public:
wxODButtonImageData(wxAnyButton *btn, const wxBitmap& bitmap) wxODButtonImageData(wxAnyButton *btn, const wxBitmapBundle& bitmapBundle)
: wxButtonImageData(bitmapBundle.GetDefaultSize())
{ {
SetExplicitBitmap(bitmap, wxAnyButton::State_Normal); SetBitmapBundle(bitmapBundle, wxAnyButton::State_Normal);
#if wxUSE_IMAGE #if wxUSE_IMAGE
SetBitmap(bitmap.ConvertToDisabled(), wxAnyButton::State_Disabled); SetBitmap(GetBitmapFromBundle(bitmapBundle).ConvertToDisabled(),
wxAnyButton::State_Disabled);
#endif #endif
m_dir = wxLEFT; m_dir = wxLEFT;
@@ -239,13 +249,20 @@ class wxXPButtonImageData : public wxButtonImageData
public: public:
// we must be constructed with the size of our images as we need to create // we must be constructed with the size of our images as we need to create
// the image list // the image list
wxXPButtonImageData(wxAnyButton *btn, const wxBitmap& bitmap) wxXPButtonImageData(wxAnyButton *btn, const wxBitmapBundle& bitmapBundle)
: m_iml(bitmap.GetWidth(), bitmap.GetHeight(), : wxButtonImageData(bitmapBundle.GetDefaultSize()),
!bitmap.HasAlpha() /* use mask only if no alpha */,
wxAnyButton::State_Max + 1 /* see "pulse" comment below */),
m_hwndBtn(GetHwndOf(btn)) m_hwndBtn(GetHwndOf(btn))
{ {
// initialize all bitmaps except for the disabled one to normal state // initialize all bitmaps except for the disabled one to normal state
const wxBitmap bitmap = bitmapBundle.GetBitmap(wxDefaultSize);
m_iml.Create
(
bitmap.GetWidth(),
bitmap.GetHeight(),
!bitmap.HasAlpha() /* use mask only if no alpha */,
wxAnyButton::State_Max + 1 /* see "pulse" comment below */
);
for ( int n = 0; n < wxAnyButton::State_Max; n++ ) for ( int n = 0; n < wxAnyButton::State_Max; n++ )
{ {
#if wxUSE_IMAGE #if wxUSE_IMAGE
@@ -266,8 +283,8 @@ public:
// just disappears during half of the time if the latter is not set so // just disappears during half of the time if the latter is not set so
// we absolutely must set it. // we absolutely must set it.
// //
// This also explains why we need to allocate an extra slot in the // This also explains why we need to allocate an extra slot when creating
// image list ctor above, the slot State_Max is used for this one. // the image list above, the slot State_Max is used for this one.
m_iml.Add(bitmap); m_iml.Add(bitmap);
m_data.himl = GetHimagelistOf(&m_iml); m_data.himl = GetHimagelistOf(&m_iml);
@@ -546,7 +563,7 @@ void wxAnyButton::AdjustForBitmapSize(wxSize &size) const
wxCHECK_RET( m_imageData, wxT("shouldn't be called if no image") ); wxCHECK_RET( m_imageData, wxT("shouldn't be called if no image") );
// account for the bitmap size, including the user-specified margins // account for the bitmap size, including the user-specified margins
const wxSize sizeBmp = m_imageData->GetImplicitBitmap(State_Normal).GetSize() const wxSize sizeBmp = m_imageData->GetBitmapSize()
+ 2*m_imageData->GetBitmapMargins(); + 2*m_imageData->GetBitmapMargins();
const wxDirection dirBmp = m_imageData->GetBitmapPosition(); const wxDirection dirBmp = m_imageData->GetBitmapPosition();
if ( dirBmp == wxLEFT || dirBmp == wxRIGHT ) if ( dirBmp == wxLEFT || dirBmp == wxRIGHT )
@@ -701,7 +718,7 @@ WXLRESULT wxAnyButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPar
if ( if (
IsEnabled() && IsEnabled() &&
( wxUxThemeIsActive() || ( wxUxThemeIsActive() ||
(m_imageData && m_imageData->GetImplicitBitmap(State_Current).IsOk()) (m_imageData && m_imageData->GetBitmap(State_Current).IsOk())
) )
) )
{ {
@@ -719,12 +736,22 @@ WXLRESULT wxAnyButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPar
wxBitmap wxAnyButton::DoGetBitmap(State which) const wxBitmap wxAnyButton::DoGetBitmap(State which) const
{ {
return m_imageData ? m_imageData->GetExplicitBitmap(which) : wxBitmap(); if ( !m_imageData )
return wxBitmap();
const wxBitmapBundle& bitmapBundle = m_imageData->GetBitmapBundle(which);
if ( !bitmapBundle.IsOk() )
return wxBitmap();
// Not really sure if it's better to use the default or current size here,
// but then this accessor is not that useful anyhow, so it probably doesn't
// matter much.
return bitmapBundle.GetBitmap(m_imageData->GetBitmapSize());
} }
void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) void wxAnyButton::DoSetBitmap(const wxBitmapBundle& bitmapBundle, State which)
{ {
if ( !bitmap.IsOk() ) if ( !bitmapBundle.IsOk() )
{ {
if ( m_imageData ) if ( m_imageData )
{ {
@@ -737,9 +764,12 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
} }
else else
{ {
// Invalidate the current bundle, if any.
m_imageData->SetBitmapBundle(bitmapBundle, which);
// Replace the removed bitmap with the normal one. // Replace the removed bitmap with the normal one.
wxBitmap bmpNormal = m_imageData->GetImplicitBitmap(State_Normal); wxBitmap bmpNormal = m_imageData->GetBitmap(State_Normal);
m_imageData->SetImplicitBitmap(which == State_Disabled m_imageData->SetBitmap(which == State_Disabled
? bmpNormal.ConvertToDisabled() ? bmpNormal.ConvertToDisabled()
: bmpNormal, : bmpNormal,
which); which);
@@ -755,7 +785,7 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
// Check if we already had bitmaps of different size. // Check if we already had bitmaps of different size.
if ( m_imageData && if ( m_imageData &&
bitmap.GetSize() != m_imageData->GetImplicitBitmap(State_Normal).GetSize() ) bitmapBundle.GetDefaultSize() != m_imageData->GetBitmapSize() )
{ {
wxASSERT_MSG( which == State_Normal, wxASSERT_MSG( which == State_Normal,
"Must set normal bitmap with the new size first" ); "Must set normal bitmap with the new size first" );
@@ -783,7 +813,7 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
// strategy for bitmap-only buttons // strategy for bitmap-only buttons
if ( ShowsLabel() && wxUxThemeIsActive() ) if ( ShowsLabel() && wxUxThemeIsActive() )
{ {
m_imageData = new wxXPButtonImageData(this, bitmap); m_imageData = new wxXPButtonImageData(this, bitmapBundle);
if ( oldData ) if ( oldData )
{ {
@@ -802,13 +832,13 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
else else
#endif // wxUSE_UXTHEME #endif // wxUSE_UXTHEME
{ {
m_imageData = new wxODButtonImageData(this, bitmap); m_imageData = new wxODButtonImageData(this, bitmapBundle);
MakeOwnerDrawn(); MakeOwnerDrawn();
} }
} }
else else
{ {
m_imageData->SetExplicitBitmap(bitmap, which); m_imageData->SetBitmapBundle(bitmapBundle, which);
// if the focus bitmap is specified but current one isn't, use // if the focus bitmap is specified but current one isn't, use
// the focus bitmap for hovering as well if this is consistent // the focus bitmap for hovering as well if this is consistent
@@ -818,9 +848,9 @@ void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
// and also makes it much easier to do "the right thing" for // and also makes it much easier to do "the right thing" for
// all platforms (some of them, such as Windows, have "hot" // all platforms (some of them, such as Windows, have "hot"
// buttons while others don't) // buttons while others don't)
if ( which == State_Focused && !m_imageData->GetExplicitBitmap(State_Current).IsOk() ) if ( which == State_Focused && !m_imageData->GetBitmapBundle(State_Current).IsOk() )
{ {
m_imageData->SetImplicitBitmap(bitmap, State_Current); m_imageData->SetBitmapFromBundle(bitmapBundle, State_Current);
} }
} }
@@ -1267,16 +1297,16 @@ void wxAnyButton::MakeOwnerDrawn()
// if necessary. // if necessary.
if ( m_imageData && wxDynamicCast(m_imageData, wxODButtonImageData) == NULL ) if ( m_imageData && wxDynamicCast(m_imageData, wxODButtonImageData) == NULL )
{ {
wxODButtonImageData* newData = new wxODButtonImageData(this, m_imageData->GetImplicitBitmap(State_Normal)); wxODButtonImageData* newData = new wxODButtonImageData(this, m_imageData->GetBitmapBundle(State_Normal));
for ( int n = 0; n < State_Max; n++ ) for ( int n = 0; n < State_Max; n++ )
{ {
State st = static_cast<State>(n); State st = static_cast<State>(n);
wxBitmap bmp = m_imageData->GetExplicitBitmap(st); wxBitmapBundle bmp = m_imageData->GetBitmapBundle(st);
if ( bmp.IsOk() ) if ( bmp.IsOk() )
newData->SetExplicitBitmap(bmp, st); newData->SetBitmapBundle(bmp, st);
else else
newData->SetImplicitBitmap(m_imageData->GetImplicitBitmap(st), st); newData->SetBitmap(m_imageData->GetBitmap(st), st);
} }
newData->SetBitmapPosition(m_imageData->GetBitmapPosition()); newData->SetBitmapPosition(m_imageData->GetBitmapPosition());
wxSize margs = m_imageData->GetBitmapMargins(); wxSize margs = m_imageData->GetBitmapMargins();
@@ -1436,9 +1466,9 @@ bool wxAnyButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
// draw the image, if any // draw the image, if any
if ( m_imageData ) if ( m_imageData )
{ {
wxBitmap bmp = m_imageData->GetImplicitBitmap(GetButtonState(this, state)); wxBitmap bmp = m_imageData->GetBitmap(GetButtonState(this, state));
if ( !bmp.IsOk() ) if ( !bmp.IsOk() )
bmp = m_imageData->GetImplicitBitmap(State_Normal); bmp = m_imageData->GetBitmap(State_Normal);
const wxSize sizeBmp = bmp.GetSize(); const wxSize sizeBmp = bmp.GetSize();
const wxSize margin = m_imageData->GetBitmapMargins(); const wxSize margin = m_imageData->GetBitmapMargins();

View File

@@ -32,7 +32,7 @@ bitmap "disabled" ,
bool wxBitmapButton::Create(wxWindow *parent, bool wxBitmapButton::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, long style, const wxSize& size, long style,
const wxValidator& validator, const wxValidator& validator,

View File

@@ -43,20 +43,20 @@ void wxAnyButton::SetLabel(const wxString& label)
wxBitmap wxAnyButton::DoGetBitmap(State which) const wxBitmap wxAnyButton::DoGetBitmap(State which) const
{ {
return m_bitmaps[which]; return m_bitmaps[which].GetBitmap(wxDefaultSize);
} }
void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) void wxAnyButton::DoSetBitmap(const wxBitmapBundle& bitmapBundle, State which)
{ {
m_bitmaps[which] = bitmap; m_bitmaps[which] = bitmapBundle;
if ( which == State_Normal ) if ( which == State_Normal )
GetPeer()->SetBitmap(bitmap); GetPeer()->SetBitmap(bitmapBundle);
else if ( which == State_Pressed ) else if ( which == State_Pressed )
{ {
wxButtonImpl* bi = dynamic_cast<wxButtonImpl*> (GetPeer()); wxButtonImpl* bi = dynamic_cast<wxButtonImpl*> (GetPeer());
if ( bi ) if ( bi )
bi->SetPressedBitmap(bitmap); bi->SetPressedBitmap(bitmapBundle);
} }
InvalidateBestSize(); InvalidateBestSize();
} }
@@ -84,11 +84,11 @@ bool wxAnyButton::DoSetLabelMarkup(const wxString& markup)
void wxAnyButton::OnEnterWindow( wxMouseEvent& WXUNUSED(event)) void wxAnyButton::OnEnterWindow( wxMouseEvent& WXUNUSED(event))
{ {
if ( DoGetBitmap( State_Current ).IsOk() ) if ( DoGetBitmap( State_Current ).IsOk() )
GetPeer()->SetBitmap( DoGetBitmap( State_Current ) ); GetPeer()->SetBitmap( m_bitmaps[State_Current] );
} }
void wxAnyButton::OnLeaveWindow( wxMouseEvent& WXUNUSED(event)) void wxAnyButton::OnLeaveWindow( wxMouseEvent& WXUNUSED(event))
{ {
if ( DoGetBitmap( State_Current ).IsOk() ) if ( DoGetBitmap( State_Current ).IsOk() )
GetPeer()->SetBitmap( DoGetBitmap( State_Normal ) ); GetPeer()->SetBitmap( m_bitmaps[State_Normal] );
} }

View File

@@ -25,7 +25,7 @@
bool wxBitmapButton::Create( wxWindow *parent, bool wxBitmapButton::Create( wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,

View File

@@ -19,6 +19,7 @@
#include "wx/tglbtn.h" #include "wx/tglbtn.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/private/bmpbndl.h"
#if wxUSE_MARKUP #if wxUSE_MARKUP
#include "wx/osx/cocoa/private/markuptoattr.h" #include "wx/osx/cocoa/private/markuptoattr.h"
@@ -88,7 +89,7 @@ wxButtonCocoaImpl::wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v)
SetNeedsFrame(false); SetNeedsFrame(false);
} }
void wxButtonCocoaImpl::SetBitmap(const wxBitmap& bitmap) void wxButtonCocoaImpl::SetBitmap(const wxBitmapBundle& bitmap)
{ {
// switch bezel style for plain pushbuttons // switch bezel style for plain pushbuttons
if ( bitmap.IsOk() ) if ( bitmap.IsOk() )
@@ -123,10 +124,10 @@ void wxButtonCocoaImpl::SetLabelMarkup(const wxString& markup)
} }
#endif // wxUSE_MARKUP #endif // wxUSE_MARKUP
void wxButtonCocoaImpl::SetPressedBitmap( const wxBitmap& bitmap ) void wxButtonCocoaImpl::SetPressedBitmap( const wxBitmapBundle& bitmap )
{ {
NSButton* button = GetNSButton(); NSButton* button = GetNSButton();
[button setAlternateImage: bitmap.GetNSImage()]; [button setAlternateImage: wxOSXGetImageFromBundle(bitmap)];
#if wxUSE_TOGGLEBTN #if wxUSE_TOGGLEBTN
if ( GetWXPeer()->IsKindOf(wxCLASSINFO(wxToggleButton)) ) if ( GetWXPeer()->IsKindOf(wxCLASSINFO(wxToggleButton)) )
{ {
@@ -227,7 +228,7 @@ SetBezelStyleFromBorderFlags(NSButton *v,
long style, long style,
wxWindowID winid, wxWindowID winid,
const wxString& label = wxString(), const wxString& label = wxString(),
const wxBitmap& bitmap = wxBitmap()) const wxBitmapBundle& bitmap = wxBitmapBundle())
{ {
// We can't display a custom label inside a button with help bezel style so // We can't display a custom label inside a button with help bezel style so
// we only use it if we are using the default label. wxButton itself checks // we only use it if we are using the default label. wxButton itself checks
@@ -245,7 +246,7 @@ SetBezelStyleFromBorderFlags(NSButton *v,
// single or multi line. // single or multi line.
const bool const bool
isSimpleText = (label.find_first_of("\n\r") == wxString::npos) isSimpleText = (label.find_first_of("\n\r") == wxString::npos)
&& (!bitmap.IsOk() || bitmap.GetHeight() < 20); && (!bitmap.IsOk() || bitmap.GetDefaultSize().y < 20);
NSBezelStyle bezel; NSBezelStyle bezel;
switch ( style & wxBORDER_MASK ) switch ( style & wxBORDER_MASK )
@@ -353,7 +354,7 @@ void wxWidgetCocoaImpl::PerformClick()
wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
wxWindowMac* WXUNUSED(parent), wxWindowMac* WXUNUSED(parent),
wxWindowID winid, wxWindowID winid,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
@@ -365,7 +366,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
SetBezelStyleFromBorderFlags(v, style, winid, wxString(), bitmap); SetBezelStyleFromBorderFlags(v, style, winid, wxString(), bitmap);
if (bitmap.IsOk()) if (bitmap.IsOk())
[v setImage:bitmap.GetNSImage() ]; [v setImage: wxOSXGetImageFromBundle(bitmap) ];
[v setButtonType:NSMomentaryPushInButton]; [v setButtonType:NSMomentaryPushInButton];
wxWidgetCocoaImpl* c = new wxButtonCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxButtonCocoaImpl( wxpeer, v );

View File

@@ -23,6 +23,7 @@
#include "wx/tglbtn.h" #include "wx/tglbtn.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/private/bmpbndl.h"
// from button.mm // from button.mm
@@ -30,7 +31,7 @@ extern "C" void SetBezelStyleFromBorderFlags(NSButton *v,
long style, long style,
wxWindowID winid = wxID_ANY, wxWindowID winid = wxID_ANY,
const wxString& label = wxString(), const wxString& label = wxString(),
const wxBitmap& bitmap = wxBitmap()); const wxBitmapBundle& bitmap = wxBitmapBundle());
wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
wxWindowMac* WXUNUSED(parent), wxWindowMac* WXUNUSED(parent),
@@ -54,7 +55,7 @@ wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
wxWindowMac* WXUNUSED(parent), wxWindowMac* WXUNUSED(parent),
wxWindowID winid, wxWindowID winid,
const wxBitmap& label, const wxBitmapBundle& label,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
@@ -66,7 +67,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
SetBezelStyleFromBorderFlags(v, style, winid, wxString(), label); SetBezelStyleFromBorderFlags(v, style, winid, wxString(), label);
if (label.IsOk()) if (label.IsOk())
[v setImage:label.GetNSImage() ]; [v setImage: wxOSXGetImageFromBundle(label) ];
[v setButtonType:NSOnOffButton]; [v setButtonType:NSOnOffButton];
wxWidgetCocoaImpl* c = new wxButtonCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxButtonCocoaImpl( wxpeer, v );

View File

@@ -25,6 +25,8 @@
#include "wx/osx/private/datatransfer.h" #include "wx/osx/private/datatransfer.h"
#endif #endif
#include "wx/private/bmpbndl.h"
#include "wx/evtloop.h" #include "wx/evtloop.h"
#if wxUSE_CARET #if wxUSE_CARET
@@ -3440,11 +3442,11 @@ wxBitmap wxWidgetCocoaImpl::GetBitmap() const
return bmp; return bmp;
} }
void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap ) void wxWidgetCocoaImpl::SetBitmap( const wxBitmapBundle& bitmap )
{ {
if ( [m_osxView respondsToSelector:@selector(setImage:)] ) if ( [m_osxView respondsToSelector:@selector(setImage:)] )
{ {
[m_osxView setImage:bitmap.GetNSImage()]; [m_osxView setImage: wxOSXGetImageFromBundle(bitmap)];
[m_osxView setNeedsDisplay:YES]; [m_osxView setNeedsDisplay:YES];
} }
} }

View File

@@ -21,6 +21,7 @@
#include "wx/stockitem.h" #include "wx/stockitem.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/private/bmpbndl.h"
@implementation wxUIButton @implementation wxUIButton
@@ -98,7 +99,7 @@ wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer,
wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
wxWindowMac* WXUNUSED(parent), wxWindowMac* WXUNUSED(parent),
wxWindowID winid, wxWindowID winid,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
@@ -111,7 +112,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
v.frame = r; v.frame = r;
if (bitmap.IsOk()) if (bitmap.IsOk())
[v setImage:bitmap.GetUIImage() forState:UIControlStateNormal]; [v setImage: wxOSXGetImageFromBundle(bitmap) forState:UIControlStateNormal];
wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v ); wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v );
return c; return c;

View File

@@ -475,7 +475,7 @@ void wxWidgetIPhoneImpl::SetValue( wxInt32 v )
{ {
} }
void wxWidgetIPhoneImpl::SetBitmap( const wxBitmap& bitmap ) void wxWidgetIPhoneImpl::SetBitmap( const wxBitmapBundle& bitmap )
{ {
} }

View File

@@ -90,10 +90,15 @@ void wxAnyButton::QtCreate(wxWindow *parent)
m_qtPushButton->setAutoDefault(false); m_qtPushButton->setAutoDefault(false);
} }
void wxAnyButton::QtSetBitmap( const wxBitmap &bitmap ) void wxAnyButton::QtSetBitmap( const wxBitmapBundle &bitmapBundle )
{ {
wxCHECK_RET(m_qtPushButton, "Invalid button."); wxCHECK_RET(m_qtPushButton, "Invalid button.");
if ( !bitmapBundle.IsOk() )
return;
wxBitmap bitmap = bitmapBundle.GetBitmap(bitmapBundle.GetDefaultSize()*GetDPIScaleFactor());
// load the bitmap and resize the button: // load the bitmap and resize the button:
QPixmap *pixmap = bitmap.GetHandle(); QPixmap *pixmap = bitmap.GetHandle();
if ( pixmap != NULL ) if ( pixmap != NULL )
@@ -117,10 +122,10 @@ QWidget *wxAnyButton::GetHandle() const
wxBitmap wxAnyButton::DoGetBitmap(State state) const wxBitmap wxAnyButton::DoGetBitmap(State state) const
{ {
return state < State_Max ? m_bitmaps[state] : wxNullBitmap; return state < State_Max ? m_bitmaps[state].GetBitmap(wxDefaultSize) : wxNullBitmap;
} }
void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which) void wxAnyButton::DoSetBitmap(const wxBitmapBundle& bitmap, State which)
{ {
wxCHECK_RET(which < State_Max, "Invalid state"); wxCHECK_RET(which < State_Max, "Invalid state");
@@ -166,7 +171,7 @@ void wxAnyButton::QtUpdateState()
State state = QtGetCurrentState(); State state = QtGetCurrentState();
// Update the bitmap // Update the bitmap
const wxBitmap& bmp = m_bitmaps[state]; const wxBitmapBundle& bmp = m_bitmaps[state];
QtSetBitmap(bmp.IsOk() ? bmp : m_bitmaps[State_Normal]); QtSetBitmap(bmp.IsOk() ? bmp : m_bitmaps[State_Normal]);
} }

View File

@@ -17,7 +17,7 @@ wxBitmapButton::wxBitmapButton()
wxBitmapButton::wxBitmapButton(wxWindow *parent, wxBitmapButton::wxBitmapButton(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
@@ -30,7 +30,7 @@ wxBitmapButton::wxBitmapButton(wxWindow *parent,
bool wxBitmapButton::Create(wxWindow *parent, bool wxBitmapButton::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,

View File

@@ -45,7 +45,7 @@ wxEND_EVENT_TABLE()
bool wxBitmapButton::Create(wxWindow *parent, bool wxBitmapButton::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxPoint &pos, const wxPoint &pos,
const wxSize &size, const wxSize &size,
long style, long style,

View File

@@ -54,7 +54,7 @@ void wxButton::Init()
bool wxButton::Create(wxWindow *parent, bool wxButton::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxBitmap& bitmap, const wxBitmapBundle& bitmap,
const wxString &lbl, const wxString &lbl,
const wxPoint &pos, const wxPoint &pos,
const wxSize &size, const wxSize &size,
@@ -148,12 +148,12 @@ wxBitmap wxButton::DoGetBitmap(State WXUNUSED(which)) const
return m_bitmap; return m_bitmap;
} }
void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which) void wxButton::DoSetBitmap(const wxBitmapBundle& bitmap, State which)
{ {
// we support only one bitmap right now, although this wouldn't be // we support only one bitmap right now, although this wouldn't be
// difficult to change // difficult to change
if ( which == State_Normal ) if ( which == State_Normal )
m_bitmap = bitmap; m_bitmap = bitmap.GetBitmap(wxDefaultSize); // TODO-HIDPI
SetBitmapMargins(DEFAULT_BTN_MARGIN_X, DEFAULT_BTN_MARGIN_Y); SetBitmapMargins(DEFAULT_BTN_MARGIN_X, DEFAULT_BTN_MARGIN_Y);
} }