Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / MS / Internal / Automation / EventMap.cs / 1606164 / EventMap.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // Accessibility event map classes are used to determine if, and how many // listeners there are for events and property changes. // // History: // 07/23/2003 : BrendanM Ported to WCP // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Windows; using System.Windows.Automation; using System.Windows.Automation.Peers; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace MS.Internal.Automation { // Manages the event map that is used to determine if there are Automation // clients interested in specific events. internal static class EventMap { private class EventInfo { internal EventInfo() { NumberOfListeners = 1; } internal int NumberOfListeners; } // Never inline, as we don't want to unnecessarily link the automation DLL. [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] private static bool IsKnownEvent(int id) { if ( id == AutomationElementIdentifiers.ToolTipOpenedEvent.Id || id == AutomationElementIdentifiers.ToolTipClosedEvent.Id || id == AutomationElementIdentifiers.MenuOpenedEvent.Id || id == AutomationElementIdentifiers.MenuClosedEvent.Id || id == AutomationElementIdentifiers.AutomationFocusChangedEvent.Id || id == InvokePatternIdentifiers.InvokedEvent.Id || id == SelectionItemPatternIdentifiers.ElementAddedToSelectionEvent.Id || id == SelectionItemPatternIdentifiers.ElementRemovedFromSelectionEvent.Id || id == SelectionItemPatternIdentifiers.ElementSelectedEvent.Id || id == SelectionPatternIdentifiers.InvalidatedEvent.Id || id == TextPatternIdentifiers.TextSelectionChangedEvent.Id || id == TextPatternIdentifiers.TextChangedEvent.Id || id == AutomationElementIdentifiers.AsyncContentLoadedEvent.Id || id == AutomationElementIdentifiers.AutomationPropertyChangedEvent.Id || id == AutomationElementIdentifiers.StructureChangedEvent.Id || ((SynchronizedInputPatternIdentifiers.InputReachedTargetEvent != null) && (id == SynchronizedInputPatternIdentifiers.InputReachedTargetEvent.Id)) || ((SynchronizedInputPatternIdentifiers.InputReachedOtherElementEvent != null) && (id == SynchronizedInputPatternIdentifiers.InputReachedOtherElementEvent.Id)) || ((SynchronizedInputPatternIdentifiers.InputDiscardedEvent != null) && (id == SynchronizedInputPatternIdentifiers.InputDiscardedEvent.Id))) { return true; } return false; } // Never inline, as we don't want to unnecessarily link the automation DLL. [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] private static AutomationEvent GetRegisteredEventObjectHelper(AutomationEvents eventId) { AutomationEvent eventObject = null; switch(eventId) { case AutomationEvents.ToolTipOpened: eventObject = AutomationElementIdentifiers.ToolTipOpenedEvent; break; case AutomationEvents.ToolTipClosed: eventObject = AutomationElementIdentifiers.ToolTipClosedEvent; break; case AutomationEvents.MenuOpened: eventObject = AutomationElementIdentifiers.MenuOpenedEvent; break; case AutomationEvents.MenuClosed: eventObject = AutomationElementIdentifiers.MenuClosedEvent; break; case AutomationEvents.AutomationFocusChanged: eventObject = AutomationElementIdentifiers.AutomationFocusChangedEvent; break; case AutomationEvents.InvokePatternOnInvoked: eventObject = InvokePatternIdentifiers.InvokedEvent; break; case AutomationEvents.SelectionItemPatternOnElementAddedToSelection: eventObject = SelectionItemPatternIdentifiers.ElementAddedToSelectionEvent; break; case AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection: eventObject = SelectionItemPatternIdentifiers.ElementRemovedFromSelectionEvent; break; case AutomationEvents.SelectionItemPatternOnElementSelected: eventObject = SelectionItemPatternIdentifiers.ElementSelectedEvent; break; case AutomationEvents.SelectionPatternOnInvalidated: eventObject = SelectionPatternIdentifiers.InvalidatedEvent; break; case AutomationEvents.TextPatternOnTextSelectionChanged: eventObject = TextPatternIdentifiers.TextSelectionChangedEvent; break; case AutomationEvents.TextPatternOnTextChanged: eventObject = TextPatternIdentifiers.TextChangedEvent; break; case AutomationEvents.AsyncContentLoaded: eventObject = AutomationElementIdentifiers.AsyncContentLoadedEvent; break; case AutomationEvents.PropertyChanged: eventObject = AutomationElementIdentifiers.AutomationPropertyChangedEvent; break; case AutomationEvents.StructureChanged: eventObject = AutomationElementIdentifiers.StructureChangedEvent; break; case AutomationEvents.InputReachedTarget: eventObject = SynchronizedInputPatternIdentifiers.InputReachedTargetEvent; break; case AutomationEvents.InputReachedOtherElement: eventObject = SynchronizedInputPatternIdentifiers.InputReachedOtherElementEvent; break; case AutomationEvents.InputDiscarded: eventObject = SynchronizedInputPatternIdentifiers.InputDiscardedEvent; break; default: throw new ArgumentException(SR.Get(SRID.Automation_InvalidEventId), "eventId"); } if ((eventObject != null) && (!_eventsTable.ContainsKey(eventObject.Id))) { eventObject = null; } return (eventObject); } internal static void AddEvent(int idEvent) { lock (_lock) { if (_eventsTable == null) _eventsTable = new Hashtable(20, .1f); if (_eventsTable.ContainsKey(idEvent)) { EventInfo info = (EventInfo)_eventsTable[idEvent]; info.NumberOfListeners++; } // to avoid unbound memory allocations, // register only events that we recognize else if (IsKnownEvent(idEvent)) { _eventsTable[idEvent] = new EventInfo(); } } } internal static void RemoveEvent(int idEvent) { lock (_lock) { if (_eventsTable != null) { // Decrement the count of listeners for this event if (_eventsTable.ContainsKey(idEvent)) { EventInfo info = (EventInfo)_eventsTable[idEvent]; // Update or remove the entry based on remaining listeners info.NumberOfListeners--; if (info.NumberOfListeners <= 0) { _eventsTable.Remove(idEvent); // If no more entries exist kill the table if (_eventsTable.Count == 0) { _eventsTable = null; } } } } } } // Unlike GetRegisteredEvent below, // HasRegisteredEvent does NOT cause automation DLLs loading internal static bool HasRegisteredEvent(AutomationEvents eventId) { lock (_lock) { if (_eventsTable != null && _eventsTable.Count != 0) { return (GetRegisteredEventObjectHelper(eventId) != null); } } return (false); } internal static AutomationEvent GetRegisteredEvent(AutomationEvents eventId) { lock (_lock) { if (_eventsTable != null && _eventsTable.Count != 0) { return (GetRegisteredEventObjectHelper(eventId)); } } return (null); } private static Hashtable _eventsTable; // key=event id, data=listener count private readonly static object _lock = new object(); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // Accessibility event map classes are used to determine if, and how many // listeners there are for events and property changes. // // History: // 07/23/2003 : BrendanM Ported to WCP // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Windows; using System.Windows.Automation; using System.Windows.Automation.Peers; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace MS.Internal.Automation { // Manages the event map that is used to determine if there are Automation // clients interested in specific events. internal static class EventMap { private class EventInfo { internal EventInfo() { NumberOfListeners = 1; } internal int NumberOfListeners; } // Never inline, as we don't want to unnecessarily link the automation DLL. [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] private static bool IsKnownEvent(int id) { if ( id == AutomationElementIdentifiers.ToolTipOpenedEvent.Id || id == AutomationElementIdentifiers.ToolTipClosedEvent.Id || id == AutomationElementIdentifiers.MenuOpenedEvent.Id || id == AutomationElementIdentifiers.MenuClosedEvent.Id || id == AutomationElementIdentifiers.AutomationFocusChangedEvent.Id || id == InvokePatternIdentifiers.InvokedEvent.Id || id == SelectionItemPatternIdentifiers.ElementAddedToSelectionEvent.Id || id == SelectionItemPatternIdentifiers.ElementRemovedFromSelectionEvent.Id || id == SelectionItemPatternIdentifiers.ElementSelectedEvent.Id || id == SelectionPatternIdentifiers.InvalidatedEvent.Id || id == TextPatternIdentifiers.TextSelectionChangedEvent.Id || id == TextPatternIdentifiers.TextChangedEvent.Id || id == AutomationElementIdentifiers.AsyncContentLoadedEvent.Id || id == AutomationElementIdentifiers.AutomationPropertyChangedEvent.Id || id == AutomationElementIdentifiers.StructureChangedEvent.Id || ((SynchronizedInputPatternIdentifiers.InputReachedTargetEvent != null) && (id == SynchronizedInputPatternIdentifiers.InputReachedTargetEvent.Id)) || ((SynchronizedInputPatternIdentifiers.InputReachedOtherElementEvent != null) && (id == SynchronizedInputPatternIdentifiers.InputReachedOtherElementEvent.Id)) || ((SynchronizedInputPatternIdentifiers.InputDiscardedEvent != null) && (id == SynchronizedInputPatternIdentifiers.InputDiscardedEvent.Id))) { return true; } return false; } // Never inline, as we don't want to unnecessarily link the automation DLL. [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] private static AutomationEvent GetRegisteredEventObjectHelper(AutomationEvents eventId) { AutomationEvent eventObject = null; switch(eventId) { case AutomationEvents.ToolTipOpened: eventObject = AutomationElementIdentifiers.ToolTipOpenedEvent; break; case AutomationEvents.ToolTipClosed: eventObject = AutomationElementIdentifiers.ToolTipClosedEvent; break; case AutomationEvents.MenuOpened: eventObject = AutomationElementIdentifiers.MenuOpenedEvent; break; case AutomationEvents.MenuClosed: eventObject = AutomationElementIdentifiers.MenuClosedEvent; break; case AutomationEvents.AutomationFocusChanged: eventObject = AutomationElementIdentifiers.AutomationFocusChangedEvent; break; case AutomationEvents.InvokePatternOnInvoked: eventObject = InvokePatternIdentifiers.InvokedEvent; break; case AutomationEvents.SelectionItemPatternOnElementAddedToSelection: eventObject = SelectionItemPatternIdentifiers.ElementAddedToSelectionEvent; break; case AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection: eventObject = SelectionItemPatternIdentifiers.ElementRemovedFromSelectionEvent; break; case AutomationEvents.SelectionItemPatternOnElementSelected: eventObject = SelectionItemPatternIdentifiers.ElementSelectedEvent; break; case AutomationEvents.SelectionPatternOnInvalidated: eventObject = SelectionPatternIdentifiers.InvalidatedEvent; break; case AutomationEvents.TextPatternOnTextSelectionChanged: eventObject = TextPatternIdentifiers.TextSelectionChangedEvent; break; case AutomationEvents.TextPatternOnTextChanged: eventObject = TextPatternIdentifiers.TextChangedEvent; break; case AutomationEvents.AsyncContentLoaded: eventObject = AutomationElementIdentifiers.AsyncContentLoadedEvent; break; case AutomationEvents.PropertyChanged: eventObject = AutomationElementIdentifiers.AutomationPropertyChangedEvent; break; case AutomationEvents.StructureChanged: eventObject = AutomationElementIdentifiers.StructureChangedEvent; break; case AutomationEvents.InputReachedTarget: eventObject = SynchronizedInputPatternIdentifiers.InputReachedTargetEvent; break; case AutomationEvents.InputReachedOtherElement: eventObject = SynchronizedInputPatternIdentifiers.InputReachedOtherElementEvent; break; case AutomationEvents.InputDiscarded: eventObject = SynchronizedInputPatternIdentifiers.InputDiscardedEvent; break; default: throw new ArgumentException(SR.Get(SRID.Automation_InvalidEventId), "eventId"); } if ((eventObject != null) && (!_eventsTable.ContainsKey(eventObject.Id))) { eventObject = null; } return (eventObject); } internal static void AddEvent(int idEvent) { lock (_lock) { if (_eventsTable == null) _eventsTable = new Hashtable(20, .1f); if (_eventsTable.ContainsKey(idEvent)) { EventInfo info = (EventInfo)_eventsTable[idEvent]; info.NumberOfListeners++; } // to avoid unbound memory allocations, // register only events that we recognize else if (IsKnownEvent(idEvent)) { _eventsTable[idEvent] = new EventInfo(); } } } internal static void RemoveEvent(int idEvent) { lock (_lock) { if (_eventsTable != null) { // Decrement the count of listeners for this event if (_eventsTable.ContainsKey(idEvent)) { EventInfo info = (EventInfo)_eventsTable[idEvent]; // Update or remove the entry based on remaining listeners info.NumberOfListeners--; if (info.NumberOfListeners <= 0) { _eventsTable.Remove(idEvent); // If no more entries exist kill the table if (_eventsTable.Count == 0) { _eventsTable = null; } } } } } } // Unlike GetRegisteredEvent below, // HasRegisteredEvent does NOT cause automation DLLs loading internal static bool HasRegisteredEvent(AutomationEvents eventId) { lock (_lock) { if (_eventsTable != null && _eventsTable.Count != 0) { return (GetRegisteredEventObjectHelper(eventId) != null); } } return (false); } internal static AutomationEvent GetRegisteredEvent(AutomationEvents eventId) { lock (_lock) { if (_eventsTable != null && _eventsTable.Count != 0) { return (GetRegisteredEventObjectHelper(eventId)); } } return (null); } private static Hashtable _eventsTable; // key=event id, data=listener count private readonly static object _lock = new object(); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlStream.cs
- EdmEntityTypeAttribute.cs
- NetTcpBinding.cs
- ReservationNotFoundException.cs
- UnSafeCharBuffer.cs
- ClientScriptManagerWrapper.cs
- MessageRpc.cs
- PageTextBox.cs
- TableAdapterManagerMethodGenerator.cs
- ModelProperty.cs
- SelectorAutomationPeer.cs
- ToolStripDropDownMenu.cs
- Translator.cs
- XmlCollation.cs
- AutomationElement.cs
- WebSysDefaultValueAttribute.cs
- DetailsViewDeletedEventArgs.cs
- WindowsIPAddress.cs
- Reference.cs
- RecommendedAsConfigurableAttribute.cs
- PingReply.cs
- ImportCatalogPart.cs
- InvariantComparer.cs
- ProxySimple.cs
- Screen.cs
- Panel.cs
- objectresult_tresulttype.cs
- TrustLevel.cs
- XmlSchemaAttributeGroup.cs
- ReadContentAsBinaryHelper.cs
- EntityDataSourceStatementEditor.cs
- ConfigurationSectionCollection.cs
- XmlSchemaException.cs
- EndSelectCardRequest.cs
- DataSourceListEditor.cs
- SecurityUtils.cs
- FrameworkEventSource.cs
- TypeUtils.cs
- BooleanAnimationUsingKeyFrames.cs
- DurableOperationAttribute.cs
- WriteTimeStream.cs
- DbConvert.cs
- Scheduler.cs
- Quaternion.cs
- ListBox.cs
- TransactionChannelFactory.cs
- DesignSurfaceManager.cs
- RichTextBox.cs
- VariableBinder.cs
- GenericPrincipal.cs
- SByte.cs
- Encoder.cs
- GenericTextProperties.cs
- MarkupProperty.cs
- ReliableChannelFactory.cs
- EventWaitHandleSecurity.cs
- GroupQuery.cs
- ToolZone.cs
- ImageFormatConverter.cs
- SystemDiagnosticsSection.cs
- CellNormalizer.cs
- ObjectContextServiceProvider.cs
- DataGridComboBoxColumn.cs
- ReadOnlyTernaryTree.cs
- AssemblyResourceLoader.cs
- Source.cs
- SqlDataSource.cs
- Sentence.cs
- UshortList2.cs
- PartialCachingAttribute.cs
- NetworkInformationException.cs
- WebPartManagerInternals.cs
- AbandonedMutexException.cs
- DocumentViewerAutomationPeer.cs
- BuildProvidersCompiler.cs
- DataFormat.cs
- AuthenticationException.cs
- IdnElement.cs
- EventlogProvider.cs
- Select.cs
- SimpleBitVector32.cs
- HttpVersion.cs
- MetafileHeaderWmf.cs
- XsltCompileContext.cs
- ISFClipboardData.cs
- PropertyGroupDescription.cs
- TrackingParameters.cs
- XmlMapping.cs
- ControlCollection.cs
- TimelineGroup.cs
- ConfigurationElement.cs
- DesignSurfaceServiceContainer.cs
- BaseResourcesBuildProvider.cs
- PersonalizableTypeEntry.cs
- GPRECT.cs
- documentation.cs
- CqlLexerHelpers.cs
- Inflater.cs
- MethodBuilder.cs
- HttpListenerResponse.cs