示例#1
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 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);
        }
示例#2
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;
        }
        // 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;
        }