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/>.
13 using DotNetTextStore.UnmanagedAPI.WinDef;
14 using DotNetTextStore.UnmanagedAPI.TSF;
15 using DotNetTextStore;
17 namespace FooEditEngine
19 static class TextStoreHelper
21 public static bool StartCompstion(Document document)
23 document.UndoManager.BeginUndoGroup();
27 public static void EndCompostion(Document document)
29 document.UndoManager.EndUndoGroup();
32 public static bool ScrollToCompstionUpdated(TextStoreBase textStore,EditView view,int start, int end)
34 if (textStore.IsLocked() == false)
36 using (Unlocker locker = textStore.LockDocument(false))
38 foreach (TextDisplayAttribute attr in textStore.EnumAttributes(start, end))
40 if (attr.attribute.bAttr == TF_DA_ATTR_INFO.TF_ATTR_TARGET_CONVERTED)
42 if (view.AdjustSrc(attr.startIndex))
52 public static void GetStringExtent(Document document,EditView view,int i_startIndex,int i_endIndex,out Point startPos,out Point endPos)
54 var endIndex = i_endIndex < 0 ? document.Length - 1 : i_endIndex;
55 TextPoint endTextPoint;
57 startPos = view.GetPostionFromTextPoint(view.LayoutLines.GetTextPointFromIndex(i_startIndex));
58 endTextPoint = view.GetLayoutLineFromIndex(endIndex);
59 endPos = view.GetPostionFromTextPoint(endTextPoint);
60 endPos.Y += view.LayoutLines.GetLayout(endTextPoint.row).Height;
63 public static void GetSelection(Controller controller, SelectCollection selectons, out int o_startIndex, out int o_endIndex)
65 if (controller.RectSelection && selectons.Count > 0)
67 o_startIndex = selectons[0].start;
68 o_endIndex = o_startIndex + selectons[0].length;
72 o_startIndex = controller.SelectionStart;
73 o_endIndex = o_startIndex + controller.SelectionLength;
77 public static void SetSelectionIndex(Controller controller,EditView view,int i_startIndex, int i_endIndex)
79 if (controller.IsRectInsertMode())
81 TextPoint start = view.LayoutLines.GetTextPointFromIndex(i_startIndex);
82 TextPoint end = view.LayoutLines.GetTextPointFromIndex(view.Selections.Last().start);
83 controller.JumpCaret(i_endIndex);
84 controller.Select(start, i_endIndex - i_startIndex, end.row - start.row);
86 else if (i_startIndex == i_endIndex)
88 controller.JumpCaret(i_startIndex);
92 controller.Select(i_startIndex, i_endIndex - i_startIndex);
96 public static void InsertTextAtSelection(Controller controller,string i_value)
98 controller.DoInputString(i_value, true);
101 public static void NotifyTextChanged(TextStoreBase textStore, int startIndex,int removeLength,int insertLength)
104 //Windows8.1では同じ値にしないと日本語入力ができなくなってしまう
105 int oldend = startIndex,
108 //TS_TEXTCHANGE structure's remark
109 //1文字削除した場合はoldendに削除前の位置を設定し、newendとstartIndexに現在位置を設定し、
110 //1文字追加した場合はoldendに追加前の位置を設定し、newendとstartIndexに現在位置を設定する
111 int oldend = startIndex + removeLength,
112 newend = startIndex + insertLength;
114 textStore.NotifyTextChanged(startIndex, oldend, newend);