From: konekoneko Date: Sun, 13 Nov 2016 09:21:26 +0000 (+0530) Subject: 警告個所の改善と表示までの流れをわかりやすくした X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e79a71b4a25d03ef7bd6ca492d641348b8cb6d59;p=fooeditengine%2FFooEditEngine.git 警告個所の改善と表示までの流れをわかりやすくした --- diff --git a/Core/AutoCompleteBoxBase.cs b/Core/AutoCompleteBoxBase.cs index 88f90d3..2521b69 100644 --- a/Core/AutoCompleteBoxBase.cs +++ b/Core/AutoCompleteBoxBase.cs @@ -3,6 +3,9 @@ using System.Linq; namespace FooEditEngine { + /// + /// イベントパラメーター + /// public sealed class ShowingCompleteBoxEventArgs : EventArgs { /// @@ -25,6 +28,12 @@ namespace FooEditEngine /// キャレット座標 /// public Point CaretPostion; + /// + /// コンストラクター + /// + /// + /// + /// public ShowingCompleteBoxEventArgs(string keyChar, Document textbox, Point caret_pos) { this.inputedWord = null; @@ -35,6 +44,9 @@ namespace FooEditEngine } } + /// + /// イベントパラメーター + /// public sealed class SelectItemEventArgs : EventArgs { /// @@ -49,6 +61,12 @@ namespace FooEditEngine /// 補完対象のテキストボックス /// public Document textbox; + /// + /// コンストラクター + /// + /// + /// + /// public SelectItemEventArgs(string word, string inputing_word, Document textbox) { this.word = word; @@ -57,13 +75,29 @@ namespace FooEditEngine } } + /// + /// イベントパンドラーの定義 + /// + /// + /// public delegate void SelectItemEventHandler(object sender,SelectItemEventArgs e); + /// + /// イベントパンドラーの定義 + /// + /// + /// public delegate void ShowingCompleteBoxEnventHandler(object sender, ShowingCompleteBoxEventArgs e); + /// + /// 自動補完のベースクラス + /// public class AutoCompleteBoxBase { const int InputLength = 2; //補完を開始する文字の長さ + /// + /// 対象となるドキュメント + /// 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 GetPostion; + internal Func GetPostion; - public virtual bool IsCloseCompleteBox + /// + /// 自動補完リストが表示されているかどうか + /// + protected virtual bool IsCloseCompleteBox { get; } + /// + /// 補完候補の表示要求を処理する + /// + /// protected virtual void RequestShowCompleteBox(ShowingCompleteBoxEventArgs ev) { } + /// + /// 補完候補の非表示要求を処理する + /// protected virtual void RequestCloseCompleteBox() { } + /// + /// 補完候補を表示する + /// + /// + /// 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); diff --git a/UWP/FooEditEngine.UWP/AutoCompleteBox.cs b/UWP/FooEditEngine.UWP/AutoCompleteBox.cs index bc0339c..ee90eee 100644 --- a/UWP/FooEditEngine.UWP/AutoCompleteBox.cs +++ b/UWP/FooEditEngine.UWP/AutoCompleteBox.cs @@ -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) diff --git a/UWP/FooEditEngine.UWP/FooTextBox.cs b/UWP/FooEditEngine.UWP/FooTextBox.cs index d79ef69..d6ab0ec 100644 --- a/UWP/FooEditEngine.UWP/FooTextBox.cs +++ b/UWP/FooEditEngine.UWP/FooTextBox.cs @@ -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; diff --git a/WPF/FooEditEngine/AutoCompleteBox.cs b/WPF/FooEditEngine/AutoCompleteBox.cs index d3911de..0888a40 100644 --- a/WPF/FooEditEngine/AutoCompleteBox.cs +++ b/WPF/FooEditEngine/AutoCompleteBox.cs @@ -52,7 +52,7 @@ namespace FooEditEngine.WPF /// /// 自動補完リストが表示されているかどうか /// - 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) diff --git a/WPF/FooEditEngine/FooTextBox.cs b/WPF/FooEditEngine/FooTextBox.cs index 073e071..c03183e 100644 --- a/WPF/FooEditEngine/FooTextBox.cs +++ b/WPF/FooEditEngine/FooTextBox.cs @@ -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)); };