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 pg
->DoClearSelection();
592 unsigned int pageIndex
= 0;
596 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
603 // -----------------------------------------------------------------------
605 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
607 wxPG_PROP_ARG_CALL_PROLOG()
609 p
->SetLabel( newproplabel
);
611 wxPropertyGridPageState
* state
= p
->GetParentState();
612 wxPropertyGrid
* pg
= state
->GetGrid();
614 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
615 pg
->SortChildren(p
->GetParent());
617 if ( pg
->GetState() == state
)
619 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
626 // -----------------------------------------------------------------------
628 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
630 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
632 wxPropertyGrid
* pg
= m_pState
->GetGrid();
634 p
->m_maxLen
= (short) maxLen
;
636 // Adjust control if selected currently
637 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
639 wxWindow
* wnd
= pg
->GetEditorControl();
640 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
642 tc
->SetMaxLength( maxLen
);
651 // -----------------------------------------------------------------------
654 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
655 const wxColour
& colour
,
658 wxPG_PROP_ARG_CALL_PROLOG()
659 p
->SetBackgroundColour(colour
, flags
);
663 // -----------------------------------------------------------------------
665 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
666 const wxColour
& colour
,
669 wxPG_PROP_ARG_CALL_PROLOG()
670 p
->SetTextColour(colour
, flags
);
674 // -----------------------------------------------------------------------
676 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
678 wxPG_PROP_ARG_CALL_PROLOG()
683 // -----------------------------------------------------------------------
685 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
687 const wxString
& text
,
688 const wxBitmap
& bitmap
,
689 const wxColour
& fgCol
,
690 const wxColour
& bgCol
)
692 wxPG_PROP_ARG_CALL_PROLOG()
694 wxPGCell
& cell
= p
->GetCell(column
);
695 if ( text
.length() && text
!= wxPG_LABEL
)
698 cell
.SetBitmap(bitmap
);
699 if ( fgCol
!= wxNullColour
)
700 cell
.SetFgCol(fgCol
);
701 if ( bgCol
!= wxNullColour
)
702 cell
.SetBgCol(bgCol
);
705 // -----------------------------------------------------------------------
706 // GetPropertyValueAsXXX methods
708 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
709 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
711 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
712 wxVariant value = p->GetValue(); \
713 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
715 wxPGGetFailed(p,wxPGTypeName_##T); \
716 return (TRET)DEFRETVAL; \
718 return (TRET)value.Get##BIGNAME(); \
721 // String is different than others.
722 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
724 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
725 return p
->GetValueAsString(wxPG_FULL_VALUE
);
728 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
730 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
731 wxVariant value
= p
->GetValue();
732 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
734 return value
.GetBool();
736 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
738 return value
.GetLong()?true:false;
740 wxPGGetFailed(p
,wxPGTypeName_bool
);
744 IMPLEMENT_GET_VALUE(long,long,Long
,0)
745 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
747 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
749 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
750 return p
->IsExpanded();
753 // -----------------------------------------------------------------------
754 // wxPropertyGridInterface wrappers
755 // -----------------------------------------------------------------------
757 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
759 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
762 // -----------------------------------------------------------------------
764 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
766 wxPG_PROP_ARG_CALL_PROLOG()
767 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
768 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
769 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
772 // -----------------------------------------------------------------------
774 bool wxPropertyGridInterface::EditorValidate()
776 return GetPropertyGrid()->DoEditorValidate();
779 // -----------------------------------------------------------------------
781 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
783 wxPG_PROP_ARG_CALL_PROLOG()
784 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
785 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
786 p
->SetFlag(wxPG_PROP_AGGREGATE
);
789 // -----------------------------------------------------------------------
790 // wxPGVIterator_State
791 // -----------------------------------------------------------------------
793 // Default returned by wxPropertyGridInterface::GetVIterator().
794 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
797 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
799 m_it
.Init( state
, flags
);
801 virtual ~wxPGVIteratorBase_State() { }
802 virtual void Next() { m_it
.Next(); }
805 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
807 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
810 // -----------------------------------------------------------------------
811 // wxPGEditableState related functions
812 // -----------------------------------------------------------------------
814 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
815 // in the input string. This is an internal functions which is
816 // used for saving states
817 // NB: Similar function exists in aui/framemanager.cpp
818 static wxString
EscapeDelimiters(const wxString
& s
)
821 result
.Alloc(s
.length());
822 const wxChar
* ch
= s
.c_str();
825 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
833 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
838 // Save state on page basis
839 unsigned int pageIndex
= 0;
840 wxArrayPtrVoid pageStates
;
844 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
847 pageStates
.Add(page
);
852 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
854 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
856 if ( includedStates
& SelectionState
)
859 if ( pageState
->GetSelection() )
860 sel
= pageState
->GetSelection()->GetName();
861 result
+= wxS("selection=");
862 result
+= EscapeDelimiters(sel
);
865 if ( includedStates
& ExpandedState
)
867 wxArrayPGProperty ptrs
;
868 wxPropertyGridConstIterator it
=
869 wxPropertyGridConstIterator( pageState
,
870 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
873 result
+= wxS("expanded=");
879 const wxPGProperty
* p
= it
.GetProperty();
881 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
882 result
+= EscapeDelimiters(p
->GetName());
887 if ( result
.Last() == wxS(',') )
892 if ( includedStates
& ScrollPosState
)
895 GetPropertyGrid()->GetViewStart(&x
,&y
);
896 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
898 if ( includedStates
& SplitterPosState
)
900 result
+= wxS("splitterpos=");
902 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
903 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
905 result
.RemoveLast(); // Remove last comma
908 if ( includedStates
& PageState
)
910 result
+= wxS("ispageselected=");
912 if ( GetPageState(-1) == pageState
)
917 if ( includedStates
& DescBoxState
)
919 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
921 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
923 result
.RemoveLast(); // Remove last semicolon
928 if ( result
.length() )
934 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
936 wxPropertyGrid
* pg
= GetPropertyGrid();
937 wxPGProperty
* newSelection
= NULL
;
941 long selectedPage
= -1;
942 bool pgSelectionSet
= false;
946 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
948 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
950 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
954 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
956 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
958 const wxString
& kvs
= kvpairStrings
[i
];
959 int eq_pos
= kvs
.Find(wxS('='));
960 if ( eq_pos
!= wxNOT_FOUND
)
962 wxString key
= kvs
.substr(0, eq_pos
);
963 wxString value
= kvs
.substr(eq_pos
+1);
965 // Further split value by commas
966 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
968 if ( key
== wxS("expanded") )
970 if ( restoreStates
& ExpandedState
)
972 wxPropertyGridIterator it
=
973 wxPropertyGridIterator( pageState
,
977 // First collapse all
978 for ( ; !it
.AtEnd(); it
.Next() )
980 wxPGProperty
* p
= it
.GetProperty();
981 pageState
->DoCollapse(p
);
984 // Then expand those which names are in values
985 for ( size_t n
=0; n
<values
.size(); n
++ )
987 const wxString
& name
= values
[n
];
988 wxPGProperty
* prop
= GetPropertyByName(name
);
990 pageState
->DoExpand(prop
);
994 else if ( key
== wxS("scrollpos") )
996 if ( restoreStates
& ScrollPosState
)
998 if ( values
.size() == 2 )
1000 values
[0].ToLong(&vx
);
1001 values
[1].ToLong(&vy
);
1009 else if ( key
== wxS("splitterpos") )
1011 if ( restoreStates
& SplitterPosState
)
1013 for ( size_t n
=1; n
<values
.size(); n
++ )
1016 values
[n
].ToLong(&pos
);
1018 pageState
->DoSetSplitterPosition(pos
, n
);
1022 else if ( key
== wxS("selection") )
1024 if ( restoreStates
& SelectionState
)
1026 if ( values
.size() > 0 )
1028 if ( pageState
->IsDisplayed() )
1030 if ( values
[0].length() )
1031 newSelection
= GetPropertyByName(value
);
1032 pgSelectionSet
= true;
1036 if ( values
[0].length() )
1037 pageState
->DoSetSelection(GetPropertyByName(value
));
1039 pageState
->DoClearSelection();
1044 else if ( key
== wxS("ispageselected") )
1046 if ( restoreStates
& PageState
)
1049 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1051 if ( pageSelStatus
)
1052 selectedPage
= pageIndex
;
1060 else if ( key
== wxS("descboxheight") )
1062 if ( restoreStates
& DescBoxState
)
1065 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1067 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1084 // Force recalculation of virtual heights of all pages
1085 // (may be needed on unclean source string).
1087 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1090 pageState
->VirtualHeightChanged();
1092 pageState
= GetPageState(pageIndex
);
1098 // Selection of visible grid page must be set after Thaw() call
1099 if ( pgSelectionSet
)
1102 pg
->DoSelectProperty(newSelection
);
1104 pg
->DoClearSelection();
1107 if ( selectedPage
!= -1 )
1109 DoSelectPage(selectedPage
);
1120 #endif // wxUSE_PROPGRID