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 // Choice related methods
225 // -----------------------------------------------------------------------
227 void wxPropertyGridInterface::AddPropertyChoice( wxPGPropArg id
,
228 const wxString
& label
,
231 wxPG_PROP_ARG_CALL_PROLOG()
233 p
->InsertChoice(label
,-1,value
);
237 void wxPropertyGridInterface::InsertPropertyChoice( wxPGPropArg id
,
238 const wxString
& label
,
242 wxPG_PROP_ARG_CALL_PROLOG()
244 p
->InsertChoice(label
,index
,value
);
248 void wxPropertyGridInterface::DeletePropertyChoice( wxPGPropArg id
,
251 wxPG_PROP_ARG_CALL_PROLOG()
253 p
->DeleteChoice(index
);
256 // -----------------------------------------------------------------------
258 void wxPropertyGridInterface::RefreshGrid( wxPropertyGridPageState
* state
)
263 wxPropertyGrid
* grid
= state
->GetGrid();
264 if ( grid
->GetState() == state
&& !grid
->IsFrozen() )
270 // -----------------------------------------------------------------------
272 wxPGProperty
* wxPropertyGridInterface::Append( wxPGProperty
* property
)
274 wxPGProperty
* retp
= m_pState
->DoAppend(property
);
276 wxPropertyGrid
* grid
= m_pState
->GetGrid();
283 // -----------------------------------------------------------------------
285 wxPGProperty
* wxPropertyGridInterface::AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
)
287 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
288 wxPGProperty
* pwc
= (wxPGProperty
*) p
;
289 wxPGProperty
* retp
= m_pState
->DoInsert(pwc
, pwc
->GetChildCount(), newproperty
);
293 // -----------------------------------------------------------------------
295 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, wxPGProperty
* property
)
297 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
298 wxPGProperty
* retp
= m_pState
->DoInsert(p
->GetParent(), p
->GetArrIndex(), property
);
303 // -----------------------------------------------------------------------
305 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, int index
, wxPGProperty
* newproperty
)
307 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
308 wxPGProperty
* retp
= m_pState
->DoInsert((wxPGProperty
*)p
,index
,newproperty
);
313 // -----------------------------------------------------------------------
315 void wxPropertyGridInterface::DeleteProperty( wxPGPropArg id
)
317 wxPG_PROP_ARG_CALL_PROLOG()
319 wxPropertyGridPageState
* state
= p
->GetParentState();
320 wxPropertyGrid
* grid
= state
->GetGrid();
322 if ( grid
->GetState() == state
)
324 bool selRes
= grid
->DoSelectProperty(NULL
, wxPG_SEL_DELETING
);
325 wxPG_CHECK_RET_DBG( selRes
,
326 wxT("failed to deselect a property (editor probably had invalid value)") );
329 state
->DoDelete( p
);
334 // -----------------------------------------------------------------------
336 wxPGProperty
* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
338 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
340 wxPGProperty
* replaced
= p
;
341 wxCHECK_MSG( replaced
&& property
,
343 wxT("NULL property") );
344 wxCHECK_MSG( !replaced
->IsCategory(),
346 wxT("cannot replace this type of property") );
347 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
349 wxT("cannot replace properties in alphabetic mode") );
351 // Get address to the slot
352 wxPGProperty
* parent
= replaced
->GetParent();
353 int ind
= replaced
->GetIndexInParent();
355 wxPropertyGridPageState
* state
= replaced
->GetParentState();
356 DeleteProperty(replaced
); // Must use generic Delete
357 state
->DoInsert(parent
,ind
,property
);
362 // -----------------------------------------------------------------------
363 // wxPropertyGridInterface property operations
364 // -----------------------------------------------------------------------
366 bool wxPropertyGridInterface::ClearSelection()
368 wxPropertyGridPageState
* state
= m_pState
;
369 wxPropertyGrid
* pg
= state
->GetGrid();
370 if ( pg
->GetState() == state
)
371 return pg
->DoClearSelection();
373 state
->SetSelection(NULL
);
377 // -----------------------------------------------------------------------
379 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
381 wxPG_PROP_ARG_CALL_PROLOG()
383 m_pState
->DoLimitPropertyEditing(p
, limit
);
387 // -----------------------------------------------------------------------
389 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
391 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
393 wxPropertyGridPageState
* state
= p
->GetParentState();
394 wxPropertyGrid
* grid
= state
->GetGrid();
398 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
401 // If active, Set active Editor.
402 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
403 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
407 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
410 // If active, Disable as active Editor.
411 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
412 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
415 state
->DoEnableProperty(p
, enable
);
417 RefreshProperty( p
);
422 // -----------------------------------------------------------------------
424 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
426 wxPropertyGridPageState
* state
= m_pState
;
428 if ( !state
->DoGetRoot()->GetChildCount() )
431 wxPropertyGrid
* pg
= state
->GetGrid();
433 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
436 if ( !pg
->ClearSelection() )
442 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
444 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
445 if ( p
->GetChildCount() )
449 if ( !p
->IsExpanded() )
456 if ( p
->IsExpanded() )
458 state
->DoCollapse(p
);
464 pg
->RecalculateVirtualSize();
471 // -----------------------------------------------------------------------
473 void wxPropertyGridInterface::SetPropertyValueUnspecified( wxPGPropArg id
)
475 wxPG_PROP_ARG_CALL_PROLOG()
476 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
478 propGrid
->DoSetPropertyValueUnspecified(p
);
480 p
->GetParentState()->DoSetPropertyValueUnspecified(p
);
483 // -----------------------------------------------------------------------
484 // wxPropertyGridInterface property value setting and getting
485 // -----------------------------------------------------------------------
487 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
489 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
492 // -----------------------------------------------------------------------
494 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
495 const wxString
& typestr
,
498 wxASSERT( p
!= NULL
);
499 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
500 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
503 // -----------------------------------------------------------------------
505 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
507 wxPG_PROP_ARG_CALL_PROLOG()
512 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
514 propGrid
->DrawItemAndValueRelated( p
);
519 // -----------------------------------------------------------------------
521 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
523 wxPG_PROP_ARG_CALL_PROLOG()
525 if ( m_pState
->DoSetPropertyValueString(p
,value
) )
527 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
529 propGrid
->DrawItemAndValueRelated( p
);
533 // -----------------------------------------------------------------------
535 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
537 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
540 // -----------------------------------------------------------------------
542 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
544 wxPGProperty
* p
= GetPropertyByName(name
);
545 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
549 // ----------------------------------------------------------------------------
551 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
555 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
557 if ( it
.GetProperty()->GetLabel() == label
)
558 return it
.GetProperty();
561 return wxNullProperty
;
564 // ----------------------------------------------------------------------------
566 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
567 wxVariant
& value
, long argFlags
)
569 wxPG_PROP_ARG_CALL_PROLOG()
571 p
->SetAttribute( name
, value
);
573 if ( argFlags
& wxPG_RECURSE
)
576 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
577 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
581 // -----------------------------------------------------------------------
583 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
584 wxPGProperty::FlagType flags
,
586 int iterFlags
) const
588 wxASSERT( targetArr
);
589 wxPGVIterator it
= GetVIterator( iterFlags
);
595 const wxPGProperty
* property
= it
.GetProperty();
599 if ( (property
->GetFlags() & flags
) == flags
)
600 targetArr
->push_back((wxPGProperty
*)property
);
604 if ( (property
->GetFlags() & flags
) != flags
)
605 targetArr
->push_back((wxPGProperty
*)property
);
610 // -----------------------------------------------------------------------
612 void wxPropertyGridInterface::SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
613 wxPGProperty::FlagType flags
,
618 for ( i
=0; i
<srcArr
.size(); i
++ )
620 wxPGProperty
* property
= srcArr
[i
];
623 property
->SetFlag(flags
);
625 property
->ClearFlag(flags
);
628 // If collapsed flag or hidden was manipulated, we need to update virtual
630 wxPropertyGrid
* pg
= GetPropertyGrid();
631 if ( flags
& (wxPG_PROP_COLLAPSED
|wxPG_PROP_HIDDEN
) )
633 GetState()->VirtualHeightChanged();
634 pg
->RecalculateVirtualSize();
638 // -----------------------------------------------------------------------
640 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
641 const wxString
& falseChoice
)
643 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
644 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
647 // -----------------------------------------------------------------------
649 wxPGChoices gs_emptyChoices
;
651 wxPGChoices
& wxPropertyGridInterface::GetPropertyChoices( wxPGPropArg id
)
653 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(gs_emptyChoices
)
656 ci
.m_choices
= (wxPGChoices
*) NULL
;
658 p
->GetChoiceInfo(&ci
);
661 return gs_emptyChoices
;
663 return *ci
.m_choices
;
666 // -----------------------------------------------------------------------
668 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
670 return m_pState
->BaseGetPropertyByName(name
);
673 // -----------------------------------------------------------------------
675 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
676 const wxString
& subname
) const
678 wxPGProperty
* p
= DoGetPropertyByName(name
);
679 if ( !p
|| !p
->GetChildCount() )
680 return wxNullProperty
;
682 return p
->GetPropertyByName(subname
);
685 // -----------------------------------------------------------------------
687 // Since GetPropertyByName is used *a lot*, this makes sense
688 // since non-virtual method can be called with less code.
689 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
691 wxPGProperty
* p
= DoGetPropertyByName(name
);
695 // Check if its "Property.SubProperty" format
696 int pos
= name
.Find(wxT('.'));
700 return GetPropertyByName(name
.substr(0,pos
),
701 name
.substr(pos
+1,name
.length()-pos
-1));
704 // -----------------------------------------------------------------------
706 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
708 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
710 wxPropertyGrid
* pg
= m_pState
->GetGrid();
712 if ( pg
== p
->GetGrid() )
713 return pg
->DoHideProperty(p
, hide
, flags
);
715 m_pState
->DoHideProperty(p
, hide
, flags
);
720 // -----------------------------------------------------------------------
722 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
724 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
725 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
727 return pg
->DoCollapse(p
);
729 return p
->GetParentState()->DoCollapse(p
);
732 // -----------------------------------------------------------------------
734 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
736 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
737 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
739 return pg
->DoExpand(p
);
741 return p
->GetParentState()->DoExpand(p
);
744 // -----------------------------------------------------------------------
746 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
748 wxPG_PROP_ARG_CALL_PROLOG()
750 p
->SetLabel( newproplabel
);
752 wxPropertyGridPageState
* state
= p
->GetParentState();
753 wxPropertyGrid
* pg
= state
->GetGrid();
755 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
756 pg
->SortChildren(p
->GetParent());
758 if ( pg
->GetState() == state
)
760 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
767 // -----------------------------------------------------------------------
769 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
771 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
773 wxPropertyGrid
* pg
= m_pState
->GetGrid();
775 p
->m_maxLen
= (short) maxLen
;
777 // Adjust control if selected currently
778 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
780 wxWindow
* wnd
= pg
->GetEditorControl();
781 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
783 tc
->SetMaxLength( maxLen
);
792 // -----------------------------------------------------------------------
793 // GetPropertyValueAsXXX methods
795 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
796 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
798 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
799 wxVariant value = p->GetValue(); \
800 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
802 wxPGGetFailed(p,wxPGTypeName_##T); \
803 return (TRET)DEFRETVAL; \
805 return (TRET)value.Get##BIGNAME(); \
808 // String is different than others.
809 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
811 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
812 return p
->GetValueAsString(wxPG_FULL_VALUE
);
815 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
817 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
818 wxVariant value
= p
->GetValue();
819 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
821 return value
.GetBool();
823 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
825 return value
.GetLong()?true:false;
827 wxPGGetFailed(p
,wxPGTypeName_bool
);
831 IMPLEMENT_GET_VALUE(long,long,Long
,0)
832 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
833 IMPLEMENT_GET_VALUE(void,void*,VoidPtr
,NULL
)
835 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
837 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
838 return p
->IsExpanded();
841 // -----------------------------------------------------------------------
842 // wxPropertyGridInterface wrappers
843 // -----------------------------------------------------------------------
845 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
847 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
850 // -----------------------------------------------------------------------
852 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
854 wxPG_PROP_ARG_CALL_PROLOG()
855 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
856 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
857 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
860 // -----------------------------------------------------------------------
862 bool wxPropertyGridInterface::EditorValidate()
864 return GetPropertyGrid()->DoEditorValidate();
867 // -----------------------------------------------------------------------
869 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
871 wxPG_PROP_ARG_CALL_PROLOG()
872 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
873 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
874 p
->SetFlag(wxPG_PROP_AGGREGATE
);
877 // -----------------------------------------------------------------------
878 // wxPGVIterator_State
879 // -----------------------------------------------------------------------
881 // Default returned by wxPropertyGridInterface::GetVIterator().
882 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
885 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
887 m_it
.Init( state
, flags
);
889 virtual ~wxPGVIteratorBase_State() { }
890 virtual void Next() { m_it
.Next(); }
893 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
895 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
898 // -----------------------------------------------------------------------
899 // wxPGEditableState related functions
900 // -----------------------------------------------------------------------
902 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
903 // in the input string. This is an internal functions which is
904 // used for saving states
905 // NB: Similar function exists in aui/framemanager.cpp
906 static wxString
EscapeDelimiters(const wxString
& s
)
909 result
.Alloc(s
.length());
910 const wxChar
* ch
= s
.c_str();
913 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
921 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
926 // Save state on page basis
927 size_t pageIndex
= 0;
928 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
929 wxArrayPtrVoid pageStates
;
932 pageStates
.Add(pageState
);
934 pageState
= GetPageState(pageIndex
);
937 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
939 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
941 if ( includedStates
& SelectionState
)
944 if ( pageState
->GetSelection() )
945 sel
= pageState
->GetSelection()->GetName();
946 result
+= wxS("selection=");
947 result
+= EscapeDelimiters(sel
);
950 if ( includedStates
& ExpandedState
)
952 wxArrayPGProperty ptrs
;
953 wxPropertyGridConstIterator it
=
954 wxPropertyGridConstIterator( pageState
,
955 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
958 result
+= wxS("expanded=");
964 const wxPGProperty
* p
= it
.GetProperty();
966 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
967 result
+= EscapeDelimiters(p
->GetName());
972 if ( result
.Last() == wxS(',') )
977 if ( includedStates
& ScrollPosState
)
980 GetPropertyGrid()->GetViewStart(&x
,&y
);
981 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
983 if ( includedStates
& SplitterPosState
)
985 result
+= wxS("splitterpos=");
987 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
988 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
990 result
.RemoveLast(); // Remove last comma
993 if ( includedStates
& PageState
)
995 result
+= wxS("ispageselected=");
997 if ( GetPageState(-1) == pageState
)
1000 result
+= wxS("0;");
1002 result
.RemoveLast(); // Remove last semicolon
1007 if ( result
.length() )
1008 result
.RemoveLast();
1013 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
1015 wxPropertyGrid
* pg
= GetPropertyGrid();
1016 wxPGProperty
* newSelection
= NULL
;
1020 long selectedPage
= -1;
1021 bool pgSelectionSet
= false;
1025 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
1027 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
1029 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1033 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
1035 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
1037 const wxString
& kvs
= kvpairStrings
[i
];
1038 int eq_pos
= kvs
.Find(wxS('='));
1039 if ( eq_pos
!= wxNOT_FOUND
)
1041 wxString key
= kvs
.substr(0, eq_pos
);
1042 wxString value
= kvs
.substr(eq_pos
+1);
1044 // Further split value by commas
1045 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
1047 if ( key
== wxS("expanded") )
1049 if ( restoreStates
& ExpandedState
)
1051 wxPropertyGridIterator it
=
1052 wxPropertyGridIterator( pageState
,
1056 // First collapse all
1057 for ( ; !it
.AtEnd(); it
.Next() )
1059 wxPGProperty
* p
= it
.GetProperty();
1060 pageState
->DoCollapse(p
);
1063 // Then expand those which names are in values
1064 for ( size_t n
=0; n
<values
.size(); n
++ )
1066 const wxString
& name
= values
[n
];
1067 wxPGProperty
* prop
= GetPropertyByName(name
);
1069 pageState
->DoExpand(prop
);
1073 else if ( key
== wxS("scrollpos") )
1075 if ( restoreStates
& ScrollPosState
)
1077 if ( values
.size() == 2 )
1079 values
[0].ToLong(&vx
);
1080 values
[1].ToLong(&vy
);
1088 else if ( key
== wxS("splitterpos") )
1090 if ( restoreStates
& SplitterPosState
)
1092 for ( size_t n
=1; n
<values
.size(); n
++ )
1095 values
[n
].ToLong(&pos
);
1097 pageState
->DoSetSplitterPosition(pos
, n
);
1101 else if ( key
== wxS("selection") )
1103 if ( restoreStates
& SelectionState
)
1105 if ( values
.size() > 0 )
1107 if ( pageState
->IsDisplayed() )
1109 if ( values
[0].length() )
1110 newSelection
= GetPropertyByName(value
);
1111 pgSelectionSet
= true;
1115 if ( values
[0].length() )
1116 pageState
->SetSelection(GetPropertyByName(value
));
1118 pageState
->DoClearSelection();
1123 else if ( key
== wxS("ispageselected") )
1125 if ( restoreStates
& PageState
)
1128 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1130 if ( pageSelStatus
)
1131 selectedPage
= pageIndex
;
1148 // Force recalculation of virtual heights of all pages
1149 // (may be needed on unclean source string).
1151 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1154 pageState
->VirtualHeightChanged();
1156 pageState
= GetPageState(pageIndex
);
1162 // Selection of visible grid page must be set after Thaw() call
1163 if ( pgSelectionSet
)
1166 pg
->SelectProperty(newSelection
);
1168 pg
->ClearSelection();
1171 if ( selectedPage
!= -1 )
1173 DoSelectPage(selectedPage
);
1184 #endif // wxUSE_PROPGRID