CPF/CPF.ReoGrid/Drawing/DrawingObjectCollection.cs
2024-06-24 10:15:59 +08:00

103 lines
2.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
namespace CPF.ReoGrid.Drawing
{
public class DrawingObjectCollection : IDrawingObjectCollection, IFloatingObjectCollection<IDrawingObject>, ICollection<IDrawingObject>, IEnumerable<IDrawingObject>, IEnumerable
{
public IDrawingContainer Owner { get; private set; }
internal DrawingObjectCollection(DrawingComponent owner)
{
this.Owner = owner;
this.list = owner.drawingObjects;
}
public virtual void Add(IDrawingObject item)
{
item.Container = this.Owner;
this.list.Add(item);
this.Owner.OnChildAdded(item, this.list.Count - 1);
}
public virtual IDrawingObject this[int index]
{
get
{
return this.list[index];
}
}
public virtual void Clear()
{
foreach (IDrawingObject drawingObject in this.list)
{
drawingObject.Container = null;
}
this.list.Clear();
this.Owner.OnChildrenClear();
}
public bool Contains(IDrawingObject item)
{
return this.list.Contains(item);
}
public void CopyTo(IDrawingObject[] array, int arrayIndex)
{
this.list.CopyTo(array, arrayIndex);
}
public int Count
{
get
{
return this.list.Count;
}
}
public bool IsReadOnly
{
get
{
return false;
}
}
public virtual bool Remove(IDrawingObject item)
{
item.Container = null;
return this.list.Remove(item);
}
private IEnumerator<IDrawingObject> GetEnum()
{
return this.list.GetEnumerator();
}
public IEnumerator<IDrawingObject> GetEnumerator()
{
return this.GetEnum();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnum();
}
public virtual void AddRange(IEnumerable<IDrawingObject> drawingObjects)
{
this.list.AddRange(drawingObjects);
int count = this.list.Count;
foreach (IDrawingObject drawingObject in drawingObjects)
{
drawingObject.Container = this.Owner;
this.Owner.OnChildAdded(drawingObject, count++);
}
}
private List<IDrawingObject> list;
}
}