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 wxPropertyGrid
* pg
= GetPropertyGrid();
226 // -----------------------------------------------------------------------
228 bool wxPropertyGridInterface::DoClearSelection( bool validation
,
232 selFlags
|= wxPG_SEL_NOVALIDATE
;
234 wxPropertyGridPageState
* state
= m_pState
;
238 wxPropertyGrid
* pg
= state
->GetGrid();
239 if ( pg
->GetState() == state
)
240 return pg
->DoSelectProperty(NULL
, selFlags
);
242 state
->DoSetSelection(NULL
);
248 // -----------------------------------------------------------------------
250 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
252 wxPG_PROP_ARG_CALL_PROLOG()
254 m_pState
->DoLimitPropertyEditing(p
, limit
);
258 // -----------------------------------------------------------------------
260 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
262 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
264 wxPropertyGridPageState
* state
= p
->GetParentState();
265 wxPropertyGrid
* grid
= state
->GetGrid();
269 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
272 // If active, Set active Editor.
273 if ( grid
&& grid
->GetState() == state
&& p
== grid
->GetSelection() )
274 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
278 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
281 // If active, Disable as active Editor.
282 if ( grid
&& grid
->GetState() == state
&& p
== grid
->GetSelection() )
283 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
286 state
->DoEnableProperty(p
, enable
);
288 RefreshProperty( p
);
293 // -----------------------------------------------------------------------
295 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
297 wxPropertyGridPageState
* state
= m_pState
;
299 if ( !state
->DoGetRoot()->GetChildCount() )
302 wxPropertyGrid
* pg
= state
->GetGrid();
304 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
307 pg
->DoClearSelection();
312 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
314 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
315 if ( p
->GetChildCount() )
319 if ( !p
->IsExpanded() )
326 if ( p
->IsExpanded() )
328 state
->DoCollapse(p
);
334 pg
->RecalculateVirtualSize();
341 // -----------------------------------------------------------------------
343 void wxPropertyGridInterface::ClearModifiedStatus()
345 unsigned int pageIndex
= 0;
349 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
352 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
353 page
->m_anyModified
= false;
358 // Update active editor control, if any
359 GetPropertyGrid()->RefreshEditor();
362 // -----------------------------------------------------------------------
363 // wxPropertyGridInterface property value setting and getting
364 // -----------------------------------------------------------------------
366 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
368 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
371 // -----------------------------------------------------------------------
373 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
374 const wxString
& typestr
,
377 wxASSERT( p
!= NULL
);
378 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
379 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
382 // -----------------------------------------------------------------------
384 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
386 wxPG_PROP_ARG_CALL_PROLOG()
392 // -----------------------------------------------------------------------
394 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
396 wxPG_PROP_ARG_CALL_PROLOG()
399 m_pState
->DoSetPropertyValueString(p
, value
);
402 // -----------------------------------------------------------------------
404 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
406 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
409 // -----------------------------------------------------------------------
411 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
413 wxPGProperty
* p
= GetPropertyByName(name
);
414 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
418 // ----------------------------------------------------------------------------
420 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
424 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
426 if ( it
.GetProperty()->GetLabel() == label
)
427 return it
.GetProperty();
430 return wxNullProperty
;
433 // ----------------------------------------------------------------------------
435 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
436 wxVariant
& value
, long argFlags
)
438 wxPG_PROP_ARG_CALL_PROLOG()
440 p
->SetAttribute( name
, value
);
442 if ( argFlags
& wxPG_RECURSE
)
445 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
446 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
450 // -----------------------------------------------------------------------
452 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
455 unsigned int pageIndex
= 0;
459 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
462 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
468 // -----------------------------------------------------------------------
470 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
471 wxPGProperty::FlagType flags
,
473 int iterFlags
) const
475 wxASSERT( targetArr
);
476 wxPGVIterator it
= GetVIterator( iterFlags
);
482 const wxPGProperty
* property
= it
.GetProperty();
486 if ( (property
->GetFlags() & flags
) == flags
)
487 targetArr
->push_back((wxPGProperty
*)property
);
491 if ( (property
->GetFlags() & flags
) != flags
)
492 targetArr
->push_back((wxPGProperty
*)property
);
497 // -----------------------------------------------------------------------
499 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
500 const wxString
& falseChoice
)
502 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
503 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
506 // -----------------------------------------------------------------------
508 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
510 return m_pState
->BaseGetPropertyByName(name
);
513 // -----------------------------------------------------------------------
515 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
516 const wxString
& subname
) const
518 wxPGProperty
* p
= DoGetPropertyByName(name
);
519 if ( !p
|| !p
->GetChildCount() )
520 return wxNullProperty
;
522 return p
->GetPropertyByName(subname
);
525 // -----------------------------------------------------------------------
527 // Since GetPropertyByName is used *a lot*, this makes sense
528 // since non-virtual method can be called with less code.
529 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
531 wxPGProperty
* p
= DoGetPropertyByName(name
);
535 // Check if its "Property.SubProperty" format
536 int pos
= name
.Find(wxT('.'));
540 return GetPropertyByName(name
.substr(0,pos
),
541 name
.substr(pos
+1,name
.length()-pos
-1));
544 // -----------------------------------------------------------------------
546 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
548 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
550 wxPropertyGrid
* pg
= m_pState
->GetGrid();
552 if ( pg
== p
->GetGrid() )
553 return pg
->DoHideProperty(p
, hide
, flags
);
555 m_pState
->DoHideProperty(p
, hide
, flags
);
560 // -----------------------------------------------------------------------
562 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
564 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
565 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
567 return pg
->DoCollapse(p
);
569 return p
->GetParentState()->DoCollapse(p
);
572 // -----------------------------------------------------------------------
574 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
576 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
577 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
579 return pg
->DoExpand(p
);
581 return p
->GetParentState()->DoExpand(p
);
584 // -----------------------------------------------------------------------
586 void wxPropertyGridInterface::Sort( int flags
)
588 wxPropertyGrid
* pg
= GetPropertyGrid();
590 unsigned int pageIndex
= 0;
594 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
600 // Fix positions of any open editor controls
602 pg
->CorrectEditorWidgetPosY();
605 // -----------------------------------------------------------------------
607 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
609 wxPG_PROP_ARG_CALL_PROLOG()
611 p
->SetLabel( newproplabel
);
613 wxPropertyGridPageState
* state
= p
->GetParentState();
614 wxPropertyGrid
* pg
= state
->GetGrid();
616 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
617 pg
->SortChildren(p
->GetParent());
619 if ( pg
->GetState() == state
)
621 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
628 // -----------------------------------------------------------------------
630 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
632 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
634 wxPropertyGrid
* pg
= m_pState
->GetGrid();
636 p
->m_maxLen
= (short) maxLen
;
638 // Adjust control if selected currently
639 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
641 wxWindow
* wnd
= pg
->GetEditorControl();
642 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
644 tc
->SetMaxLength( maxLen
);
653 // -----------------------------------------------------------------------
656 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
657 const wxColour
& colour
,
660 wxPG_PROP_ARG_CALL_PROLOG()
661 p
->SetBackgroundColour(colour
, flags
);
665 // -----------------------------------------------------------------------
667 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
668 const wxColour
& colour
,
671 wxPG_PROP_ARG_CALL_PROLOG()
672 p
->SetTextColour(colour
, flags
);
676 // -----------------------------------------------------------------------
678 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
680 wxPG_PROP_ARG_CALL_PROLOG()
685 // -----------------------------------------------------------------------
687 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
689 const wxString
& text
,
690 const wxBitmap
& bitmap
,
691 const wxColour
& fgCol
,
692 const wxColour
& bgCol
)
694 wxPG_PROP_ARG_CALL_PROLOG()
696 wxPGCell
& cell
= p
->GetCell(column
);
697 if ( text
.length() && text
!= wxPG_LABEL
)
700 cell
.SetBitmap(bitmap
);
701 if ( fgCol
!= wxNullColour
)
702 cell
.SetFgCol(fgCol
);
703 if ( bgCol
!= wxNullColour
)
704 cell
.SetBgCol(bgCol
);
707 // -----------------------------------------------------------------------
708 // GetPropertyValueAsXXX methods
710 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
711 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
713 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
714 wxVariant value = p->GetValue(); \
715 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
717 wxPGGetFailed(p,wxPGTypeName_##T); \
718 return (TRET)DEFRETVAL; \
720 return (TRET)value.Get##BIGNAME(); \
723 // String is different than others.
724 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
726 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
727 return p
->GetValueAsString(wxPG_FULL_VALUE
);
730 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
732 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
733 wxVariant value
= p
->GetValue();
734 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
736 return value
.GetBool();
738 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
740 return value
.GetLong()?true:false;
742 wxPGGetFailed(p
,wxPGTypeName_bool
);
746 IMPLEMENT_GET_VALUE(long,long,Long
,0)
747 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
749 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
751 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
752 return p
->IsExpanded();
755 // -----------------------------------------------------------------------
756 // wxPropertyGridInterface wrappers
757 // -----------------------------------------------------------------------
759 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
761 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
764 // -----------------------------------------------------------------------
766 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
768 wxPG_PROP_ARG_CALL_PROLOG()
769 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
770 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
771 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
774 // -----------------------------------------------------------------------
776 bool wxPropertyGridInterface::EditorValidate()
778 return GetPropertyGrid()->DoEditorValidate();
781 // -----------------------------------------------------------------------
783 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
785 wxPG_PROP_ARG_CALL_PROLOG()
786 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
787 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
788 p
->SetFlag(wxPG_PROP_AGGREGATE
);
791 // -----------------------------------------------------------------------
792 // wxPGVIterator_State
793 // -----------------------------------------------------------------------
795 // Default returned by wxPropertyGridInterface::GetVIterator().
796 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
799 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
801 m_it
.Init( state
, flags
);
803 virtual ~wxPGVIteratorBase_State() { }
804 virtual void Next() { m_it
.Next(); }
807 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
809 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
812 // -----------------------------------------------------------------------
813 // wxPGEditableState related functions
814 // -----------------------------------------------------------------------
816 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
817 // in the input string. This is an internal functions which is
818 // used for saving states
819 // NB: Similar function exists in aui/framemanager.cpp
820 static wxString
EscapeDelimiters(const wxString
& s
)
823 result
.Alloc(s
.length());
824 const wxChar
* ch
= s
.c_str();
827 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
835 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
840 // Save state on page basis
841 unsigned int pageIndex
= 0;
842 wxArrayPtrVoid pageStates
;
846 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
849 pageStates
.Add(page
);
854 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
856 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
858 if ( includedStates
& SelectionState
)
861 if ( pageState
->GetSelection() )
862 sel
= pageState
->GetSelection()->GetName();
863 result
+= wxS("selection=");
864 result
+= EscapeDelimiters(sel
);
867 if ( includedStates
& ExpandedState
)
869 wxArrayPGProperty ptrs
;
870 wxPropertyGridConstIterator it
=
871 wxPropertyGridConstIterator( pageState
,
872 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
875 result
+= wxS("expanded=");
881 const wxPGProperty
* p
= it
.GetProperty();
883 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
884 result
+= EscapeDelimiters(p
->GetName());
889 if ( result
.Last() == wxS(',') )
894 if ( includedStates
& ScrollPosState
)
897 GetPropertyGrid()->GetViewStart(&x
,&y
);
898 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
900 if ( includedStates
& SplitterPosState
)
902 result
+= wxS("splitterpos=");
904 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
905 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
907 result
.RemoveLast(); // Remove last comma
910 if ( includedStates
& PageState
)
912 result
+= wxS("ispageselected=");
914 if ( GetPageState(-1) == pageState
)
919 if ( includedStates
& DescBoxState
)
921 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
923 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
925 result
.RemoveLast(); // Remove last semicolon
930 if ( result
.length() )
936 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
938 wxPropertyGrid
* pg
= GetPropertyGrid();
939 wxPGProperty
* newSelection
= NULL
;
943 long selectedPage
= -1;
944 bool pgSelectionSet
= false;
948 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
950 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
952 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
956 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
958 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
960 const wxString
& kvs
= kvpairStrings
[i
];
961 int eq_pos
= kvs
.Find(wxS('='));
962 if ( eq_pos
!= wxNOT_FOUND
)
964 wxString key
= kvs
.substr(0, eq_pos
);
965 wxString value
= kvs
.substr(eq_pos
+1);
967 // Further split value by commas
968 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
970 if ( key
== wxS("expanded") )
972 if ( restoreStates
& ExpandedState
)
974 wxPropertyGridIterator it
=
975 wxPropertyGridIterator( pageState
,
979 // First collapse all
980 for ( ; !it
.AtEnd(); it
.Next() )
982 wxPGProperty
* p
= it
.GetProperty();
983 pageState
->DoCollapse(p
);
986 // Then expand those which names are in values
987 for ( size_t n
=0; n
<values
.size(); n
++ )
989 const wxString
& name
= values
[n
];
990 wxPGProperty
* prop
= GetPropertyByName(name
);
992 pageState
->DoExpand(prop
);
996 else if ( key
== wxS("scrollpos") )
998 if ( restoreStates
& ScrollPosState
)
1000 if ( values
.size() == 2 )
1002 values
[0].ToLong(&vx
);
1003 values
[1].ToLong(&vy
);
1011 else if ( key
== wxS("splitterpos") )
1013 if ( restoreStates
& SplitterPosState
)
1015 for ( size_t n
=1; n
<values
.size(); n
++ )
1018 values
[n
].ToLong(&pos
);
1020 pageState
->DoSetSplitterPosition(pos
, n
);
1024 else if ( key
== wxS("selection") )
1026 if ( restoreStates
& SelectionState
)
1028 if ( values
.size() > 0 )
1030 if ( pageState
->IsDisplayed() )
1032 if ( values
[0].length() )
1033 newSelection
= GetPropertyByName(value
);
1034 pgSelectionSet
= true;
1038 if ( values
[0].length() )
1039 pageState
->DoSetSelection(GetPropertyByName(value
));
1041 pageState
->DoClearSelection();
1046 else if ( key
== wxS("ispageselected") )
1048 if ( restoreStates
& PageState
)
1051 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1053 if ( pageSelStatus
)
1054 selectedPage
= pageIndex
;
1062 else if ( key
== wxS("descboxheight") )
1064 if ( restoreStates
& DescBoxState
)
1067 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1069 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1086 // Force recalculation of virtual heights of all pages
1087 // (may be needed on unclean source string).
1089 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1092 pageState
->VirtualHeightChanged();
1094 pageState
= GetPageState(pageIndex
);
1100 // Selection of visible grid page must be set after Thaw() call
1101 if ( pgSelectionSet
)
1104 pg
->DoSelectProperty(newSelection
);
1106 pg
->DoClearSelection();
1109 if ( selectedPage
!= -1 )
1111 DoSelectPage(selectedPage
);
1122 #endif // wxUSE_PROPGRID