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