1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgridiface.cpp
3 // Purpose: wxPropertyGridInterface class
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/settings.h"
40 #include "wx/propgrid/property.h"
41 #include "wx/propgrid/propgrid.h"
44 const wxChar
*wxPGTypeName_long
= wxT("long");
45 const wxChar
*wxPGTypeName_bool
= wxT("bool");
46 const wxChar
*wxPGTypeName_double
= wxT("double");
47 const wxChar
*wxPGTypeName_wxString
= wxT("string");
48 const wxChar
*wxPGTypeName_void
= wxT("void*");
49 const wxChar
*wxPGTypeName_wxArrayString
= wxT("arrstring");
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxPoint
, WXDLLIMPEXP_PROPGRID
)
57 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxSize
, WXDLLIMPEXP_PROPGRID
)
58 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(wxArrayInt
, WXDLLIMPEXP_PROPGRID
)
59 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxFont
, WXDLLIMPEXP_PROPGRID
)
61 // -----------------------------------------------------------------------
63 // -----------------------------------------------------------------------
65 wxPGProperty
* wxPGPropArgCls::GetPtr( wxPropertyGridInterface
* iface
) const
67 if ( m_flags
== IsProperty
)
69 wxASSERT_MSG( m_ptr
.property
, wxT("invalid property ptr") );
70 return m_ptr
.property
;
72 else if ( m_flags
& IsWxString
)
73 return iface
->GetPropertyByNameA(*m_ptr
.stringName
);
74 else if ( m_flags
& IsCharPtr
)
75 return iface
->GetPropertyByNameA(m_ptr
.charName
);
77 else if ( m_flags
& IsWCharPtr
)
78 return iface
->GetPropertyByNameA(m_ptr
.wcharName
);
84 // -----------------------------------------------------------------------
85 // wxPropertyGridInterface
86 // -----------------------------------------------------------------------
88 void wxPropertyGridInterface::RefreshGrid( wxPropertyGridPageState
* state
)
93 wxPropertyGrid
* grid
= state
->GetGrid();
94 if ( grid
->GetState() == state
&& !grid
->IsFrozen() )
100 // -----------------------------------------------------------------------
102 wxPGProperty
* wxPropertyGridInterface::Append( wxPGProperty
* property
)
104 wxPGProperty
* retp
= m_pState
->DoAppend(property
);
106 wxPropertyGrid
* grid
= m_pState
->GetGrid();
113 // -----------------------------------------------------------------------
115 wxPGProperty
* wxPropertyGridInterface::AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
)
117 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
118 wxPGProperty
* pwc
= (wxPGProperty
*) p
;
119 wxPGProperty
* retp
= m_pState
->DoInsert(pwc
, pwc
->GetChildCount(), newproperty
);
123 // -----------------------------------------------------------------------
125 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, wxPGProperty
* property
)
127 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
128 wxPGProperty
* retp
= m_pState
->DoInsert(p
->GetParent(), p
->GetIndexInParent(), property
);
133 // -----------------------------------------------------------------------
135 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, int index
, wxPGProperty
* newproperty
)
137 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
138 wxPGProperty
* retp
= m_pState
->DoInsert((wxPGProperty
*)p
,index
,newproperty
);
143 // -----------------------------------------------------------------------
145 void wxPropertyGridInterface::DeleteProperty( wxPGPropArg id
)
147 wxPG_PROP_ARG_CALL_PROLOG()
149 wxPropertyGridPageState
* state
= p
->GetParentState();
151 state
->DoDelete( p
, true );
156 // -----------------------------------------------------------------------
158 wxPGProperty
* wxPropertyGridInterface::RemoveProperty( wxPGPropArg id
)
160 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
162 wxCHECK( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
),
165 wxPropertyGridPageState
* state
= p
->GetParentState();
167 state
->DoDelete( p
, false );
169 // Mark the property as 'unattached'
170 p
->m_parentState
= NULL
;
178 // -----------------------------------------------------------------------
180 wxPGProperty
* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
182 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
184 wxPGProperty
* replaced
= p
;
185 wxCHECK_MSG( replaced
&& property
,
187 wxT("NULL property") );
188 wxCHECK_MSG( !replaced
->IsCategory(),
190 wxT("cannot replace this type of property") );
191 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
193 wxT("cannot replace properties in alphabetic mode") );
195 // Get address to the slot
196 wxPGProperty
* parent
= replaced
->GetParent();
197 int ind
= replaced
->GetIndexInParent();
199 wxPropertyGridPageState
* state
= replaced
->GetParentState();
200 DeleteProperty(replaced
); // Must use generic Delete
201 state
->DoInsert(parent
,ind
,property
);
206 // -----------------------------------------------------------------------
207 // wxPropertyGridInterface property operations
208 // -----------------------------------------------------------------------
210 wxPGProperty
* wxPropertyGridInterface::GetSelection() const
212 return m_pState
->GetSelection();
215 // -----------------------------------------------------------------------
217 bool wxPropertyGridInterface::ClearSelection( bool validation
)
219 bool res
= DoClearSelection(validation
, wxPG_SEL_DONT_SEND_EVENT
);
220 GetPropertyGrid()->Refresh();
224 // -----------------------------------------------------------------------
226 bool wxPropertyGridInterface::DoClearSelection( bool validation
,
230 selFlags
|= wxPG_SEL_NOVALIDATE
;
232 wxPropertyGridPageState
* state
= m_pState
;
236 wxPropertyGrid
* pg
= state
->GetGrid();
237 if ( pg
->GetState() == state
)
238 return pg
->DoSelectProperty(NULL
, selFlags
);
240 state
->DoSetSelection(NULL
);
246 // -----------------------------------------------------------------------
248 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
250 wxPG_PROP_ARG_CALL_PROLOG()
252 m_pState
->DoLimitPropertyEditing(p
, limit
);
256 // -----------------------------------------------------------------------
258 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
260 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
262 wxPropertyGridPageState
* state
= p
->GetParentState();
263 wxPropertyGrid
* grid
= state
->GetGrid();
267 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
270 // If active, Set active Editor.
271 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
272 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
276 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
279 // If active, Disable as active Editor.
280 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
281 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
284 state
->DoEnableProperty(p
, enable
);
286 RefreshProperty( p
);
291 // -----------------------------------------------------------------------
293 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
295 wxPropertyGridPageState
* state
= m_pState
;
297 if ( !state
->DoGetRoot()->GetChildCount() )
300 wxPropertyGrid
* pg
= state
->GetGrid();
302 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
305 pg
->DoClearSelection();
310 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
312 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
313 if ( p
->GetChildCount() )
317 if ( !p
->IsExpanded() )
324 if ( p
->IsExpanded() )
326 state
->DoCollapse(p
);
332 pg
->RecalculateVirtualSize();
339 // -----------------------------------------------------------------------
341 void wxPropertyGridInterface::ClearModifiedStatus()
343 unsigned int pageIndex
= 0;
347 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
350 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
355 // Update active editor control, if any
356 GetPropertyGrid()->RefreshEditor();
359 // -----------------------------------------------------------------------
360 // wxPropertyGridInterface property value setting and getting
361 // -----------------------------------------------------------------------
363 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
365 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
368 // -----------------------------------------------------------------------
370 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
371 const wxString
& typestr
,
374 wxASSERT( p
!= NULL
);
375 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
376 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
379 // -----------------------------------------------------------------------
381 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
383 wxPG_PROP_ARG_CALL_PROLOG()
389 // -----------------------------------------------------------------------
391 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
393 wxPG_PROP_ARG_CALL_PROLOG()
396 m_pState
->DoSetPropertyValueString(p
, value
);
399 // -----------------------------------------------------------------------
401 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
403 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
406 // -----------------------------------------------------------------------
408 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
410 wxPGProperty
* p
= GetPropertyByName(name
);
411 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
415 // ----------------------------------------------------------------------------
417 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
421 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
423 if ( it
.GetProperty()->GetLabel() == label
)
424 return it
.GetProperty();
427 return wxNullProperty
;
430 // ----------------------------------------------------------------------------
432 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
433 wxVariant
& value
, long argFlags
)
435 wxPG_PROP_ARG_CALL_PROLOG()
437 p
->SetAttribute( name
, value
);
439 if ( argFlags
& wxPG_RECURSE
)
442 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
443 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
447 // -----------------------------------------------------------------------
449 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
452 unsigned int pageIndex
= 0;
456 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
459 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
465 // -----------------------------------------------------------------------
467 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
468 wxPGProperty::FlagType flags
,
470 int iterFlags
) const
472 wxASSERT( targetArr
);
473 wxPGVIterator it
= GetVIterator( iterFlags
);
479 const wxPGProperty
* property
= it
.GetProperty();
483 if ( (property
->GetFlags() & flags
) == flags
)
484 targetArr
->push_back((wxPGProperty
*)property
);
488 if ( (property
->GetFlags() & flags
) != flags
)
489 targetArr
->push_back((wxPGProperty
*)property
);
494 // -----------------------------------------------------------------------
496 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
497 const wxString
& falseChoice
)
499 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
500 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
503 // -----------------------------------------------------------------------
505 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
507 return m_pState
->BaseGetPropertyByName(name
);
510 // -----------------------------------------------------------------------
512 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
513 const wxString
& subname
) const
515 wxPGProperty
* p
= DoGetPropertyByName(name
);
516 if ( !p
|| !p
->GetChildCount() )
517 return wxNullProperty
;
519 return p
->GetPropertyByName(subname
);
522 // -----------------------------------------------------------------------
524 // Since GetPropertyByName is used *a lot*, this makes sense
525 // since non-virtual method can be called with less code.
526 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
528 wxPGProperty
* p
= DoGetPropertyByName(name
);
532 // Check if its "Property.SubProperty" format
533 int pos
= name
.Find(wxT('.'));
537 return GetPropertyByName(name
.substr(0,pos
),
538 name
.substr(pos
+1,name
.length()-pos
-1));
541 // -----------------------------------------------------------------------
543 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
545 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
547 wxPropertyGrid
* pg
= m_pState
->GetGrid();
549 if ( pg
== p
->GetGrid() )
550 return pg
->DoHideProperty(p
, hide
, flags
);
552 m_pState
->DoHideProperty(p
, hide
, flags
);
557 // -----------------------------------------------------------------------
559 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
561 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
562 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
564 return pg
->DoCollapse(p
);
566 return p
->GetParentState()->DoCollapse(p
);
569 // -----------------------------------------------------------------------
571 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
573 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
574 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
576 return pg
->DoExpand(p
);
578 return p
->GetParentState()->DoExpand(p
);
581 // -----------------------------------------------------------------------
583 void wxPropertyGridInterface::Sort( int flags
)
585 wxPropertyGrid
* pg
= GetPropertyGrid();
587 pg
->DoClearSelection();
589 unsigned int pageIndex
= 0;
593 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
600 // -----------------------------------------------------------------------
602 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
604 wxPG_PROP_ARG_CALL_PROLOG()
606 p
->SetLabel( newproplabel
);
608 wxPropertyGridPageState
* state
= p
->GetParentState();
609 wxPropertyGrid
* pg
= state
->GetGrid();
611 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
612 pg
->SortChildren(p
->GetParent());
614 if ( pg
->GetState() == state
)
616 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
623 // -----------------------------------------------------------------------
625 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
627 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
629 wxPropertyGrid
* pg
= m_pState
->GetGrid();
631 p
->m_maxLen
= (short) maxLen
;
633 // Adjust control if selected currently
634 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
636 wxWindow
* wnd
= pg
->GetEditorControl();
637 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
639 tc
->SetMaxLength( maxLen
);
648 // -----------------------------------------------------------------------
651 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
652 const wxColour
& colour
,
655 wxPG_PROP_ARG_CALL_PROLOG()
656 p
->SetBackgroundColour( colour
, recursively
);
657 RefreshProperty( p
);
660 // -----------------------------------------------------------------------
662 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
663 const wxColour
& colour
,
666 wxPG_PROP_ARG_CALL_PROLOG()
667 p
->SetTextColour( colour
, recursively
);
668 RefreshProperty( p
);
671 // -----------------------------------------------------------------------
673 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
675 wxPG_PROP_ARG_CALL_PROLOG()
680 // -----------------------------------------------------------------------
682 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
684 const wxString
& text
,
685 const wxBitmap
& bitmap
,
686 const wxColour
& fgCol
,
687 const wxColour
& bgCol
)
689 wxPG_PROP_ARG_CALL_PROLOG()
691 wxPGCell
& cell
= p
->GetCell(column
);
692 if ( text
.length() && text
!= wxPG_LABEL
)
695 cell
.SetBitmap(bitmap
);
696 if ( fgCol
!= wxNullColour
)
697 cell
.SetFgCol(fgCol
);
698 if ( bgCol
!= wxNullColour
)
699 cell
.SetBgCol(bgCol
);
702 // -----------------------------------------------------------------------
703 // GetPropertyValueAsXXX methods
705 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
706 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
708 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
709 wxVariant value = p->GetValue(); \
710 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
712 wxPGGetFailed(p,wxPGTypeName_##T); \
713 return (TRET)DEFRETVAL; \
715 return (TRET)value.Get##BIGNAME(); \
718 // String is different than others.
719 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
721 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
722 return p
->GetValueAsString(wxPG_FULL_VALUE
);
725 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
727 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
728 wxVariant value
= p
->GetValue();
729 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
731 return value
.GetBool();
733 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
735 return value
.GetLong()?true:false;
737 wxPGGetFailed(p
,wxPGTypeName_bool
);
741 IMPLEMENT_GET_VALUE(long,long,Long
,0)
742 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
744 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
746 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
747 return p
->IsExpanded();
750 // -----------------------------------------------------------------------
751 // wxPropertyGridInterface wrappers
752 // -----------------------------------------------------------------------
754 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
756 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
759 // -----------------------------------------------------------------------
761 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
763 wxPG_PROP_ARG_CALL_PROLOG()
764 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
765 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
766 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
769 // -----------------------------------------------------------------------
771 bool wxPropertyGridInterface::EditorValidate()
773 return GetPropertyGrid()->DoEditorValidate();
776 // -----------------------------------------------------------------------
778 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
780 wxPG_PROP_ARG_CALL_PROLOG()
781 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
782 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
783 p
->SetFlag(wxPG_PROP_AGGREGATE
);
786 // -----------------------------------------------------------------------
787 // wxPGVIterator_State
788 // -----------------------------------------------------------------------
790 // Default returned by wxPropertyGridInterface::GetVIterator().
791 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
794 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
796 m_it
.Init( state
, flags
);
798 virtual ~wxPGVIteratorBase_State() { }
799 virtual void Next() { m_it
.Next(); }
802 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
804 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
807 // -----------------------------------------------------------------------
808 // wxPGEditableState related functions
809 // -----------------------------------------------------------------------
811 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
812 // in the input string. This is an internal functions which is
813 // used for saving states
814 // NB: Similar function exists in aui/framemanager.cpp
815 static wxString
EscapeDelimiters(const wxString
& s
)
818 result
.Alloc(s
.length());
819 const wxChar
* ch
= s
.c_str();
822 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
830 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
835 // Save state on page basis
836 unsigned int pageIndex
= 0;
837 wxArrayPtrVoid pageStates
;
841 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
844 pageStates
.Add(page
);
849 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
851 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
853 if ( includedStates
& SelectionState
)
856 if ( pageState
->GetSelection() )
857 sel
= pageState
->GetSelection()->GetName();
858 result
+= wxS("selection=");
859 result
+= EscapeDelimiters(sel
);
862 if ( includedStates
& ExpandedState
)
864 wxArrayPGProperty ptrs
;
865 wxPropertyGridConstIterator it
=
866 wxPropertyGridConstIterator( pageState
,
867 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
870 result
+= wxS("expanded=");
876 const wxPGProperty
* p
= it
.GetProperty();
878 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
879 result
+= EscapeDelimiters(p
->GetName());
884 if ( result
.Last() == wxS(',') )
889 if ( includedStates
& ScrollPosState
)
892 GetPropertyGrid()->GetViewStart(&x
,&y
);
893 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
895 if ( includedStates
& SplitterPosState
)
897 result
+= wxS("splitterpos=");
899 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
900 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
902 result
.RemoveLast(); // Remove last comma
905 if ( includedStates
& PageState
)
907 result
+= wxS("ispageselected=");
909 if ( GetPageState(-1) == pageState
)
914 if ( includedStates
& DescBoxState
)
916 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
918 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
920 result
.RemoveLast(); // Remove last semicolon
925 if ( result
.length() )
931 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
933 wxPropertyGrid
* pg
= GetPropertyGrid();
934 wxPGProperty
* newSelection
= NULL
;
938 long selectedPage
= -1;
939 bool pgSelectionSet
= false;
943 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
945 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
947 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
951 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
953 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
955 const wxString
& kvs
= kvpairStrings
[i
];
956 int eq_pos
= kvs
.Find(wxS('='));
957 if ( eq_pos
!= wxNOT_FOUND
)
959 wxString key
= kvs
.substr(0, eq_pos
);
960 wxString value
= kvs
.substr(eq_pos
+1);
962 // Further split value by commas
963 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
965 if ( key
== wxS("expanded") )
967 if ( restoreStates
& ExpandedState
)
969 wxPropertyGridIterator it
=
970 wxPropertyGridIterator( pageState
,
974 // First collapse all
975 for ( ; !it
.AtEnd(); it
.Next() )
977 wxPGProperty
* p
= it
.GetProperty();
978 pageState
->DoCollapse(p
);
981 // Then expand those which names are in values
982 for ( size_t n
=0; n
<values
.size(); n
++ )
984 const wxString
& name
= values
[n
];
985 wxPGProperty
* prop
= GetPropertyByName(name
);
987 pageState
->DoExpand(prop
);
991 else if ( key
== wxS("scrollpos") )
993 if ( restoreStates
& ScrollPosState
)
995 if ( values
.size() == 2 )
997 values
[0].ToLong(&vx
);
998 values
[1].ToLong(&vy
);
1006 else if ( key
== wxS("splitterpos") )
1008 if ( restoreStates
& SplitterPosState
)
1010 for ( size_t n
=1; n
<values
.size(); n
++ )
1013 values
[n
].ToLong(&pos
);
1015 pageState
->DoSetSplitterPosition(pos
, n
);
1019 else if ( key
== wxS("selection") )
1021 if ( restoreStates
& SelectionState
)
1023 if ( values
.size() > 0 )
1025 if ( pageState
->IsDisplayed() )
1027 if ( values
[0].length() )
1028 newSelection
= GetPropertyByName(value
);
1029 pgSelectionSet
= true;
1033 if ( values
[0].length() )
1034 pageState
->DoSetSelection(GetPropertyByName(value
));
1036 pageState
->DoClearSelection();
1041 else if ( key
== wxS("ispageselected") )
1043 if ( restoreStates
& PageState
)
1046 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1048 if ( pageSelStatus
)
1049 selectedPage
= pageIndex
;
1057 else if ( key
== wxS("descboxheight") )
1059 if ( restoreStates
& DescBoxState
)
1062 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1064 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1081 // Force recalculation of virtual heights of all pages
1082 // (may be needed on unclean source string).
1084 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1087 pageState
->VirtualHeightChanged();
1089 pageState
= GetPageState(pageIndex
);
1095 // Selection of visible grid page must be set after Thaw() call
1096 if ( pgSelectionSet
)
1099 pg
->DoSelectProperty(newSelection
);
1101 pg
->DoClearSelection();
1104 if ( selectedPage
!= -1 )
1106 DoSelectPage(selectedPage
);
1117 #endif // wxUSE_PROPGRID