27 #include <wx/string.h> 28 #include <wx/bitmap.h> 30 #include <wx/validate.h> 31 #include <wx/propgrid/property.h> 37 #include <type_traits> 56 #define TYPE_HASH( x ) typeid( x ).hash_code() 57 #define TYPE_NAME( x ) typeid( x ).name() 60 template<
typename Owner,
typename T>
66 virtual T
operator()( Owner* aOwner )
const = 0;
69 template<
typename Owner,
typename T,
typename FuncType>
80 return ( aOwner->*
m_func )();
87 template<
typename Owner,
typename T>
93 virtual void operator()( Owner* aOwner, T aValue ) = 0;
96 template<
typename Owner,
typename T,
typename FuncType>
108 ( aOwner->*
m_func )( aValue );
116 template<
typename Owner,
typename T,
typename Base = Owner>
197 static wxPGChoices
empty;
242 virtual size_t BaseHash()
const = 0;
247 virtual size_t TypeHash()
const = 0;
258 void set(
void* aObject, T aValue )
267 wxAny a =
getter( aObject );
269 if ( !( std::is_enum<T>::value && a.CheckType<
int>() ) && !a.CheckType<T>() )
270 throw std::invalid_argument(
"Invalid requested type" );
272 return wxANY_AS(a, T);
275 virtual void setter(
void* aObject, wxAny& aValue ) = 0;
276 virtual wxAny
getter(
void* aObject )
const = 0;
288 template<
typename Owner,
typename T,
typename Base = Owner>
295 template<
typename SetType,
typename GetType>
297 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
300 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay )
304 template<
typename SetType,
typename GetType>
306 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )()
const,
309 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay )
344 virtual void setter(
void* obj, wxAny& v )
override 348 if( !v.CheckType<T>() )
349 throw std::invalid_argument(
"Invalid type requested" );
351 Owner* o = reinterpret_cast<Owner*>( obj );
353 (*m_setter)( o, value );
356 virtual wxAny
getter(
void* obj )
const override 358 Owner* o = reinterpret_cast<Owner*>( obj );
359 wxAny res = (*m_getter)( o );
380 template<
typename Owner,
typename T,
typename Base = Owner>
384 template<
typename SetType,
typename GetType>
386 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
388 :
PROPERTY<Owner, T, Base>( aName,
METHOD<Owner, T, Base>::Wrap( aSetter ),
389 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay )
391 if ( std::is_enum<T>::value )
394 wxASSERT_MSG(
m_choices.GetCount() > 0,
"No enum choices defined" );
398 template<
typename SetType,
typename GetType>
400 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )()
const,
402 :
PROPERTY<Owner, T, Base>( aName,
METHOD<Owner, T, Base>::Wrap( aSetter ),
403 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay )
405 if ( std::is_enum<T>::value )
408 wxASSERT_MSG(
m_choices.GetCount() > 0,
"No enum choices defined" );
412 virtual void setter(
void* obj, wxAny& v )
override 415 Owner* o = reinterpret_cast<Owner*>( obj );
417 if( v.CheckType<T>() )
419 T value = wxANY_AS(v, T);
422 else if (v.CheckType<
int>() )
424 int value = wxANY_AS(v,
int);
429 throw std::invalid_argument(
"Invalid type requested" );
433 virtual wxAny
getter(
void* obj )
const override 435 Owner* o = reinterpret_cast<Owner*>( obj );
464 virtual void*
operator()(
void* aPointer )
const = 0;
465 virtual const void*
operator()(
const void* aPointer )
const = 0;
466 virtual size_t BaseHash()
const = 0;
471 template<
typename Base,
typename Derived>
481 Base* base = reinterpret_cast<Base*>( aPointer );
482 return static_cast<Derived*>( base );
485 const void*
operator()(
const void* aPointer )
const override 487 const Base* base = reinterpret_cast<const Base*>( aPointer );
488 return static_cast<const Derived*>( base );
515 m_choices.Add( aName, static_cast<int>( aValue ) );
528 static const wxString s_undef =
"UNDEFINED";
530 int idx =
m_choices.Index( static_cast<int>( value ) );
532 if( idx >= 0 && idx < (
int)
m_choices.GetCount() )
533 return m_choices.GetLabel( static_cast<int>( idx ) );
563 #define DECLARE_ENUM_TO_WXANY( type ) \ 565 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \ 567 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \ 569 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \ 570 virtual ~wxAnyValueTypeImpl() {} \ 571 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \ 572 wxAnyValueBuffer& dst ) const override \ 574 type value = GetValue( src ); \ 575 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \ 576 if( dstType->CheckType<wxString>() ) \ 578 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \ 581 if( dstType->CheckType<int>() ) \ 583 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \ 593 #define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) 595 #define ENUM_TO_WXANY( type ) \ 596 DECLARE_ENUM_TO_WXANY( type ) \ 597 IMPLEMENT_ENUM_TO_WXANY( type ) 600 #define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr ) size_t BaseHash() const override
Display value expressed in degrees.
virtual void * operator()(void *aPointer) const =0
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)() const)
virtual bool HasChoices() const
Returns true if this PROPERTY has a limited set of possible values.
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
virtual size_t BaseHash() const =0
PROPERTY_BASE(const wxString &aName, PROPERTY_DISPLAY aDisplay=DEFAULT)
Used to generate unique IDs. Must come up front so it's initialized before ctor.
void * operator()(void *aPointer) const override
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)())
virtual void setter(void *obj, wxAny &v) override
ENUM_MAP & Undefined(T aValue)
PROPERTY(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=DEFAULT)
const size_t m_typeHash
Property value type-id
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Get method
virtual T operator()(Owner *aOwner) const =0
const wxPGChoices & Choices() const override
Returns a limited set of possible values (e.g.
virtual void operator()(Owner *aOwner, T aValue)=0
virtual size_t TypeHash() const =0
Returns type-id of the property type.
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Set method
static ENUM_MAP< T > & Instance()
PROPERTY_DISPLAY GetDisplay() const
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)())
virtual size_t DerivedHash() const =0
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)() const)
std::decay< T >::type BASE_TYPE
virtual wxAny getter(void *obj) const override
virtual wxAny getter(void *aObject) const =0
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)() const, PROPERTY_DISPLAY aDisplay=PROPERTY_DISPLAY::DEFAULT)
const PROPERTY_DISPLAY m_display
virtual void setter(void *obj, wxAny &v) override
static constexpr GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)() const)
void operator()(Owner *aOwner, T aValue) override
bool IsReadOnly() const override
Display value expressed in distance units (mm/inch)
const void * operator()(const void *aPointer) const override
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PROPERTY_DISPLAY::DEFAULT)
const T ToEnum(const wxString value)
virtual ~TYPE_CAST_BASE()
void SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Sets a callback function to determine whether an object provides this property.
PROPERTY(const wxString &aName, SETTER_BASE< Owner, T > *s, GETTER_BASE< Owner, T > *g, PROPERTY_DISPLAY aDisplay)
Convert decidegrees to degrees for display.
virtual wxAny getter(void *obj) const override
const wxString & Name() const
bool HasChoices() const override
Returns true if this PROPERTY has a limited set of possible values.
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T &))
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T))
PROPERTY_DISPLAY
Common property types
Class that other classes need to inherit from, in order to be inspectable.
T operator()(Owner *aOwner) const override
virtual const wxPGChoices & Choices() const
Returns a limited set of possible values (e.g.
virtual void setter(void *aObject, wxAny &aValue)=0
size_t DerivedHash() const override
std::function< bool(INSPECTABLE *)> m_availFunc
virtual bool IsReadOnly() const =0
void SetChoices(const wxPGChoices &aChoices) override
Sets the possible values for for the property.
static constexpr GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)())
virtual void SetChoices(const wxPGChoices &aChoices)
Sets the possible values for for the property.
bool Available(INSPECTABLE *aObject) const
Returns true if aObject offers this PROPERTY.
static bool empty(const wxTextEntryBase *aCtrl)
std::unordered_map< wxString, T > m_reverseMap
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(const T &))
size_t BaseHash() const override
Returns type-id of the Base class.
const size_t m_ownerHash
Owner class type-id
virtual size_t BaseHash() const =0
Returns type-id of the Base class.
size_t OwnerHash() const override
Returns type-id of the Owner class.
void set(void *aObject, T aValue)
Default property for a given type.
ENUM_MAP & Map(T aValue, const wxString &aName)
virtual size_t OwnerHash() const =0
Returns type-id of the Owner class.
size_t TypeHash() const override
Returns type-id of the property type.
const size_t m_baseHash
Base class type-id
const wxString & ToString(T value) const
PROPERTY(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)() const, PROPERTY_DISPLAY aDisplay=DEFAULT)