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
);
325 // -----------------------------------------------------------------------
327 wxPGProperty
* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
)
329 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
331 wxPGProperty
* replaced
= p
;
332 wxCHECK_MSG( replaced
&& property
,
334 wxT("NULL property") );
335 wxCHECK_MSG( !replaced
->IsCategory(),
337 wxT("cannot replace this type of property") );
338 wxCHECK_MSG( !m_pState
->IsInNonCatMode(),
340 wxT("cannot replace properties in alphabetic mode") );
342 // Get address to the slot
343 wxPGProperty
* parent
= replaced
->GetParent();
344 int ind
= replaced
->GetIndexInParent();
346 wxPropertyGridPageState
* state
= replaced
->GetParentState();
347 DeleteProperty(replaced
); // Must use generic Delete
348 state
->DoInsert(parent
,ind
,property
);
353 // -----------------------------------------------------------------------
354 // wxPropertyGridInterface property operations
355 // -----------------------------------------------------------------------
357 bool wxPropertyGridInterface::ClearSelection( bool validation
)
361 flags
|= wxPG_SEL_NOVALIDATE
;
363 wxPropertyGridPageState
* state
= m_pState
;
367 wxPropertyGrid
* pg
= state
->GetGrid();
368 if ( pg
->GetState() == state
)
369 return pg
->DoSelectProperty(NULL
, flags
);
371 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 pg
->ClearSelection(false);
441 for ( it
= GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
443 wxPGProperty
* p
= (wxPGProperty
*) it
.GetProperty();
444 if ( p
->GetChildCount() )
448 if ( !p
->IsExpanded() )
455 if ( p
->IsExpanded() )
457 state
->DoCollapse(p
);
463 pg
->RecalculateVirtualSize();
470 // -----------------------------------------------------------------------
472 void wxPropertyGridInterface::SetPropertyValueUnspecified( wxPGPropArg id
)
474 wxPG_PROP_ARG_CALL_PROLOG()
475 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
477 propGrid
->DoSetPropertyValueUnspecified(p
);
479 p
->GetParentState()->DoSetPropertyValueUnspecified(p
);
482 // -----------------------------------------------------------------------
484 void wxPropertyGridInterface::ClearModifiedStatus()
486 unsigned int pageIndex
= 0;
490 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
493 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
499 // -----------------------------------------------------------------------
500 // wxPropertyGridInterface property value setting and getting
501 // -----------------------------------------------------------------------
503 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
505 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
508 // -----------------------------------------------------------------------
510 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
511 const wxString
& typestr
,
514 wxASSERT( p
!= NULL
);
515 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
516 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
519 // -----------------------------------------------------------------------
521 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
523 wxPG_PROP_ARG_CALL_PROLOG()
528 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
530 propGrid
->DrawItemAndValueRelated( p
);
535 // -----------------------------------------------------------------------
537 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
539 wxPG_PROP_ARG_CALL_PROLOG()
541 if ( m_pState
->DoSetPropertyValueString(p
,value
) )
543 wxPropertyGrid
* propGrid
= p
->GetGridIfDisplayed();
545 propGrid
->DrawItemAndValueRelated( p
);
549 // -----------------------------------------------------------------------
551 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
553 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
556 // -----------------------------------------------------------------------
558 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
560 wxPGProperty
* p
= GetPropertyByName(name
);
561 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
565 // ----------------------------------------------------------------------------
567 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
571 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
573 if ( it
.GetProperty()->GetLabel() == label
)
574 return it
.GetProperty();
577 return wxNullProperty
;
580 // ----------------------------------------------------------------------------
582 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
583 wxVariant
& value
, long argFlags
)
585 wxPG_PROP_ARG_CALL_PROLOG()
587 p
->SetAttribute( name
, value
);
589 if ( argFlags
& wxPG_RECURSE
)
592 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
593 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
597 // -----------------------------------------------------------------------
599 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
602 unsigned int pageIndex
= 0;
606 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
609 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
615 // -----------------------------------------------------------------------
617 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
618 wxPGProperty::FlagType flags
,
620 int iterFlags
) const
622 wxASSERT( targetArr
);
623 wxPGVIterator it
= GetVIterator( iterFlags
);
629 const wxPGProperty
* property
= it
.GetProperty();
633 if ( (property
->GetFlags() & flags
) == flags
)
634 targetArr
->push_back((wxPGProperty
*)property
);
638 if ( (property
->GetFlags() & flags
) != flags
)
639 targetArr
->push_back((wxPGProperty
*)property
);
644 // -----------------------------------------------------------------------
646 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
647 const wxString
& falseChoice
)
649 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
650 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
653 // -----------------------------------------------------------------------
655 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
657 return m_pState
->BaseGetPropertyByName(name
);
660 // -----------------------------------------------------------------------
662 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
663 const wxString
& subname
) const
665 wxPGProperty
* p
= DoGetPropertyByName(name
);
666 if ( !p
|| !p
->GetChildCount() )
667 return wxNullProperty
;
669 return p
->GetPropertyByName(subname
);
672 // -----------------------------------------------------------------------
674 // Since GetPropertyByName is used *a lot*, this makes sense
675 // since non-virtual method can be called with less code.
676 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
678 wxPGProperty
* p
= DoGetPropertyByName(name
);
682 // Check if its "Property.SubProperty" format
683 int pos
= name
.Find(wxT('.'));
687 return GetPropertyByName(name
.substr(0,pos
),
688 name
.substr(pos
+1,name
.length()-pos
-1));
691 // -----------------------------------------------------------------------
693 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
695 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
697 wxPropertyGrid
* pg
= m_pState
->GetGrid();
699 if ( pg
== p
->GetGrid() )
700 return pg
->DoHideProperty(p
, hide
, flags
);
702 m_pState
->DoHideProperty(p
, hide
, flags
);
707 // -----------------------------------------------------------------------
709 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
711 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
712 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
714 return pg
->DoCollapse(p
);
716 return p
->GetParentState()->DoCollapse(p
);
719 // -----------------------------------------------------------------------
721 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
723 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
724 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
726 return pg
->DoExpand(p
);
728 return p
->GetParentState()->DoExpand(p
);
731 // -----------------------------------------------------------------------
733 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
735 wxPG_PROP_ARG_CALL_PROLOG()
737 p
->SetLabel( newproplabel
);
739 wxPropertyGridPageState
* state
= p
->GetParentState();
740 wxPropertyGrid
* pg
= state
->GetGrid();
742 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
743 pg
->SortChildren(p
->GetParent());
745 if ( pg
->GetState() == state
)
747 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
754 // -----------------------------------------------------------------------
756 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
758 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
760 wxPropertyGrid
* pg
= m_pState
->GetGrid();
762 p
->m_maxLen
= (short) maxLen
;
764 // Adjust control if selected currently
765 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
767 wxWindow
* wnd
= pg
->GetEditorControl();
768 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
770 tc
->SetMaxLength( maxLen
);
779 // -----------------------------------------------------------------------
782 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
783 const wxColour
& colour
,
786 wxPG_PROP_ARG_CALL_PROLOG()
787 p
->SetBackgroundColour( colour
, recursively
);
788 RefreshProperty( p
);
791 // -----------------------------------------------------------------------
793 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
794 const wxColour
& colour
,
797 wxPG_PROP_ARG_CALL_PROLOG()
798 p
->SetTextColour( colour
, recursively
);
799 RefreshProperty( p
);
802 // -----------------------------------------------------------------------
804 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
806 wxPG_PROP_ARG_CALL_PROLOG()
811 // -----------------------------------------------------------------------
813 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
815 const wxString
& text
,
816 const wxBitmap
& bitmap
,
817 const wxColour
& fgCol
,
818 const wxColour
& bgCol
)
820 wxPG_PROP_ARG_CALL_PROLOG()
822 wxPGCell
& cell
= p
->GetCell(column
);
823 if ( text
.length() && text
!= wxPG_LABEL
)
826 cell
.SetBitmap(bitmap
);
827 if ( fgCol
!= wxNullColour
)
828 cell
.SetFgCol(fgCol
);
829 if ( bgCol
!= wxNullColour
)
830 cell
.SetBgCol(bgCol
);
833 // -----------------------------------------------------------------------
834 // GetPropertyValueAsXXX methods
836 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
837 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
839 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
840 wxVariant value = p->GetValue(); \
841 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
843 wxPGGetFailed(p,wxPGTypeName_##T); \
844 return (TRET)DEFRETVAL; \
846 return (TRET)value.Get##BIGNAME(); \
849 // String is different than others.
850 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
852 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
853 return p
->GetValueAsString(wxPG_FULL_VALUE
);
856 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
858 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
859 wxVariant value
= p
->GetValue();
860 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
862 return value
.GetBool();
864 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
866 return value
.GetLong()?true:false;
868 wxPGGetFailed(p
,wxPGTypeName_bool
);
872 IMPLEMENT_GET_VALUE(long,long,Long
,0)
873 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
875 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
877 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
878 return p
->IsExpanded();
881 // -----------------------------------------------------------------------
882 // wxPropertyGridInterface wrappers
883 // -----------------------------------------------------------------------
885 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
887 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
890 // -----------------------------------------------------------------------
892 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
894 wxPG_PROP_ARG_CALL_PROLOG()
895 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
896 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
897 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
900 // -----------------------------------------------------------------------
902 bool wxPropertyGridInterface::EditorValidate()
904 return GetPropertyGrid()->DoEditorValidate();
907 // -----------------------------------------------------------------------
909 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
911 wxPG_PROP_ARG_CALL_PROLOG()
912 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
913 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
914 p
->SetFlag(wxPG_PROP_AGGREGATE
);
917 // -----------------------------------------------------------------------
918 // wxPGVIterator_State
919 // -----------------------------------------------------------------------
921 // Default returned by wxPropertyGridInterface::GetVIterator().
922 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
925 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
927 m_it
.Init( state
, flags
);
929 virtual ~wxPGVIteratorBase_State() { }
930 virtual void Next() { m_it
.Next(); }
933 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
935 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
938 // -----------------------------------------------------------------------
939 // wxPGEditableState related functions
940 // -----------------------------------------------------------------------
942 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
943 // in the input string. This is an internal functions which is
944 // used for saving states
945 // NB: Similar function exists in aui/framemanager.cpp
946 static wxString
EscapeDelimiters(const wxString
& s
)
949 result
.Alloc(s
.length());
950 const wxChar
* ch
= s
.c_str();
953 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
961 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
966 // Save state on page basis
967 unsigned int pageIndex
= 0;
968 wxArrayPtrVoid pageStates
;
972 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
975 pageStates
.Add(page
);
980 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
982 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
984 if ( includedStates
& SelectionState
)
987 if ( pageState
->GetSelection() )
988 sel
= pageState
->GetSelection()->GetName();
989 result
+= wxS("selection=");
990 result
+= EscapeDelimiters(sel
);
993 if ( includedStates
& ExpandedState
)
995 wxArrayPGProperty ptrs
;
996 wxPropertyGridConstIterator it
=
997 wxPropertyGridConstIterator( pageState
,
998 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
1001 result
+= wxS("expanded=");
1007 const wxPGProperty
* p
= it
.GetProperty();
1009 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
1010 result
+= EscapeDelimiters(p
->GetName());
1015 if ( result
.Last() == wxS(',') )
1016 result
.RemoveLast();
1020 if ( includedStates
& ScrollPosState
)
1023 GetPropertyGrid()->GetViewStart(&x
,&y
);
1024 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
1026 if ( includedStates
& SplitterPosState
)
1028 result
+= wxS("splitterpos=");
1030 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
1031 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
1033 result
.RemoveLast(); // Remove last comma
1036 if ( includedStates
& PageState
)
1038 result
+= wxS("ispageselected=");
1040 if ( GetPageState(-1) == pageState
)
1041 result
+= wxS("1;");
1043 result
+= wxS("0;");
1045 if ( includedStates
& DescBoxState
)
1047 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
1049 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
1051 result
.RemoveLast(); // Remove last semicolon
1056 if ( result
.length() )
1057 result
.RemoveLast();
1062 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
1064 wxPropertyGrid
* pg
= GetPropertyGrid();
1065 wxPGProperty
* newSelection
= NULL
;
1069 long selectedPage
= -1;
1070 bool pgSelectionSet
= false;
1074 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
1076 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
1078 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1082 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
1084 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
1086 const wxString
& kvs
= kvpairStrings
[i
];
1087 int eq_pos
= kvs
.Find(wxS('='));
1088 if ( eq_pos
!= wxNOT_FOUND
)
1090 wxString key
= kvs
.substr(0, eq_pos
);
1091 wxString value
= kvs
.substr(eq_pos
+1);
1093 // Further split value by commas
1094 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
1096 if ( key
== wxS("expanded") )
1098 if ( restoreStates
& ExpandedState
)
1100 wxPropertyGridIterator it
=
1101 wxPropertyGridIterator( pageState
,
1105 // First collapse all
1106 for ( ; !it
.AtEnd(); it
.Next() )
1108 wxPGProperty
* p
= it
.GetProperty();
1109 pageState
->DoCollapse(p
);
1112 // Then expand those which names are in values
1113 for ( size_t n
=0; n
<values
.size(); n
++ )
1115 const wxString
& name
= values
[n
];
1116 wxPGProperty
* prop
= GetPropertyByName(name
);
1118 pageState
->DoExpand(prop
);
1122 else if ( key
== wxS("scrollpos") )
1124 if ( restoreStates
& ScrollPosState
)
1126 if ( values
.size() == 2 )
1128 values
[0].ToLong(&vx
);
1129 values
[1].ToLong(&vy
);
1137 else if ( key
== wxS("splitterpos") )
1139 if ( restoreStates
& SplitterPosState
)
1141 for ( size_t n
=1; n
<values
.size(); n
++ )
1144 values
[n
].ToLong(&pos
);
1146 pageState
->DoSetSplitterPosition(pos
, n
);
1150 else if ( key
== wxS("selection") )
1152 if ( restoreStates
& SelectionState
)
1154 if ( values
.size() > 0 )
1156 if ( pageState
->IsDisplayed() )
1158 if ( values
[0].length() )
1159 newSelection
= GetPropertyByName(value
);
1160 pgSelectionSet
= true;
1164 if ( values
[0].length() )
1165 pageState
->SetSelection(GetPropertyByName(value
));
1167 pageState
->DoClearSelection();
1172 else if ( key
== wxS("ispageselected") )
1174 if ( restoreStates
& PageState
)
1177 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1179 if ( pageSelStatus
)
1180 selectedPage
= pageIndex
;
1188 else if ( key
== wxS("descboxheight") )
1190 if ( restoreStates
& DescBoxState
)
1193 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1195 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1212 // Force recalculation of virtual heights of all pages
1213 // (may be needed on unclean source string).
1215 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1218 pageState
->VirtualHeightChanged();
1220 pageState
= GetPageState(pageIndex
);
1226 // Selection of visible grid page must be set after Thaw() call
1227 if ( pgSelectionSet
)
1230 pg
->SelectProperty(newSelection
);
1232 pg
->ClearSelection();
1235 if ( selectedPage
!= -1 )
1237 DoSelectPage(selectedPage
);
1248 #endif // wxUSE_PROPGRID