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 return DoClearSelection(validation
, wxPG_SEL_DONT_SEND_EVENT
);
222 // -----------------------------------------------------------------------
224 bool wxPropertyGridInterface::DoClearSelection( bool validation
,
228 selFlags
|= wxPG_SEL_NOVALIDATE
;
230 wxPropertyGridPageState
* state
= m_pState
;
234 wxPropertyGrid
* pg
= state
->GetGrid();
235 if ( pg
->GetState() == state
)
236 return pg
->DoSelectProperty(NULL
, selFlags
);
238 state
->DoSetSelection(NULL
);
244 // -----------------------------------------------------------------------
246 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
248 wxPG_PROP_ARG_CALL_PROLOG()
250 m_pState
->DoLimitPropertyEditing(p
, limit
);
254 // -----------------------------------------------------------------------
256 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
258 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
260 wxPropertyGridPageState
* state
= p
->GetParentState();
261 wxPropertyGrid
* grid
= state
->GetGrid();
265 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
268 // If active, Set active Editor.
269 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
270 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
274 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
277 // If active, Disable as active Editor.
278 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
279 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
282 state
->DoEnableProperty(p
, enable
);
284 RefreshProperty( p
);
289 // -----------------------------------------------------------------------
291 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
293 wxPropertyGridPageState
* state
= m_pState
;
295 if ( !state
->DoGetRoot()->GetChildCount() )
298 wxPropertyGrid
* pg
= state
->GetGrid();
300 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
303 pg
->DoClearSelection();
308 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
310 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
311 if ( p
->GetChildCount() )
315 if ( !p
->IsExpanded() )
322 if ( p
->IsExpanded() )
324 state
->DoCollapse(p
);
330 pg
->RecalculateVirtualSize();
337 // -----------------------------------------------------------------------
339 void wxPropertyGridInterface::ClearModifiedStatus()
341 unsigned int pageIndex
= 0;
345 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
348 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
353 // Update active editor control, if any
354 GetPropertyGrid()->RefreshEditor();
357 // -----------------------------------------------------------------------
358 // wxPropertyGridInterface property value setting and getting
359 // -----------------------------------------------------------------------
361 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
363 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
366 // -----------------------------------------------------------------------
368 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
369 const wxString
& typestr
,
372 wxASSERT( p
!= NULL
);
373 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
374 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
377 // -----------------------------------------------------------------------
379 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
381 wxPG_PROP_ARG_CALL_PROLOG()
387 // -----------------------------------------------------------------------
389 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
391 wxPG_PROP_ARG_CALL_PROLOG()
394 m_pState
->DoSetPropertyValueString(p
, value
);
397 // -----------------------------------------------------------------------
399 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
401 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
404 // -----------------------------------------------------------------------
406 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
408 wxPGProperty
* p
= GetPropertyByName(name
);
409 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
413 // ----------------------------------------------------------------------------
415 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
419 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
421 if ( it
.GetProperty()->GetLabel() == label
)
422 return it
.GetProperty();
425 return wxNullProperty
;
428 // ----------------------------------------------------------------------------
430 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
431 wxVariant
& value
, long argFlags
)
433 wxPG_PROP_ARG_CALL_PROLOG()
435 p
->SetAttribute( name
, value
);
437 if ( argFlags
& wxPG_RECURSE
)
440 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
441 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
445 // -----------------------------------------------------------------------
447 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
450 unsigned int pageIndex
= 0;
454 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
457 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
463 // -----------------------------------------------------------------------
465 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
466 wxPGProperty::FlagType flags
,
468 int iterFlags
) const
470 wxASSERT( targetArr
);
471 wxPGVIterator it
= GetVIterator( iterFlags
);
477 const wxPGProperty
* property
= it
.GetProperty();
481 if ( (property
->GetFlags() & flags
) == flags
)
482 targetArr
->push_back((wxPGProperty
*)property
);
486 if ( (property
->GetFlags() & flags
) != flags
)
487 targetArr
->push_back((wxPGProperty
*)property
);
492 // -----------------------------------------------------------------------
494 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
495 const wxString
& falseChoice
)
497 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
498 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
501 // -----------------------------------------------------------------------
503 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
505 return m_pState
->BaseGetPropertyByName(name
);
508 // -----------------------------------------------------------------------
510 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
511 const wxString
& subname
) const
513 wxPGProperty
* p
= DoGetPropertyByName(name
);
514 if ( !p
|| !p
->GetChildCount() )
515 return wxNullProperty
;
517 return p
->GetPropertyByName(subname
);
520 // -----------------------------------------------------------------------
522 // Since GetPropertyByName is used *a lot*, this makes sense
523 // since non-virtual method can be called with less code.
524 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
526 wxPGProperty
* p
= DoGetPropertyByName(name
);
530 // Check if its "Property.SubProperty" format
531 int pos
= name
.Find(wxT('.'));
535 return GetPropertyByName(name
.substr(0,pos
),
536 name
.substr(pos
+1,name
.length()-pos
-1));
539 // -----------------------------------------------------------------------
541 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
543 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
545 wxPropertyGrid
* pg
= m_pState
->GetGrid();
547 if ( pg
== p
->GetGrid() )
548 return pg
->DoHideProperty(p
, hide
, flags
);
550 m_pState
->DoHideProperty(p
, hide
, flags
);
555 // -----------------------------------------------------------------------
557 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
559 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
560 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
562 return pg
->DoCollapse(p
);
564 return p
->GetParentState()->DoCollapse(p
);
567 // -----------------------------------------------------------------------
569 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
571 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
572 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
574 return pg
->DoExpand(p
);
576 return p
->GetParentState()->DoExpand(p
);
579 // -----------------------------------------------------------------------
581 void wxPropertyGridInterface::Sort( int flags
)
583 wxPropertyGrid
* pg
= GetPropertyGrid();
585 pg
->DoClearSelection();
587 unsigned int pageIndex
= 0;
591 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
598 // -----------------------------------------------------------------------
600 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
602 wxPG_PROP_ARG_CALL_PROLOG()
604 p
->SetLabel( newproplabel
);
606 wxPropertyGridPageState
* state
= p
->GetParentState();
607 wxPropertyGrid
* pg
= state
->GetGrid();
609 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
610 pg
->SortChildren(p
->GetParent());
612 if ( pg
->GetState() == state
)
614 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
621 // -----------------------------------------------------------------------
623 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
625 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
627 wxPropertyGrid
* pg
= m_pState
->GetGrid();
629 p
->m_maxLen
= (short) maxLen
;
631 // Adjust control if selected currently
632 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
634 wxWindow
* wnd
= pg
->GetEditorControl();
635 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
637 tc
->SetMaxLength( maxLen
);
646 // -----------------------------------------------------------------------
649 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
650 const wxColour
& colour
,
653 wxPG_PROP_ARG_CALL_PROLOG()
654 p
->SetBackgroundColour( colour
, recursively
);
655 RefreshProperty( p
);
658 // -----------------------------------------------------------------------
660 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
661 const wxColour
& colour
,
664 wxPG_PROP_ARG_CALL_PROLOG()
665 p
->SetTextColour( colour
, recursively
);
666 RefreshProperty( p
);
669 // -----------------------------------------------------------------------
671 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
673 wxPG_PROP_ARG_CALL_PROLOG()
678 // -----------------------------------------------------------------------
680 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
682 const wxString
& text
,
683 const wxBitmap
& bitmap
,
684 const wxColour
& fgCol
,
685 const wxColour
& bgCol
)
687 wxPG_PROP_ARG_CALL_PROLOG()
689 wxPGCell
& cell
= p
->GetCell(column
);
690 if ( text
.length() && text
!= wxPG_LABEL
)
693 cell
.SetBitmap(bitmap
);
694 if ( fgCol
!= wxNullColour
)
695 cell
.SetFgCol(fgCol
);
696 if ( bgCol
!= wxNullColour
)
697 cell
.SetBgCol(bgCol
);
700 // -----------------------------------------------------------------------
701 // GetPropertyValueAsXXX methods
703 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
704 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
706 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
707 wxVariant value = p->GetValue(); \
708 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
710 wxPGGetFailed(p,wxPGTypeName_##T); \
711 return (TRET)DEFRETVAL; \
713 return (TRET)value.Get##BIGNAME(); \
716 // String is different than others.
717 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
719 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
720 return p
->GetValueAsString(wxPG_FULL_VALUE
);
723 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
725 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
726 wxVariant value
= p
->GetValue();
727 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
729 return value
.GetBool();
731 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
733 return value
.GetLong()?true:false;
735 wxPGGetFailed(p
,wxPGTypeName_bool
);
739 IMPLEMENT_GET_VALUE(long,long,Long
,0)
740 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
742 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
744 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
745 return p
->IsExpanded();
748 // -----------------------------------------------------------------------
749 // wxPropertyGridInterface wrappers
750 // -----------------------------------------------------------------------
752 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
754 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
757 // -----------------------------------------------------------------------
759 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
761 wxPG_PROP_ARG_CALL_PROLOG()
762 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
763 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
764 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
767 // -----------------------------------------------------------------------
769 bool wxPropertyGridInterface::EditorValidate()
771 return GetPropertyGrid()->DoEditorValidate();
774 // -----------------------------------------------------------------------
776 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
778 wxPG_PROP_ARG_CALL_PROLOG()
779 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
780 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
781 p
->SetFlag(wxPG_PROP_AGGREGATE
);
784 // -----------------------------------------------------------------------
785 // wxPGVIterator_State
786 // -----------------------------------------------------------------------
788 // Default returned by wxPropertyGridInterface::GetVIterator().
789 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
792 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
794 m_it
.Init( state
, flags
);
796 virtual ~wxPGVIteratorBase_State() { }
797 virtual void Next() { m_it
.Next(); }
800 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
802 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
805 // -----------------------------------------------------------------------
806 // wxPGEditableState related functions
807 // -----------------------------------------------------------------------
809 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
810 // in the input string. This is an internal functions which is
811 // used for saving states
812 // NB: Similar function exists in aui/framemanager.cpp
813 static wxString
EscapeDelimiters(const wxString
& s
)
816 result
.Alloc(s
.length());
817 const wxChar
* ch
= s
.c_str();
820 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
828 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
833 // Save state on page basis
834 unsigned int pageIndex
= 0;
835 wxArrayPtrVoid pageStates
;
839 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
842 pageStates
.Add(page
);
847 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
849 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
851 if ( includedStates
& SelectionState
)
854 if ( pageState
->GetSelection() )
855 sel
= pageState
->GetSelection()->GetName();
856 result
+= wxS("selection=");
857 result
+= EscapeDelimiters(sel
);
860 if ( includedStates
& ExpandedState
)
862 wxArrayPGProperty ptrs
;
863 wxPropertyGridConstIterator it
=
864 wxPropertyGridConstIterator( pageState
,
865 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
868 result
+= wxS("expanded=");
874 const wxPGProperty
* p
= it
.GetProperty();
876 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
877 result
+= EscapeDelimiters(p
->GetName());
882 if ( result
.Last() == wxS(',') )
887 if ( includedStates
& ScrollPosState
)
890 GetPropertyGrid()->GetViewStart(&x
,&y
);
891 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
893 if ( includedStates
& SplitterPosState
)
895 result
+= wxS("splitterpos=");
897 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
898 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
900 result
.RemoveLast(); // Remove last comma
903 if ( includedStates
& PageState
)
905 result
+= wxS("ispageselected=");
907 if ( GetPageState(-1) == pageState
)
912 if ( includedStates
& DescBoxState
)
914 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
916 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
918 result
.RemoveLast(); // Remove last semicolon
923 if ( result
.length() )
929 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
931 wxPropertyGrid
* pg
= GetPropertyGrid();
932 wxPGProperty
* newSelection
= NULL
;
936 long selectedPage
= -1;
937 bool pgSelectionSet
= false;
941 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
943 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
945 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
949 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
951 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
953 const wxString
& kvs
= kvpairStrings
[i
];
954 int eq_pos
= kvs
.Find(wxS('='));
955 if ( eq_pos
!= wxNOT_FOUND
)
957 wxString key
= kvs
.substr(0, eq_pos
);
958 wxString value
= kvs
.substr(eq_pos
+1);
960 // Further split value by commas
961 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
963 if ( key
== wxS("expanded") )
965 if ( restoreStates
& ExpandedState
)
967 wxPropertyGridIterator it
=
968 wxPropertyGridIterator( pageState
,
972 // First collapse all
973 for ( ; !it
.AtEnd(); it
.Next() )
975 wxPGProperty
* p
= it
.GetProperty();
976 pageState
->DoCollapse(p
);
979 // Then expand those which names are in values
980 for ( size_t n
=0; n
<values
.size(); n
++ )
982 const wxString
& name
= values
[n
];
983 wxPGProperty
* prop
= GetPropertyByName(name
);
985 pageState
->DoExpand(prop
);
989 else if ( key
== wxS("scrollpos") )
991 if ( restoreStates
& ScrollPosState
)
993 if ( values
.size() == 2 )
995 values
[0].ToLong(&vx
);
996 values
[1].ToLong(&vy
);
1004 else if ( key
== wxS("splitterpos") )
1006 if ( restoreStates
& SplitterPosState
)
1008 for ( size_t n
=1; n
<values
.size(); n
++ )
1011 values
[n
].ToLong(&pos
);
1013 pageState
->DoSetSplitterPosition(pos
, n
);
1017 else if ( key
== wxS("selection") )
1019 if ( restoreStates
& SelectionState
)
1021 if ( values
.size() > 0 )
1023 if ( pageState
->IsDisplayed() )
1025 if ( values
[0].length() )
1026 newSelection
= GetPropertyByName(value
);
1027 pgSelectionSet
= true;
1031 if ( values
[0].length() )
1032 pageState
->DoSetSelection(GetPropertyByName(value
));
1034 pageState
->DoClearSelection();
1039 else if ( key
== wxS("ispageselected") )
1041 if ( restoreStates
& PageState
)
1044 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1046 if ( pageSelStatus
)
1047 selectedPage
= pageIndex
;
1055 else if ( key
== wxS("descboxheight") )
1057 if ( restoreStates
& DescBoxState
)
1060 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1062 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1079 // Force recalculation of virtual heights of all pages
1080 // (may be needed on unclean source string).
1082 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1085 pageState
->VirtualHeightChanged();
1087 pageState
= GetPageState(pageIndex
);
1093 // Selection of visible grid page must be set after Thaw() call
1094 if ( pgSelectionSet
)
1097 pg
->DoSelectProperty(newSelection
);
1099 pg
->DoClearSelection();
1102 if ( selectedPage
!= -1 )
1104 DoSelectPage(selectedPage
);
1115 #endif // wxUSE_PROPGRID