Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Core / System / Windows / Automation / Peers / UIElementAutomationPeer.cs / 3 / UIElementAutomationPeer.cs
using System; using System.Security; using System.Windows; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Collections.Generic; using MS.Internal; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace System.Windows.Automation.Peers { /// public class UIElementAutomationPeer: AutomationPeer { /// public UIElementAutomationPeer(UIElement owner) { if(owner == null) { throw new ArgumentNullException("owner"); } _owner = owner; } /// public UIElement Owner { get { return _owner; } } ////// This static helper creates an AutomationPeer for the specified element and /// caches it - that means the created peer is going to live long and shadow the /// element for its lifetime. The peer will be used by Automation to proxy the element, and /// to fire events to the Automation when something happens with the element. /// The created peer is returned from this method and also from subsequent calls to this method /// and public static AutomationPeer CreatePeerForElement(UIElement element) { if(element == null) { throw new ArgumentNullException("element"); } return element.CreateAutomationPeer(); } /// public static AutomationPeer FromElement(UIElement element) { if(element == null) { throw new ArgumentNullException("element"); } return element.GetAutomationPeer(); } /// override protected List. The type of the peer is determined by the /// virtual callback. If UIElement does not /// implement the callback, there will be no peer and this method will return 'null' (in other /// words, there is no such thing as a 'default peer'). /// GetChildrenCore() { List children = null; iterate(_owner, (IteratorCallback)delegate(AutomationPeer peer) { if (children == null) children = new List (); children.Add(peer); return (false); }); return children; } /// /// /// Critical - Calls critical AutomationPeer.Hwnd setter. /// [SecurityCritical] internal static AutomationPeer GetRootAutomationPeer(Visual rootVisual, IntPtr hwnd) { AutomationPeer root = null; iterate(rootVisual, (IteratorCallback)delegate(AutomationPeer peer) { root = peer; return (true); }); if (root != null) { root.Hwnd = hwnd; } return root; } private delegate bool IteratorCallback(AutomationPeer peer); // private static bool iterate(DependencyObject parent, IteratorCallback callback) { bool done = false; if(parent != null) { AutomationPeer peer = null; int count = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < count && !done; i++) { DependencyObject child = VisualTreeHelper.GetChild(parent, i); if( child != null && child is UIElement && (peer = CreatePeerForElement((UIElement)child)) != null ) { done = callback(peer); } else if ( child != null && child is UIElement3D && (peer = UIElement3DAutomationPeer.CreatePeerForElement(((UIElement3D)child))) != null ) { done = callback(peer); } else { done = iterate(child, callback); } } } return done; } /// override public object GetPattern(PatternInterface patternInterface) { return null; } // // P R O P E R T I E S // /// protected override AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.Custom; } /// protected override string GetAutomationIdCore() { return (AutomationProperties.GetAutomationId(_owner)); } /// protected override string GetNameCore() { return (AutomationProperties.GetName(_owner)); } /// protected override string GetHelpTextCore() { return (AutomationProperties.GetHelpText(_owner)); } /// ////// Critical - Calls PresentationSource.CriticalFromVisual to get the source for this visual /// TreatAsSafe - The returned PresenationSource object is not exposed and is only used for converting /// co-ordinates to screen space. /// [SecurityCritical, SecurityTreatAsSafe] override protected Rect GetBoundingRectangleCore() { PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return empty rect if(presentationSource == null) return Rect.Empty; HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwnSource, there's not much we can do, return empty rect if(hwndSource == null) return Rect.Empty; Rect rectElement = new Rect(new Point(0, 0), _owner.RenderSize); Rect rectRoot = PointUtil.ElementToRoot(rectElement, _owner, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rectScreen = PointUtil.ClientToScreen(rectClient, hwndSource); return rectScreen; } /// override protected bool IsOffscreenCore() { return !_owner.IsVisible; } /// override protected AutomationOrientation GetOrientationCore() { return (AutomationOrientation.None); } /// override protected string GetItemTypeCore() { return AutomationProperties.GetItemType(_owner); } /// override protected string GetClassNameCore() { return string.Empty; } /// override protected string GetItemStatusCore() { return AutomationProperties.GetItemStatus(_owner); } /// override protected bool IsRequiredForFormCore() { return AutomationProperties.GetIsRequiredForForm(_owner); } /// override protected bool IsKeyboardFocusableCore() { return Keyboard.IsFocusable(_owner); } /// override protected bool HasKeyboardFocusCore() { return _owner.IsKeyboardFocused; } /// override protected bool IsEnabledCore() { return _owner.IsEnabled; } /// override protected bool IsPasswordCore() { return false; } /// override protected bool IsContentElementCore() { return true; } /// override protected bool IsControlElementCore() { return true; } /// override protected AutomationPeer GetLabeledByCore() { UIElement element = AutomationProperties.GetLabeledBy(_owner); if (element != null) return element.GetAutomationPeer(); return null; } /// override protected string GetAcceleratorKeyCore() { return AutomationProperties.GetAcceleratorKey(_owner); } /// override protected string GetAccessKeyCore() { string result = AutomationProperties.GetAccessKey(_owner); if (string.IsNullOrEmpty(result)) return AccessKeyManager.InternalGetAccessKeyCharacter(_owner); return string.Empty; } // // M E T H O D S // /// ////// Critical - Calls PresentationSource.CriticalFromVisual to get the source for this visual /// TreatAsSafe - The returned PresenationSource object is not exposed and is only used for converting /// co-ordinates to screen space. /// [SecurityCritical, SecurityTreatAsSafe] override protected Point GetClickablePointCore() { Point pt = new Point(double.NaN, double.NaN); PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return (double.NaN, double.NaN) point if(presentationSource == null) return pt; HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwnSource, there's not much we can do, return (double.NaN, double.NaN) point if(hwndSource == null) return pt; Rect rectElement = new Rect(new Point(0, 0), _owner.RenderSize); Rect rectRoot = PointUtil.ElementToRoot(rectElement, _owner, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rectScreen = PointUtil.ClientToScreen(rectClient, hwndSource); pt = new Point(rectScreen.Left + rectScreen.Width * 0.5, rectScreen.Top + rectScreen.Height * 0.5); return pt; } /// override protected void SetFocusCore() { if (!_owner.Focus()) throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed)); } private UIElement _owner; } } // 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
- XsltOutput.cs
- ExpressionVisitor.cs
- ManagedWndProcTracker.cs
- WebPartDisplayModeCollection.cs
- Style.cs
- CodeAttributeDeclarationCollection.cs
- DesignObjectWrapper.cs
- RegexGroupCollection.cs
- BitConverter.cs
- ChildrenQuery.cs
- ConnectionManagementElement.cs
- SizeAnimationClockResource.cs
- DiscoveryVersionConverter.cs
- Interlocked.cs
- OrderedDictionary.cs
- SoapHeaderException.cs
- PropertyFilter.cs
- TabletDeviceInfo.cs
- WindowsButton.cs
- Pens.cs
- ResolvedKeyFrameEntry.cs
- IntPtr.cs
- FtpRequestCacheValidator.cs
- ColorPalette.cs
- Int32AnimationBase.cs
- WhiteSpaceTrimStringConverter.cs
- CollectionChangedEventManager.cs
- ParameterCollection.cs
- AssociationTypeEmitter.cs
- DataRelationCollection.cs
- StringFormat.cs
- Propagator.cs
- CatalogZoneDesigner.cs
- MDIWindowDialog.cs
- DynamicQueryableWrapper.cs
- ProxyHwnd.cs
- PersonalizablePropertyEntry.cs
- BitmapInitialize.cs
- ObjectItemNoOpAssemblyLoader.cs
- TextElement.cs
- StylusPlugInCollection.cs
- HttpCapabilitiesBase.cs
- EDesignUtil.cs
- URLIdentityPermission.cs
- ContainerUtilities.cs
- PropertyPushdownHelper.cs
- AxisAngleRotation3D.cs
- MobileCapabilities.cs
- MetabaseReader.cs
- PathSegmentCollection.cs
- HostingPreferredMapPath.cs
- SchemaCreator.cs
- TrustLevel.cs
- WebPartEditorOkVerb.cs
- TypeContext.cs
- DoubleConverter.cs
- SRDisplayNameAttribute.cs
- RecognizedAudio.cs
- DayRenderEvent.cs
- EventLogPermissionEntry.cs
- OAVariantLib.cs
- QilParameter.cs
- RSAOAEPKeyExchangeFormatter.cs
- ShaperBuffers.cs
- QueryResponse.cs
- WebPartTracker.cs
- Currency.cs
- TypeDependencyAttribute.cs
- ActivityInstanceReference.cs
- FormViewInsertEventArgs.cs
- SelectionHighlightInfo.cs
- TextElementEnumerator.cs
- Activator.cs
- FrameworkTextComposition.cs
- RootProjectionNode.cs
- HttpValueCollection.cs
- ActivitySurrogateSelector.cs
- ListSortDescriptionCollection.cs
- BaseTreeIterator.cs
- FixedSOMTableRow.cs
- JsonDataContract.cs
- ImageListImage.cs
- SystemDiagnosticsSection.cs
- IDReferencePropertyAttribute.cs
- ListBoxChrome.cs
- ScrollChrome.cs
- Annotation.cs
- PartBasedPackageProperties.cs
- StateDesigner.Layouts.cs
- ColorBlend.cs
- ConversionHelper.cs
- ObjectDataSourceDisposingEventArgs.cs
- BindingExpressionBase.cs
- XmlMemberMapping.cs
- XmlSchemaAnyAttribute.cs
- InputScopeManager.cs
- ClrProviderManifest.cs
- ForceCopyBuildProvider.cs
- BasicKeyConstraint.cs
- WebInvokeAttribute.cs