From 94b8ecf1cdefea63f07f9ed2b54a2ad2556ec001 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sat, 31 Jan 2009 11:48:28 +0000 Subject: [PATCH] Fixed broken 'hidden categories' mode (aka. alphabetic mode); Added distinct names and labels for the two root properties (to help with debugging); Refactored wxPropertyGridState::DoInsert() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58543 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/property.h | 2 +- include/wx/propgrid/propgridpagestate.h | 7 ++- src/propgrid/property.cpp | 7 ++- src/propgrid/propgridpagestate.cpp | 75 ++++++++++--------------- 4 files changed, 41 insertions(+), 50 deletions(-) diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index fb4dc1cae2..8fe0448c76 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -2358,7 +2358,7 @@ public: public: /** Constructor. */ - wxPGRootProperty(); + wxPGRootProperty( const wxString& name = wxS("") ); virtual ~wxPGRootProperty(); virtual bool StringToValue( wxVariant&, const wxString&, int ) const diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index ec1c8064ef..9f3764a71e 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -569,9 +569,6 @@ public: bool IsInNonCatMode() const { return (bool)(m_properties == m_abcArray); } - /** Only inits arrays, doesn't migrate things or such. */ - void InitNonCatMode (); - void DoLimitPropertyEditing( wxPGProperty* p, bool limit = true ) { p->SetFlagRecursively(wxPG_PROP_NOEDITOR, limit); @@ -707,6 +704,10 @@ protected: unsigned char m_anyModified; unsigned char m_vhCalcPending; + +private: + /** Only inits arrays, doesn't migrate things or such. */ + void InitNonCatMode(); }; #endif // #ifndef SWIG diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 05a46fdb0d..dc3d8fc346 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2430,11 +2430,14 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty,none,TextCtrl) IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty, wxPGProperty) -wxPGRootProperty::wxPGRootProperty() +wxPGRootProperty::wxPGRootProperty( const wxString& name ) : wxPGProperty() { #ifdef __WXDEBUG__ - m_name = wxS(""); + m_name = name; + m_label = m_name; +#else + wxUnusedVar(name); #endif SetParentalType(0); m_depth = 0; diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 51959e3362..59c3a88a39 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -231,7 +231,7 @@ void wxPropertyGridPageState::InitNonCatMode() { if ( !m_abcArray ) { - m_abcArray = new wxPGRootProperty(); + m_abcArray = new wxPGRootProperty(wxS("")); m_abcArray->SetParentState(this); m_abcArray->SetFlag(wxPG_PROP_CHILDREN_ARE_COPIES); } @@ -683,17 +683,9 @@ void wxPropertyGridPageState::DoSort( int flags ) { DoSortChildren( m_properties, flags | wxPG_RECURSE ); - // Sort categories as well (but we need not do it recursively) - if ( IsInNonCatMode() ) - { - size_t i; - for ( i=0;iIsCategory() ) - DoSortChildren( p, 0 ); - } - } + // We used to sort categories as well here also if in non-categorized + // mode, but doing would naturally cause child indices to become + // corrupted. } // ----------------------------------------------------------------------- @@ -1644,6 +1636,9 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index if ( !res ) return m_currentCategory; + bool parentIsRoot = parent->IsRoot(); + bool parentIsCategory = parent->IsCategory(); + // Note that item must be added into current mode later. // If parent is wxParentProperty, just stick it in... @@ -1656,42 +1651,34 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index // 1) Add to given category in given index. // 2) Add as last item in m_abcArray. - if ( !parent->IsCategory() && !parent->IsRoot() ) - { - // Parent is wxParentingProperty: Just stick it in... - parent->AddChild2( property, index ); - } - else + if ( m_properties == &m_regularArray ) { - // Parent is Category or Root. + // We are currently in Categorized mode - if ( m_properties == &m_regularArray ) + // Only add non-categories to m_abcArray. + if ( m_abcArray && !property->IsCategory() && + (parentIsCategory || parentIsRoot) ) { - // Categorized mode - - // Only add non-categories to m_abcArray. - if ( m_abcArray && !property->IsCategory() ) - m_abcArray->AddChild2( property, -1, false ); - - // Add to current mode. - parent->AddChild2( property, index ); - + m_abcArray->AddChild2( property, -1, false ); } - else - { - // Non-categorized mode. - if ( parent != m_properties ) - // Parent is category. - parent->AddChild2( property, index, false ); - else - // Parent is root. - m_regularArray.AddChild2( property, -1, false ); - - // Add to current mode (no categories). - if ( !property->IsCategory() ) - m_abcArray->AddChild2( property, index ); - } + // Add to current mode. + parent->AddChild2( property, index, true ); + } + else + { + // We are currently in Non-categorized/Alphabetic mode + + if ( parentIsCategory ) + // Parent is category. + parent->AddChild2( property, index, false ); + else if ( parentIsRoot ) + // Parent is root. + m_regularArray.AddChild2( property, -1, false ); + + // Add to current mode + if ( !property->IsCategory() ) + m_abcArray->AddChild2( property, index, true ); } // category stuff @@ -1705,7 +1692,7 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index // Only add name to hashmap if parent is root or category if ( property->m_name.length() && - (parent->IsCategory() || parent->IsRoot()) ) + (parentIsCategory || parentIsRoot) ) m_dictName[property->m_name] = (void*) property; VirtualHeightChanged(); -- 2.45.2