OSDN Git Service

TSF Wrapperで複数の選択領域を返せるようにした
authorgdkhd812 <test@nnn.co.jp>
Sat, 28 Nov 2015 11:13:16 +0000 (16:43 +0530)
committergdkhd812 <test@nnn.co.jp>
Sat, 28 Nov 2015 11:13:16 +0000 (16:43 +0530)
Core/TextServiceFramework/TextStoreHelper.cs
DotNetTextStore/TextStoreBase.cs
Metro/FooEditEngine/FooTextBox.cs
WPF/FooEditEngine/FooTextBox.cs

index f043f07..10be1d2 100644 (file)
@@ -61,22 +61,25 @@ namespace FooEditEngine
             endPos.Y += view.LayoutLines.GetLayout(endTextPoint.row).Height + 15;
         }
 
-        public static void GetSelection(Controller controller, SelectCollection selectons, out int o_startIndex, out int o_endIndex)
+        public static void GetSelection(Controller controller, SelectCollection selectons, out DotNetTextStore.TextSelection[] sels)
         {
+            sels = new TextSelection[1];
+            sels[0] = new TextSelection();
             if (controller.RectSelection && selectons.Count > 0)
             {
-                o_startIndex = selectons[0].start;
-                o_endIndex = o_startIndex + selectons[0].length;
+                sels[0].start = selectons[0].start;
+                sels[0].end = sels[0].start + selectons[0].length;
             }
             else
             {
-                o_startIndex = controller.SelectionStart;
-                o_endIndex = o_startIndex + controller.SelectionLength;
+                sels[0].start = controller.SelectionStart;
+                sels[0].end = sels[0].start + controller.SelectionLength;
             }
         }
 
-        public static void SetSelectionIndex(Controller controller,EditView view,int i_startIndex, int i_endIndex)
+        public static void SetSelectionIndex(Controller controller,EditView view,DotNetTextStore.TextSelection[] sels)
         {
+            int i_startIndex = sels[0].start, i_endIndex = sels[0].end;
             if (controller.IsRectInsertMode())
             {
                 TextPoint start = view.LayoutLines.GetTextPointFromIndex(i_startIndex);
index e0b5222..17d76b8 100644 (file)
@@ -64,6 +64,17 @@ namespace DotNetTextStore
 
     //========================================================================================
 
+    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
@@ -100,13 +111,15 @@ namespace DotNetTextStore
         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);
@@ -138,13 +151,16 @@ namespace DotNetTextStore
         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
                 {
                     // スレッドマネージャ-の生成
@@ -795,6 +811,8 @@ namespace DotNetTextStore
                 else
                     o_documentStatus.dynamicFlags = 0;
                 o_documentStatus.staticFlags = StaticStatusFlags.TS_SS_REGIONS;
+                if (this._allow_multi_sel)
+                    o_documentStatus.staticFlags |= StaticStatusFlags.TS_SS_DISJOINTSEL;
             }
         }
 
@@ -859,7 +877,7 @@ namespace DotNetTextStore
 
                 // -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つだけしかサポートしていません。",
@@ -869,24 +887,31 @@ namespace DotNetTextStore
 
                 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);
@@ -907,7 +932,7 @@ namespace DotNetTextStore
                 if (SetSelectionIndex == null)
                     throw new NotImplementedException();
 
-                if (i_count != 1)
+                if (i_count != 1 && !this._allow_multi_sel)
                 {
                     throw new COMException(
                         "選択は1つだけしかサポートしていません。",
@@ -923,7 +948,13 @@ namespace DotNetTextStore
                     );
                 }
 
-                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);
@@ -1115,39 +1146,56 @@ namespace DotNetTextStore
                 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);
+                    }
                 }
             }
         }
index 57a8c77..6df7193 100644 (file)
@@ -750,14 +750,14 @@ namespace FooEditEngine.Metro
             o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
         }
 
-        void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
+        void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
         {
-            TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
+            TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out sels);
         }
 
-        void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
+        void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
         {
-            TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
+            TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels);
             this.Refresh();
         }
 
index 145dcd2..7c3203a 100644 (file)
@@ -611,14 +611,14 @@ namespace FooEditEngine.WPF
             o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
         }
 
-        void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
+        void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
         {
-            TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
+            TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out sels);
         }
 
-        void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
+        void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
         {
-            TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
+            TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels);
             this.Refresh();
         }