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
)
318 grid
->DoSelectProperty(NULL
, wxPG_SEL_DELETING
|wxPG_SEL_NOVALIDATE
);
320 state
->DoDelete( p
, true );
325 // -----------------------------------------------------------------------
327 wxPGProperty
* wxPropertyGridInterface::RemoveProperty( wxPGPropArg id
)
329 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
331 wxCHECK( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
),
334 wxPropertyGridPageState
* state
= p
->GetParentState();
335 wxPropertyGrid
* grid
= state
->GetGrid();
337 if ( grid
->GetState() == state
)
339 grid
->DoSelectProperty(NULL
,
340 wxPG_SEL_DELETING
|wxPG_SEL_NOVALIDATE
);
343 state
->DoDelete( p
, false );
345 // Mark the property as 'unattached'
346 p
->m_parentState
= NULL
;
354 // -----------------------------------------------------------------------
356 wxPGProperty
* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
358 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
360 wxPGProperty
* replaced
= p
;
361 wxCHECK_MSG( replaced
&& property
,
363 wxT("NULL property") );
364 wxCHECK_MSG( !replaced
->IsCategory(),
366 wxT("cannot replace this type of property") );
367 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
369 wxT("cannot replace properties in alphabetic mode") );
371 // Get address to the slot
372 wxPGProperty
* parent
= replaced
->GetParent();
373 int ind
= replaced
->GetIndexInParent();
375 wxPropertyGridPageState
* state
= replaced
->GetParentState();
376 DeleteProperty(replaced
); // Must use generic Delete
377 state
->DoInsert(parent
,ind
,property
);
382 // -----------------------------------------------------------------------
383 // wxPropertyGridInterface property operations
384 // -----------------------------------------------------------------------
386 bool wxPropertyGridInterface::ClearSelection( bool validation
)
390 flags
|= wxPG_SEL_NOVALIDATE
;
392 wxPropertyGridPageState
* state
= m_pState
;
396 wxPropertyGrid
* pg
= state
->GetGrid();
397 if ( pg
->GetState() == state
)
398 return pg
->DoSelectProperty(NULL
, flags
);
400 state
->SetSelection(NULL
);
406 // -----------------------------------------------------------------------
408 void wxPropertyGridInterface::LimitPropertyEditing( wxPGPropArg id
, bool limit
)
410 wxPG_PROP_ARG_CALL_PROLOG()
412 m_pState
->DoLimitPropertyEditing(p
, limit
);
416 // -----------------------------------------------------------------------
418 bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id
, bool enable
)
420 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
422 wxPropertyGridPageState
* state
= p
->GetParentState();
423 wxPropertyGrid
* grid
= state
->GetGrid();
427 if ( !(p
->m_flags
& wxPG_PROP_DISABLED
) )
430 // If active, Set active Editor.
431 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
432 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
436 if ( p
->m_flags
& wxPG_PROP_DISABLED
)
439 // If active, Disable as active Editor.
440 if ( grid
->GetState() == state
&& p
== grid
->GetSelection() )
441 grid
->DoSelectProperty( p
, wxPG_SEL_FORCE
);
444 state
->DoEnableProperty(p
, enable
);
446 RefreshProperty( p
);
451 // -----------------------------------------------------------------------
453 bool wxPropertyGridInterface::ExpandAll( bool doExpand
)
455 wxPropertyGridPageState
* state
= m_pState
;
457 if ( !state
->DoGetRoot()->GetChildCount() )
460 wxPropertyGrid
* pg
= state
->GetGrid();
462 if ( GetSelection() && GetSelection() != state
->DoGetRoot() &&
465 pg
->ClearSelection(false);
470 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
472 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
473 if ( p
->GetChildCount() )
477 if ( !p
->IsExpanded() )
484 if ( p
->IsExpanded() )
486 state
->DoCollapse(p
);
492 pg
->RecalculateVirtualSize();
499 // -----------------------------------------------------------------------
501 void wxPropertyGridInterface::SetPropertyValueUnspecified( wxPGPropArg id
)
503 wxPG_PROP_ARG_CALL_PROLOG()
504 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
506 propGrid
->DoSetPropertyValueUnspecified(p
);
508 p
->GetParentState()->DoSetPropertyValueUnspecified(p
);
511 // -----------------------------------------------------------------------
513 void wxPropertyGridInterface::ClearModifiedStatus()
515 unsigned int pageIndex
= 0;
519 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
522 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
527 // Update active editor control, if any
528 GetPropertyGrid()->RefreshEditor();
531 // -----------------------------------------------------------------------
532 // wxPropertyGridInterface property value setting and getting
533 // -----------------------------------------------------------------------
535 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
537 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
540 // -----------------------------------------------------------------------
542 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
543 const wxString
& typestr
,
546 wxASSERT( p
!= NULL
);
547 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
548 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
551 // -----------------------------------------------------------------------
553 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
555 wxPG_PROP_ARG_CALL_PROLOG()
560 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
562 propGrid
->DrawItemAndValueRelated( p
);
567 // -----------------------------------------------------------------------
569 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
571 wxPG_PROP_ARG_CALL_PROLOG()
573 if ( m_pState
->DoSetPropertyValueString(p
,value
) )
575 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
577 propGrid
->DrawItemAndValueRelated( p
);
581 // -----------------------------------------------------------------------
583 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
585 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
588 // -----------------------------------------------------------------------
590 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
592 wxPGProperty
* p
= GetPropertyByName(name
);
593 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
597 // ----------------------------------------------------------------------------
599 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
603 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
605 if ( it
.GetProperty()->GetLabel() == label
)
606 return it
.GetProperty();
609 return wxNullProperty
;
612 // ----------------------------------------------------------------------------
614 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
615 wxVariant
& value
, long argFlags
)
617 wxPG_PROP_ARG_CALL_PROLOG()
619 p
->SetAttribute( name
, value
);
621 if ( argFlags
& wxPG_RECURSE
)
624 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
625 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
629 // -----------------------------------------------------------------------
631 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
634 unsigned int pageIndex
= 0;
638 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
641 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
647 // -----------------------------------------------------------------------
649 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
650 wxPGProperty::FlagType flags
,
652 int iterFlags
) const
654 wxASSERT( targetArr
);
655 wxPGVIterator it
= GetVIterator( iterFlags
);
661 const wxPGProperty
* property
= it
.GetProperty();
665 if ( (property
->GetFlags() & flags
) == flags
)
666 targetArr
->push_back((wxPGProperty
*)property
);
670 if ( (property
->GetFlags() & flags
) != flags
)
671 targetArr
->push_back((wxPGProperty
*)property
);
676 // -----------------------------------------------------------------------
678 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
679 const wxString
& falseChoice
)
681 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
682 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
685 // -----------------------------------------------------------------------
687 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
689 return m_pState
->BaseGetPropertyByName(name
);
692 // -----------------------------------------------------------------------
694 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
695 const wxString
& subname
) const
697 wxPGProperty
* p
= DoGetPropertyByName(name
);
698 if ( !p
|| !p
->GetChildCount() )
699 return wxNullProperty
;
701 return p
->GetPropertyByName(subname
);
704 // -----------------------------------------------------------------------
706 // Since GetPropertyByName is used *a lot*, this makes sense
707 // since non-virtual method can be called with less code.
708 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
710 wxPGProperty
* p
= DoGetPropertyByName(name
);
714 // Check if its "Property.SubProperty" format
715 int pos
= name
.Find(wxT('.'));
719 return GetPropertyByName(name
.substr(0,pos
),
720 name
.substr(pos
+1,name
.length()-pos
-1));
723 // -----------------------------------------------------------------------
725 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
727 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
729 wxPropertyGrid
* pg
= m_pState
->GetGrid();
731 if ( pg
== p
->GetGrid() )
732 return pg
->DoHideProperty(p
, hide
, flags
);
734 m_pState
->DoHideProperty(p
, hide
, flags
);
739 // -----------------------------------------------------------------------
741 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
743 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
744 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
746 return pg
->DoCollapse(p
);
748 return p
->GetParentState()->DoCollapse(p
);
751 // -----------------------------------------------------------------------
753 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
755 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
756 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
758 return pg
->DoExpand(p
);
760 return p
->GetParentState()->DoExpand(p
);
763 // -----------------------------------------------------------------------
765 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
767 wxPG_PROP_ARG_CALL_PROLOG()
769 p
->SetLabel( newproplabel
);
771 wxPropertyGridPageState
* state
= p
->GetParentState();
772 wxPropertyGrid
* pg
= state
->GetGrid();
774 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
775 pg
->SortChildren(p
->GetParent());
777 if ( pg
->GetState() == state
)
779 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
786 // -----------------------------------------------------------------------
788 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
790 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
792 wxPropertyGrid
* pg
= m_pState
->GetGrid();
794 p
->m_maxLen
= (short) maxLen
;
796 // Adjust control if selected currently
797 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
799 wxWindow
* wnd
= pg
->GetEditorControl();
800 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
802 tc
->SetMaxLength( maxLen
);
811 // -----------------------------------------------------------------------
814 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
815 const wxColour
& colour
,
818 wxPG_PROP_ARG_CALL_PROLOG()
819 p
->SetBackgroundColour( colour
, recursively
);
820 RefreshProperty( p
);
823 // -----------------------------------------------------------------------
825 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
826 const wxColour
& colour
,
829 wxPG_PROP_ARG_CALL_PROLOG()
830 p
->SetTextColour( colour
, recursively
);
831 RefreshProperty( p
);
834 // -----------------------------------------------------------------------
836 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
838 wxPG_PROP_ARG_CALL_PROLOG()
843 // -----------------------------------------------------------------------
845 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
847 const wxString
& text
,
848 const wxBitmap
& bitmap
,
849 const wxColour
& fgCol
,
850 const wxColour
& bgCol
)
852 wxPG_PROP_ARG_CALL_PROLOG()
854 wxPGCell
& cell
= p
->GetCell(column
);
855 if ( text
.length() && text
!= wxPG_LABEL
)
858 cell
.SetBitmap(bitmap
);
859 if ( fgCol
!= wxNullColour
)
860 cell
.SetFgCol(fgCol
);
861 if ( bgCol
!= wxNullColour
)
862 cell
.SetBgCol(bgCol
);
865 // -----------------------------------------------------------------------
866 // GetPropertyValueAsXXX methods
868 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
869 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
871 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
872 wxVariant value = p->GetValue(); \
873 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
875 wxPGGetFailed(p,wxPGTypeName_##T); \
876 return (TRET)DEFRETVAL; \
878 return (TRET)value.Get##BIGNAME(); \
881 // String is different than others.
882 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
884 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
885 return p
->GetValueAsString(wxPG_FULL_VALUE
);
888 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
890 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
891 wxVariant value
= p
->GetValue();
892 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
894 return value
.GetBool();
896 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
898 return value
.GetLong()?true:false;
900 wxPGGetFailed(p
,wxPGTypeName_bool
);
904 IMPLEMENT_GET_VALUE(long,long,Long
,0)
905 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
907 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
909 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
910 return p
->IsExpanded();
913 // -----------------------------------------------------------------------
914 // wxPropertyGridInterface wrappers
915 // -----------------------------------------------------------------------
917 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
919 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
922 // -----------------------------------------------------------------------
924 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
926 wxPG_PROP_ARG_CALL_PROLOG()
927 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
928 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
929 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
932 // -----------------------------------------------------------------------
934 bool wxPropertyGridInterface::EditorValidate()
936 return GetPropertyGrid()->DoEditorValidate();
939 // -----------------------------------------------------------------------
941 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
943 wxPG_PROP_ARG_CALL_PROLOG()
944 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
945 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
946 p
->SetFlag(wxPG_PROP_AGGREGATE
);
949 // -----------------------------------------------------------------------
950 // wxPGVIterator_State
951 // -----------------------------------------------------------------------
953 // Default returned by wxPropertyGridInterface::GetVIterator().
954 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
957 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
959 m_it
.Init( state
, flags
);
961 virtual ~wxPGVIteratorBase_State() { }
962 virtual void Next() { m_it
.Next(); }
965 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
967 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
970 // -----------------------------------------------------------------------
971 // wxPGEditableState related functions
972 // -----------------------------------------------------------------------
974 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
975 // in the input string. This is an internal functions which is
976 // used for saving states
977 // NB: Similar function exists in aui/framemanager.cpp
978 static wxString
EscapeDelimiters(const wxString
& s
)
981 result
.Alloc(s
.length());
982 const wxChar
* ch
= s
.c_str();
985 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
993 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
998 // Save state on page basis
999 unsigned int pageIndex
= 0;
1000 wxArrayPtrVoid pageStates
;
1004 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
1007 pageStates
.Add(page
);
1012 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
1014 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
1016 if ( includedStates
& SelectionState
)
1019 if ( pageState
->GetSelection() )
1020 sel
= pageState
->GetSelection()->GetName();
1021 result
+= wxS("selection=");
1022 result
+= EscapeDelimiters(sel
);
1025 if ( includedStates
& ExpandedState
)
1027 wxArrayPGProperty ptrs
;
1028 wxPropertyGridConstIterator it
=
1029 wxPropertyGridConstIterator( pageState
,
1030 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
1033 result
+= wxS("expanded=");
1039 const wxPGProperty
* p
= it
.GetProperty();
1041 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
1042 result
+= EscapeDelimiters(p
->GetName());
1047 if ( result
.Last() == wxS(',') )
1048 result
.RemoveLast();
1052 if ( includedStates
& ScrollPosState
)
1055 GetPropertyGrid()->GetViewStart(&x
,&y
);
1056 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
1058 if ( includedStates
& SplitterPosState
)
1060 result
+= wxS("splitterpos=");
1062 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
1063 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
1065 result
.RemoveLast(); // Remove last comma
1068 if ( includedStates
& PageState
)
1070 result
+= wxS("ispageselected=");
1072 if ( GetPageState(-1) == pageState
)
1073 result
+= wxS("1;");
1075 result
+= wxS("0;");
1077 if ( includedStates
& DescBoxState
)
1079 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
1081 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
1083 result
.RemoveLast(); // Remove last semicolon
1088 if ( result
.length() )
1089 result
.RemoveLast();
1094 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
1096 wxPropertyGrid
* pg
= GetPropertyGrid();
1097 wxPGProperty
* newSelection
= NULL
;
1101 long selectedPage
= -1;
1102 bool pgSelectionSet
= false;
1106 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
1108 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
1110 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1114 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
1116 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
1118 const wxString
& kvs
= kvpairStrings
[i
];
1119 int eq_pos
= kvs
.Find(wxS('='));
1120 if ( eq_pos
!= wxNOT_FOUND
)
1122 wxString key
= kvs
.substr(0, eq_pos
);
1123 wxString value
= kvs
.substr(eq_pos
+1);
1125 // Further split value by commas
1126 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
1128 if ( key
== wxS("expanded") )
1130 if ( restoreStates
& ExpandedState
)
1132 wxPropertyGridIterator it
=
1133 wxPropertyGridIterator( pageState
,
1137 // First collapse all
1138 for ( ; !it
.AtEnd(); it
.Next() )
1140 wxPGProperty
* p
= it
.GetProperty();
1141 pageState
->DoCollapse(p
);
1144 // Then expand those which names are in values
1145 for ( size_t n
=0; n
<values
.size(); n
++ )
1147 const wxString
& name
= values
[n
];
1148 wxPGProperty
* prop
= GetPropertyByName(name
);
1150 pageState
->DoExpand(prop
);
1154 else if ( key
== wxS("scrollpos") )
1156 if ( restoreStates
& ScrollPosState
)
1158 if ( values
.size() == 2 )
1160 values
[0].ToLong(&vx
);
1161 values
[1].ToLong(&vy
);
1169 else if ( key
== wxS("splitterpos") )
1171 if ( restoreStates
& SplitterPosState
)
1173 for ( size_t n
=1; n
<values
.size(); n
++ )
1176 values
[n
].ToLong(&pos
);
1178 pageState
->DoSetSplitterPosition(pos
, n
);
1182 else if ( key
== wxS("selection") )
1184 if ( restoreStates
& SelectionState
)
1186 if ( values
.size() > 0 )
1188 if ( pageState
->IsDisplayed() )
1190 if ( values
[0].length() )
1191 newSelection
= GetPropertyByName(value
);
1192 pgSelectionSet
= true;
1196 if ( values
[0].length() )
1197 pageState
->SetSelection(GetPropertyByName(value
));
1199 pageState
->DoClearSelection();
1204 else if ( key
== wxS("ispageselected") )
1206 if ( restoreStates
& PageState
)
1209 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1211 if ( pageSelStatus
)
1212 selectedPage
= pageIndex
;
1220 else if ( key
== wxS("descboxheight") )
1222 if ( restoreStates
& DescBoxState
)
1225 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1227 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1244 // Force recalculation of virtual heights of all pages
1245 // (may be needed on unclean source string).
1247 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1250 pageState
->VirtualHeightChanged();
1252 pageState
= GetPageState(pageIndex
);
1258 // Selection of visible grid page must be set after Thaw() call
1259 if ( pgSelectionSet
)
1262 pg
->SelectProperty(newSelection
);
1264 pg
->ClearSelection();
1267 if ( selectedPage
!= -1 )
1269 DoSelectPage(selectedPage
);
1280 #endif // wxUSE_PROPGRID