From 7f3f8f1e85e34898a30a8463ca73c86d6550548d Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Tue, 18 Aug 2009 14:28:08 +0000 Subject: [PATCH] Made code that uses wxArrayPGProperty more STL compliant (still can't use wxVector for it because I think there is no wx equivalent of std::sort) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61695 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/propgridpagestate.h | 2 + src/propgrid/propgrid.cpp | 2 +- src/propgrid/propgridpagestate.cpp | 66 ++++++++++++++++--------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index 9aa0c11335..1f5e00078e 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -517,6 +517,8 @@ public: return DoSelectProperty(NULL); } + void DoRemoveFromSelection( wxPGProperty* prop ); + wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const; wxPGProperty* GetPropertyByLabel( const wxString& name, diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 5f3801518a..bedca1688b 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -784,7 +784,7 @@ bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty* prop, int selFlags ) } else { - selection.Remove(prop); + m_pState->DoRemoveFromSelection(prop); RefreshProperty(prop); res = true; } diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 966a921002..fa4d8cf261 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -605,23 +605,6 @@ bool wxPropertyGridPageState::EnableCategories( bool enable ) // ----------------------------------------------------------------------- -#if wxUSE_STL -#include - -static bool wxPG_SortFunc_ByFunction(wxPGProperty *p1, wxPGProperty *p2) -{ - wxPropertyGrid* pg = p1->GetGrid(); - wxPGSortCallback sortFunction = pg->GetSortFunction(); - return sortFunction(pg, p1, p2) < 0; -} - -static bool wxPG_SortFunc_ByLabel(wxPGProperty *p1, wxPGProperty *p2) -{ - return p1->GetLabel().CmpNoCase( p2->GetLabel() ) < 0; -} - -#else - static int wxPG_SortFunc_ByFunction(wxPGProperty **pp1, wxPGProperty **pp2) { wxPGProperty *p1 = *pp1; @@ -638,6 +621,24 @@ static int wxPG_SortFunc_ByLabel(wxPGProperty **pp1, wxPGProperty **pp2) return p1->GetLabel().CmpNoCase( p2->GetLabel() ); } +#if 0 +// +// For wxVector w/ wxUSE_STL=1, you would use code like this instead: +// + +#include + +static bool wxPG_SortFunc_ByFunction(wxPGProperty *p1, wxPGProperty *p2) +{ + wxPropertyGrid* pg = p1->GetGrid(); + wxPGSortCallback sortFunction = pg->GetSortFunction(); + return sortFunction(pg, p1, p2) < 0; +} + +static bool wxPG_SortFunc_ByLabel(wxPGProperty *p1, wxPGProperty *p2) +{ + return p1->GetLabel().CmpNoCase( p2->GetLabel() ) < 0; +} #endif void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, @@ -658,18 +659,21 @@ void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, && !p->IsCategory() && !p->IsRoot() ) return; -#if wxUSE_STL + if ( GetGrid()->GetSortFunction() ) + p->m_children.Sort( wxPG_SortFunc_ByFunction ); + else + p->m_children.Sort( wxPG_SortFunc_ByLabel ); + +#if 0 + // + // For wxVector w/ wxUSE_STL=1, you would use code like this instead: + // if ( GetGrid()->GetSortFunction() ) std::sort(p->m_children.begin(), p->m_children.end(), wxPG_SortFunc_ByFunction); else std::sort(p->m_children.begin(), p->m_children.end(), wxPG_SortFunc_ByLabel); -#else - if ( GetGrid()->GetSortFunction() ) - p->m_children.Sort( wxPG_SortFunc_ByFunction ); - else - p->m_children.Sort( wxPG_SortFunc_ByLabel ); #endif // Fix indices @@ -1208,6 +1212,20 @@ bool wxPropertyGridPageState::DoIsPropertySelected( wxPGProperty* prop ) const // ----------------------------------------------------------------------- +void wxPropertyGridPageState::DoRemoveFromSelection( wxPGProperty* prop ) +{ + for ( unsigned int i=0; i