2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
12 using System.Collections.Generic;
14 namespace FooEditEngine
19 struct Selection : IRange,IEqualityComparer<Selection>
33 public static Selection Create(int start, int length)
35 return new Selection { start = start, length = length};
38 public bool Equals(Selection x, Selection y)
40 return x.length == y.length && x.start == y.start;
43 public int GetHashCode(Selection obj)
45 return this.start ^ this.length;
50 /// 選択範囲が更新されたことを通知するデリゲート
52 /// <param name="sender">送信元クラス</param>
53 /// <param name="e">イベントデータ</param>
54 public delegate void SelectChangeEventHandler(object sender,EventArgs e);
57 /// 選択範囲を格納するコレクションを表します
59 sealed class SelectCollection : IEnumerable<Selection>
61 RangeCollection<Selection> collection;
66 public SelectCollection()
74 /// <param name="selections">コレクションを表します</param>
75 public SelectCollection(IEnumerable<Selection> selections)
77 if (selections != null)
78 collection = new RangeCollection<Selection>(selections);
80 collection = new RangeCollection<Selection>();
81 this.SelectChange += new SelectChangeEventHandler((s,e)=>{});
85 /// 選択領域が更新されたことを通知します
87 public event SelectChangeEventHandler SelectChange;
92 /// <param name="i">0から始まるインデックス</param>
93 /// <returns>選択領域を返します</returns>
94 public Selection this[int i]
98 return this.collection[i];
102 this.collection[i] = value;
109 /// <param name="sel">選択領域</param>
110 public void Add(Selection sel)
112 this.collection.Add(sel);
113 this.SelectChange(this, null);
121 this.collection.Clear();
122 this.SelectChange(this, null);
128 /// <param name="index">インデックス</param>
129 /// <param name="length">長さ</param>
130 /// <returns>要素を表すイテレーター</returns>
131 public IEnumerable<Selection> Get(int index, int length)
133 return this.collection.Get(index, length);
137 /// 格納されている選択領域の数を返します
143 return this.collection.Count;
147 #region IEnumerable<Selection> メンバー
152 /// <returns>IEnumeratorオブジェクトを返す</returns>
153 public IEnumerator<Selection> GetEnumerator()
155 for (int i = 0; i < this.collection.Count; i++)
156 yield return this.collection[i];
161 #region IEnumerable メンバー
163 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
165 throw new NotImplementedException();