Skip to content

Replace ArrayList with List<T> in CompositionAdorner for type safety #10839

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

Closed
Closed
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
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections; // ArrayList
using System.Collections.Generic; // List<T>
using System.Windows.Media; // Brush, Transform
using System.Windows.Controls.Primitives; // TextBoxBase
using System.Windows.Input; // InputLanguageManager
Expand Down Expand Up @@ -29,14 +29,14 @@ static CompositionAdorner()
// Provide a new default value for the composition adorner so that it is not hit-testable.
IsEnabledProperty.OverrideMetadata(typeof(CompositionAdorner), new FrameworkPropertyMetadata(false));
}

/// <summary>
/// Creates new instance of CompositionAdorner.
/// </summary>
/// <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 @@ -49,7 +49,7 @@ static CompositionAdorner()
/// <param name="attributeRanges">
/// Attribute ranges
/// </param>
internal CompositionAdorner(ITextView textView, ArrayList attributeRanges)
internal CompositionAdorner(ITextView textView, List<AttributeRange> attributeRanges)
: base(textView.RenderScope)
{
Debug.Assert(textView != null && textView.RenderScope != null);
Expand All @@ -58,7 +58,7 @@ internal CompositionAdorner(ITextView textView, ArrayList attributeRanges)
// als be used for GetRectangleFromTextPosition/GetLineRange
_textView = textView;

// Create ArrayList for the composition attribute ranges and composition lines
// Store composition attribute ranges using a strongly-typed List
_attributeRanges = attributeRanges;
}

Expand All @@ -82,15 +82,15 @@ 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;
{
t = Transform.Identity;
}

// Translate the adorner to (0, 0) point
Expand All @@ -113,7 +113,7 @@ public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
// Protected Methods
//
//------------------------------------------------------

#region Protected Methods

/// <summary>
Expand Down Expand Up @@ -240,7 +240,7 @@ protected override void OnRender(DrawingContext drawingContext)
// to the closest area of the bottom text.
Point startPoint = new Point(compositionLine.StartPoint.X + clauseGap, compositionLine.StartPoint.Y - halfLineHeight);
Point endPoint = new Point(compositionLine.EndPoint.X - clauseGap, compositionLine.EndPoint.Y - halfLineHeight);

// Apply composition line color which is actually the foreground of text as well
pen.Brush = new SolidColorBrush(compositionLine.LineColor);

Expand All @@ -253,14 +253,14 @@ protected override void OnRender(DrawingContext drawingContext)
{
Rect rect = Rect.Union(compositionLine.StartRect, compositionLine.EndRect);
rect = transform.TransformBounds(rect);

drawingContext.PushOpacity(selectionOpacity);

drawingContext.DrawRectangle(selectionBrush, selectionPen, rect);

drawingContext.Pop();
}

if (squiggle)
{
// Draw the squiggle line with using of the PathFigure and DrawGemetry.
Expand Down Expand Up @@ -397,7 +397,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 Expand Up @@ -440,7 +440,7 @@ internal void Uninitialize()
//
//------------------------------------------------------

private class AttributeRange
internal class AttributeRange
{
//------------------------------------------------------
//
Expand All @@ -458,7 +458,7 @@ internal AttributeRange(ITextView textView, ITextPointer start, ITextPointer end

_textServicesDisplayAttribute = textServicesDisplayAttribute;

_compositionLines = new ArrayList(1);
_compositionLines = new List<CompositionLine>(1);
}

#endregion Constructors
Expand Down Expand Up @@ -533,7 +533,7 @@ internal double Height
/// <summary>
/// CompositionLines of the composition attribute range.
/// </summary>
internal ArrayList CompositionLines
internal List<CompositionLine> CompositionLines
{
get
{
Expand Down Expand Up @@ -656,8 +656,8 @@ private void AddMultipleCompositionLines(ITextPointer start, ITextPointer end)
// Composition display attribute that is specified from IME
private readonly TextServicesDisplayAttribute _textServicesDisplayAttribute;

// ArrayList for the composition lines
private readonly ArrayList _compositionLines;
// List of composition lines to be rendered
private readonly List<CompositionLine> _compositionLines;

#endregion Private Fields
}
Expand Down Expand Up @@ -716,23 +716,23 @@ internal Point EndPoint
/// </summary>
internal Rect StartRect
{
get
{
return _startRect;
get
{
return _startRect;
}
}

/// <summary>
/// End rect of the composition line draw
/// </summary>
internal Rect EndRect
{
get
{
return _endRect;
get
{
return _endRect;
}
}

/// <summary>
/// Color of the composition line draw
/// </summary>
Expand Down Expand Up @@ -767,5 +767,3 @@ internal Color LineColor
}
}
}


Loading