//////////////////////////////////////////////////////////////////////////////////////////////////// // NoesisGUI - http://www.noesisengine.com // Copyright (c) 2013 Noesis Technologies S.L. All Rights Reserved. //////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef __GUI_PROPERTYMETADATA_H__ #define __GUI_PROPERTYMETADATA_H__ #include #include #include #include #include #include namespace Noesis { class DependencyProperty; class DependencyObject; struct DependencyPropertyChangedEventArgs; //////////////////////////////////////////////////////////////////////////////////////////////////// typedef Delegate PropertyChangedCallback; //////////////////////////////////////////////////////////////////////////////////////////////////// typedef Delegate CoerceValueCallback; NS_WARNING_PUSH NS_MSVC_WARNING_DISABLE(4251 4275) //////////////////////////////////////////////////////////////////////////////////////////////////// /// Defines certain behavior aspects of a dependency property as it is applied to a specific type, /// including conditions it was registered with. //////////////////////////////////////////////////////////////////////////////////////////////////// class NS_GUI_DEPENDENCYSYSTEM_API PropertyMetadata: public BaseComponent { public: // Helper functions to create a new PropertyMetadata //@{ static Ptr Create(); static Ptr Create(const PropertyChangedCallback& changed); static Ptr Create(const CoerceValueCallback& coerce); template inline static Ptr Create(const T& defaultValue); template inline static Ptr Create(const T& defaultValue, const PropertyChangedCallback& changed); template inline static Ptr Create(const T& defaultValue, const CoerceValueCallback& coerce); template inline static Ptr Create(const T& defaultValue, const PropertyChangedCallback& changed, const CoerceValueCallback& coerce); //@} ~PropertyMetadata(); /// Gets or sets the default value of the dependency property //@{ inline const ValueStorage* GetDefaultValueStorage() const; inline const void* GetDefaultValue() const; void SetDefaultValue(ValueStorageManager* defaultValueManager, const void* defaultValue); template void SetDefaultValue(const T& defaultValue); //@} /// Gets default value as a boxed object inline Ptr GetDefaultValueObject() const; /// Gets *DefaultValue* memory manager inline ValueStorageManager* GetValueManager() const; /// Indicates if this metadata has a DefaultValue set inline bool HasDefaultValue() const; /// Gets or sets a PropertyChangedCallback implementation specified in this metadata /// \prop //@{ inline const PropertyChangedCallback& GetPropertyChangedCallback() const; void SetPropertyChangedCallback(const PropertyChangedCallback& changed); /// Indicates if this metadata has a PropertyChangedCallback set inline bool HasPropertyChangedCallback() const; /// Gets or sets a CoerceValueCallback implementation specified in this metadata /// \prop //@{ inline const CoerceValueCallback& GetCoerceValueCallback() const; void SetCoerceValueCallback(const CoerceValueCallback& coerce); //@} /// Indicates if this metadata has a CoerceValueCallback set inline bool HasCoerceValueCallback() const; /// Determines if the values of the property using this metadata should not be cached /// prop //@{ inline bool GetUncached() const; void SetUncached(bool value); //@} /// Indicates if this metadata has a the Uncached flag set inline bool IsUncached() const; /// Remove inherited values from ancestors virtual void ClearInheritedValues(); /// Inherit ancestor values if they are not local in this class virtual void Merge(const PropertyMetadata* ancestor); /// Notifies listeners when metadata is destroyed typedef Delegate DestroyedDelegate; DestroyedDelegate& Destroyed(); protected: /// Constructors //@{ PropertyMetadata(); static Ptr Create(ValueStorageManager* defaultValueManager, const void* defaultValue); static Ptr Create(ValueStorageManager* defaultValueManager, const void* defaultValue, const PropertyChangedCallback& changed); static Ptr Create(ValueStorageManager* defaultValueManager, const void* defaultValue, const CoerceValueCallback& coerce); static Ptr Create(ValueStorageManager* defaultValueManager, const void* defaultValue, const PropertyChangedCallback& changed, const CoerceValueCallback& coerce); //@} /// From BaseComponent //@{ int32_t OnDestroy() override; //@} bool CheckSealed() const; private: void ResetDefaultValue(); private: ValueStorage mDefaultValue; ValueStorageManager* mDefaultValueManager; PropertyChangedCallback mLocalChanged; PropertyChangedCallback mChanged; CoerceValueCallback mCoerce; DestroyedDelegate mDestroyed; enum PropertyFlags { PropertyFlags_None = 0, PropertyFlags_Default = 1 << 1, PropertyFlags_Coerce = 1 << 2, PropertyFlags_Changed = 1 << 3, PropertyFlags_Uncached = 1 << 4 }; // Flag to control if properties value are local or inherited uint32_t mLocalFlags; // Tells if the property must not be cached in the DependencyObject internal hash bool mLocalUncached; bool mUncached; friend class DependencyProperty; bool mSealed; NS_DECLARE_REFLECTION(PropertyMetadata, BaseComponent) }; NS_WARNING_POP } // Inline Include #include #endif