Пример #1
0
        // Token: 0x06000C65 RID: 3173 RVA: 0x0002E3C0 File Offset: 0x0002C5C0
        internal static FrugalObjectList <DependencyProperty> InvalidateTreeDependentProperties(TreeChangeInfo info, FrameworkElement fe, FrameworkContentElement fce, Style selfStyle, Style selfThemeStyle, ref ChildRecord childRecord, bool isChildRecordValid, bool hasStyleChanged, bool isSelfInheritanceParent, bool wasSelfInheritanceParent)
        {
            DependencyObject dependencyObject = (fe != null) ? fe : fce;
            FrameworkObject  frameworkObject  = new FrameworkObject(fe, fce);
            FrugalObjectList <DependencyProperty> frugalObjectList = info.InheritablePropertiesStack.Peek();
            int num = (frugalObjectList != null) ? frugalObjectList.Count : 0;
            FrugalObjectList <DependencyProperty> frugalObjectList2 = null;

            if (TreeWalkHelper.HasChildren(fe, fce))
            {
                frugalObjectList2 = new FrugalObjectList <DependencyProperty>(num);
            }
            info.ResetInheritableValueIndexer();
            for (int i = 0; i < num; i++)
            {
                DependencyProperty dependencyProperty = frugalObjectList[i];
                PropertyMetadata   metadata           = dependencyProperty.GetMetadata(dependencyObject);
                if (metadata.IsInherited)
                {
                    FrameworkPropertyMetadata frameworkPropertyMetadata = (FrameworkPropertyMetadata)metadata;
                    bool flag = TreeWalkHelper.InvalidateTreeDependentProperty(info, dependencyObject, ref frameworkObject, dependencyProperty, frameworkPropertyMetadata, selfStyle, selfThemeStyle, ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent, wasSelfInheritanceParent);
                    if (flag && frugalObjectList2 != null && (!TreeWalkHelper.SkipNow(frameworkObject.InheritanceBehavior) || frameworkPropertyMetadata.OverridesInheritanceBehavior))
                    {
                        frugalObjectList2.Add(dependencyProperty);
                    }
                }
            }
            return(frugalObjectList2);
        }
Пример #2
0
        public IEnumerable <NameFixupToken> GetRemainingSimpleFixups()
        {
            foreach (object obj2 in this._dependenciesByParentObject.Keys)
            {
                this._uninitializedObjectsAtParseEnd.Add(obj2);
            }
            List <string> iteratorVariable0 = new List <string>(this._dependenciesByName.Keys);

            foreach (string iteratorVariable1 in iteratorVariable0)
            {
                FrugalObjectList <NameFixupToken> iteratorVariable2 = this._dependenciesByName[iteratorVariable1];
                int index = 0;
                while (index < iteratorVariable2.Count)
                {
                    NameFixupToken token = iteratorVariable2[index];
                    if (!token.CanAssignDirectly)
                    {
                        index++;
                        continue;
                    }
                    iteratorVariable2.RemoveAt(index);
                    if (iteratorVariable2.Count == 0)
                    {
                        this._dependenciesByName.Remove(iteratorVariable1);
                    }
                    this.RemoveTokenByParent(token);
                    yield return(token);
                }
            }
        }
Пример #3
0
        // Returns a RoutedEvents that match
        // the ownerType input param
        // If not found returns null
        internal static RoutedEvent[] GetRoutedEventsForOwner(Type ownerType)
        {
            if ((ownerType == typeof(DependencyObject)) || ownerType.IsSubclassOf(typeof(DependencyObject)))
            {
                // Search DTypeMap
                DependencyObjectType dType = DependencyObjectType.FromSystemTypeInternal(ownerType);

                // Get the ItemList of RoutedEvents for the given DType
                FrugalObjectList <RoutedEvent> ownerRoutedEventList = (FrugalObjectList <RoutedEvent>)_dTypedRoutedEventList[dType];
                if (ownerRoutedEventList != null)
                {
                    return(ownerRoutedEventList.ToArray());
                }
            }
            else // Search Hashtable
            {
                // Get the ItemList of RoutedEvents for the given OwnerType
                FrugalObjectList <RoutedEvent> ownerRoutedEventList = (FrugalObjectList <RoutedEvent>)_ownerTypedRoutedEventList[ownerType];
                if (ownerRoutedEventList != null)
                {
                    return(ownerRoutedEventList.ToArray());
                }
            }

            // No match found
            return(null);
        }
Пример #4
0
        // At end of parse, removes and returns all remaining simple fixups, whether or not they
        // are resolved
        public IEnumerable <NameFixupToken> GetRemainingSimpleFixups()
        {
            foreach (object key in _dependenciesByParentObject.Keys)
            {
                _uninitializedObjectsAtParseEnd.Add(key);
            }

            List <string> names = new List <string>(_dependenciesByName.Keys);

            foreach (string name in names)
            {
                FrugalObjectList <NameFixupToken> dependencies = _dependenciesByName[name];
                int i = 0;
                while (i < dependencies.Count)
                {
                    NameFixupToken token = dependencies[i];
                    if (!token.CanAssignDirectly)
                    {
                        i++;
                        continue;
                    }
                    dependencies.RemoveAt(i);
                    if (dependencies.Count == 0)
                    {
                        _dependenciesByName.Remove(name);
                    }
                    RemoveTokenByParent(token);
                    yield return(token);
                }
            }
        }
Пример #5
0
        internal void InitLocalizabilityCache()
        {
            _assemblyNames            = new FrugalObjectList <string>();
            _classNameToAssemblyIndex = new Hashtable(8);

            _classAttributeTable    = new Dictionary <string, ElementLocalizability> (8);
            _propertyAttributeTable = new Dictionary <string, LocalizabilityAttribute> (8);

            // 8 cached values for comments. Slots are reused in round-robin fashion
            _comments      = new ElementComments[8];
            _commentsIndex = 0;

            XmlDocument doc = null;

            if (_commentingText != null)
            {
                doc = new XmlDocument();

                try {
                    doc.Load(_commentingText);
                }catch (XmlException)
                {
                    RaiseErrorNotifyEvent(
                        new BamlLocalizerErrorNotifyEventArgs(
                            new BamlLocalizableResourceKey(string.Empty, string.Empty, string.Empty),
                            BamlLocalizerError.InvalidCommentingXml
                            )
                        );

                    doc = null;
                }
            }
            _commentsDocument = doc;
        }
Пример #6
0
        internal static void AddOwner(RoutedEvent routedEvent, Type ownerType)
        {
            // If the ownerType is a subclass of DependencyObject
            // we map it to a DType use DTypeMap for storage else
            // we use the more generic Hashtable.
            if ((ownerType == typeof(DependencyObject)) || ownerType.IsSubclassOf(typeof(DependencyObject)))
            {
                DependencyObjectType dType = DependencyObjectType.FromSystemTypeInternal(ownerType);

                // Get the ItemList of RoutedEvents for the given OwnerType
                // Requires GlobalLock to access _dTypedRoutedEventList
                object ownerRoutedEventListObj = _dTypedRoutedEventList[dType];
                FrugalObjectList <RoutedEvent> ownerRoutedEventList;
                if (ownerRoutedEventListObj == null)
                {
                    // Create an ItemList of RoutedEvents for the
                    // given OwnerType if one does not already exist
                    ownerRoutedEventList          = new FrugalObjectList <RoutedEvent>(1);
                    _dTypedRoutedEventList[dType] = ownerRoutedEventList;
                }
                else
                {
                    ownerRoutedEventList = (FrugalObjectList <RoutedEvent>)ownerRoutedEventListObj;
                }

                // Add the newly created
                // RoutedEvent to the ItemList
                // Requires GlobalLock to access ownerRoutedEventList
                if (!ownerRoutedEventList.Contains(routedEvent))
                {
                    ownerRoutedEventList.Add(routedEvent);
                }
            }
            else
            {
                // Get the ItemList of RoutedEvents for the given OwnerType
                // Requires GlobalLock to access _ownerTypedRoutedEventList
                object ownerRoutedEventListObj = _ownerTypedRoutedEventList[ownerType];
                FrugalObjectList <RoutedEvent> ownerRoutedEventList;
                if (ownerRoutedEventListObj == null)
                {
                    // Create an ItemList of RoutedEvents for the
                    // given OwnerType if one does not already exist
                    ownerRoutedEventList = new FrugalObjectList <RoutedEvent>(1);
                    _ownerTypedRoutedEventList[ownerType] = ownerRoutedEventList;
                }
                else
                {
                    ownerRoutedEventList = (FrugalObjectList <RoutedEvent>)ownerRoutedEventListObj;
                }

                // Add the newly created
                // RoutedEvent to the ItemList
                // Requires GlobalLock to access ownerRoutedEventList
                if (!ownerRoutedEventList.Contains(routedEvent))
                {
                    ownerRoutedEventList.Add(routedEvent);
                }
            }
        }
        /// <summary>
        ///     Adds a routed event handler for the given
        ///     RoutedEvent to the store
        /// </summary>
        public void AddRoutedEventHandler(
            RoutedEvent routedEvent,
            Delegate handler,
            bool handledEventsToo)
        {
            if (routedEvent == null)
            {
                throw new ArgumentNullException("routedEvent");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            if (!routedEvent.IsLegalHandler(handler))
            {
                throw new ArgumentException(SR.Get(SRID.HandlerTypeIllegal));
            }

            // Create a new RoutedEventHandler
            RoutedEventHandlerInfo routedEventHandlerInfo =
                new RoutedEventHandlerInfo(handler, handledEventsToo);

            // Get the entry corresponding to the given RoutedEvent
            FrugalObjectList <RoutedEventHandlerInfo> handlers = (FrugalObjectList <RoutedEventHandlerInfo>) this[routedEvent];

            if (handlers == null)
            {
                _entries[routedEvent.GlobalIndex] = handlers = new FrugalObjectList <RoutedEventHandlerInfo>(1);
            }

            // Add the RoutedEventHandlerInfo to the list
            handlers.Add(routedEventHandlerInfo);
        }
Пример #8
0
        public string propertyName;         // the real name - could be "Width"

        public SourceValueInfo(SourceValueType t, DrillIn d, string n)
        {
            type = t;
            drillIn = d;
            name = n;
            paramList = null;
            propertyName = null;
        }
Пример #9
0
 public SourceValueInfo(SourceValueType t, DrillIn d, FrugalObjectList<IndexerParamInfo> list)
 {
     type = t;
     drillIn = d;
     name = null;
     paramList = list;
     propertyName = null;
 }
Пример #10
0
 public SourceValueInfo(SourceValueType t, DrillIn d, FrugalObjectList <IndexerParamInfo> list)
 {
     type         = t;
     drillIn      = d;
     name         = null;
     paramList    = list;
     propertyName = null;
 }
Пример #11
0
        public string                              propertyName; // the real name - could be "Width"

        public SourceValueInfo(SourceValueType t, DrillIn d, string n)
        {
            type         = t;
            drillIn      = d;
            name         = n;
            paramList    = null;
            propertyName = null;
        }
Пример #12
0
        internal void OnAncestorChangedInternal(TreeChangeInfo parentTreeState)
        {
            // Cache the IsSelfInheritanceParent flag
            bool wasSelfInheritanceParent = IsSelfInheritanceParent;

            if (parentTreeState.Root != this)
            {
                // Clear the HasStyleChanged flag
                HasStyleChanged     = false;
                HasStyleInvalidated = false;
            }

            // If this is a tree add operation update the ShouldLookupImplicitStyles
            // flag with respect to your parent.
            if (parentTreeState.IsAddOperation)
            {
                FrameworkObject fo =

                    new FrameworkObject(null, this);
                fo.SetShouldLookupImplicitStyles();
            }

            // Invalidate ResourceReference properties
            if (HasResourceReference)
            {
                // This operation may cause a style change and hence should be done before the call to
                // InvalidateTreeDependents as it relies on the HasStyleChanged flag
                TreeWalkHelper.OnResourcesChanged(this, ResourcesChangeInfo.TreeChangeInfo, false);
            }

            // If parent is a FrameworkElement
            // This is also an operation that could change the style
            FrugalObjectList <DependencyProperty> currentInheritableProperties =
                InvalidateTreeDependentProperties(parentTreeState, IsSelfInheritanceParent, wasSelfInheritanceParent);

            // we have inherited properties that changes as a result of the above;
            // invalidation; push that list of inherited properties on the stack
            // for the children to use
            parentTreeState.InheritablePropertiesStack.Push(currentInheritableProperties);


            // Notify the PresentationSource that this element's ancestry may have changed.
            // We only need the ContentElement's because UIElements are taken care of
            // through the Visual class.
            PresentationSource.OnAncestorChanged(this);


            // Call OnAncestorChanged
            OnAncestorChanged();

            // Notify mentees if they exist
            if (PotentiallyHasMentees)
            {
                // Raise the ResourcesChanged Event so that ResourceReferenceExpressions
                // on non-[FE/FCE] listening for this can then update their values
                RaiseClrEvent(FrameworkElement.ResourcesChangedKey, EventArgs.Empty);
            }
        }
Пример #13
0
 public NameScopeDictionary(INameScope underlyingNameScope)
 {
     if (underlyingNameScope == null)
     {
         throw new ArgumentNullException("underlyingNameScope");
     }
     this._names = new FrugalObjectList <string>();
     this._underlyingNameScope = underlyingNameScope;
 }
Пример #14
0
        private static void AddToMultiDict <TKey>(Dictionary <TKey, FrugalObjectList <NameFixupToken> > dict, TKey key, NameFixupToken value)
        {
            FrugalObjectList <NameFixupToken> list;

            if (!dict.TryGetValue(key, out list))
            {
                list = new FrugalObjectList <NameFixupToken>(1);
                dict.Add(key, list);
            }
            list.Add(value);
        }
        /// <summary>
        ///     Determines whether the given
        ///     RoutedEvent exists in the store.
        /// </summary>
        /// <param name="routedEvent">
        ///     the RoutedEvent of the event.
        /// </param>

        public bool Contains(RoutedEvent routedEvent)
        {
            if (routedEvent == null)
            {
                throw new ArgumentNullException("routedEvent");
            }

            FrugalObjectList <RoutedEventHandlerInfo> handlers = (FrugalObjectList <RoutedEventHandlerInfo>) this[routedEvent];

            return(handlers != null && handlers.Count != 0);
        }
Пример #16
0
        // Returns a copy of the list of registered RoutedEvents
        // Returns a copy of the list so the original cannot be modified
        internal static RoutedEvent[] GetRoutedEvents()
        {
            RoutedEvent[] routedEvents;

            lock (Synchronized)
            {
                // Requires GlobalLock to access _countRoutedEvents
                routedEvents = new RoutedEvent[_countRoutedEvents];

                // Enumerate through all of the RoutedEvents in the DTypeMap
                // Requires GlobalLock to access _dTypedRoutedEventList
                ItemStructList <DependencyObjectType> keys = _dTypedRoutedEventList.ActiveDTypes;

                int destIndex = 0;
                for (int i = 0; i < keys.Count; i++)
                {
                    FrugalObjectList <RoutedEvent> dTypedRoutedEventList = (FrugalObjectList <RoutedEvent>)_dTypedRoutedEventList[keys.List[i]];

                    for (int j = 0; j < dTypedRoutedEventList.Count; j++)
                    {
                        RoutedEvent routedEvent = dTypedRoutedEventList[j];

                        if (Array.IndexOf(routedEvents, routedEvent) < 0)
                        {
                            routedEvents[destIndex++] = routedEvent;
                        }
                    }
                }

                // Enumerate through all of the RoutedEvents in the Hashtable
                // Requires GlobalLock to access _ownerTypedRoutedEventList
                IDictionaryEnumerator htEnumerator = _ownerTypedRoutedEventList.GetEnumerator();

                while (htEnumerator.MoveNext() == true)
                {
                    FrugalObjectList <RoutedEvent> ownerRoutedEventList = (FrugalObjectList <RoutedEvent>)htEnumerator.Value;

                    for (int j = 0; j < ownerRoutedEventList.Count; j++)
                    {
                        RoutedEvent routedEvent = ownerRoutedEventList[j];

                        if (Array.IndexOf(routedEvents, routedEvent) < 0)
                        {
                            routedEvents[destIndex++] = routedEvent;
                        }
                    }
                }
            }

            return(routedEvents);
        }
Пример #17
0
 public Enumerator(NameScopeDictionary nameScopeDictionary)
 {
     this._nameMap             = nameScopeDictionary._nameMap;
     this._underlyingNameScope = nameScopeDictionary._underlyingNameScope;
     this._names = nameScopeDictionary._names;
     if (this._underlyingNameScope != null)
     {
         this.index = -1;
     }
     else if (this._nameMap != null)
     {
         this.dictionaryEnumerator = this._nameMap.GetEnumerator();
     }
 }
Пример #18
0
        private void RemoveTokenByParent(NameFixupToken token)
        {
            object instance = token.Target.Instance;
            FrugalObjectList <NameFixupToken> list = this._dependenciesByParentObject[instance];

            if (list.Count == 1)
            {
                this._dependenciesByParentObject.Remove(instance);
            }
            else
            {
                list.Remove(token);
            }
        }
        /// <summary>
        ///     Get all the event handlers in this store for the given routed event
        /// </summary>
        public RoutedEventHandlerInfo[] GetRoutedEventHandlers(RoutedEvent routedEvent)
        {
            if (routedEvent == null)
            {
                throw new ArgumentNullException("routedEvent");
            }

            FrugalObjectList <RoutedEventHandlerInfo> handlers = this[routedEvent];

            if (handlers != null)
            {
                return(handlers.ToArray());
            }

            return(null);
        }
Пример #20
0
        private void RemoveTokenByParent(NameFixupToken token)
        {
            object parentInstance = token.Target.Instance;
            FrugalObjectList <NameFixupToken> parentDependencies = _dependenciesByParentObject[parentInstance];

            Debug.Assert(parentDependencies.Contains(token));

            if (parentDependencies.Count == 1)
            {
                _dependenciesByParentObject.Remove(parentInstance);
            }
            else
            {
                parentDependencies.Remove(token);
            }
        }
Пример #21
0
            public Enumerator(NameScopeDictionary nameScopeDictionary)
            {
                _nameMap             = nameScopeDictionary._nameMap;
                _underlyingNameScope = nameScopeDictionary._underlyingNameScope;
                _names = nameScopeDictionary._names;

                if (_underlyingNameScope != null)
                {
                    index = -1;
                }
                else
                {
                    if (_nameMap != null)
                    {
                        dictionaryEnumerator = _nameMap.GetEnumerator();
                    }
                }
            }
Пример #22
0
        // At end of parse, removes and returns all remaining reparse fixups, whether or not they
        // are resolved. Assumes that all simple fixups have already been removed.
        public IEnumerable <NameFixupToken> GetRemainingReparses()
        {
            List <object> parentObjs = new List <object>(_dependenciesByParentObject.Keys);

            foreach (object parentObj in parentObjs)
            {
                FrugalObjectList <NameFixupToken> dependencies = _dependenciesByParentObject[parentObj];
                int i = 0;
                while (i < dependencies.Count)
                {
                    NameFixupToken token = dependencies[i];
                    if (token.FixupType == FixupType.MarkupExtensionFirstRun ||
                        token.FixupType == FixupType.UnresolvedChildren)
                    {
                        i++;
                        continue;
                    }

                    // Remove this token from the _dependenciesByParentObject dictionary
                    dependencies.RemoveAt(i);
                    if (dependencies.Count == 0)
                    {
                        _dependenciesByParentObject.Remove(parentObj);
                    }

                    // Remove this token from the _dependenciesByName dictionary
                    foreach (string name in token.NeededNames)
                    {
                        FrugalObjectList <NameFixupToken> nameDependencies = _dependenciesByName[name];
                        if (nameDependencies.Count == 1)
                        {
                            nameDependencies.Remove(token);
                        }
                        else
                        {
                            _dependenciesByName.Remove(name);
                        }
                    }

                    yield return(token);
                }
            }
        }
        /// <summary>
        ///     Removes an instance of the specified
        ///     routed event handler for the given
        ///     RoutedEvent from the store
        /// </summary>
        /// <remarks>
        ///     NOTE: This method does nothing if no
        ///     matching handler instances are found
        ///     in the store
        /// </remarks>
        public void RemoveRoutedEventHandler(RoutedEvent routedEvent, Delegate handler)
        {
            if (routedEvent == null)
            {
                throw new ArgumentNullException("routedEvent");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            if (!routedEvent.IsLegalHandler(handler))
            {
                throw new ArgumentException(SR.Get(SRID.HandlerTypeIllegal));
            }

            // Get the entry corresponding to the given RoutedEvent
            FrugalObjectList <RoutedEventHandlerInfo> handlers = (FrugalObjectList <RoutedEventHandlerInfo>) this[routedEvent];

            if (handlers != null && handlers.Count > 0)
            {
                if ((handlers.Count == 1) && (handlers[0].Handler == handler))
                {
                    // this is the only handler for this event and it's being removed
                    // reclaim space in underlying FrugalMap by setting value to
                    // DependencyProperty.UnsetValue
                    _entries[routedEvent.GlobalIndex] = DependencyProperty.UnsetValue;
                }
                else
                {
                    // When a matching instance is found remove it
                    for (int i = 0; i < handlers.Count; i++)
                    {
                        if (handlers[i].Handler == handler)
                        {
                            handlers.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
        }
Пример #24
0
            internal XamlTypeMapperSchemaContext(XamlTypeMapper typeMapper)
                : base()
            {
                _typeMapper          = typeMapper;
                _sharedSchemaContext = (WpfSharedXamlSchemaContext)XamlReader.GetWpfSchemaContext();

                // Copy all the NamespaceMapEntrys from our parent into _nsDefinitions
                if (typeMapper._namespaceMaps != null)
                {
                    _nsDefinitions = new Dictionary <string, FrugalObjectList <string> >();
                    foreach (NamespaceMapEntry mapEntry in _typeMapper._namespaceMaps)
                    {
                        FrugalObjectList <string> clrNsList;
                        if (!_nsDefinitions.TryGetValue(mapEntry.XmlNamespace, out clrNsList))
                        {
                            clrNsList = new FrugalObjectList <string>(1);
                            _nsDefinitions.Add(mapEntry.XmlNamespace, clrNsList);
                        }
                        string clrNs = GetClrNsUri(mapEntry.ClrNamespace, mapEntry.AssemblyName);
                        clrNsList.Add(clrNs);
                    }
                }

                // Copy all the PIs from our parent into _piNamespaces
                if (typeMapper.PITable.Count > 0)
                {
                    _piNamespaces = new Dictionary <string, string>(typeMapper.PITable.Count);
                    foreach (DictionaryEntry entry in typeMapper.PITable)
                    {
                        ClrNamespaceAssemblyPair pair = (ClrNamespaceAssemblyPair)entry.Value;
                        string clrNs = GetClrNsUri(pair.ClrNamespace, pair.AssemblyName);
                        _piNamespaces.Add((string)entry.Key, clrNs);
                    }
                }

                _clrNamespaces = new HashSet <string>();
            }
Пример #25
0
        public IEnumerable <NameFixupToken> GetRemainingReparses()
        {
            List <object> iteratorVariable0 = new List <object>(this._dependenciesByParentObject.Keys);

            foreach (object iteratorVariable1 in iteratorVariable0)
            {
                FrugalObjectList <NameFixupToken> iteratorVariable2 = this._dependenciesByParentObject[iteratorVariable1];
                int index = 0;
                while (index < iteratorVariable2.Count)
                {
                    NameFixupToken iteratorVariable4 = iteratorVariable2[index];
                    if ((iteratorVariable4.FixupType == FixupType.MarkupExtensionFirstRun) || (iteratorVariable4.FixupType == FixupType.UnresolvedChildren))
                    {
                        index++;
                        continue;
                    }
                    iteratorVariable2.RemoveAt(index);
                    if (iteratorVariable2.Count == 0)
                    {
                        this._dependenciesByParentObject.Remove(iteratorVariable1);
                    }
                    foreach (string str in iteratorVariable4.NeededNames)
                    {
                        FrugalObjectList <NameFixupToken> list = this._dependenciesByName[str];
                        if (list.Count == 1)
                        {
                            list.Remove(iteratorVariable4);
                        }
                        else
                        {
                            this._dependenciesByName.Remove(str);
                        }
                    }
                    yield return(iteratorVariable4);
                }
            }
        }
        internal static void AddOwner(RoutedEvent routedEvent, Type ownerType)
        {
            // If the ownerType is a subclass of DependencyObject 
            // we map it to a DType use DTypeMap for storage else 
            // we use the more generic Hashtable.
            if ((ownerType == typeof(DependencyObject)) || ownerType.IsSubclassOf(typeof(DependencyObject)))
            {
                DependencyObjectType dType = DependencyObjectType.FromSystemTypeInternal(ownerType);
                
                // Get the ItemList of RoutedEvents for the given OwnerType
                // Requires GlobalLock to access _dTypedRoutedEventList
                object ownerRoutedEventListObj = _dTypedRoutedEventList[dType];
                FrugalObjectList<RoutedEvent> ownerRoutedEventList;
                if (ownerRoutedEventListObj == null)
                {
                    // Create an ItemList of RoutedEvents for the 
                    // given OwnerType if one does not already exist
                    ownerRoutedEventList = new FrugalObjectList<RoutedEvent>(1);
                    _dTypedRoutedEventList[dType] = ownerRoutedEventList;
                }
                else
                {
                    ownerRoutedEventList = (FrugalObjectList<RoutedEvent>)ownerRoutedEventListObj;
                }

                // Add the newly created 
                // RoutedEvent to the ItemList
                // Requires GlobalLock to access ownerRoutedEventList
                if(!ownerRoutedEventList.Contains(routedEvent))
                {
                    ownerRoutedEventList.Add(routedEvent);
                }
            }
            else
            {
                // Get the ItemList of RoutedEvents for the given OwnerType
                // Requires GlobalLock to access _ownerTypedRoutedEventList
                object ownerRoutedEventListObj = _ownerTypedRoutedEventList[ownerType];
                FrugalObjectList<RoutedEvent> ownerRoutedEventList;
                if (ownerRoutedEventListObj == null)
                {
                    // Create an ItemList of RoutedEvents for the 
                    // given OwnerType if one does not already exist
                    ownerRoutedEventList = new FrugalObjectList<RoutedEvent>(1);
                    _ownerTypedRoutedEventList[ownerType] = ownerRoutedEventList;
                }
                else
                {
                    ownerRoutedEventList = (FrugalObjectList<RoutedEvent>)ownerRoutedEventListObj;
                }
                
                // Add the newly created 
                // RoutedEvent to the ItemList
                // Requires GlobalLock to access ownerRoutedEventList
                if(!ownerRoutedEventList.Contains(routedEvent))
                {
                    ownerRoutedEventList.Add(routedEvent);
                }
            }
        }
Пример #27
0
 /// <summary>
 /// Create a new instance of ListenerList.
 /// </summary>
 public ListenerList()
 {
     _list = new FrugalObjectList<Listener>();
 }
Пример #28
0
        /// <summary>
        ///     Adds a routed event handler for the given 
        ///     RoutedEvent to the store
        /// </summary> 
        public void AddRoutedEventHandler( 
            RoutedEvent routedEvent,
            Delegate handler, 
            bool handledEventsToo)
        {
            if (routedEvent == null)
            { 
                throw new ArgumentNullException("routedEvent");
            } 
            if (handler == null) 
            {
                throw new ArgumentNullException("handler"); 
            }
            if (!routedEvent.IsLegalHandler(handler))
            {
                throw new ArgumentException(SR.Get(SRID.HandlerTypeIllegal)); 
            }
 
            // Create a new RoutedEventHandler 
            RoutedEventHandlerInfo routedEventHandlerInfo =
                new RoutedEventHandlerInfo(handler, handledEventsToo); 

            // Get the entry corresponding to the given RoutedEvent
            FrugalObjectList<RoutedEventHandlerInfo> handlers = (FrugalObjectList<RoutedEventHandlerInfo>)this[routedEvent];
            if (handlers == null) 
            {
                _entries[routedEvent.GlobalIndex] = handlers = new FrugalObjectList<RoutedEventHandlerInfo>(1); 
            } 

            // Add the RoutedEventHandlerInfo to the list 
            handlers.Add(routedEventHandlerInfo);
        }
Пример #29
0
 /// <summary>
 /// Create a new instance of ListenerList, with given capacity.
 /// </summary>
 public ListenerList(int capacity)
 {
     _list = new FrugalObjectList<Listener>(capacity);
 }
Пример #30
0
        void AddIndexer()
        {
            // indexer args are parsed by a (sub-) state machine with four
            // states.  The string is a comma-separated list of params, each
            // of which has two parts:  a "paren string" and a "value string"
            // (both parts are optional).  The character ^ can be used to
            // escape any of the special characters:  comma, parens, ], ^,
            // and white space.

            int start = ++_index;       // skip over initial [
            int level = 1;              // level of nested []

            bool escaped = false;       // true if current char is escaped
            bool trimRight = false;     // true if value string has trailing white space

            StringBuilder parenStringBuilder = new StringBuilder();
            StringBuilder valueStringBuilder = new StringBuilder();

            FrugalObjectList<IndexerParamInfo> paramList = new FrugalObjectList<IndexerParamInfo>();

            IndexerState state = IndexerState.BeginParam;
            while (state != IndexerState.Done)
            {
                if (_index >= _n)
                {
                    SetError(SRID.UnmatchedBracket, _path.Substring(start - 1));
                    return;
                }

                Char c = _path[_index++];

                // handle the escape character - set the flag for the next character
                if (c == EscapeChar && !escaped)
                {
                    escaped = true;
                    continue;
                }

                switch (state)
                {
                    case IndexerState.BeginParam:   // look for optional (...)
                        if (escaped)
                        {
                            // no '(', go parse the value
                            state = IndexerState.ValueString;
                            goto case IndexerState.ValueString;
                        }
                        else if (c == '(')
                        {
                            // '(' introduces optional paren string
                            state = IndexerState.ParenString;
                        }
                        else if (Char.IsWhiteSpace(c))
                        {
                            // ignore leading white space
                        }
                        else
                        {
                            // no '(', go parse the value
                            state = IndexerState.ValueString;
                            goto case IndexerState.ValueString;
                        }
                        break;

                    case IndexerState.ParenString:  // parse (...)
                        if (escaped)
                        {
                            // add an escaped character without question
                            parenStringBuilder.Append(c);
                        }
                        else if (c == ')')
                        {
                            // end of (...), start to parse value
                            state = IndexerState.ValueString;
                        }
                        else
                        {
                            // add normal characters inside (...)
                            parenStringBuilder.Append(c);
                        }
                        break;

                    case IndexerState.ValueString:  // parse value
                        if (escaped)
                        {
                            // add an escaped character without question
                            valueStringBuilder.Append(c);
                            trimRight = false;
                        }
                        else if (level > 1)
                        {
                            // inside nested [], add characters without question
                            valueStringBuilder.Append(c);
                            trimRight = false;

                            if (c == ']')
                            {
                                --level;
                            }
                        }
                        else if (Char.IsWhiteSpace(c))
                        {
                            // add white space, but trim it later if it's trailing
                            valueStringBuilder.Append(c);
                            trimRight = true;
                        }
                        else if (c == ',' || c == ']')
                        {
                            // end of current paramater - assemble the two parts
                            string parenString = parenStringBuilder.ToString();
                            string valueString = valueStringBuilder.ToString();
                            if (trimRight)
                            {
                                valueString = valueString.TrimEnd();
                            }

                            // add the parts to the final result
                            paramList.Add(new IndexerParamInfo(parenString, valueString));

                            // reset for the next parameter
                            parenStringBuilder.Length = 0;
                            valueStringBuilder.Length = 0;
                            trimRight = false;

                            // after ',' parse next parameter;  after ']' we're done
                            state = (c == ']') ? IndexerState.Done : IndexerState.BeginParam;
                        }
                        else
                        {
                            // add normal characters
                            valueStringBuilder.Append(c);
                            trimRight = false;

                            // keep track of nested []
                            if (c == '[')
                            {
                                ++level;
                            }
                        }
                        break;
                }

                // after processing each character, clear the escape flag
                escaped = false;
            }

            // assemble the final result
            SourceValueInfo info = new SourceValueInfo(
                                        SourceValueType.Indexer,
                                        _drillIn, paramList);
            _al.Add(info);

            StartNewLevel();
        }
Пример #31
0
        internal void BeginInvokeOnRender( 
            DispatcherOperationCallback callback,
            object arg) 
        {
            Debug.Assert(callback != null);

            // While technically it could be OK for the arg to be null, for now 
            // I know that arg represents the this reference for the layout
            // process and should never be null. 
            Debug.Assert(arg != null); 

            if (_invokeOnRenderCallbacks == null) 
            {
                _invokeOnRenderCallbacks = new FrugalObjectList<InvokeOnRenderCallback>();
            }
 
            _invokeOnRenderCallbacks.Add(new InvokeOnRenderCallback(callback, arg));
 
            if (!_isRendering) 
            {
                PostRender(); 
            }
        }
Пример #32
0
        // At end of parse, removes and returns all remaining MarkupExtensionFirstRun and UnresolvedChildren
        // tokens, even if they are not fully initialized. Assumes that all simple fixups and reparses have
        // already been removed.
        public IEnumerable <NameFixupToken> GetRemainingObjectDependencies()
        {
            // We'd like to return dependencies in a topologically sorted order, but the graph is
            // not acylic. (If it were, all references would have been resolved during the regular parse.)
            // However, we don't allow ProvideValue cycles. So find a MarkupExtension that doesn't have
            // dependencies on any other MarkupExtension.

            // Note: at this point we can't use _dependenciesByChildObject for general traversal,
            // because it's not updated by AddEndOfParseDependency. However, AddEndOfParseDependency
            // doesn't add MarkupExtension edges, so we can still use _dependenciesByChildObject for that.
            List <NameFixupToken> markupExtensionTokens = new List <NameFixupToken>();

            foreach (NameFixupToken curToken in _dependenciesByChildObject.Values)
            {
                if (curToken.FixupType == FixupType.MarkupExtensionFirstRun)
                {
                    markupExtensionTokens.Add(curToken);
                }
            }
            while (markupExtensionTokens.Count > 0)
            {
                bool found = false;
                int  i     = 0;
                while (i < markupExtensionTokens.Count)
                {
                    NameFixupToken        meToken      = markupExtensionTokens[i];
                    List <NameFixupToken> dependencies = new List <NameFixupToken>();
                    if (!FindDependencies(meToken, dependencies))
                    {
                        i++;
                        continue;
                    }
                    // Iterate the list in backwards order, so we return the deepest first
                    for (int j = dependencies.Count - 1; j >= 0; j--)
                    {
                        NameFixupToken token = dependencies[j];
                        RemoveTokenByParent(token);
                        yield return(token);
                    }
                    found = true;
                    markupExtensionTokens.RemoveAt(i);
                }
                if (!found)
                {
                    // We have MEs left, but they all have dependencies on other MEs.
                    // That means we have a cycle.
                    ThrowProvideValueCycle(markupExtensionTokens);
                }
            }

            // For the remaining EndInits, we pick an arbitrary point and return a DFS of its dependencies
            while (_dependenciesByParentObject.Count > 0)
            {
                FrugalObjectList <NameFixupToken> startNodeOutEdges = null;
                foreach (FrugalObjectList <NameFixupToken> list in _dependenciesByParentObject.Values)
                {
                    startNodeOutEdges = list;
                    break;
                }
                for (int i = 0; i < startNodeOutEdges.Count; i++)
                {
                    List <NameFixupToken> dependencies = new List <NameFixupToken>();
                    FindDependencies(startNodeOutEdges[i], dependencies);
                    // Iterate the list in backwards order, so we return the deepest first
                    for (int j = dependencies.Count - 1; j >= 0; j--)
                    {
                        NameFixupToken token = dependencies[j];
                        RemoveTokenByParent(token);
                        yield return(token);
                    }
                }
            }

            // Finally, if there was a deferred ProvideValue at the root, return it
            if (_deferredRootProvideValue != null)
            {
                yield return(_deferredRootProvideValue);
            }
        }
Пример #33
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);
        }
Пример #34
0
        internal void InitLocalizabilityCache()
        {
            _assemblyNames              = new FrugalObjectList<string>();
            _classNameToAssemblyIndex   = new Hashtable(8);
            
            _classAttributeTable        = new Dictionary<string, ElementLocalizability> (8);
            _propertyAttributeTable     = new Dictionary<string, LocalizabilityAttribute> (8); 

            // 8 cached values for comments. Slots are reused in round-robin fashion
            _comments         = new ElementComments[8]; 
            _commentsIndex    = 0;           

            XmlDocument doc = null;
            if (_commentingText != null)
            {
                doc = new XmlDocument();

                try {
                    doc.Load(_commentingText);
                }catch (XmlException)
                {
                    RaiseErrorNotifyEvent(
                        new BamlLocalizerErrorNotifyEventArgs(
                            new BamlLocalizableResourceKey(string.Empty, string.Empty, string.Empty),
                            BamlLocalizerError.InvalidCommentingXml
                            )
                        );
                        
                    doc = null;
                }
            }
            _commentsDocument = doc;
        }
Пример #35
0
        private void PruneContexts(FrugalObjectList<FreezableContextPair> oldList, int numDead)
        {
            int count = oldList.Count;

            if (count - numDead == 0)
            {
                RemoveContextList();
            }
            else if (numDead > 0)
            {
                FrugalObjectList<FreezableContextPair> newList =
                    new FrugalObjectList<FreezableContextPair>(count - numDead);

                for (int i = 0; i < count; i++)
                {
                    if (oldList[i].Owner.IsAlive)
                    {
                        newList.Add(oldList[i]);
                    }
                }

                ContextList = newList;
            }
        }
Пример #36
0
        /// <summary>
        /// Helper function to convert to using a list to store context information.
        /// The SingletonContext is inserted into the list.
        /// </summary>
        private void ConvertToContextList()
        {
            Debug.Assert(Freezable_UsingSingletonContext);

            // The list is initialized with capacity for 2 entries since we
            // know we have a 2nd context to insert, hence the conversion
            // from the singleton context state.
            FrugalObjectList<FreezableContextPair> list = new FrugalObjectList<FreezableContextPair>(2);

            // Note: This converts the SingletonContext from a strong reference to a WeakReference
            list.Add(new FreezableContextPair(SingletonContext, SingletonContextProperty));

            if (HasHandlers)
            {
                ((HandlerContextStorage)_contextStorage)._contextStorage = list;
            }
            else
            {
                _contextStorage = list;
            }

            Freezable_UsingContextList = true;
            Freezable_UsingSingletonContext = false;

            // clear the singleton context property
            _property = null;
        }
Пример #37
0
        /// <summary>
        /// Helper function to convert to using a list to store context information.
        /// The SingletonContext is inserted into the list.
        /// </summary>
        private void ConvertToHandlerList()
        {
            Debug.Assert(Freezable_UsingSingletonHandler);

            EventHandler singletonHandler = SingletonHandler;

            // The list is initialized with capacity for 2 entries since we
            // know we have a 2nd handler to insert, hence the conversion
            // from the singleton handler state.
            FrugalObjectList<EventHandler> list = new FrugalObjectList<EventHandler>(2);

            list.Add(singletonHandler);

            if (HasContextInformation)
            {
                ((HandlerContextStorage)_contextStorage)._handlerStorage = list;
            }
            else
            {
                _contextStorage = list;
            }

            Freezable_UsingHandlerList = true;
            Freezable_UsingSingletonHandler = 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);
        }
        [FriendAccessAllowed] // Built into Core, also used by Framework.
        internal static void ApplyAnimationClocks(
            DependencyObject d,
            DependencyProperty dp,
            IList<AnimationClock> animationClocks,
            HandoffBehavior handoffBehavior)
        {
            Debug.Assert(animationClocks != null,
                "The animationClocks parameter should not be passed in as null.");
            Debug.Assert(animationClocks.Count > 0,
                "The animationClocks parameter should contain at least one clock.");
            Debug.Assert(!animationClocks.Contains(null),
                "The animationClocks parameter should not contain a null entry.");
            Debug.Assert(HandoffBehaviorEnum.IsDefined(handoffBehavior),
                "Public API caller of this internal method is responsible for validating that the HandoffBehavior value is valid." );

            AnimationStorage storage = GetStorage(d, dp);

            // handoffBehavior is SnapshotAndReplace or the situation is such
            // that it is the equivalent because we have nothing to compose
            // with.
            if (   handoffBehavior == HandoffBehavior.SnapshotAndReplace
                || storage == null
                || storage._animationClocks == null)
            {
                if (storage != null)
                {
                    EventHandler handler = new EventHandler(storage.OnCurrentStateInvalidated);

                    // If we have a sticky snapshot value, the clock that would have
                    // unstuck it is being replaced, so we need to remove our event
                    // handler from that clock.
                    if (storage._hasStickySnapshotValue)
                    {
                        storage._animationClocks[0].CurrentStateInvalidated -= handler;
                    }
                    // Calculate a snapshot value if we don't already have one
                    // since the last tick.
                    else
                    {
                        storage._snapshotValue = d.GetValue(dp);
                    }

                    // If we have a new clock in a stopped state, then the snapshot
                    // value will be sticky.
                    if (animationClocks[0].CurrentState == ClockState.Stopped)
                    {
                        storage._hasStickySnapshotValue = true;
                        animationClocks[0].CurrentStateInvalidated += new EventHandler(storage.OnCurrentStateInvalidated);
                    }
                    // Otherwise it won't be sticky.
                    else
                    {
                        storage._hasStickySnapshotValue = false;
                    }

                    storage.ClearAnimations();
                }
                else
                {
                    storage = CreateStorage(d, dp);
                }

                // Add and attach new animation.
                storage._animationClocks = new FrugalObjectList<AnimationClock>(animationClocks.Count);

                for (int i = 0; i < animationClocks.Count; i++)
                {
                    Debug.Assert(animationClocks[i] != null);

                    storage._animationClocks.Add(animationClocks[i]);
                    storage.AttachAnimationClock(animationClocks[i], storage._removeRequestedHandler);
                }
            }
            else
            {
                Debug.Assert(handoffBehavior == HandoffBehavior.Compose);
                Debug.Assert(storage != null);
                Debug.Assert(storage._animationClocks != null);

                FrugalObjectList<AnimationClock> newClockCollection = new FrugalObjectList<AnimationClock>(storage._animationClocks.Count + animationClocks.Count);

                for (int i = 0; i < storage._animationClocks.Count; i++)
                {
                    newClockCollection.Add(storage._animationClocks[i]);
                }

                storage._animationClocks = newClockCollection;

                for (int i = 0; i < animationClocks.Count; i++)
                {
                    newClockCollection.Add(animationClocks[i]);
                    storage.AttachAnimationClock(animationClocks[i], storage._removeRequestedHandler);
                }
            }

            storage.WritePostscript();
        }
Пример #40
0
 private ListenerList(FrugalObjectList<WeakReference> list)
 {
     _list = list;
 } 
 /// <summary>
 /// Create a new instance of ListenerList.
 /// </summary>
 public ListenerList()
 {
     _list = new FrugalObjectList <Listener>();
 }
Пример #42
0
        [FriendAccessAllowed] // Built into Core, also used by Framework. 
        internal LoadedOrUnloadedOperation AddLoadedOrUnloadedCallback(
            DispatcherOperationCallback callback, 
            DependencyObject target)
        {
            LoadedOrUnloadedOperation op = new LoadedOrUnloadedOperation(callback, target);
 
            if (_loadedOrUnloadedPendingOperations == null)
            { 
                _loadedOrUnloadedPendingOperations = new FrugalObjectList<LoadedOrUnloadedOperation>(1); 
            }
 
            _loadedOrUnloadedPendingOperations.Add(op);

            return op;
        } 
 /// <summary>
 /// Create a new instance of ListenerList, with given capacity.
 /// </summary>
 public ListenerList(int capacity)
 {
     _list = new FrugalObjectList <Listener>(capacity);
 }
Пример #44
0
        /// <summary> 
        ///     Invalidate all the properties in the given
        ///     collection of inheritable properties 
        /// </summary> 
        /// <remarks>
        ///     This method is called during an [FE/FCE].OnAncestorChange 
        /// </remarks>
        internal static FrugalObjectList<DependencyProperty> InvalidateTreeDependentProperties(
            TreeChangeInfo                       info,
            FrameworkElement                     fe, 
            FrameworkContentElement              fce,
            Style                                selfStyle, 
            Style                                selfThemeStyle, 
            ref ChildRecord                      childRecord,
            bool                                 isChildRecordValid, 
            bool                                 hasStyleChanged,
            bool                                 isSelfInheritanceParent)
        {
            Debug.Assert(fe != null || fce != null, "Must have non-null current node"); 
            DependencyObject d = fe != null ? (DependencyObject)fe : (DependencyObject)fce;
            FrameworkObject fo = new FrameworkObject(fe, fce); 
 
            // Pull up the parent's InheritableProperties cache
            FrugalObjectList<DependencyProperty> parentInheritableProperties = info.InheritablePropertiesStack.Peek(); 

            // Loop through all cached inheritable
            // to see if they should be invalidated.
            int inheritablePropertiesCount = parentInheritableProperties  != null ? parentInheritableProperties.Count : 0; 

            FrugalObjectList<DependencyProperty> currentInheritableProperties = null; 
            if (HasChildren(fe, fce)) 
            {
                currentInheritableProperties = new FrugalObjectList<DependencyProperty>(inheritablePropertiesCount); 
            }

            info.ResetInheritableValueIndexer();
 
            for (int i = 0; i < inheritablePropertiesCount; i++)
            { 
                DependencyProperty inheritableProperty = parentInheritableProperties[i]; 

                Debug.Assert(inheritableProperty.IsPotentiallyInherited, "if we got here, it means that this property is inheritable by someone"); 

                PropertyMetadata metadata = inheritableProperty.GetMetadata(d);

                // Invalidate only properties that are marked as inheritable. 
                // These are the ones that will be affected by an ancestor changes.
                if (metadata.IsInherited) 
                { 
                    FrameworkPropertyMetadata fMetadata = (FrameworkPropertyMetadata)metadata;
 
                    bool changed = InvalidateTreeDependentProperty(info, d, ref fo, inheritableProperty, fMetadata,
                        selfStyle, selfThemeStyle, ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent);

                    // If a change is detected then add the inheritable property to 
                    // the current list so that it can be used to invalidate further children
                    if (changed && currentInheritableProperties != null) 
                    { 
                        Debug.Assert(!currentInheritableProperties.Contains(inheritableProperty), "InheritableProperties list should not have duplicates");
 
                        // Children do not need to inherit properties across a tree boundary
                        // unless the property is set to override this behavior.

                        if (!SkipNow(fo.InheritanceBehavior) || fMetadata.OverridesInheritanceBehavior) 
                        {
                            currentInheritableProperties.Add(inheritableProperty); 
                        } 
                    }
                } 
            }

            return currentInheritableProperties;
        } 
Пример #45
0
        //
        //  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;
        }
Пример #46
0
 // Token: 0x060007BF RID: 1983 RVA: 0x000185F8 File Offset: 0x000167F8
 private IndexerParameterInfo[] ResolveIndexerParams(FrugalObjectList <IndexerParamInfo> paramList, object context, bool throwOnError)
 {
     IndexerParameterInfo[] array = new IndexerParameterInfo[paramList.Count];
     for (int i = 0; i < array.Length; i++)
     {
         if (string.IsNullOrEmpty(paramList[i].parenString))
         {
             array[i].value = paramList[i].valueString;
         }
         else if (string.IsNullOrEmpty(paramList[i].valueString))
         {
             int num;
             if (int.TryParse(paramList[i].parenString.Trim(), NumberStyles.Integer, TypeConverterHelper.InvariantEnglishUS.NumberFormat, out num))
             {
                 if (0 <= num && num < this.PathParameters.Count)
                 {
                     object obj = this.PathParameters[num];
                     if (obj != null)
                     {
                         array[i].value = obj;
                         array[i].type  = obj.GetType();
                     }
                     else if (throwOnError)
                     {
                         throw new InvalidOperationException(SR.Get("PathParameterIsNull", new object[]
                         {
                             num
                         }));
                     }
                 }
                 else if (throwOnError)
                 {
                     throw new InvalidOperationException(SR.Get("PathParametersIndexOutOfRange", new object[]
                     {
                         num,
                         this.PathParameters.Count
                     }));
                 }
             }
             else
             {
                 array[i].value = "(" + paramList[i].parenString + ")";
             }
         }
         else
         {
             array[i].type = this.GetTypeFromName(paramList[i].parenString, context);
             if (array[i].type != null)
             {
                 object typedParamValue = this.GetTypedParamValue(paramList[i].valueString.Trim(), array[i].type, throwOnError);
                 if (typedParamValue != null)
                 {
                     array[i].value = typedParamValue;
                 }
                 else
                 {
                     if (throwOnError)
                     {
                         throw new InvalidOperationException(SR.Get("PropertyPathIndexWrongType", new object[]
                         {
                             paramList[i].parenString,
                             paramList[i].valueString
                         }));
                     }
                     array[i].type = null;
                 }
             }
             else
             {
                 array[i].value = "(" + paramList[i].parenString + ")" + paramList[i].valueString;
             }
         }
     }
     return(array);
 }
Пример #47
0
        /// <summary>
        ///     Removes a handler for the SourceChanged event to the element.
        /// </summary>
        /// <param name="e">The element to remove the handler from.</param>
        /// <param name="handler">The hander to remove.</param>
        /// <remarks>
        ///     Even though this is a routed event handler, there are special
        ///     restrictions placed on this event.
        ///     1) You cannot use the UIElement or ContentElement RemoveHandler() method.
        /// </remarks>
        public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEventHandler handler)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (!InputElement.IsValid(e))
            {
                throw new ArgumentException(SR.Get(SRID.Invalid_IInputElement), "e");
            }
            DependencyObject o = (DependencyObject)e;

            //             o.VerifyAccess();

            // I would rather throw an exception here, but the CLR doesn't
            // so we won't either.
            if (handler != null)
            {
                FrugalObjectList <RoutedEventHandlerInfo> info = null;
                EventHandlersStore store;

                // Either UIElement or ContentElement.
                if (InputElement.IsUIElement(o))
                {
                    UIElement uie = o as UIElement;
                    uie.RemoveHandler(SourceChangedEvent, handler);
                    store = uie.EventHandlersStore;
                    if (store != null)
                    {
                        info = store[SourceChangedEvent];
                    }
                    if (info == null || info.Count == 0)
                    {
                        uie.VisualAncestorChanged -= new Visual.AncestorChangedEventHandler(uie.OnVisualAncestorChanged);;
                        RemoveElementFromWatchList(uie);
                    }
                }
                else if (InputElement.IsUIElement3D(o))
                {
                    UIElement3D uie3D = o as UIElement3D;
                    uie3D.RemoveHandler(SourceChangedEvent, handler);
                    store = uie3D.EventHandlersStore;
                    if (store != null)
                    {
                        info = store[SourceChangedEvent];
                    }
                    if (info == null || info.Count == 0)
                    {
                        uie3D.VisualAncestorChanged -= new Visual.AncestorChangedEventHandler(uie3D.OnVisualAncestorChanged);;
                        RemoveElementFromWatchList(uie3D);
                    }
                }
                else
                {
                    ContentElement ce = o as ContentElement;
                    ce.RemoveHandler(SourceChangedEvent, handler);
                    store = ce.EventHandlersStore;
                    if (store != null)
                    {
                        info = store[SourceChangedEvent];
                    }
                    if (info == null || info.Count == 0)
                    {
                        RemoveElementFromWatchList(ce);
                    }
                }
            }
        }