예제 #1
0
        /// <summary>
        /// Searches for a subrange of text that has the specified attribute.
        /// To search the entire document use the text pattern's document range.
        /// </summary>
        /// <param name="attribute">The attribute to search for.</param>
        /// <param name="value">The value of the specified attribute to search for.  The value must be of the exact type specified for the
        /// attribute.  For example when searching for font size you must specify the size in points as a double.
        /// If you specify the point size as an integer then you will never get any matches due to the differing types.</param>
        /// <param name="backward">true if the last occurring range should be returned instead of the first.</param>
        /// <returns>A subrange with the specified attribute, or null if no such subrange exists.</returns>
        public TextPatternRange FindAttribute(AutomationTextAttribute attribute, object value, bool backward)
        {
            Misc.ValidateArgumentNonNull(attribute, "attribute");
            Misc.ValidateArgumentNonNull(value, "value"); // no text attributes can have null as a valid value

            // Check that attribute value is of expected type...
            AutomationAttributeInfo ai;

            if (!Schema.GetAttributeInfo(attribute, out ai))
            {
                throw new ArgumentException(SR.Get(SRID.UnsupportedAttribute));
            }

            if (value.GetType() != ai.Type)
            {
                throw new ArgumentException(SR.Get(SRID.TextAttributeValueWrongType, attribute, ai.Type.Name, value.GetType().Name), "value");
            }

            // note: if we implement attributes whose values are logical elements, patterns,
            // or ranges then we'll need to unwrap the objects here before passing them on to
            // the provider.
            if (attribute == TextPattern.CultureAttribute)
            {
                if (value is CultureInfo)
                {
                    value = ((CultureInfo)value).LCID;
                }
            }

            SafeTextRangeHandle hResultTextRange = UiaCoreApi.TextRange_FindAttribute(_hTextRange, attribute.Id, value, backward);

            return(Wrap(hResultTextRange, _pattern));
        }
예제 #2
0
 internal static TextPatternRange Wrap(SafeTextRangeHandle hTextRange, TextPattern pattern)
 {
     if (hTextRange.IsInvalid)
     {
         return(null);
     }
     return(new TextPatternRange(hTextRange, pattern));
 }
예제 #3
0
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        internal TextPatternRange(SafeTextRangeHandle hTextRange, TextPattern pattern)
        {
            Debug.Assert(!hTextRange.IsInvalid);
            Debug.Assert(pattern != null);

            _hTextRange = hTextRange;
            _pattern    = pattern;
        }
예제 #4
0
파일: TextRange.cs 프로젝트: JianwenSun/cc
 internal static TextPatternRange Wrap(SafeTextRangeHandle hTextRange, TextPattern pattern)
 {
     if (hTextRange.IsInvalid)
     {
         return null;
     }
     return new TextPatternRange(hTextRange, pattern);
 }
예제 #5
0
파일: TextRange.cs 프로젝트: JianwenSun/cc
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        internal TextPatternRange(SafeTextRangeHandle hTextRange, TextPattern pattern)
        {
            Debug.Assert(!hTextRange.IsInvalid);
            Debug.Assert(pattern != null);

            _hTextRange = hTextRange;
            _pattern = pattern;
        }
예제 #6
0
        /// <summary>
        /// Searches for an occurrence of text within the range.
        /// </summary>
        /// <param name="text">The text to search for.</param>
        /// <param name="backward">true if the last occurring range should be returned instead of the first.</param>
        /// <param name="ignoreCase">true if case should be ignored for the purposes of comparison.</param>
        /// <returns>A subrange with the specified text, or null if no such subrange exists.</returns>
        public TextPatternRange FindText(string text, bool backward, bool ignoreCase)
        {
            // PerSharp/PreFast will flag this as warning 6507/56507: Prefer 'string.IsNullOrEmpty(text)' over checks for null and/or emptiness.
            // A null string is not should throw an ArgumentNullException while an empty string should throw an ArgumentException.
            // Therefore we can not use IsNullOrEmpty() here, suppress the warning.
            Misc.ValidateArgumentNonNull(text, "text");
#pragma warning suppress 6507
            Misc.ValidateArgument(text.Length != 0, SRID.TextMustNotBeNullOrEmpty);

            SafeTextRangeHandle hResultTextRange = UiaCoreApi.TextRange_FindText(_hTextRange, text, backward, ignoreCase);
            return(Wrap(hResultTextRange, _pattern));
        }
예제 #7
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Retrieves a new range covering an identical span of text.  The new range can be manipulated independently from the original.
        /// </summary>
        /// <returns>The new range.</returns>
        public TextPatternRange Clone()
        {
            SafeTextRangeHandle hResultTextRange = UiaCoreApi.TextRange_Clone(_hTextRange);

            return(Wrap(hResultTextRange, _pattern));
        }
예제 #8
0
파일: TextRange.cs 프로젝트: JianwenSun/cc
        internal static TextPatternRange [] Wrap(SafeTextRangeHandle [] hTextRanges, TextPattern pattern)
        {
            if (hTextRanges == null)
                return null;

            TextPatternRange[] ranges = new TextPatternRange[hTextRanges.Length];
            for (int i = 0; i < hTextRanges.Length; i++)
            {
                // if invalid, leave as null
                if (!hTextRanges[i].IsInvalid)
                {
                    ranges[i] = new TextPatternRange(hTextRanges[i], pattern);
                }
            }
            return ranges;
        }