OSDN Git Service

警告個所の改善と表示までの流れをわかりやすくした
authorkonekoneko <test2214@hotmail.co.jp>
Sun, 13 Nov 2016 09:21:26 +0000 (14:51 +0530)
committerkonekoneko <test2214@hotmail.co.jp>
Sun, 13 Nov 2016 09:21:26 +0000 (14:51 +0530)
Core/AutoCompleteBoxBase.cs
UWP/FooEditEngine.UWP/AutoCompleteBox.cs
UWP/FooEditEngine.UWP/FooTextBox.cs
WPF/FooEditEngine/AutoCompleteBox.cs
WPF/FooEditEngine/FooTextBox.cs

index 88f90d3..2521b69 100644 (file)
@@ -3,6 +3,9 @@ using System.Linq;
 
 namespace FooEditEngine
 {
+    /// <summary>
+    /// イベントパラメーター
+    /// </summary>
     public sealed class ShowingCompleteBoxEventArgs : EventArgs
     {
         /// <summary>
@@ -25,6 +28,12 @@ namespace FooEditEngine
         /// キャレット座標
         /// </summary>
         public Point CaretPostion;
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        /// <param name="keyChar"></param>
+        /// <param name="textbox"></param>
+        /// <param name="caret_pos"></param>
         public ShowingCompleteBoxEventArgs(string keyChar, Document textbox, Point caret_pos)
         {
             this.inputedWord = null;
@@ -35,6 +44,9 @@ namespace FooEditEngine
         }
     }
 
+    /// <summary>
+    /// イベントパラメーター
+    /// </summary>
     public sealed class SelectItemEventArgs : EventArgs
     {
         /// <summary>
@@ -49,6 +61,12 @@ namespace FooEditEngine
         /// 補完対象のテキストボックス
         /// </summary>
         public Document textbox;
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        /// <param name="word"></param>
+        /// <param name="inputing_word"></param>
+        /// <param name="textbox"></param>
         public SelectItemEventArgs(string word, string inputing_word, Document textbox)
         {
             this.word = word;
@@ -57,13 +75,29 @@ namespace FooEditEngine
         }
     }
 
+    /// <summary>
+    /// イベントパンドラーの定義
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     public delegate void SelectItemEventHandler(object sender,SelectItemEventArgs e);
+    /// <summary>
+    /// イベントパンドラーの定義
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     public delegate void ShowingCompleteBoxEnventHandler(object sender, ShowingCompleteBoxEventArgs e);
 
+    /// <summary>
+    /// 自動補完のベースクラス
+    /// </summary>
     public class AutoCompleteBoxBase
     {
         const int InputLength = 2;  //補完を開始する文字の長さ
 
+        /// <summary>
+        /// 対象となるドキュメント
+        /// </summary>
         protected Document Document
         {
             get;
@@ -117,7 +151,7 @@ namespace FooEditEngine
             this.Document = document;
         }
 
-        public void ParseInput(string input_text)
+        internal void ParseInput(string input_text)
         {
             if (this.Operators == null ||
                 input_text == "\r" ||
@@ -156,26 +190,41 @@ namespace FooEditEngine
             set;
         }
 
-        internal Func<TextPoint, Point> GetPostion;
+        internal Func<TextPoint,Document, Point> GetPostion;
 
-        public virtual bool IsCloseCompleteBox
+        /// <summary>
+        /// 自動補完リストが表示されているかどうか
+        /// </summary>
+        protected virtual bool IsCloseCompleteBox
         {
             get;
         }
 
+        /// <summary>
+        /// 補完候補の表示要求を処理する
+        /// </summary>
+        /// <param name="ev"></param>
         protected virtual void RequestShowCompleteBox(ShowingCompleteBoxEventArgs ev)
         {
         }
 
+        /// <summary>
+        /// 補完候補の非表示要求を処理する
+        /// </summary>
         protected virtual void RequestCloseCompleteBox()
         {
         }
 
+        /// <summary>
+        /// 補完候補を表示する
+        /// </summary>
+        /// <param name="key_char"></param>
+        /// <param name="force"></param>
         public void OpenCompleteBox(string key_char, bool force = false)
         {
             if (this.GetPostion == null)
                 throw new InvalidOperationException("GetPostionがnullです");
-            Point p = this.GetPostion(this.Document.CaretPostion);
+            Point p = this.GetPostion(this.Document.CaretPostion,this.Document);
 
             ShowingCompleteBoxEventArgs ev = new ShowingCompleteBoxEventArgs(key_char, this.Document, p);
             ShowingCompleteBox(this, ev);
index bc0339c..ee90eee 100644 (file)
@@ -13,13 +13,15 @@ namespace FooEditEngine.UWP
         private Popup popup = new Popup();
         private Document doc;
 
+        public const int CompleteListBoxHeight = 200;
+
         public AutoCompleteBox(Document doc) : base(doc)
         {
             //リストボックスを追加する
             this.popup.Child = this.listBox1;
             this.listBox1.DoubleTapped += ListBox1_DoubleTapped;
             this.listBox1.KeyDown += listBox1_KeyDown;
-            this.listBox1.Height = 200;
+            this.listBox1.Height = CompleteListBoxHeight;
             this.doc = doc;
         }
 
@@ -39,7 +41,7 @@ namespace FooEditEngine.UWP
             }
         }
 
-        public override bool IsCloseCompleteBox
+        protected override bool IsCloseCompleteBox
         {
             get
             {
@@ -50,10 +52,11 @@ namespace FooEditEngine.UWP
         protected override void RequestShowCompleteBox(ShowingCompleteBoxEventArgs ev)
         {
             this.inputedWord = ev.inputedWord;
-            DecideListBoxLocation(this.doc,this.listBox1, ev.CaretPostion);
             this.listBox1.SelectedIndex = ev.foundIndex;
             this.listBox1.ScrollIntoView(this.listBox1.SelectedItem);
             this.popup.IsOpen = true;
+            Canvas.SetLeft(this.popup, ev.CaretPostion.X);
+            Canvas.SetTop(this.popup, ev.CaretPostion.Y);
         }
 
         protected override void RequestCloseCompleteBox()
@@ -61,19 +64,6 @@ namespace FooEditEngine.UWP
             this.popup.IsOpen = false;
         }
 
-        void DecideListBoxLocation(Document doc, ListBox listbox, Point p)
-        {
-            int height = (int)doc.LayoutLines.GetLayout(doc.CaretPostion.row).Height;
-
-            if (p.Y + listbox.Height + height > doc.LayoutLines.Render.TextArea.Height)
-                p.Y -= listbox.Height;
-            else
-                p.Y += height;
-
-            Canvas.SetLeft(this.popup, p.X);
-            Canvas.SetTop(this.popup, p.Y);
-        }
-
         public bool ProcessKeyDown(FooTextBox textbox, KeyRoutedEventArgs e,bool isCtrl,bool isShift)
         {
             if (this.popup.IsOpen == false)
index d79ef69..d6ab0ec 100644 (file)
@@ -1292,9 +1292,15 @@ namespace FooEditEngine.UWP
             this._Document.LoadProgress += Document_LoadProgress;
             if(this._Document.AutoComplete != null)
             {
-                this._Document.AutoComplete.GetPostion = (tp) =>
+                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;
index d3911de..0888a40 100644 (file)
@@ -52,7 +52,7 @@ namespace FooEditEngine.WPF
         /// <summary>
         /// 自動補完リストが表示されているかどうか
         /// </summary>
-        public override bool IsCloseCompleteBox
+        protected override bool IsCloseCompleteBox
         {
             get
             {
@@ -81,9 +81,10 @@ namespace FooEditEngine.WPF
         protected override void RequestShowCompleteBox(ShowingCompleteBoxEventArgs ev)
         {
             this.inputedWord = ev.inputedWord;
-            DecideListBoxLocation(this.doc,this.listBox1, ev.CaretPostion);
             this.listBox1.SelectedIndex = ev.foundIndex;
             this.listBox1.ScrollIntoView(this.listBox1.SelectedItem);
+            this.popup.Placement = PlacementMode.Absolute;
+            this.popup.PlacementRectangle = new Rect(ev.CaretPostion, new Size(listBox1.ActualWidth, listBox1.Height));
             this.popup.IsOpen = true;
         }
 
@@ -97,7 +98,6 @@ namespace FooEditEngine.WPF
 
         void DecideListBoxLocation(Document doc, ListBox listbox, Point p)
         {
-            this.popup.PlacementRectangle = new Rect(p, new Size(listBox1.ActualWidth, listBox1.Height));
         }
 
         internal bool ProcessKeyDown(FooTextBox textbox, KeyEventArgs e,bool isCtrl,bool isShift)
index 073e071..c03183e 100644 (file)
@@ -1258,10 +1258,10 @@ namespace FooEditEngine.WPF
             if (this._Document.AutoComplete != null)
             {
                 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
-                this._Document.AutoComplete.GetPostion = (tp) =>
+                this._Document.AutoComplete.GetPostion = (tp, doc) =>
                 {
                     var p = this.View.GetPostionFromTextPoint(tp);
-                    int height = (int)this._Document.LayoutLines.GetLayout(this._Document.CaretPostion.row).Height;
+                    int height = (int)doc.LayoutLines.GetLayout(doc.CaretPostion.row).Height;
                     p.Y += height;
                     return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
                 };