//////////////////////////////////////////////////////////////////////////////////////////////////// // NoesisGUI - http://www.noesisengine.com // Copyright (c) 2013 Noesis Technologies S.L. All Rights Reserved. //////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef __GUI_DEPENDENCYDATA_H__ #define __GUI_DEPENDENCYDATA_H__ #include #include #include #include #include #include #include namespace Noesis { class PropertyMetadata; class DependencyDataTest; class UIElementDataTest; NS_WARNING_PUSH NS_MSVC_WARNING_DISABLE(4251 4275) //////////////////////////////////////////////////////////////////////////////////////////////////// /// Metadata used for registering dependency properties //////////////////////////////////////////////////////////////////////////////////////////////////// class NS_GUI_DEPENDENCYSYSTEM_API DependencyData: public TypeMetaData { public: DependencyData(const TypeClass* ownerType); /// Registers a dependency property template void RegisterProperty(const DependencyProperty*& dp, const char* name, PropertyMetadata* metadata); /// Registers a dependency property with a given validation callback template void RegisterProperty(const DependencyProperty*& dp, const char* name, PropertyMetadata* metadata, ValidateValueCallback validate); /// Registers a read-only dependency property template void RegisterPropertyRO(const DependencyProperty*& dp, const char* name, PropertyMetadata* metadata); /// Registers a read-only dependency property with callback for getting the value template void RegisterPropertyRO(const DependencyProperty*& dp, const char* name, PropertyMetadata* metadata, GetReadOnlyValueCallback getReadOnlyValue); /// Registers a read-only dependency property with a given validation callback template void RegisterPropertyRO(const DependencyProperty*& dp, const char* name, PropertyMetadata* metadata, ValidateValueCallback validate); /// Adds another type as an owner of a dependency property that has already been registered, /// providing dependency property metadata for the dependency property as it will exist on /// the provided owner type template void AddOwner(const DependencyProperty*& dp, const char* name, const DependencyProperty*& source, PropertyMetadata* metadata = 0); /// Specifies alternate metadata for this dependency property when it is present on instances /// of a specified type, overriding the metadata that existed for the dependency property as /// it was inherited from base types template void OverrideMetadata(const DependencyProperty*& dp, const char* name, PropertyMetadata* metadata); /// Finds a property for the given owner type name const DependencyProperty* FindProperty(Symbol name) const; /// Removes specified type metadatas from all registered properties void ClearMetadata(const TypeClass* forType); const DependencyProperty* InsertProperty(const DependencyProperty* dp); /// Enumerates the registered properties typedef void(*EnumPropertiesCallback)(const DependencyProperty* dp, void* user); void EnumProperties(EnumPropertiesCallback callback, void* user) const; protected: const TypeClass* mOwnerType; private: void CheckMetadata(const char* name, PropertyMetadata* metadata, const Type* type) const; template void RegisterProperty(const DependencyProperty*& dp, const char* name, PropertyMetadata* metadata, ValidateValueCallback validate, PropertyAccess access); void RegisterExistingProperty(const DependencyProperty* dp, const char* name, PropertyMetadata* metadata, ValidateValueCallback validate, PropertyAccess access); typedef Int2Type<0> IsNotBaseComponent; typedef Int2Type<1> IsBaseComponent; template Ptr CreateProperty(const char* name, PropertyMetadata* metadata, ValidateValueCallback validate, PropertyAccess access, IsNotBaseComponent); template Ptr CreateProperty(const char* name, PropertyMetadata* metadata, ValidateValueCallback validate, PropertyAccess access, IsBaseComponent); template Ptr CreateProperty(const char* name, IsNotBaseComponent); template Ptr CreateProperty(const char* name, IsBaseComponent); private: friend class DependencyDataTest; friend class UIElementDataTest; struct DPKeyInfo { static bool IsEmpty(const Ptr& k) { return k.GetPtr() == (const DependencyProperty*)0x01; } static void MarkEmpty(const Ptr& k) { *(const DependencyProperty**)(&k) = (const DependencyProperty*)0x01; } static uint32_t HashValue(const Ptr& k) { return k->GetName(); } static uint32_t HashValue(Symbol k) { return k; } static bool IsEqual(const Ptr& lhs, const Ptr& rhs) { return !IsEmpty(lhs) && lhs->GetName() == rhs->GetName(); } static bool IsEqual(const Ptr& lhs, Symbol rhs) { return !IsEmpty(lhs) && lhs->GetName() == rhs; } }; typedef HashBucket_K, DPKeyInfo> Bucket; typedef HashSet, 0, Bucket> PropertySet; PropertySet mProperties; friend class VisualTreeInspectorHelper; NS_DECLARE_REFLECTION(DependencyData, TypeMetaData) }; NS_WARNING_POP } #include #endif