diff --git a/include/wx/aui/auibar.h b/include/wx/aui/auibar.h index 6b612b545a..2e2f3e3a52 100644 --- a/include/wx/aui/auibar.h +++ b/include/wx/aui/auibar.h @@ -211,6 +211,11 @@ public: void SetAlignment(int l) { m_alignment = l; } int GetAlignment() const { return m_alignment; } + bool CanBeToggled() const + { + return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; + } + private: wxWindow* m_window; // item's associated window diff --git a/include/wx/event.h b/include/wx/event.h index f4477868b1..5042ada638 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -2892,6 +2892,7 @@ public: m_setShown = m_setText = m_setChecked = false; + m_isCheckable = true; } wxUpdateUIEvent(const wxUpdateUIEvent& event) : wxCommandEvent(event), @@ -2902,6 +2903,7 @@ public: m_setShown(event.m_setShown), m_setText(event.m_setText), m_setChecked(event.m_setChecked), + m_isCheckable(event.m_isCheckable), m_text(event.m_text) { } @@ -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; } + // A flag saying if the item can be checked. True by default. + bool IsCheckable() const { return m_isCheckable; } + void DisallowCheck() { m_isCheckable = false; } + // 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; } @@ -2951,6 +2957,7 @@ protected: bool m_setShown; bool m_setText; bool m_setChecked; + bool m_isCheckable; wxString m_text; #if wxUSE_LONGLONG static wxLongLong sm_lastUpdate; diff --git a/interface/wx/aui/auibar.h b/interface/wx/aui/auibar.h index 2c118bd19b..5d2e640272 100644 --- a/interface/wx/aui/auibar.h +++ b/interface/wx/aui/auibar.h @@ -407,6 +407,13 @@ public: */ int GetAlignment() const; + + /** + Returns whether the toolbar item can be toggled. + + @since 3.1.5 + */ + bool CanBeToggled() const; }; /** diff --git a/interface/wx/event.h b/interface/wx/event.h index ff18c94bb1..061c5de997 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -2374,6 +2374,26 @@ public: */ bool GetEnabled() const; + /** + Returns @true if the UI element can be checked. + + For the event handlers that can be used for multiple items, not all of + which can be checked, this method can be useful to determine whether + to call Check() on the event object or not, i.e. the main use case for + this method is: + @code + void MyWindow::OnUpdateUI(wxUpdateUIEvent& event) + { + .... + if ( event.IsCheckable() ) + event.Check(...some condition...); + } + @endcode + + @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..eacb77e7be 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -1546,7 +1546,7 @@ void wxAuiToolBar::ToggleTool(int tool_id, bool state) { wxAuiToolBarItem* tool = FindTool(tool_id); - if (tool && (tool->m_kind == wxITEM_CHECK || tool->m_kind == wxITEM_RADIO)) + if ( tool && tool->CanBeToggled() ) { if (tool->m_kind == wxITEM_RADIO) { @@ -1587,13 +1587,8 @@ bool wxAuiToolBar::GetToolToggled(int tool_id) const { wxAuiToolBarItem* tool = FindTool(tool_id); - if (tool) - { - if ( (tool->m_kind != wxITEM_CHECK) && (tool->m_kind != wxITEM_RADIO) ) - return false; - + if ( tool && tool->CanBeToggled() ) return (tool->m_state & wxAUI_BUTTON_STATE_CHECKED) ? true : false; - } return false; } @@ -2200,6 +2195,9 @@ void wxAuiToolBar::DoIdleUpdate() wxUpdateUIEvent evt(item.m_toolId); evt.SetEventObject(this); + if ( !item.CanBeToggled() ) + evt.DisallowCheck(); + if (handler->ProcessEvent(evt)) { if (evt.GetSetEnabled()) diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 73e0568c50..f70e85e002 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -617,6 +617,9 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source) wxUpdateUIEvent event(itemid); event.SetEventObject( this ); + if ( !item->IsCheckable() ) + event.DisallowCheck(); + if ( source->ProcessEvent(event) ) { // if anything changed, update the changed attribute diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index 3c2a6e99a7..c44dfdf175 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -739,6 +739,9 @@ void wxToolBarBase::UpdateWindowUI(long flags) wxUpdateUIEvent event(toolid); event.SetEventObject(this); + if ( !tool->CanBeToggled() ) + event.DisallowCheck(); + if ( evtHandler->ProcessEvent(event) ) { if ( event.GetSetEnabled() ) diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 712f2a95d9..df85dc2c89 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -324,6 +324,9 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow wxUpdateUIEvent event(menuid); event.SetEventObject( this ); + if ( !item || !item->IsCheckable() ) + event.DisallowCheck(); + bool processed = DoProcessEvent(this, event, GetWindow()); if ( !processed && senderWindow != NULL)