//========================================================================================
+ public struct TextSelection
+ {
+ public int start;
+ public int end;
+ public TextSelection(int start = 0,int end = 0)
+ {
+ this.start = start;
+ this.end = end;
+ }
+ }
+
/// <summary>Dispose() で TextStore のロック解除を行うクラス。</summary>
public class Unlocker : IDisposable
public delegate bool IsLoadingHandler();
public event IsLoadingHandler IsLoading;
+ public event Func<int> GetSelectionCount;
+
public delegate int GetStringLengthHandler();
public event GetStringLengthHandler GetStringLength;
- public delegate void GetSelectionIndexHandler(out int o_start, out int o_end);
+ public delegate void GetSelectionIndexHandler(int start_index, int max_count, out TextSelection[] sel);
public event GetSelectionIndexHandler GetSelectionIndex;
- public delegate void SetSelectionIndexHandler(int i_start, int i_end);
+ public delegate void SetSelectionIndexHandler(TextSelection[] sel);
public event SetSelectionIndexHandler SetSelectionIndex;
public delegate string GetStringHandler(int start, int length);
public delegate void CompositionEndedHandler();
public event CompositionEndedHandler CompositionEnded;
+ bool _allow_multi_sel = false;
+
#region "生成と破棄"
- public TextStoreBase()
+ public TextStoreBase(bool allow_multi_sel = false)
{
#if TSF_DEBUG_OUTPUT
using(var dbgout = new DebugOut("{0}()", DebugOut.GetCaller()) )
#endif
{
+ this._allow_multi_sel = allow_multi_sel;
try
{
// スレッドマネージャ-の生成
else
o_documentStatus.dynamicFlags = 0;
o_documentStatus.staticFlags = StaticStatusFlags.TS_SS_REGIONS;
+ if (this._allow_multi_sel)
+ o_documentStatus.staticFlags |= StaticStatusFlags.TS_SS_DISJOINTSEL;
}
}
// -1 は TF_DEFAULT_SELECTION。選択は1つだけしかサポートしないので、
// TF_DEFAULT_SELECTION でもなく、0 を超える数値が指定された場合はエラー。
- if (i_index != -1 && i_index > 0)
+ if (i_index != -1 && i_index > 0 && !this._allow_multi_sel)
{
throw new COMException(
"選択は1つだけしかサポートしていません。",
if (i_selectionBufferLength > 0)
{
- int start = 0, end = 0;
- GetSelectionIndex(out start, out end);
- if (start <= end)
+ TextSelection[] sels;
+ GetSelectionIndex(i_index,i_selectionBufferLength,out sels);
+ if (sels == null)
+ throw new InvalidOperationException("selsはnull以外の値を返す必要があります");
+ for(int i = 0; i < sels.Length; i++)
{
- o_selections[0].start = start;
- o_selections[0].end = end;
- o_selections[0].style.ase = TsActiveSelEnd.TS_AE_END;
- o_selections[0].style.interimChar = false;
- }
- else
- {
- o_selections[0].start = end;
- o_selections[0].end = start;
- o_selections[0].style.ase = TsActiveSelEnd.TS_AE_START;
- o_selections[0].style.interimChar = false;
+ int start = sels[i].start, end = sels[i].end;
+
+ if (start <= end)
+ {
+ o_selections[0].start = start;
+ o_selections[0].end = end;
+ o_selections[0].style.ase = TsActiveSelEnd.TS_AE_END;
+ o_selections[0].style.interimChar = false;
+ }
+ else
+ {
+ o_selections[0].start = end;
+ o_selections[0].end = start;
+ o_selections[0].style.ase = TsActiveSelEnd.TS_AE_START;
+ o_selections[0].style.interimChar = false;
+ }
}
- o_fetchedLength = 1;
+ o_fetchedLength = sels.Length;
#if TSF_DEBUG_OUTPUT
DebugOut.Print("sel start:{0} end:{1}", start, end);
if (SetSelectionIndex == null)
throw new NotImplementedException();
- if (i_count != 1)
+ if (i_count != 1 && !this._allow_multi_sel)
{
throw new COMException(
"選択は1つだけしかサポートしていません。",
);
}
- SetSelectionIndex(i_selections[0].start, i_selections[0].end);
+ TextSelection[] sels = new TextSelection[i_count];
+ for(int i = 0; i < i_count; i++)
+ {
+ sels[i] = new TextSelection(i_selections[i].start, i_selections[i].end);
+ }
+
+ SetSelectionIndex(sels);
#if TSF_DEBUG_OUTPUT
DebugOut.Print("set selection startIndex:{0} endIndex:{1}", i_selections[0].start, i_selections[0].end);
if (GetSelectionIndex == null || InsertAtSelection == null)
throw new NotImplementedException();
- int selectionStart = 0, selectionEnd = 0;
- GetSelectionIndex(out selectionStart, out selectionEnd);
+ int sel_count = 1;
+ if(this.GetSelectionCount != null)
+ sel_count = this.GetSelectionCount();
- // 問い合わせのみで実際には操作を行わない
- if ((i_flags & InsertAtSelectionFlags.TF_IAS_QUERYONLY) != 0)
- {
- o_startIndex = Math.Min(selectionStart, selectionEnd);
- o_endIndex = Math.Max(selectionStart, selectionEnd);//o_startIndex + i_length;
+ if (sel_count == 0)
+ throw new InvalidOperationException("sel_countは1以上の値でなければなりません");
- o_textChange.start = o_startIndex;
- o_textChange.oldEnd = o_endIndex;
- o_textChange.newEnd = o_startIndex + i_length;
- }
- else
+ //エラーになるので適当な値で埋めておく
+ o_startIndex = 0;
+ o_endIndex = 0;
+ o_textChange.start = 0;
+ o_textChange.oldEnd = 0;
+ o_textChange.newEnd = 0;
+
+ TextSelection[] sels;
+ GetSelectionIndex(0, sel_count, out sels);
+
+ for(int i = 0; i < sel_count; i++)
{
- var start = Math.Min(selectionStart, selectionEnd);
- var end = Math.Max(selectionStart, selectionEnd);
+ // 問い合わせのみで実際には操作を行わない
+ if ((i_flags & InsertAtSelectionFlags.TF_IAS_QUERYONLY) != 0)
+ {
+ o_startIndex = Math.Min(sels[i].start, sels[i].end);
+ o_endIndex = Math.Max(sels[i].start, sels[i].end);//o_startIndex + i_length;
+
+ o_textChange.start = o_startIndex;
+ o_textChange.oldEnd = o_endIndex;
+ o_textChange.newEnd = o_startIndex + i_length;
+ }
+ else
+ {
+ var start = Math.Min(sels[i].start, sels[i].end);
+ var end = Math.Max(sels[i].start, sels[i].end);
#if TSF_DEBUG_OUTPUT
DebugOut.Print("start: {0}, end: {1}, text: {2}", start, end, new string(i_text));
#endif
- o_startIndex = start;
- o_endIndex = start + i_length;
+ o_startIndex = start;
+ o_endIndex = start + i_length;
- InsertAtSelection(new string(i_text), ref o_startIndex, ref o_endIndex);
+ InsertAtSelection(new string(i_text), ref o_startIndex, ref o_endIndex);
- o_textChange.start = start;
- o_textChange.oldEnd = end;
- o_textChange.newEnd = o_endIndex;
- // InsertAtSelection() 内でカーソル位置を更新しているため、ここでは不要。
- // 改行した時に位置が狂う。
- // SetSelectionIndex(start, start + i_length);
+ o_textChange.start = start;
+ o_textChange.oldEnd = end;
+ o_textChange.newEnd = o_endIndex;
+ // InsertAtSelection() 内でカーソル位置を更新しているため、ここでは不要。
+ // 改行した時に位置が狂う。
+ // SetSelectionIndex(start, start + i_length);
+ }
}
}
}