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();
150 wxPropertyGrid
* grid
= state
->GetGrid();
152 if ( grid
->GetState() == state
)
153 grid
->DoSelectProperty(NULL
, wxPG_SEL_DELETING
|wxPG_SEL_NOVALIDATE
);
155 state
->DoDelete( p
, true );
160 // -----------------------------------------------------------------------
162 wxPGProperty
* wxPropertyGridInterface::RemoveProperty( wxPGPropArg id
)
164 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
166 wxCHECK( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
),
169 wxPropertyGridPageState
* state
= p
->GetParentState();
170 wxPropertyGrid
* grid
= state
->GetGrid();
172 if ( grid
->GetState() == state
)
174 grid
->DoSelectProperty(NULL
,
175 wxPG_SEL_DELETING
|wxPG_SEL_NOVALIDATE
);
178 state
->DoDelete( p
, false );
180 // Mark the property as 'unattached'
181 p
->m_parentState
= NULL
;
189 // -----------------------------------------------------------------------
191 wxPGProperty
* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
193 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
195 wxPGProperty
* replaced
= p
;
196 wxCHECK_MSG( replaced
&& property
,
198 wxT("NULL property") );
199 wxCHECK_MSG( !replaced
->IsCategory(),
201 wxT("cannot replace this type of property") );
202 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
204 wxT("cannot replace properties in alphabetic mode") );
206 // Get address to the slot
207 wxPGProperty
* parent
= replaced
->GetParent();
208 int ind
= replaced
->GetIndexInParent();
210 wxPropertyGridPageState
* state
= replaced
->GetParentState();
211 DeleteProperty(replaced
); // Must use generic Delete
212 state
->DoInsert(parent
,ind
,property
);
217 // -----------------------------------------------------------------------
218 // wxPropertyGridInterface property operations
219 // -----------------------------------------------------------------------
221 bool wxPropertyGridInterface::ClearSelection( bool validation
)
223 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
225 flags
|= wxPG_SEL_NOVALIDATE
;
227 wxPropertyGridPageState
* state
= m_pState
;
231 wxPropertyGrid
* pg
= state
->GetGrid();
232 if ( pg
->GetState() == state
)
233 return pg
->DoSelectProperty(NULL
, flags
);
235 state
->SetSelection(NULL
);
241 // -----------------------------------------------------------------------
243 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
245 wxPG_PROP_ARG_CALL_PROLOG()
247 m_pState
->DoLimitPropertyEditing(p
, limit
);
251 // -----------------------------------------------------------------------
253 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
255 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
257 wxPropertyGridPageState
* state
= p
->GetParentState();
258 wxPropertyGrid
* grid
= state
->GetGrid();
262 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
265 // If active, Set active Editor.
266 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
267 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
271 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
274 // If active, Disable as active Editor.
275 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
276 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
279 state
->DoEnableProperty(p
, enable
);
281 RefreshProperty( p
);
286 // -----------------------------------------------------------------------
288 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
290 wxPropertyGridPageState
* state
= m_pState
;
292 if ( !state
->DoGetRoot()->GetChildCount() )
295 wxPropertyGrid
* pg
= state
->GetGrid();
297 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
300 pg
->DoClearSelection();
305 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
307 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
308 if ( p
->GetChildCount() )
312 if ( !p
->IsExpanded() )
319 if ( p
->IsExpanded() )
321 state
->DoCollapse(p
);
327 pg
->RecalculateVirtualSize();
334 // -----------------------------------------------------------------------
336 void wxPropertyGridInterface::ClearModifiedStatus()
338 unsigned int pageIndex
= 0;
342 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
345 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
350 // Update active editor control, if any
351 GetPropertyGrid()->RefreshEditor();
354 // -----------------------------------------------------------------------
355 // wxPropertyGridInterface property value setting and getting
356 // -----------------------------------------------------------------------
358 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
360 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
363 // -----------------------------------------------------------------------
365 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
366 const wxString
& typestr
,
369 wxASSERT( p
!= NULL
);
370 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
371 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
374 // -----------------------------------------------------------------------
376 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
378 wxPG_PROP_ARG_CALL_PROLOG()
384 // -----------------------------------------------------------------------
386 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
388 wxPG_PROP_ARG_CALL_PROLOG()
391 m_pState
->DoSetPropertyValueString(p
, value
);
394 // -----------------------------------------------------------------------
396 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
398 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
401 // -----------------------------------------------------------------------
403 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
405 wxPGProperty
* p
= GetPropertyByName(name
);
406 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
410 // ----------------------------------------------------------------------------
412 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
416 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
418 if ( it
.GetProperty()->GetLabel() == label
)
419 return it
.GetProperty();
422 return wxNullProperty
;
425 // ----------------------------------------------------------------------------
427 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
428 wxVariant
& value
, long argFlags
)
430 wxPG_PROP_ARG_CALL_PROLOG()
432 p
->SetAttribute( name
, value
);
434 if ( argFlags
& wxPG_RECURSE
)
437 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
438 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
442 // -----------------------------------------------------------------------
444 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
447 unsigned int pageIndex
= 0;
451 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
454 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
460 // -----------------------------------------------------------------------
462 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
463 wxPGProperty::FlagType flags
,
465 int iterFlags
) const
467 wxASSERT( targetArr
);
468 wxPGVIterator it
= GetVIterator( iterFlags
);
474 const wxPGProperty
* property
= it
.GetProperty();
478 if ( (property
->GetFlags() & flags
) == flags
)
479 targetArr
->push_back((wxPGProperty
*)property
);
483 if ( (property
->GetFlags() & flags
) != flags
)
484 targetArr
->push_back((wxPGProperty
*)property
);
489 // -----------------------------------------------------------------------
491 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
492 const wxString
& falseChoice
)
494 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
495 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
498 // -----------------------------------------------------------------------
500 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
502 return m_pState
->BaseGetPropertyByName(name
);
505 // -----------------------------------------------------------------------
507 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
508 const wxString
& subname
) const
510 wxPGProperty
* p
= DoGetPropertyByName(name
);
511 if ( !p
|| !p
->GetChildCount() )
512 return wxNullProperty
;
514 return p
->GetPropertyByName(subname
);
517 // -----------------------------------------------------------------------
519 // Since GetPropertyByName is used *a lot*, this makes sense
520 // since non-virtual method can be called with less code.
521 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
523 wxPGProperty
* p
= DoGetPropertyByName(name
);
527 // Check if its "Property.SubProperty" format
528 int pos
= name
.Find(wxT('.'));
532 return GetPropertyByName(name
.substr(0,pos
),
533 name
.substr(pos
+1,name
.length()-pos
-1));
536 // -----------------------------------------------------------------------
538 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
540 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
542 wxPropertyGrid
* pg
= m_pState
->GetGrid();
544 if ( pg
== p
->GetGrid() )
545 return pg
->DoHideProperty(p
, hide
, flags
);
547 m_pState
->DoHideProperty(p
, hide
, flags
);
552 // -----------------------------------------------------------------------
554 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
556 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
557 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
559 return pg
->DoCollapse(p
);
561 return p
->GetParentState()->DoCollapse(p
);
564 // -----------------------------------------------------------------------
566 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
568 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
569 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
571 return pg
->DoExpand(p
);
573 return p
->GetParentState()->DoExpand(p
);
576 // -----------------------------------------------------------------------
578 void wxPropertyGridInterface::Sort( int flags
)
580 wxPropertyGrid
* pg
= GetPropertyGrid();
582 pg
->DoClearSelection();
584 unsigned int pageIndex
= 0;
588 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
595 // -----------------------------------------------------------------------
597 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
599 wxPG_PROP_ARG_CALL_PROLOG()
601 p
->SetLabel( newproplabel
);
603 wxPropertyGridPageState
* state
= p
->GetParentState();
604 wxPropertyGrid
* pg
= state
->GetGrid();
606 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
607 pg
->SortChildren(p
->GetParent());
609 if ( pg
->GetState() == state
)
611 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
618 // -----------------------------------------------------------------------
620 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
622 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
624 wxPropertyGrid
* pg
= m_pState
->GetGrid();
626 p
->m_maxLen
= (short) maxLen
;
628 // Adjust control if selected currently
629 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
631 wxWindow
* wnd
= pg
->GetEditorControl();
632 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
634 tc
->SetMaxLength( maxLen
);
643 // -----------------------------------------------------------------------
646 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
647 const wxColour
& colour
,
650 wxPG_PROP_ARG_CALL_PROLOG()
651 p
->SetBackgroundColour( colour
, recursively
);
652 RefreshProperty( p
);
655 // -----------------------------------------------------------------------
657 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
658 const wxColour
& colour
,
661 wxPG_PROP_ARG_CALL_PROLOG()
662 p
->SetTextColour( colour
, recursively
);
663 RefreshProperty( p
);
666 // -----------------------------------------------------------------------
668 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
670 wxPG_PROP_ARG_CALL_PROLOG()
675 // -----------------------------------------------------------------------
677 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
679 const wxString
& text
,
680 const wxBitmap
& bitmap
,
681 const wxColour
& fgCol
,
682 const wxColour
& bgCol
)
684 wxPG_PROP_ARG_CALL_PROLOG()
686 wxPGCell
& cell
= p
->GetCell(column
);
687 if ( text
.length() && text
!= wxPG_LABEL
)
690 cell
.SetBitmap(bitmap
);
691 if ( fgCol
!= wxNullColour
)
692 cell
.SetFgCol(fgCol
);
693 if ( bgCol
!= wxNullColour
)
694 cell
.SetBgCol(bgCol
);
697 // -----------------------------------------------------------------------
698 // GetPropertyValueAsXXX methods
700 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
701 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
703 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
704 wxVariant value = p->GetValue(); \
705 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
707 wxPGGetFailed(p,wxPGTypeName_##T); \
708 return (TRET)DEFRETVAL; \
710 return (TRET)value.Get##BIGNAME(); \
713 // String is different than others.
714 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
716 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
717 return p
->GetValueAsString(wxPG_FULL_VALUE
);
720 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
722 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
723 wxVariant value
= p
->GetValue();
724 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
726 return value
.GetBool();
728 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
730 return value
.GetLong()?true:false;
732 wxPGGetFailed(p
,wxPGTypeName_bool
);
736 IMPLEMENT_GET_VALUE(long,long,Long
,0)
737 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
739 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
741 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
742 return p
->IsExpanded();
745 // -----------------------------------------------------------------------
746 // wxPropertyGridInterface wrappers
747 // -----------------------------------------------------------------------
749 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
751 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
754 // -----------------------------------------------------------------------
756 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
758 wxPG_PROP_ARG_CALL_PROLOG()
759 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
760 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
761 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
764 // -----------------------------------------------------------------------
766 bool wxPropertyGridInterface::EditorValidate()
768 return GetPropertyGrid()->DoEditorValidate();
771 // -----------------------------------------------------------------------
773 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
775 wxPG_PROP_ARG_CALL_PROLOG()
776 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
777 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
778 p
->SetFlag(wxPG_PROP_AGGREGATE
);
781 // -----------------------------------------------------------------------
782 // wxPGVIterator_State
783 // -----------------------------------------------------------------------
785 // Default returned by wxPropertyGridInterface::GetVIterator().
786 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
789 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
791 m_it
.Init( state
, flags
);
793 virtual ~wxPGVIteratorBase_State() { }
794 virtual void Next() { m_it
.Next(); }
797 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
799 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
802 // -----------------------------------------------------------------------
803 // wxPGEditableState related functions
804 // -----------------------------------------------------------------------
806 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
807 // in the input string. This is an internal functions which is
808 // used for saving states
809 // NB: Similar function exists in aui/framemanager.cpp
810 static wxString
EscapeDelimiters(const wxString
& s
)
813 result
.Alloc(s
.length());
814 const wxChar
* ch
= s
.c_str();
817 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
825 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
830 // Save state on page basis
831 unsigned int pageIndex
= 0;
832 wxArrayPtrVoid pageStates
;
836 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
839 pageStates
.Add(page
);
844 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
846 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
848 if ( includedStates
& SelectionState
)
851 if ( pageState
->GetSelection() )
852 sel
= pageState
->GetSelection()->GetName();
853 result
+= wxS("selection=");
854 result
+= EscapeDelimiters(sel
);
857 if ( includedStates
& ExpandedState
)
859 wxArrayPGProperty ptrs
;
860 wxPropertyGridConstIterator it
=
861 wxPropertyGridConstIterator( pageState
,
862 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
865 result
+= wxS("expanded=");
871 const wxPGProperty
* p
= it
.GetProperty();
873 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
874 result
+= EscapeDelimiters(p
->GetName());
879 if ( result
.Last() == wxS(',') )
884 if ( includedStates
& ScrollPosState
)
887 GetPropertyGrid()->GetViewStart(&x
,&y
);
888 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
890 if ( includedStates
& SplitterPosState
)
892 result
+= wxS("splitterpos=");
894 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
895 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
897 result
.RemoveLast(); // Remove last comma
900 if ( includedStates
& PageState
)
902 result
+= wxS("ispageselected=");
904 if ( GetPageState(-1) == pageState
)
909 if ( includedStates
& DescBoxState
)
911 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
913 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
915 result
.RemoveLast(); // Remove last semicolon
920 if ( result
.length() )
926 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
928 wxPropertyGrid
* pg
= GetPropertyGrid();
929 wxPGProperty
* newSelection
= NULL
;
933 long selectedPage
= -1;
934 bool pgSelectionSet
= false;
938 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
940 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
942 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
946 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
948 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
950 const wxString
& kvs
= kvpairStrings
[i
];
951 int eq_pos
= kvs
.Find(wxS('='));
952 if ( eq_pos
!= wxNOT_FOUND
)
954 wxString key
= kvs
.substr(0, eq_pos
);
955 wxString value
= kvs
.substr(eq_pos
+1);
957 // Further split value by commas
958 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
960 if ( key
== wxS("expanded") )
962 if ( restoreStates
& ExpandedState
)
964 wxPropertyGridIterator it
=
965 wxPropertyGridIterator( pageState
,
969 // First collapse all
970 for ( ; !it
.AtEnd(); it
.Next() )
972 wxPGProperty
* p
= it
.GetProperty();
973 pageState
->DoCollapse(p
);
976 // Then expand those which names are in values
977 for ( size_t n
=0; n
<values
.size(); n
++ )
979 const wxString
& name
= values
[n
];
980 wxPGProperty
* prop
= GetPropertyByName(name
);
982 pageState
->DoExpand(prop
);
986 else if ( key
== wxS("scrollpos") )
988 if ( restoreStates
& ScrollPosState
)
990 if ( values
.size() == 2 )
992 values
[0].ToLong(&vx
);
993 values
[1].ToLong(&vy
);
1001 else if ( key
== wxS("splitterpos") )
1003 if ( restoreStates
& SplitterPosState
)
1005 for ( size_t n
=1; n
<values
.size(); n
++ )
1008 values
[n
].ToLong(&pos
);
1010 pageState
->DoSetSplitterPosition(pos
, n
);
1014 else if ( key
== wxS("selection") )
1016 if ( restoreStates
& SelectionState
)
1018 if ( values
.size() > 0 )
1020 if ( pageState
->IsDisplayed() )
1022 if ( values
[0].length() )
1023 newSelection
= GetPropertyByName(value
);
1024 pgSelectionSet
= true;
1028 if ( values
[0].length() )
1029 pageState
->SetSelection(GetPropertyByName(value
));
1031 pageState
->DoClearSelection();
1036 else if ( key
== wxS("ispageselected") )
1038 if ( restoreStates
& PageState
)
1041 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1043 if ( pageSelStatus
)
1044 selectedPage
= pageIndex
;
1052 else if ( key
== wxS("descboxheight") )
1054 if ( restoreStates
& DescBoxState
)
1057 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1059 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1076 // Force recalculation of virtual heights of all pages
1077 // (may be needed on unclean source string).
1079 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1082 pageState
->VirtualHeightChanged();
1084 pageState
= GetPageState(pageIndex
);
1090 // Selection of visible grid page must be set after Thaw() call
1091 if ( pgSelectionSet
)
1094 pg
->DoSelectProperty(newSelection
);
1096 pg
->DoClearSelection();
1099 if ( selectedPage
!= -1 )
1101 DoSelectPage(selectedPage
);
1112 #endif // wxUSE_PROPGRID