Skip to content

Replace ArrayList from CompositionAdorner with List<AttributeRange> #10673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static CompositionAdorner()
/// <param name="textView">
/// TextView to which this CompositionAdorner is attached as adorner.
/// </param>
internal CompositionAdorner(ITextView textView) : this(textView, new ArrayList())
internal CompositionAdorner(ITextView textView) : this(textView, new List<AttributeRange>())
{
}

Expand All @@ -50,8 +50,7 @@ static CompositionAdorner()
/// <param name="attributeRanges">
/// Attribute ranges
/// </param>
internal CompositionAdorner(ITextView textView, ArrayList attributeRanges)
: base(textView.RenderScope)
private CompositionAdorner(ITextView textView, List<AttributeRange> attributeRanges) : base(textView.RenderScope)
{
Debug.Assert(textView != null && textView.RenderScope != null);

Expand Down Expand Up @@ -83,23 +82,17 @@ internal CompositionAdorner(ITextView textView, ArrayList attributeRanges)
/// Transform to apply to the adorner
/// </returns>
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
TranslateTransform translation;
GeneralTransformGroup group = new GeneralTransformGroup();

{
// Get the matrix transform out, skip all non affine transforms
Transform t = transform.AffineTransform;
if (t == null)
{
t = Transform.Identity;
}
Transform t = transform.AffineTransform ?? Transform.Identity;

// Translate the adorner to (0, 0) point
translation = new TranslateTransform(-(t.Value.OffsetX), -(t.Value.OffsetY));
TranslateTransform translation = new(-t.Value.OffsetX, -t.Value.OffsetY);

GeneralTransformGroup group = new GeneralTransformGroup();
group.Children.Add(translation);

if (transform != null)
if (transform is not null)
{
group.Children.Add(transform);
}
Expand All @@ -124,8 +117,7 @@ protected override void OnRender(DrawingContext drawingContext)
{
// Get the matrix from AdornedElement to the visual parent to get the transformed
// start/end point
Visual parent2d = VisualTreeHelper.GetParent(this.AdornedElement) as Visual;
if (parent2d == null)
if (VisualTreeHelper.GetParent(AdornedElement) is not Visual parent2d)
{
return;
}
Expand All @@ -149,7 +141,7 @@ protected override void OnRender(DrawingContext drawingContext)
DoubleCollection dashArray;

// Get the composition attribute range from the attribute range lists
AttributeRange attributeRange = (AttributeRange)_attributeRanges[i];
AttributeRange attributeRange = _attributeRanges[i];

// Skip the rendering composition lines if the composition line doesn't exist.
if (attributeRange.CompositionLines.Count == 0)
Expand All @@ -158,7 +150,7 @@ protected override void OnRender(DrawingContext drawingContext)
}

// Set the line bold and squiggle
bool lineBold = attributeRange.TextServicesDisplayAttribute.IsBoldLine ? true : false;
bool lineBold = attributeRange.TextServicesDisplayAttribute.IsBoldLine;
bool squiggle = false;
bool hasVirtualSelection = (attributeRange.TextServicesDisplayAttribute.AttrInfo & UnsafeNativeMethods.TF_DA_ATTR_INFO.TF_ATTR_TARGET_CONVERTED) != 0;

Expand Down Expand Up @@ -340,15 +332,14 @@ internal void InvalidateAdorner()
for (int i = 0; i < _attributeRanges.Count; i++)
{
// Get the composition attribute range from the attribute range lists
AttributeRange attributeRange = (AttributeRange)_attributeRanges[i];
AttributeRange attributeRange = _attributeRanges[i];

// Add the composition lines for rendering the composition lines
attributeRange.AddCompositionLines();
}

// Invalidate the CompositionAdorner to update the rendering.
AdornerLayer adornerLayer = VisualTreeHelper.GetParent(this) as AdornerLayer;
if (adornerLayer != null)
if (VisualTreeHelper.GetParent(this) is AdornerLayer adornerLayer)
{
adornerLayer.Update(AdornedElement);
adornerLayer.InvalidateArrange();
Expand All @@ -375,7 +366,7 @@ internal void Uninitialize()
{
if (_adornerLayer != null)
{
// Remove CompositionAdorner form the socping of AdornerLayer
// Remove CompositionAdorner from the scoping of AdornerLayer
_adornerLayer.Remove(this);
_adornerLayer = null;
}
Expand All @@ -398,7 +389,7 @@ internal void Uninitialize()
private ITextView _textView;

// ArrayList for the composition attribute ranges
private readonly ArrayList _attributeRanges;
private readonly List<AttributeRange> _attributeRanges;

// Composition line's dot length
private const double DotLength = 1.2;
Expand Down