Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Automation / Peers / TreeViewDataItemAutomationPeer.cs / 1407647 / TreeViewDataItemAutomationPeer.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // // File: TreeViewDataItemAutomationPeer.cs // // Description: Data Item Automation peer for TreeViewItem, it may be associated with the // full-fleged peer called wrapper peer, TreeViewItemAutomationPeer, if the item is realized. // // History: // 20/12/2008 : [....] - Added // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Security; using System.Text; using System.Windows; using System.Windows.Automation.Provider; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; using MS.Internal; using MS.Win32; namespace System.Windows.Automation.Peers { public class TreeViewDataItemAutomationPeer : ItemAutomationPeer, ISelectionItemProvider, IScrollItemProvider, IExpandCollapseProvider { /// public TreeViewDataItemAutomationPeer(object item, ItemsControlAutomationPeer itemsControlAutomationPeer, TreeViewDataItemAutomationPeer parentDataItemAutomationPeer) : base(item, null) { if(itemsControlAutomationPeer.Owner is TreeView || parentDataItemAutomationPeer == null) ItemsControlAutomationPeer = itemsControlAutomationPeer; _parentDataItemAutomationPeer = parentDataItemAutomationPeer; } /// override public object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.ExpandCollapse) { return this; } else if (patternInterface == PatternInterface.SelectionItem) { return this; } else if (patternInterface == PatternInterface.ScrollItem) { return this; } else if ((patternInterface == PatternInterface.ItemContainer) || (patternInterface == PatternInterface.SynchronizedInput)) { TreeViewItemAutomationPeer treeViewItemAutomationPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (treeViewItemAutomationPeer != null) { if(patternInterface == PatternInterface.SynchronizedInput) { return treeViewItemAutomationPeer.GetPattern(patternInterface); } else { return treeViewItemAutomationPeer; } } } return base.GetPattern(patternInterface); } /// override internal AutomationPeer GetWrapperPeer() { AutomationPeer wrapperPeer = base.GetWrapperPeer(); TreeViewItemAutomationPeer treeViewItemWrapperPeer = wrapperPeer as TreeViewItemAutomationPeer; if (treeViewItemWrapperPeer != null) { treeViewItemWrapperPeer.AddDataPeerInfo(this); } return wrapperPeer; } /// override protected string GetClassNameCore() { return "TreeViewItem"; } /// override protected AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.TreeItem; } public TreeViewDataItemAutomationPeer ParentDataItemAutomationPeer { get { return _parentDataItemAutomationPeer; } } // Return the ItemsControlAP (wrapper peer) corresponding to parent data item, as that will have most up-to-date reference. Sometime along with items even the parent could // be virtualized as well, for eg in case of muti-level TreeView, intermediate TreeView item nodes could be virtualized and realized at any point in time, in that wrapper peer will be // recreated as well. override internal ItemsControlAutomationPeer GetItemsControlAutomationPeer() { if(_parentDataItemAutomationPeer == null) return base.GetItemsControlAutomationPeer(); else { return _parentDataItemAutomationPeer.GetWrapperPeer() as ItemsControlAutomationPeer; } } /// override internal void RealizeCore() { RecursiveScrollIntoView(); } /// void IExpandCollapseProvider.Expand() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IExpandCollapseProvider iExpandCollapseProvider = wrapperPeer as IExpandCollapseProvider; iExpandCollapseProvider.Expand(); } else ThrowElementNotAvailableException(); } /// void IExpandCollapseProvider.Collapse() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IExpandCollapseProvider iExpandCollapseProvider = wrapperPeer as IExpandCollapseProvider; iExpandCollapseProvider.Collapse(); } else ThrowElementNotAvailableException(); } ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState { get { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IExpandCollapseProvider iExpandCollapseProvider = wrapperPeer as IExpandCollapseProvider; return iExpandCollapseProvider.ExpandCollapseState; } else ThrowElementNotAvailableException(); return ExpandCollapseState.LeafNode; } } // [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue) { RaisePropertyChangedEvent( ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed, newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed); } #region ISelectionItemProvider ////// Selects this element, removing any other element from the selection. /// void ISelectionItemProvider.Select() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; iSelectionItemProvider.Select(); } else ThrowElementNotAvailableException(); } ////// Selects this item. /// void ISelectionItemProvider.AddToSelection() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; iSelectionItemProvider.AddToSelection(); } else ThrowElementNotAvailableException(); } ////// Unselects this item. /// void ISelectionItemProvider.RemoveFromSelection() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; iSelectionItemProvider.RemoveFromSelection(); } else ThrowElementNotAvailableException(); } ////// Returns whether the item is selected. /// bool ISelectionItemProvider.IsSelected { get { // Virtualized Element are treated as not selected. TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; return iSelectionItemProvider.IsSelected; } return false; } } ////// The logical element that supports the SelectionPattern for this item. /// IRawElementProviderSimple ISelectionItemProvider.SelectionContainer { get { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; return iSelectionItemProvider.SelectionContainer; } else ThrowElementNotAvailableException(); return null; } } void IScrollItemProvider.ScrollIntoView() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IScrollItemProvider iScrollItemProvider = wrapperPeer as IScrollItemProvider; iScrollItemProvider.ScrollIntoView(); } else { RecursiveScrollIntoView(); } } // [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseAutomationIsSelectedChanged(bool isSelected) { RaisePropertyChangedEvent( SelectionItemPatternIdentifiers.IsSelectedProperty, !isSelected, isSelected); } #endregion private void RecursiveScrollIntoView() { ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; // to check if the parent of this item is TreeViewItem. if (ParentDataItemAutomationPeer != null) { // there might be a possibility that it's parent item is itself virtualized so we have to realize it and make a second attempt if (itemsControlAutomationPeer == null) { ParentDataItemAutomationPeer.RecursiveScrollIntoView(); itemsControlAutomationPeer = ItemsControlAutomationPeer; } } if (itemsControlAutomationPeer != null) { TreeViewItemAutomationPeer treeViewItemAutomationPeer = itemsControlAutomationPeer as TreeViewItemAutomationPeer; if (treeViewItemAutomationPeer != null && (treeViewItemAutomationPeer as IExpandCollapseProvider).ExpandCollapseState == ExpandCollapseState.Collapsed) { (treeViewItemAutomationPeer as IExpandCollapseProvider).Expand(); } ItemsControl parent = itemsControlAutomationPeer.Owner as ItemsControl; if (parent != null) { if (parent.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) { parent.OnBringItemIntoView(Item); } else { // The items aren't generated, try at a later time Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(parent.OnBringItemIntoView), Item); } } } } // This is needed for scenarios where there is a deeply nested tree and client has hold of leaf DataItemPeer, now as it gets virtualized // it’s parent’s WrapperPeer goes away but WeakRef collection won't as they will be reffered in this DataPeer corresponding to that parent. // And at later time when it gets realized the Wrapper will use the collection stored here. internal ItemPeersStorageWeakRefElementProxyStorageCache { get { return _WeakRefElementProxyStorageCache; } set { _WeakRefElementProxyStorageCache = value; } } private TreeViewDataItemAutomationPeer _parentDataItemAutomationPeer; private ItemPeersStorage _WeakRefElementProxyStorageCache; } } // 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. // // File: TreeViewDataItemAutomationPeer.cs // // Description: Data Item Automation peer for TreeViewItem, it may be associated with the // full-fleged peer called wrapper peer, TreeViewItemAutomationPeer, if the item is realized. // // History: // 20/12/2008 : [....] - Added // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Security; using System.Text; using System.Windows; using System.Windows.Automation.Provider; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; using MS.Internal; using MS.Win32; namespace System.Windows.Automation.Peers { public class TreeViewDataItemAutomationPeer : ItemAutomationPeer, ISelectionItemProvider, IScrollItemProvider, IExpandCollapseProvider { /// public TreeViewDataItemAutomationPeer(object item, ItemsControlAutomationPeer itemsControlAutomationPeer, TreeViewDataItemAutomationPeer parentDataItemAutomationPeer) : base(item, null) { if(itemsControlAutomationPeer.Owner is TreeView || parentDataItemAutomationPeer == null) ItemsControlAutomationPeer = itemsControlAutomationPeer; _parentDataItemAutomationPeer = parentDataItemAutomationPeer; } /// override public object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.ExpandCollapse) { return this; } else if (patternInterface == PatternInterface.SelectionItem) { return this; } else if (patternInterface == PatternInterface.ScrollItem) { return this; } else if ((patternInterface == PatternInterface.ItemContainer) || (patternInterface == PatternInterface.SynchronizedInput)) { TreeViewItemAutomationPeer treeViewItemAutomationPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (treeViewItemAutomationPeer != null) { if(patternInterface == PatternInterface.SynchronizedInput) { return treeViewItemAutomationPeer.GetPattern(patternInterface); } else { return treeViewItemAutomationPeer; } } } return base.GetPattern(patternInterface); } /// override internal AutomationPeer GetWrapperPeer() { AutomationPeer wrapperPeer = base.GetWrapperPeer(); TreeViewItemAutomationPeer treeViewItemWrapperPeer = wrapperPeer as TreeViewItemAutomationPeer; if (treeViewItemWrapperPeer != null) { treeViewItemWrapperPeer.AddDataPeerInfo(this); } return wrapperPeer; } /// override protected string GetClassNameCore() { return "TreeViewItem"; } /// override protected AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.TreeItem; } public TreeViewDataItemAutomationPeer ParentDataItemAutomationPeer { get { return _parentDataItemAutomationPeer; } } // Return the ItemsControlAP (wrapper peer) corresponding to parent data item, as that will have most up-to-date reference. Sometime along with items even the parent could // be virtualized as well, for eg in case of muti-level TreeView, intermediate TreeView item nodes could be virtualized and realized at any point in time, in that wrapper peer will be // recreated as well. override internal ItemsControlAutomationPeer GetItemsControlAutomationPeer() { if(_parentDataItemAutomationPeer == null) return base.GetItemsControlAutomationPeer(); else { return _parentDataItemAutomationPeer.GetWrapperPeer() as ItemsControlAutomationPeer; } } /// override internal void RealizeCore() { RecursiveScrollIntoView(); } /// void IExpandCollapseProvider.Expand() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IExpandCollapseProvider iExpandCollapseProvider = wrapperPeer as IExpandCollapseProvider; iExpandCollapseProvider.Expand(); } else ThrowElementNotAvailableException(); } /// void IExpandCollapseProvider.Collapse() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IExpandCollapseProvider iExpandCollapseProvider = wrapperPeer as IExpandCollapseProvider; iExpandCollapseProvider.Collapse(); } else ThrowElementNotAvailableException(); } ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState { get { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IExpandCollapseProvider iExpandCollapseProvider = wrapperPeer as IExpandCollapseProvider; return iExpandCollapseProvider.ExpandCollapseState; } else ThrowElementNotAvailableException(); return ExpandCollapseState.LeafNode; } } // [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue) { RaisePropertyChangedEvent( ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed, newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed); } #region ISelectionItemProvider /// /// Selects this element, removing any other element from the selection. /// void ISelectionItemProvider.Select() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; iSelectionItemProvider.Select(); } else ThrowElementNotAvailableException(); } ////// Selects this item. /// void ISelectionItemProvider.AddToSelection() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; iSelectionItemProvider.AddToSelection(); } else ThrowElementNotAvailableException(); } ////// Unselects this item. /// void ISelectionItemProvider.RemoveFromSelection() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; iSelectionItemProvider.RemoveFromSelection(); } else ThrowElementNotAvailableException(); } ////// Returns whether the item is selected. /// bool ISelectionItemProvider.IsSelected { get { // Virtualized Element are treated as not selected. TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; return iSelectionItemProvider.IsSelected; } return false; } } ////// The logical element that supports the SelectionPattern for this item. /// IRawElementProviderSimple ISelectionItemProvider.SelectionContainer { get { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { ISelectionItemProvider iSelectionItemProvider = wrapperPeer as ISelectionItemProvider; return iSelectionItemProvider.SelectionContainer; } else ThrowElementNotAvailableException(); return null; } } void IScrollItemProvider.ScrollIntoView() { TreeViewItemAutomationPeer wrapperPeer = GetWrapperPeer() as TreeViewItemAutomationPeer; if (wrapperPeer != null) { IScrollItemProvider iScrollItemProvider = wrapperPeer as IScrollItemProvider; iScrollItemProvider.ScrollIntoView(); } else { RecursiveScrollIntoView(); } } // [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseAutomationIsSelectedChanged(bool isSelected) { RaisePropertyChangedEvent( SelectionItemPatternIdentifiers.IsSelectedProperty, !isSelected, isSelected); } #endregion private void RecursiveScrollIntoView() { ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; // to check if the parent of this item is TreeViewItem. if (ParentDataItemAutomationPeer != null) { // there might be a possibility that it's parent item is itself virtualized so we have to realize it and make a second attempt if (itemsControlAutomationPeer == null) { ParentDataItemAutomationPeer.RecursiveScrollIntoView(); itemsControlAutomationPeer = ItemsControlAutomationPeer; } } if (itemsControlAutomationPeer != null) { TreeViewItemAutomationPeer treeViewItemAutomationPeer = itemsControlAutomationPeer as TreeViewItemAutomationPeer; if (treeViewItemAutomationPeer != null && (treeViewItemAutomationPeer as IExpandCollapseProvider).ExpandCollapseState == ExpandCollapseState.Collapsed) { (treeViewItemAutomationPeer as IExpandCollapseProvider).Expand(); } ItemsControl parent = itemsControlAutomationPeer.Owner as ItemsControl; if (parent != null) { if (parent.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) { parent.OnBringItemIntoView(Item); } else { // The items aren't generated, try at a later time Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(parent.OnBringItemIntoView), Item); } } } } // This is needed for scenarios where there is a deeply nested tree and client has hold of leaf DataItemPeer, now as it gets virtualized // it’s parent’s WrapperPeer goes away but WeakRef collection won't as they will be reffered in this DataPeer corresponding to that parent. // And at later time when it gets realized the Wrapper will use the collection stored here. internal ItemPeersStorageWeakRefElementProxyStorageCache { get { return _WeakRefElementProxyStorageCache; } set { _WeakRefElementProxyStorageCache = value; } } private TreeViewDataItemAutomationPeer _parentDataItemAutomationPeer; private ItemPeersStorage _WeakRefElementProxyStorageCache; } } // 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
- QueryAccessibilityHelpEvent.cs
- ReachNamespaceInfo.cs
- QilPatternVisitor.cs
- ThreadStateException.cs
- DataGridToolTip.cs
- TableRow.cs
- DocumentXmlWriter.cs
- ListViewCancelEventArgs.cs
- FormViewInsertedEventArgs.cs
- ModifierKeysValueSerializer.cs
- ScrollViewer.cs
- RegisterResponseInfo.cs
- DocumentPageTextView.cs
- DesignerDataStoredProcedure.cs
- PointHitTestResult.cs
- PointValueSerializer.cs
- ToolStripPanelCell.cs
- CssStyleCollection.cs
- documentsequencetextview.cs
- PatternMatcher.cs
- oledbmetadatacolumnnames.cs
- mda.cs
- MediaTimeline.cs
- ProfileModule.cs
- HiddenFieldPageStatePersister.cs
- MessagePropertyAttribute.cs
- DataBinder.cs
- MetadataWorkspace.cs
- ProgressBarRenderer.cs
- OdbcTransaction.cs
- DataGridCommandEventArgs.cs
- XmlWrappingReader.cs
- TemplateEditingVerb.cs
- WindowsFormsSynchronizationContext.cs
- SQLBinary.cs
- CultureData.cs
- MouseButtonEventArgs.cs
- RemoteWebConfigurationHost.cs
- ComponentResourceManager.cs
- ChtmlCommandAdapter.cs
- StrokeNodeEnumerator.cs
- Privilege.cs
- SpellerHighlightLayer.cs
- FacetChecker.cs
- Glyph.cs
- SoapDocumentServiceAttribute.cs
- CodeDirectionExpression.cs
- InstanceDataCollection.cs
- HtmlInputSubmit.cs
- ValidationRule.cs
- WebServiceResponseDesigner.cs
- CustomGrammar.cs
- DrawingCollection.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- NaturalLanguageHyphenator.cs
- ButtonFieldBase.cs
- ConnectionManagementElementCollection.cs
- PersistenceTypeAttribute.cs
- HttpException.cs
- SqlDataRecord.cs
- CompositeKey.cs
- FreezableDefaultValueFactory.cs
- Selector.cs
- IntPtr.cs
- CodePropertyReferenceExpression.cs
- ResolveResponse.cs
- WsdlBuildProvider.cs
- ApplicationException.cs
- PropertyItemInternal.cs
- RegistrationServices.cs
- IndexedGlyphRun.cs
- GB18030Encoding.cs
- RegexCompilationInfo.cs
- FloatSumAggregationOperator.cs
- DbDataSourceEnumerator.cs
- SmtpException.cs
- ProgressBarHighlightConverter.cs
- Predicate.cs
- ProcessHostServerConfig.cs
- PixelShader.cs
- HideDisabledControlAdapter.cs
- ImageSourceValueSerializer.cs
- DataQuery.cs
- PrimitiveCodeDomSerializer.cs
- XmlImplementation.cs
- AppSettingsSection.cs
- DeploymentSection.cs
- SQLInt64.cs
- MetadataItemEmitter.cs
- PerformanceCounterPermission.cs
- StorageEntitySetMapping.cs
- PointHitTestResult.cs
- EntityTransaction.cs
- Pts.cs
- SourceCollection.cs
- BamlResourceSerializer.cs
- AssertSection.cs
- HwndSourceKeyboardInputSite.cs
- DataGridColumnHeaderAutomationPeer.cs
- PrintingPermissionAttribute.cs