1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgridiface.cpp
3 // Purpose: wxPropertyGridInterface class
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/settings.h"
40 #include <wx/propgrid/property.h>
41 #include <wx/propgrid/propgrid.h>
44 const wxChar
*wxPGTypeName_long
= wxT("long");
45 const wxChar
*wxPGTypeName_bool
= wxT("bool");
46 const wxChar
*wxPGTypeName_double
= wxT("double");
47 const wxChar
*wxPGTypeName_wxString
= wxT("string");
48 const wxChar
*wxPGTypeName_void
= wxT("void*");
49 const wxChar
*wxPGTypeName_wxArrayString
= wxT("arrstring");
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxPoint
, WXDLLIMPEXP_PROPGRID
)
57 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxSize
, WXDLLIMPEXP_PROPGRID
)
58 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(wxArrayInt
, WXDLLIMPEXP_PROPGRID
)
60 // For wxLongLong and wxULongLong have custom classname << variant
61 // implementation for improved flexibility.
62 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ_NO_GETTER(wxLongLong
, WXDLLIMPEXP_PROPGRID
)
63 WX_PG_IMPLEMENT_VARIANT_DATA_EQ(wxLongLong
, WXDLLIMPEXP_PROPGRID
)
64 WXDLLIMPEXP_PROPGRID wxLongLong
& operator << ( wxLongLong
&value
, const wxVariant
&variant
)
67 if ( !wxPGVariantToLongLong(variant
, &ll
) )
69 wxFAIL_MSG("Cannot convert to wxLongLong");
74 WXDLLIMPEXP_PROPGRID wxLongLong_t
& operator << ( wxLongLong_t
&value
, const wxVariant
&variant
)
76 if ( !wxPGVariantToLongLong(variant
, &value
) )
78 wxFAIL_MSG("Cannot convert to wxLongLong");
83 WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ_NO_GETTER(wxULongLong
, WXDLLIMPEXP_PROPGRID
)
84 WX_PG_IMPLEMENT_VARIANT_DATA_EQ(wxULongLong
, WXDLLIMPEXP_PROPGRID
)
85 WXDLLIMPEXP_PROPGRID wxULongLong
& operator << ( wxULongLong
&value
, const wxVariant
&variant
)
88 if ( !wxPGVariantToULongLong(variant
, &ull
) )
90 wxFAIL_MSG("Cannot convert to wxULongLong");
95 WXDLLIMPEXP_PROPGRID wxULongLong_t
& operator << ( wxULongLong_t
&value
, const wxVariant
&variant
)
97 if ( !wxPGVariantToULongLong(variant
, &value
) )
99 wxFAIL_MSG("Cannot convert to wxULongLong");
104 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxFont
, WXDLLIMPEXP_PROPGRID
)
106 // -----------------------------------------------------------------------
108 // -----------------------------------------------------------------------
110 long wxPGVariantToInt( const wxVariant
& variant
, long defVal
)
112 if ( variant
.IsNull() )
115 if ( variant
.GetType() == wxS("long") )
116 return variant
.GetLong();
118 if ( variant
.GetType() == wxS("bool") )
119 return variant
.GetBool() ? 1 : 0;
121 if ( variant
.GetType() == wxS("wxLongLong") )
125 if ( ll
>= LONG_MAX
)
127 else if ( ll
<= LONG_MIN
)
134 if ( variant
.GetType() == wxPG_VARIANT_TYPE_STRING
)
135 variant
.GetString().ToLong(&l
, 0);
140 // -----------------------------------------------------------------------
142 bool wxPGVariantToLongLong( const wxVariant
& variant
, wxLongLong_t
* pResult
)
144 if ( variant
.IsNull() )
147 wxString variantType
= variant
.GetType();
149 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
151 *pResult
= variant
.GetLong();
155 if ( variantType
== wxLongLong_VariantType
)
157 // NOTE: << operator uses this functions, so we can't use it here
158 *pResult
= wxLongLongRefFromVariant(variant
).GetValue();
165 // -----------------------------------------------------------------------
167 bool wxPGVariantToULongLong( const wxVariant
& variant
, wxULongLong_t
* pResult
)
169 if ( variant
.IsNull() )
172 wxString variantType
= variant
.GetType();
174 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
176 *pResult
= (unsigned long)variant
.GetLong();
180 if ( variantType
== wxULongLong_VariantType
)
182 // NOTE: << operator uses this functions, so we can't use it here
183 *pResult
= wxULongLongRefFromVariant(variant
).GetValue();
190 // -----------------------------------------------------------------------
192 bool wxPGVariantToDouble( const wxVariant
& variant
, double* pResult
)
194 if ( variant
.IsNull() )
197 wxString variantType
= variant
.GetType();
199 if ( variantType
== wxPG_VARIANT_TYPE_DOUBLE
)
201 *pResult
= variant
.GetDouble();
205 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
207 *pResult
= (double)variant
.GetLong();
211 if ( variantType
== wxLongLong_VariantType
)
215 *pResult
= ll
.ToDouble();
219 if ( variantType
== wxPG_VARIANT_TYPE_STRING
)
220 if ( variant
.GetString().ToDouble(pResult
) )
226 // -----------------------------------------------------------------------
228 // -----------------------------------------------------------------------
230 wxPGProperty
* wxPGPropArgCls::GetPtr( wxPropertyGridInterface
* iface
) const
232 if ( m_flags
== IsProperty
)
234 wxASSERT_MSG( m_ptr
.property
, wxT("invalid property ptr") );
235 return m_ptr
.property
;
237 else if ( m_flags
& IsWxString
)
238 return iface
->GetPropertyByNameA(*m_ptr
.stringName
);
239 else if ( m_flags
& IsCharPtr
)
240 return iface
->GetPropertyByNameA(m_ptr
.charName
);
242 else if ( m_flags
& IsWCharPtr
)
243 return iface
->GetPropertyByNameA(m_ptr
.wcharName
);
249 // -----------------------------------------------------------------------
250 // wxPropertyGridInterface
251 // -----------------------------------------------------------------------
253 void wxPropertyGridInterface::RefreshGrid( wxPropertyGridPageState
* state
)
258 wxPropertyGrid
* grid
= state
->GetGrid();
259 if ( grid
->GetState() == state
&& !grid
->IsFrozen() )
265 // -----------------------------------------------------------------------
267 wxPGProperty
* wxPropertyGridInterface::Append( wxPGProperty
* property
)
269 wxPGProperty
* retp
= m_pState
->DoAppend(property
);
271 wxPropertyGrid
* grid
= m_pState
->GetGrid();
278 // -----------------------------------------------------------------------
280 wxPGProperty
* wxPropertyGridInterface::AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
)
282 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
283 wxPGProperty
* pwc
= (wxPGProperty
*) p
;
284 wxPGProperty
* retp
= m_pState
->DoInsert(pwc
, pwc
->GetChildCount(), newproperty
);
288 // -----------------------------------------------------------------------
290 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, wxPGProperty
* property
)
292 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
293 wxPGProperty
* retp
= m_pState
->DoInsert(p
->GetParent(), p
->GetIndexInParent(), property
);
298 // -----------------------------------------------------------------------
300 wxPGProperty
* wxPropertyGridInterface::Insert( wxPGPropArg id
, int index
, wxPGProperty
* newproperty
)
302 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
303 wxPGProperty
* retp
= m_pState
->DoInsert((wxPGProperty
*)p
,index
,newproperty
);
308 // -----------------------------------------------------------------------
310 void wxPropertyGridInterface::DeleteProperty( wxPGPropArg id
)
312 wxPG_PROP_ARG_CALL_PROLOG()
314 wxPropertyGridPageState
* state
= p
->GetParentState();
315 wxPropertyGrid
* grid
= state
->GetGrid();
317 if ( grid
->GetState() == state
)
319 bool selRes
= grid
->DoSelectProperty(NULL
, wxPG_SEL_DELETING
);
320 wxPG_CHECK_RET_DBG( selRes
,
321 wxT("failed to deselect a property (editor probably had invalid value)") );
324 state
->DoDelete( p
);
329 // -----------------------------------------------------------------------
331 wxPGProperty
* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
333 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
335 wxPGProperty
* replaced
= p
;
336 wxCHECK_MSG( replaced
&& property
,
338 wxT("NULL property") );
339 wxCHECK_MSG( !replaced
->IsCategory(),
341 wxT("cannot replace this type of property") );
342 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
344 wxT("cannot replace properties in alphabetic mode") );
346 // Get address to the slot
347 wxPGProperty
* parent
= replaced
->GetParent();
348 int ind
= replaced
->GetIndexInParent();
350 wxPropertyGridPageState
* state
= replaced
->GetParentState();
351 DeleteProperty(replaced
); // Must use generic Delete
352 state
->DoInsert(parent
,ind
,property
);
357 // -----------------------------------------------------------------------
358 // wxPropertyGridInterface property operations
359 // -----------------------------------------------------------------------
361 bool wxPropertyGridInterface::ClearSelection()
363 wxPropertyGridPageState
* state
= m_pState
;
364 wxPropertyGrid
* pg
= state
->GetGrid();
365 if ( pg
->GetState() == state
)
366 return pg
->DoClearSelection();
368 state
->SetSelection(NULL
);
372 // -----------------------------------------------------------------------
374 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
376 wxPG_PROP_ARG_CALL_PROLOG()
378 m_pState
->DoLimitPropertyEditing(p
, limit
);
382 // -----------------------------------------------------------------------
384 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
386 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
388 wxPropertyGridPageState
* state
= p
->GetParentState();
389 wxPropertyGrid
* grid
= state
->GetGrid();
393 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
396 // If active, Set active Editor.
397 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
398 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
402 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
405 // If active, Disable as active Editor.
406 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
407 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
410 state
->DoEnableProperty(p
, enable
);
412 RefreshProperty( p
);
417 // -----------------------------------------------------------------------
419 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
421 wxPropertyGridPageState
* state
= m_pState
;
423 if ( !state
->DoGetRoot()->GetChildCount() )
426 wxPropertyGrid
* pg
= state
->GetGrid();
428 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
431 if ( !pg
->ClearSelection() )
437 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
439 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
440 if ( p
->GetChildCount() )
444 if ( !p
->IsExpanded() )
451 if ( p
->IsExpanded() )
453 state
->DoCollapse(p
);
459 pg
->RecalculateVirtualSize();
466 // -----------------------------------------------------------------------
468 void wxPropertyGridInterface::SetPropertyValueUnspecified( wxPGPropArg id
)
470 wxPG_PROP_ARG_CALL_PROLOG()
471 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
473 propGrid
->DoSetPropertyValueUnspecified(p
);
475 p
->GetParentState()->DoSetPropertyValueUnspecified(p
);
478 // -----------------------------------------------------------------------
480 void wxPropertyGridInterface::ClearModifiedStatus()
482 unsigned int pageIndex
= 0;
486 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
489 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
495 // -----------------------------------------------------------------------
496 // wxPropertyGridInterface property value setting and getting
497 // -----------------------------------------------------------------------
499 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
501 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
504 // -----------------------------------------------------------------------
506 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
507 const wxString
& typestr
,
510 wxASSERT( p
!= NULL
);
511 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
512 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
515 // -----------------------------------------------------------------------
517 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
519 wxPG_PROP_ARG_CALL_PROLOG()
524 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
526 propGrid
->DrawItemAndValueRelated( p
);
531 // -----------------------------------------------------------------------
533 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
535 wxPG_PROP_ARG_CALL_PROLOG()
537 if ( m_pState
->DoSetPropertyValueString(p
,value
) )
539 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
541 propGrid
->DrawItemAndValueRelated( p
);
545 // -----------------------------------------------------------------------
547 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
549 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
552 // -----------------------------------------------------------------------
554 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
556 wxPGProperty
* p
= GetPropertyByName(name
);
557 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
561 // ----------------------------------------------------------------------------
563 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
567 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
569 if ( it
.GetProperty()->GetLabel() == label
)
570 return it
.GetProperty();
573 return wxNullProperty
;
576 // ----------------------------------------------------------------------------
578 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
579 wxVariant
& value
, long argFlags
)
581 wxPG_PROP_ARG_CALL_PROLOG()
583 p
->SetAttribute( name
, value
);
585 if ( argFlags
& wxPG_RECURSE
)
588 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
589 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
593 // -----------------------------------------------------------------------
595 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
598 unsigned int pageIndex
= 0;
602 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
605 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
611 // -----------------------------------------------------------------------
613 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
614 wxPGProperty::FlagType flags
,
616 int iterFlags
) const
618 wxASSERT( targetArr
);
619 wxPGVIterator it
= GetVIterator( iterFlags
);
625 const wxPGProperty
* property
= it
.GetProperty();
629 if ( (property
->GetFlags() & flags
) == flags
)
630 targetArr
->push_back((wxPGProperty
*)property
);
634 if ( (property
->GetFlags() & flags
) != flags
)
635 targetArr
->push_back((wxPGProperty
*)property
);
640 // -----------------------------------------------------------------------
642 void wxPropertyGridInterface::SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
643 wxPGProperty::FlagType flags
,
648 for ( i
=0; i
<srcArr
.size(); i
++ )
650 wxPGProperty
* property
= srcArr
[i
];
653 property
->SetFlag(flags
);
655 property
->ClearFlag(flags
);
658 // If collapsed flag or hidden was manipulated, we need to update virtual
660 wxPropertyGrid
* pg
= GetPropertyGrid();
661 if ( flags
& (wxPG_PROP_COLLAPSED
|wxPG_PROP_HIDDEN
) )
663 GetState()->VirtualHeightChanged();
664 pg
->RecalculateVirtualSize();
668 // -----------------------------------------------------------------------
670 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
671 const wxString
& falseChoice
)
673 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
674 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
677 // -----------------------------------------------------------------------
679 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
681 return m_pState
->BaseGetPropertyByName(name
);
684 // -----------------------------------------------------------------------
686 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
687 const wxString
& subname
) const
689 wxPGProperty
* p
= DoGetPropertyByName(name
);
690 if ( !p
|| !p
->GetChildCount() )
691 return wxNullProperty
;
693 return p
->GetPropertyByName(subname
);
696 // -----------------------------------------------------------------------
698 // Since GetPropertyByName is used *a lot*, this makes sense
699 // since non-virtual method can be called with less code.
700 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
702 wxPGProperty
* p
= DoGetPropertyByName(name
);
706 // Check if its "Property.SubProperty" format
707 int pos
= name
.Find(wxT('.'));
711 return GetPropertyByName(name
.substr(0,pos
),
712 name
.substr(pos
+1,name
.length()-pos
-1));
715 // -----------------------------------------------------------------------
717 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
719 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
721 wxPropertyGrid
* pg
= m_pState
->GetGrid();
723 if ( pg
== p
->GetGrid() )
724 return pg
->DoHideProperty(p
, hide
, flags
);
726 m_pState
->DoHideProperty(p
, hide
, flags
);
731 // -----------------------------------------------------------------------
733 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
735 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
736 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
738 return pg
->DoCollapse(p
);
740 return p
->GetParentState()->DoCollapse(p
);
743 // -----------------------------------------------------------------------
745 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
747 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
748 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
750 return pg
->DoExpand(p
);
752 return p
->GetParentState()->DoExpand(p
);
755 // -----------------------------------------------------------------------
757 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
759 wxPG_PROP_ARG_CALL_PROLOG()
761 p
->SetLabel( newproplabel
);
763 wxPropertyGridPageState
* state
= p
->GetParentState();
764 wxPropertyGrid
* pg
= state
->GetGrid();
766 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
767 pg
->SortChildren(p
->GetParent());
769 if ( pg
->GetState() == state
)
771 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
778 // -----------------------------------------------------------------------
780 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
782 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
784 wxPropertyGrid
* pg
= m_pState
->GetGrid();
786 p
->m_maxLen
= (short) maxLen
;
788 // Adjust control if selected currently
789 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
791 wxWindow
* wnd
= pg
->GetEditorControl();
792 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
794 tc
->SetMaxLength( maxLen
);
803 // -----------------------------------------------------------------------
804 // GetPropertyValueAsXXX methods
806 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
807 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
809 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
810 wxVariant value = p->GetValue(); \
811 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
813 wxPGGetFailed(p,wxPGTypeName_##T); \
814 return (TRET)DEFRETVAL; \
816 return (TRET)value.Get##BIGNAME(); \
819 // String is different than others.
820 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
822 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
823 return p
->GetValueAsString(wxPG_FULL_VALUE
);
826 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
828 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
829 wxVariant value
= p
->GetValue();
830 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
832 return value
.GetBool();
834 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
836 return value
.GetLong()?true:false;
838 wxPGGetFailed(p
,wxPGTypeName_bool
);
842 IMPLEMENT_GET_VALUE(long,long,Long
,0)
843 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
845 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
847 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
848 return p
->IsExpanded();
851 // -----------------------------------------------------------------------
852 // wxPropertyGridInterface wrappers
853 // -----------------------------------------------------------------------
855 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
857 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
860 // -----------------------------------------------------------------------
862 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
864 wxPG_PROP_ARG_CALL_PROLOG()
865 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
866 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
867 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
870 // -----------------------------------------------------------------------
872 bool wxPropertyGridInterface::EditorValidate()
874 return GetPropertyGrid()->DoEditorValidate();
877 // -----------------------------------------------------------------------
879 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
881 wxPG_PROP_ARG_CALL_PROLOG()
882 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
883 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
884 p
->SetFlag(wxPG_PROP_AGGREGATE
);
887 // -----------------------------------------------------------------------
888 // wxPGVIterator_State
889 // -----------------------------------------------------------------------
891 // Default returned by wxPropertyGridInterface::GetVIterator().
892 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
895 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
897 m_it
.Init( state
, flags
);
899 virtual ~wxPGVIteratorBase_State() { }
900 virtual void Next() { m_it
.Next(); }
903 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
905 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
908 // -----------------------------------------------------------------------
909 // wxPGEditableState related functions
910 // -----------------------------------------------------------------------
912 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
913 // in the input string. This is an internal functions which is
914 // used for saving states
915 // NB: Similar function exists in aui/framemanager.cpp
916 static wxString
EscapeDelimiters(const wxString
& s
)
919 result
.Alloc(s
.length());
920 const wxChar
* ch
= s
.c_str();
923 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
931 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
936 // Save state on page basis
937 unsigned int pageIndex
= 0;
938 wxArrayPtrVoid pageStates
;
942 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
945 pageStates
.Add(page
);
950 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
952 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
954 if ( includedStates
& SelectionState
)
957 if ( pageState
->GetSelection() )
958 sel
= pageState
->GetSelection()->GetName();
959 result
+= wxS("selection=");
960 result
+= EscapeDelimiters(sel
);
963 if ( includedStates
& ExpandedState
)
965 wxArrayPGProperty ptrs
;
966 wxPropertyGridConstIterator it
=
967 wxPropertyGridConstIterator( pageState
,
968 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
971 result
+= wxS("expanded=");
977 const wxPGProperty
* p
= it
.GetProperty();
979 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
980 result
+= EscapeDelimiters(p
->GetName());
985 if ( result
.Last() == wxS(',') )
990 if ( includedStates
& ScrollPosState
)
993 GetPropertyGrid()->GetViewStart(&x
,&y
);
994 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
996 if ( includedStates
& SplitterPosState
)
998 result
+= wxS("splitterpos=");
1000 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
1001 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
1003 result
.RemoveLast(); // Remove last comma
1006 if ( includedStates
& PageState
)
1008 result
+= wxS("ispageselected=");
1010 if ( GetPageState(-1) == pageState
)
1011 result
+= wxS("1;");
1013 result
+= wxS("0;");
1015 result
.RemoveLast(); // Remove last semicolon
1020 if ( result
.length() )
1021 result
.RemoveLast();
1026 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
1028 wxPropertyGrid
* pg
= GetPropertyGrid();
1029 wxPGProperty
* newSelection
= NULL
;
1033 long selectedPage
= -1;
1034 bool pgSelectionSet
= false;
1038 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
1040 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
1042 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1046 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
1048 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
1050 const wxString
& kvs
= kvpairStrings
[i
];
1051 int eq_pos
= kvs
.Find(wxS('='));
1052 if ( eq_pos
!= wxNOT_FOUND
)
1054 wxString key
= kvs
.substr(0, eq_pos
);
1055 wxString value
= kvs
.substr(eq_pos
+1);
1057 // Further split value by commas
1058 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
1060 if ( key
== wxS("expanded") )
1062 if ( restoreStates
& ExpandedState
)
1064 wxPropertyGridIterator it
=
1065 wxPropertyGridIterator( pageState
,
1069 // First collapse all
1070 for ( ; !it
.AtEnd(); it
.Next() )
1072 wxPGProperty
* p
= it
.GetProperty();
1073 pageState
->DoCollapse(p
);
1076 // Then expand those which names are in values
1077 for ( size_t n
=0; n
<values
.size(); n
++ )
1079 const wxString
& name
= values
[n
];
1080 wxPGProperty
* prop
= GetPropertyByName(name
);
1082 pageState
->DoExpand(prop
);
1086 else if ( key
== wxS("scrollpos") )
1088 if ( restoreStates
& ScrollPosState
)
1090 if ( values
.size() == 2 )
1092 values
[0].ToLong(&vx
);
1093 values
[1].ToLong(&vy
);
1101 else if ( key
== wxS("splitterpos") )
1103 if ( restoreStates
& SplitterPosState
)
1105 for ( size_t n
=1; n
<values
.size(); n
++ )
1108 values
[n
].ToLong(&pos
);
1110 pageState
->DoSetSplitterPosition(pos
, n
);
1114 else if ( key
== wxS("selection") )
1116 if ( restoreStates
& SelectionState
)
1118 if ( values
.size() > 0 )
1120 if ( pageState
->IsDisplayed() )
1122 if ( values
[0].length() )
1123 newSelection
= GetPropertyByName(value
);
1124 pgSelectionSet
= true;
1128 if ( values
[0].length() )
1129 pageState
->SetSelection(GetPropertyByName(value
));
1131 pageState
->DoClearSelection();
1136 else if ( key
== wxS("ispageselected") )
1138 if ( restoreStates
& PageState
)
1141 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1143 if ( pageSelStatus
)
1144 selectedPage
= pageIndex
;
1161 // Force recalculation of virtual heights of all pages
1162 // (may be needed on unclean source string).
1164 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1167 pageState
->VirtualHeightChanged();
1169 pageState
= GetPageState(pageIndex
);
1175 // Selection of visible grid page must be set after Thaw() call
1176 if ( pgSelectionSet
)
1179 pg
->SelectProperty(newSelection
);
1181 pg
->ClearSelection();
1184 if ( selectedPage
!= -1 )
1186 DoSelectPage(selectedPage
);
1197 #endif // wxUSE_PROPGRID