public TextPattern(A11yElement e, IUIAutomationTextPattern p) : base(e, PatternType.UIA_TextPatternId) { Pattern = p; PopulateProperties(); // if textPattern is supported , it means that user would do select text in the control. // so it should be marked as UI actionable IsUIActionable = true; }
protected override void Dispose(bool disposing) { if (Pattern != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(Pattern); this.Pattern = null; } base.Dispose(disposing); }
public TextPattern(A11yElement e, IUIAutomationTextPattern p) : base(e, PatternType.UIA_TextPatternId) { // UIA sometimes throws a NotImplementedException. If it does, exclude it // from telemetry ExcludingExceptionWrapper.ExecuteWithExcludedExceptionConversion(typeof(NotImplementedException), () => { Pattern = p; PopulateProperties(); // if textPattern is supported , it means that user would do select text in the control. // so it should be marked as UI actionable IsUIActionable = true; }); }
internal static new object Wrap(AutomationElement el, object pattern, bool cached) { TextPattern2 result = null; if (pattern != null) { IUIAutomationTextPattern basePattern = (IUIAutomationTextPattern)el.GetRawPattern(TextPattern.Pattern, cached); if (basePattern != null) { result = new TextPattern2(el, (IUIAutomationTextPattern2)pattern, basePattern, cached); } } return(result); }
internal static TextPattern Wrap( AutomationElement element, IUIAutomationTextPattern pattern) { return(new TextPattern(element: element, textPattern: pattern)); }
internal TextPattern(AutomationElement element, IUIAutomationTextPattern textPattern) : base(el: element) { this._textPattern = textPattern; }
protected TextPattern(AutomationElement el, IUIAutomationTextPattern pattern, bool cached) : base(el, cached) { Debug.Assert(pattern != null); this._pattern = pattern; }
private TextPattern2(AutomationElement el, IUIAutomationTextPattern2 pattern, IUIAutomationTextPattern basePattern, bool cached) : base(el, basePattern, cached) { Debug.Assert(pattern != null); this._pattern = pattern; }
public string GetMail() { string strMailContent = ""; // Try to find a Windows Live Mail window for composing and reading e-mails. // Using the Spy tool, the class of the main window can be found. This test // app assumes there's only one Windows Live Mail window of interest. IntPtr hwnd = Win32.FindWindow("ATH_Note", null); if (hwnd != IntPtr.Zero) { // We found a window, so get the UIA element associated with the window. IUIAutomationElement elementMailAppWindow = _automation.ElementFromHandle( hwnd); // Find an element somewhere beneath the main window element in the UIA // tree which represents the main area where the e-mail content is shown. // Using the Inspect SDK tool, we can see that the main e-mail content // is contained within an element whose accessible name is "NoteWindow". // So create a condition such that the FindFirst() call below will only // return an element if its name is "NoteWindow". IUIAutomationCondition conditionNote = _automation.CreatePropertyCondition( _propertyIdName, "NoteWindow"); IUIAutomationElement elementNoteWindow = elementMailAppWindow.FindFirst( TreeScope.TreeScope_Descendants, conditionNote); // As it happens, the actual element that supports the Text Pattern is // somewhere beneath the "NoteWindow" element in the UIA tree. Using // Inspect we can see that there is an element that supports the // Text Pattern. Once we have that element, we can avoid a cross-process // call to access the Text Pattern object by using cache request. IUIAutomationCacheRequest cacheRequest = _automation.CreateCacheRequest(); cacheRequest.AddPattern(_patternIdTextPattern); // Now find the element that supports the Text Pattern. This test app assumes // there’s only one element that can be returned which supports the Text Pattern. bool fTextPatternSupported = true; IUIAutomationCondition conditionTextPattern = _automation.CreatePropertyCondition( _propertyIdIsTextPatternAvailable, fTextPatternSupported); IUIAutomationElement elementMailContent = elementMailAppWindow.FindFirstBuildCache( TreeScope.TreeScope_Descendants, conditionTextPattern, cacheRequest); // Because the Text Pattern object is cached, we don't have to make a cross-process // call here to get object. Later calls which actually use methods and properties // on the Text Pattern object will incur cross-proc calls. IUIAutomationTextPattern textPattern = (IUIAutomationTextPattern) elementMailContent.GetCachedPattern( _patternIdTextPattern); // This test app is only interested in getting all the e-mail text, so we get that through // the DocumentRange property. A more fully featured app might be interested in getting a // collection of Text Ranges from the e-mail. Each range might relate to an individual // word or paragraph. Given that a provider which supports the Text Pattern allows a // client to find the bounding rectangles of these ranges, the client could choose to use // its own method of highlighting the text as the text is being spoken. IUIAutomationTextRange rangeDocument = textPattern.DocumentRange; // Pass -1 here because we're not interested in limiting the amount of text here. strMailContent = rangeDocument.GetText(-1); } return(strMailContent); }