Skip to content
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

Refactor ResizeBehavior to use List<T> instead of ArrayList #10236

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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 @@ -3,7 +3,6 @@

#nullable disable

using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
Expand All @@ -17,7 +16,7 @@ internal class ResizeBehavior : Behavior
{
private struct ResizeComponent
{
public object resizeControl;
public Control resizeControl;
public Rectangle resizeBounds;
public SelectionRules resizeRules;
}
Expand Down Expand Up @@ -200,19 +199,19 @@ private SnapLine[] GenerateSnapLines(SelectionRules rules, Point loc)
private void InitiateResize()
{
bool useSnapLines = BehaviorService.UseSnapLines;
List<IComponent> components = new();
List<IComponent> components = [];
//check to see if the current designer participate with SnapLines cache the control bounds
for (int i = 0; i < _resizeComponents.Length; i++)
{
_resizeComponents[i].resizeBounds = ((Control)(_resizeComponents[i].resizeControl)).Bounds;
_resizeComponents[i].resizeBounds = _resizeComponents[i].resizeControl.Bounds;
if (useSnapLines)
{
components.Add((Control)_resizeComponents[i].resizeControl);
components.Add(_resizeComponents[i].resizeControl);
}

if (_serviceProvider.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost)
{
if (designerHost.GetDesigner(_resizeComponents[i].resizeControl as Component) is ControlDesigner designer)
if (designerHost.GetDesigner(_resizeComponents[i].resizeControl) is ControlDesigner designer)
{
_resizeComponents[i].resizeRules = designer.SelectionRules;
}
Expand Down Expand Up @@ -316,22 +315,22 @@ public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
_primaryControl = selSvc.PrimarySelection as Control;

// Since we don't know exactly how many valid objects we are going to have we use this temp
ArrayList components = new ArrayList();
foreach (object o in selSvc.GetSelectedComponents())
List<Control> components = [];
foreach (object component in selSvc.GetSelectedComponents())
{
if (o is Control)
if (component is Control control)
{
//don't drag locked controls
PropertyDescriptor prop = TypeDescriptor.GetProperties(o)["Locked"];
PropertyDescriptor prop = TypeDescriptor.GetProperties(control)["Locked"];
if (prop is not null)
{
if ((bool)prop.GetValue(o))
if ((bool)prop.GetValue(control))
{
continue;
}
}

components.Add(o);
components.Add(control);
}
}

Expand Down Expand Up @@ -370,7 +369,7 @@ public override void OnLoseCapture(Glyph g, EventArgs e)
//make sure we get rid of the selection rectangle
for (int i = 0; !_captureLost && i < _resizeComponents.Length; i++)
{
Control control = _resizeComponents[i].resizeControl as Control;
Control control = _resizeComponents[i].resizeControl;
Rectangle borderRect = BehaviorService.ControlRectInAdornerWindow(control);
if (!borderRect.IsEmpty)
{
Expand Down Expand Up @@ -531,7 +530,7 @@ public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
}
}

Control targetControl = _resizeComponents[0].resizeControl as Control;
Control targetControl = _resizeComponents[0].resizeControl;
_lastMouseLoc = mouseLoc;
_lastMouseAbs = new Point(mouseLoc.X, mouseLoc.Y);
PInvoke.ClientToScreen(_behaviorService.AdornerWindowControl, ref _lastMouseAbs);
Expand Down Expand Up @@ -602,7 +601,7 @@ public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
Color backColor = targetControl.Parent is not null ? targetControl.Parent.BackColor : Color.Empty;
for (int i = 0; i < _resizeComponents.Length; i++)
{
Control control = _resizeComponents[i].resizeControl as Control;
Control control = _resizeComponents[i].resizeControl;
Rectangle bounds = control.Bounds;
Rectangle oldBounds = bounds;
// We need to compute the offset based on the original cached Bounds ... ListBox doesnt allow drag on the top boundary if this is not done when it is "IntegralHeight"
Expand Down Expand Up @@ -858,24 +857,24 @@ public override bool OnMouseUp(Glyph g, MouseButtons button)
PropertyDescriptor propLeft = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Left"];
for (int i = 0; i < _resizeComponents.Length; i++)
{
if (propWidth is not null && ((Control)_resizeComponents[i].resizeControl).Width != _resizeComponents[i].resizeBounds.Width)
if (propWidth is not null && _resizeComponents[i].resizeControl.Width != _resizeComponents[i].resizeBounds.Width)
{
propWidth.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Width);
propWidth.SetValue(_resizeComponents[i].resizeControl, _resizeComponents[i].resizeControl.Width);
}

if (propHeight is not null && ((Control)_resizeComponents[i].resizeControl).Height != _resizeComponents[i].resizeBounds.Height)
if (propHeight is not null && _resizeComponents[i].resizeControl.Height != _resizeComponents[i].resizeBounds.Height)
{
propHeight.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Height);
propHeight.SetValue(_resizeComponents[i].resizeControl, _resizeComponents[i].resizeControl.Height);
}

if (propTop is not null && ((Control)_resizeComponents[i].resizeControl).Top != _resizeComponents[i].resizeBounds.Y)
if (propTop is not null && _resizeComponents[i].resizeControl.Top != _resizeComponents[i].resizeBounds.Y)
{
propTop.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Top);
propTop.SetValue(_resizeComponents[i].resizeControl, _resizeComponents[i].resizeControl.Top);
}

if (propLeft is not null && ((Control)_resizeComponents[i].resizeControl).Left != _resizeComponents[i].resizeBounds.X)
if (propLeft is not null && _resizeComponents[i].resizeControl.Left != _resizeComponents[i].resizeBounds.X)
{
propLeft.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Left);
propLeft.SetValue(_resizeComponents[i].resizeControl, _resizeComponents[i].resizeControl.Left);
}

if (_resizeComponents[i].resizeControl == _primaryControl && _statusCommandUI is not null)
Expand Down
Loading