namespace FooEditEngine
{
+ /// <summary>
+ /// イベントパラメーター
+ /// </summary>
public sealed class ShowingCompleteBoxEventArgs : EventArgs
{
/// <summary>
/// キャレット座標
/// </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;
}
}
+ /// <summary>
+ /// イベントパラメーター
+ /// </summary>
public sealed class SelectItemEventArgs : EventArgs
{
/// <summary>
/// 補完対象のテキストボックス
/// </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;
}
}
+ /// <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;
this.Document = document;
}
- public void ParseInput(string input_text)
+ internal void ParseInput(string input_text)
{
if (this.Operators == null ||
input_text == "\r" ||
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);
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;
}
}
}
- public override bool IsCloseCompleteBox
+ protected override bool IsCloseCompleteBox
{
get
{
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()
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)
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;
/// <summary>
/// 自動補完リストが表示されているかどうか
/// </summary>
- public override bool IsCloseCompleteBox
+ protected override bool IsCloseCompleteBox
{
get
{
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;
}
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)
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));
};