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"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcmemory.h"
30 #include "wx/button.h"
33 #include "wx/cursor.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/choice.h"
38 #include "wx/stattext.h"
39 #include "wx/scrolwin.h"
40 #include "wx/dirdlg.h"
41 #include "wx/layout.h"
43 #include "wx/textdlg.h"
44 #include "wx/filedlg.h"
45 #include "wx/statusbr.h"
50 #include <wx/propgrid/property.h>
51 #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(wxPGVariantDataPoint
, wxPoint
)
69 WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataSize
, wxSize
)
70 WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataArrayInt
, wxArrayInt
)
71 WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataLongLong
, wxLongLong
)
72 WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataULongLong
, wxULongLong
)
74 WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(wxPGVariantDataFont
, wxFont
)
76 wxObject
* wxPG_VariantToWxObject( const wxVariant
& variant
, wxClassInfo
* classInfo
)
78 if ( !variant
.IsValueKindOf(classInfo
) )
79 return (wxObject
*) NULL
;
81 wxVariantData
* vdata
= variant
.GetData();
83 wxPGVariantData
* pgvdata
= wxDynamicCastVariantData(vdata
, wxPGVariantData
);
85 return (wxObject
*) pgvdata
->GetValuePtr();
87 if ( wxPGIsVariantClassInfo(wxPGVariantDataGetClassInfo(vdata
), wxobject
) )
88 return variant
.GetWxObjectPtr();
90 return (wxObject
*) NULL
;
93 // -----------------------------------------------------------------------
95 // -----------------------------------------------------------------------
97 long wxPGVariantToInt( const wxVariant
& variant
, long defVal
)
99 if ( variant
.IsNull() )
102 if ( wxPGIsVariantType(variant
, long) )
103 return variant
.GetLong();
105 if ( wxPGIsVariantType(variant
, bool) )
106 return variant
.GetBool() ? 1 : 0;
108 if ( typeid(*variant
.GetData()) == typeid(wxPGVariantDataLongLong
) )
110 wxLongLong ll
= ((const wxPGVariantDataLongLong
&)variant
).GetValue();
111 if ( ll
>= LONG_MAX
)
113 else if ( ll
<= LONG_MIN
)
120 if ( wxPGIsVariantType(variant
, string
) )
121 variant
.GetString().ToLong(&l
, 0);
126 // -----------------------------------------------------------------------
128 bool wxPGVariantToLongLong( const wxVariant
& variant
, wxLongLong_t
* pResult
)
130 if ( variant
.IsNull() )
133 if ( wxPGIsVariantType(variant
, long) )
135 *pResult
= variant
.GetLong();
139 if ( typeid(*variant
.GetData()) == typeid(wxPGVariantDataLongLong
) )
141 *pResult
= ((const wxPGVariantDataLongLong
&)variant
).GetValue().GetValue();
148 // -----------------------------------------------------------------------
150 bool wxPGVariantToULongLong( const wxVariant
& variant
, wxULongLong_t
* pResult
)
152 if ( variant
.IsNull() )
155 if ( wxPGIsVariantType(variant
, long) )
157 *pResult
= (unsigned long)variant
.GetLong();
161 if ( typeid(*variant
.GetData()) == typeid(wxPGVariantDataULongLong
) )
163 *pResult
= ((const wxPGVariantDataULongLong
&)variant
).GetValue().GetValue();
170 // -----------------------------------------------------------------------
172 bool wxPGVariantToDouble( const wxVariant
& variant
, double* pResult
)
174 if ( variant
.IsNull() )
177 if ( wxPGIsVariantType(variant
, double) )
179 *pResult
= variant
.GetDouble();
183 if ( wxPGIsVariantType(variant
, long) )
185 *pResult
= (double)variant
.GetLong();
189 if ( typeid(*variant
.GetData()) == typeid(wxPGVariantDataLongLong
) )
191 wxLongLong ll
= ((const wxPGVariantDataLongLong
&)variant
).GetValue();
192 *pResult
= ll
.ToDouble();
196 if ( wxPGIsVariantType(variant
, string
) )
197 if ( variant
.GetString().ToDouble(pResult
) )
203 // -----------------------------------------------------------------------
204 // Choice related methods
205 // -----------------------------------------------------------------------
207 void wxPropertyGridInterface::AddPropertyChoice( wxPGPropArg id
,
208 const wxString
& label
,
211 wxPG_PROP_ARG_CALL_PROLOG()
213 p
->InsertChoice(label
,-1,value
);
217 void wxPropertyGridInterface::InsertPropertyChoice( wxPGPropArg id
,
218 const wxString
& label
,
222 wxPG_PROP_ARG_CALL_PROLOG()
224 p
->InsertChoice(label
,index
,value
);
228 void wxPropertyGridInterface::DeletePropertyChoice( wxPGPropArg id
,
231 wxPG_PROP_ARG_CALL_PROLOG()
233 p
->DeleteChoice(index
);
236 // -----------------------------------------------------------------------
238 void wxPropertyGridInterface::RefreshGrid( wxPropertyGridPageState
* state
)
243 wxPropertyGrid
* grid
= state
->GetGrid();
244 if ( grid
->GetState() == state
&& !grid
->IsFrozen() )
250 // -----------------------------------------------------------------------
252 wxPGProperty
* wxPropertyGridInterface::Append( wxPGProperty
* property
)
254 wxPGProperty
* retp
= m_pState
->DoAppend(property
);
256 wxPropertyGrid
* grid
= m_pState
->GetGrid();
263 // -----------------------------------------------------------------------
265 wxPGProperty
* wxPropertyGridInterface::AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
)
267 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
268 wxPGProperty
* pwc
= (wxPGProperty
*) p
;
269 wxPGProperty
* retp
= m_pState
->DoInsert(pwc
, pwc
->GetChildCount(), newproperty
);
273 // -----------------------------------------------------------------------
275 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, wxPGProperty
* property
)
277 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
278 wxPGProperty
* retp
= m_pState
->DoInsert(p
->GetParent(), p
->GetArrIndex(), property
);
283 // -----------------------------------------------------------------------
285 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, int index
, wxPGProperty
* newproperty
)
287 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
288 wxPGProperty
* retp
= m_pState
->DoInsert((wxPGProperty
*)p
,index
,newproperty
);
293 // -----------------------------------------------------------------------
295 void wxPropertyGridInterface::DeleteProperty( wxPGPropArg id
)
297 wxPG_PROP_ARG_CALL_PROLOG()
299 wxPropertyGridPageState
* state
= p
->GetParentState();
300 wxPropertyGrid
* grid
= state
->GetGrid();
302 if ( grid
->GetState() == state
)
304 bool selRes
= grid
->DoSelectProperty(NULL
, wxPG_SEL_DELETING
);
305 wxPG_CHECK_RET_DBG( selRes
,
306 wxT("failed to deselect a property (editor probably had invalid value)") );
309 state
->DoDelete( p
);
314 // -----------------------------------------------------------------------
316 wxPGProperty
* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
318 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
320 wxPGProperty
* replaced
= p
;
321 wxCHECK_MSG( replaced
&& property
,
323 wxT("NULL property") );
324 wxCHECK_MSG( !replaced
->IsCategory(),
326 wxT("cannot replace this type of property") );
327 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
329 wxT("cannot replace properties in alphabetic mode") );
331 // Get address to the slot
332 wxPGProperty
* parent
= replaced
->GetParent();
333 int ind
= replaced
->GetIndexInParent();
335 wxPropertyGridPageState
* state
= replaced
->GetParentState();
336 DeleteProperty(replaced
); // Must use generic Delete
337 state
->DoInsert(parent
,ind
,property
);
342 // -----------------------------------------------------------------------
343 // wxPropertyGridInterface property operations
344 // -----------------------------------------------------------------------
346 bool wxPropertyGridInterface::ClearSelection()
348 wxPropertyGridPageState
* state
= m_pState
;
349 wxPropertyGrid
* pg
= state
->GetGrid();
350 if ( pg
->GetState() == state
)
351 return pg
->DoClearSelection();
353 state
->SetSelection(NULL
);
357 // -----------------------------------------------------------------------
359 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
361 wxPG_PROP_ARG_CALL_PROLOG()
363 m_pState
->DoLimitPropertyEditing(p
, limit
);
367 // -----------------------------------------------------------------------
369 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
371 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
373 wxPropertyGridPageState
* state
= p
->GetParentState();
374 wxPropertyGrid
* grid
= state
->GetGrid();
378 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
381 // If active, Set active Editor.
382 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
383 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
387 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
390 // If active, Disable as active Editor.
391 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
392 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
395 state
->DoEnableProperty(p
, enable
);
397 RefreshProperty( p
);
402 // -----------------------------------------------------------------------
404 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
406 wxPropertyGridPageState
* state
= m_pState
;
408 if ( !state
->DoGetRoot()->GetChildCount() )
411 wxPropertyGrid
* pg
= state
->GetGrid();
413 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
416 if ( !pg
->ClearSelection() )
422 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
424 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
425 if ( p
->GetChildCount() )
429 if ( !p
->IsExpanded() )
436 if ( p
->IsExpanded() )
438 state
->DoCollapse(p
);
444 pg
->RecalculateVirtualSize();
451 // -----------------------------------------------------------------------
453 void wxPropertyGridInterface::SetPropertyValueUnspecified( wxPGPropArg id
)
455 wxPG_PROP_ARG_CALL_PROLOG()
456 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
458 propGrid
->DoSetPropertyValueUnspecified(p
);
460 p
->GetParentState()->DoSetPropertyValueUnspecified(p
);
463 // -----------------------------------------------------------------------
464 // wxPropertyGridInterface property value setting and getting
465 // -----------------------------------------------------------------------
467 void wxPGGetFailed( const wxPGProperty
* p
, const wxChar
* typestr
)
469 wxPGTypeOperationFailed(p
,typestr
,wxT("Get"));
472 // -----------------------------------------------------------------------
474 void wxPGTypeOperationFailed( const wxPGProperty
* p
, const wxChar
* typestr
,
477 wxASSERT( p
!= NULL
);
478 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
479 op
,p
->GetLabel().c_str(),p
->GetValue().GetType().c_str(),typestr
);
482 // -----------------------------------------------------------------------
484 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
486 wxPG_PROP_ARG_CALL_PROLOG()
491 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
493 propGrid
->DrawItemAndValueRelated( p
);
498 // -----------------------------------------------------------------------
500 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
502 wxPG_PROP_ARG_CALL_PROLOG()
504 if ( m_pState
->DoSetPropertyValueString(p
,value
) )
506 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
508 propGrid
->DrawItemAndValueRelated( p
);
512 // -----------------------------------------------------------------------
514 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
516 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
519 // -----------------------------------------------------------------------
521 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
523 wxPGProperty
* p
= GetPropertyByName(name
);
524 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
528 // ----------------------------------------------------------------------------
530 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
534 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
536 if ( it
.GetProperty()->GetLabel() == label
)
537 return it
.GetProperty();
540 return wxNullProperty
;
543 // ----------------------------------------------------------------------------
545 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
546 wxVariant
& value
, long argFlags
)
548 wxPG_PROP_ARG_CALL_PROLOG()
550 p
->SetAttribute( name
, value
);
552 if ( argFlags
& wxPG_RECURSE
)
555 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
556 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
560 // -----------------------------------------------------------------------
562 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
563 wxPGProperty::FlagType flags
,
565 int iterFlags
) const
567 wxASSERT( targetArr
);
568 wxPGVIterator it
= GetVIterator( iterFlags
);
574 const wxPGProperty
* property
= it
.GetProperty();
578 if ( (property
->GetFlags() & flags
) == flags
)
579 targetArr
->push_back((wxPGProperty
*)property
);
583 if ( (property
->GetFlags() & flags
) != flags
)
584 targetArr
->push_back((wxPGProperty
*)property
);
589 // -----------------------------------------------------------------------
591 void wxPropertyGridInterface::SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
592 wxPGProperty::FlagType flags
,
597 for ( i
=0; i
<srcArr
.size(); i
++ )
599 wxPGProperty
* property
= srcArr
[i
];
602 property
->SetFlag(flags
);
604 property
->ClearFlag(flags
);
607 // If collapsed flag or hidden was manipulated, we need to update virtual
609 wxPropertyGrid
* pg
= GetPropertyGrid();
610 if ( flags
& (wxPG_PROP_COLLAPSED
|wxPG_PROP_HIDDEN
) )
612 GetState()->VirtualHeightChanged();
613 pg
->RecalculateVirtualSize();
617 // -----------------------------------------------------------------------
619 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
620 const wxString
& falseChoice
)
622 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
623 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
626 // -----------------------------------------------------------------------
628 wxPGChoices gs_emptyChoices
;
630 wxPGChoices
& wxPropertyGridInterface::GetPropertyChoices( wxPGPropArg id
)
632 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(gs_emptyChoices
)
635 ci
.m_choices
= (wxPGChoices
*) NULL
;
637 p
->GetChoiceInfo(&ci
);
640 return gs_emptyChoices
;
642 return *ci
.m_choices
;
645 // -----------------------------------------------------------------------
647 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
649 return m_pState
->BaseGetPropertyByName(name
);
652 // -----------------------------------------------------------------------
654 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
655 const wxString
& subname
) const
657 wxPGProperty
* p
= DoGetPropertyByName(name
);
658 if ( !p
|| !p
->GetChildCount() )
659 return wxNullProperty
;
661 return p
->GetPropertyByName(subname
);
664 // -----------------------------------------------------------------------
666 // Since GetPropertyByName is used *a lot*, this makes sense
667 // since non-virtual method can be called with less code.
668 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
670 wxPGProperty
* p
= DoGetPropertyByName(name
);
674 // Check if its "Property.SubProperty" format
675 int pos
= name
.Find(wxT('.'));
679 return GetPropertyByName(name
.substr(0,pos
),
680 name
.substr(pos
+1,name
.length()-pos
-1));
683 // -----------------------------------------------------------------------
685 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
687 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
689 wxPropertyGrid
* pg
= m_pState
->GetGrid();
691 if ( pg
== p
->GetGrid() )
692 return pg
->DoHideProperty(p
, hide
, flags
);
694 m_pState
->DoHideProperty(p
, hide
, flags
);
699 // -----------------------------------------------------------------------
701 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
703 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
704 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
706 return pg
->DoCollapse(p
);
708 return p
->GetParentState()->DoCollapse(p
);
711 // -----------------------------------------------------------------------
713 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
715 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
716 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
718 return pg
->DoExpand(p
);
720 return p
->GetParentState()->DoExpand(p
);
723 // -----------------------------------------------------------------------
725 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
727 wxPG_PROP_ARG_CALL_PROLOG()
729 p
->SetLabel( newproplabel
);
731 wxPropertyGridPageState
* state
= p
->GetParentState();
732 wxPropertyGrid
* pg
= state
->GetGrid();
734 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
735 pg
->SortChildren(p
->GetParent());
737 if ( pg
->GetState() == state
)
739 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
746 // -----------------------------------------------------------------------
748 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
750 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
752 wxPropertyGrid
* pg
= m_pState
->GetGrid();
754 p
->m_maxLen
= (short) maxLen
;
756 // Adjust control if selected currently
757 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
759 wxWindow
* wnd
= pg
->GetEditorControl();
760 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
762 tc
->SetMaxLength( maxLen
);
771 // -----------------------------------------------------------------------
772 // GetPropertyValueAsXXX methods
774 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
775 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
777 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
778 wxVariant value = p->GetValue(); \
779 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
781 wxPGGetFailed(p,wxPGTypeName_##T); \
782 return (TRET)DEFRETVAL; \
784 return (TRET)value.Get##BIGNAME(); \
787 // String is different than others.
788 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
790 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
791 return p
->GetValueAsString(wxPG_FULL_VALUE
);
794 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
796 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
797 wxVariant value
= p
->GetValue();
798 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
800 return value
.GetBool();
802 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
804 return value
.GetLong()?true:false;
806 wxPGGetFailed(p
,wxPGTypeName_bool
);
810 IMPLEMENT_GET_VALUE(long,long,Long
,0)
811 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
812 IMPLEMENT_GET_VALUE(void,void*,VoidPtr
,NULL
)
814 // wxObject is different than others.
815 wxObject
* wxPropertyGridInterface::GetPropertyValueAsWxObjectPtr( wxPGPropArg id
) const
817 wxPG_PROP_ARG_CALL_PROLOG_RETVAL((wxObject
*)NULL
)
819 wxVariant value
= p
->GetValue();
820 wxVariantData
* vdata
= value
.GetData();
822 if ( !vdata
->GetValueClassInfo() )
823 return (wxObject
*) NULL
;
825 wxPGVariantData
* pgvdata
= wxDynamicCastVariantData(vdata
, wxPGVariantData
);
827 return (wxObject
*) pgvdata
->GetValuePtr();
829 if ( wxPGIsVariantClassInfo(wxPGVariantDataGetClassInfo(vdata
), wxobject
) )
830 return (wxObject
*) value
.GetWxObjectPtr();
832 return (wxObject
*) NULL
;
835 // -----------------------------------------------------------------------
837 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
839 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
840 return p
->IsExpanded();
843 // -----------------------------------------------------------------------
844 // wxPropertyGridInterface wrappers
845 // -----------------------------------------------------------------------
847 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
849 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
852 // -----------------------------------------------------------------------
854 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
856 wxPG_PROP_ARG_CALL_PROLOG()
857 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
858 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
859 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
862 // -----------------------------------------------------------------------
864 bool wxPropertyGridInterface::EditorValidate()
866 return GetPropertyGrid()->DoEditorValidate();
869 // -----------------------------------------------------------------------
871 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
873 wxPG_PROP_ARG_CALL_PROLOG()
874 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
875 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
876 p
->SetFlag(wxPG_PROP_AGGREGATE
);
879 // -----------------------------------------------------------------------
880 // wxPGVIterator_State
881 // -----------------------------------------------------------------------
883 // Default returned by wxPropertyGridInterface::GetVIterator().
884 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
887 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
889 m_it
.Init( state
, flags
);
891 virtual ~wxPGVIteratorBase_State() { }
892 virtual void Next() { m_it
.Next(); }
895 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
897 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
900 // -----------------------------------------------------------------------
901 // wxPGEditableState related functions
902 // -----------------------------------------------------------------------
904 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
905 // in the input string. This is an internal functions which is
906 // used for saving states
907 // NB: Similar function exists in aui/framemanager.cpp
908 static wxString
EscapeDelimiters(const wxString
& s
)
911 result
.Alloc(s
.length());
912 const wxChar
* ch
= s
.c_str();
915 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
923 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
928 // Save state on page basis
929 size_t pageIndex
= 0;
930 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
931 wxArrayPtrVoid pageStates
;
934 pageStates
.Add(pageState
);
936 pageState
= GetPageState(pageIndex
);
939 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
941 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
943 if ( includedStates
& SelectionState
)
946 if ( pageState
->GetSelection() )
947 sel
= pageState
->GetSelection()->GetName();
948 result
+= wxS("selection=");
949 result
+= EscapeDelimiters(sel
);
952 if ( includedStates
& ExpandedState
)
954 wxArrayPGProperty ptrs
;
955 wxPropertyGridConstIterator it
=
956 wxPropertyGridConstIterator( pageState
,
957 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
960 result
+= wxS("expanded=");
966 const wxPGProperty
* p
= it
.GetProperty();
968 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
969 result
+= EscapeDelimiters(p
->GetName());
974 if ( result
.Last() == wxS(',') )
979 if ( includedStates
& ScrollPosState
)
982 GetPropertyGrid()->GetViewStart(&x
,&y
);
983 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
985 if ( includedStates
& SplitterPosState
)
987 result
+= wxS("splitterpos=");
989 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
990 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
992 result
.RemoveLast(); // Remove last comma
995 if ( includedStates
& PageState
)
997 result
+= wxS("ispageselected=");
999 if ( GetPageState(-1) == pageState
)
1000 result
+= wxS("1;");
1002 result
+= wxS("0;");
1004 result
.RemoveLast(); // Remove last semicolon
1009 if ( result
.length() )
1010 result
.RemoveLast();
1015 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
1017 wxPropertyGrid
* pg
= GetPropertyGrid();
1018 wxPGProperty
* newSelection
= NULL
;
1022 long selectedPage
= -1;
1023 bool pgSelectionSet
= false;
1027 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
1029 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
1031 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1035 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
1037 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
1039 const wxString
& kvs
= kvpairStrings
[i
];
1040 int eq_pos
= kvs
.Find(wxS('='));
1041 if ( eq_pos
!= wxNOT_FOUND
)
1043 wxString key
= kvs
.substr(0, eq_pos
);
1044 wxString value
= kvs
.substr(eq_pos
+1);
1046 // Further split value by commas
1047 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
1049 if ( key
== wxS("expanded") )
1051 if ( restoreStates
& ExpandedState
)
1053 wxPropertyGridIterator it
=
1054 wxPropertyGridIterator( pageState
,
1058 // First collapse all
1059 for ( ; !it
.AtEnd(); it
.Next() )
1061 wxPGProperty
* p
= it
.GetProperty();
1062 pageState
->DoCollapse(p
);
1065 // Then expand those which names are in values
1066 for ( size_t n
=0; n
<values
.size(); n
++ )
1068 const wxString
& name
= values
[n
];
1069 wxPGProperty
* prop
= GetPropertyByName(name
);
1071 pageState
->DoExpand(prop
);
1075 else if ( key
== wxS("scrollpos") )
1077 if ( restoreStates
& ScrollPosState
)
1079 if ( values
.size() == 2 )
1081 values
[0].ToLong(&vx
);
1082 values
[1].ToLong(&vy
);
1090 else if ( key
== wxS("splitterpos") )
1092 if ( restoreStates
& SplitterPosState
)
1094 for ( size_t n
=1; n
<values
.size(); n
++ )
1097 values
[n
].ToLong(&pos
);
1099 pageState
->DoSetSplitterPosition(pos
, n
);
1103 else if ( key
== wxS("selection") )
1105 if ( restoreStates
& SelectionState
)
1107 if ( values
.size() > 0 )
1109 if ( pageState
->IsDisplayed() )
1111 if ( values
[0].length() )
1112 newSelection
= GetPropertyByName(value
);
1113 pgSelectionSet
= true;
1117 if ( values
[0].length() )
1118 pageState
->SetSelection(GetPropertyByName(value
));
1120 pageState
->DoClearSelection();
1125 else if ( key
== wxS("ispageselected") )
1127 if ( restoreStates
& PageState
)
1130 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1132 if ( pageSelStatus
)
1133 selectedPage
= pageIndex
;
1150 // Force recalculation of virtual heights of all pages
1151 // (may be needed on unclean source string).
1153 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1156 pageState
->VirtualHeightChanged();
1158 pageState
= GetPageState(pageIndex
);
1164 // Selection of visible grid page must be set after Thaw() call
1165 if ( pgSelectionSet
)
1168 pg
->SelectProperty(newSelection
);
1170 pg
->ClearSelection();
1173 if ( selectedPage
!= -1 )
1175 DoSelectPage(selectedPage
);