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>
56 const wxChar
*wxPGTypeName_long
= wxT("long");
57 const wxChar
*wxPGTypeName_bool
= wxT("bool");
58 const wxChar
*wxPGTypeName_double
= wxT("double");
59 const wxChar
*wxPGTypeName_wxString
= wxT("string");
60 const wxChar
*wxPGTypeName_void
= wxT("void*");
61 const wxChar
*wxPGTypeName_wxArrayString
= wxT("arrstring");
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxPoint
, WXDLLIMPEXP_PROPGRID
)
69 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxSize
, WXDLLIMPEXP_PROPGRID
)
70 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(wxArrayInt
, WXDLLIMPEXP_PROPGRID
)
71 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxLongLong
, WXDLLIMPEXP_PROPGRID
)
72 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxULongLong
, WXDLLIMPEXP_PROPGRID
)
74 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxFont
, WXDLLIMPEXP_PROPGRID
)
76 // -----------------------------------------------------------------------
78 // -----------------------------------------------------------------------
80 long wxPGVariantToInt( const wxVariant
& variant
, long defVal
)
82 if ( variant
.IsNull() )
85 if ( variant
.GetType() == wxS("long") )
86 return variant
.GetLong();
88 if ( variant
.GetType() == wxS("bool") )
89 return variant
.GetBool() ?
1 : 0;
91 if ( variant
.GetType() == wxS("wxLongLong") )
97 else if ( ll
<= LONG_MIN
)
104 if ( variant
.GetType() == wxPG_VARIANT_TYPE_STRING
)
105 variant
.GetString().ToLong(&l
, 0);
110 // -----------------------------------------------------------------------
112 bool wxPGVariantToLongLong( const wxVariant
& variant
, wxLongLong_t
* pResult
)
114 if ( variant
.IsNull() )
117 wxString variantType
= variant
.GetType();
119 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
121 *pResult
= variant
.GetLong();
125 if ( variantType
== wxLongLong_VariantType
)
129 *pResult
= ll
.GetValue();
136 // -----------------------------------------------------------------------
138 bool wxPGVariantToULongLong( const wxVariant
& variant
, wxULongLong_t
* pResult
)
140 if ( variant
.IsNull() )
143 wxString variantType
= variant
.GetType();
145 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
147 *pResult
= (unsigned long)variant
.GetLong();
151 if ( variantType
== wxULongLong_VariantType
)
155 *pResult
= ull
.GetValue();
162 // -----------------------------------------------------------------------
164 bool wxPGVariantToDouble( const wxVariant
& variant
, double* pResult
)
166 if ( variant
.IsNull() )
169 wxString variantType
= variant
.GetType();
171 if ( variantType
== wxPG_VARIANT_TYPE_DOUBLE
)
173 *pResult
= variant
.GetDouble();
177 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
179 *pResult
= (double)variant
.GetLong();
183 if ( variantType
== wxLongLong_VariantType
)
187 *pResult
= ll
.ToDouble();
191 if ( variantType
== wxPG_VARIANT_TYPE_STRING
)
192 if ( variant
.GetString().ToDouble(pResult
) )
198 // -----------------------------------------------------------------------
200 // -----------------------------------------------------------------------
202 wxPGProperty
* wxPGPropArgCls
::GetPtr( wxPropertyGridInterface
* iface
) const
204 if ( m_flags
== IsProperty
)
206 wxASSERT_MSG( m_ptr
.property
, wxT("invalid property ptr") );
207 return m_ptr
.property
;
209 else if ( m_flags
& IsWxString
)
210 return iface
->GetPropertyByNameA(*m_ptr
.stringName
);
211 else if ( m_flags
& IsCharPtr
)
212 return iface
->GetPropertyByNameA(m_ptr
.charName
);
214 else if ( m_flags
& IsWCharPtr
)
215 return iface
->GetPropertyByNameA(m_ptr
.wcharName
);
221 // -----------------------------------------------------------------------
222 // wxPropertyGridInterface
223 // -----------------------------------------------------------------------
225 void wxPropertyGridInterface
::RefreshGrid( wxPropertyGridPageState
* state
)
230 wxPropertyGrid
* grid
= state
->GetGrid();
231 if ( grid
->GetState() == state
&& !grid
->IsFrozen() )
237 // -----------------------------------------------------------------------
239 wxPGProperty
* wxPropertyGridInterface
::Append( wxPGProperty
* property
)
241 wxPGProperty
* retp
= m_pState
->DoAppend(property
);
243 wxPropertyGrid
* grid
= m_pState
->GetGrid();
250 // -----------------------------------------------------------------------
252 wxPGProperty
* wxPropertyGridInterface
::AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
)
254 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
255 wxPGProperty
* pwc
= (wxPGProperty
*) p
;
256 wxPGProperty
* retp
= m_pState
->DoInsert(pwc
, pwc
->GetChildCount(), newproperty
);
260 // -----------------------------------------------------------------------
262 wxPGProperty
* wxPropertyGridInterface
::Insert( wxPGPropArg id
, wxPGProperty
* property
)
264 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
265 wxPGProperty
* retp
= m_pState
->DoInsert(p
->GetParent(), p
->GetArrIndex(), property
);
270 // -----------------------------------------------------------------------
272 wxPGProperty
* wxPropertyGridInterface
::Insert( wxPGPropArg id
, int index
, wxPGProperty
* newproperty
)
274 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
275 wxPGProperty
* retp
= m_pState
->DoInsert((wxPGProperty
*)p
,index
,newproperty
);
280 // -----------------------------------------------------------------------
282 void wxPropertyGridInterface
::DeleteProperty( wxPGPropArg id
)
284 wxPG_PROP_ARG_CALL_PROLOG()
286 wxPropertyGridPageState
* state
= p
->GetParentState();
287 wxPropertyGrid
* grid
= state
->GetGrid();
289 if ( grid
->GetState() == state
)
291 bool selRes
= grid
->DoSelectProperty(NULL
, wxPG_SEL_DELETING
);
292 wxPG_CHECK_RET_DBG( selRes
,
293 wxT("failed to deselect a property (editor probably had invalid value)") );
296 state
->DoDelete( p
);
301 // -----------------------------------------------------------------------
303 wxPGProperty
* wxPropertyGridInterface
::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
305 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
307 wxPGProperty
* replaced
= p
;
308 wxCHECK_MSG( replaced
&& property
,
310 wxT("NULL property") );
311 wxCHECK_MSG( !replaced
->IsCategory(),
313 wxT("cannot replace this type of property") );
314 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
316 wxT("cannot replace properties in alphabetic mode") );
318 // Get address to the slot
319 wxPGProperty
* parent
= replaced
->GetParent();
320 int ind
= replaced
->GetIndexInParent();
322 wxPropertyGridPageState
* state
= replaced
->GetParentState();
323 DeleteProperty(replaced
); // Must use generic Delete
324 state
->DoInsert(parent
,ind
,property
);
329 // -----------------------------------------------------------------------
330 // wxPropertyGridInterface property operations
331 // -----------------------------------------------------------------------
333 bool wxPropertyGridInterface
::ClearSelection()
335 wxPropertyGridPageState
* state
= m_pState
;
336 wxPropertyGrid
* pg
= state
->GetGrid();
337 if ( pg
->GetState() == state
)
338 return pg
->DoClearSelection();
340 state
->SetSelection(NULL
);
344 // -----------------------------------------------------------------------
346 void wxPropertyGridInterface
::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
348 wxPG_PROP_ARG_CALL_PROLOG()
350 m_pState
->DoLimitPropertyEditing(p
, limit
);
354 // -----------------------------------------------------------------------
356 bool wxPropertyGridInterface
::EnableProperty( wxPGPropArg id
, bool enable
)
358 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
360 wxPropertyGridPageState
* state
= p
->GetParentState();
361 wxPropertyGrid
* grid
= state
->GetGrid();
365 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
368 // If active, Set active Editor.
369 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
370 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
374 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
377 // If active, Disable as active Editor.
378 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
379 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
382 state
->DoEnableProperty(p
, enable
);
384 RefreshProperty( p
);
389 // -----------------------------------------------------------------------
391 bool wxPropertyGridInterface
::ExpandAll( bool doExpand
)
393 wxPropertyGridPageState
* state
= m_pState
;
395 if ( !state
->DoGetRoot()->GetChildCount() )
398 wxPropertyGrid
* pg
= state
->GetGrid();
400 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
403 if ( !pg
->ClearSelection() )
409 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
411 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
412 if ( p
->GetChildCount() )
416 if ( !p
->IsExpanded() )
423 if ( p
->IsExpanded() )
425 state
->DoCollapse(p
);
431 pg
->RecalculateVirtualSize();
438 // -----------------------------------------------------------------------
440 void wxPropertyGridInterface
::SetPropertyValueUnspecified( wxPGPropArg id
)
442 wxPG_PROP_ARG_CALL_PROLOG()
443 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
445 propGrid
->DoSetPropertyValueUnspecified(p
);
447 p
->GetParentState()->DoSetPropertyValueUnspecified(p
);
450 // -----------------------------------------------------------------------
451 // wxPropertyGridInterface property value setting and getting
452 // -----------------------------------------------------------------------
454 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
456 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
459 // -----------------------------------------------------------------------
461 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
462 const wxString
& typestr
,
465 wxASSERT( p
!= NULL
);
466 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
467 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
470 // -----------------------------------------------------------------------
472 void wxPropertyGridInterface
::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
474 wxPG_PROP_ARG_CALL_PROLOG()
479 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
481 propGrid
->DrawItemAndValueRelated( p
);
486 // -----------------------------------------------------------------------
488 void wxPropertyGridInterface
::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
490 wxPG_PROP_ARG_CALL_PROLOG()
492 if ( m_pState
->DoSetPropertyValueString(p
,value
) )
494 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
496 propGrid
->DrawItemAndValueRelated( p
);
500 // -----------------------------------------------------------------------
502 void wxPropertyGridInterface
::SetValidationFailureBehavior( int vfbFlags
)
504 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
507 // -----------------------------------------------------------------------
509 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByNameA( const wxString
& name
) const
511 wxPGProperty
* p
= GetPropertyByName(name
);
512 wxASSERT_MSG(p
,wxString
::Format(wxT("no property with name '%s'"),name
.c_str()));
516 // ----------------------------------------------------------------------------
518 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByLabel( const wxString
& label
) const
522 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
524 if ( it
.GetProperty()->GetLabel() == label
)
525 return it
.GetProperty();
528 return wxNullProperty
;
531 // ----------------------------------------------------------------------------
533 void wxPropertyGridInterface
::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
534 wxVariant
& value
, long argFlags
)
536 wxPG_PROP_ARG_CALL_PROLOG()
538 p
->SetAttribute( name
, value
);
540 if ( argFlags
& wxPG_RECURSE
)
543 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
544 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
548 // -----------------------------------------------------------------------
550 void wxPropertyGridInterface
::SetPropertyAttributeAll( const wxString
& attrName
,
553 unsigned int pageIndex
= 0;
557 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
560 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
566 // -----------------------------------------------------------------------
568 void wxPropertyGridInterface
::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
569 wxPGProperty
::FlagType flags
,
571 int iterFlags
) const
573 wxASSERT( targetArr
);
574 wxPGVIterator it
= GetVIterator( iterFlags
);
580 const wxPGProperty
* property
= it
.GetProperty();
584 if ( (property
->GetFlags() & flags
) == flags
)
585 targetArr
->push_back((wxPGProperty
*)property
);
589 if ( (property
->GetFlags() & flags
) != flags
)
590 targetArr
->push_back((wxPGProperty
*)property
);
595 // -----------------------------------------------------------------------
597 void wxPropertyGridInterface
::SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
598 wxPGProperty
::FlagType flags
,
603 for ( i
=0; i
<srcArr
.size(); i
++ )
605 wxPGProperty
* property
= srcArr
[i
];
608 property
->SetFlag(flags
);
610 property
->ClearFlag(flags
);
613 // If collapsed flag or hidden was manipulated, we need to update virtual
615 wxPropertyGrid
* pg
= GetPropertyGrid();
616 if ( flags
& (wxPG_PROP_COLLAPSED
|wxPG_PROP_HIDDEN
) )
618 GetState()->VirtualHeightChanged();
619 pg
->RecalculateVirtualSize();
623 // -----------------------------------------------------------------------
625 void wxPropertyGridInterface
::SetBoolChoices( const wxString
& trueChoice
,
626 const wxString
& falseChoice
)
628 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
629 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
632 // -----------------------------------------------------------------------
634 wxPGProperty
* wxPropertyGridInterface
::DoGetPropertyByName( const wxString
& name
) const
636 return m_pState
->BaseGetPropertyByName(name
);
639 // -----------------------------------------------------------------------
641 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByName( const wxString
& name
,
642 const wxString
& subname
) const
644 wxPGProperty
* p
= DoGetPropertyByName(name
);
645 if ( !p
|| !p
->GetChildCount() )
646 return wxNullProperty
;
648 return p
->GetPropertyByName(subname
);
651 // -----------------------------------------------------------------------
653 // Since GetPropertyByName is used *a lot*, this makes sense
654 // since non-virtual method can be called with less code.
655 wxPGProperty
* wxPropertyGridInterface
::GetPropertyByName( const wxString
& name
) const
657 wxPGProperty
* p
= DoGetPropertyByName(name
);
661 // Check if its "Property.SubProperty" format
662 int pos
= name
.Find(wxT('.'));
666 return GetPropertyByName(name
.substr(0,pos
),
667 name
.substr(pos
+1,name
.length()-pos
-1));
670 // -----------------------------------------------------------------------
672 bool wxPropertyGridInterface
::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
674 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
676 wxPropertyGrid
* pg
= m_pState
->GetGrid();
678 if ( pg
== p
->GetGrid() )
679 return pg
->DoHideProperty(p
, hide
, flags
);
681 m_pState
->DoHideProperty(p
, hide
, flags
);
686 // -----------------------------------------------------------------------
688 bool wxPropertyGridInterface
::Collapse( wxPGPropArg id
)
690 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
691 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
693 return pg
->DoCollapse(p
);
695 return p
->GetParentState()->DoCollapse(p
);
698 // -----------------------------------------------------------------------
700 bool wxPropertyGridInterface
::Expand( wxPGPropArg id
)
702 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
703 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
705 return pg
->DoExpand(p
);
707 return p
->GetParentState()->DoExpand(p
);
710 // -----------------------------------------------------------------------
712 void wxPropertyGridInterface
::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
714 wxPG_PROP_ARG_CALL_PROLOG()
716 p
->SetLabel( newproplabel
);
718 wxPropertyGridPageState
* state
= p
->GetParentState();
719 wxPropertyGrid
* pg
= state
->GetGrid();
721 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
722 pg
->SortChildren(p
->GetParent());
724 if ( pg
->GetState() == state
)
726 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
733 // -----------------------------------------------------------------------
735 bool wxPropertyGridInterface
::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
737 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
739 wxPropertyGrid
* pg
= m_pState
->GetGrid();
741 p
->m_maxLen
= (short) maxLen
;
743 // Adjust control if selected currently
744 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
746 wxWindow
* wnd
= pg
->GetEditorControl();
747 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
749 tc
->SetMaxLength( maxLen
);
758 // -----------------------------------------------------------------------
759 // GetPropertyValueAsXXX methods
761 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
762 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
764 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
765 wxVariant value = p->GetValue(); \
766 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
768 wxPGGetFailed(p,wxPGTypeName_##T); \
769 return (TRET)DEFRETVAL; \
771 return (TRET)value.Get##BIGNAME(); \
774 // String is different than others.
775 wxString wxPropertyGridInterface
::GetPropertyValueAsString( wxPGPropArg id
) const
777 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
778 return p
->GetValueAsString(wxPG_FULL_VALUE
);
781 bool wxPropertyGridInterface
::GetPropertyValueAsBool( wxPGPropArg id
) const
783 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
784 wxVariant value
= p
->GetValue();
785 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
787 return value
.GetBool();
789 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
791 return value
.GetLong()?
true:false;
793 wxPGGetFailed(p
,wxPGTypeName_bool
);
797 IMPLEMENT_GET_VALUE(long,long,Long
,0)
798 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
799 IMPLEMENT_GET_VALUE(void,void*,VoidPtr
,NULL
)
801 bool wxPropertyGridInterface
::IsPropertyExpanded( wxPGPropArg id
) const
803 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
804 return p
->IsExpanded();
807 // -----------------------------------------------------------------------
808 // wxPropertyGridInterface wrappers
809 // -----------------------------------------------------------------------
811 bool wxPropertyGridInterface
::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
813 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
816 // -----------------------------------------------------------------------
818 void wxPropertyGridInterface
::BeginAddChildren( wxPGPropArg id
)
820 wxPG_PROP_ARG_CALL_PROLOG()
821 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
822 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
823 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
826 // -----------------------------------------------------------------------
828 bool wxPropertyGridInterface
::EditorValidate()
830 return GetPropertyGrid()->DoEditorValidate();
833 // -----------------------------------------------------------------------
835 void wxPropertyGridInterface
::EndAddChildren( wxPGPropArg id
)
837 wxPG_PROP_ARG_CALL_PROLOG()
838 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
839 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
840 p
->SetFlag(wxPG_PROP_AGGREGATE
);
843 // -----------------------------------------------------------------------
844 // wxPGVIterator_State
845 // -----------------------------------------------------------------------
847 // Default returned by wxPropertyGridInterface::GetVIterator().
848 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
851 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
853 m_it
.Init( state
, flags
);
855 virtual ~wxPGVIteratorBase_State() { }
856 virtual void Next() { m_it
.Next(); }
859 wxPGVIterator wxPropertyGridInterface
::GetVIterator( int flags
) const
861 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
864 // -----------------------------------------------------------------------
865 // wxPGEditableState related functions
866 // -----------------------------------------------------------------------
868 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
869 // in the input string. This is an internal functions which is
870 // used for saving states
871 // NB: Similar function exists in aui/framemanager.cpp
872 static wxString
EscapeDelimiters(const wxString
& s
)
875 result
.Alloc(s
.length());
876 const wxChar
* ch
= s
.c_str();
879 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
887 wxString wxPropertyGridInterface
::SaveEditableState( int includedStates
) const
892 // Save state on page basis
893 unsigned int pageIndex
= 0;
894 wxArrayPtrVoid pageStates
;
898 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
901 pageStates
.Add(page
);
906 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
908 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
910 if ( includedStates
& SelectionState
)
913 if ( pageState
->GetSelection() )
914 sel
= pageState
->GetSelection()->GetName();
915 result
+= wxS("selection=");
916 result
+= EscapeDelimiters(sel
);
919 if ( includedStates
& ExpandedState
)
921 wxArrayPGProperty ptrs
;
922 wxPropertyGridConstIterator it
=
923 wxPropertyGridConstIterator( pageState
,
924 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
927 result
+= wxS("expanded=");
933 const wxPGProperty
* p
= it
.GetProperty();
935 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
936 result
+= EscapeDelimiters(p
->GetName());
941 if ( result
.Last() == wxS(',') )
946 if ( includedStates
& ScrollPosState
)
949 GetPropertyGrid()->GetViewStart(&x
,&y
);
950 result
+= wxString
::Format(wxS("scrollpos=%i,%i;"), x
, y
);
952 if ( includedStates
& SplitterPosState
)
954 result
+= wxS("splitterpos=");
956 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
957 result
+= wxString
::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
959 result
.RemoveLast(); // Remove last comma
962 if ( includedStates
& PageState
)
964 result
+= wxS("ispageselected=");
966 if ( GetPageState(-1) == pageState
)
971 result
.RemoveLast(); // Remove last semicolon
976 if ( result
.length() )
982 bool wxPropertyGridInterface
::RestoreEditableState( const wxString
& src
, int restoreStates
)
984 wxPropertyGrid
* pg
= GetPropertyGrid();
985 wxPGProperty
* newSelection
= NULL
;
989 long selectedPage
= -1;
990 bool pgSelectionSet
= false;
994 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
996 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
998 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1002 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
1004 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
1006 const wxString
& kvs
= kvpairStrings
[i
];
1007 int eq_pos
= kvs
.Find(wxS('='));
1008 if ( eq_pos
!= wxNOT_FOUND
)
1010 wxString key
= kvs
.substr(0, eq_pos
);
1011 wxString value
= kvs
.substr(eq_pos
+1);
1013 // Further split value by commas
1014 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
1016 if ( key
== wxS("expanded") )
1018 if ( restoreStates
& ExpandedState
)
1020 wxPropertyGridIterator it
=
1021 wxPropertyGridIterator( pageState
,
1025 // First collapse all
1026 for ( ; !it
.AtEnd(); it
.Next() )
1028 wxPGProperty
* p
= it
.GetProperty();
1029 pageState
->DoCollapse(p
);
1032 // Then expand those which names are in values
1033 for ( size_t n
=0; n
<values
.size(); n
++ )
1035 const wxString
& name
= values
[n
];
1036 wxPGProperty
* prop
= GetPropertyByName(name
);
1038 pageState
->DoExpand(prop
);
1042 else if ( key
== wxS("scrollpos") )
1044 if ( restoreStates
& ScrollPosState
)
1046 if ( values
.size() == 2 )
1048 values
[0].ToLong(&vx
);
1049 values
[1].ToLong(&vy
);
1057 else if ( key
== wxS("splitterpos") )
1059 if ( restoreStates
& SplitterPosState
)
1061 for ( size_t n
=1; n
<values
.size(); n
++ )
1064 values
[n
].ToLong(&pos
);
1066 pageState
->DoSetSplitterPosition(pos
, n
);
1070 else if ( key
== wxS("selection") )
1072 if ( restoreStates
& SelectionState
)
1074 if ( values
.size() > 0 )
1076 if ( pageState
->IsDisplayed() )
1078 if ( values
[0].length() )
1079 newSelection
= GetPropertyByName(value
);
1080 pgSelectionSet
= true;
1084 if ( values
[0].length() )
1085 pageState
->SetSelection(GetPropertyByName(value
));
1087 pageState
->DoClearSelection();
1092 else if ( key
== wxS("ispageselected") )
1094 if ( restoreStates
& PageState
)
1097 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1099 if ( pageSelStatus
)
1100 selectedPage
= pageIndex
;
1117 // Force recalculation of virtual heights of all pages
1118 // (may be needed on unclean source string).
1120 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1123 pageState
->VirtualHeightChanged();
1125 pageState
= GetPageState(pageIndex
);
1131 // Selection of visible grid page must be set after Thaw() call
1132 if ( pgSelectionSet
)
1135 pg
->SelectProperty(newSelection
);
1137 pg
->ClearSelection();
1140 if ( selectedPage
!= -1 )
1142 DoSelectPage(selectedPage
);
1153 #endif // wxUSE_PROPGRID