1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Automation
7 using System.Collections.Generic;
8 using System.Windows.Automation.Peers;
9 using System.Windows.Controls;
12 using System.Activities.Presentation;
13 using System.Activities.Presentation.Internal.Properties;
14 using System.Windows.Input;
17 // AutomationPeer for PropertyInspector
19 internal class PropertyInspectorAutomationPeer : UIElementAutomationPeer
22 private PropertyInspector _inspector;
24 // Current list of children automation peers.
25 private List<AutomationPeer> _children;
27 public PropertyInspectorAutomationPeer(PropertyInspector owner)
32 throw FxTrace.Exception.ArgumentNull("owner");
39 // Gets a list of AutomationPeers that contains the following:
42 // List of CategoryContainerAutomationPeers
44 // <returns></returns>
45 protected override List<AutomationPeer> GetChildrenCore()
47 // If children list is not null and contains AutomationPeer that implements IAutomationFocusChangedEventSource
48 // Then, unhook the automation focus events before clearing the list
49 // Else, create a new one.
50 if (_children != null)
52 foreach (AutomationPeer peer in _children)
54 IAutomationFocusChangedEventSource unhookEventPeer = peer as IAutomationFocusChangedEventSource;
55 if (unhookEventPeer != null)
57 unhookEventPeer.UnloadEventHook();
64 _children = new List<AutomationPeer>();
66 _children.Add(new TextBlockAutomationPeer(_inspector.SelectionTypeLabel));
67 _children.Add(new UIElementAutomationPeer(_inspector.PropertyToolBar));
68 _children.Add(new InfoTextBlockAutomationPeer(_inspector.UninitializedLabel));
69 _children.Add(new InfoTextBlockAutomationPeer(_inspector.NoSearchResultsLabel));
70 _children.Add(new CategoryListAutomationPeer(_inspector.CategoryList));
75 protected override Point GetClickablePointCore()
77 // return a point that, when clicked, selects the grid without selecting
79 return this.Owner.PointToScreen(new Point(10, 10));
82 protected override string GetHelpTextCore()
84 return Resources.PropertyEditing_PropertyInspectorAutomationPeerHelp;
87 protected override string GetNameCore()
89 return Resources.PropertyEditing_PropertyInspector;
92 protected override string GetClassNameCore()
94 return typeof(PropertyInspector).Name;
97 // The following automation peers provide accessiblity support (Raise automation events on receiving keyboard focus)
98 // This is necessary for ACC-TOOLS especially screen readers like JAWS.
99 // We cannot use the base AutomationPeers (like UIElementAutomationPeer) and *have* to derive from the respective types
100 // since the actual implementation of the handler when the focus event differs from element to element.
101 // So we cannot use single base class to achieve the desired goal.
105 private class InfoTextBlockAutomationPeer : TextBlockAutomationPeer, IAutomationFocusChangedEventSource
108 private TextBlock _informationLabel;
110 public InfoTextBlockAutomationPeer(TextBlock informationLabel)
111 : base(informationLabel)
113 if (informationLabel == null)
115 throw FxTrace.Exception.ArgumentNull("informationLabel");
117 _informationLabel = informationLabel;
118 _informationLabel.PreviewGotKeyboardFocus += new KeyboardFocusChangedEventHandler(OnPreviewGotKeyboardFocus);
122 // PreviewGotKeyboardFocus event to raise the "AutomationFocus" event.
124 // <param name="sender">TextBlock</param>
125 // <param name="e">KeyboardFocusChangedEventArgs</param>
126 void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
128 this.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged);
131 protected override AutomationPeer GetLabeledByCore()
133 return new TextBlockAutomationPeer(_informationLabel);
136 // IAutomationFocusChangedEventSource Members
138 public void UnloadEventHook()
140 Owner.PreviewGotKeyboardFocus -= new KeyboardFocusChangedEventHandler(OnPreviewGotKeyboardFocus);