OSDN Git Service

AutoCompleteをあとからセットする可能性があった
authorkonekoneko <test2214@hotmail.co.jp>
Wed, 16 Nov 2016 16:28:53 +0000 (21:58 +0530)
committerkonekoneko <test2214@hotmail.co.jp>
Wed, 16 Nov 2016 16:28:53 +0000 (21:58 +0530)
Core/Document.cs
UWP/FooEditEngine.UWP/FooTextBox.cs
WPF/FooEditEngine/FooTextBox.cs

index 8ec563d..40f6d4f 100644 (file)
@@ -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;
index 798875c..49f03d5 100644 (file)
@@ -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;
+            };
+        }
+
         /// <inheritdoc/>
         public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
         {
index 0bd9fff..0fa8933 100644 (file)
@@ -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));
+            };
+        }
+
         /// <summary>
         /// プロパティーが変更されたときに呼ばれます
         /// </summary>