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::ClearModifiedStatus()
503 unsigned int pageIndex
= 0;
507 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
510 page
->DoGetRoot()->SetFlagRecursively(wxPG_PROP_MODIFIED
, false);
515 // Update active editor control, if any
516 GetPropertyGrid()->RefreshEditor();
519 // -----------------------------------------------------------------------
520 // wxPropertyGridInterface property value setting and getting
521 // -----------------------------------------------------------------------
523 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
)
525 wxPGTypeOperationFailed(p
, typestr
, wxS("Get"));
528 // -----------------------------------------------------------------------
530 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
531 const wxString
& typestr
,
534 wxASSERT( p
!= NULL
);
535 wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
536 op
.c_str(), p
->GetLabel().c_str(), p
->GetValue().GetType().c_str(), typestr
.c_str() );
539 // -----------------------------------------------------------------------
541 void wxPropertyGridInterface::SetPropVal( wxPGPropArg id
, wxVariant
& value
)
543 wxPG_PROP_ARG_CALL_PROLOG()
549 // -----------------------------------------------------------------------
551 void wxPropertyGridInterface::SetPropertyValueString( wxPGPropArg id
, const wxString
& value
)
553 wxPG_PROP_ARG_CALL_PROLOG()
556 m_pState
->DoSetPropertyValueString(p
, value
);
559 // -----------------------------------------------------------------------
561 void wxPropertyGridInterface::SetValidationFailureBehavior( int vfbFlags
)
563 GetPropertyGrid()->m_permanentValidationFailureBehavior
= vfbFlags
;
566 // -----------------------------------------------------------------------
568 wxPGProperty
* wxPropertyGridInterface::GetPropertyByNameA( const wxString
& name
) const
570 wxPGProperty
* p
= GetPropertyByName(name
);
571 wxASSERT_MSG(p
,wxString::Format(wxT("no property with name '%s'"),name
.c_str()));
575 // ----------------------------------------------------------------------------
577 wxPGProperty
* wxPropertyGridInterface::GetPropertyByLabel( const wxString
& label
) const
581 for ( it
= GetVIterator( wxPG_ITERATE_PROPERTIES
); !it
.AtEnd(); it
.Next() )
583 if ( it
.GetProperty()->GetLabel() == label
)
584 return it
.GetProperty();
587 return wxNullProperty
;
590 // ----------------------------------------------------------------------------
592 void wxPropertyGridInterface::DoSetPropertyAttribute( wxPGPropArg id
, const wxString
& name
,
593 wxVariant
& value
, long argFlags
)
595 wxPG_PROP_ARG_CALL_PROLOG()
597 p
->SetAttribute( name
, value
);
599 if ( argFlags
& wxPG_RECURSE
)
602 for ( i
= 0; i
< p
->GetChildCount(); i
++ )
603 DoSetPropertyAttribute(p
->Item(i
), name
, value
, argFlags
);
607 // -----------------------------------------------------------------------
609 void wxPropertyGridInterface::SetPropertyAttributeAll( const wxString
& attrName
,
612 unsigned int pageIndex
= 0;
616 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
619 DoSetPropertyAttribute(page
->DoGetRoot(), attrName
, value
, wxPG_RECURSE
);
625 // -----------------------------------------------------------------------
627 void wxPropertyGridInterface::GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
628 wxPGProperty::FlagType flags
,
630 int iterFlags
) const
632 wxASSERT( targetArr
);
633 wxPGVIterator it
= GetVIterator( iterFlags
);
639 const wxPGProperty
* property
= it
.GetProperty();
643 if ( (property
->GetFlags() & flags
) == flags
)
644 targetArr
->push_back((wxPGProperty
*)property
);
648 if ( (property
->GetFlags() & flags
) != flags
)
649 targetArr
->push_back((wxPGProperty
*)property
);
654 // -----------------------------------------------------------------------
656 void wxPropertyGridInterface::SetBoolChoices( const wxString
& trueChoice
,
657 const wxString
& falseChoice
)
659 wxPGGlobalVars
->m_boolChoices
[0] = falseChoice
;
660 wxPGGlobalVars
->m_boolChoices
[1] = trueChoice
;
663 // -----------------------------------------------------------------------
665 wxPGProperty
* wxPropertyGridInterface::DoGetPropertyByName( const wxString
& name
) const
667 return m_pState
->BaseGetPropertyByName(name
);
670 // -----------------------------------------------------------------------
672 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
,
673 const wxString
& subname
) const
675 wxPGProperty
* p
= DoGetPropertyByName(name
);
676 if ( !p
|| !p
->GetChildCount() )
677 return wxNullProperty
;
679 return p
->GetPropertyByName(subname
);
682 // -----------------------------------------------------------------------
684 // Since GetPropertyByName is used *a lot*, this makes sense
685 // since non-virtual method can be called with less code.
686 wxPGProperty
* wxPropertyGridInterface::GetPropertyByName( const wxString
& name
) const
688 wxPGProperty
* p
= DoGetPropertyByName(name
);
692 // Check if its "Property.SubProperty" format
693 int pos
= name
.Find(wxT('.'));
697 return GetPropertyByName(name
.substr(0,pos
),
698 name
.substr(pos
+1,name
.length()-pos
-1));
701 // -----------------------------------------------------------------------
703 bool wxPropertyGridInterface::HideProperty( wxPGPropArg id
, bool hide
, int flags
)
705 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
707 wxPropertyGrid
* pg
= m_pState
->GetGrid();
709 if ( pg
== p
->GetGrid() )
710 return pg
->DoHideProperty(p
, hide
, flags
);
712 m_pState
->DoHideProperty(p
, hide
, flags
);
717 // -----------------------------------------------------------------------
719 bool wxPropertyGridInterface::Collapse( wxPGPropArg id
)
721 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
722 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
724 return pg
->DoCollapse(p
);
726 return p
->GetParentState()->DoCollapse(p
);
729 // -----------------------------------------------------------------------
731 bool wxPropertyGridInterface::Expand( wxPGPropArg id
)
733 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
734 wxPropertyGrid
* pg
= p
->GetGridIfDisplayed();
736 return pg
->DoExpand(p
);
738 return p
->GetParentState()->DoExpand(p
);
741 // -----------------------------------------------------------------------
743 void wxPropertyGridInterface::Sort( int flags
)
745 wxPropertyGrid
* pg
= GetPropertyGrid();
747 pg
->ClearSelection(false);
749 unsigned int pageIndex
= 0;
753 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
760 // -----------------------------------------------------------------------
762 void wxPropertyGridInterface::SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
)
764 wxPG_PROP_ARG_CALL_PROLOG()
766 p
->SetLabel( newproplabel
);
768 wxPropertyGridPageState
* state
= p
->GetParentState();
769 wxPropertyGrid
* pg
= state
->GetGrid();
771 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
772 pg
->SortChildren(p
->GetParent());
774 if ( pg
->GetState() == state
)
776 if ( pg
->HasFlag(wxPG_AUTO_SORT
) )
783 // -----------------------------------------------------------------------
785 bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id
, int maxLen
)
787 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
789 wxPropertyGrid
* pg
= m_pState
->GetGrid();
791 p
->m_maxLen
= (short) maxLen
;
793 // Adjust control if selected currently
794 if ( pg
== p
->GetGrid() && p
== m_pState
->GetSelection() )
796 wxWindow
* wnd
= pg
->GetEditorControl();
797 wxTextCtrl
* tc
= wxDynamicCast(wnd
,wxTextCtrl
);
799 tc
->SetMaxLength( maxLen
);
808 // -----------------------------------------------------------------------
811 wxPropertyGridInterface::SetPropertyBackgroundColour( wxPGPropArg id
,
812 const wxColour
& colour
,
815 wxPG_PROP_ARG_CALL_PROLOG()
816 p
->SetBackgroundColour( colour
, recursively
);
817 RefreshProperty( p
);
820 // -----------------------------------------------------------------------
822 void wxPropertyGridInterface::SetPropertyTextColour( wxPGPropArg id
,
823 const wxColour
& colour
,
826 wxPG_PROP_ARG_CALL_PROLOG()
827 p
->SetTextColour( colour
, recursively
);
828 RefreshProperty( p
);
831 // -----------------------------------------------------------------------
833 void wxPropertyGridInterface::SetPropertyColoursToDefault( wxPGPropArg id
)
835 wxPG_PROP_ARG_CALL_PROLOG()
840 // -----------------------------------------------------------------------
842 void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id
,
844 const wxString
& text
,
845 const wxBitmap
& bitmap
,
846 const wxColour
& fgCol
,
847 const wxColour
& bgCol
)
849 wxPG_PROP_ARG_CALL_PROLOG()
851 wxPGCell
& cell
= p
->GetCell(column
);
852 if ( text
.length() && text
!= wxPG_LABEL
)
855 cell
.SetBitmap(bitmap
);
856 if ( fgCol
!= wxNullColour
)
857 cell
.SetFgCol(fgCol
);
858 if ( bgCol
!= wxNullColour
)
859 cell
.SetBgCol(bgCol
);
862 // -----------------------------------------------------------------------
863 // GetPropertyValueAsXXX methods
865 #define IMPLEMENT_GET_VALUE(T,TRET,BIGNAME,DEFRETVAL) \
866 TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \
868 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \
869 wxVariant value = p->GetValue(); \
870 if ( wxStrcmp(value.GetType(), wxPGTypeName_##T) != 0 ) \
872 wxPGGetFailed(p,wxPGTypeName_##T); \
873 return (TRET)DEFRETVAL; \
875 return (TRET)value.Get##BIGNAME(); \
878 // String is different than others.
879 wxString
wxPropertyGridInterface::GetPropertyValueAsString( wxPGPropArg id
) const
881 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxEmptyString
)
882 return p
->GetValueAsString(wxPG_FULL_VALUE
);
885 bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id
) const
887 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
888 wxVariant value
= p
->GetValue();
889 if ( wxStrcmp(value
.GetType(), wxPGTypeName_bool
) == 0 )
891 return value
.GetBool();
893 if ( wxStrcmp(value
.GetType(), wxPGTypeName_long
) == 0 )
895 return value
.GetLong()?true:false;
897 wxPGGetFailed(p
,wxPGTypeName_bool
);
901 IMPLEMENT_GET_VALUE(long,long,Long
,0)
902 IMPLEMENT_GET_VALUE(double,double,Double
,0.0)
904 bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id
) const
906 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
907 return p
->IsExpanded();
910 // -----------------------------------------------------------------------
911 // wxPropertyGridInterface wrappers
912 // -----------------------------------------------------------------------
914 bool wxPropertyGridInterface::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
916 return GetPropertyGrid()->ChangePropertyValue(id
, newValue
);
919 // -----------------------------------------------------------------------
921 void wxPropertyGridInterface::BeginAddChildren( wxPGPropArg id
)
923 wxPG_PROP_ARG_CALL_PROLOG()
924 wxCHECK_RET( p
->HasFlag(wxPG_PROP_AGGREGATE
), wxT("only call on properties with fixed children") );
925 p
->ClearFlag(wxPG_PROP_AGGREGATE
);
926 p
->SetFlag(wxPG_PROP_MISC_PARENT
);
929 // -----------------------------------------------------------------------
931 bool wxPropertyGridInterface::EditorValidate()
933 return GetPropertyGrid()->DoEditorValidate();
936 // -----------------------------------------------------------------------
938 void wxPropertyGridInterface::EndAddChildren( wxPGPropArg id
)
940 wxPG_PROP_ARG_CALL_PROLOG()
941 wxCHECK_RET( p
->HasFlag(wxPG_PROP_MISC_PARENT
), wxT("only call on properties for which BeginAddChildren was called prior") );
942 p
->ClearFlag(wxPG_PROP_MISC_PARENT
);
943 p
->SetFlag(wxPG_PROP_AGGREGATE
);
946 // -----------------------------------------------------------------------
947 // wxPGVIterator_State
948 // -----------------------------------------------------------------------
950 // Default returned by wxPropertyGridInterface::GetVIterator().
951 class wxPGVIteratorBase_State
: public wxPGVIteratorBase
954 wxPGVIteratorBase_State( wxPropertyGridPageState
* state
, int flags
)
956 m_it
.Init( state
, flags
);
958 virtual ~wxPGVIteratorBase_State() { }
959 virtual void Next() { m_it
.Next(); }
962 wxPGVIterator
wxPropertyGridInterface::GetVIterator( int flags
) const
964 return wxPGVIterator( new wxPGVIteratorBase_State( m_pState
, flags
) );
967 // -----------------------------------------------------------------------
968 // wxPGEditableState related functions
969 // -----------------------------------------------------------------------
971 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
972 // in the input string. This is an internal functions which is
973 // used for saving states
974 // NB: Similar function exists in aui/framemanager.cpp
975 static wxString
EscapeDelimiters(const wxString
& s
)
978 result
.Alloc(s
.length());
979 const wxChar
* ch
= s
.c_str();
982 if (*ch
== wxT(';') || *ch
== wxT('|') || *ch
== wxT(','))
990 wxString
wxPropertyGridInterface::SaveEditableState( int includedStates
) const
995 // Save state on page basis
996 unsigned int pageIndex
= 0;
997 wxArrayPtrVoid pageStates
;
1001 wxPropertyGridPageState
* page
= GetPageState(pageIndex
);
1004 pageStates
.Add(page
);
1009 for ( pageIndex
=0; pageIndex
< pageStates
.size(); pageIndex
++ )
1011 wxPropertyGridPageState
* pageState
= (wxPropertyGridPageState
*) pageStates
[pageIndex
];
1013 if ( includedStates
& SelectionState
)
1016 if ( pageState
->GetSelection() )
1017 sel
= pageState
->GetSelection()->GetName();
1018 result
+= wxS("selection=");
1019 result
+= EscapeDelimiters(sel
);
1022 if ( includedStates
& ExpandedState
)
1024 wxArrayPGProperty ptrs
;
1025 wxPropertyGridConstIterator it
=
1026 wxPropertyGridConstIterator( pageState
,
1027 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
,
1030 result
+= wxS("expanded=");
1036 const wxPGProperty
* p
= it
.GetProperty();
1038 if ( !p
->HasFlag(wxPG_PROP_COLLAPSED
) )
1039 result
+= EscapeDelimiters(p
->GetName());
1044 if ( result
.Last() == wxS(',') )
1045 result
.RemoveLast();
1049 if ( includedStates
& ScrollPosState
)
1052 GetPropertyGrid()->GetViewStart(&x
,&y
);
1053 result
+= wxString::Format(wxS("scrollpos=%i,%i;"), x
, y
);
1055 if ( includedStates
& SplitterPosState
)
1057 result
+= wxS("splitterpos=");
1059 for ( size_t i
=0; i
<pageState
->GetColumnCount(); i
++ )
1060 result
+= wxString::Format(wxS("%i,"), pageState
->DoGetSplitterPosition(i
));
1062 result
.RemoveLast(); // Remove last comma
1065 if ( includedStates
& PageState
)
1067 result
+= wxS("ispageselected=");
1069 if ( GetPageState(-1) == pageState
)
1070 result
+= wxS("1;");
1072 result
+= wxS("0;");
1074 if ( includedStates
& DescBoxState
)
1076 wxVariant v
= GetEditableStateItem(wxS("descboxheight"));
1078 result
+= wxString::Format(wxS("descboxheight=%i;"), (int)v
.GetLong());
1080 result
.RemoveLast(); // Remove last semicolon
1085 if ( result
.length() )
1086 result
.RemoveLast();
1091 bool wxPropertyGridInterface::RestoreEditableState( const wxString
& src
, int restoreStates
)
1093 wxPropertyGrid
* pg
= GetPropertyGrid();
1094 wxPGProperty
* newSelection
= NULL
;
1098 long selectedPage
= -1;
1099 bool pgSelectionSet
= false;
1103 wxArrayString pageStrings
= ::wxSplit(src
, wxS('|'), wxS('\\'));
1105 for ( pageIndex
=0; pageIndex
<pageStrings
.size(); pageIndex
++ )
1107 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1111 wxArrayString kvpairStrings
= ::wxSplit(pageStrings
[pageIndex
], wxS(';'), wxS('\\'));
1113 for ( size_t i
=0; i
<kvpairStrings
.size(); i
++ )
1115 const wxString
& kvs
= kvpairStrings
[i
];
1116 int eq_pos
= kvs
.Find(wxS('='));
1117 if ( eq_pos
!= wxNOT_FOUND
)
1119 wxString key
= kvs
.substr(0, eq_pos
);
1120 wxString value
= kvs
.substr(eq_pos
+1);
1122 // Further split value by commas
1123 wxArrayString values
= ::wxSplit(value
, wxS(','), wxS('\\'));
1125 if ( key
== wxS("expanded") )
1127 if ( restoreStates
& ExpandedState
)
1129 wxPropertyGridIterator it
=
1130 wxPropertyGridIterator( pageState
,
1134 // First collapse all
1135 for ( ; !it
.AtEnd(); it
.Next() )
1137 wxPGProperty
* p
= it
.GetProperty();
1138 pageState
->DoCollapse(p
);
1141 // Then expand those which names are in values
1142 for ( size_t n
=0; n
<values
.size(); n
++ )
1144 const wxString
& name
= values
[n
];
1145 wxPGProperty
* prop
= GetPropertyByName(name
);
1147 pageState
->DoExpand(prop
);
1151 else if ( key
== wxS("scrollpos") )
1153 if ( restoreStates
& ScrollPosState
)
1155 if ( values
.size() == 2 )
1157 values
[0].ToLong(&vx
);
1158 values
[1].ToLong(&vy
);
1166 else if ( key
== wxS("splitterpos") )
1168 if ( restoreStates
& SplitterPosState
)
1170 for ( size_t n
=1; n
<values
.size(); n
++ )
1173 values
[n
].ToLong(&pos
);
1175 pageState
->DoSetSplitterPosition(pos
, n
);
1179 else if ( key
== wxS("selection") )
1181 if ( restoreStates
& SelectionState
)
1183 if ( values
.size() > 0 )
1185 if ( pageState
->IsDisplayed() )
1187 if ( values
[0].length() )
1188 newSelection
= GetPropertyByName(value
);
1189 pgSelectionSet
= true;
1193 if ( values
[0].length() )
1194 pageState
->SetSelection(GetPropertyByName(value
));
1196 pageState
->DoClearSelection();
1201 else if ( key
== wxS("ispageselected") )
1203 if ( restoreStates
& PageState
)
1206 if ( values
.size() == 1 && values
[0].ToLong(&pageSelStatus
) )
1208 if ( pageSelStatus
)
1209 selectedPage
= pageIndex
;
1217 else if ( key
== wxS("descboxheight") )
1219 if ( restoreStates
& DescBoxState
)
1222 if ( values
.size() == 1 && values
[0].ToLong(&descBoxHeight
) )
1224 SetEditableStateItem(wxS("descboxheight"), descBoxHeight
);
1241 // Force recalculation of virtual heights of all pages
1242 // (may be needed on unclean source string).
1244 wxPropertyGridPageState
* pageState
= GetPageState(pageIndex
);
1247 pageState
->VirtualHeightChanged();
1249 pageState
= GetPageState(pageIndex
);
1255 // Selection of visible grid page must be set after Thaw() call
1256 if ( pgSelectionSet
)
1259 pg
->SelectProperty(newSelection
);
1261 pg
->ClearSelection();
1264 if ( selectedPage
!= -1 )
1266 DoSelectPage(selectedPage
);
1277 #endif // wxUSE_PROPGRID