From 2352862a7ee8440fdc2ae65baff31b73e40179d5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 14 Jun 2009 22:55:24 +0000 Subject: [PATCH] preparation work for implementing images support in wxButton: move wxBitmapButton methods to the base class (enhancing/completing them in the process); there are no functionality changes yet (hopefully) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 + include/wx/bmpbuttn.h | 34 +----- include/wx/button.h | 79 +++++++++++++- include/wx/defs.h | 5 + include/wx/motif/bmpbuttn.h | 36 ++----- include/wx/msw/bmpbuttn.h | 16 ++- include/wx/univ/bmpbuttn.h | 4 +- include/wx/univ/button.h | 5 +- interface/wx/bmpbuttn.h | 142 ++----------------------- interface/wx/button.h | 199 +++++++++++++++++++++++++++++++++++- interface/wx/defs.h | 23 +++++ src/gtk/bmpbuttn.cpp | 24 ++--- src/motif/bmpbuttn.cpp | 83 ++++++--------- src/msw/bmpbuttn.cpp | 127 ++++++++++++----------- src/msw/button.cpp | 5 + src/os2/bmpbuttn.cpp | 38 +++---- src/osx/bmpbuttn_osx.cpp | 24 ++--- src/univ/bmpbuttn.cpp | 27 +++-- src/univ/button.cpp | 13 ++- 19 files changed, 503 insertions(+), 385 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 8d93e57aa9..389a43410e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -236,6 +236,10 @@ Changes in behaviour which may result in compilation errors You may use wxEventLoopBase::SuspendProcessingOfPendingEvents instead of locking wxPendingEventsLocker now. +- wxBitmapButton::GetBitmapXXX() overloads returning non-const wxBitmap + references have been removed, modifying the returned bitmaps never worked and + now results in compile-time error. + Deprecated methods and their replacements ----------------------------------------- diff --git a/include/wx/bmpbuttn.h b/include/wx/bmpbuttn.h index 0ac15ef292..0c369003e0 100644 --- a/include/wx/bmpbuttn.h +++ b/include/wx/bmpbuttn.h @@ -35,30 +35,6 @@ public: m_marginY = 0; } - // set the bitmaps - virtual void SetBitmapLabel(const wxBitmap& bitmap) - { m_bmpNormal = bitmap; OnSetBitmap(); } - virtual void SetBitmapSelected(const wxBitmap& sel) - { m_bmpSelected = sel; OnSetBitmap(); } - virtual void SetBitmapFocus(const wxBitmap& focus) - { m_bmpFocus = focus; OnSetBitmap(); } - virtual void SetBitmapDisabled(const wxBitmap& disabled) - { m_bmpDisabled = disabled; OnSetBitmap(); } - virtual void SetBitmapHover(const wxBitmap& hover) - { m_bmpHover = hover; OnSetBitmap(); } - - // retrieve the bitmaps - const wxBitmap& GetBitmapLabel() const { return m_bmpNormal; } - const wxBitmap& GetBitmapSelected() const { return m_bmpSelected; } - const wxBitmap& GetBitmapFocus() const { return m_bmpFocus; } - const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; } - const wxBitmap& GetBitmapHover() const { return m_bmpHover; } - wxBitmap& GetBitmapLabel() { return m_bmpNormal; } - wxBitmap& GetBitmapSelected() { return m_bmpSelected; } - wxBitmap& GetBitmapFocus() { return m_bmpFocus; } - wxBitmap& GetBitmapDisabled() { return m_bmpDisabled; } - wxBitmap& GetBitmapHover() { return m_bmpHover; } - // 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; } @@ -77,12 +53,12 @@ protected: // function called when any of the bitmaps changes virtual void OnSetBitmap() { InvalidateBestSize(); Refresh(); } + virtual wxBitmap DoGetBitmap(State which) const { return m_bitmaps[which]; } + virtual void DoSetBitmap(const wxBitmap& bitmap, State which) + { m_bitmaps[which] = bitmap; OnSetBitmap(); } + // the bitmaps for various states - wxBitmap m_bmpNormal, - m_bmpSelected, - m_bmpFocus, - m_bmpDisabled, - m_bmpHover; + wxBitmap m_bitmaps[State_Max]; // the margins around the bitmap int m_marginX, diff --git a/include/wx/button.h b/include/wx/button.h index 25d56365f0..5f6da7282a 100644 --- a/include/wx/button.h +++ b/include/wx/button.h @@ -58,11 +58,50 @@ class WXDLLIMPEXP_CORE wxButtonBase : public wxControl public: wxButtonBase() { } - // show the image in the button in addition to the label - virtual void SetImageLabel(const wxBitmap& WXUNUSED(bitmap)) { } + // show the image in the button in addition to the label: this method is + // supported on all (major) platforms + void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT) + { + SetBitmapLabel(bitmap); + SetBitmapPosition(dir); + } + + wxBitmap GetBitmap() const { return DoGetBitmap(State_Normal); } + + // Methods for setting individual images for different states: normal, + // selected (meaning pushed or pressed), focused (meaning normal state for + // a focused button), disabled or hover (a.k.a. hot or current). + // + // Remember that SetBitmap() itself must be called before any other + // SetBitmapXXX() methods (except for SetBitmapLabel() which is a synonym + // for it anyhow) and that all bitmaps passed to these functions should be + // of the same size. + void SetBitmapLabel(const wxBitmap& bitmap) + { DoSetBitmap(bitmap, State_Normal); } + void SetBitmapPressed(const wxBitmap& bitmap) + { DoSetBitmap(bitmap, State_Pressed); } + void SetBitmapDisabled(const wxBitmap& bitmap) + { DoSetBitmap(bitmap, State_Disabled); } + void SetBitmapCurrent(const wxBitmap& bitmap) + { DoSetBitmap(bitmap, State_Current); } + void SetBitmapFocus(const wxBitmap& bitmap) + { DoSetBitmap(bitmap, State_Focused); } + + wxBitmap GetBitmapLabel() const { return DoGetBitmap(State_Normal); } + wxBitmap GetBitmapPressed() const { return DoGetBitmap(State_Pressed); } + wxBitmap GetBitmapDisabled() const { return DoGetBitmap(State_Disabled); } + wxBitmap GetBitmapCurrent() const { return DoGetBitmap(State_Current); } + wxBitmap GetBitmapFocus() const { return DoGetBitmap(State_Focused); } + // set the margins around the image - virtual void SetImageMargins(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) { } + void SetBitmapMargins(wxCoord x, wxCoord y) { DoSetBitmapMargins(x, y); } + void SetBitmapMargins(const wxSize& sz) { DoSetBitmapMargins(sz.x, sz.y); } + + // set the image position relative to the text, i.e. wxLEFT means that the + // image is to the left of the text (this is the default) + virtual void SetBitmapPosition(wxDirection WXUNUSED(dir)) { } + // make this button the default button in its top level window // @@ -77,10 +116,44 @@ public: // returns the default button size for this platform static wxSize GetDefaultSize(); + // wxUniv-compatible and deprecated equivalents to SetBitmapXXX() +#if WXWIN_COMPATIBILITY_2_8 + void SetImageLabel(const wxBitmap& bitmap) { SetBitmap(bitmap); } + void SetImageMargins(wxCoord x, wxCoord y) { SetBitmapMargins(x, y); } +#endif // WXWIN_COMPATIBILITY_2_8 + + // backwards compatible names for pressed/current bitmaps: they're not + // 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 + wxBitmap GetBitmapSelected() const { return GetBitmapPressed(); } + wxBitmap GetBitmapHover() const { return GetBitmapCurrent(); } + + void SetBitmapSelected(const wxBitmap& bitmap) { SetBitmapPressed(bitmap); } + void SetBitmapHover(const wxBitmap& bitmap) { SetBitmapCurrent(bitmap); } + protected: // choose the default border for this window virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + enum State + { + State_Normal, + State_Pressed, // a.k.a. "selected" in public API for some reason + State_Current, // a.k.a. hot or "hovering" + State_Disabled, + State_Focused, + State_Max + }; + + virtual wxBitmap DoGetBitmap(State WXUNUSED(which)) const + { return wxBitmap(); } + virtual void DoSetBitmap(const wxBitmap& WXUNUSED(bitmap), + State WXUNUSED(which)) + { } + virtual void DoSetBitmapMargins(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) + { } + + wxDECLARE_NO_COPY_CLASS(wxButtonBase); }; diff --git a/include/wx/defs.h b/include/wx/defs.h index 37ee6b5f17..963a4b3d13 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -522,6 +522,11 @@ typedef short int WXTYPE; */ #define wxDEPRECATED_INLINE(func, body) wxDEPRECATED(func) { body } +/* + A macro to define a simple deprecated accessor. + */ +#define wxDEPRECATED_ACCESSOR(func, what) wxDEPRECATED_INLINE(func, return what;) + /* Special variant of the macro above which should be used for the functions which are deprecated but called by wx itself: this often happens with diff --git a/include/wx/motif/bmpbuttn.h b/include/wx/motif/bmpbuttn.h index d923c76870..40ff8f5b17 100644 --- a/include/wx/motif/bmpbuttn.h +++ b/include/wx/motif/bmpbuttn.h @@ -18,7 +18,6 @@ class WXDLLIMPEXP_CORE wxBitmapButton: public wxBitmapButtonBase { - DECLARE_DYNAMIC_CLASS(wxBitmapButton) public: wxBitmapButton(); virtual ~wxBitmapButton(); @@ -37,37 +36,24 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr); - virtual void SetLabel(const wxBitmap& bitmap) - { - SetBitmapLabel(bitmap); - } - virtual void SetLabel(const wxString& label) - { - wxControl::SetLabel(label); - } - - virtual void SetBitmapLabel(const wxBitmap& bitmap); - - void SetBitmapSelected(const wxBitmap& sel); - void SetBitmapFocus(const wxBitmap& focus); - void SetBitmapDisabled(const wxBitmap& disabled); - // Implementation - void DoSetBitmap(); virtual void ChangeBackgroundColour(); - virtual wxSize DoGetBestSize() const; protected: - wxBitmap m_bmpNormalOriginal; // May be different from m_buttonBitmap - // if m_buttonBitmap has been changed - // to reflect button background colour - wxBitmap m_bmpSelectedOriginal; - wxBitmap m_bmpDisabledOriginal; + virtual wxSize DoGetBestSize() const; + + virtual void DoSetBitmap(const wxBitmap& bitmap, State which); + virtual void OnSetBitmap(); + + // original bitmaps may be different from the ones we were initialized with + // if they were changed to reflect button background colour + wxBitmap m_bitmapsOriginal[State_Max]; wxBitmapCache m_bitmapCache; WXPixmap m_insensPixmap; + + DECLARE_DYNAMIC_CLASS(wxBitmapButton) }; -#endif -// _WX_BMPBUTTN_H_ +#endif // _WX_BMPBUTTN_H_ diff --git a/include/wx/msw/bmpbuttn.h b/include/wx/msw/bmpbuttn.h index fb53b039bf..a0d1dfd2fe 100644 --- a/include/wx/msw/bmpbuttn.h +++ b/include/wx/msw/bmpbuttn.h @@ -44,13 +44,6 @@ 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); @@ -70,6 +63,8 @@ protected: 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); @@ -81,11 +76,12 @@ 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 + // true if disabled bitmap was set by user, false if we created it + // ourselves from the normal one bool m_disabledSetByUser; - // true if m_bmpHover was set by user, false if it was set from m_bmpFocus + // true if hover bitmap was set by user, false if it was set from focused + // one bool m_hoverSetByUser; diff --git a/include/wx/univ/bmpbuttn.h b/include/wx/univ/bmpbuttn.h index b3b81d0d66..4bfce6e7fe 100644 --- a/include/wx/univ/bmpbuttn.h +++ b/include/wx/univ/bmpbuttn.h @@ -59,8 +59,8 @@ protected: // called when one of the bitmap is changed by user virtual void OnSetBitmap(); - // set bitmap to the given one if it's ok or to m_bmpNormal and return - // true if the bitmap really changed + // set bitmap to the given one if it's ok or to the normal bitmap and + // return true if the bitmap really changed bool ChangeBitmap(const wxBitmap& bmp); private: diff --git a/include/wx/univ/button.h b/include/wx/univ/button.h index 2aaf0cf4b2..9c41fb392c 100644 --- a/include/wx/univ/button.h +++ b/include/wx/univ/button.h @@ -87,8 +87,6 @@ public: virtual ~wxButton(); - virtual void SetImageLabel(const wxBitmap& bitmap); - virtual void SetImageMargins(wxCoord x, wxCoord y); virtual wxWindow *SetDefault(); virtual bool IsPressed() const { return m_isPressed; } @@ -119,6 +117,9 @@ protected: virtual bool DoDrawBackground(wxDC& dc); virtual void DoDraw(wxControlRenderer *renderer); + virtual void DoSetBitmap(const wxBitmap& bitmap, State which); + virtual void DoSetBitmapMargins(wxCoord x, wxCoord y); + // common part of all ctors void Init(); diff --git a/interface/wx/bmpbuttn.h b/interface/wx/bmpbuttn.h index ba624b7121..1d352d856a 100644 --- a/interface/wx/bmpbuttn.h +++ b/interface/wx/bmpbuttn.h @@ -10,28 +10,12 @@ @class wxBitmapButton A bitmap button is a control that contains a bitmap. - It may be placed on a wxDialog or a wxPanel, or indeed almost any other window. - @remarks - A bitmap button can be supplied with a single bitmap, and wxWidgets will draw - all button states using this bitmap. If the application needs more control, - additional bitmaps for the selected state, unpressed focused state, and greyed-out - state may be supplied. - - @section bitmapbutton_states Button states - - This class supports bitmaps for several different states: - @li @b normal: this is the bitmap shown in the default state, it must be always - valid while all the other bitmaps are optional and don't have to be set. - @li @b disabled: bitmap shown when the button is disabled. - @li @b selected: bitmap shown when the button is pushed (e.g. while the user - keeps the mouse button pressed on it) - @li @b focus: bitmap shown when the button has keyboard focus but is not pressed. - @li @b hover: bitmap shown when the mouse is over the button (but it is not pressed). - Notice that if hover bitmap is not specified but the current platform UI uses - hover images for the buttons (such as Windows XP or GTK+), then the focus bitmap - is used for hover state as well. This makes it possible to set focus bitmap only - to get reasonably good behaviour on all platforms. + Notice that since wxWidgets 2.9.1 bitmap display is supported by the base + wxButton class itself and the only tiny advantage of using this class is + that it allows to specify the bitmap in its constructor, unlike wxButton. + Please see the base class documentation for more information about images + support in wxButton. @beginStyleTable @style{wxBU_AUTODRAW} @@ -98,7 +82,7 @@ public: @remarks The bitmap parameter is normally the only bitmap you need to provide, and wxWidgets will draw the button correctly in its different states. - If you want more control, call any of the functions SetBitmapSelected(), + If you want more control, call any of the functions SetBitmapPressed(), SetBitmapFocus(), SetBitmapDisabled(). @see Create(), wxValidator @@ -111,11 +95,6 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr); - /** - Destructor, destroying the button. - */ - virtual ~wxBitmapButton(); - /** Button creation function for two-step creation. For more details, see wxBitmapButton(). @@ -127,114 +106,5 @@ public: long style = wxBU_AUTODRAW, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr); - - //@{ - /** - Returns the bitmap for the disabled state, which may be invalid. - - @return A reference to the disabled state bitmap. - - @see SetBitmapDisabled() - */ - const wxBitmap& GetBitmapDisabled() const; - wxBitmap& GetBitmapDisabled(); - //@} - - //@{ - /** - Returns the bitmap for the focused state, which may be invalid. - - @return A reference to the focused state bitmap. - - @see SetBitmapFocus() - */ - const wxBitmap& GetBitmapFocus() const; - wxBitmap& GetBitmapFocus(); - //@} - - //@{ - /** - Returns the bitmap used when the mouse is over the button, which may be invalid. - - @see SetBitmapHover() - */ - const wxBitmap& GetBitmapHover() const; - wxBitmap& GetBitmapHover(); - //@} - - //@{ - /** - Returns the label bitmap (the one passed to the constructor), always valid. - - @return A reference to the button's label bitmap. - - @see SetBitmapLabel() - */ - const wxBitmap& GetBitmapLabel() const; - wxBitmap& GetBitmapLabel(); - //@} - - /** - Returns the bitmap for the selected state. - - @return A reference to the selected state bitmap. - - @see SetBitmapSelected() - */ - const wxBitmap& GetBitmapSelected() const; - - /** - Sets the bitmap for the disabled button appearance. - - @param bitmap - The bitmap to set. - - @see GetBitmapDisabled(), SetBitmapLabel(), - SetBitmapSelected(), SetBitmapFocus() - */ - virtual void SetBitmapDisabled(const wxBitmap& bitmap); - - /** - Sets the bitmap for the button appearance when it has the keyboard focus. - - @param bitmap - The bitmap to set. - - @see GetBitmapFocus(), SetBitmapLabel(), - SetBitmapSelected(), SetBitmapDisabled() - */ - virtual void SetBitmapFocus(const wxBitmap& bitmap); - - /** - Sets the bitmap to be shown when the mouse is over the button. - - @since 2.7.0 - - The hover bitmap is currently only supported in wxMSW. - - @see GetBitmapHover() - */ - virtual void SetBitmapHover(const wxBitmap& bitmap); - - /** - Sets the bitmap label for the button. - - @param bitmap - The bitmap label to set. - - @remarks This is the bitmap used for the unselected state, and for all - other states if no other bitmaps are provided. - - @see GetBitmapLabel() - */ - virtual void SetBitmapLabel(const wxBitmap& bitmap); - - /** - Sets the bitmap for the selected (depressed) button appearance. - - @param bitmap - The bitmap to set. - */ - virtual void SetBitmapSelected(const wxBitmap& bitmap); }; diff --git a/interface/wx/button.h b/interface/wx/button.h index 5bb2bff16e..fa2882bc24 100644 --- a/interface/wx/button.h +++ b/interface/wx/button.h @@ -36,6 +36,34 @@ Process a wxEVT_COMMAND_BUTTON_CLICKED event, when the button is clicked. @endEventTable + + Since version 2.9.1 wxButton supports showing both text and an image, see + SetBitmap() and SetBitmapLabel(), SetBitmapDisabled() &c methods. In the + previous wxWidgets versions this functionality was only available in (the + now trivial) wxBitmapButton class which was only capable of showing an + image without text. + + A button may have either a single image for all states or different images + for the following states: + @li @b normal: the default state + @li @b disabled: bitmap shown when the button is disabled. + @li @b pressed: bitmap shown when the button is pushed (e.g. while the user + keeps the mouse button pressed on it) + @li @b focus: bitmap shown when the button has keyboard focus (but is not + pressed as in this case the button is in the pressed state) + @li @b current: bitmap shown when the mouse is over the button (but it is + not pressed although it may have focus). Notice that if current bitmap + is not specified but the current platform UI uses hover images for the + buttons (such as Windows XP or GTK+), then the focus bitmap is used for + hover state as well. This makes it possible to set focus bitmap only to + get reasonably good behaviour on all platforms. + + All of the bitmaps must be of the same size and the normal bitmap must be + set first (to a valid bitmap), before setting any other ones. + + The position of the image inside the button be configured using + SetBitmapPosition(). By default the image is on the left of the text. + @library{wxcore} @category{ctrl} @appearance{button.png} @@ -87,11 +115,6 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr); - /** - Destructor, destroying the button. - */ - virtual ~wxButton(); - /** Button creation function for two-step creation. For more details, see wxButton(). @@ -104,6 +127,69 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr); + /** + Return the bitmap shown by the button. + + The returned bitmap may be invalid only if the button doesn't show any + images. + + @see SetBitmap() + + @since 2.9.1 + */ + wxBitmap GetBitmap() const; + + /** + Returns the bitmap used when the mouse is over the button, which may be + invalid. + + @see SetBitmapCurrent() + + @since 2.9.1 (available as wxBitmapButton::GetBitmapHover() in previous + versions) + */ + wxBitmap GetBitmapCurrent() const; + + /** + Returns the bitmap for the disabled state, which may be invalid. + + @see SetBitmapDisabled() + + @since 2.9.1 (available in wxBitmapButton only in previous versions) + */ + wxBitmap GetBitmapDisabled() const; + + /** + Returns the bitmap for the focused state, which may be invalid. + + @see SetBitmapFocus() + + @since 2.9.1 (available in wxBitmapButton only in previous versions) + */ + wxBitmap GetBitmapFocus() const; + + /** + Returns the bitmap for the normal state. + + This is exactly the same as GetBitmap() but uses a name + backwards-compatible with wxBitmapButton. + + @see SetBitmap(), SetBitmapLabel() + + @since 2.9.1 (available in wxBitmapButton only in previous versions) + */ + wxBitmap GetBitmapLabel() const; + + /** + Returns the bitmap for the pressed state, which may be invalid. + + @see SetBitmapPressed() + + @since 2.9.1 (available as wxBitmapButton::GetBitmapSelected() in + previous versions) + */ + wxBitmap GetBitmapPressed() const; + /** Returns the default size for the buttons. It is advised to make all the dialog buttons of the same size and this function allows to retrieve the (platform and @@ -118,6 +204,109 @@ public: */ wxString GetLabel() const; + /** + Sets the bitmap to display in the button. + + The bitmap is displayed together with the button label. This method + sets up a single bitmap which is used in all button states, use + SetBitmapDisabled(), SetBitmapPressed(), SetBitmapCurrent() or + SetBitmapFocus() to change the individual images used in different + states. + + @param bitmap + The bitmap to display in the button. May be invalid to remove any + currently displayed bitmap. + @param dir + 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. + Other possible values include wxRIGHT, wxTOP and wxBOTTOM. + + @see SetBitmapPosition(), SetBitmapMargins() + + @since 2.9.1 + */ + void SetBitmap(const wxBitmap& bitmap, wxDirection dir = wxLEFT); + + /** + Sets the bitmap to be shown when the mouse is over the button. + + @see GetBitmapCurrent() + + @since 2.9.1 (available as wxBitmapButton::SetBitmapHover() in previous + versions) + */ + void SetBitmapCurrent(const wxBitmap& bitmap); + + /** + Sets the bitmap for the disabled button appearance. + + @see GetBitmapDisabled(), SetBitmapLabel(), + SetBitmapPressed(), SetBitmapFocus() + + @since 2.9.1 (available in wxBitmapButton only in previous versions) + */ + void SetBitmapDisabled(const wxBitmap& bitmap); + + /** + Sets the bitmap for the button appearance when it has the keyboard + focus. + + @see GetBitmapFocus(), SetBitmapLabel(), + SetBitmapPressed(), SetBitmapDisabled() + + @since 2.9.1 (available in wxBitmapButton only in previous versions) + */ + void SetBitmapFocus(const wxBitmap& bitmap); + + /** + Sets the bitmap label for the button. + + @remarks This is the bitmap used for the unselected state, and for all + other states if no other bitmaps are provided. + + @see SetBitmap(), GetBitmapLabel() + + @since 2.9.1 (available in wxBitmapButton only in previous versions) + */ + void SetBitmapLabel(const wxBitmap& bitmap); + + /** + Sets the bitmap for the selected (depressed) button appearance. + + @since 2.9.1 (available as wxBitmapButton::SetBitmapSelected() in + previous versions) + */ + void SetBitmapPressed(const wxBitmap& bitmap); + + /** + Set the margins between the bitmap and the text of the button. + + This method is currently only implemented under MSW. If it is not + called, default margin is used around the bitmap. + + @see SetBitmap(), SetBitmapPosition() + + @since 2.9.1 + */ + //@{ + void SetBitmapMargins(wxCoord x, wxCoord y); + void SetBitmapMargins(const wxSize& sz); + //@} + + /** + Set the position at which the bitmap is displayed. + + This method should only be called if the button does have an associated + bitmap. + + @since 2.9.1 + + @param dir + Direction in which the bitmap should be positioned, one of wxLEFT, + wxRIGHT, wxTOP or wxBOTTOM. + */ + void SetBitmapPosition(wxDirection dir); + /** This sets the button to be the default item in its top-level window (e.g. the panel or the dialog box containing it). diff --git a/interface/wx/defs.h b/interface/wx/defs.h index cb756d8ca2..2b2afd8f16 100644 --- a/interface/wx/defs.h +++ b/interface/wx/defs.h @@ -1119,6 +1119,29 @@ template wxDELETEA(T*& array); */ #define wxDEPRECATED_INLINE(func, body) +/** + A helper macro allowing to easily define a simple deprecated accessor. + + Compared to wxDEPRECATED_INLINE() it saves a @c return statement and, + especially, a strangely looking semicolon inside a macro. + + Example of use + @code + class wxFoo + { + public: + int GetValue() const { return m_value; } + + // this one is deprecated because it was erroneously non-const + wxDEPRECATED_ACCESSOR( int GetValue(), m_value ) + + private: + int m_value; + }; + @endcode + */ +#define wxDEPRECATED_ACCESSOR(func, what) + /** Combination of wxDEPRECATED_BUT_USED_INTERNALLY() and wxDEPRECATED_INLINE(). diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index 7920f09130..c6b94b5699 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -134,7 +134,7 @@ bool wxBitmapButton::Create( wxWindow *parent, return false; } - m_bmpNormal = bitmap; + m_bitmaps[State_Normal] = bitmap; m_widget = gtk_button_new(); g_object_ref(m_widget); @@ -142,7 +142,7 @@ bool wxBitmapButton::Create( wxWindow *parent, if (style & wxNO_BORDER) gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); - if (m_bmpNormal.Ok()) + if (bitmap.IsOk()) { OnSetBitmap(); } @@ -190,20 +190,20 @@ void wxBitmapButton::OnSetBitmap() wxBitmap the_one; if (!IsThisEnabled()) - the_one = m_bmpDisabled; + the_one = GetBitmapDisabled(); else if (m_isPressed) - the_one = m_bmpSelected; + the_one = GetBitmapPressed(); else if (m_mouseHovers) - the_one = m_bmpHover; + the_one = GetBitmapHover(); else if (HasFocus()) - the_one = m_bmpFocus; - else - the_one = m_bmpNormal; + the_one = GetBitmapFocus(); - if (!the_one.Ok()) - the_one = m_bmpNormal; - if (!the_one.Ok()) - return; + if (!the_one.IsOk()) + { + the_one = GetBitmapLabel(); + if (!the_one.IsOk()) + return; + } GtkWidget* image = GTK_BIN(m_widget)->child; if (image == NULL) diff --git a/src/motif/bmpbuttn.cpp b/src/motif/bmpbuttn.cpp index 9ebada34b8..0ba91fd8fd 100644 --- a/src/motif/bmpbuttn.cpp +++ b/src/motif/bmpbuttn.cpp @@ -49,8 +49,10 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, return false; PreCreation(); - m_bmpNormal = m_bmpNormalOriginal = bitmap; - m_bmpSelected = m_bmpSelectedOriginal = bitmap; + m_bitmaps[State_Normal] = + m_bitmapsOriginal[State_Normal] = bitmap; + m_bitmaps[State_Pressed] = + m_bitmapsOriginal[State_Pressed] = bitmap; Widget parentWidget = (Widget) parent->GetClientWidget(); @@ -82,7 +84,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, XmNactivateCallback, (XtCallbackProc) wxButtonCallback, (XtPointer) this); - wxSize best = m_bmpNormal.Ok() ? GetBestSize() : wxSize(30, 30); + wxSize best = GetBitmapLabel().IsOk() ? GetBestSize() : wxSize(30, 30); if( size.x != -1 ) best.x = size.x; if( size.y != -1 ) best.y = size.y; @@ -104,39 +106,18 @@ wxBitmapButton::~wxBitmapButton() (Pixmap) m_insensPixmap); } -void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) +void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which) { - m_bmpNormalOriginal = bitmap; - m_bmpNormal = bitmap; + m_bitmapsOriginal[which] = bitmap; - DoSetBitmap(); -} - -void wxBitmapButton::SetBitmapSelected(const wxBitmap& sel) -{ - m_bmpSelected = sel; - m_bmpSelectedOriginal = sel; - - DoSetBitmap(); -} - -void wxBitmapButton::SetBitmapFocus(const wxBitmap& focus) -{ - m_bmpFocus = focus; - // Not used in Motif + wxBitmapButtonBase::DoSetBitmap(bitmap, which); } -void wxBitmapButton::SetBitmapDisabled(const wxBitmap& disabled) +void wxBitmapButton::OnSetBitmap() { - m_bmpDisabled = disabled; - m_bmpDisabledOriginal = disabled; + wxBitmapButtonBase::OnSetBitmap(); - DoSetBitmap(); -} - -void wxBitmapButton::DoSetBitmap() -{ - if (m_bmpNormalOriginal.Ok()) + if ( m_bitmapsOriginal[State_Normal].IsOk() ) { Pixmap pixmap = 0; Pixmap insensPixmap = 0; @@ -144,7 +125,7 @@ void wxBitmapButton::DoSetBitmap() // Must re-make the bitmap to have its transparent areas drawn // in the current widget background colour. - if (m_bmpNormalOriginal.GetMask()) + if ( m_bitmapsOriginal[State_Normal].GetMask() ) { WXPixel backgroundPixel; XtVaGetValues((Widget) m_mainWidget, @@ -155,21 +136,21 @@ void wxBitmapButton::DoSetBitmap() col.SetPixel(backgroundPixel); wxBitmap newBitmap = - wxCreateMaskedBitmap(m_bmpNormalOriginal, col); - m_bmpNormal = newBitmap; - m_bitmapCache.SetBitmap( m_bmpNormal ); + wxCreateMaskedBitmap(m_bitmapsOriginal[State_Normal], col); + m_bitmaps[State_Normal] = newBitmap; + m_bitmapCache.SetBitmap( m_bitmaps[State_Normal] ); - pixmap = (Pixmap) m_bmpNormal.GetDrawable(); + pixmap = (Pixmap) m_bitmaps[State_Normal].GetDrawable(); } else { - m_bitmapCache.SetBitmap( m_bmpNormal ); + m_bitmapCache.SetBitmap( m_bitmaps[State_Normal] ); pixmap = (Pixmap) m_bitmapCache.GetLabelPixmap(m_mainWidget); } - if (m_bmpDisabledOriginal.Ok()) + if (m_bitmapsOriginal[State_Disabled].IsOk()) { - if (m_bmpDisabledOriginal.GetMask()) + if (m_bitmapsOriginal[State_Disabled].GetMask()) { WXPixel backgroundPixel; XtVaGetValues((Widget) m_mainWidget, @@ -180,10 +161,10 @@ void wxBitmapButton::DoSetBitmap() col.SetPixel(backgroundPixel); wxBitmap newBitmap = - wxCreateMaskedBitmap(m_bmpDisabledOriginal, col); - m_bmpDisabled = newBitmap; + wxCreateMaskedBitmap(m_bitmapsOriginal[State_Disabled], col); + m_bitmaps[State_Disabled] = newBitmap; - insensPixmap = (Pixmap) m_bmpDisabled.GetDrawable(); + insensPixmap = (Pixmap) m_bitmaps[State_Disabled].GetDrawable(); } else insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget); @@ -192,9 +173,9 @@ void wxBitmapButton::DoSetBitmap() insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget); // Now make the bitmap representing the armed state - if (m_bmpSelectedOriginal.Ok()) + if (m_bitmapsOriginal[State_Pressed].IsOk()) { - if (m_bmpSelectedOriginal.GetMask()) + if (m_bitmapsOriginal[State_Pressed].GetMask()) { WXPixel backgroundPixel; XtVaGetValues((Widget) m_mainWidget, @@ -205,10 +186,10 @@ void wxBitmapButton::DoSetBitmap() col.SetPixel(backgroundPixel); wxBitmap newBitmap = - wxCreateMaskedBitmap(m_bmpSelectedOriginal, col); - m_bmpSelected = newBitmap; + wxCreateMaskedBitmap(m_bitmapsOriginal[State_Pressed], col); + m_bitmaps[State_Pressed] = newBitmap; - armPixmap = (Pixmap) m_bmpSelected.GetDrawable(); + armPixmap = (Pixmap) m_bitmaps[State_Pressed].GetDrawable(); } else armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget); @@ -248,11 +229,13 @@ wxSize wxBitmapButton::DoGetBestSize() const { wxSize ret( 30,30 ); - if (m_bmpNormal.Ok()) + if (GetBitmapLabel().IsOk()) { - int border = (GetWindowStyle() & wxNO_BORDER) ? 4 : 10; - ret.x = m_bmpNormal.GetWidth()+border; - ret.y = m_bmpNormal.GetHeight()+border; + int border = HasFlag(wxNO_BORDER) ? 4 : 10; + ret.x += border; + ret.y += border; + + ret += GetBitmapLabel().GetSize(); } return ret; diff --git a/src/msw/bmpbuttn.cpp b/src/msw/bmpbuttn.cpp index 5cc8685060..0f38686c31 100644 --- a/src/msw/bmpbuttn.cpp +++ b/src/msw/bmpbuttn.cpp @@ -190,53 +190,55 @@ void wxBitmapButton::OnSysColourChanged(wxSysColourChangedEvent& event) void wxBitmapButton::OnMouseEnterOrLeave(wxMouseEvent& event) { - if ( IsEnabled() && m_bmpHover.Ok() ) + if ( IsEnabled() && m_bitmaps[State_Current].IsOk() ) Refresh(); event.Skip(); } -void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) +void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which) { -#if wxUSE_IMAGE - if ( !HasFlag(wxBU_AUTODRAW) && !m_disabledSetByUser && bitmap.IsOk() ) + if ( bitmap.IsOk() ) { - m_bmpDisabled = wxBitmap(bitmap.ConvertToImage().ConvertToGreyscale()); - } + switch ( which ) + { +#if wxUSE_IMAGE + case State_Normal: + if ( !HasFlag(wxBU_AUTODRAW) && !m_disabledSetByUser ) + { + wxImage img(bitmap.ConvertToImage().ConvertToGreyscale()); + m_bitmaps[State_Disabled] = wxBitmap(img); + } + break; #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 - // Windows version look and feel - // - // 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 ( focus.Ok() && !m_hoverSetByUser ) - m_bmpHover = m_bmpFocus; - - 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; + case State_Focused: + // if the focus bitmap is specified but current one isn't, use + // the focus bitmap for hovering as well if this is consistent + // with the current Windows version look and feel + // + // 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_hoverSetByUser ) + m_bitmaps[State_Current] = bitmap; + break; + + case State_Current: + // don't overwrite it with the focused bitmap + m_hoverSetByUser = true; + break; + + case State_Disabled: + // don't overwrite it with the version automatically created + // from the normal one + m_disabledSetByUser = true; + break; + } + } - wxBitmapButtonBase::SetBitmapHover(hover); + wxBitmapButtonBase::DoSetBitmap(bitmap, which); } #if wxUSE_UXTHEME @@ -331,33 +333,38 @@ bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item) HDC hDC = lpDIS->hDC; UINT state = lpDIS->itemState; bool isSelected = (state & ODS_SELECTED) != 0; - bool autoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0; + bool autoDraw = HasFlag(wxBU_AUTODRAW); // choose the bitmap to use depending on the button state - wxBitmap *bitmap; - - if ( isSelected && m_bmpSelected.Ok() ) - bitmap = &m_bmpSelected; - else if ( m_bmpHover.Ok() && IsMouseInWindow() ) - bitmap = &m_bmpHover; - else if ((state & ODS_FOCUS) && m_bmpFocus.Ok()) - bitmap = &m_bmpFocus; - else if ((state & ODS_DISABLED) && m_bmpDisabled.Ok()) - bitmap = &m_bmpDisabled; - else - bitmap = &m_bmpNormal; + wxBitmap bitmap; - if ( !bitmap->Ok() ) - return false; + if ( isSelected ) + bitmap = GetBitmapSelected(); + else if ( IsMouseInWindow() ) + bitmap = GetBitmapCurrent(); + else if ( state & ODS_DISABLED ) + bitmap = GetBitmapDisabled(); + + if ( !bitmap.IsOk() ) + { + if ( state & ODS_FOCUS ) + bitmap = GetBitmapFocus(); + + if ( !bitmap.IsOk() ) + bitmap = GetBitmapLabel(); + + if ( !bitmap.IsOk() ) + return false; + } // centre the bitmap in the control area int x = lpDIS->rcItem.left; int y = lpDIS->rcItem.top; int width = lpDIS->rcItem.right - x; int height = lpDIS->rcItem.bottom - y; - int wBmp = bitmap->GetWidth(); - int hBmp = bitmap->GetHeight(); + int wBmp = bitmap.GetWidth(); + int hBmp = bitmap.GetHeight(); #if wxUSE_UXTHEME if ( autoDraw && wxUxThemeEngine::GetIfActive() ) @@ -404,7 +411,7 @@ bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item) // draw the bitmap wxDCTemp dst((WXHDC)hDC); - dst.DrawBitmap(*bitmap, x1, y1, true); + dst.DrawBitmap(bitmap, x1, y1, true); return true; } @@ -443,7 +450,7 @@ bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item) // draw the bitmap wxDCTemp dst((WXHDC)hDC); - dst.DrawBitmap(*bitmap, x1, y1, true); + dst.DrawBitmap(bitmap, x1, y1, true); // draw focus / disabled state, if auto-drawing if ( (state & ODS_DISABLED) && autoDraw ) @@ -544,7 +551,7 @@ wxBitmapButton::DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg ) { - if ( !m_brushDisabled.Ok() ) + if ( !m_brushDisabled.IsOk() ) { // draw a bitmap with two black and two background colour pixels wxBitmap bmp(2, 2); @@ -579,10 +586,10 @@ wxBitmapButton::DrawButtonDisable( WXHDC dc, wxSize wxBitmapButton::DoGetBestSize() const { - if ( m_bmpNormal.Ok() ) + if ( GetBitmapLabel().IsOk() ) { - int width = m_bmpNormal.GetWidth(), - height = m_bmpNormal.GetHeight(); + int width = GetBitmapLabel().GetWidth(), + height = GetBitmapLabel().GetHeight(); int marginH = 0, marginV = 0; diff --git a/src/msw/button.cpp b/src/msw/button.cpp index ef43802277..305638ca4a 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -58,6 +58,11 @@ #define TMT_CONTENTMARGINS 3602 #endif + + #ifndef BCM_SETIMAGELIST + #define BCM_SETIMAGELIST 0x1602 + #define BCM_SETTEXTMARGIN 0x1604 + #endif #endif // wxUSE_UXTHEME #ifndef WM_THEMECHANGED diff --git a/src/os2/bmpbuttn.cpp b/src/os2/bmpbuttn.cpp index bfaf5a7217..6112b02a56 100644 --- a/src/os2/bmpbuttn.cpp +++ b/src/os2/bmpbuttn.cpp @@ -36,7 +36,7 @@ bool wxBitmapButton::Create( wxWindow* pParent, const wxValidator& rValidator, const wxString& rsName ) { - m_bmpNormal = rBitmap; + m_bitmaps[State_Normal] = rBitmap; SetName(rsName); #if wxUSE_VALIDATORS SetValidator(rValidator); @@ -64,10 +64,10 @@ bool wxBitmapButton::Create( wxWindow* pParent, else m_windowId = vId; - if (nWidth == wxDefaultCoord && rBitmap.Ok()) + if (nWidth == wxDefaultCoord && rBitmap.IsOk()) nWidth = rBitmap.GetWidth() + 4 * m_marginX; - if (nHeight == wxDefaultCoord && rBitmap.Ok()) + if (nHeight == wxDefaultCoord && rBitmap.IsOk()) nHeight = rBitmap.GetHeight() + 4 * m_marginY; ULONG ulOS2Style = WS_VISIBLE | WS_TABSTOP | BS_USERBUTTON; @@ -108,21 +108,23 @@ bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem) if (!pUser) return false; - wxBitmap* pBitmap; + wxBitmap bitmap; bool bIsSelected = pUser->fsState & BDS_HILITED; wxClientDC vDc(this); - if (bIsSelected && m_bmpSelected.Ok()) - pBitmap = &m_bmpSelected; - else if ((pUser->fsState & BDS_DEFAULT) && m_bmpFocus.Ok()) - pBitmap = &m_bmpFocus; - else if ((pUser->fsState & BDS_DISABLED) && m_bmpDisabled.Ok()) - pBitmap = &m_bmpDisabled; - else - pBitmap = &m_bmpNormal; + if (bIsSelected) + bitmap = GetBitmapPressed(); + else if (pUser->fsState & BDS_DEFAULT) + bitmap = GetBitmapFocus(); + else if (pUser->fsState & BDS_DISABLED) + bitmap = GetBitmapDisabled(); - if (!pBitmap->Ok() ) - return false; + if (!bitmap.IsOk() ) + { + bitmap = GetBitmapLabel(); + if (!bitmap.IsOk() ) + return false; + } // @@ -133,8 +135,8 @@ bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem) wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl(); int nWidth = impl->m_vRclPaint.xRight - impl->m_vRclPaint.xLeft; int nHeight = impl->m_vRclPaint.yTop - impl->m_vRclPaint.yBottom; - int nBmpWidth = pBitmap->GetWidth(); - int nBmpHeight = pBitmap->GetHeight(); + int nBmpWidth = bitmap.GetWidth(); + int nBmpHeight = bitmap.GetHeight(); nX1 = (nWidth - nBmpWidth) / 2; nY1 = (nHeight - nBmpHeight) / 2; @@ -153,14 +155,14 @@ bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem) // // Draw the bitmap // - vDc.DrawBitmap( *pBitmap, nX1, nY1, true ); + vDc.DrawBitmap( bitmap, nX1, nY1, true ); // // Draw focus / disabled state, if auto-drawing // if ((pUser->fsState == BDS_DISABLED) && bAutoDraw) { - DrawButtonDisable( vDc, *pBitmap ); + DrawButtonDisable( vDc, bitmap ); } else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw) { diff --git a/src/osx/bmpbuttn_osx.cpp b/src/osx/bmpbuttn_osx.cpp index 195c0ffc79..f4c76447f4 100644 --- a/src/osx/bmpbuttn_osx.cpp +++ b/src/osx/bmpbuttn_osx.cpp @@ -27,7 +27,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) //--------------------------------------------------------------------------- bool wxBitmapButton::Create( wxWindow *parent, - wxWindowID id, const wxBitmap& bitmap, + wxWindowID id, + const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, @@ -36,8 +37,6 @@ bool wxBitmapButton::Create( wxWindow *parent, { m_macIsUserPane = false; - // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create - // essentially creates an additional button if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) return false; @@ -52,7 +51,7 @@ bool wxBitmapButton::Create( wxWindow *parent, m_marginY = 0; } - m_bmpNormal = bitmap; + m_bitmaps[State_Normal] = bitmap; m_peer = wxWidgetImpl::CreateBitmapButton( this, parent, id, bitmap, pos, size, style, GetExtraStyle() ); @@ -62,25 +61,24 @@ bool wxBitmapButton::Create( wxWindow *parent, } void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap ) -{ +{ InvalidateBestSize(); - + m_peer->SetBitmap( bitmap ); } wxSize wxBitmapButton::DoGetBestSize() const { - wxSize best; + wxSize best(m_marginX, m_marginY); - best.x = 2 * m_marginX; - best.y = 2 * m_marginY; - if ( m_bmpNormal.Ok() ) + best *= 2; + + if ( GetBitmapLabel().IsOk() ) { - best.x += m_bmpNormal.GetWidth(); - best.y += m_bmpNormal.GetHeight(); + best += GetBitmapLabel().GetSize(); } return best; } -#endif +#endif // wxUSE_BMPBUTTON diff --git a/src/univ/bmpbuttn.cpp b/src/univ/bmpbuttn.cpp index 2a9f873ccc..eb4faa5584 100644 --- a/src/univ/bmpbuttn.cpp +++ b/src/univ/bmpbuttn.cpp @@ -65,7 +65,7 @@ bool wxBitmapButton::Create(wxWindow *parent, pos, size, style | wxBU_EXACTFIT, validator, name) ) return false; - m_bmpNormal = bitmap; + m_bitmaps[State_Normal] = bitmap; return true; } @@ -75,27 +75,24 @@ void wxBitmapButton::OnSetBitmap() wxBitmap bmp; if ( !IsEnabled() ) { - bmp = m_bmpDisabled; + bmp = GetBitmapDisabled(); } else if ( IsPressed() ) { - bmp = m_bmpSelected; + bmp = GetBitmapPressed(); } else if ( IsFocused() ) { - bmp = m_bmpFocus; - } - else - { - bmp = m_bmpNormal; + bmp = GetBitmapFocus(); } + //else: just leave it invalid, this means "normal" anyhow in ChangeBitmap() ChangeBitmap(bmp); } bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp) { - wxBitmap bitmap = bmp.Ok() ? bmp : m_bmpNormal; + wxBitmap bitmap = bmp.IsOk() ? bmp : GetBitmapLabel(); if ( bitmap.IsSameAs(m_bitmap) ) return false; @@ -109,7 +106,7 @@ bool wxBitmapButton::Enable(bool enable) if ( !wxButton::Enable(enable) ) return false; - if ( !enable && ChangeBitmap(m_bmpDisabled) ) + if ( !enable && ChangeBitmap(GetBitmapDisabled()) ) Refresh(); return true; @@ -117,14 +114,14 @@ bool wxBitmapButton::Enable(bool enable) bool wxBitmapButton::SetCurrent(bool doit) { - ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal); + ChangeBitmap(doit ? GetBitmapFocus() : GetBitmapLabel()); return wxButton::SetCurrent(doit); } void wxBitmapButton::OnSetFocus(wxFocusEvent& event) { - if ( ChangeBitmap(m_bmpFocus) ) + if ( ChangeBitmap(GetBitmapFocus()) ) Refresh(); event.Skip(); @@ -132,7 +129,7 @@ void wxBitmapButton::OnSetFocus(wxFocusEvent& event) void wxBitmapButton::OnKillFocus(wxFocusEvent& event) { - if ( ChangeBitmap(m_bmpNormal) ) + if ( ChangeBitmap(GetBitmapLabel()) ) Refresh(); event.Skip(); @@ -140,14 +137,14 @@ void wxBitmapButton::OnKillFocus(wxFocusEvent& event) void wxBitmapButton::Press() { - ChangeBitmap(m_bmpSelected); + ChangeBitmap(GetBitmapPressed()); wxButton::Press(); } void wxBitmapButton::Release() { - ChangeBitmap(IsFocused() ? m_bmpFocus : m_bmpNormal); + ChangeBitmap(IsFocused() ? GetBitmapFocus() : GetBitmapLabel()); wxButton::Release(); } diff --git a/src/univ/button.cpp b/src/univ/button.cpp index 7bda74e449..05f3c3373f 100644 --- a/src/univ/button.cpp +++ b/src/univ/button.cpp @@ -128,7 +128,7 @@ bool wxButton::Create(wxWindow *parent, SetLabel(label); if (bitmap.Ok()) - SetImageLabel(bitmap); // SetInitialSize called by SetImageLabel() + SetBitmap(bitmap); // SetInitialSize called by SetBitmap() else SetInitialSize(size); @@ -315,14 +315,17 @@ wxInputHandler *wxButton::GetStdInputHandler(wxInputHandler *handlerDef) // misc // ---------------------------------------------------------------------------- -void wxButton::SetImageLabel(const wxBitmap& bitmap) +void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which) { - m_bitmap = bitmap; + // we support only one bitmap right now, although this wouldn't be + // difficult to change + if ( which == State_Normal ) + m_bitmap = bitmap; - SetImageMargins(DEFAULT_BTN_MARGIN_X, DEFAULT_BTN_MARGIN_Y); + SetBitmapMargins(DEFAULT_BTN_MARGIN_X, DEFAULT_BTN_MARGIN_Y); } -void wxButton::SetImageMargins(wxCoord x, wxCoord y) +void wxButton::DoSetBitmapMargins(wxCoord x, wxCoord y) { m_marginBmpX = x + 2; m_marginBmpY = y + 2; -- 2.45.2