diff --git a/include/wx/aui/auibar.h b/include/wx/aui/auibar.h index 05b841983a..6b612b545a 100644 --- a/include/wx/aui/auibar.h +++ b/include/wx/aui/auibar.h @@ -525,6 +525,12 @@ public: void ClearTools() { Clear() ; } void Clear(); + + bool DestroyTool(int toolId); + bool DestroyToolByIndex(int idx); + + // Note that these methods do _not_ delete the associated control, if any. + // Use DestroyTool() or DestroyToolByIndex() if this is wanted. bool DeleteTool(int toolId); bool DeleteByIndex(int toolId); diff --git a/interface/wx/aui/auibar.h b/interface/wx/aui/auibar.h index a3e23752d7..04e261b7a3 100644 --- a/interface/wx/aui/auibar.h +++ b/interface/wx/aui/auibar.h @@ -724,11 +724,33 @@ public: void Clear(); /** - Removes the tool with the given ID from the tool bar. + Destroys the tool with the given ID and its associated window, if any. + + @param tool_id ID of a previously added tool. + @return @true if the tool was destroyed or @false otherwise, e.g. if + the tool with the given ID was not found. + + @since 3.1.4 + */ + bool DestroyTool(int tool_id); + + /** + Destroys the tool at the given position and its associated window, if + any. + + @param idx The index, or position, of a previously added tool. + @return @true if the tool was destroyed or @false otherwise, e.g. if + the provided index is out of range. + */ + bool DestroyToolByIndex(int idx); + + /** + Removes the tool with the given ID from the toolbar. Note that if this tool was added by AddControl(), the associated control is @e not deleted and must either be reused (e.g. by reparenting it under a different window) or destroyed by caller. + If this behaviour is unwanted, prefer using DestroyTool() instead. @param tool_id ID of a previously added tool. @return @true if the tool was removed or @false otherwise, e.g. if the @@ -737,11 +759,13 @@ public: bool DeleteTool(int tool_id); /** - Removes the tool at the given position from the tool bar. + Removes the tool at the given position from the toolbar. Note that if this tool was added by AddControl(), the associated control is @e not deleted and must either be reused (e.g. by reparenting it under a different window) or destroyed by caller. + If this behaviour is unwanted, prefer using DestroyToolByIndex() + instead. @param idx The index, or position, of a previously added tool. @return @true if the tool was removed or @false otherwise, e.g. if the diff --git a/src/aui/auibar.cpp b/src/aui/auibar.cpp index 2d2fd80bb3..22c1b45d3f 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -1180,6 +1180,22 @@ bool wxAuiToolBar::DeleteByIndex(int idx) return false; } +bool wxAuiToolBar::DestroyTool(int tool_id) +{ + return DestroyToolByIndex(GetToolIndex(tool_id)); +} + +bool wxAuiToolBar::DestroyToolByIndex(int idx) +{ + if ( idx < 0 || static_cast(idx) >= m_items.GetCount() ) + return false; + + if ( wxWindow* window = m_items[idx].GetWindow() ) + window->Destroy(); + + return DeleteByIndex(idx); +} + wxControl* wxAuiToolBar::FindControl(int id) {