diff --git a/docs/changes.txt b/docs/changes.txt index 6024c25123..4c82ec6c28 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -121,6 +121,7 @@ wxGTK: - Support building wxGTK3 under Windows (Kolya Kosenko). - Fix vertical cell alignment in wxDataViewCtrl. - Fix clearing of wxComboBox with wxCB_READONLY (Chuddah). +- Fix setting "pressed" bitmap for wxToggleButton (Kevin B. McCarty). - Fix GTK+ warnings for wxFileDialog with wxFD_MULTIPLE style. wxMSW: diff --git a/include/wx/anybutton.h b/include/wx/anybutton.h index 9f170b9a95..ff41ce999c 100644 --- a/include/wx/anybutton.h +++ b/include/wx/anybutton.h @@ -135,6 +135,13 @@ public: State_Max }; + // return the current setting for the "normal" state of the button, it can + // be different from State_Normal for a wxToggleButton + virtual State GetNormalState() const + { + return State_Normal; + } + // return true if this button shouldn't show the text label, either because // it doesn't have it or because it was explicitly disabled with wxBU_NOTEXT bool DontShowLabel() const diff --git a/include/wx/msw/anybutton.h b/include/wx/msw/anybutton.h index 75a24464b9..3c876aeb2d 100644 --- a/include/wx/msw/anybutton.h +++ b/include/wx/msw/anybutton.h @@ -36,7 +36,6 @@ public: virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item); - virtual State GetNormalState() const { return State_Normal; } // returns true if the platform should explicitly apply a theme border virtual bool CanApplyThemeBorder() const { return false; } diff --git a/include/wx/msw/tglbtn.h b/include/wx/msw/tglbtn.h index 523c4489ec..0dec96fa11 100644 --- a/include/wx/msw/tglbtn.h +++ b/include/wx/msw/tglbtn.h @@ -46,8 +46,6 @@ public: virtual bool MSWCommand(WXUINT param, WXWORD id); virtual void Command(wxCommandEvent& event); - virtual State GetNormalState() const; - // returns true if the platform should explicitly apply a theme border virtual bool CanApplyThemeBorder() const { return false; } diff --git a/include/wx/tglbtn.h b/include/wx/tglbtn.h index 7cef5be1cc..bb11446696 100644 --- a/include/wx/tglbtn.h +++ b/include/wx/tglbtn.h @@ -36,6 +36,12 @@ public: virtual void SetValue(bool state) = 0; virtual bool GetValue() const = 0; + // The current "normal" state for the toggle button depends upon its value. + virtual State GetNormalState() const wxOVERRIDE + { + return GetValue() ? State_Pressed : State_Normal; + } + void UpdateWindowUI(long flags) wxOVERRIDE { wxControl::UpdateWindowUI(flags); diff --git a/src/gtk/anybutton.cpp b/src/gtk/anybutton.cpp index f2df6f069b..8088bab14b 100644 --- a/src/gtk/anybutton.cpp +++ b/src/gtk/anybutton.cpp @@ -139,17 +139,32 @@ void wxAnyButton::GTKOnFocus(wxFocusEvent& event) wxAnyButton::State wxAnyButton::GTKGetCurrentBitmapState() const { if ( !IsThisEnabled() ) - return m_bitmaps[State_Disabled].IsOk() ? State_Disabled : State_Normal; + { + if ( m_bitmaps[State_Disabled].IsOk() ) + return State_Disabled; + } + else + { + if ( m_isPressed && m_bitmaps[State_Pressed].IsOk() ) + return State_Pressed; - if ( m_isPressed && m_bitmaps[State_Pressed].IsOk() ) - return State_Pressed; + if ( m_isCurrent && m_bitmaps[State_Current].IsOk() ) + return State_Current; - if ( m_isCurrent && m_bitmaps[State_Current].IsOk() ) - return State_Current; + if ( HasFocus() && m_bitmaps[State_Focused].IsOk() ) + return State_Focused; + } - if ( HasFocus() && m_bitmaps[State_Focused].IsOk() ) - return State_Focused; + // Fall back on the normal state: which still might be different from + // State_Normal for the toggle buttons, so the check for bitmap validity is + // still needed. + const State normalState = GetNormalState(); + if ( m_bitmaps[normalState].IsOk() ) + return normalState; + // And if nothing else can (or should) be used, finally fall back to the + // normal state which is the only one guaranteed to have a bitmap (if we're + // using bitmaps at all and we're only called in this case). return State_Normal; } diff --git a/src/msw/tglbtn.cpp b/src/msw/tglbtn.cpp index cd83ea9613..7791e08c0e 100644 --- a/src/msw/tglbtn.cpp +++ b/src/msw/tglbtn.cpp @@ -190,12 +190,4 @@ bool wxToggleButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) return true; } -wxAnyButton::State wxToggleButton::GetNormalState() const -{ - if ( GetValue() ) - return State_Pressed; - else - return State_Normal; -} - #endif // wxUSE_TOGGLEBTN