3 * $Date: 2010-03-18 20:45:05 +0900 (木, 18 3 2010) $
7 using System.Collections.Generic;
8 using System.Diagnostics;
12 using System.Windows.Forms;
15 using Lugens.Components;
17 using System.Runtime.InteropServices;
18 using Newtonsoft.Json;
19 using Microsoft.WindowsAPICodePack.Shell;
20 using System.Drawing.Imaging;
22 namespace Lugens.Passer
24 public partial class MainForm
27 private void DoResize(int width)
29 Size size = this.Size;
33 else if (size.Width > 600)
36 Settings.Set(Settings.PASSER_FORM_MAIN_WIDTH, size.Width);
40 size.Height = this.searchTextBox.Size.Height;
41 this.searchTextBox.Size = size;
42 if (this.searchTextBox.TextBox.DropdownForm.Visible)
44 Program.Status = ProgramStatus.MainFormOpen;
45 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
50 private void MainForm_MouseDown(object sender, MouseEventArgs e)
52 if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
54 this.mousePoint = new Point(-e.X, -e.Y);
55 this.windowMoveFlag = true;
59 private void MainForm_MouseMove(object sender, MouseEventArgs e)
61 if (this.Cursor == Cursors.SizeWE && (e.Button & MouseButtons.Left) == MouseButtons.Left)
66 else if (this.windowMoveFlag && (e.Button & MouseButtons.Left) == MouseButtons.Left)
69 this.seenPoint = new Point(this.Left + mousePoint.X + e.X, this.Top + mousePoint.Y + e.Y);
70 this.Location = this.seenPoint;
72 Settings.Set(Settings.PASSER_FORM_MAIN_X, this.seenPoint.X);
73 Settings.Set(Settings.PASSER_FORM_MAIN_Y, this.seenPoint.Y);
75 if (this.searchTextBox.TextBox.DropdownForm.Visible)
77 Program.Status = ProgramStatus.MainFormOpen;
78 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
81 else if (e.X >= (this.Size.Width - 4))
84 this.Cursor = Cursors.SizeWE;
89 if (this.Cursor == Cursors.SizeWE)
90 this.Cursor = Cursors.Default;
94 private void MainForm_MouseUp(object sender, MouseEventArgs e)
96 this.windowMoveFlag = false;
99 private void MainForm_Load(object sender, System.EventArgs e)
101 this.Visible = false;
102 this.Size = new Size(256, 32);
103 this.Location = this.seenPoint;
105 this.searchTextBox.TextBox.DropdownForm.DrawType = Lugens.Components.DropdownListForm.DrawMode.IconText;
106 this.searchTextBox.TextBox.DropdownForm.IconCallBack = this.GetIconCallBack;
107 this.searchTextBox.TextBox.DropdownForm.VisibleChanged += this.dropdownListBox_SelectedIndexChanged;
108 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndexChanged += this.dropdownListBox_SelectedIndexChanged;
109 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.VisibleChanged += this.dropdownListBox_SelectedIndexChanged;
110 this.Activated += this.dropdownListBox_SelectedIndexChanged;
111 this.AddOwnedForm(this.searchTextBox.TextBox.DropdownForm);
113 if (Program.Main_MemorizeEngine)
115 EngineInfo info = Program.GetEngineInfo(Settings.GetInt(Settings.PASSER_MAIN_ENGINE_INDEX));
117 this.SetSearchEngine(Program.GetEngineInfo(0));
119 this.SetSearchEngine(info);
123 private void ShowDropdownForm(bool filter)
125 switch (this.SelectedEngineType)
128 this.SetDropdownList(filter);
129 if (this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count > 0)
131 this.searchTextBox.TextBox.SetDropdownFormLocation();
132 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex = 0;
133 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(true);
137 this.SetLocalDropdownList(filter);
138 if (this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count > 0)
140 this.searchTextBox.TextBox.SetDropdownFormLocation();
141 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex = 0;
142 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(true);
147 if (String.IsNullOrEmpty(this.searchTextBox.TextBox.Text))
149 Program.Status = ProgramStatus.MainFormOpen;
150 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
151 this.suggestString = "";
155 this.textChanged = true;
161 private void SetRootDriveList()
163 Program.RootDriveList.Clear();
164 Program.AliasDic.Clear();
165 foreach (DriveInfo d in DriveInfo.GetDrives())
167 IconListBoxItem item = new IconListBoxItem();
169 item.Text = item.Name;
170 item.ToolTipText = item.Name;
171 item.Type = IconListBoxType.Directory;
174 case DriveType.Fixed:
175 if (Environment.SystemDirectory.StartsWith(d.Name))
176 item.IconImage = Properties.Resources.IconDriveWin.ToBitmap();
178 item.IconImage = Properties.Resources.IconDriveFix.ToBitmap();
180 case DriveType.Network:
181 item.IconImage = Properties.Resources.IconDriveNet.ToBitmap();
183 case DriveType.CDRom:
184 item.IconImage = Properties.Resources.IconDriveCD.ToBitmap();
186 case DriveType.Removable:
187 item.IconImage = Properties.Resources.IconDriveRem.ToBitmap();
190 item.IconImage = Properties.Resources.IconDriveFix.ToBitmap();
193 Program.RootDriveList.Add(item);
196 if (Program.OSVersion >= 6.1)
200 ShellObject lib = (ShellObject)KnownFolders.Libraries;
201 IconListBoxItem item = new IconListBoxItem();
202 item.Name = lib.ToString() + "\\";
203 item.Text = item.Name;
204 item.ToolTipText = item.Name;
205 item.Regex = Program.Ime.GetRomaji(item.Name);
206 item.Type = IconListBoxType.Directory;
207 lib.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
208 item.IconImage = Program.GetBitmap(lib);
209 Program.RootDriveList.Add(item);
210 Program.AliasDic.Add(lib.ToString(), KnownFolders.Libraries.Path);
215 private void SetDropdownList(bool filter)
217 string[] commands = Program.ParseCommand(this.searchTextBox.TextBox.Text);
219 if(commands.Length > 0)
220 command = commands[commands.Length - 1];
222 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Clear();
223 if (filter && command.Equals(""))
225 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
230 foreach (IconListBoxItem item in this.searchTextBox.TextBox.Items)
232 if (item.Text.ToLower().StartsWith(this.searchTextBox.TextBox.Text.ToLower()) || Program.Ime.StartsWith(item.Regex, this.searchTextBox.TextBox.Text))
233 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
235 if (command.Length > 0)
237 foreach (string str in Program.CommandHistoryList)
239 if (str.StartsWith(command))
242 foreach (IconListBoxItem item in this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items)
244 if (str.Equals(item.Text))
253 IconListBoxItem i = new IconListBoxItem();
256 i.Type = IconListBoxType.History;
258 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(i);
263 if (this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count == 0)
265 Program.Status = ProgramStatus.MainFormOpen;
266 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
275 /// <param name="text"></param>
276 public void SetLocalDropdownList(bool filter)
279 string[] commands = Program.ParseFile(this.searchTextBox.TextBox.Text);
282 foreach(string s in commands)
283 Debug.WriteLine("commands:" + s);
284 Debug.WriteLine("end");
287 if (commands.Length > 0)
288 command = commands[commands.Length - 1];
290 string command = this.searchTextBox.TextBox.Text;
292 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Clear();
293 if (filter && command.Equals(""))
295 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
299 if (command.LastIndexOf('\\') == -1)
302 string str = command.ToLower();
303 foreach (IconListBoxItem item in Program.RootDriveList)
305 if (item.Text.ToLower().StartsWith(str) || Program.Ime.StartsWith(item.Regex, str))
306 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
311 if (Program.OSVersion >= 6.1 && command.StartsWith("ライブラリ"))
313 string[] directories = command.Split('\\');
314 if (directories.Length == 2)
316 file = directories[1];
317 ShellContainer sc = KnownFolders.Libraries as ShellContainer;
318 foreach (ShellObject o in sc)
320 string regex = Program.Ime.GetRomaji(o.Name);
321 if (o.Name.StartsWith(file) || Program.Ime.StartsWith(regex, file))
323 IconListBoxItem item = new IconListBoxItem();
324 item.Name = o.Name + "\\";
325 item.Text = item.Name;
326 item.ToolTipText = item.Text;
327 item.Type = IconListBoxType.Directory;
329 o.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
330 item.IconImage = Program.GetBitmap(o);
331 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
335 else if (directories.Length == 3)
337 file = directories[2];
338 ShellLibrary lib = Program.GetShellLibrary(directories[1]);
342 foreach (ShellObject o in lib)
344 if (o is ShellContainer)
346 ShellContainer sc = o as ShellContainer;
347 foreach (ShellObject so in sc)
349 string regex = Program.Ime.GetRomaji(so.Name);
350 if (so.Name.StartsWith(file) || Program.Ime.StartsWith(regex, file))
352 IconListBoxItem item = new IconListBoxItem();
353 item.Name = so.Name + "\\";
354 item.Text = item.Name;
355 item.ToolTipText = item.Text;
356 item.Type = IconListBoxType.Directory;
358 so.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
359 item.IconImage = Program.GetBitmap(so);
360 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
361 Debug.WriteLine(so.ParsingName);
368 else if (directories.Length > 3)
372 file = directories[2];
373 ShellLibrary lib = Program.GetShellLibrary(directories[1]);
377 foreach (ShellObject o in lib)
379 if (o is ShellContainer)
381 ShellContainer sc = o as ShellContainer;
382 foreach (ShellObject so in sc)
384 if (so.Name.Equals(file))
386 fullDir = so.ParsingName + "\\";
401 for (int i = 3; i < directories.Length; i++)
403 fullDir += directories[i];
404 if (i + 1 < directories.Length)
408 int lindex = fullDir.LastIndexOf("\\") + 1;
411 string dir = fullDir.Substring(0, lindex);
412 string files = fullDir.Substring(lindex);
413 this.AddFileSearchItem(files, dir);
419 int lindex = command.LastIndexOf('\\') + 1;
422 string directories = command.Substring(0, lindex);
423 string files = command.Substring(lindex);
424 this.AddFileSearchItem(files, directories);
428 if(this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count == 0)
429 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
432 public bool AddFileSearchItem(string files, string directories)
436 if (Directory.GetFileSystemEntries(directories, "*").Length > 0)
438 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Clear();
439 if (this.searchTextBox.TextBox.Text.Equals(Directory.GetDirectoryRoot(directories)))
441 DriveInfo driveInfo = new DriveInfo(this.searchTextBox.TextBox.Text[0].ToString());
442 if (!driveInfo.IsReady)
445 foreach (string directory in Directory.GetDirectories(directories))
447 string name = directory.Substring(directories.Length) + "\\";
448 if (name.StartsWith(files) || Program.Ime.StartsWith(Program.Ime.GetRomaji(name), files))
450 IconListBoxItem item = new IconListBoxItem();
452 item.Text = item.Name;
453 item.ToolTipText = item.Text;
454 item.Type = IconListBoxType.Directory;
455 item.IconImage = Program.DirectoryIcon.ToBitmap();
456 item.Regex = Program.Ime.GetRomaji(item.Name);
457 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
460 foreach (string s in Directory.GetFiles(directories))
462 string name = s.Substring(directories.Length);
463 if (name.StartsWith(files) || Program.Ime.StartsWith(Program.Ime.GetRomaji(name), files))
467 IconListBoxItem item = new IconListBoxItem();
469 item.Text = item.Name;
470 item.ToolTipText = item.Name;
471 item.Type = IconListBoxType.File;
473 extindex = item.Name.LastIndexOf('.');
474 ext = extindex == -1 ? "" : item.Name.Substring(extindex + 1);
476 if ("exe".Equals(ext) || "lnk".Equals(ext))
478 Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();
479 Win32.SHGetFileInfo(s, 0, ref shinfo, Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
480 if (shinfo.hIcon != IntPtr.Zero)
481 item.IconImage = System.Drawing.Icon.FromHandle(shinfo.hIcon).ToBitmap();
485 if (Program.ExtIconCacheDic.ContainsKey(ext))
487 if (Program.ExtIconCacheDic[ext] != null)
488 item.IconImage = Program.ExtIconCacheDic[ext].ToBitmap();
492 Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();
493 Win32.SHGetFileInfo(s, 0, ref shinfo, Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
494 if (shinfo.hIcon != IntPtr.Zero)
496 Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
497 Program.ExtIconCacheDic.Add(ext, icon);
498 item.IconImage = icon.ToBitmap();
502 Program.ExtIconCacheDic.Add(ext, null);
506 item.Regex = Program.Ime.GetRomaji(item.Name);
507 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
516 //MessageBox.Show(e.ToString());
517 //this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
525 public void SetEngineDropdownList(string text)
527 if (!this.suggestSupport || this.suggestString.Equals(text))
530 EngineInfo info = Program.GetEngineInfo(this.SelectedEngineIndex);
535 string url = info.SuggestUrl.Replace("%s", Uri.EscapeDataString(text));
536 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
538 req.UserAgent = Program.UserAgent;
540 AsyncCallback readCallBack = new AsyncCallback(SuggestReadCallBack);
541 req.BeginGetResponse(readCallBack, req);
542 this.suggestString = text;
548 /// DropdownFormにエンジンリスト一覧を表示する
550 public void ShowEngineList()
552 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
555 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Clear();
556 foreach (string key in Program.DefaultEngineList)
558 EngineInfo info = Program.DefaultEngineDic[key];
559 IconListBoxItem item = new IconListBoxItem();
560 item.Name = info.Name;
561 item.Text = info.Name;
562 item.ToolTipText = info.Display;
563 item.IconImage = info.IconImage;
564 item.Type = IconListBoxType.SearchEngine;
566 item.Regex = Program.Ime.GetRomaji(item.Name);
567 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
569 foreach (string key in Program.EngineList)
571 EngineInfo info = Program.EngineDic[key];
572 IconListBoxItem item = new IconListBoxItem();
573 item.Name = info.Name;
574 item.Text = info.Name;
575 item.ToolTipText = info.Display;
576 item.IconImage = info.IconImage;
577 item.Type = IconListBoxType.SearchEngine;
579 item.Regex = Program.Ime.GetRomaji(item.Name);
580 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
582 this.searchTextBox.TextBox.SetDropdownFormLocation();
583 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(true);
584 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex = 0;
585 Program.Status = ProgramStatus.SelectingSearchEngine;
590 private void SuggestReadCallBack(IAsyncResult ar)
594 HttpWebRequest req = (HttpWebRequest)ar.AsyncState;
595 HttpWebResponse response = (HttpWebResponse)req.EndGetResponse(ar);
596 StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet));
597 string str = streamReader.ReadToEnd();
598 streamReader.Close();
599 Win32.PostMessage(Program.MainFormHandle, Program.WM_SUGGEST_END, IntPtr.Zero, Marshal.StringToHGlobalAuto(str));
603 Debug.WriteLine("error:" + ex);
607 private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
609 if (Program.HotKeyEngineList.Contains(KeyboardHook.Keycode))
611 EngineInfo info = Program.GetEngineInfoFromHotKey(KeyboardHook.Keycode);
615 this.SetSearchEngine(info);
616 if (this.searchTextBox.TextBox.DropdownForm.Visible)
617 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
622 switch ((Keys)e.KeyChar)
626 if (this.searchTextBox.TextBox.DropdownForm.Visible && this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex >= 0)
629 this.searchTextBox.TextBox.Complemented = true;
630 IconListBoxItem item = (IconListBoxItem)this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedItem;
633 case IconListBoxType.File:
634 case IconListBoxType.Directory:
635 int index = this.searchTextBox.TextBox.Text.LastIndexOf('\\');
637 this.searchTextBox.TextBox.Text = item.Name;
639 this.searchTextBox.TextBox.Text = this.searchTextBox.TextBox.Text.Substring(0, index + 1) + item.Name;
640 this.searchTextBox.TextBox.SelectionStart = this.searchTextBox.TextBox.Text.Length;
641 Program.Status = ProgramStatus.MainFormOpen;
642 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
644 case IconListBoxType.Command:
645 case IconListBoxType.History:
646 case IconListBoxType.SysCommand:
647 case IconListBoxType.SearchEngineText:
648 this.searchTextBox.TextBox.Text = item.Text;
649 this.searchTextBox.TextBox.SelectionStart = this.searchTextBox.TextBox.Text.Length;
650 Program.Status = ProgramStatus.MainFormOpen;
651 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
653 case IconListBoxType.SearchEngine:
654 EngineInfo info = (EngineInfo)item.Data;
655 this.SetSearchEngine(info);
656 Program.Status = ProgramStatus.MainFormOpen;
657 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
662 if (this.SearchTextBox.TextBox.Complemented)
665 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
667 this.ShowDropdownForm(false);
673 if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
676 if (!this.searchTextBox.TextBox.DropdownForm.Visible)
678 switch (this.SelectedEngineType)
682 if (this.SearchTextBox.TextBox.ShowableDropdownList)
683 this.ShowDropdownForm(false);
686 this.suggestString = "";
687 this.textChanged = true;
696 if (this.searchTextBox.TextBox.DropdownForm.Visible)
698 if (this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex >= 0)
700 IconListBoxItem item = (IconListBoxItem)this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items[this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex];
701 if (item.Type == IconListBoxType.SearchEngine)
703 EngineInfo info = (EngineInfo)item.Data;
704 this.SetSearchEngine(info);
705 Program.Status = ProgramStatus.MainFormOpen;
706 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
711 if (item.Type == IconListBoxType.File || item.Type == IconListBoxType.Directory)
713 int index = this.searchTextBox.TextBox.Text.LastIndexOf('\\');
715 this.searchTextBox.TextBox.Text = item.Name;
717 this.searchTextBox.TextBox.Text = this.searchTextBox.TextBox.Text.Substring(0, index + 1) + item.Name;
718 this.searchTextBox.TextBox.SelectionStart = this.searchTextBox.TextBox.Text.Length;
719 Program.Status = ProgramStatus.MainFormOpen;
720 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
723 this.searchTextBox.TextBox.Text = this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Text;
724 this.searchTextBox.TextBox.SelectionStart = this.Text.Length;
725 Program.Status = ProgramStatus.MainFormOpen;
726 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
731 string command = this.SearchTextBox.TextBox.Text.Trim();
732 switch (this.SelectedEngineType)
735 if (this.ExecCommand(command))
737 Program.AddHistoryList(command);
742 this.ExecFile(command);
746 this.ExecSearch(command);
752 if (this.SearchTextBox.TextBox.DropdownForm.Visible)
754 Program.Status = ProgramStatus.MainFormOpen;
755 this.SearchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
756 Program.HideToolTip();
760 if (!"".Equals(searchTextBox.TextBox.Text))
762 this.SearchTextBox.TextBox.Text = "";
763 this.SearchTextBox.TextBox.SelectionStart = 0;
769 this.DoVisibleChange(false);
770 Program.ForceForegroundWindow(this.beforeHWnd);
776 if (Program.Status == ProgramStatus.SelectingSearchEngine)
779 string key = e.KeyChar + "";
780 IconListBoxItem item;
781 int index = this.SearchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex + 1;
782 if (index >= this.SearchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count)
784 for (int i = 0; i < this.SearchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count; i++)
786 item = (IconListBoxItem)this.SearchTextBox.TextBox.DropdownForm.DropdownListBox.Items[index];
787 EngineInfo info = (EngineInfo)item.Data;
788 if (Program.Ime.StartsWith(item.Regex, key))
790 this.SearchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex = index;
793 if (++index >= this.SearchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count)
803 private void textBox_cmd_KeyDown(object sender, KeyEventArgs e)
805 if (Program.MainForm.Opacity != Program.FormOpacity)
806 Program.MainForm.Opacity = Program.FormOpacity;
811 if ((Keys.Control & Control.ModifierKeys) == Keys.Control)
813 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
816 this.SelectedEngineIndex--;
817 if (this.SelectedEngineIndex == -1)
818 this.SelectedEngineIndex = Program.DefaultEngineList.Count + Program.EngineList.Count - 1;
819 this.SetSearchEngine(Program.GetEngineInfo(this.SelectedEngineIndex));
824 if (this.SelectedEngineType == 0)
826 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
828 if (Program.CommandHistoryList.Count > 0)
830 if (Program.CommandHistoryList.Count > Program.CommandHistoryIndex)
831 Program.CommandHistoryIndex++;
832 this.showDropdownSupport = false;
833 this.SearchTextBox.TextBox.Text = Program.CommandHistoryList[Program.CommandHistoryIndex - 1];
834 this.SearchTextBox.TextBox.SelectionStart = this.SearchTextBox.TextBox.Text.Length;
835 this.showDropdownSupport = true;
843 if ((Keys.Alt & Control.ModifierKeys) == Keys.Alt)
845 this.ShowEngineList();
847 else if ((Keys.Control & Control.ModifierKeys) == Keys.Control)
849 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
852 this.SelectedEngineIndex++;
853 int count = Program.DefaultEngineList.Count + Program.EngineList.Count;
854 if (this.SelectedEngineIndex == count)
855 this.SelectedEngineIndex = 0;
856 this.SetSearchEngine(Program.GetEngineInfo(this.SelectedEngineIndex));
861 switch (this.SelectedEngineType)
864 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
866 if (Program.CommandHistoryIndex > 0)
868 Program.CommandHistoryIndex--;
869 this.showDropdownSupport = false;
870 if (Program.CommandHistoryIndex == 0)
871 this.SearchTextBox.TextBox.Text = "";
873 this.SearchTextBox.TextBox.Text = Program.CommandHistoryList[Program.CommandHistoryIndex - 1];
874 this.SearchTextBox.TextBox.SelectionStart = this.SearchTextBox.TextBox.Text.Length;
875 this.showDropdownSupport = true;
879 this.ShowDropdownForm(false);
885 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
887 this.ShowDropdownForm(false);
891 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
893 this.suggestString = "";
894 this.textChanged = true;
903 private void textBox_cmd_TextChanged(object sender, EventArgs e)
905 this.latestKeyTime = DateTime.Now.Ticks;
906 this.searchTextBox.TextBox.ImeText = this.searchTextBox.TextBox.Text;
907 if (!this.showDropdownSupport || !this.Visible)
910 Size s = TextRenderer.MeasureText(this.searchTextBox.TextBox.Text, this.searchTextBox.TextBox.Font);
911 if (s.Width > this.searchTextBox.TextBox.Width)
913 //MessageBox.Show("!!!");
916 if(!this.searchTextBox.TextBox.Complemented)
917 this.ShowDropdownForm(true);
920 private void textBox_cmd_Complement(IconListBoxType type)
924 private void textBox_cmd_ImeComposition(int type, string text)
926 if(!String.IsNullOrEmpty(this.searchTextBox.TextBox.Text))
928 string str = this.searchTextBox.TextBox.Text;
929 text = str.Substring(0, this.searchTextBox.TextBox.SelectionStart)
931 + str.Substring(this.searchTextBox.TextBox.SelectionStart);
933 this.searchTextBox.TextBox.ImeText = text;
935 if (type == 0 && String.IsNullOrEmpty(text))
937 Program.Status = ProgramStatus.MainFormOpen;
938 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
939 this.suggestString = "";
943 if ((type & Win32.GCS_RESULTSTR) != Win32.GCS_RESULTSTR)
945 this.latestKeyTime = DateTime.Now.Ticks;
946 this.textChanged = true;
951 private void dropdownListBox_SelectedIndexChanged(object sender, EventArgs e)
953 Program.HideToolTip();
954 if (!this.searchTextBox.TextBox.DropdownForm.Visible)
957 IconListBox listBox = this.searchTextBox.TextBox.DropdownForm.DropdownListBox;
958 if (listBox.SelectedIndex == -1)
961 string text = listBox.Text;
962 if (text.Equals(this.dropdownListBoxText))
965 int lastIndex = listBox.ClientRectangle.Height / listBox.ItemHeight;
966 if (listBox.TopIndex > listBox.SelectedIndex || (listBox.TopIndex + lastIndex) <= listBox.SelectedIndex)
969 IconListBoxItem item = (IconListBoxItem)listBox.SelectedItem;
970 if (item.Type == IconListBoxType.SearchEngineText)
973 DropdownListForm dropdownForm = this.searchTextBox.TextBox.DropdownForm;
975 Rectangle r = dropdownForm.Bounds;
976 r.Y = dropdownForm.Location.Y + listBox.GetItemRectangle(listBox.SelectedIndex).Y;
977 if (this.SelectedEngineType == 0 && (item.ToolTipText == null || item.ToolTipText.Length == 0))
979 if (Program.CommandDic.ContainsKey(text))
\r
981 CommandInfo info = Program.CommandDic[text];
\r
982 text = info.Comment == null ? info.Name : info.Comment;
\r
987 text = item.ToolTipText;
989 Program.ShowToolTip(Util.CutText(text, 50, 10), r, 5000, false);
992 private void timer1_Tick(object sender, System.EventArgs e)
996 if (this.Opacity + Program.FadeInSpeed < Program.FormOpacity)
998 this.Opacity += Program.FadeInSpeed;
999 this.searchTextBox.TextBox.DropdownForm.Opacity = this.Opacity;
1004 this.Opacity = Program.FormOpacity;
1005 this.searchTextBox.TextBox.DropdownForm.Opacity = this.Opacity;
1011 private void timer_keyRecoding_Tick(object sender, EventArgs e)
1013 if (Program.Status == ProgramStatus.KeyRecoding && Program.Main_ShowBalloonWhileRecoding && Program.BallonWindowHandle != IntPtr.Zero)
1014 Win32.PostMessage(Program.BallonWindowHandle, Win32.WM_MOUSEMOVE, (IntPtr)0, (IntPtr)0);
1017 private void timer_suggest_Tick(object sender, EventArgs e)
1019 if (this.SelectedEngineType == 2 && this.textChanged)
1021 string text = this.searchTextBox.TextBox.ImeText;
1022 if (String.IsNullOrEmpty(text))
1025 if (DateTime.Now.Ticks > this.latestKeyTime + 000000 && !this.suggestString.Equals(text))
1027 this.textChanged = false;
1028 this.SetEngineDropdownList(text);
1033 private void toolTip_Popup(object sender, PopupEventArgs e)
1038 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
1040 if (e.Button == MouseButtons.Left)
1042 switch (Program.Status)
1044 case ProgramStatus.Loading:
1045 case ProgramStatus.Waiting:
1046 case ProgramStatus.MainFormOpen:
1047 HotKeyProcessExecuter.OpenMainForm();
1053 private void DropdownListView_MouseDoubleClick(object sender, MouseEventArgs e)
1055 this.searchTextBox.TextBox.Text = this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Text;
1056 this.searchTextBox.TextBox.Select(this.searchTextBox.TextBox.Text.Length, 0);
1057 Program.Status = ProgramStatus.MainFormOpen;
1058 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
1061 private void 表示ToolStripMenuItem_Click(object sender, EventArgs e)
1063 switch (Program.Status)
1065 case ProgramStatus.Loading:
1066 case ProgramStatus.Waiting:
1067 case ProgramStatus.MainFormOpen:
1068 HotKeyProcessExecuter.OpenMainForm();
1073 private void リスト設定ToolStripMenuItem_Click(object sender, EventArgs e)
1075 if (!Program.SettingForm.Visible)
1077 this.DoVisibleChange(false);
1078 Program.SettingForm.DoVisibleChange(true);
1082 private void バージョン情報ToolStripMenuItem_Click(object sender, EventArgs e)
1084 if (Program.Status == ProgramStatus.Waiting)
1086 Program.Status = ProgramStatus.VersionFormOpen;
1087 VersionForm f = new VersionForm();
1089 Program.Status = ProgramStatus.Waiting;
1093 private void 終了ToolStripMenuItem_Click(object sender, EventArgs e)