diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index 99f899a0ed..9239043908 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -1572,8 +1572,8 @@ protected: wxPGCell m_unspecifiedAppearance; // List of properties to be deleted/removed in idle event handler. - wxArrayPGProperty m_deletedProperties; - wxArrayPGProperty m_removedProperties; + wxVector m_deletedProperties; + wxVector m_removedProperties; #if !WXWIN_COMPATIBILITY_3_0 // List of editors and their event handlers to be deleted in idle event handler. @@ -2280,7 +2280,7 @@ public: // added. wxPGProperty* GetCurParent() const { - return (wxPGProperty*) m_propHierarchy[m_propHierarchy.size()-1]; + return m_propHierarchy.back(); } wxPropertyGridPageState* GetState() { return m_state; } @@ -2309,7 +2309,7 @@ protected: wxPropertyGridPageState* m_state; // Tree-hierarchy of added properties (that can have children). - wxArrayPGProperty m_propHierarchy; + wxVector m_propHierarchy; // Hashmap for string-id to wxPGChoicesData mapping. wxPGHashMapS2P m_dictIdChoices; diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 6fb3782835..1981069b3b 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -5588,17 +5588,20 @@ void wxPropertyGrid::ClearActionTriggers( int action ) } #if WXWIN_COMPATIBILITY_3_0 -// Utility to find if specific item is in a vector. Returns index to -// the item, or wxNOT_FOUND if not present. -template -int wxPGFindInVector( CONTAINER vector, const T& item ) +// Utility to check if specific item is in a vector. +template +static bool wxPGItemExistsInVector(const wxVector& vector, const T& item) { - for ( unsigned int i=0; i::const_iterator it = vector.begin(); it != vector.end(); ++it) { - if ( vector[i] == item ) - return (int) i; + if ( *it == item ) + return true; } - return wxNOT_FOUND; + return false; +#endif // wxUSE_STL/!wxUSE_STL } #endif // WXWIN_COMPATIBILITY_3_0 @@ -5706,7 +5709,7 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) if ( fromChild && #if WXWIN_COMPATIBILITY_3_0 // Deprecated: use a hash set instead. - wxPGFindInVector(m_dedicatedKeys, keycode) == wxNOT_FOUND ) + !wxPGItemExistsInVector(m_dedicatedKeys, keycode) ) #else m_dedicatedKeys.find(keycode) == m_dedicatedKeys.end() ) #endif @@ -6602,11 +6605,10 @@ bool wxPropertyGridPopulator::AddAttribute( const wxString& name, const wxString& type, const wxString& value ) { - int l = m_propHierarchy.size(); - if ( !l ) + if ( m_propHierarchy.empty() ) return false; - wxPGProperty* p = m_propHierarchy[l-1]; + wxPGProperty* p = m_propHierarchy.back(); wxString valuel = value.Lower(); wxVariant variant; diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 870354a27f..679c39b405 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -43,6 +43,43 @@ #define wxPG_DEFAULT_SPLITTERX 110 +// Utility to remove given item from the vector. +template +static void wxPGRemoveItemFromVector(wxVector& vector, const T& item) +{ +#if wxUSE_STL + wxVector::iterator it = std::find(vector.begin(), vector.end(), item); + if ( it != vector.end() ) + { + vector.erase(it); + } +#else + for (wxVector::iterator it = vector.begin(); it != vector.end(); ++it) + { + if ( *it == item ) + { + vector.erase(it); + return; + } + } +#endif // wxUSE_STL/!wxUSE_STL +} + +// Utility to check if specific item is in a vector. +template +static bool wxPGItemExistsInVector(const wxVector& vector, const T& item) +{ +#if wxUSE_STL + return std::find(vector.begin(), vector.end(), item) != vector.end(); +#else + for (wxVector::const_iterator it = vector.begin(); it != vector.end(); ++it) + { + if ( *it == item ) + return true; + } + return false; +#endif // wxUSE_STL/!wxUSE_STL +} // ----------------------------------------------------------------------- // wxPropertyGridIterator @@ -303,16 +340,8 @@ void wxPropertyGridPageState::DoClear() for (unsigned int i = 0; i < m_regularArray.GetChildCount(); i++) { wxPGProperty* p = m_regularArray.Item(i); - int index = m_pPropGrid->m_deletedProperties.Index(p); - if (index != wxNOT_FOUND) - { - m_pPropGrid->m_deletedProperties.RemoveAt(index); - } - index = m_pPropGrid->m_removedProperties.Index(p); - if (index != wxNOT_FOUND) - { - m_pPropGrid->m_removedProperties.RemoveAt(index); - } + wxPGRemoveItemFromVector(m_pPropGrid->m_deletedProperties, p); + wxPGRemoveItemFromVector(m_pPropGrid->m_removedProperties, p); } m_regularArray.Empty(); @@ -2004,14 +2033,14 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) // Prevent adding duplicates to the lists. if ( doDelete ) { - if ( pg->m_deletedProperties.Index(item) != wxNOT_FOUND ) + if ( wxPGItemExistsInVector(pg->m_deletedProperties, item) ) return; pg->m_deletedProperties.push_back(item); } else { - if ( pg->m_removedProperties.Index(item) != wxNOT_FOUND ) + if ( wxPGItemExistsInVector(pg->m_removedProperties, item) ) return; pg->m_removedProperties.push_back(item); @@ -2112,20 +2141,12 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) { // Remove the item from both lists of pending operations. // (Deleted item cannot be also the subject of further removal.) - int index = pg->m_deletedProperties.Index(item); - if ( index != wxNOT_FOUND ) - { - pg->m_deletedProperties.RemoveAt(index); - } - wxASSERT_MSG( pg->m_deletedProperties.Index(item) == wxNOT_FOUND, + wxPGRemoveItemFromVector(pg->m_deletedProperties, item); + wxASSERT_MSG( !wxPGItemExistsInVector(pg->m_deletedProperties, item), wxS("Too many occurrences of the item")); - index = pg->m_removedProperties.Index(item); - if ( index != wxNOT_FOUND ) - { - pg->m_removedProperties.RemoveAt(index); - } - wxASSERT_MSG( pg->m_removedProperties.Index(item) == wxNOT_FOUND, + wxPGRemoveItemFromVector(pg->m_removedProperties, item); + wxASSERT_MSG( !wxPGItemExistsInVector(pg->m_removedProperties, item), wxS("Too many occurrences of the item")); delete item; @@ -2133,12 +2154,8 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) else { // Remove the item from the list of pending removals. - int index = pg->m_removedProperties.Index(item); - if ( index != wxNOT_FOUND ) - { - pg->m_removedProperties.RemoveAt(index); - } - wxASSERT_MSG( pg->m_removedProperties.Index(item) == wxNOT_FOUND, + wxPGRemoveItemFromVector(pg->m_removedProperties, item); + wxASSERT_MSG( !wxPGItemExistsInVector(pg->m_removedProperties, item), wxS("Too many occurrences of the item")); item->OnDetached(this, pg);