From 65ddb48c31c2b725432c840292c99603083ee8db Mon Sep 17 00:00:00 2001 From: konekoneko Date: Wed, 16 Nov 2016 21:58:53 +0530 Subject: [PATCH] =?utf8?q?AutoComplete=E3=82=92=E3=81=82=E3=81=A8=E3=81=8B?= =?utf8?q?=E3=82=89=E3=82=BB=E3=83=83=E3=83=88=E3=81=99=E3=82=8B=E5=8F=AF?= =?utf8?q?=E8=83=BD=E6=80=A7=E3=81=8C=E3=81=82=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Core/Document.cs | 15 +++++++++++++-- UWP/FooEditEngine.UWP/FooTextBox.cs | 38 +++++++++++++++++++++---------------- WPF/FooEditEngine/FooTextBox.cs | 31 ++++++++++++++++++------------ 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/Core/Document.cs b/Core/Document.cs index 8ec563d..40f6d4f 100644 --- a/Core/Document.cs +++ b/Core/Document.cs @@ -233,10 +233,21 @@ namespace FooEditEngine set; } + public event EventHandler AutoCompleteChanged; + + AutoCompleteBoxBase _AutoComplete; public AutoCompleteBoxBase AutoComplete { - get; - set; + get + { + return this._AutoComplete; + } + set + { + this._AutoComplete = value; + if (this.AutoCompleteChanged != null) + this.AutoCompleteChanged(this, null); + } } public event ProgressEventHandler LoadProgress; diff --git a/UWP/FooEditEngine.UWP/FooTextBox.cs b/UWP/FooEditEngine.UWP/FooTextBox.cs index 798875c..49f03d5 100644 --- a/UWP/FooEditEngine.UWP/FooTextBox.cs +++ b/UWP/FooEditEngine.UWP/FooTextBox.cs @@ -1279,6 +1279,7 @@ namespace FooEditEngine.UWP old_doc.Update -= new DocumentUpdateEventHandler(Document_Update); this._Document.SelectionChanged -= Controller_SelectionChanged; this._Document.LoadProgress -= Document_LoadProgress; + this._Document.AutoCompleteChanged -= _Document_AutoCompleteChanged; if (this._Document.AutoComplete != null) { this._Document.AutoComplete.GetPostion = null; @@ -1295,22 +1296,9 @@ namespace FooEditEngine.UWP this._Document.LayoutLines.Render = this.Render; this._Document.Update += new DocumentUpdateEventHandler(Document_Update); this._Document.LoadProgress += Document_LoadProgress; - if(this._Document.AutoComplete != null) - { - this._Document.AutoComplete.GetPostion = (tp,doc) => - { - var p = this.View.GetPostionFromTextPoint(tp); - int height = (int)doc.LayoutLines.GetLayout(doc.CaretPostion.row).Height; - - if (p.Y + AutoCompleteBox.CompleteListBoxHeight + height > doc.LayoutLines.Render.TextArea.Height) - p.Y -= AutoCompleteBox.CompleteListBoxHeight; - else - p.Y += height; - //AutoCompleteBox内ではCanvasで位置を指定しているので変換する必要がある - var pointInWindow = Util.GetPointInWindow(p, this); - return pointInWindow; - }; - } + this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged; + if (this._Document.AutoComplete != null && this._Document.AutoComplete.GetPostion == null) + this._Document_AutoCompleteChanged(this._Document, null); //初期化が終わっていればすべて存在する if (this.Controller != null && this.View != null) { @@ -1343,6 +1331,24 @@ namespace FooEditEngine.UWP this._Document.SelectionChanged += Controller_SelectionChanged; } + private void _Document_AutoCompleteChanged(object sender, EventArgs e) + { + Document doc = (Document)sender; + doc.AutoComplete.GetPostion = (tp, e_doc) => + { + var p = this.View.GetPostionFromTextPoint(tp); + int height = (int)e_doc.LayoutLines.GetLayout(e_doc.CaretPostion.row).Height; + + if (p.Y + AutoCompleteBox.CompleteListBoxHeight + height > e_doc.LayoutLines.Render.TextArea.Height) + p.Y -= AutoCompleteBox.CompleteListBoxHeight; + else + p.Y += height; + //AutoCompleteBox内ではCanvasで位置を指定しているので変換する必要がある + var pointInWindow = Util.GetPointInWindow(p, this); + return pointInWindow; + }; + } + /// public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e) { diff --git a/WPF/FooEditEngine/FooTextBox.cs b/WPF/FooEditEngine/FooTextBox.cs index 0bd9fff..0fa8933 100644 --- a/WPF/FooEditEngine/FooTextBox.cs +++ b/WPF/FooEditEngine/FooTextBox.cs @@ -1245,7 +1245,8 @@ namespace FooEditEngine.WPF { old_doc.Update -= new DocumentUpdateEventHandler(Document_Update); old_doc.LoadProgress -= Document_LoadProgress; - old_doc.SelectionChanged += new EventHandler(Controller_SelectionChanged); + old_doc.SelectionChanged -= new EventHandler(Controller_SelectionChanged); + old_doc.AutoCompleteChanged -= _Document_AutoCompleteChanged; oldLength = old_doc.Length; if (this._Document.AutoComplete != null) { @@ -1259,17 +1260,9 @@ namespace FooEditEngine.WPF this._Document.LayoutLines.Render = this.Render; this._Document.Update += new DocumentUpdateEventHandler(Document_Update); this._Document.LoadProgress += Document_LoadProgress; - if (this._Document.AutoComplete != null) - { - ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup; - this._Document.AutoComplete.GetPostion = (tp, doc) => - { - var p = this.View.GetPostionFromTextPoint(tp); - int height = (int)doc.LayoutLines.GetLayout(doc.CaretPostion.row).Height; - p.Y += height; - return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this)); - }; - } + this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged; + if (this._Document.AutoComplete != null && this.Document.AutoComplete.GetPostion == null) + this._Document_AutoCompleteChanged(this.Document, null); //初期化が終わっていればすべて存在する if (this.Controller != null && this.View != null && this.textStore != null) { @@ -1299,6 +1292,20 @@ namespace FooEditEngine.WPF this.Refresh(); } } + + private void _Document_AutoCompleteChanged(object sender, EventArgs e) + { + Document doc = (Document)sender; + ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup; + this._Document.AutoComplete.GetPostion = (tp, edoc) => + { + var p = this.View.GetPostionFromTextPoint(tp); + int height = (int)doc.LayoutLines.GetLayout(edoc.CaretPostion.row).Height; + p.Y += height; + return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this)); + }; + } + /// /// プロパティーが変更されたときに呼ばれます /// -- 2.11.0