Fix setting "pressed" bitmap for wxToggleButton.

Move wxAnyButton::GetNormalState(), which allows wxToggleButton to override
what "normal" means for it, down to the platform-independent wxAnyButtonBase
class and use it now in wxGTK as well to correctly choose the pressed bitmap
for a toggle button in this state.

Closes #16771.
This commit is contained in:
Kevin B. McCarty
2015-05-09 19:22:28 +02:00
committed by Vadim Zeitlin
parent c0ae81ced7
commit 1ad4596e8c
7 changed files with 36 additions and 18 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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; }

View File

@@ -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; }

View File

@@ -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);

View File

@@ -139,8 +139,12 @@ 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;
@@ -149,7 +153,18 @@ wxAnyButton::State wxAnyButton::GTKGetCurrentBitmapState() const
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;
}

View File

@@ -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