[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Automation / SubPropertyEditorAutomationPeer.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;
9     using System.Windows.Automation;
10     using System.Windows.Automation.Peers;
11     using System.Windows.Automation.Provider;
12     using System.Windows.Controls;
13     using System.Windows.Media;
14
15     using System.Activities.Presentation.PropertyEditing;
16     using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.ValueEditors;
17
18     using System.Activities.Presentation.Internal.PropertyEditing.Editors;
19     using System.Activities.Presentation.Internal.Properties;
20
21     // <summary>
22     // AutomationPeer for the SubPropertyEditor
23     // </summary>
24     internal class SubPropertyEditorAutomationPeer : UIElementAutomationPeer, IExpandCollapseProvider 
25     {
26
27         private SubPropertyEditor _editor;
28         List<AutomationPeer> _children;
29
30         public SubPropertyEditorAutomationPeer(SubPropertyEditor editor)
31             : base(editor) 
32         {
33             _editor = editor;
34
35             // Hook into the VisualsChanged event so that this peer can invalidate
36             // itself appropriately
37             if (editor != null)
38             {
39                 editor.VisualsChanged += new EventHandler(OnEditorVisualsChanged);
40             }
41
42             _children = new List<AutomationPeer>();
43
44         }
45
46         // <summary>
47         // Gets the ExpandCollapse state of the sub-properties
48         // </summary>
49         public ExpandCollapseState ExpandCollapseState 
50         {
51             get {
52                 return _editor.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
53             }
54         }
55
56
57         protected override string GetNameCore() 
58         {
59             return Resources.PropertyEditing_SubPropertyEditorAutomationName;
60         }
61
62         protected override string GetClassNameCore() 
63         {
64             return typeof(SubPropertyEditor).Name;
65         }
66
67         // Support the ExpandCollapse pattern
68         public override object GetPattern(PatternInterface patternInterface) 
69         {
70             if (patternInterface == PatternInterface.ExpandCollapse)
71             {
72                 return this;
73             }
74
75             return base.GetPattern(patternInterface);
76         }
77
78         protected override List<AutomationPeer> GetChildrenCore() 
79         {
80             if (_children != null) 
81             {
82                 foreach (AutomationPeer peer in _children) 
83                 {
84                     IAutomationFocusChangedEventSource unhookEventPeer = peer as IAutomationFocusChangedEventSource;
85                     if (unhookEventPeer != null) 
86                     {
87                         unhookEventPeer.UnloadEventHook();
88                     }
89                 }
90                 _children.Clear();
91             }
92
93             // See if we have access to the QuickTypes combo box (it may or may not be available)
94             AutomatedChoiceEditor choiceEditor = VisualTreeUtils.GetNamedChild<AutomatedChoiceEditor>(_editor, "PART_ValueEditor");
95
96             // If we do, present it as one of our children
97             if (choiceEditor != null) 
98             {
99                 _children.Add(new HiddenUIElementAutomationPeer(choiceEditor));
100             }
101
102             // Add any sub-properties
103             ItemsControl properties = VisualTreeUtils.GetNamedChild<ItemsControl>(_editor, "PART_SubPropertyList");
104
105             if (properties != null) 
106             {
107                 int childCount = properties.Items.Count;
108
109                 for (int i = 0; i < childCount; i++) 
110                 {
111                     PropertyContainer propertyContainer = properties.ItemContainerGenerator.ContainerFromIndex(i) as PropertyContainer;
112
113                     if (propertyContainer != null) 
114                     {
115                         PropertyContainerAutomationPeer peer = new PropertyContainerAutomationPeer(propertyContainer);
116                         _children.Add(peer);
117                     }
118
119                 }
120             }
121
122             return _children;
123         }
124
125         private void OnEditorVisualsChanged(object sender, EventArgs e) 
126         {
127             this.InvalidatePeer();
128         }
129
130         // IExpandCollapseProvider Members
131
132         // <summary>
133         // Attempts to collapse the sub-properties
134         // </summary>
135         public void Collapse() 
136         {
137             if (_editor != null)
138             {
139                 _editor.IsExpanded = false;
140             }
141         }
142
143         // <summary>
144         // Attempts to expand the sub-properties
145         // </summary>
146         public void Expand() 
147         {
148             if (_editor != null &&
149                 _editor.PropertyEntry != null &&
150                 _editor.PropertyEntry.PropertyValue.HasSubProperties == true)
151             {
152                 _editor.IsExpanded = true;
153             }
154         }
155     }
156 }