[corlib] Update ValueTuple implementation
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Automation / PropertyInspectorAutomationPeer.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Automation 
5 {
6     using System;
7     using System.Collections.Generic;
8     using System.Windows.Automation.Peers;
9     using System.Windows.Controls;
10     using System.Windows;
11
12     using System.Activities.Presentation;
13     using System.Activities.Presentation.Internal.Properties;
14     using System.Windows.Input;
15
16     // <summary>
17     // AutomationPeer for PropertyInspector
18     // </summary>
19     internal class PropertyInspectorAutomationPeer : UIElementAutomationPeer 
20     {
21
22         private PropertyInspector _inspector;
23
24         // Current list of children automation peers.
25         private List<AutomationPeer> _children;
26
27         public PropertyInspectorAutomationPeer(PropertyInspector owner)
28             : base(owner) 
29         {
30             if (owner == null)
31             {
32                 throw FxTrace.Exception.ArgumentNull("owner");
33             }
34
35             _inspector = owner;
36         }
37
38         // <summary>
39         // Gets a list of AutomationPeers that contains the following:
40         //     Type text box
41         //     Name text box
42         //     List of CategoryContainerAutomationPeers
43         // </summary>
44         // <returns></returns>
45         protected override List<AutomationPeer> GetChildrenCore() 
46         {
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) 
51             {
52                 foreach (AutomationPeer peer in _children) 
53                 {
54                     IAutomationFocusChangedEventSource unhookEventPeer = peer as IAutomationFocusChangedEventSource;
55                     if (unhookEventPeer != null) 
56                     {
57                         unhookEventPeer.UnloadEventHook();
58                     }
59                 }
60                 _children.Clear();
61             }
62             else 
63             {
64                 _children = new List<AutomationPeer>();
65             }
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));
71
72             return _children;
73         }
74
75         protected override Point GetClickablePointCore() 
76         {
77             // return a point that, when clicked, selects the grid without selecting
78             // any of the rows
79             return this.Owner.PointToScreen(new Point(10, 10));
80         }
81
82         protected override string GetHelpTextCore() 
83         {
84             return Resources.PropertyEditing_PropertyInspectorAutomationPeerHelp;
85         }
86
87         protected override string GetNameCore() 
88         {
89             return Resources.PropertyEditing_PropertyInspector;
90         }
91
92         protected override string GetClassNameCore() 
93         {
94             return typeof(PropertyInspector).Name;
95         }
96
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. 
102         // 
103
104
105         private class InfoTextBlockAutomationPeer : TextBlockAutomationPeer, IAutomationFocusChangedEventSource 
106         {
107
108             private TextBlock _informationLabel;
109
110             public InfoTextBlockAutomationPeer(TextBlock informationLabel)
111                 : base(informationLabel) 
112             {
113                 if (informationLabel == null)
114                 {
115                     throw FxTrace.Exception.ArgumentNull("informationLabel");
116                 }
117                 _informationLabel = informationLabel;
118                 _informationLabel.PreviewGotKeyboardFocus += new KeyboardFocusChangedEventHandler(OnPreviewGotKeyboardFocus);
119             }
120
121             // <summary>
122             // PreviewGotKeyboardFocus event to raise the "AutomationFocus" event.
123             // </summary>
124             // <param name="sender">TextBlock</param>
125             // <param name="e">KeyboardFocusChangedEventArgs</param>
126             void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) 
127             {
128                 this.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged);
129             }
130
131             protected override AutomationPeer GetLabeledByCore() 
132             {
133                 return new TextBlockAutomationPeer(_informationLabel);
134             }
135
136         // IAutomationFocusChangedEventSource Members
137
138             public void UnloadEventHook() 
139             {
140                 Owner.PreviewGotKeyboardFocus -= new KeyboardFocusChangedEventHandler(OnPreviewGotKeyboardFocus);
141             }
142
143         }
144     }
145 }