4 using System.Collections.Generic;
6 using System.Reflection;
8 namespace SiliconStudio.Paradox.UI.Events
23 var currentType = ownerType;
24 while (currentType != null)
26 if (ownerToEvents.ContainsKey(currentType) && ownerToEvents[currentType].ContainsKey(eventName))
27 return ownerToEvents[currentType][eventName];
29 currentType = currentType.GetTypeInfo().BaseType;
41 return routedEvents.ToArray();
53 var currentType = ownerType;
54 while (currentType != null)
56 types.Add(currentType);
57 currentType = currentType.GetTypeInfo().BaseType;
60 return types.Where(t => ownerToEvents.ContainsKey(t)).SelectMany(t => ownerToEvents[t].Values).ToArray();
72 public static void RegisterClassHandler<T>(Type classType,
RoutedEvent<T> routedEvent, EventHandler<T> handler,
bool handledEventsToo =
false) where T :
RoutedEventArgs
74 if (classType == null)
throw new ArgumentNullException(
"classType");
75 if (routedEvent == null)
throw new ArgumentNullException(
"routedEvent");
76 if (handler == null)
throw new ArgumentNullException(
"handler");
78 if(!classesToClassHandlers.ContainsKey(classType))
79 classesToClassHandlers[classType] =
new Dictionary<RoutedEvent, RoutedEventHandlerInfo>();
81 classesToClassHandlers[classType][routedEvent] =
new RoutedEventHandlerInfo<T>(handler, handledEventsToo);
91 internal static RoutedEventHandlerInfo GetClassHandler(Type classType,
RoutedEvent routedEvent)
93 if (classType == null)
throw new ArgumentNullException(
"classType");
94 if (routedEvent == null)
throw new ArgumentNullException(
"routedEvent");
96 var currentType = classType;
97 while (currentType != null)
99 if (classesToClassHandlers.ContainsKey(currentType) && classesToClassHandlers[currentType].ContainsKey(routedEvent))
100 return classesToClassHandlers[currentType][routedEvent];
102 currentType = currentType.GetTypeInfo().BaseType;
108 private readonly
static Dictionary<Type, Dictionary<RoutedEvent, RoutedEventHandlerInfo>> classesToClassHandlers =
new Dictionary<Type, Dictionary<RoutedEvent, RoutedEventHandlerInfo>>();
124 if (name == null)
throw new ArgumentNullException(
"name");
125 if (ownerType == null)
throw new ArgumentNullException(
"ownerType");
127 if (GetRoutedEvent(ownerType, name) != null)
128 throw new InvalidOperationException(
"A routed event named '" + name +
"' already exists in provided owner type '" + ownerType +
"' or base classes.");
131 routedEvents.Add(newRoutedEvent);
133 if(!ownerToEvents.ContainsKey(ownerType))
134 ownerToEvents[ownerType] =
new Dictionary<string, RoutedEvent>();
136 ownerToEvents[ownerType][name] = newRoutedEvent;
138 return newRoutedEvent;
141 private readonly
static List<RoutedEvent> routedEvents =
new List<RoutedEvent>();
142 private readonly
static Dictionary<Type, Dictionary<string, RoutedEvent>> ownerToEvents =
new Dictionary<Type, Dictionary<string, RoutedEvent>>();
148 internal static void ResetRegisters()
150 routedEvents.Clear();
151 ownerToEvents.Clear();
152 classesToClassHandlers.Clear();
static RoutedEvent GetRoutedEvent(Type ownerType, string eventName)
Finds the routed event identified by its name and owner.
Contains state information and event data associated with a routed event.
Provides event-related utility methods that register routed events for class owners and add class han...
static RoutedEvent[] GetRoutedEventsForOwner(Type ownerType)
Finds all routed event identifiers for events that are registered with the provided owner type...
Represents and identifies a routed event and declares its characteristics.
static RoutedEvent[] GetRoutedEvents()
Returns identifiers for routed events that have been registered to the event system.
A routed event typed with the RoutedEventArgs it triggers.
RoutingStrategy
Indicates the routing strategy of a routed event.