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/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
43 #include "wx/layout.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
52 #include <wx/propgrid/property.h>
53 #include <wx/propgrid/propgrid.h>
58 const wxChar
*wxPGTypeName_long
= wxT("long");
59 const wxChar
*wxPGTypeName_bool
= wxT("bool");
60 const wxChar
*wxPGTypeName_double
= wxT("double");
61 const wxChar
*wxPGTypeName_wxString
= wxT("string");
62 const wxChar
*wxPGTypeName_void
= wxT("void*");
63 const wxChar
*wxPGTypeName_wxArrayString
= wxT("arrstring");
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxPoint
, WXDLLIMPEXP_PROPGRID
)
71 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxSize
, WXDLLIMPEXP_PROPGRID
)
72 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(wxArrayInt
, WXDLLIMPEXP_PROPGRID
)
73 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxLongLong
, WXDLLIMPEXP_PROPGRID
)
74 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxULongLong
, WXDLLIMPEXP_PROPGRID
)
76 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxFont
, WXDLLIMPEXP_PROPGRID
)
78 // -----------------------------------------------------------------------
80 // -----------------------------------------------------------------------
82 long wxPGVariantToInt( const wxVariant
& variant
, long defVal
)
84 if ( variant
.IsNull() )
87 if ( variant
.GetType() == wxS("long") )
88 return variant
.GetLong();
90 if ( variant
.GetType() == wxS("bool") )
91 return variant
.GetBool() ?
1 : 0;
93 if ( variant
.GetType() == wxS("wxLongLong") )
99 else if ( ll
<= LONG_MIN
)
106 if ( variant
.GetType() == wxPG_VARIANT_TYPE_STRING
)
107 variant
.GetString().ToLong(&l
, 0);
112 // -----------------------------------------------------------------------
114 bool wxPGVariantToLongLong( const wxVariant
& variant
, wxLongLong_t
* pResult
)
116 if ( variant
.IsNull() )
119 wxString variantType
= variant
.GetType();
121 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
123 *pResult
= variant
.GetLong();
127 if ( variantType
== wxLongLong_VariantType
)
131 *pResult
= ll
.GetValue();
138 // -----------------------------------------------------------------------
140 bool wxPGVariantToULongLong( const wxVariant
& variant
, wxULongLong_t
* pResult
)
142 if ( variant
.IsNull() )
145 wxString variantType
= variant
.GetType();
147 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
149 *pResult
= (unsigned long)variant
.GetLong();
153 if ( variantType
== wxULongLong_VariantType
)
157 *pResult
= ull
.GetValue();
164 // -----------------------------------------------------------------------
166 bool wxPGVariantToDouble( const wxVariant
& variant
, double* pResult
)
168 if ( variant
.IsNull() )
171 wxString variantType
= variant
.GetType();
173 if ( variantType
== wxPG_VARIANT_TYPE_DOUBLE
)
175 *pResult
= variant
.GetDouble();
179 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
181 *pResult
= (double)variant
.GetLong();
185 if ( variantType
== wxLongLong_VariantType
)
189 *pResult
= ll
.ToDouble();
193 if ( variantType
== wxPG_VARIANT_TYPE_STRING
)
194 if ( variant
.GetString().ToDouble(pResult
) )
200 // -----------------------------------------------------------------------
202 // -----------------------------------------------------------------------
204 wxPGProperty
* wxPGPropArgCls
::GetPtr( wxPropertyGridInterface
* iface
) const
206 if ( m_flags
== IsProperty
)
208 wxASSERT_MSG( m_ptr
.property
, wxT("invalid property ptr") );
209 return m_ptr
.property
;
211 else if ( m_flags
& IsWxString
)
212 return iface
->GetPropertyByNameA(*m_ptr
.stringName
);
213 else if ( m_flags
& IsCharPtr
)
214 return iface
->GetPropertyByNameA(m_ptr
.charName
);
216 else if ( m_flags
& IsWCharPtr
)
217 return iface
->GetPropertyByNameA(m_ptr
.wcharName
);
223 // -----------------------------------------------------------------------
224 // wxPropertyGridInterface
225 // -----------------------------------------------------------------------
227 void wxPropertyGridInterface
::RefreshGrid( wxPropertyGridPageState
* state
)
232 wxPropertyGrid
* grid
= state
->GetGrid();
233 if ( grid
->GetState() == state
&& !grid
->IsFrozen() )
239 // -----------------------------------------------------------------------
241 wxPGProperty
* wxPropertyGridInterface
::Append( wxPGProperty
* property
)
243 wxPGProperty
* retp
= m_pState
->DoAppend(property
);
245 wxPropertyGrid
* grid
= m_pState
->GetGrid();
252 // -----------------------------------------------------------------------
254 wxPGProperty
* wxPropertyGridInterface
::AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
)
256 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
257 wxPGProperty
* pwc
= (wxPGProperty
*) p
;
258 wxPGProperty
* retp
= m_pState
->DoInsert(pwc
, pwc
->GetChildCount(), newproperty
);
262 // -----------------------------------------------------------------------
264 wxPGProperty
* wxPropertyGridInterface
::Insert( wxPGPropArg id
, wxPGProperty
* property
)
266 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
267 wxPGProperty
* retp
= m_pState
->DoInsert(p
->GetParent(), p
->GetArrIndex(), property
);
272 // -----------------------------------------------------------------------
274 wxPGProperty
* wxPropertyGridInterface
::Insert( wxPGPropArg id
, int index
, wxPGProperty
* newproperty
)
276 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
277 wxPGProperty
* retp
= m_pState
->DoInsert((wxPGProperty
*)p
,index
,newproperty
);
282 // -----------------------------------------------------------------------
284 void wxPropertyGridInterface
::DeleteProperty( wxPGPropArg id
)
286 wxPG_PROP_ARG_CALL_PROLOG()
288 wxPropertyGridPageState
* state
= p
->GetParentState();
289 wxPropertyGrid
* grid
= state
->GetGrid();
291 if ( grid
->GetState() == state
)
293 bool selRes
= grid
->DoSelectProperty(NULL
, wxPG_SEL_DELETING
);
294 wxPG_CHECK_RET_DBG( selRes
,
295 wxT("failed to deselect a property (editor probably had invalid value)") );
298 state
->DoDelete( p
);
303 // -----------------------------------------------------------------------
305 wxPGProperty
* wxPropertyGridInterface
::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
307 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
309 wxPGProperty
* replaced
= p
;
310 wxCHECK_MSG( replaced
&& property
,
312 wxT("NULL property") );
313 wxCHECK_MSG( !replaced
->IsCategory(),
315 wxT("cannot replace this type of property") );
316 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
318 wxT("cannot replace properties in alphabetic mode") );
320 // Get address to the slot
321 wxPGProperty
* parent
= replaced
->GetParent();
322 int ind
= replaced
->GetIndexInParent();
324 wxPropertyGridPageState
* state
= replaced
->GetParentState();
325 DeleteProperty(replaced
); // Must use generic Delete
326 state
->DoInsert(parent
,ind
,property
);
331 // -----------------------------------------------------------------------
332 // wxPropertyGridInterface property operations
333 // -----------------------------------------------------------------------
335 bool wxPropertyGridInterface
::ClearSelection()
337 wxPropertyGridPageState
* state
= m_pState
;
338 wxPropertyGrid
* pg
= state
->GetGrid();
339 if ( pg
->GetState() == state
)
340 return pg
->DoClearSelection();
342 state
->SetSelection(NULL
);
346 // -----------------------------------------------------------------------
348 void wxPropertyGridInterface
::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
350 wxPG_PROP_ARG_CALL_PROLOG()
352 m_pState
->DoLimitPropertyEditing(p
, limit
);
356 // -----------------------------------------------------------------------
358 bool wxPropertyGridInterface
::EnableProperty( wxPGPropArg id
, bool enable
)
360 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
362 wxPropertyGridPageState
* state
= p
->GetParentState();
363 wxPropertyGrid
* grid
= state
->GetGrid();
367 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
370 // If active, Set active Editor.
371 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
372 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
376 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
379 // If active, Disable as active Editor.
380 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
381 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
384 state
->DoEnableProperty(p
, enable
);
386 RefreshProperty( p
);
391 // -----------------------------------------------------------------------
393 bool wxPropertyGridInterface
::ExpandAll( bool doExpand
)
395 wxPropertyGridPageState
* state
= m_pState
;
397 if ( !state
->DoGetRoot()->GetChildCount() )
400 wxPropertyGrid
* pg
= state
->GetGrid();
402 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
405 if ( !pg
->ClearSelection() )
411 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
413 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
414 if ( p
->GetChildCount() )
418 if ( !p
->IsExpanded() )
425 if ( p
->IsExpanded() )
427 state
->DoCollapse(p
);
433 pg
->RecalculateVirtualSize();
440 // -----------------------------------------------------------------------
442 void wxPropertyGridInterface
::SetPropertyValueUnspecified( wxPGPropArg id
)
444 wxPG_PROP_ARG_CALL_PROLOG()
445 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
447 propGrid
->DoSetPropertyValueUnspecified(p
);
449 p
->GetParentState()->DoSetPropertyValueUnspecified(p
);
452 // -----------------------------------------------------------------------
453 // wxPropertyGridInterface property value setting and getting
454 // -----------------------------------------------------------------------
456 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
458 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
461 // -----------------------------------------------------------------------
463 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
464 const wxString
& typestr
,
467 wxASSERT( p
!= NULL
);
468 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
469 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
472 // -----------------------------------------------------------------------
474 void wxPropertyGridInterface
::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
476 wxPG_PROP_ARG_CALL_PROLOG()
481 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
483 propGrid
->DrawItemAndValueRelated( p
);
488 // -----------------------------------------------------------------------
490 void wxPropertyGridInterface
::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
492 wxPG_PROP_ARG_CALL_PROLOG()
494 if ( m_pState
->DoSetPropertyValueString(p
,value
) )
496 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
498 propGrid
->DrawItemAndValueRelated( p
);
502 // -----------------------------------------------------------------------
504 void wxPropertyGridInterface
::SetValidationFailureBehavior( int vfbFlags
)
506 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
509 // -----------------------------------------------------------------------
511 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByNameA( const wxString
& name
) const
513 wxPGProperty
* p
= GetPropertyByName(name
);
514 wxASSERT_MSG(p
,wxString
::Format(wxT("no property with name '%s'"),name
.c_str()));
518 // ----------------------------------------------------------------------------
520 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByLabel( const wxString
& label
) const
524 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
526 if ( it
.GetProperty()->GetLabel() == label
)
527 return it
.GetProperty();
530 return wxNullProperty
;
533 // ----------------------------------------------------------------------------
535 void wxPropertyGridInterface
::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
536 wxVariant
& value
, long argFlags
)
538 wxPG_PROP_ARG_CALL_PROLOG()
540 p
->SetAttribute( name
, value
);
542 if ( argFlags
& wxPG_RECURSE
)
545 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
546 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
550 // -----------------------------------------------------------------------
552 void wxPropertyGridInterface
::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
553 wxPGProperty
::FlagType flags
,
555 int iterFlags
) const
557 wxASSERT( targetArr
);
558 wxPGVIterator it
= GetVIterator( iterFlags
);
564 const wxPGProperty
* property
= it
.GetProperty();
568 if ( (property
->GetFlags() & flags
) == flags
)
569 targetArr
->push_back((wxPGProperty
*)property
);
573 if ( (property
->GetFlags() & flags
) != flags
)
574 targetArr
->push_back((wxPGProperty
*)property
);
579 // -----------------------------------------------------------------------
581 void wxPropertyGridInterface
::SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
582 wxPGProperty
::FlagType flags
,
587 for ( i
=0; i
<srcArr
.size(); i
++ )
589 wxPGProperty
* property
= srcArr
[i
];
592 property
->SetFlag(flags
);
594 property
->ClearFlag(flags
);
597 // If collapsed flag or hidden was manipulated, we need to update virtual
599 wxPropertyGrid
* pg
= GetPropertyGrid();
600 if ( flags
& (wxPG_PROP_COLLAPSED
|wxPG_PROP_HIDDEN
) )
602 GetState()->VirtualHeightChanged();
603 pg
->RecalculateVirtualSize();
607 // -----------------------------------------------------------------------
609 void wxPropertyGridInterface
::SetBoolChoices( const wxString
& trueChoice
,
610 const wxString
& falseChoice
)
612 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
613 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
616 // -----------------------------------------------------------------------
618 wxPGProperty
* wxPropertyGridInterface
::DoGetPropertyByName( const wxString
& name
) const
620 return m_pState
->BaseGetPropertyByName(name
);
623 // -----------------------------------------------------------------------
625 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByName( const wxString
& name
,
626 const wxString
& subname
) const
628 wxPGProperty
* p
= DoGetPropertyByName(name
);
629 if ( !p
|| !p
->GetChildCount() )
630 return wxNullProperty
;
632 return p
->GetPropertyByName(subname
);
635 // -----------------------------------------------------------------------
637 // Since GetPropertyByName is used *a lot*, this makes sense
638 // since non-virtual method can be called with less code.
639 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByName( const wxString
& name
) const
641 wxPGProperty
* p
= DoGetPropertyByName(name
);
645 // Check if its "Property.SubProperty" format
646 int pos
= name
.Find(wxT('.'));
650 return GetPropertyByName(name
.substr(0,pos
),
651 name
.substr(pos
+1,name
.length()-pos
-1));
654 // -----------------------------------------------------------------------
656 bool wxPropertyGridInterface
::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
658 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
660 wxPropertyGrid
* pg
= m_pState
->GetGrid();
662 if ( pg
== p
->GetGrid() )
663 return pg
->DoHideProperty(p
, hide
, flags
);
665 m_pState
->DoHideProperty(p
, hide
, flags
);
670 // -----------------------------------------------------------------------
672 bool wxPropertyGridInterface
::Collapse( wxPGPropArg id
)
674 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
675 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
677 return pg
->DoCollapse(p
);
679 return p
->GetParentState()->DoCollapse(p
);
682 // -----------------------------------------------------------------------
684 bool wxPropertyGridInterface
::Expand( wxPGPropArg id
)
686 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
687 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
689 return pg
->DoExpand(p
);
691 return p
->GetParentState()->DoExpand(p
);
694 // -----------------------------------------------------------------------
696 void wxPropertyGridInterface
::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
698 wxPG_PROP_ARG_CALL_PROLOG()
700 p
->SetLabel( newproplabel
);
702 wxPropertyGridPageState
* state
= p
->GetParentState();
703 wxPropertyGrid
* pg
= state
->GetGrid();
705 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
706 pg
->SortChildren(p
->GetParent());
708 if ( pg
->GetState() == state
)
710 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
717 // -----------------------------------------------------------------------
719 bool wxPropertyGridInterface
::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
721 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
723 wxPropertyGrid
* pg
= m_pState
->GetGrid();
725 p
->m_maxLen
= (short) maxLen
;
727 // Adjust control if selected currently
728 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
730 wxWindow
* wnd
= pg
->GetEditorControl();
731 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
733 tc
->SetMaxLength( maxLen
);
742 // -----------------------------------------------------------------------
743 // GetPropertyValueAsXXX methods
745 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
746 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
748 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
749 wxVariant value = p->GetValue(); \
750 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
752 wxPGGetFailed(p,wxPGTypeName_##T); \
753 return (TRET)DEFRETVAL; \
755 return (TRET)value.Get##BIGNAME(); \
758 // String is different than others.
759 wxString wxPropertyGridInterface
::GetPropertyValueAsString( wxPGPropArg id
) const
761 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
762 return p
->GetValueAsString(wxPG_FULL_VALUE
);
765 bool wxPropertyGridInterface
::GetPropertyValueAsBool( wxPGPropArg id
) const
767 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
768 wxVariant value
= p
->GetValue();
769 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
771 return value
.GetBool();
773 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
775 return value
.GetLong()?
true:false;
777 wxPGGetFailed(p
,wxPGTypeName_bool
);
781 IMPLEMENT_GET_VALUE(long,long,Long
,0)
782 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
783 IMPLEMENT_GET_VALUE(void,void*,VoidPtr
,NULL
)
785 bool wxPropertyGridInterface
::IsPropertyExpanded( wxPGPropArg id
) const
787 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
788 return p
->IsExpanded();
791 // -----------------------------------------------------------------------
792 // wxPropertyGridInterface wrappers
793 // -----------------------------------------------------------------------
795 bool wxPropertyGridInterface
::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
797 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
800 // -----------------------------------------------------------------------
802 void wxPropertyGridInterface
::BeginAddChildren( wxPGPropArg id
)
804 wxPG_PROP_ARG_CALL_PROLOG()
805 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
806 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
807 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
810 // -----------------------------------------------------------------------
812 bool wxPropertyGridInterface
::EditorValidate()
814 return GetPropertyGrid()->DoEditorValidate();
817 // -----------------------------------------------------------------------
819 void wxPropertyGridInterface
::EndAddChildren( wxPGPropArg id
)
821 wxPG_PROP_ARG_CALL_PROLOG()
822 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
823 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
824 p
->SetFlag(wxPG_PROP_AGGREGATE
);
827 // -----------------------------------------------------------------------
828 // wxPGVIterator_State
829 // -----------------------------------------------------------------------
831 // Default returned by wxPropertyGridInterface::GetVIterator().
832 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
835 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
837 m_it
.Init( state
, flags
);
839 virtual ~wxPGVIteratorBase_State() { }
840 virtual void Next() { m_it
.Next(); }
843 wxPGVIterator wxPropertyGridInterface
::GetVIterator( int flags
) const
845 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
848 // -----------------------------------------------------------------------
849 // wxPGEditableState related functions
850 // -----------------------------------------------------------------------
852 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
853 // in the input string. This is an internal functions which is
854 // used for saving states
855 // NB: Similar function exists in aui/framemanager.cpp
856 static wxString
EscapeDelimiters(const wxString
& s
)
859 result
.Alloc(s
.length());
860 const wxChar
* ch
= s
.c_str();
863 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
871 wxString wxPropertyGridInterface
::SaveEditableState( int includedStates
) const
876 // Save state on page basis
877 size_t pageIndex
= 0;
878 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
879 wxArrayPtrVoid pageStates
;
882 pageStates
.Add(pageState
);
884 pageState
= GetPageState(pageIndex
);
887 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
889 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
891 if ( includedStates
& SelectionState
)
894 if ( pageState
->GetSelection() )
895 sel
= pageState
->GetSelection()->GetName();
896 result
+= wxS("selection=");
897 result
+= EscapeDelimiters(sel
);
900 if ( includedStates
& ExpandedState
)
902 wxArrayPGProperty ptrs
;
903 wxPropertyGridConstIterator it
=
904 wxPropertyGridConstIterator( pageState
,
905 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
908 result
+= wxS("expanded=");
914 const wxPGProperty
* p
= it
.GetProperty();
916 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
917 result
+= EscapeDelimiters(p
->GetName());
922 if ( result
.Last() == wxS(',') )
927 if ( includedStates
& ScrollPosState
)
930 GetPropertyGrid()->GetViewStart(&x
,&y
);
931 result
+= wxString
::Format(wxS("scrollpos=%i,%i;"), x
, y
);
933 if ( includedStates
& SplitterPosState
)
935 result
+= wxS("splitterpos=");
937 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
938 result
+= wxString
::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
940 result
.RemoveLast(); // Remove last comma
943 if ( includedStates
& PageState
)
945 result
+= wxS("ispageselected=");
947 if ( GetPageState(-1) == pageState
)
952 result
.RemoveLast(); // Remove last semicolon
957 if ( result
.length() )
963 bool wxPropertyGridInterface
::RestoreEditableState( const wxString
& src
, int restoreStates
)
965 wxPropertyGrid
* pg
= GetPropertyGrid();
966 wxPGProperty
* newSelection
= NULL
;
970 long selectedPage
= -1;
971 bool pgSelectionSet
= false;
975 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
977 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
979 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
983 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
985 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
987 const wxString
& kvs
= kvpairStrings
[i
];
988 int eq_pos
= kvs
.Find(wxS('='));
989 if ( eq_pos
!= wxNOT_FOUND
)
991 wxString key
= kvs
.substr(0, eq_pos
);
992 wxString value
= kvs
.substr(eq_pos
+1);
994 // Further split value by commas
995 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
997 if ( key
== wxS("expanded") )
999 if ( restoreStates
& ExpandedState
)
1001 wxPropertyGridIterator it
=
1002 wxPropertyGridIterator( pageState
,
1006 // First collapse all
1007 for ( ; !it
.AtEnd(); it
.Next() )
1009 wxPGProperty
* p
= it
.GetProperty();
1010 pageState
->DoCollapse(p
);
1013 // Then expand those which names are in values
1014 for ( size_t n
=0; n
<values
.size(); n
++ )
1016 const wxString
& name
= values
[n
];
1017 wxPGProperty
* prop
= GetPropertyByName(name
);
1019 pageState
->DoExpand(prop
);
1023 else if ( key
== wxS("scrollpos") )
1025 if ( restoreStates
& ScrollPosState
)
1027 if ( values
.size() == 2 )
1029 values
[0].ToLong(&vx
);
1030 values
[1].ToLong(&vy
);
1038 else if ( key
== wxS("splitterpos") )
1040 if ( restoreStates
& SplitterPosState
)
1042 for ( size_t n
=1; n
<values
.size(); n
++ )
1045 values
[n
].ToLong(&pos
);
1047 pageState
->DoSetSplitterPosition(pos
, n
);
1051 else if ( key
== wxS("selection") )
1053 if ( restoreStates
& SelectionState
)
1055 if ( values
.size() > 0 )
1057 if ( pageState
->IsDisplayed() )
1059 if ( values
[0].length() )
1060 newSelection
= GetPropertyByName(value
);
1061 pgSelectionSet
= true;
1065 if ( values
[0].length() )
1066 pageState
->SetSelection(GetPropertyByName(value
));
1068 pageState
->DoClearSelection();
1073 else if ( key
== wxS("ispageselected") )
1075 if ( restoreStates
& PageState
)
1078 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1080 if ( pageSelStatus
)
1081 selectedPage
= pageIndex
;
1098 // Force recalculation of virtual heights of all pages
1099 // (may be needed on unclean source string).
1101 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1104 pageState
->VirtualHeightChanged();
1106 pageState
= GetPageState(pageIndex
);
1112 // Selection of visible grid page must be set after Thaw() call
1113 if ( pgSelectionSet
)
1116 pg
->SelectProperty(newSelection
);
1118 pg
->ClearSelection();
1121 if ( selectedPage
!= -1 )
1123 DoSelectPage(selectedPage
);
1134 #endif // wxUSE_PROPGRID