3 using System.Collections.Generic;
6 using System.Windows.Controls;
7 using System.Windows.Controls.Primitives;
8 using System.Windows.Input;
11 namespace FooEditEngine.WPF
16 public class AutoCompleteBox : AutoCompleteBoxBase
18 private string inputedWord;
19 private ListBox listBox1 = new ListBox();
26 /// <param name="doc">ドキュメント</param>
27 public AutoCompleteBox(Document doc) : base(doc)
30 this.listBox1.MouseDoubleClick += listBox1_MouseDoubleClick;
31 this.listBox1.KeyDown += listBox1_KeyDown;
32 this.listBox1.Height = 200;
37 /// オートコンプリートの対象となる単語のリスト
39 public override CompleteCollection<ICompleteItem> Items
43 return (CompleteCollection<ICompleteItem>)this.listBox1.ItemsSource;
47 this.listBox1.ItemsSource = value;
48 this.listBox1.DisplayMemberPath = CompleteCollection<ICompleteItem>.ShowMember;
53 /// 自動補完リストが表示されているかどうか
55 protected override bool IsCloseCompleteBox
59 return !this.popup.IsOpen;
63 internal Popup TargetPopup
72 this.popup.Child = this.listBox1;
73 this.popup.Height = 200;
80 /// <param name="ev"></param>
81 protected override void RequestShowCompleteBox(ShowingCompleteBoxEventArgs ev)
83 this.inputedWord = ev.inputedWord;
84 this.listBox1.SelectedIndex = ev.foundIndex;
85 this.listBox1.ScrollIntoView(this.listBox1.SelectedItem);
86 this.popup.Placement = PlacementMode.Absolute;
87 this.popup.PlacementRectangle = new Rect(ev.CaretPostion, new Size(listBox1.ActualWidth, listBox1.Height));
88 this.popup.IsOpen = true;
94 protected override void RequestCloseCompleteBox()
96 this.popup.IsOpen = false;
99 void DecideListBoxLocation(Document doc, ListBox listbox, Point p)
103 internal bool ProcessKeyDown(FooTextBox textbox, KeyEventArgs e,bool isCtrl,bool isShift)
105 if (this.popup.IsOpen == false)
107 if (e.Key == Key.Space && isCtrl)
109 this.OpenCompleteBox(string.Empty);
120 this.RequestCloseCompleteBox();
125 if (this.listBox1.SelectedIndex + 1 >= this.listBox1.Items.Count)
126 this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
128 this.listBox1.SelectedIndex++;
129 this.listBox1.ScrollIntoView(this.listBox1.SelectedItem);
133 if (this.listBox1.SelectedIndex - 1 < 0)
134 this.listBox1.SelectedIndex = 0;
136 this.listBox1.SelectedIndex--;
137 this.listBox1.ScrollIntoView(this.listBox1.SelectedItem);
142 this.RequestCloseCompleteBox();
143 CompleteWord selWord = (CompleteWord)this.listBox1.SelectedItem;
144 this.SelectItem(this, new SelectItemEventArgs(selWord, this.inputedWord, this.Document));
152 private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
154 this.popup.IsOpen = false;
155 CompleteWord selWord = (CompleteWord)this.listBox1.SelectedItem;
156 this.SelectItem(this, new SelectItemEventArgs(selWord, this.inputedWord, this.Document));
159 void listBox1_KeyDown(object sender, KeyEventArgs e)
161 if (e.Key == Key.Enter)
163 this.popup.IsOpen = false;
164 CompleteWord selWord = (CompleteWord)this.listBox1.SelectedItem;
165 this.SelectItem(this, new SelectItemEventArgs(selWord, this.inputedWord, this.Document));