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 bool wxPropertyGridInterface::SetColumnProportion( unsigned int column
,
365 wxCHECK(m_pState
, false);
366 wxPropertyGrid
* pg
= m_pState
->GetGrid();
368 wxCHECK(pg
->HasFlag(wxPG_SPLITTER_AUTO_CENTER
), false);
369 m_pState
->DoSetColumnProportion(column
, proportion
);
373 // -----------------------------------------------------------------------
374 // wxPropertyGridInterface property value setting and getting
375 // -----------------------------------------------------------------------
377 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
379 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
382 // -----------------------------------------------------------------------
384 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
385 const wxString
& typestr
,
388 wxASSERT( p
!= NULL
);
389 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
390 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
393 // -----------------------------------------------------------------------
395 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
397 wxPG_PROP_ARG_CALL_PROLOG()
403 // -----------------------------------------------------------------------
405 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
407 wxPG_PROP_ARG_CALL_PROLOG()
410 m_pState
->DoSetPropertyValueString(p
, value
);
413 // -----------------------------------------------------------------------
415 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
417 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
420 // -----------------------------------------------------------------------
422 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
424 wxPGProperty
* p
= GetPropertyByName(name
);
425 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
429 // ----------------------------------------------------------------------------
431 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
435 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
437 if ( it
.GetProperty()->GetLabel() == label
)
438 return it
.GetProperty();
441 return wxNullProperty
;
444 // ----------------------------------------------------------------------------
446 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
447 wxVariant
& value
, long argFlags
)
449 wxPG_PROP_ARG_CALL_PROLOG()
451 p
->SetAttribute( name
, value
);
453 if ( argFlags
& wxPG_RECURSE
)
456 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
457 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
461 // -----------------------------------------------------------------------
463 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
466 unsigned int pageIndex
= 0;
470 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
473 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
479 // -----------------------------------------------------------------------
481 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
482 wxPGProperty::FlagType flags
,
484 int iterFlags
) const
486 wxASSERT( targetArr
);
487 wxPGVIterator it
= GetVIterator( iterFlags
);
493 const wxPGProperty
* property
= it
.GetProperty();
497 if ( (property
->GetFlags() & flags
) == flags
)
498 targetArr
->push_back((wxPGProperty
*)property
);
502 if ( (property
->GetFlags() & flags
) != flags
)
503 targetArr
->push_back((wxPGProperty
*)property
);
508 // -----------------------------------------------------------------------
510 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
511 const wxString
& falseChoice
)
513 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
514 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
517 // -----------------------------------------------------------------------
519 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
521 return m_pState
->BaseGetPropertyByName(name
);
524 // -----------------------------------------------------------------------
526 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
527 const wxString
& subname
) const
529 wxPGProperty
* p
= DoGetPropertyByName(name
);
530 if ( !p
|| !p
->GetChildCount() )
531 return wxNullProperty
;
533 return p
->GetPropertyByName(subname
);
536 // -----------------------------------------------------------------------
538 // Since GetPropertyByName is used *a lot*, this makes sense
539 // since non-virtual method can be called with less code.
540 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
542 wxPGProperty
* p
= DoGetPropertyByName(name
);
546 // Check if its "Property.SubProperty" format
547 int pos
= name
.Find(wxT('.'));
551 return GetPropertyByName(name
.substr(0,pos
),
552 name
.substr(pos
+1,name
.length()-pos
-1));
555 // -----------------------------------------------------------------------
557 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
559 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
561 wxPropertyGrid
* pg
= m_pState
->GetGrid();
563 if ( pg
== p
->GetGrid() )
564 return pg
->DoHideProperty(p
, hide
, flags
);
566 m_pState
->DoHideProperty(p
, hide
, flags
);
571 // -----------------------------------------------------------------------
573 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
575 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
576 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
578 return pg
->DoCollapse(p
);
580 return p
->GetParentState()->DoCollapse(p
);
583 // -----------------------------------------------------------------------
585 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
587 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
588 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
590 return pg
->DoExpand(p
);
592 return p
->GetParentState()->DoExpand(p
);
595 // -----------------------------------------------------------------------
597 void wxPropertyGridInterface::Sort( int flags
)
599 wxPropertyGrid
* pg
= GetPropertyGrid();
601 unsigned int pageIndex
= 0;
605 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
611 // Fix positions of any open editor controls
613 pg
->CorrectEditorWidgetPosY();
616 // -----------------------------------------------------------------------
618 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
620 wxPG_PROP_ARG_CALL_PROLOG()
622 p
->SetLabel( newproplabel
);
624 wxPropertyGridPageState
* state
= p
->GetParentState();
625 wxPropertyGrid
* pg
= state
->GetGrid();
627 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
628 pg
->SortChildren(p
->GetParent());
630 if ( pg
->GetState() == state
)
632 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
639 // -----------------------------------------------------------------------
641 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
643 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
645 wxPropertyGrid
* pg
= m_pState
->GetGrid();
647 p
->m_maxLen
= (short) maxLen
;
649 // Adjust control if selected currently
650 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
652 wxWindow
* wnd
= pg
->GetEditorControl();
653 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
655 tc
->SetMaxLength( maxLen
);
664 // -----------------------------------------------------------------------
667 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
668 const wxColour
& colour
,
671 wxPG_PROP_ARG_CALL_PROLOG()
672 p
->SetBackgroundColour(colour
, flags
);
676 // -----------------------------------------------------------------------
678 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
679 const wxColour
& colour
,
682 wxPG_PROP_ARG_CALL_PROLOG()
683 p
->SetTextColour(colour
, flags
);
687 // -----------------------------------------------------------------------
689 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
691 wxPG_PROP_ARG_CALL_PROLOG()
696 // -----------------------------------------------------------------------
698 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
700 const wxString
& text
,
701 const wxBitmap
& bitmap
,
702 const wxColour
& fgCol
,
703 const wxColour
& bgCol
)
705 wxPG_PROP_ARG_CALL_PROLOG()
707 wxPGCell
& cell
= p
->GetCell(column
);
708 if ( text
.length() && text
!= wxPG_LABEL
)
711 cell
.SetBitmap(bitmap
);
712 if ( fgCol
!= wxNullColour
)
713 cell
.SetFgCol(fgCol
);
714 if ( bgCol
!= wxNullColour
)
715 cell
.SetBgCol(bgCol
);
718 // -----------------------------------------------------------------------
719 // GetPropertyValueAsXXX methods
721 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
722 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
724 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
725 wxVariant value = p->GetValue(); \
726 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
728 wxPGGetFailed(p,wxPGTypeName_##T); \
729 return (TRET)DEFRETVAL; \
731 return (TRET)value.Get##BIGNAME(); \
734 // String is different than others.
735 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
737 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
738 return p
->GetValueAsString(wxPG_FULL_VALUE
);
741 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
743 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
744 wxVariant value
= p
->GetValue();
745 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
747 return value
.GetBool();
749 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
751 return value
.GetLong()?true:false;
753 wxPGGetFailed(p
,wxPGTypeName_bool
);
757 IMPLEMENT_GET_VALUE(long,long,Long
,0)
758 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
760 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
762 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
763 return p
->IsExpanded();
766 // -----------------------------------------------------------------------
767 // wxPropertyGridInterface wrappers
768 // -----------------------------------------------------------------------
770 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
772 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
775 // -----------------------------------------------------------------------
777 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
779 wxPG_PROP_ARG_CALL_PROLOG()
780 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
781 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
782 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
785 // -----------------------------------------------------------------------
787 bool wxPropertyGridInterface::EditorValidate()
789 return GetPropertyGrid()->DoEditorValidate();
792 // -----------------------------------------------------------------------
794 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
796 wxPG_PROP_ARG_CALL_PROLOG()
797 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
798 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
799 p
->SetFlag(wxPG_PROP_AGGREGATE
);
802 // -----------------------------------------------------------------------
803 // wxPGVIterator_State
804 // -----------------------------------------------------------------------
806 // Default returned by wxPropertyGridInterface::GetVIterator().
807 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
810 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
812 m_it
.Init( state
, flags
);
814 virtual ~wxPGVIteratorBase_State() { }
815 virtual void Next() { m_it
.Next(); }
818 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
820 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
823 // -----------------------------------------------------------------------
824 // wxPGEditableState related functions
825 // -----------------------------------------------------------------------
827 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
828 // in the input string. This is an internal functions which is
829 // used for saving states
830 // NB: Similar function exists in aui/framemanager.cpp
831 static wxString
EscapeDelimiters(const wxString
& s
)
834 result
.Alloc(s
.length());
835 const wxChar
* ch
= s
.c_str();
838 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
846 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
851 // Save state on page basis
852 unsigned int pageIndex
= 0;
853 wxArrayPtrVoid pageStates
;
857 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
860 pageStates
.Add(page
);
865 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
867 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
869 if ( includedStates
& SelectionState
)
872 if ( pageState
->GetSelection() )
873 sel
= pageState
->GetSelection()->GetName();
874 result
+= wxS("selection=");
875 result
+= EscapeDelimiters(sel
);
878 if ( includedStates
& ExpandedState
)
880 wxArrayPGProperty ptrs
;
881 wxPropertyGridConstIterator it
=
882 wxPropertyGridConstIterator( pageState
,
883 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
886 result
+= wxS("expanded=");
892 const wxPGProperty
* p
= it
.GetProperty();
894 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
895 result
+= EscapeDelimiters(p
->GetName());
900 if ( result
.Last() == wxS(',') )
905 if ( includedStates
& ScrollPosState
)
908 GetPropertyGrid()->GetViewStart(&x
,&y
);
909 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
911 if ( includedStates
& SplitterPosState
)
913 result
+= wxS("splitterpos=");
915 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
916 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
918 result
.RemoveLast(); // Remove last comma
921 if ( includedStates
& PageState
)
923 result
+= wxS("ispageselected=");
925 if ( GetPageState(-1) == pageState
)
930 if ( includedStates
& DescBoxState
)
932 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
934 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
936 result
.RemoveLast(); // Remove last semicolon
941 if ( result
.length() )
947 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
949 wxPropertyGrid
* pg
= GetPropertyGrid();
950 wxPGProperty
* newSelection
= NULL
;
954 long selectedPage
= -1;
955 bool pgSelectionSet
= false;
959 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
961 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
963 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
967 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
969 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
971 const wxString
& kvs
= kvpairStrings
[i
];
972 int eq_pos
= kvs
.Find(wxS('='));
973 if ( eq_pos
!= wxNOT_FOUND
)
975 wxString key
= kvs
.substr(0, eq_pos
);
976 wxString value
= kvs
.substr(eq_pos
+1);
978 // Further split value by commas
979 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
981 if ( key
== wxS("expanded") )
983 if ( restoreStates
& ExpandedState
)
985 wxPropertyGridIterator it
=
986 wxPropertyGridIterator( pageState
,
990 // First collapse all
991 for ( ; !it
.AtEnd(); it
.Next() )
993 wxPGProperty
* p
= it
.GetProperty();
994 pageState
->DoCollapse(p
);
997 // Then expand those which names are in values
998 for ( size_t n
=0; n
<values
.size(); n
++ )
1000 const wxString
& name
= values
[n
];
1001 wxPGProperty
* prop
= GetPropertyByName(name
);
1003 pageState
->DoExpand(prop
);
1007 else if ( key
== wxS("scrollpos") )
1009 if ( restoreStates
& ScrollPosState
)
1011 if ( values
.size() == 2 )
1013 values
[0].ToLong(&vx
);
1014 values
[1].ToLong(&vy
);
1022 else if ( key
== wxS("splitterpos") )
1024 if ( restoreStates
& SplitterPosState
)
1026 for ( size_t n
=1; n
<values
.size(); n
++ )
1029 values
[n
].ToLong(&pos
);
1031 pageState
->DoSetSplitterPosition(pos
, n
);
1035 else if ( key
== wxS("selection") )
1037 if ( restoreStates
& SelectionState
)
1039 if ( values
.size() > 0 )
1041 if ( pageState
->IsDisplayed() )
1043 if ( values
[0].length() )
1044 newSelection
= GetPropertyByName(value
);
1045 pgSelectionSet
= true;
1049 if ( values
[0].length() )
1050 pageState
->DoSetSelection(GetPropertyByName(value
));
1052 pageState
->DoClearSelection();
1057 else if ( key
== wxS("ispageselected") )
1059 if ( restoreStates
& PageState
)
1062 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1064 if ( pageSelStatus
)
1065 selectedPage
= pageIndex
;
1073 else if ( key
== wxS("descboxheight") )
1075 if ( restoreStates
& DescBoxState
)
1078 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1080 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1097 // Force recalculation of virtual heights of all pages
1098 // (may be needed on unclean source string).
1100 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1103 pageState
->VirtualHeightChanged();
1105 pageState
= GetPageState(pageIndex
);
1111 // Selection of visible grid page must be set after Thaw() call
1112 if ( pgSelectionSet
)
1115 pg
->DoSelectProperty(newSelection
);
1117 pg
->DoClearSelection();
1120 if ( selectedPage
!= -1 )
1122 DoSelectPage(selectedPage
);
1133 #endif // wxUSE_PROPGRID