/UIAVerify/UIAComWrapper/UIAComWrapper/LegacyIAccessiblePattern.cs

# · C# · 198 lines · 170 code · 24 blank · 4 comment · 10 complexity · c74b7be852c3b6f04eb8441e0ab2f14e MD5 · raw file

  1. // (c) Copyright Microsoft Corporation, 2010.
  2. // This source is subject to the Microsoft Permissive License.
  3. // See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  4. // All other rights reserved.
  5. using System;
  6. using System.Collections;
  7. using System.Diagnostics;
  8. using System.Runtime.InteropServices;
  9. using UIAComWrapperInternal;
  10. namespace System.Windows.Automation
  11. {
  12. public class LegacyIAccessiblePattern : BasePattern
  13. {
  14. public static readonly AutomationProperty ChildIdProperty = LegacyIAccessiblePatternIdentifiers.ChildIdProperty;
  15. public static readonly AutomationProperty NameProperty = LegacyIAccessiblePatternIdentifiers.NameProperty;
  16. public static readonly AutomationProperty ValueProperty = LegacyIAccessiblePatternIdentifiers.ValueProperty;
  17. public static readonly AutomationProperty DescriptionProperty = LegacyIAccessiblePatternIdentifiers.DescriptionProperty;
  18. public static readonly AutomationProperty RoleProperty = LegacyIAccessiblePatternIdentifiers.RoleProperty;
  19. public static readonly AutomationProperty StateProperty = LegacyIAccessiblePatternIdentifiers.StateProperty;
  20. public static readonly AutomationProperty HelpProperty = LegacyIAccessiblePatternIdentifiers.HelpProperty;
  21. public static readonly AutomationProperty KeyboardShortcutProperty = LegacyIAccessiblePatternIdentifiers.KeyboardShortcutProperty;
  22. public static readonly AutomationProperty SelectionProperty = LegacyIAccessiblePatternIdentifiers.SelectionProperty;
  23. public static readonly AutomationProperty DefaultActionProperty = LegacyIAccessiblePatternIdentifiers.DefaultActionProperty;
  24. public static readonly AutomationPattern Pattern = LegacyIAccessiblePatternIdentifiers.Pattern;
  25. private UIAutomationClient.IUIAutomationLegacyIAccessiblePattern _pattern;
  26. private LegacyIAccessiblePattern(AutomationElement el, UIAutomationClient.IUIAutomationLegacyIAccessiblePattern pattern, bool cached)
  27. : base(el, cached)
  28. {
  29. Debug.Assert(pattern != null);
  30. this._pattern = pattern;
  31. }
  32. public void Select(int flagsSelect)
  33. {
  34. try
  35. {
  36. this._pattern.Select(flagsSelect);
  37. }
  38. catch (System.Runtime.InteropServices.COMException e)
  39. {
  40. Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
  41. }
  42. }
  43. public void DoDefaultAction()
  44. {
  45. try
  46. {
  47. this._pattern.DoDefaultAction();
  48. }
  49. catch (System.Runtime.InteropServices.COMException e)
  50. {
  51. Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
  52. }
  53. }
  54. public void SetValue(string value)
  55. {
  56. try
  57. {
  58. this._pattern.SetValue(value);
  59. }
  60. catch (System.Runtime.InteropServices.COMException e)
  61. {
  62. Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
  63. }
  64. }
  65. public Accessibility.IAccessible GetIAccessible()
  66. {
  67. try
  68. {
  69. return (Accessibility.IAccessible)this._pattern.GetIAccessible();
  70. }
  71. catch (System.Runtime.InteropServices.COMException e)
  72. {
  73. Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
  74. }
  75. }
  76. internal static object Wrap(AutomationElement el, object pattern, bool cached)
  77. {
  78. return (pattern == null) ? null : new LegacyIAccessiblePattern(el, (UIAutomationClient.IUIAutomationLegacyIAccessiblePattern)pattern, cached);
  79. }
  80. public LegacyIAccessiblePatternInformation Cached
  81. {
  82. get
  83. {
  84. Utility.ValidateCached(this._cached);
  85. return new LegacyIAccessiblePatternInformation(this._el, true);
  86. }
  87. }
  88. public LegacyIAccessiblePatternInformation Current
  89. {
  90. get
  91. {
  92. return new LegacyIAccessiblePatternInformation(this._el, false);
  93. }
  94. }
  95. [StructLayout(LayoutKind.Sequential)]
  96. public struct LegacyIAccessiblePatternInformation
  97. {
  98. private AutomationElement _el;
  99. private bool _isCached;
  100. internal LegacyIAccessiblePatternInformation(AutomationElement element, bool isCached)
  101. {
  102. this._el = element;
  103. this._isCached = isCached;
  104. }
  105. public AutomationElement[] GetSelection()
  106. {
  107. return (AutomationElement[])this._el.GetPropertyValue(LegacyIAccessiblePattern.SelectionProperty, _isCached);
  108. }
  109. public int ChildId
  110. {
  111. get
  112. {
  113. return (int)this._el.GetPropertyValue(LegacyIAccessiblePattern.ChildIdProperty, _isCached);
  114. }
  115. }
  116. public string DefaultAction
  117. {
  118. get
  119. {
  120. return (string)this._el.GetPropertyValue(LegacyIAccessiblePattern.DefaultActionProperty, _isCached);
  121. }
  122. }
  123. public string Description
  124. {
  125. get
  126. {
  127. return (string)this._el.GetPropertyValue(LegacyIAccessiblePattern.DescriptionProperty, _isCached);
  128. }
  129. }
  130. public string Help
  131. {
  132. get
  133. {
  134. return (string)this._el.GetPropertyValue(LegacyIAccessiblePattern.HelpProperty, _isCached);
  135. }
  136. }
  137. public string KeyboardShortcut
  138. {
  139. get
  140. {
  141. return (string)this._el.GetPropertyValue(LegacyIAccessiblePattern.KeyboardShortcutProperty, _isCached);
  142. }
  143. }
  144. public string Name
  145. {
  146. get
  147. {
  148. return (string)this._el.GetPropertyValue(LegacyIAccessiblePattern.NameProperty, _isCached);
  149. }
  150. }
  151. public uint Role
  152. {
  153. get
  154. {
  155. return Convert.ToUInt32(this._el.GetPropertyValue(LegacyIAccessiblePattern.RoleProperty, _isCached));
  156. }
  157. }
  158. public uint State
  159. {
  160. get
  161. {
  162. return Convert.ToUInt32(this._el.GetPropertyValue(LegacyIAccessiblePattern.StateProperty, _isCached));
  163. }
  164. }
  165. public string Value
  166. {
  167. get
  168. {
  169. return (string)this._el.GetPropertyValue(LegacyIAccessiblePattern.ValueProperty, _isCached);
  170. }
  171. }
  172. }
  173. }
  174. }