From 0eb877f2c1bdb9d937dac85c7b374b1e9c511b9c Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sat, 10 Jan 2009 15:16:03 +0000 Subject: [PATCH] Reverted to old wxPG_AUTO_SORT behavior in which only root properties and immediate children of categories are (automatically) sorted; Added Sort flags; Applied slight optimization when sorting on propgridmanager page change git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57975 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/propgriddefs.h | 7 +++- include/wx/propgrid/propgridiface.h | 19 ++++++---- include/wx/propgrid/propgridpagestate.h | 6 ++-- interface/wx/propgrid/propgridiface.h | 17 ++++++--- src/propgrid/propgrid.cpp | 5 ++- src/propgrid/propgridiface.cpp | 4 +-- src/propgrid/propgridpagestate.cpp | 46 ++++++++++++++++++------- 7 files changed, 73 insertions(+), 31 deletions(-) diff --git a/include/wx/propgrid/propgriddefs.h b/include/wx/propgrid/propgriddefs.h index 996823d03b..cff40b5048 100644 --- a/include/wx/propgrid/propgriddefs.h +++ b/include/wx/propgrid/propgriddefs.h @@ -387,7 +387,12 @@ wxPG_INC_ATTRIBUTES = 0x00000040, wxPG_RECURSE_STARTS = 0x00000080, /** Force value change. */ -wxPG_FORCE = 0x00000100 +wxPG_FORCE = 0x00000100, + +/** Only sort categories and their immediate children. + Sorting done by wxPG_AUTO_SORT option uses this. +*/ +wxPG_SORT_TOP_LEVEL_ONLY = 0x00000200 }; diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index 8c8b39d47d..fb8158ed0d 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -1227,11 +1227,17 @@ public: void SetValidationFailureBehavior( int vfbFlags ); /** - Sorts all properties. + Sorts all properties recursively. + + @param flags + This can contain any of the following options: + wxPG_SORT_TOP_LEVEL_ONLY: Only sort categories and their + immediate children. Sorting done by wxPG_AUTO_SORT option + uses this. @see SortChildren, wxPropertyGrid::SetSortFunction */ - void Sort(); + void Sort( int flags = 0 ); /** Sorts children of a property. @@ -1239,15 +1245,16 @@ public: @param id Name or pointer to a property. - @param recursively - If @true, then children are sorted recursively. + @param flags + This can contain any of the following options: + wxPG_RECURSE: Sorts recursively. @see Sort, wxPropertyGrid::SetSortFunction */ - void SortChildren( wxPGPropArg id, bool recursively = false ) + void SortChildren( wxPGPropArg id, int flags = 0 ) { wxPG_PROP_ARG_CALL_PROLOG() - m_pState->DoSortChildren(p, recursively); + m_pState->DoSortChildren(p, flags); } #ifdef SWIG diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index 4c9172de82..658147f150 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -613,8 +613,10 @@ public: /** Set virtual width for this particular page. */ void SetVirtualWidth( int width ); - void DoSortChildren( wxPGProperty* p, bool recursively = false ); - void DoSort(); + void DoSortChildren( wxPGProperty* p, int flags = 0 ); + void DoSort( int flags = 0 ); + + bool PrepareAfterItemsAdded(); void SetSelection( wxPGProperty* p ) { m_selected = p; } diff --git a/interface/wx/propgrid/propgridiface.h b/interface/wx/propgrid/propgridiface.h index 97725fad6c..83bc402577 100644 --- a/interface/wx/propgrid/propgridiface.h +++ b/interface/wx/propgrid/propgridiface.h @@ -902,11 +902,17 @@ public: void SetValidationFailureBehavior( int vfbFlags ); /** - Sorts all properties. + Sorts all properties recursively. + + @param flags + This can contain any of the following options: + wxPG_SORT_TOP_LEVEL_ONLY: Only sort categories and their + immediate children. Sorting done by wxPG_AUTO_SORT option + uses this. @see SortChildren, wxPropertyGrid::SetSortFunction */ - void Sort(); + void Sort( int flags = 0 ); /** Sorts children of a property. @@ -914,12 +920,13 @@ public: @param id Name or pointer to a property. - @param recursively - If @true, then children are sorted recursively. + @param flags + This can contain any of the following options: + wxPG_RECURSE: Sorts recursively. @see Sort, wxPropertyGrid::SetSortFunction */ - void SortChildren( wxPGPropArg id, bool recursively = false ); + void SortChildren( wxPGPropArg id, int flags = 0 ); /** Returns editor pointer of editor with given name; diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 4eaae9aedd..2d91cae007 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -1180,7 +1180,7 @@ void wxPropertyGrid::PrepareAfterItemsAdded() m_pState->m_itemsAdded = 0; if ( m_windowStyle & wxPG_AUTO_SORT ) - Sort(); + Sort(wxPG_SORT_TOP_LEVEL_ONLY); RecalculateVirtualSize(); } @@ -2277,8 +2277,7 @@ void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState ) else if ( !m_frozen ) { // Refresh, if not frozen. - if ( m_pState->m_itemsAdded ) - PrepareAfterItemsAdded(); + m_pState->PrepareAfterItemsAdded(); // Reselect if ( m_pState->m_selected ) diff --git a/src/propgrid/propgridiface.cpp b/src/propgrid/propgridiface.cpp index 033f061213..afa04000c8 100644 --- a/src/propgrid/propgridiface.cpp +++ b/src/propgrid/propgridiface.cpp @@ -762,7 +762,7 @@ bool wxPropertyGridInterface::Expand( wxPGPropArg id ) // ----------------------------------------------------------------------- -void wxPropertyGridInterface::Sort() +void wxPropertyGridInterface::Sort( int flags ) { wxPropertyGrid* pg = GetPropertyGrid(); @@ -774,7 +774,7 @@ void wxPropertyGridInterface::Sort() { wxPropertyGridPageState* page = GetPageState(pageIndex); if ( !page ) break; - page->DoSort(); + page->DoSort(flags); pageIndex++; } } diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index db836d605d..0803b12037 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -635,16 +635,21 @@ static int wxPG_SortFunc_ByLabel(wxPGProperty **pp1, wxPGProperty **pp2) #endif void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, - bool recursively ) + int flags ) { if ( !p ) p = m_properties; + // Can only sort items with children if ( !p->GetChildCount() ) return; - // Can only sort items with children - if ( p->GetChildCount() < 1 ) + // Never sort children of aggregate properties + if ( p->HasFlag(wxPG_PROP_AGGREGATE) ) + return; + + if ( (flags & wxPG_SORT_TOP_LEVEL_ONLY) + && !p->IsCategory() && !p->IsRoot() ) return; #if wxUSE_STL @@ -661,35 +666,52 @@ void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, p->m_children.Sort( wxPG_SortFunc_ByLabel ); #endif - // Fix indexes + // Fix indices p->FixIndicesOfChildren(); - if ( recursively && !p->HasFlag(wxPG_PROP_AGGREGATE) ) + if ( flags & wxPG_RECURSE ) { + // Apply sort recursively for ( unsigned int i=0; iGetChildCount(); i++ ) - DoSortChildren(p->Item(i)); + DoSortChildren(p->Item(i), flags); } } // ----------------------------------------------------------------------- -void wxPropertyGridPageState::DoSort() +void wxPropertyGridPageState::DoSort( int flags ) { - DoSortChildren( m_properties, true ); + DoSortChildren( m_properties, flags | wxPG_RECURSE ); // Sort categories as well (but we need not do it recursively) - if ( !IsInNonCatMode() ) + if ( IsInNonCatMode() ) { size_t i; - for ( i=0;iGetChildCount();i++) + for ( i=0;iItem(i); + wxPGProperty* p = m_regularArray.Item(i); if ( p->IsCategory() ) - DoSortChildren( p ); + DoSortChildren( p, 0 ); } } } +// ----------------------------------------------------------------------- + +bool wxPropertyGridPageState::PrepareAfterItemsAdded() +{ + if ( !m_itemsAdded ) return false; + + wxPropertyGrid* pg = GetGrid(); + + m_itemsAdded = 0; + + if ( pg->HasFlag(wxPG_AUTO_SORT) ) + DoSort(wxPG_SORT_TOP_LEVEL_ONLY); + + return true; +} + // ----------------------------------------------------------------------- // wxPropertyGridPageState splitter, column and hittest functions // ----------------------------------------------------------------------- -- 2.47.2