From 1a31eef1897ade6ba8b5a474bda2f408584c4ae4 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 10 Apr 2022 13:40:08 +0200 Subject: [PATCH] Cleanup wxPropertyGridInterface declarations Move definitions of GetPropertyValueAs*() functions away from class declaration to avoid polluting the header. --- include/wx/propgrid/propgridiface.h | 56 +++------------------- src/propgrid/propgridiface.cpp | 73 ++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 63 deletions(-) diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index 9eb91579ba..108984d3ea 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -433,11 +433,7 @@ public: // Returns value as wxVariant. To get wxObject pointer from it, // you will have to use WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) macro. // If property value is unspecified, wxNullVariant is returned. - wxVariant GetPropertyValue( wxPGPropArg id ) - { - wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxVariant()) - return p->GetValue(); - } + wxVariant GetPropertyValue(wxPGPropArg id); wxString GetPropertyValueAsString( wxPGPropArg id ) const; long GetPropertyValueAsLong( wxPGPropArg id ) const; @@ -450,58 +446,18 @@ public: bool GetPropertyValueAsBool( wxPGPropArg id ) const; double GetPropertyValueAsDouble( wxPGPropArg id ) const; -#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(PGTypeName, DEFVAL) \ - wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \ - wxVariant value = p->GetValue(); \ - if ( !value.IsType(PGTypeName) ) \ - { \ - wxPGGetFailed(p, PGTypeName); \ - return DEFVAL; \ - } - -#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(PGTypeName, DEFVAL) \ - wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \ - wxVariant value = p->GetValue(); \ - if ( !value.IsType(PGTypeName) ) \ - return DEFVAL; \ - - wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const - { - wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxPG_VARIANT_TYPE_ARRSTRING, - wxArrayString()) - return value.GetArrayString(); - } + wxArrayString GetPropertyValueAsArrayString(wxPGPropArg id) const; #if defined(wxLongLong_t) && wxUSE_LONGLONG - wxLongLong_t GetPropertyValueAsLongLong( wxPGPropArg id ) const - { - wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0) - return p->GetValue().GetLongLong().GetValue(); - } + wxLongLong_t GetPropertyValueAsLongLong(wxPGPropArg id) const; - wxULongLong_t GetPropertyValueAsULongLong( wxPGPropArg id ) const - { - wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0) - return p->GetValue().GetULongLong().GetValue(); - } + wxULongLong_t GetPropertyValueAsULongLong(wxPGPropArg id) const; #endif - wxArrayInt GetPropertyValueAsArrayInt( wxPGPropArg id ) const - { - wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxArrayInt_VariantType, - wxArrayInt()) - wxArrayInt arr; - arr << value; - return arr; - } + wxArrayInt GetPropertyValueAsArrayInt(wxPGPropArg id) const; #if wxUSE_DATETIME - wxDateTime GetPropertyValueAsDateTime( wxPGPropArg id ) const - { - wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxPG_VARIANT_TYPE_DATETIME, - wxDateTime()) - return value.GetDateTime(); - } + wxDateTime GetPropertyValueAsDateTime(wxPGPropArg id) const; #endif // Returns a wxVariant list containing wxVariant versions of all diff --git a/src/propgrid/propgridiface.cpp b/src/propgrid/propgridiface.cpp index 97f85619d5..7f8e37d6bc 100644 --- a/src/propgrid/propgridiface.cpp +++ b/src/propgrid/propgridiface.cpp @@ -759,17 +759,10 @@ void wxPropertyGridInterface::SetPropertyCell( wxPGPropArg id, // ----------------------------------------------------------------------- // GetPropertyValueAsXXX methods -#define IMPLEMENT_GET_VALUE(TRET,PGTypeName,BIGNAME,DEFRETVAL) \ -TRET wxPropertyGridInterface::GetPropertyValueAs##BIGNAME( wxPGPropArg id ) const \ -{ \ - wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFRETVAL) \ - wxVariant value = p->GetValue(); \ - if ( !value.IsType(PGTypeName) ) \ - { \ - wxPGGetFailed(p, PGTypeName); \ - return (TRET)DEFRETVAL; \ - } \ - return (TRET)value.Get##BIGNAME(); \ +wxVariant wxPropertyGridInterface::GetPropertyValue(wxPGPropArg id) +{ + wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxVariant()) + return p->GetValue(); } // String is different from others. @@ -795,8 +788,62 @@ bool wxPropertyGridInterface::GetPropertyValueAsBool( wxPGPropArg id ) const return false; } -IMPLEMENT_GET_VALUE(long,wxPG_VARIANT_TYPE_LONG,Long,0) -IMPLEMENT_GET_VALUE(double,wxPG_VARIANT_TYPE_DOUBLE,Double,0.0) +#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(PGTypeName, DEFVAL) \ + wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \ + wxVariant value = p->GetValue(); \ + if ( !value.IsType(PGTypeName) ) \ + { \ + wxPGGetFailed(p, PGTypeName); \ + return DEFVAL; \ + } + +long wxPropertyGridInterface::GetPropertyValueAsLong(wxPGPropArg id) const +{ + wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxPG_VARIANT_TYPE_LONG, 0L) + return value.GetLong(); +} + +double wxPropertyGridInterface::GetPropertyValueAsDouble(wxPGPropArg id) const +{ + wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxPG_VARIANT_TYPE_DOUBLE, 0.0) + return value.GetDouble(); +} + +wxArrayString wxPropertyGridInterface::GetPropertyValueAsArrayString(wxPGPropArg id) const +{ + wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxPG_VARIANT_TYPE_ARRSTRING, wxArrayString()) + return value.GetArrayString(); +} + +#if defined(wxLongLong_t) && wxUSE_LONGLONG +wxLongLong_t wxPropertyGridInterface::GetPropertyValueAsLongLong(wxPGPropArg id) const +{ + wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0) + return p->GetValue().GetLongLong().GetValue(); +} + +wxULongLong_t wxPropertyGridInterface::GetPropertyValueAsULongLong(wxPGPropArg id) const +{ + wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0) + return p->GetValue().GetULongLong().GetValue(); +} +#endif + +wxArrayInt wxPropertyGridInterface::GetPropertyValueAsArrayInt(wxPGPropArg id) const +{ + wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxArrayInt_VariantType, wxArrayInt()) + wxArrayInt arr; + arr << value; + return arr; +} + +#if wxUSE_DATETIME +wxDateTime wxPropertyGridInterface::GetPropertyValueAsDateTime(wxPGPropArg id) const +{ + wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxPG_VARIANT_TYPE_DATETIME, wxDateTime()) + return value.GetDateTime(); +} +#endif bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id ) const {