protected override void OnApply(DependencyProperty dp, Type targetType)
 {
     doType = DependencyObjectType.FromSystemType(targetType);
     propertyChangedCallbackInternal = PropertyChangedCallback;
     PropertyChangedCallback = OnPropertyChanged;
     base.OnApply(dp, targetType);
 }
Ejemplo n.º 2
0
 internal object GetDefaultValue(DependencyObjectType dependencyObjectType)
 {
     if (!IsDefaultValueChanged)
     {
         return(DefaultMetadata.DefaultValue);
     }
     return(GetMetadata(dependencyObjectType).DefaultValue);
 }
Ejemplo n.º 3
0
 internal object GetDefaultValue(Type forType)
 {
     if (!IsDefaultValueChanged)
     {
         return(DefaultMetadata.DefaultValue);
     }
     return(GetMetadata(DependencyObjectType.FromSystemTypeInternal(forType)).DefaultValue);
 }
 public static void RemovePropertyChanged(DependencyProperty dp, DependencyObjectType type,
                                          DependencyPropertyChangedEventHandler handler)
 {
     var hcpm = dp.GetMetadata(type) as HandleChangesPropertyMetadata;
     if (hcpm == null)
         throw new ArgumentException();
     hcpm.RemovePropertyChanged(type, handler);
 }
Ejemplo n.º 5
0
 /// <summary>Returns the metadata for this dependency property as it exists on a specified existing type. </summary>
 /// <returns>A property metadata object.</returns>
 /// <param name="forType">The specific type from which to retrieve the dependency property metadata.</param>
 public PropertyMetadata GetMetadata(Type forType)
 {
     if (forType != null)
     {
         return(GetMetadata(DependencyObjectType.FromSystemType(forType)));
     }
     throw new ArgumentNullException("forType");
 }
Ejemplo n.º 6
0
 public PropertyMetadata GetMetadata(DependencyObjectType dependencyObjectType)
 {
     if (metadataByType.ContainsKey(dependencyObjectType.SystemType))
     {
         return(metadataByType[dependencyObjectType.SystemType]);
     }
     return(null);
 }
Ejemplo n.º 7
0
        // Returns the list of class listeners for the given
        // DType and RoutedEvent
        // NOTE: Returns null if no matches found
        // Helper method for GetClassListeners
        // Invoked only when trying to build the event route
        internal static RoutedEventHandlerInfoList GetDTypedClassListeners(
            DependencyObjectType dType,
            RoutedEvent routedEvent)
        {
            ClassHandlersStore classListenersLists;
            int index;

            // Class Forwarded
            return(GetDTypedClassListeners(dType, routedEvent, out classListenersLists, out index));
        }
		public static DependencyObjectType FromSystemType(Type systemType)
		{
			if (typeMap.ContainsKey (systemType))
				return typeMap[systemType];

			DependencyObjectType dot;

			typeMap[systemType] = dot = new DependencyObjectType (current_id++, systemType);

			return dot;
		}
        public static DependencyObjectType FromSystemType(Type systemType)
        {
            if (typeMap.ContainsKey(systemType))
            {
                return(typeMap[systemType]);
            }

            DependencyObjectType dot;

            typeMap[systemType] = dot = new DependencyObjectType(current_id++, systemType);

            return(dot);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Parameter validation for OverrideMetadata, includes code to force
        /// all base classes of "forType" to register their metadata so we know
        /// what we are overriding.
        /// </summary>
        private void SetupOverrideMetadata(
            Type forType,
            PropertyMetadata typeMetadata,
            out DependencyObjectType dType,
            out PropertyMetadata baseMetadata)
        {
            if (forType == null)
            {
                throw new ArgumentNullException("forType");
            }

            if (typeMetadata == null)
            {
                throw new ArgumentNullException("typeMetadata");
            }

            if (typeMetadata.Sealed)
            {
                throw new ArgumentException(SR.TypeMetadataAlreadyInUse);
            }

            if (!typeof(DependencyObject).IsAssignableFrom(forType))
            {
                throw new ArgumentException(SR.Format(SR.TypeMustBeDependencyObjectDerived, forType.Name));
            }

            // Ensure default value is a correct value (if it was supplied,
            // otherwise, the default value will be taken from the base metadata
            // which was already validated)
            if (typeMetadata.IsDefaultValueModified)
            {
                // Will throw ArgumentException if fails.
                ValidateMetadataDefaultValue(typeMetadata, PropertyType, Name, ValidateValueCallback);
            }

            // Force all base classes to register their metadata
            dType = DependencyObjectType.FromSystemType(forType);

            // Get metadata for the base type
            baseMetadata = GetMetadata(dType.BaseType);

            // Make sure overriding metadata is the same type or derived type of
            // the base metadata
            if (!baseMetadata.GetType().IsAssignableFrom(typeMetadata.GetType()))
            {
                throw new ArgumentException(SR.OverridingMetadataDoesNotMatchBaseMetadataType);
            }
        }
Ejemplo n.º 11
0
 /// <summary> Returns the metadata for this dependency property as it exists on a specified type. </summary>
 /// <returns>A property metadata object.</returns>
 /// <param name="dependencyObjectType">A specific object that records the dependency object type from which the dependency property metadata is desired.</param>
 public PropertyMetadata GetMetadata(DependencyObjectType dependencyObjectType)
 {
     if (dependencyObjectType != null)
     {
         int num = _metadataMap.Count - 1;
         if (num < 0)
         {
             return(_defaultMetadata);
         }
         int    key;
         object value;
         if (num == 0)
         {
             _metadataMap.GetKeyValuePair(num, out key, out value);
             while (dependencyObjectType.Id > key)
             {
                 dependencyObjectType = dependencyObjectType.BaseType;
             }
             if (key == dependencyObjectType.Id)
             {
                 return((PropertyMetadata)value);
             }
         }
         else if (dependencyObjectType.Id != 0)
         {
             do
             {
                 _metadataMap.GetKeyValuePair(num, out key, out value);
                 num--;
                 while (dependencyObjectType.Id < key && num >= 0)
                 {
                     _metadataMap.GetKeyValuePair(num, out key, out value);
                     num--;
                 }
                 while (dependencyObjectType.Id > key)
                 {
                     dependencyObjectType = dependencyObjectType.BaseType;
                 }
                 if (key == dependencyObjectType.Id)
                 {
                     return((PropertyMetadata)value);
                 }
             }while (num >= 0);
         }
     }
     return(_defaultMetadata);
 }
Ejemplo n.º 12
0
        /// <summary>
        ///     Determines whether the specifed object is an instance of the current DependencyObjectType
        /// </summary>
        /// <param name="dependencyObject">The object to compare with the current Type</param>
        /// <returns>
        ///     true if the current DependencyObjectType is in the inheritance hierarchy of the
        ///     object represented by the o parameter. false otherwise.
        /// </returns>
        public bool IsInstanceOfType(DependencyObject dependencyObject)
        {
            if (dependencyObject != null)
            {
                DependencyObjectType dType = dependencyObject.DependencyObjectType;

                do
                {
                    if (dType.Id == Id)
                    {
                        return(true);
                    }

                    dType = dType._baseDType;
                }while (dType != null);
            }
            return(false);
        }
Ejemplo n.º 13
0
        // Register a Class Handler
        // NOTE: Handler Type must be the
        // same as the one specified when
        // registering the corresponding RoutedEvent
        internal static void RegisterClassHandler(
            Type classType,
            RoutedEvent routedEvent,
            Delegate handler,
            bool handledEventsToo)
        {
            Debug.Assert(
                typeof(UIElement).IsAssignableFrom(classType) ||
                typeof(ContentElement).IsAssignableFrom(classType) ||
                typeof(UIElement3D).IsAssignableFrom(classType),
                "Class Handlers can be registered only for UIElement/ContentElement/UIElement3D and their sub types");
            Debug.Assert(routedEvent.IsLegalHandler(handler),
                         "Handler Type mismatch");

            ClassHandlersStore classListenersLists;
            int index;

            // We map the classType to a DType use DTypeMap for storage
            DependencyObjectType dType = DependencyObjectType.FromSystemTypeInternal(classType);

            // Get the updated EventHandlersStore for the given DType
            GetDTypedClassListeners(dType, routedEvent, out classListenersLists, out index);

            // Reuired to update storage
            lock (Synchronized)
            {
                // Add new routed event handler and get the updated set of handlers
                RoutedEventHandlerInfoList updatedClassListeners =
                    classListenersLists.AddToExistingHandlers(index, handler, handledEventsToo);

                // Update Sub Classes
                ItemStructList <DependencyObjectType> keys = _dTypedClassListeners.ActiveDTypes;

                for (int i = 0; i < keys.Count; i++)
                {
                    if (keys.List[i].IsSubclassOf(dType) == true)
                    {
                        classListenersLists = (ClassHandlersStore)_dTypedClassListeners[keys.List[i]];
                        classListenersLists.UpdateSubClassHandlers(routedEvent, updatedClassListeners);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     After parameters have been validated for OverrideMetadata, this
        /// method is called to actually update the data structures.
        /// </summary>
        private void ProcessOverrideMetadata(
            Type forType,
            PropertyMetadata typeMetadata,
            DependencyObjectType dType,
            PropertyMetadata baseMetadata)
        {
            // Store per-Type metadata for this property. Locks only on Write.
            // Datastructure guaranteed to be valid for non-locking readers
            lock (Synchronized)
            {
                if (DependencyProperty.UnsetValue == _metadataMap[dType.Id])
                {
                    _metadataMap[dType.Id] = typeMetadata;
                }
                else
                {
                    throw new ArgumentException(SR.Format(SR.TypeMetadataAlreadyRegistered, forType.Name));
                }
            }

            // Merge base's metadata into this metadata
            // CALLBACK
            typeMetadata.InvokeMerge(baseMetadata, this);

            // Type metadata may no longer change (calls OnApply)
            typeMetadata.Seal(this, forType);

            if (typeMetadata.IsInherited)
            {
                _packedData |= Flags.IsPotentiallyInherited;
            }

            if (typeMetadata.DefaultValueWasSet() && (typeMetadata.DefaultValue != DefaultMetadata.DefaultValue))
            {
                _packedData |= Flags.IsDefaultValueChanged;
            }

            if (typeMetadata.UsingDefaultValueFactory)
            {
                _packedData |= Flags.IsPotentiallyUsingDefaultValueFactory;
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Determines whether the current DependencyObjectType derives from the
        ///     specified DependencyObjectType
        /// </summary>
        /// <param name="dependencyObjectType">The DependencyObjectType to compare
        ///     with the current DependencyObjectType</param>
        /// <returns>
        ///     true if the DependencyObjectType represented by the dType parameter and the
        ///     current DependencyObjectType represent classes, and the class represented
        ///     by the current DependencyObjectType derives from the class represented by
        ///     c; otherwise, false. This method also returns false if dType and the
        ///     current Type represent the same class.
        /// </returns>
        public bool IsSubclassOf(DependencyObjectType dependencyObjectType)
        {
            // Check for null and return false, since this type is never a subclass of null.
            if (dependencyObjectType != null)
            {
                // A DependencyObjectType isn't considered a subclass of itself, so start with base type
                DependencyObjectType dType = _baseDType;

                while (dType != null)
                {
                    if (dType.Id == dependencyObjectType.Id)
                    {
                        return(true);
                    }

                    dType = dType._baseDType;
                }
            }
            return(false);
        }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------


        /// <summary>
        ///     Returns true if the dependency object passed to the method is a type,
        ///     subtype or implememts the interface of any of the the types contained
        ///     in this object.
        /// </summary>
        internal override bool IsBrowsable(DependencyObject d, DependencyProperty dp)
        {
            if (d == null)
            {
                throw new ArgumentNullException("d");
            }
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            // Get the dependency object type for our target type.
            // We cannot assume the user didn't do something wrong and
            // feed us a type that is not a dependency object, but that is
            // rare enough that it is worth the try/catch here rather than
            // a double IsAssignableFrom (one here, and one in DependencyObjectType).
            // We still use a flag here rather than checking for a null
            // _dTargetType so that a bad property that throws won't consistently
            // slow the system down with ArgumentExceptions.

            if (!_dTargetTypeChecked)
            {
                try
                {
                    _dTargetType = DependencyObjectType.FromSystemType(_targetType);
                }
                catch (ArgumentException)
                {
                }

                _dTargetTypeChecked = true;
            }


            if (_dTargetType != null && _dTargetType.IsInstanceOfType(d))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        // ------------------------------------------------
        // 
        // Methods
        //
        // ------------------------------------------------
 
        #region Methods
 
        /// <summary> 
        ///     Returns a resource for the given key type from the system resources collection.
        /// </summary> 
        /// <param name="key">The resource id to search for.</param>
        /// <returns>The resource if it exists, null otherwise.</returns>
        //[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking Bug: 29647
        internal static object FindThemeStyle(DependencyObjectType key) 
        {
            // Find a cached theme style 
            object resource = _themeStyleCache[key]; 
            if (resource != null)
            { 
                // Found a cached value
                if (resource == _specialNull)
                {
                    // We cached a null, set it to a real null 
                    return null; // Null resource found
                } 
 
                return resource;
            } 

            // Find the resource from the system resources collection
            resource = FindResourceInternal(key.SystemType);
 
            // The above read operation was lock free. Writing
            // to the cache will need a lock though 
            lock (ThemeDictionaryLock) 
            {
                if (resource != null) 
                {
                    // Cache the value
                    _themeStyleCache[key] = resource;
                } 
                else
                { 
                    // Record nulls so we don't bother doing lookups for them later 
                    // Any theme changes will clear these values
                    _themeStyleCache[key] = _specialNull; 
                }
            }

            return resource; 
        }
Ejemplo n.º 18
0
        public object this[DependencyObjectType dType]
        {
            get
            {
                if (dType.Id < _entryCount)
                {
                    return _entries[dType.Id];
                }
                else
                {
                    if (_overFlow != null)
                    {
                        return _overFlow[dType];
                    }

                    return null;
                }
            }

            set
            {
                if (dType.Id < _entryCount)
                {
                    _entries[dType.Id] = value;
                }
                else
                {
                    if (_overFlow == null)
                    {
                        _overFlow = new Hashtable();
                    }

                    _overFlow[dType] = value;
                }

                _activeDTypes.Add(dType);
            }
        }
 public bool IsSubclassOf(DependencyObjectType dependencyObjectType)
 {
     return systemType.IsSubclassOf (dependencyObjectType.SystemType);
 }
        /// <summary>
        /// Reteive metadata for a DependencyObject type described by the
        /// given DependencyObjectType
        /// </summary>
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.LinkDemand, PublicKey = BuildInfo.WCP_PUBLIC_KEY_STRING)]
        public PropertyMetadata GetMetadata(DependencyObjectType dependencyObjectType)
        {
            // All static constructors for this DType and all base types have already
            // been run. If no overriden metadata was provided, then look up base types.
            // If no metadata found on base types, then return default

            if (null != dependencyObjectType)
            {
                // Do we in fact have any overrides at all?
                int index = _metadataMap.Count - 1;
                int Id;
                object value;

                if (index < 0)
                {
                    // No overrides or it's the base class
                    return _defaultMetadata;
                }
                else if (index == 0)
                {
                    // Only 1 override
                    _metadataMap.GetKeyValuePair(index, out Id, out value);

                    // If there is overriden metadata, then there is a base class with
                    // lower or equal Id of this class, or this class is already a base class
                    // of the overridden one. Therefore dependencyObjectType won't ever
                    // become null before we exit the while loop
                    while (dependencyObjectType.Id > Id)
                    {
                        dependencyObjectType = dependencyObjectType.BaseType;
                    }

                    if (Id == dependencyObjectType.Id)
                    {
                        // Return the override
                        return (PropertyMetadata)value;
                    }
                    // Return default metadata
                }
                else
                {
                    // We have more than 1 override for this class, so we will have to loop through
                    // both the overrides and the class Id
                    if (0 != dependencyObjectType.Id)
                    {
                        do
                        {
                            // Get the Id of the most derived class with overridden metadata
                            _metadataMap.GetKeyValuePair(index, out Id, out value);
                            --index;

                            // If the Id of this class is less than the override, then look for an override
                            // with an equal or lower Id until we run out of overrides
                            while ((dependencyObjectType.Id < Id) && (index >= 0))
                            {
                                _metadataMap.GetKeyValuePair(index, out Id, out value);
                                --index;
                            }

                            // If there is overriden metadata, then there is a base class with
                            // lower or equal Id of this class, or this class is already a base class
                            // of the overridden one. Therefore dependencyObjectType won't ever
                            // become null before we exit the while loop
                            while (dependencyObjectType.Id > Id)
                            {
                                dependencyObjectType = dependencyObjectType.BaseType;
                            }

                            if (Id == dependencyObjectType.Id)
                            {
                                // Return the override
                                return (PropertyMetadata)value;
                            }
                        }
                        while (index >= 0);
                    }
                }
            }
            return _defaultMetadata;
        }
        // The caller must wrap this routine inside a locked block.
        //  This recursive routine manipulates the static hashtable DTypeFromCLRType
        //  and it must not be allowed to do this across multiple threads
        //  simultaneously.
        private static DependencyObjectType FromSystemTypeRecursive(Type systemType)
        {
            DependencyObjectType dType;

            // Map a CLR Type to a DependencyObjectType
            if (!DTypeFromCLRType.TryGetValue(systemType, out dType))
            {
                // No DependencyObjectType found, create
                dType = new DependencyObjectType();

                // Store CLR type
                dType._systemType = systemType;

                // Store reverse mapping
                DTypeFromCLRType[systemType] = dType;

                // Establish base DependencyObjectType and base property count
                if (systemType != typeof(DependencyObject))
                {
                    // Get base type
                    dType._baseDType = FromSystemTypeRecursive(systemType.BaseType);
                }

                // Store DependencyObjectType zero-based Id
                dType._id = DTypeCount++;
            }

            return dType;
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes the <see cref="LineSeries2D"/> class.
 /// </summary>
 static LineSeries2D()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
 public PropertyMetadata GetMetadata(DependencyObjectType type)
 {
   return GetMetadata(type.SystemType);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Initializes the <see cref="SeriesPoint"/> class.
 /// </summary>
 static SeriesPoint()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
Ejemplo n.º 25
0
 static ContentControl()
 {
     FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof (ContentControl), (PropertyMetadata) new FrameworkPropertyMetadata((object) typeof (ContentControl)));
       ContentControl._dType = DependencyObjectType.FromSystemTypeInternal(typeof (ContentControl));
 }
        /// <summary>
        ///     Parameter validation for OverrideMetadata, includes code to force
        /// all base classes of "forType" to register their metadata so we know
        /// what we are overriding.
        /// </summary>
        private void SetupOverrideMetadata(
                Type forType,
                PropertyMetadata typeMetadata,
            out DependencyObjectType dType,
            out PropertyMetadata baseMetadata )
        {
            if (forType == null)
            {
                throw new ArgumentNullException("forType");
            }

            if (typeMetadata == null)
            {
                throw new ArgumentNullException("typeMetadata");
            }

            if (typeMetadata.Sealed)
            {
                throw new ArgumentException(SR.Get(SRID.TypeMetadataAlreadyInUse));
            }

            if (!typeof(DependencyObject).IsAssignableFrom(forType))
            {
                throw new ArgumentException(SR.Get(SRID.TypeMustBeDependencyObjectDerived, forType.Name));
            }

            // Ensure default value is a correct value (if it was supplied,
            // otherwise, the default value will be taken from the base metadata
            // which was already validated)
            if (typeMetadata.IsDefaultValueModified)
            {
                // Will throw ArgumentException if fails.
                ValidateMetadataDefaultValue( typeMetadata, PropertyType, Name, ValidateValueCallback );
            }

            // Force all base classes to register their metadata
            dType = DependencyObjectType.FromSystemType(forType);

            // Get metadata for the base type
            baseMetadata = GetMetadata(dType.BaseType);

            // Make sure overriding metadata is the same type or derived type of
            // the base metadata
            if (!baseMetadata.GetType().IsAssignableFrom(typeMetadata.GetType()))
            {
                throw new ArgumentException(SR.Get(SRID.OverridingMetadataDoesNotMatchBaseMetadataType));
            }
        }
        /// <summary>
        ///     After parameters have been validated for OverrideMetadata, this
        /// method is called to actually update the data structures.
        /// </summary>
        private void ProcessOverrideMetadata(
            Type forType,
            PropertyMetadata typeMetadata,
            DependencyObjectType dType,
            PropertyMetadata baseMetadata)
        {
            // Store per-Type metadata for this property. Locks only on Write.
            // Datastructure guaranteed to be valid for non-locking readers
            lock (Synchronized)
            {
                if (DependencyProperty.UnsetValue == _metadataMap[dType.Id])
                {
                    _metadataMap[dType.Id] = typeMetadata;
                }
                else
                {
                    throw new ArgumentException(SR.Get(SRID.TypeMetadataAlreadyRegistered, forType.Name));
                }
           }

            // Merge base's metadata into this metadata
            // CALLBACK
            typeMetadata.InvokeMerge(baseMetadata, this);

            // Type metadata may no longer change (calls OnApply)
            typeMetadata.Seal(this, forType);

            if (typeMetadata.IsInherited)
            {
                _packedData |= Flags.IsPotentiallyInherited;
            }

            if (typeMetadata.DefaultValueWasSet() && (typeMetadata.DefaultValue != DefaultMetadata.DefaultValue))
            {
                _packedData |= Flags.IsDefaultValueChanged;
            }

            if (typeMetadata.UsingDefaultValueFactory)
            {
                _packedData |= Flags.IsPotentiallyUsingDefaultValueFactory;
            }
        }
Ejemplo n.º 28
0
 static AnimatedImage()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
Ejemplo n.º 29
0
 private void ProcessOverrideMetadata(Type forType, PropertyMetadata typeMetadata, DependencyObjectType dType, PropertyMetadata baseMetadata)
 {
     lock (Synchronized) {
         if (UnsetValue != _metadataMap[dType.Id])
         {
             throw new ArgumentException(SR.Get("TypeMetadataAlreadyRegistered", forType.Name));
         }
         _metadataMap[dType.Id] = typeMetadata;
     }
     typeMetadata.InvokeMerge(baseMetadata, this);
     typeMetadata.Seal(this, forType);
     if (typeMetadata.IsInherited)
     {
         _packedData |= Flags.IsPotentiallyInherited;
     }
     if (typeMetadata.DefaultValueWasSet() && typeMetadata.DefaultValue != DefaultMetadata.DefaultValue)
     {
         _packedData |= Flags.IsDefaultValueChanged;
     }
     if (typeMetadata.UsingDefaultValueFactory)
     {
         _packedData |= Flags.IsPotentiallyUsingDefaultValueFactory;
     }
 }
Ejemplo n.º 30
0
 private void SetupOverrideMetadata(Type forType, PropertyMetadata typeMetadata, out DependencyObjectType dType, out PropertyMetadata baseMetadata)
 {
     if (forType == null)
     {
         throw new ArgumentNullException("forType");
     }
     if (typeMetadata == null)
     {
         throw new ArgumentNullException("typeMetadata");
     }
     if (typeMetadata.Sealed)
     {
         throw new ArgumentException(SR.Get("TypeMetadataAlreadyInUse"));
     }
     if (!typeof(DependencyObject).IsAssignableFrom(forType))
     {
         throw new ArgumentException(SR.Get("TypeMustBeDependencyObjectDerived", forType.Name));
     }
     if (typeMetadata.IsDefaultValueModified)
     {
         ValidateMetadataDefaultValue(typeMetadata, PropertyType, Name, ValidateValueCallback);
     }
     dType        = DependencyObjectType.FromSystemType(forType);
     baseMetadata = GetMetadata(dType.BaseType);
     if (!baseMetadata.GetType().IsAssignableFrom(typeMetadata.GetType()))
     {
         throw new ArgumentException(SR.Get("OverridingMetadataDoesNotMatchBaseMetadataType"));
     }
 }
Ejemplo n.º 31
0
        // Token: 0x06000C59 RID: 3161 RVA: 0x0002DFDC File Offset: 0x0002C1DC
        internal FrugalObjectList <DependencyProperty> CreateParentInheritableProperties(DependencyObject d, DependencyObject parent, bool isAddOperation)
        {
            if (parent == null)
            {
                return(new FrugalObjectList <DependencyProperty>(0));
            }
            DependencyObjectType dependencyObjectType = d.DependencyObjectType;

            EffectiveValueEntry[] array = null;
            uint num  = 0U;
            uint num2 = 0U;

            if (!parent.IsSelfInheritanceParent)
            {
                DependencyObject inheritanceParent = parent.InheritanceParent;
                if (inheritanceParent != null)
                {
                    array = inheritanceParent.EffectiveValues;
                    num   = inheritanceParent.EffectiveValuesCount;
                    num2  = inheritanceParent.InheritableEffectiveValuesCount;
                }
            }
            else
            {
                array = parent.EffectiveValues;
                num   = parent.EffectiveValuesCount;
                num2  = parent.InheritableEffectiveValuesCount;
            }
            FrugalObjectList <DependencyProperty> frugalObjectList = new FrugalObjectList <DependencyProperty>((int)num2);

            if (num2 == 0U)
            {
                return(frugalObjectList);
            }
            this._rootInheritableValues = new InheritablePropertyChangeInfo[num2];
            int             num3            = 0;
            FrameworkObject frameworkObject = new FrameworkObject(parent);

            for (uint num4 = 0U; num4 < num; num4 += 1U)
            {
                EffectiveValueEntry effectiveValueEntry = array[(int)num4];
                DependencyProperty  dependencyProperty  = DependencyProperty.RegisteredPropertyList.List[effectiveValueEntry.PropertyIndex];
                if (dependencyProperty != null && dependencyProperty.IsPotentiallyInherited)
                {
                    PropertyMetadata metadata = dependencyProperty.GetMetadata(parent.DependencyObjectType);
                    if (metadata != null && metadata.IsInherited)
                    {
                        FrameworkPropertyMetadata frameworkPropertyMetadata = (FrameworkPropertyMetadata)metadata;
                        if (!TreeWalkHelper.SkipNow(frameworkObject.InheritanceBehavior) || frameworkPropertyMetadata.OverridesInheritanceBehavior)
                        {
                            frugalObjectList.Add(dependencyProperty);
                            EffectiveValueEntry valueEntry = d.GetValueEntry(d.LookupEntry(dependencyProperty.GlobalIndex), dependencyProperty, dependencyProperty.GetMetadata(dependencyObjectType), RequestFlags.DeferredReferences);
                            EffectiveValueEntry newEntry;
                            if (isAddOperation)
                            {
                                newEntry = effectiveValueEntry;
                                if (newEntry.BaseValueSourceInternal != BaseValueSourceInternal.Default || newEntry.HasModifiers)
                                {
                                    newEntry = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved);
                                    newEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
                                }
                            }
                            else
                            {
                                newEntry = default(EffectiveValueEntry);
                            }
                            this._rootInheritableValues[num3++] = new InheritablePropertyChangeInfo(d, dependencyProperty, valueEntry, newEntry);
                            if ((ulong)num2 == (ulong)((long)num3))
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(frugalObjectList);
        }
        // Returns the list of class listeners for the given 
        // DType and RoutedEvent
        // NOTE: Returns null if no matches found
        // Helper method for GetClassListeners
        // Invoked when trying to build the event route 
        // as well as when registering a new class handler
        internal static RoutedEventHandlerInfoList GetDTypedClassListeners(
            DependencyObjectType dType,
            RoutedEvent routedEvent,
            out ClassHandlersStore classListenersLists,
            out int index)
        {          
            // Get the ClassHandlersStore for the given DType
            classListenersLists = (ClassHandlersStore)_dTypedClassListeners[dType];
            RoutedEventHandlerInfoList handlers;
            if (classListenersLists != null)
            {
                // Get the handlers for the given DType and RoutedEvent
                index = classListenersLists.GetHandlersIndex(routedEvent);
                if (index != -1)
                {
                    handlers = classListenersLists.GetExistingHandlers(index);
                    return handlers;
                }
            }

            lock (Synchronized)
            {
                // Search the DTypeMap for the list of matching RoutedEventHandlerInfo
                handlers = GetUpdatedDTypedClassListeners(dType, routedEvent, out classListenersLists, out index);
            }        
            
            return handlers;
        }
Ejemplo n.º 33
0
 public PropertyMetadata GetMetadata(DependencyObjectType type)
 {
     return(GetMetadata(type.SystemType));
 }
 // Returns the list of class listeners for the given 
 // DType and RoutedEvent
 // NOTE: Returns null if no matches found
 // Helper method for GetClassListeners
 // Invoked only when trying to build the event route
 internal static RoutedEventHandlerInfoList GetDTypedClassListeners(
     DependencyObjectType dType,
     RoutedEvent routedEvent)
 {
     ClassHandlersStore classListenersLists;
     int index;
     
     // Class Forwarded
     return GetDTypedClassListeners(dType, routedEvent, out classListenersLists, out index);
 }
 private void RemovePropertyChanged(DependencyObjectType type, DependencyPropertyChangedEventHandler handler)
 {
     if (type != doType && !type.IsSubclassOf(doType))
         throw new ArgumentException();
     handlers.RemoveHandler(type, handler);
 }
Ejemplo n.º 36
0
		public PropertyMetadata GetMetadata(DependencyObjectType dependencyObjectType)
		{
			if (metadataByType.ContainsKey (dependencyObjectType.SystemType))
				return metadataByType[dependencyObjectType.SystemType];
			return null;
		}
Ejemplo n.º 37
0
        /// <summary>
        /// Reteive metadata for a DependencyObject type described by the
        /// given DependencyObjectType
        /// </summary>
        public PropertyMetadata GetMetadata(DependencyObjectType dependencyObjectType)
        {
            // All static constructors for this DType and all base types have already
            // been run. If no overriden metadata was provided, then look up base types.
            // If no metadata found on base types, then return default

            if (null != dependencyObjectType)
            {
                // Do we in fact have any overrides at all?
                int    index = _metadataMap.Count - 1;
                int    Id;
                object value;

                if (index < 0)
                {
                    // No overrides or it's the base class
                    return(_defaultMetadata);
                }
                else if (index == 0)
                {
                    // Only 1 override
                    _metadataMap.GetKeyValuePair(index, out Id, out value);

                    // If there is overriden metadata, then there is a base class with
                    // lower or equal Id of this class, or this class is already a base class
                    // of the overridden one. Therefore dependencyObjectType won't ever
                    // become null before we exit the while loop
                    while (dependencyObjectType.Id > Id)
                    {
                        dependencyObjectType = dependencyObjectType.BaseType;
                    }

                    if (Id == dependencyObjectType.Id)
                    {
                        // Return the override
                        return((PropertyMetadata)value);
                    }
                    // Return default metadata
                }
                else
                {
                    // We have more than 1 override for this class, so we will have to loop through
                    // both the overrides and the class Id
                    if (0 != dependencyObjectType.Id)
                    {
                        do
                        {
                            // Get the Id of the most derived class with overridden metadata
                            _metadataMap.GetKeyValuePair(index, out Id, out value);
                            --index;

                            // If the Id of this class is less than the override, then look for an override
                            // with an equal or lower Id until we run out of overrides
                            while ((dependencyObjectType.Id < Id) && (index >= 0))
                            {
                                _metadataMap.GetKeyValuePair(index, out Id, out value);
                                --index;
                            }

                            // If there is overriden metadata, then there is a base class with
                            // lower or equal Id of this class, or this class is already a base class
                            // of the overridden one. Therefore dependencyObjectType won't ever
                            // become null before we exit the while loop
                            while (dependencyObjectType.Id > Id)
                            {
                                dependencyObjectType = dependencyObjectType.BaseType;
                            }

                            if (Id == dependencyObjectType.Id)
                            {
                                // Return the override
                                return((PropertyMetadata)value);
                            }
                        }while (index >= 0);
                    }
                }
            }
            return(_defaultMetadata);
        }
Ejemplo n.º 38
0
        // Returns a RoutedEvents that match
        // the name and ownerType input params
        // If not found returns null
        internal static RoutedEvent GetRoutedEventFromName(
            string name,
            Type ownerType,
            bool includeSupers)
        {
            if ((ownerType == typeof(DependencyObject)) || ownerType.IsSubclassOf(typeof(DependencyObject)))
            {
                // Search DTypeMap
                DependencyObjectType dType = DependencyObjectType.FromSystemTypeInternal(ownerType);

                while (dType != null)
                {
                    // Get the ItemList of RoutedEvents for the given DType
                    FrugalObjectList <RoutedEvent> ownerRoutedEventList = (FrugalObjectList <RoutedEvent>)_dTypedRoutedEventList[dType];
                    if (ownerRoutedEventList != null)
                    {
                        // Check for RoutedEvent with matching name in the ItemList
                        for (int i = 0; i < ownerRoutedEventList.Count; i++)
                        {
                            RoutedEvent routedEvent = ownerRoutedEventList[i];
                            if (routedEvent.Name.Equals(name))
                            {
                                // Return if found match
                                return(routedEvent);
                            }
                        }
                    }

                    // If not found match yet check for BaseType if specified to do so
                    dType = includeSupers ? dType.BaseType : null;
                }
            }
            else
            {
                // Search Hashtable
                while (ownerType != null)
                {
                    // Get the ItemList of RoutedEvents for the given OwnerType
                    FrugalObjectList <RoutedEvent> ownerRoutedEventList = (FrugalObjectList <RoutedEvent>)_ownerTypedRoutedEventList[ownerType];
                    if (ownerRoutedEventList != null)
                    {
                        // Check for RoutedEvent with matching name in the ItemList
                        for (int i = 0; i < ownerRoutedEventList.Count; i++)
                        {
                            RoutedEvent routedEvent = ownerRoutedEventList[i];
                            if (routedEvent.Name.Equals(name))
                            {
                                // Return if found match
                                return(routedEvent);
                            }
                        }
                    }

                    // If not found match yet check for BaseType if specified to do so
                    ownerType = includeSupers?ownerType.BaseType : null;
                }
            }

            // No match found
            return(null);
        }
Ejemplo n.º 39
0
 /// <summary>
 /// Initializes the <see cref="Chart"/> class.
 /// </summary>
 static Chart()
 {
     DefaultStyleKeyProperty.OverrideMetadata(typeof(Chart), new FrameworkPropertyMetadata(typeof(Chart)));
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
Ejemplo n.º 40
0
        // Helper method for GetDTypedClassListeners
        // Returns updated list of class listeners for the given
        // DType and RoutedEvent
        // NOTE: Returns null if no matches found
        // Invoked when trying to build the event route
        // as well as when registering a new class handler
        private static RoutedEventHandlerInfoList GetUpdatedDTypedClassListeners(
            DependencyObjectType dType,
            RoutedEvent routedEvent,
            out ClassHandlersStore classListenersLists,
            out int index)
        {
            // Get the ClassHandlersStore for the given DType
            classListenersLists = (ClassHandlersStore)_dTypedClassListeners[dType];
            RoutedEventHandlerInfoList handlers;

            if (classListenersLists != null)
            {
                // Get the handlers for the given DType and RoutedEvent
                index = classListenersLists.GetHandlersIndex(routedEvent);
                if (index != -1)
                {
                    handlers = classListenersLists.GetExistingHandlers(index);
                    return(handlers);
                }
            }

            // Since matching handlers were not found at this level
            // browse base classes to check for registered class handlers
            DependencyObjectType       tempDType = dType;
            ClassHandlersStore         tempClassListenersLists = null;
            RoutedEventHandlerInfoList tempHandlers            = null;
            int tempIndex = -1;

            while (tempIndex == -1 && tempDType.Id != _dependencyObjectType.Id)
            {
                tempDType = tempDType.BaseType;
                tempClassListenersLists = (ClassHandlersStore)_dTypedClassListeners[tempDType];
                if (tempClassListenersLists != null)
                {
                    // Get the handlers for the DType and RoutedEvent
                    tempIndex = tempClassListenersLists.GetHandlersIndex(routedEvent);
                    if (tempIndex != -1)
                    {
                        tempHandlers = tempClassListenersLists.GetExistingHandlers(tempIndex);
                    }
                }
            }

            if (classListenersLists == null)
            {
                if (dType.SystemType == typeof(UIElement) || dType.SystemType == typeof(ContentElement))
                {
                    classListenersLists = new ClassHandlersStore(80); // Based on the number of class handlers for these classes
                }
                else
                {
                    classListenersLists = new ClassHandlersStore(1);
                }

                _dTypedClassListeners[dType] = classListenersLists;
            }

            index = classListenersLists.CreateHandlersLink(routedEvent, tempHandlers);

            return(tempHandlers);
        }
        // Helper method for GetDTypedClassListeners
        // Returns updated list of class listeners for the given 
        // DType and RoutedEvent
        // NOTE: Returns null if no matches found
        // Invoked when trying to build the event route 
        // as well as when registering a new class handler
        private static RoutedEventHandlerInfoList GetUpdatedDTypedClassListeners(
            DependencyObjectType dType,
            RoutedEvent routedEvent,
            out ClassHandlersStore classListenersLists,
            out int index)
        {
            // Get the ClassHandlersStore for the given DType
            classListenersLists = (ClassHandlersStore)_dTypedClassListeners[dType];
            RoutedEventHandlerInfoList handlers;
            if (classListenersLists != null)
            {
                // Get the handlers for the given DType and RoutedEvent
                index = classListenersLists.GetHandlersIndex(routedEvent);
                if (index != -1)
                {
                    handlers = classListenersLists.GetExistingHandlers(index);
                    return handlers;
                }
            }

            // Since matching handlers were not found at this level 
            // browse base classes to check for registered class handlers
            DependencyObjectType tempDType = dType;
            ClassHandlersStore tempClassListenersLists = null;
            RoutedEventHandlerInfoList tempHandlers = null;
            int tempIndex = -1;
            while (tempIndex == -1 && tempDType.Id != _dependencyObjectType.Id)
            {
                tempDType = tempDType.BaseType;
                tempClassListenersLists = (ClassHandlersStore)_dTypedClassListeners[tempDType];
                if (tempClassListenersLists != null)
                {
                    // Get the handlers for the DType and RoutedEvent
                    tempIndex = tempClassListenersLists.GetHandlersIndex(routedEvent);
                    if (tempIndex != -1)
                    {
                        tempHandlers = tempClassListenersLists.GetExistingHandlers(tempIndex);
                    }
                }
            }
        
            if (classListenersLists == null)
            {
                if (dType.SystemType == typeof(UIElement) || dType.SystemType == typeof(ContentElement))
                {
                    classListenersLists = new ClassHandlersStore(80); // Based on the number of class handlers for these classes
                }
                else
                {
                    classListenersLists = new ClassHandlersStore(1);
                }

                _dTypedClassListeners[dType] = classListenersLists;
            }

            index = classListenersLists.CreateHandlersLink(routedEvent, tempHandlers);
            
            return tempHandlers;
        }
        /// <summary>
        ///     Determines whether the current DependencyObjectType derives from the
        ///     specified DependencyObjectType
        /// </summary>
        /// <param name="dependencyObjectType">The DependencyObjectType to compare
        ///     with the current DependencyObjectType</param>
        /// <returns>
        ///     true if the DependencyObjectType represented by the dType parameter and the
        ///     current DependencyObjectType represent classes, and the class represented
        ///     by the current DependencyObjectType derives from the class represented by
        ///     c; otherwise, false. This method also returns false if dType and the
        ///     current Type represent the same class.
        /// </returns>
        public bool IsSubclassOf(DependencyObjectType dependencyObjectType)
        {
            // Check for null and return false, since this type is never a subclass of null.
            if (dependencyObjectType != null)
            {
                // A DependencyObjectType isn't considered a subclass of itself, so start with base type
                DependencyObjectType dType = _baseDType;

                while (dType != null)
                {
                    if (dType.Id == dependencyObjectType.Id)
                    {
                        return true;
                    }

                    dType = dType._baseDType;
                }
            }
            return false;
        }
        //
        //  This method
        //  1. Is called from AncestorChange InvalidateTree.
        //  2. It is used to create the InheritableProperties on the given node.
        //  3. It also accumulates oldValues for the inheritable properties that are about to be invalidated
        //
        internal FrugalObjectList <DependencyProperty> CreateParentInheritableProperties(
            DependencyObject d,
            DependencyObject parent,
            bool isAddOperation)
        {
            Debug.Assert(d != null, "Must have non-null current node");

            if (parent == null)
            {
                return(new FrugalObjectList <DependencyProperty>(0));
            }

            DependencyObjectType treeObjDOT = d.DependencyObjectType;

            // See if we have a cached value.
            EffectiveValueEntry[] parentEffectiveValues = null;
            uint parentEffectiveValuesCount             = 0;
            uint inheritablePropertiesCount             = 0;

            // If inheritable properties aren't cached on you then use the effective
            // values cache on the parent to discover those inherited properties that
            // may need to be invalidated on the children nodes.
            if (!parent.IsSelfInheritanceParent)
            {
                DependencyObject inheritanceParent = parent.InheritanceParent;
                if (inheritanceParent != null)
                {
                    parentEffectiveValues      = inheritanceParent.EffectiveValues;
                    parentEffectiveValuesCount = inheritanceParent.EffectiveValuesCount;
                    inheritablePropertiesCount = inheritanceParent.InheritableEffectiveValuesCount;
                }
            }
            else
            {
                parentEffectiveValues      = parent.EffectiveValues;
                parentEffectiveValuesCount = parent.EffectiveValuesCount;
                inheritablePropertiesCount = parent.InheritableEffectiveValuesCount;
            }

            FrugalObjectList <DependencyProperty> inheritableProperties = new FrugalObjectList <DependencyProperty>((int)inheritablePropertiesCount);

            if (inheritablePropertiesCount == 0)
            {
                return(inheritableProperties);
            }

            _rootInheritableValues = new InheritablePropertyChangeInfo[(int)inheritablePropertiesCount];
            int inheritableIndex = 0;

            FrameworkObject foParent = new FrameworkObject(parent);

            for (uint i = 0; i < parentEffectiveValuesCount; i++)
            {
                // Add all the inheritable properties from the effectiveValues
                // cache to the TreeStateCache on the parent
                EffectiveValueEntry entry = parentEffectiveValues[i];
                DependencyProperty  dp    = DependencyProperty.RegisteredPropertyList.List[entry.PropertyIndex];

                // There are UncommonFields also stored in the EffectiveValues cache. We need to exclude those.
                if ((dp != null) && dp.IsPotentiallyInherited)
                {
                    PropertyMetadata metadata = dp.GetMetadata(parent.DependencyObjectType);
                    if (metadata != null && metadata.IsInherited)
                    {
                        Debug.Assert(!inheritableProperties.Contains(dp), "EffectiveValues cache must not contains duplicate entries for the same DP");

                        FrameworkPropertyMetadata fMetadata = (FrameworkPropertyMetadata)metadata;

                        // Children do not need to inherit properties across a tree boundary
                        // unless the property is set to override this behavior.

                        if (!TreeWalkHelper.SkipNow(foParent.InheritanceBehavior) || fMetadata.OverridesInheritanceBehavior)
                        {
                            inheritableProperties.Add(dp);

                            EffectiveValueEntry oldEntry;
                            EffectiveValueEntry newEntry;

                            oldEntry = d.GetValueEntry(
                                d.LookupEntry(dp.GlobalIndex),
                                dp,
                                dp.GetMetadata(treeObjDOT),
                                RequestFlags.DeferredReferences);

                            if (isAddOperation)
                            {
                                // set up the new value
                                newEntry = entry;

                                if ((newEntry.BaseValueSourceInternal != BaseValueSourceInternal.Default) || newEntry.HasModifiers)
                                {
                                    newEntry = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved);
                                    newEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
                                }
                            }
                            else
                            {
                                newEntry = new EffectiveValueEntry();
                            }


                            _rootInheritableValues[inheritableIndex++] =
                                new InheritablePropertyChangeInfo(d, dp, oldEntry, newEntry);

                            if (inheritablePropertiesCount == inheritableIndex)
                            {
                                // no more inheritable properties, bail early
                                break;
                            }
                        }
                    }
                }
            }

            return(inheritableProperties);
        }
Ejemplo n.º 44
0
 /// <summary>
 /// Texts the box.
 /// </summary>
 static NumericTextBox()
 {
     dependencyType = DependencyObjectType.FromSystemType(typeOfThis);
 }
        [FriendAccessAllowed]   // Built into Base, also used by Core & Framework.
        internal object GetDefaultValue(DependencyObjectType dependencyObjectType)
        {
            if (!IsDefaultValueChanged)
            {
                return DefaultMetadata.DefaultValue;
            }

            return GetMetadata(dependencyObjectType).DefaultValue;
        }
 public bool IsSubclassOf(DependencyObjectType dependencyObjectType)
 {
     return(systemType.IsSubclassOf(dependencyObjectType.SystemType));
 }
Ejemplo n.º 47
0
 internal static void SetDependencyObjectType(this DependencyObject element, DependencyObjectType type)
 {
     element.SetValue(RadRoutedEventHelper.DependencyObjectTypeProperty, type);
 }