From 65e124bb645427e135590a7379512d1b9ac1229d Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 20 Aug 2020 23:10:42 +0100 Subject: [PATCH] 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 --- include/wx/event.h | 9 ++++++++- interface/wx/event.h | 7 +++++++ src/aui/auibar.cpp | 3 +++ src/common/menucmn.cpp | 1 + src/common/tbarbase.cpp | 1 + src/common/wincmn.cpp | 1 + src/osx/menu_osx.cpp | 5 +++++ src/ribbon/buttonbar.cpp | 1 + src/ribbon/toolbar.cpp | 1 + 9 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/wx/event.h b/include/wx/event.h index f4477868b1..6f0128c76d 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -2891,10 +2891,12 @@ public: m_setEnabled = m_setShown = m_setText = - m_setChecked = false; + m_setChecked = + m_isCheckable = false; } wxUpdateUIEvent(const wxUpdateUIEvent& event) : wxCommandEvent(event), + m_isCheckable(event.m_isCheckable), m_checked(event.m_checked), m_enabled(event.m_enabled), m_shown(event.m_shown), @@ -2919,6 +2921,10 @@ public: void Show(bool show) { m_shown = show; m_setShown = 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. // Set to -1 to disable updates, or to 0 to update as frequently as possible. static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; } @@ -2944,6 +2950,7 @@ public: virtual wxEvent *Clone() const wxOVERRIDE { return new wxUpdateUIEvent(*this); } protected: + bool m_isCheckable; bool m_checked; bool m_enabled; bool m_shown; diff --git a/interface/wx/event.h b/interface/wx/event.h index ff18c94bb1..d2683e5970 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -2374,6 +2374,13 @@ public: */ 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 events: to all windows, or only to those which specify that they will process diff --git a/src/aui/auibar.cpp b/src/aui/auibar.cpp index f97bf53adb..83f022371e 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -2200,6 +2200,9 @@ void wxAuiToolBar::DoIdleUpdate() wxUpdateUIEvent evt(item.m_toolId); evt.SetEventObject(this); + if ( item.m_kind == wxITEM_CHECK || item.m_kind == wxITEM_RADIO ) + evt.SetIsCheckable(true); + if (handler->ProcessEvent(evt)) { if (evt.GetSetEnabled()) diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 73e0568c50..da51fc32b1 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -616,6 +616,7 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source) wxWindowID itemid = item->GetId(); wxUpdateUIEvent event(itemid); event.SetEventObject( this ); + event.SetIsCheckable(item->IsCheckable()); if ( source->ProcessEvent(event) ) { diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index 3c2a6e99a7..285a5ddb8f 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -738,6 +738,7 @@ void wxToolBarBase::UpdateWindowUI(long flags) wxUpdateUIEvent event(toolid); event.SetEventObject(this); + event.SetIsCheckable(tool->CanBeToggled()); if ( evtHandler->ProcessEvent(event) ) { diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 9b2e522920..2aca66e556 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2817,6 +2817,7 @@ void wxWindowBase::UpdateWindowUI(long flags) { wxUpdateUIEvent event(GetId()); event.SetEventObject(this); + event.SetIsCheckable(true); if ( GetEventHandler()->ProcessEvent(event) ) { diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 712f2a95d9..3c8552ffa4 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -324,6 +324,11 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow wxUpdateUIEvent event(menuid); event.SetEventObject( this ); + if ( item ) + event.SetIsCheckable(item->IsCheckable()); + else + event.SetIsCheckable(true); + bool processed = DoProcessEvent(this, event, GetWindow()); if ( !processed && senderWindow != NULL) diff --git a/src/ribbon/buttonbar.cpp b/src/ribbon/buttonbar.cpp index 7e631d88a0..52751002fa 100644 --- a/src/ribbon/buttonbar.cpp +++ b/src/ribbon/buttonbar.cpp @@ -905,6 +905,7 @@ void wxRibbonButtonBar::UpdateWindowUI(long flags) wxUpdateUIEvent event(id); event.SetEventObject(this); + event.SetIsCheckable(true); if ( ProcessWindowEvent(event) ) { diff --git a/src/ribbon/toolbar.cpp b/src/ribbon/toolbar.cpp index ec6c2e0054..dffc8147c4 100644 --- a/src/ribbon/toolbar.cpp +++ b/src/ribbon/toolbar.cpp @@ -1178,6 +1178,7 @@ void wxRibbonToolBar::UpdateWindowUI(long flags) wxUpdateUIEvent event(id); event.SetEventObject(this); + event.SetIsCheckable(true); if ( ProcessWindowEvent(event) ) {