/// <summary> /// Retrieves the value of a text attribute over the entire range. /// </summary> /// <param name="attribute">The text attribute.</param> /// <returns>The value of the attribute across the range. /// If the attribute's value varies over the range then the value is TextPattern.MixedAttributeValue</returns> public object GetAttributeValue(AutomationTextAttribute attribute) { Misc.ValidateArgumentNonNull(attribute, "attribute"); AutomationAttributeInfo ai; if (!Schema.GetAttributeInfo(attribute, out ai)) { throw new ArgumentException(SR.Get(SRID.UnsupportedAttribute)); } object obj = UiaCoreApi.TextRange_GetAttributeValue(_hTextRange, attribute.Id); if (ai.Type.IsEnum && obj is int) { // Convert ints from COM Interop to the appropriate enum type obj = Enum.ToObject(ai.Type, (int)obj); } else if (obj != AutomationElement.NotSupported && ai.ObjectConverter != null) { // Use a custom converter, if needed (eg. converts LCIDs to CultureInfo) obj = ai.ObjectConverter(obj); } return(obj); }
internal static object GetTextAttribute(AutomationElement control, AutomationTextAttribute attribute) { TextPattern pat = (TextPattern)CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control); object retVal = pat.DocumentRange.GetAttributeValue(attribute); return(retVal); }
public ITextPatternRange FindAttribute(AutomationTextAttribute attribute, object value, bool backward) { // TODO: Support this in at-spi. // I don't want to iterate over the wire. Log.Debug("AtspiUiaSource: TODO: FindAttribute"); return(null); }
public TextPatternRange FindAttribute(AutomationTextAttribute attribute, object value, bool backward) { Utility.ValidateArgumentNonNull(attribute, "attribute"); Utility.ValidateArgumentNonNull(value, "value"); if ((attribute == TextPattern.CultureAttribute) && (value is CultureInfo)) { value = ((CultureInfo)value).LCID; } try { return(TextPatternRange.Wrap( this._range.FindAttribute(attribute.Id, value, Utility.ConvertToInt(backward)), this._pattern)); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
/// <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)); }
public object GetAttributeValue(AutomationTextAttribute attribute) { Utility.ValidateArgumentNonNull(attribute, "attribute"); try { PropertyTypeInfo info; if (!Schema.GetPropertyTypeInfo(attribute, out info)) { throw new ArgumentException("Unsupported Attribute"); } object valueAsObject = this._range.GetAttributeValue(attribute.Id); if (info.Type.IsEnum && (valueAsObject is int)) { return(Enum.ToObject(info.Type, (int)valueAsObject)); } if ((valueAsObject != AutomationElement.NotSupported) && (info.ObjectConverter != null)) { valueAsObject = info.ObjectConverter(valueAsObject); } return(valueAsObject); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
public object GetAttributeValue(AutomationTextAttribute attribute) { try { //todo Need object transformation return(range.GetAttributeValue(attribute.Id)); } catch (Exception ex) { throw DbusExceptionTranslator.Translate(ex); } }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors internal AutomationAttributeInfo( AutomationPropertyConverter converter, AutomationTextAttribute id, Type type ) { _id = id; _type = type; _converter = converter; }
private object GetAttributeValue(AutomationTextAttribute attribute) { Func <TextRangeProvider, object> func; if (_attributeGetter.TryGetValue(attribute, out func)) { return(func(this)); } return(null); }
public TextPatternRange FindAttribute(AutomationTextAttribute attribute, Object @value, bool backward) { ITextPatternRange range = source.FindAttribute(attribute, value, backward); if (range == null) { return(null); } return(new TextPatternRange(TextPattern, range)); }
// a big pseudo-switch statement based on the attribute private object GetAttributeValue(AutomationTextAttribute attribute) { object rval; if (attribute == TextPattern.BackgroundColorAttribute) { rval = GetBackgroundColor(); } else if (attribute == TextPattern.CapStyleAttribute) { rval = GetCapStyle(_provider.WindowStyle); } else if (attribute == TextPattern.FontNameAttribute) { rval = GetFontName(_provider.GetLogfont()); } else if (attribute == TextPattern.FontSizeAttribute) { rval = GetFontSize(_provider.GetLogfont()); } else if (attribute == TextPattern.FontWeightAttribute) { rval = GetFontWeight(_provider.GetLogfont()); } else if (attribute == TextPattern.ForegroundColorAttribute) { rval = GetForegroundColor(); } else if (attribute == TextPattern.HorizontalTextAlignmentAttribute) { rval = GetHorizontalTextAlignment(_provider.WindowStyle); } else if (attribute == TextPattern.IsItalicAttribute) { rval = GetItalic(_provider.GetLogfont()); } else if (attribute == TextPattern.IsReadOnlyAttribute) { rval = GetReadOnly(); } else if (attribute == TextPattern.StrikethroughStyleAttribute) { rval = GetStrikethroughStyle(_provider.GetLogfont()); } else if (attribute == TextPattern.UnderlineStyleAttribute) { rval = GetUnderlineStyle(_provider.GetLogfont()); } else { rval = AutomationElement.NotSupported; } return(rval); }
public ITextPatternRange FindAttribute(AutomationTextAttribute attribute, object value, bool backward) { //todo Need object transformation string path = null; try { path = range.FindAttribute(attribute.Id, value, backward); } catch (Exception ex) { throw DbusExceptionTranslator.Translate(ex); } return(parent.GetTextPatternRange(path)); }
public TextPatternRange FindAttribute( AutomationTextAttribute attribute, object value, bool backward) { Validate.ArgumentNotNull(parameter: attribute, parameterName: nameof(attribute)); var variant = value.ToVariant(); var textPatternRange = new TextPatternRange(textPatternRange: IUIAutomationTextRange.FindAttribute(attr: attribute.Id, val: variant, backward: Convert.ToInt32(value: backward))); variant.Free(); return(textPatternRange); }
// look up information on the specified property, returns true if found, else false internal static bool GetAttributeInfo(AutomationTextAttribute id, out AutomationAttributeInfo info) { foreach (AutomationAttributeInfo ai in _attributeInfoTable) { if (ai.ID == id) { info = ai; return(true); } } info = null; Debug.Assert(false, "GetAttributeInfo failed " + id); return(false); }
ITextRangeProvider ITextRangeProvider.FindAttribute(int attributeId, object val, bool backwards) { AutomationTextAttribute attribute = AutomationTextAttribute.LookupById(attributeId); // generic controls are plain text so if the attribute matches then it matches over the whole range. // To workaround the conversion that Marshaling of COM-interop did. object targetAttribute = GetAttributeValue(attribute); if (targetAttribute is Enum) { targetAttribute = (int)targetAttribute; } return(val.Equals(targetAttribute) ? new WindowsEditBoxRange(_provider, Start, End) : null); }
public void MarginTrailingAttributeTest() { AutomationTextAttribute myMarginTrailingAttribute = TextPatternIdentifiers.MarginTrailingAttribute; Assert.IsNotNull( myMarginTrailingAttribute, "Field must not be null."); Assert.AreEqual( 40021, myMarginTrailingAttribute.Id, "Id"); Assert.AreEqual( "TextPatternIdentifiers.MarginTrailingAttribute", myMarginTrailingAttribute.ProgrammaticName, "ProgrammaticName"); Assert.AreEqual( myMarginTrailingAttribute, AutomationTextAttribute.LookupById(myMarginTrailingAttribute.Id), "LookupById"); }
public void TextFlowDirectionsAttributeTest() { AutomationTextAttribute myTextFlowDirectionsAttribute = TextPatternIdentifiers.TextFlowDirectionsAttribute; Assert.IsNotNull( myTextFlowDirectionsAttribute, "Field must not be null."); Assert.AreEqual( 40028, myTextFlowDirectionsAttribute.Id, "Id"); Assert.AreEqual( "TextPatternIdentifiers.TextFlowDirectionsAttribute", myTextFlowDirectionsAttribute.ProgrammaticName, "ProgrammaticName"); Assert.AreEqual( myTextFlowDirectionsAttribute, AutomationTextAttribute.LookupById(myTextFlowDirectionsAttribute.Id), "LookupById"); }
public void UnderlineStyleAttributeTest() { AutomationTextAttribute myUnderlineStyleAttribute = TextPatternIdentifiers.UnderlineStyleAttribute; Assert.IsNotNull( myUnderlineStyleAttribute, "Field must not be null."); Assert.AreEqual( 40030, myUnderlineStyleAttribute.Id, "Id"); Assert.AreEqual( "TextPatternIdentifiers.UnderlineStyleAttribute", myUnderlineStyleAttribute.ProgrammaticName, "ProgrammaticName"); Assert.AreEqual( myUnderlineStyleAttribute, AutomationTextAttribute.LookupById(myUnderlineStyleAttribute.Id), "LookupById"); }
public void BackgroundColorAttributeTest() { AutomationTextAttribute myBackgroundColorAttribute = TextPatternIdentifiers.BackgroundColorAttribute; Assert.IsNotNull( myBackgroundColorAttribute, "Field must not be null."); Assert.AreEqual( 40001, myBackgroundColorAttribute.Id, "Id"); Assert.AreEqual( "TextPatternIdentifiers.BackgroundColorAttribute", myBackgroundColorAttribute.ProgrammaticName, "ProgrammaticName"); Assert.AreEqual( myBackgroundColorAttribute, AutomationTextAttribute.LookupById(myBackgroundColorAttribute.Id), "LookupById"); }
public void HorizontalTextAlignmentAttributeTest() { AutomationTextAttribute myHorizontalTextAlignmentAttribute = TextPatternIdentifiers.HorizontalTextAlignmentAttribute; Assert.IsNotNull( myHorizontalTextAlignmentAttribute, "Field must not be null."); Assert.AreEqual( 40009, myHorizontalTextAlignmentAttribute.Id, "Id"); Assert.AreEqual( "TextPatternIdentifiers.HorizontalTextAlignmentAttribute", myHorizontalTextAlignmentAttribute.ProgrammaticName, "ProgrammaticName"); Assert.AreEqual( myHorizontalTextAlignmentAttribute, AutomationTextAttribute.LookupById(myHorizontalTextAlignmentAttribute.Id), "LookupById"); }
public object GetAttributeValue(int attribute) { return(GetAttributeValue(AutomationTextAttribute.LookupById(attribute))); }
public object GetAttributeValue(AutomationTextAttribute attribute) { Validate.ArgumentNotNull(parameter: attribute, parameterName: nameof(attribute)); return(IUIAutomationTextRange.GetAttributeValue(attr: attribute.Id)); }
public object GetAttributeValue(AutomationTextAttribute attribute) { int start, end; IDictionary <string, string> attributes = text.GetAttributeRun(startOffset, out start, out end, true); string val; if (attributes == null) { return(null); } if (end < endOffset) { return(TextPattern.MixedAttributeValue); } if (attribute.Id == TextPattern.FontWeightAttribute.Id && attributes.TryGetValue("weight", out val)) { if (val == "bold") { return(400); } return(Int32.Parse(val)); } else if (attribute.Id == TextPattern.BackgroundColorAttribute.Id && attributes.TryGetValue("bg-color", out val)) { Match m = parse_color.Match(val); if (m.Success) { int v1, v2, v3; v1 = Int32.Parse(m.Groups [1].ToString()); v2 = Int32.Parse(m.Groups [2].ToString()); v3 = Int32.Parse(m.Groups [3].ToString()); return((v1 << 16) + (v2 << 8) + v3); } } else if (attribute.Id == TextPattern.ForegroundColorAttribute.Id && attributes.TryGetValue("fg-color", out val)) { Match m = parse_color.Match(val); if (m.Success) { int v1, v2, v3; v1 = Int32.Parse(m.Groups [1].ToString()); v2 = Int32.Parse(m.Groups [2].ToString()); v3 = Int32.Parse(m.Groups [3].ToString()); return((v1 << 16) + (v2 << 8) + v3); } } else if (attribute.Id == TextPattern.FontNameAttribute.Id && attributes.TryGetValue("family-name", out val)) { return(val); } else if (attribute.Id == TextPattern.FontSizeAttribute.Id && attributes.TryGetValue("size", out val)) { return(Int32.Parse(val)); } else if (attribute.Id == TextPattern.IsItalicAttribute.Id) { if (attributes.TryGetValue("font-size", out val)) { return(val == "italic"); } return(false); } Log.Debug("TODO: GetAttributeValue for " + attribute.ProgrammaticName); return(null); }
public object GetAttributeValue(AutomationTextAttribute attribute) { Utility.ValidateArgumentNonNull(attribute, "attribute"); try { PropertyTypeInfo info; if (!Schema.GetPropertyTypeInfo(attribute, out info)) { throw new ArgumentException("Unsupported Attribute"); } object valueAsObject = this._range.GetAttributeValue(attribute.Id); if (info.Type.IsEnum && (valueAsObject is int)) { return Enum.ToObject(info.Type, (int)valueAsObject); } if ((valueAsObject != AutomationElement.NotSupported) && (info.ObjectConverter != null)) { valueAsObject = info.ObjectConverter(valueAsObject); } return valueAsObject; } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
public Object GetAttributeValue (AutomationTextAttribute attribute) { return source.GetAttributeValue (attribute); }
public TextPatternRange FindAttribute (AutomationTextAttribute attribute, Object @value, bool backward) { ITextPatternRange range = source.FindAttribute (attribute, value, backward); if (range == null) return null; return new TextPatternRange (TextPattern, range); }
public TextPatternRange FindAttribute(AutomationTextAttribute attribute, object value, bool backward) { Utility.ValidateArgumentNonNull(attribute, "attribute"); Utility.ValidateArgumentNonNull(value, "value"); if ((attribute == TextPattern.CultureAttribute) && (value is CultureInfo)) { value = ((CultureInfo)value).LCID; } try { return TextPatternRange.Wrap( this._range.FindAttribute(attribute.Id, value, Utility.ConvertToInt(backward)), this._pattern); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
object ITextRangeProvider.GetAttributeValue(int attributeId) { AutomationTextAttribute attribute = AutomationTextAttribute.LookupById(attributeId); return(GetAttributeValue(attribute)); }
public Object GetAttributeValue(AutomationTextAttribute attribute) { return(source.GetAttributeValue(attribute)); }
/// <summary> /// Returns a text range subset that has the specified attribute value. /// </summary> /// <param name="control">The UI Automation element</param> /// <param name="targetRange">The target range.</param> /// <param name="attribute">The attribute to search for.</param> /// <param name="value">The attribute value to search for. This value must match the type specified for the attribute.</param> /// <param name="backward">true if the last occurring text range should be returned instead of the first; otherwise false.</param> /// <returns> /// A text range having a matching attribute and attribute value; otherwise null /// </returns> internal static TextPatternRange FindAttribute(AutomationElement control, TextPatternRange targetRange, AutomationTextAttribute attribute, object value, bool backward) { CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control); return(targetRange.FindAttribute(attribute, value, backward)); }
/// <summary> /// Retrieves the value of a text attribute over the entire range. /// </summary> /// <param name="attribute">The text attribute.</param> /// <returns>The value of the attribute across the range. /// If the attribute's value varies over the range then the value is TextPattern.MixedAttributeValue</returns> public object GetAttributeValue(AutomationTextAttribute attribute) { Misc.ValidateArgumentNonNull(attribute, "attribute"); AutomationAttributeInfo ai; if(!Schema.GetAttributeInfo(attribute, out ai)) { throw new ArgumentException(SR.Get(SRID.UnsupportedAttribute)); } object obj = UiaCoreApi.TextRange_GetAttributeValue(_hTextRange, attribute.Id); if (ai.Type.IsEnum && obj is int) { // Convert ints from COM Interop to the appropriate enum type obj = Enum.ToObject(ai.Type, (int)obj); } else if (obj != AutomationElement.NotSupported && ai.ObjectConverter != null) { // Use a custom converter, if needed (eg. converts LCIDs to CultureInfo) obj = ai.ObjectConverter(obj); } return obj; }
/// <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); }