Add a flag to wxUpdateUIEvent to tell if the item supports the check action

Not all items support check being set in an UpdateUIEvent handler,
so it is nice to provide an API to find out if the item supports it.

Fixes #13369
This commit is contained in:
Ian McInerney
2020-08-20 23:10:42 +01:00
parent 5192feb38e
commit 65e124bb64
9 changed files with 28 additions and 1 deletions

View File

@@ -2891,10 +2891,12 @@ public:
m_setEnabled = m_setEnabled =
m_setShown = m_setShown =
m_setText = m_setText =
m_setChecked = false; m_setChecked =
m_isCheckable = false;
} }
wxUpdateUIEvent(const wxUpdateUIEvent& event) wxUpdateUIEvent(const wxUpdateUIEvent& event)
: wxCommandEvent(event), : wxCommandEvent(event),
m_isCheckable(event.m_isCheckable),
m_checked(event.m_checked), m_checked(event.m_checked),
m_enabled(event.m_enabled), m_enabled(event.m_enabled),
m_shown(event.m_shown), m_shown(event.m_shown),
@@ -2919,6 +2921,10 @@ public:
void Show(bool show) { m_shown = show; m_setShown = true; } void Show(bool show) { m_shown = show; m_setShown = true; }
void SetText(const wxString& text) { m_text = text; m_setText = true; } void SetText(const wxString& text) { m_text = text; m_setText = true; }
// Set a flag saying if the object being updated supports the check action
bool IsCheckable() const { return m_isCheckable; }
void SetIsCheckable(bool aCheckable) { m_isCheckable = aCheckable; }
// Sets the interval between updates in milliseconds. // Sets the interval between updates in milliseconds.
// Set to -1 to disable updates, or to 0 to update as frequently as possible. // Set to -1 to disable updates, or to 0 to update as frequently as possible.
static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; } static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; }
@@ -2944,6 +2950,7 @@ public:
virtual wxEvent *Clone() const wxOVERRIDE { return new wxUpdateUIEvent(*this); } virtual wxEvent *Clone() const wxOVERRIDE { return new wxUpdateUIEvent(*this); }
protected: protected:
bool m_isCheckable;
bool m_checked; bool m_checked;
bool m_enabled; bool m_enabled;
bool m_shown; bool m_shown;

View File

@@ -2374,6 +2374,13 @@ public:
*/ */
bool GetEnabled() const; bool GetEnabled() const;
/**
Returns @true if the UI element can be checked.
@since 3.1.5
*/
bool IsCheckable() const;
/** /**
Static function returning a value specifying how wxWidgets will send update Static function returning a value specifying how wxWidgets will send update
events: to all windows, or only to those which specify that they will process events: to all windows, or only to those which specify that they will process

View File

@@ -2200,6 +2200,9 @@ void wxAuiToolBar::DoIdleUpdate()
wxUpdateUIEvent evt(item.m_toolId); wxUpdateUIEvent evt(item.m_toolId);
evt.SetEventObject(this); evt.SetEventObject(this);
if ( item.m_kind == wxITEM_CHECK || item.m_kind == wxITEM_RADIO )
evt.SetIsCheckable(true);
if (handler->ProcessEvent(evt)) if (handler->ProcessEvent(evt))
{ {
if (evt.GetSetEnabled()) if (evt.GetSetEnabled())

View File

@@ -616,6 +616,7 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source)
wxWindowID itemid = item->GetId(); wxWindowID itemid = item->GetId();
wxUpdateUIEvent event(itemid); wxUpdateUIEvent event(itemid);
event.SetEventObject( this ); event.SetEventObject( this );
event.SetIsCheckable(item->IsCheckable());
if ( source->ProcessEvent(event) ) if ( source->ProcessEvent(event) )
{ {

View File

@@ -738,6 +738,7 @@ void wxToolBarBase::UpdateWindowUI(long flags)
wxUpdateUIEvent event(toolid); wxUpdateUIEvent event(toolid);
event.SetEventObject(this); event.SetEventObject(this);
event.SetIsCheckable(tool->CanBeToggled());
if ( evtHandler->ProcessEvent(event) ) if ( evtHandler->ProcessEvent(event) )
{ {

View File

@@ -2817,6 +2817,7 @@ void wxWindowBase::UpdateWindowUI(long flags)
{ {
wxUpdateUIEvent event(GetId()); wxUpdateUIEvent event(GetId());
event.SetEventObject(this); event.SetEventObject(this);
event.SetIsCheckable(true);
if ( GetEventHandler()->ProcessEvent(event) ) if ( GetEventHandler()->ProcessEvent(event) )
{ {

View File

@@ -324,6 +324,11 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow
wxUpdateUIEvent event(menuid); wxUpdateUIEvent event(menuid);
event.SetEventObject( this ); event.SetEventObject( this );
if ( item )
event.SetIsCheckable(item->IsCheckable());
else
event.SetIsCheckable(true);
bool processed = DoProcessEvent(this, event, GetWindow()); bool processed = DoProcessEvent(this, event, GetWindow());
if ( !processed && senderWindow != NULL) if ( !processed && senderWindow != NULL)

View File

@@ -905,6 +905,7 @@ void wxRibbonButtonBar::UpdateWindowUI(long flags)
wxUpdateUIEvent event(id); wxUpdateUIEvent event(id);
event.SetEventObject(this); event.SetEventObject(this);
event.SetIsCheckable(true);
if ( ProcessWindowEvent(event) ) if ( ProcessWindowEvent(event) )
{ {

View File

@@ -1178,6 +1178,7 @@ void wxRibbonToolBar::UpdateWindowUI(long flags)
wxUpdateUIEvent event(id); wxUpdateUIEvent event(id);
event.SetEventObject(this); event.SetEventObject(this);
event.SetIsCheckable(true);
if ( ProcessWindowEvent(event) ) if ( ProcessWindowEvent(event) )
{ {