Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Automation / Peers / UIElement3DAutomationPeer.cs / 1 / UIElement3DAutomationPeer.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 UIElement3DAutomationPeer: AutomationPeer { /// public UIElement3DAutomationPeer(UIElement3D owner) { if(owner == null) { throw new ArgumentNullException("owner"); } _owner = owner; } /// public UIElement3D 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(UIElement3D element) { if(element == null) { throw new ArgumentNullException("element"); } return element.CreateAutomationPeer(); } /// public static AutomationPeer FromElement(UIElement3D 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 UIElement3D 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; } 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 = UIElementAutomationPeer.CreatePeerForElement((UIElement)child)) != null ) { done = callback(peer); } else if ( child != null && child is UIElement3D && (peer = 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)); } /// /// override protected Rect GetBoundingRectangleCore() { Rect rectScreen; if (!ComputeBoundingRectangle(out rectScreen)) { rectScreen = Rect.Empty; } return rectScreen; } /// ////// /// 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] private bool ComputeBoundingRectangle(out Rect rect) { rect = Rect.Empty; PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return empty rect if(presentationSource == null) return false; HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwndSource, there's not much we can do, return empty rect if(hwndSource == null) return false; Rect rectElement = _owner.Visual2DContentBounds; // we use VisualTreeHelper.GetContainingVisual2D to transform from the containing Viewport3DVisual Rect rectRoot = PointUtil.ElementToRoot(rectElement, VisualTreeHelper.GetContainingVisual2D(_owner), presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); rect = PointUtil.ClientToScreen(rectClient, hwndSource); return true; } /// 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 // ////// override protected Point GetClickablePointCore() { Rect rectScreen; Point pt = new Point(double.NaN, double.NaN); if (ComputeBoundingRectangle(out rectScreen)) { 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 UIElement3D _owner; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. 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 UIElement3DAutomationPeer: AutomationPeer { /// public UIElement3DAutomationPeer(UIElement3D owner) { if(owner == null) { throw new ArgumentNullException("owner"); } _owner = owner; } /// public UIElement3D 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(UIElement3D element) { if(element == null) { throw new ArgumentNullException("element"); } return element.CreateAutomationPeer(); } /// public static AutomationPeer FromElement(UIElement3D 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 UIElement3D 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; } 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 = UIElementAutomationPeer.CreatePeerForElement((UIElement)child)) != null ) { done = callback(peer); } else if ( child != null && child is UIElement3D && (peer = 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)); } /// /// override protected Rect GetBoundingRectangleCore() { Rect rectScreen; if (!ComputeBoundingRectangle(out rectScreen)) { rectScreen = Rect.Empty; } return rectScreen; } /// ////// /// 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] private bool ComputeBoundingRectangle(out Rect rect) { rect = Rect.Empty; PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return empty rect if(presentationSource == null) return false; HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwndSource, there's not much we can do, return empty rect if(hwndSource == null) return false; Rect rectElement = _owner.Visual2DContentBounds; // we use VisualTreeHelper.GetContainingVisual2D to transform from the containing Viewport3DVisual Rect rectRoot = PointUtil.ElementToRoot(rectElement, VisualTreeHelper.GetContainingVisual2D(_owner), presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); rect = PointUtil.ClientToScreen(rectClient, hwndSource); return true; } /// 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 // ////// override protected Point GetClickablePointCore() { Rect rectScreen; Point pt = new Point(double.NaN, double.NaN); if (ComputeBoundingRectangle(out rectScreen)) { 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 UIElement3D _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
- DataSourceControlBuilder.cs
- DomNameTable.cs
- ArgumentOutOfRangeException.cs
- DataAdapter.cs
- ClientCredentials.cs
- UInt32Storage.cs
- Button.cs
- PersonalizationState.cs
- SerializationEventsCache.cs
- ActivitiesCollection.cs
- TextTreeInsertElementUndoUnit.cs
- XmlTypeMapping.cs
- ApplicationServiceHelper.cs
- SqlCharStream.cs
- GcSettings.cs
- ListViewDeletedEventArgs.cs
- TableTextElementCollectionInternal.cs
- ToolZone.cs
- DoubleCollectionValueSerializer.cs
- UrlMapping.cs
- RefExpr.cs
- UntypedNullExpression.cs
- ExpressionBinding.cs
- BitmapImage.cs
- ObjectManager.cs
- BezierSegment.cs
- SystemEvents.cs
- SplayTreeNode.cs
- embossbitmapeffect.cs
- MetadataAssemblyHelper.cs
- ShapingWorkspace.cs
- ErrorWrapper.cs
- Style.cs
- GeometryDrawing.cs
- TextParaClient.cs
- SemaphoreSecurity.cs
- PolyBezierSegmentFigureLogic.cs
- safesecurityhelperavalon.cs
- TopClause.cs
- SettingsPropertyCollection.cs
- LinearGradientBrush.cs
- AutomationElementCollection.cs
- Crypto.cs
- DataControlFieldCell.cs
- Window.cs
- sqlstateclientmanager.cs
- MdImport.cs
- Knowncolors.cs
- XmlSchemaGroup.cs
- SynchronizationValidator.cs
- DataGridViewColumnStateChangedEventArgs.cs
- IIS7UserPrincipal.cs
- WebConfigurationHostFileChange.cs
- MeasureData.cs
- ReadWriteControlDesigner.cs
- QuaternionIndependentAnimationStorage.cs
- DefaultWorkflowTransactionService.cs
- FormsAuthentication.cs
- BufferedGraphics.cs
- EventData.cs
- DataServiceHost.cs
- ObjectTokenCategory.cs
- Timer.cs
- RunClient.cs
- sitestring.cs
- SetterBaseCollection.cs
- WebPartConnectionsConfigureVerb.cs
- TextRenderer.cs
- DataGridBoolColumn.cs
- QilPatternVisitor.cs
- WebPartDesigner.cs
- CompositeFontParser.cs
- WebScriptMetadataFormatter.cs
- SymDocumentType.cs
- DispatcherObject.cs
- WmfPlaceableFileHeader.cs
- SecureConversationSecurityTokenParameters.cs
- OleDbFactory.cs
- UserNameSecurityTokenAuthenticator.cs
- Vector3DValueSerializer.cs
- ResourceContainer.cs
- ConfigurationException.cs
- ObjectMemberMapping.cs
- FixedSOMContainer.cs
- DataBoundControlAdapter.cs
- Scene3D.cs
- TextServicesDisplayAttributePropertyRanges.cs
- graph.cs
- SchemaElement.cs
- ZipPackagePart.cs
- Baml2006ReaderContext.cs
- LambdaValue.cs
- ParseElementCollection.cs
- WriteTimeStream.cs
- SingleQueryOperator.cs
- SortedSet.cs
- _NegoStream.cs
- MulticastDelegate.cs
- BinaryMethodMessage.cs
- GAC.cs