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/>.
11 #if METRO || WPF || WINDOWS_UWP
15 using DotNetTextStore.UnmanagedAPI.WinDef;
16 using DotNetTextStore.UnmanagedAPI.TSF;
17 using DotNetTextStore;
20 namespace FooEditEngine
22 static class TextStoreHelper
24 public static bool StartCompstion(Document document)
26 document.UndoManager.BeginUndoGroup();
30 public static void EndCompostion(Document document)
32 document.UndoManager.EndUndoGroup();
36 public static bool ScrollToCompstionUpdated(TextStoreBase textStore,EditView view,int start, int end)
38 if (textStore.IsLocked() == false)
40 using (Unlocker locker = textStore.LockDocument(false))
42 foreach (TextDisplayAttribute attr in textStore.EnumAttributes(start, end))
44 if (attr.attribute.bAttr == TF_DA_ATTR_INFO.TF_ATTR_TARGET_CONVERTED)
46 if (view.AdjustSrc(attr.startIndex))
57 public static void GetStringExtent(Document document,EditView view,int i_startIndex,int i_endIndex,out Point startPos,out Point endPos)
59 var endIndex = i_endIndex < 0 ? document.Length - 1 : i_endIndex;
60 TextPoint endTextPoint;
62 startPos = view.GetPostionFromTextPoint(view.LayoutLines.GetTextPointFromIndex(i_startIndex));
63 endTextPoint = view.GetLayoutLineFromIndex(endIndex);
64 endPos = view.GetPostionFromTextPoint(endTextPoint);
65 //アンダーラインを描くことがあるので少しずらす
66 endPos.Y += view.LayoutLines.GetLayout(endTextPoint.row).Height + 5;
69 public static void GetSelection(Controller controller, SelectCollection selectons, out TextRange sel)
71 if (controller.RectSelection && selectons.Count > 0)
73 sel.Index = selectons[0].start;
78 sel.Index = controller.SelectionStart;
79 sel.Length = controller.SelectionLength;
83 public static void SetSelectionIndex(Controller controller,EditView view,int i_startIndex,int i_endIndex)
85 if (controller.IsRectInsertMode())
87 TextPoint start = view.LayoutLines.GetTextPointFromIndex(i_startIndex);
88 TextPoint end = view.LayoutLines.GetTextPointFromIndex(view.Selections.Last().start);
89 controller.JumpCaret(i_endIndex);
90 controller.Document.Select(start, i_endIndex - i_startIndex, end.row - start.row);
92 else if (i_startIndex == i_endIndex)
94 controller.JumpCaret(i_startIndex);
98 controller.Document.Select(i_startIndex, i_endIndex - i_startIndex);
102 public static void InsertTextAtSelection(Controller controller,string i_value, bool fromTIP = true)
104 controller.DoInputString(i_value, fromTIP);
108 public static void NotifyTextChanged(TextStoreBase textStore, int startIndex,int removeLength,int insertLength)
111 //Windows8.1では同じ値にしないと日本語入力ができなくなってしまう
112 int oldend = startIndex,
115 //TS_TEXTCHANGE structure's remark
116 //1文字削除した場合はoldendに削除前の位置を設定し、newendとstartIndexに現在位置を設定し、
117 //1文字追加した場合はoldendに追加前の位置を設定し、newendとstartIndexに現在位置を設定する
118 int oldend = startIndex + removeLength,
119 newend = startIndex + insertLength;
121 textStore.NotifyTextChanged(startIndex, oldend, newend);