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
This commit is contained in:
Jaakko Salli
2009-08-18 14:28:08 +00:00
parent f9136b63ee
commit 7f3f8f1e85
3 changed files with 45 additions and 25 deletions

View File

@@ -517,6 +517,8 @@ public:
return DoSelectProperty(NULL); return DoSelectProperty(NULL);
} }
void DoRemoveFromSelection( wxPGProperty* prop );
wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const; wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const;
wxPGProperty* GetPropertyByLabel( const wxString& name, wxPGProperty* GetPropertyByLabel( const wxString& name,

View File

@@ -784,7 +784,7 @@ bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty* prop, int selFlags )
} }
else else
{ {
selection.Remove(prop); m_pState->DoRemoveFromSelection(prop);
RefreshProperty(prop); RefreshProperty(prop);
res = true; res = true;
} }

View File

@@ -605,23 +605,6 @@ bool wxPropertyGridPageState::EnableCategories( bool enable )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
#if wxUSE_STL
#include <algorithm>
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) static int wxPG_SortFunc_ByFunction(wxPGProperty **pp1, wxPGProperty **pp2)
{ {
wxPGProperty *p1 = *pp1; wxPGProperty *p1 = *pp1;
@@ -638,6 +621,24 @@ static int wxPG_SortFunc_ByLabel(wxPGProperty **pp1, wxPGProperty **pp2)
return p1->GetLabel().CmpNoCase( p2->GetLabel() ); return p1->GetLabel().CmpNoCase( p2->GetLabel() );
} }
#if 0
//
// For wxVector w/ wxUSE_STL=1, you would use code like this instead:
//
#include <algorithm>
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 #endif
void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p,
@@ -658,18 +659,21 @@ void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p,
&& !p->IsCategory() && !p->IsRoot() ) && !p->IsCategory() && !p->IsRoot() )
return; 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() ) if ( GetGrid()->GetSortFunction() )
std::sort(p->m_children.begin(), p->m_children.end(), std::sort(p->m_children.begin(), p->m_children.end(),
wxPG_SortFunc_ByFunction); wxPG_SortFunc_ByFunction);
else else
std::sort(p->m_children.begin(), p->m_children.end(), std::sort(p->m_children.begin(), p->m_children.end(),
wxPG_SortFunc_ByLabel); wxPG_SortFunc_ByLabel);
#else
if ( GetGrid()->GetSortFunction() )
p->m_children.Sort( wxPG_SortFunc_ByFunction );
else
p->m_children.Sort( wxPG_SortFunc_ByLabel );
#endif #endif
// Fix indices // Fix indices
@@ -1208,6 +1212,20 @@ bool wxPropertyGridPageState::DoIsPropertySelected( wxPGProperty* prop ) const
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void wxPropertyGridPageState::DoRemoveFromSelection( wxPGProperty* prop )
{
for ( unsigned int i=0; i<m_selection.size(); i++ )
{
if ( m_selection[i] == prop )
{
m_selection.erase( m_selection.begin() + i );
return;
}
}
}
// -----------------------------------------------------------------------
bool wxPropertyGridPageState::DoCollapse( wxPGProperty* p ) bool wxPropertyGridPageState::DoCollapse( wxPGProperty* p )
{ {
wxCHECK_MSG( p, false, wxT("invalid property id") ); wxCHECK_MSG( p, false, wxT("invalid property id") );
@@ -1740,7 +1758,7 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
} }
else else
{ {
m_selection.Remove(item); DoRemoveFromSelection(item);
} }
} }