Exemplo n.º 1
0
 internal TextPatternRange(IUIAutomationTextRange range, TextPattern pattern)
 {
     Debug.Assert(range != null);
     Debug.Assert(pattern != null);
     this._range   = range;
     this._pattern = pattern;
 }
Exemplo n.º 2
0
 internal static TextPatternRange Wrap(IUIAutomationTextRange range, TextPattern pattern)
 {
     Debug.Assert(pattern != null);
     if (range == null)
     {
         return(null);
     }
     else
     {
         return(new TextPatternRange(range, pattern));
     }
 }
Exemplo n.º 3
0
 public TextRange(IUIAutomationTextRange tr, TextPattern tp)
 {
     UIATextRange     = tr;
     this.TextPattern = tp;
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 internal TextPatternRange(IUIAutomationTextRange textPatternRange)
 {
     Validate.ArgumentNotNull(parameter: textPatternRange, parameterName: nameof(textPatternRange));
     IUIAutomationTextRange = textPatternRange;
 }
        public void HandleActiveTextPositionChangedEvent(IUIAutomationElement sender, IUIAutomationTextRange range)
        {
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                const int maxTextLengthToInclude = 100;
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("Type", range.GetType()),
                    new KeyValuePair <string, dynamic>("Text", range.GetText(maxTextLengthToInclude))
                };

                this.ListenEventMessage(m);
            }
        }
        public void HandleActiveTextPositionChangedEvent(IUIAutomationElement sender, IUIAutomationTextRange range)
        {
            if (range == null)
            {
                return;
            }

#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(this.EventId, sender);
#pragma warning restore CA2000

            if (m != null)
            {
                const int maxTextLengthToInclude = 100;
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("Type", range.GetType()),
                    new KeyValuePair <string, dynamic>("Text", range.GetText(maxTextLengthToInclude))
                };

                this.ListenEventMessage(m);
            }
        }