OSDN Git Service

v2.6.0.0 draft
[passer/Passer2.git] / passer / MainFormEvent.cs
1 /**
2  * $Revision: 238 $
3  * $Date: 2010-03-18 20:45:05 +0900 (木, 18 3 2010) $
4 */
5
6 using System;
7 using System.Collections.Generic;
8 using System.Diagnostics;
9 using System.Drawing;
10 using System.IO;
11 using System.Text;
12 using System.Windows.Forms;
13 using System.Net;
14 using System.Web;
15 using Lugens.Components;
16 using Lugens.Utils;
17 using System.Runtime.InteropServices;
18 using Newtonsoft.Json;
19
20 namespace Lugens.Passer
21 {
22     public partial class MainForm
23     {
24
25         private void DoResize(int width)
26         {
27             Size size = this.Size;
28             size.Width = width;
29             if (size.Width < 200)
30                 size.Width = 200;
31             else if (size.Width > 600)
32                 size.Width = 600;
33
34             Settings.Set(Settings.PASSER_FORM_MAIN_WIDTH, size.Width);
35
36             this.Size = size;
37             size.Width -= 16;
38             size.Height = this.searchTextBox.Size.Height;
39             this.searchTextBox.Size = size;
40             if (this.searchTextBox.TextBox.DropdownForm.Visible)
41                 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
42
43         }
44
45         private void MainForm_MouseDown(object sender, MouseEventArgs e)
46         {
47             if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
48             {
49                 this.mousePoint = new Point(-e.X, -e.Y);
50                 this.windowMoveFlag = true;
51             }
52         }
53
54         private void MainForm_MouseMove(object sender, MouseEventArgs e)
55         {
56             if (this.Cursor == Cursors.SizeWE && (e.Button & MouseButtons.Left) == MouseButtons.Left)
57             {
58                 //ウィンドウの幅変更
59                 this.DoResize(e.X);
60             }
61             else if (this.windowMoveFlag && (e.Button & MouseButtons.Left) == MouseButtons.Left)
62             {
63                 //ウィンドウの移動
64                 this.seenPoint = new Point(this.Left + mousePoint.X + e.X, this.Top + mousePoint.Y + e.Y);
65                 this.Location = this.seenPoint;
66
67                 Settings.Set(Settings.PASSER_FORM_MAIN_X, this.seenPoint.X);
68                 Settings.Set(Settings.PASSER_FORM_MAIN_Y, this.seenPoint.Y);
69
70                 if (this.searchTextBox.TextBox.DropdownForm.Visible)
71                     this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
72             }
73             else if (e.X >= (this.Size.Width - 4))
74             {
75                 //幅変更カーソルに変更
76                 this.Cursor = Cursors.SizeWE;
77             }
78             else
79             {
80                 //標準カーソルに変更
81                 if (this.Cursor == Cursors.SizeWE)
82                     this.Cursor = Cursors.Default;
83             }
84         }
85
86         private void MainForm_MouseUp(object sender, MouseEventArgs e)
87         {
88             this.windowMoveFlag = false;
89         }
90
91         private void MainForm_Load(object sender, System.EventArgs e)
92         {
93             this.Visible = false;
94             this.Size = new Size(256, 32);
95             this.Location = this.seenPoint;
96             ReadCommandList();
97             this.searchTextBox.TextBox.DropdownForm.DrawType = Lugens.Components.DropdownListForm.DrawMode.IconText;
98             this.searchTextBox.TextBox.DropdownForm.IconCallBack = this.GetIconCallBack;
99             this.searchTextBox.TextBox.DropdownForm.VisibleChanged += this.dropdownListBox_SelectedIndexChanged;
100             this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndexChanged += this.dropdownListBox_SelectedIndexChanged;
101             this.searchTextBox.TextBox.DropdownForm.DropdownListBox.VisibleChanged += this.dropdownListBox_SelectedIndexChanged;
102             this.Activated += this.dropdownListBox_SelectedIndexChanged;
103             this.AddOwnedForm(this.searchTextBox.TextBox.DropdownForm);
104
105             if (Program.Main_MemorizeEngine)
106             {
107                 EngineInfo info = Program.GetEngineInfo(Settings.GetInt(Settings.PASSER_MAIN_ENGINE_INDEX));
108                 if(info == null)
109                     this.SetSearchEngine(Program.GetEngineInfo(0));
110                 else
111                     this.SetSearchEngine(info);
112             }
113         }
114
115         private void ShowDropdownForm(bool filter)
116         {
117             switch (this.SelectedEngineType)
118             {
119                 case 0: //Passer
120                 case 1: //FileSearch
121                     this.SetDropdownList(filter);
122                     if (this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count > 0)
123                     {
124                         this.searchTextBox.TextBox.DropdownForm.DropdownListBox.SelectedIndex = 0;
125                         this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(true);
126                     }
127                     break;
128
129                 case 2: //WebSearch
130                     if (String.IsNullOrEmpty(this.searchTextBox.TextBox.Text))
131                     {
132                         this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
133                         this.suggestString = "";
134                     }
135                     else
136                     {
137                         this.textChanged = true;
138                     }
139                     break;
140             }
141         }
142
143         private void SetDropdownList()
144         {
145             this.SetDropdownList(true);
146         }
147
148         private void SetRootDriveList()
149         {
150             Program.RootDriveList.Clear();
151             foreach (DriveInfo d in DriveInfo.GetDrives())
152             {
153                 IconListViewItem item = new IconListViewItem();
154                 item.Name = d.Name;
155                 item.Text = d.Name;
156                 item.Type = IconListViewType.Directory;
157                 switch (d.DriveType)
158                 {
159                     case DriveType.Fixed:
160                         if (Environment.SystemDirectory.StartsWith(d.Name))
161                             item.Icon = Properties.Resources.IconDriveWin;
162                         else
163                             item.Icon = Properties.Resources.IconDriveFix;
164                         break;
165                     case DriveType.Network:
166                         item.Icon = Properties.Resources.IconDriveNet;
167                         break;
168                     case DriveType.CDRom:
169                         item.Icon = Properties.Resources.IconDriveCD;
170                         break;
171                     case DriveType.Removable:
172                         item.Icon = Properties.Resources.IconDriveRem;
173                         break;
174                     default:
175                         item.Icon = Properties.Resources.IconDriveFix;
176                         break;
177                 }
178                 Program.RootDriveList.Add(item);
179                 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
180             }
181         }
182
183         private void SetDropdownList(bool filter)
184         {
185             string[] commands = Program.ParseCommand(this.searchTextBox.TextBox.Text);
186             string command = "";
187             if(commands.Length > 0)
188                 command = commands[commands.Length - 1];
189
190             this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Clear();
191             if (filter && command.Equals(""))
192             {
193                 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
194                 return;
195             }
196
197 //            if ("c:\\".Equals(command))
198 //            {
199 //                //command = command;
200 //            }
201
202             if (!command.Equals("") && command[0] == '\\')
203             {
204 /*
205                 if (command.Length == 1)
206                 {
207                     this.SetRootDriveList();
208                 }
209                 else if (command.LastIndexOf('\\') == 0)
210                 {
211                     //ルートドライブ
212                     string str = command.Substring(1);
213                     foreach (ListViewItem item in Program.RootDriveList)
214                     {
215                         if (this.textBox_cmd.CaseSensitive)
216                         {
217                             if (item.Text.StartsWith(str))
218                                 this.textBox_cmd.DropdownForm.DropdownListView.Items.Add(item);
219                         }
220                         else
221                         {
222                             if (item.Text.ToLower().StartsWith(str.ToLower()))
223                                 this.textBox_cmd.DropdownForm.DropdownListView.Items.Add(item);
224                         }
225                     }
226                 } */
227             }
228             else if (!command.Equals("") && command[0] == '!')
229             {
230                 if (command.Length == 1)
231                 {
232                     foreach (string str in Program.CommandHistoryList)
233                     {
234                         IconListBoxItem item = new IconListBoxItem();
235                         item.Name = str;
236                         item.Text = str;
237                         item.Type = IconListBoxType.History;
238                         item.IconImage = Properties.Resources.IconHistory.ToBitmap();
239                         this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
240                     }
241                 }
242                 else
243                 {
244                     foreach (string str in Program.CommandHistoryList)
245                     {
246                         string text = command.Substring(1);
247                         //if (item.Text.ToLower().StartsWith(this.textBox_cmd.Text.ToLower()) || Program.Ime.StartsWith(item.Regex, this.textBox_cmd.Text))
248
249                         if (str.ToLower().StartsWith(text.ToLower()))
250                         {
251                             IconListBoxItem item = new IconListBoxItem();
252                             item.Name = str;
253                             item.Text = str;
254                             item.Type = IconListBoxType.History;
255                             item.IconImage = Properties.Resources.IconHistory.ToBitmap();
256                             this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
257                         }
258                     }
259                 }
260
261             }
262             else
263             {
264                 int lindex = command.LastIndexOf('\\') + 1;
265                 if (lindex > 0)
266                 {
267                     string directories = command.Substring(0, lindex);
268                     string files = command.Substring(lindex);
269
270                     try
271                     {
272                         if (Directory.GetFileSystemEntries(directories, files + "*").Length > 0)
273                         {
274                             this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Clear();
275                             if (this.searchTextBox.TextBox.Text.Equals(Directory.GetDirectoryRoot(command)))
276                             {
277                                 DriveInfo driveInfo = new DriveInfo(this.searchTextBox.TextBox.Text[0].ToString());
278                                 if (!driveInfo.IsReady)
279                                     return;
280                             }
281                             foreach (string directory in Directory.GetDirectories(directories, files + "*"))
282                             {
283                                 IconListBoxItem item = new IconListBoxItem();
284                                 item.Name = directory.Substring(directories.Length) + "\\";
285                                 item.Text = directory + "\\";
286                                 item.Type = IconListBoxType.Directory;
287                                 item.IconImage = Program.DirectoryIcon.ToBitmap();
288                                 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
289                             }
290                             foreach (string file in Directory.GetFiles(directories, files + "*"))
291                             {
292                                 int extindex;
293                                 string ext;
294                                 IconListBoxItem item = new IconListBoxItem();
295                                 item.Name = file.Substring(directories.Length);
296                                 item.Text = file;
297                                 item.Type = IconListBoxType.Directory;
298
299                                 extindex = item.Name.LastIndexOf('.');
300                                 ext = extindex == -1 ? "" : item.Name.Substring(extindex + 1);
301
302                                 if ("exe".Equals(ext) || "lnk".Equals(ext))
303                                 {
304                                     Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();
305                                     Win32.SHGetFileInfo(file, 0, ref shinfo, Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
306                                     if (shinfo.hIcon != IntPtr.Zero)
307                                         item.IconImage = System.Drawing.Icon.FromHandle(shinfo.hIcon).ToBitmap();
308                                 }
309                                 else
310                                 {
311                                     if (Program.ExtIconCacheDic.ContainsKey(ext))
312                                     {
313                                         if (Program.ExtIconCacheDic[ext] != null)
314                                             item.IconImage = Program.ExtIconCacheDic[ext].ToBitmap();
315                                     }
316                                     else
317                                     {
318                                         Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();
319                                         Win32.SHGetFileInfo(file, 0, ref shinfo, Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
320                                         if (shinfo.hIcon != IntPtr.Zero)
321                                         {
322                                             Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
323                                             Program.ExtIconCacheDic.Add(ext, icon);
324                                             item.IconImage = icon.ToBitmap();
325                                         }
326                                         else
327                                         {
328                                             Program.ExtIconCacheDic.Add(ext, null);
329                                         }
330                                     }
331                                 }
332                                 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
333                             }
334                         }
335                     }
336                     catch (Exception ex) { MessageBox.Show("ex: " + ex.ToString()); }
337                 }
338                 else
339                 {
340                     foreach (IconListBoxItem item in this.searchTextBox.TextBox.Items)
341                     {
342                         if (item.Text.ToLower().StartsWith(this.searchTextBox.TextBox.Text.ToLower()) || Program.Ime.StartsWith(item.Regex, this.searchTextBox.TextBox.Text))
343                             this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(item);
344                     }
345                     if (command.Length > 0)
346                     {
347                         foreach (string str in Program.CommandHistoryList)
348                         {
349                             if (str.StartsWith(command))
350                             {
351                                 bool exist = false;
352                                 foreach (IconListBoxItem item in this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items)
353                                 {
354                                     if (str.Equals(item.Text))
355                                     {
356                                         exist = true;
357                                         break;
358                                     }
359                                 }
360
361                                 if (exist)
362                                     continue;
363                                 IconListBoxItem i = new IconListBoxItem();
364                                 i.Name = str;
365                                 i.Text = str;
366                                 i.Type = IconListBoxType.History;
367                                 i.IconImage = null;
368                                 this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Add(i);
369                             }
370                         }
371                     }
372
373                 }
374             }
375             if (this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Items.Count == 0)
376             {
377                 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
378                 return;
379             }
380             this.searchTextBox.TextBox.SetDropdownFormLocation();
381         }
382
383         /// <summary>
384         /// 検索エンジンのサジェスト
385         /// </summary>
386         public void SetEngineDropdownList(string text)
387         {
388             if (this.suggestString.Equals(text))
389                 return;
390
391             EngineInfo info = Program.GetEngineInfo(this.SelectedEngineIndex);
392             if (info == null)
393                 return;
394
395
396             string url = info.SuggestUrl.Replace("%s", Uri.EscapeDataString(text));
397             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
398             req.Method = "GET";
399             req.UserAgent = Program.UserAgent;
400
401             AsyncCallback readCallBack = new AsyncCallback(SuggestReadCallBack);
402             req.BeginGetResponse(readCallBack, req);
403             this.suggestString = text;
404
405         }
406
407         private void SuggestReadCallBack(IAsyncResult ar)
408         {
409             try
410             {
411                 HttpWebRequest req = (HttpWebRequest)ar.AsyncState;
412                 HttpWebResponse response = (HttpWebResponse)req.EndGetResponse(ar);
413                 StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet));
414                 string str = streamReader.ReadToEnd();
415                 streamReader.Close();
416                 Win32.PostMessage(Program.MainFormHandle, Program.WM_SUGGEST_END, IntPtr.Zero, Marshal.StringToHGlobalAuto(str));
417             }
418             catch (Exception ex)
419             {
420                 Debug.WriteLine("error:" + ex);
421                 string s = ex.ToString();
422                 s += "hoge";
423             } 
424         } 
425
426         private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
427         {
428             if (Program.HotKeyEngineList.Contains(KeyboardHook.Keycode))
429             {
430                 EngineInfo info = Program.GetEngineInfoFromHotKey(KeyboardHook.Keycode);
431                 if (info == null)
432                     return;
433
434                 this.SetSearchEngine(info);
435                 e.Handled = true;
436                 return;
437             }
438
439             switch ((Keys)e.KeyChar)
440             {
441                 case Keys.Tab:
442                     e.Handled = true;
443                     if (this.SearchTextBox.TextBox.Complemented)
444                         return;
445
446                     if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
447                     {
448                         this.ShowDropdownForm(false);
449                         return;
450                     }
451                     break;
452
453                 case Keys.Space:
454                     if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
455                     {
456                         switch (this.SelectedEngineType)
457                         {
458                             case 0:
459                                 if (this.SearchTextBox.TextBox.ShowableDropdownList)
460                                     this.ShowDropdownForm(false);
461                                 e.Handled = true;
462                                 break;
463                             case 2:
464                                 this.suggestString = "";
465                                 this.textChanged = true;
466                                 e.Handled = true;
467                                 break;
468                         }
469                     }
470                     break;
471
472                 case Keys.Enter:
473                     string command = this.SearchTextBox.TextBox.Text.Trim();
474                     switch (this.SelectedEngineType)
475                     {
476                         case 0: //COMMAND
477                             if (this.ExecCommand(command))
478                             {
479                                 Program.AddHistoryList(command);
480                             }
481                             break;
482
483                         case 1: //FILE_VIEW
484                             break;
485
486                         case 2: //WEB_SEARCH
487                             this.ExecSearch(command);
488                             break;
489                     }
490                     e.Handled = true;
491                     return;
492
493                 case Keys.Escape:
494                     if (this.SearchTextBox.TextBox.DropdownForm.Visible)
495                     {
496                         this.SearchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
497                         Program.HideToolTip();
498                         e.Handled = true;
499                         return;
500                     }
501                     if (!"".Equals(searchTextBox.TextBox.Text))
502                     {
503                         this.SearchTextBox.TextBox.Text = "";
504                         this.SearchTextBox.TextBox.SelectionStart = 0;
505                         e.Handled = true;
506                         return;
507                     }
508                     if(this.Visible)
509                     {
510                         this.DoVisibleChange(false);
511                         Program.ForceForegroundWindow(this.beforeHWnd);
512                     }
513                     e.Handled = true;
514                     return;
515             }
516         }
517
518         private void textBox_cmd_KeyDown(object sender, KeyEventArgs e)
519         {
520             if (Program.MainForm.Opacity != Program.FormOpacity)
521                 Program.MainForm.Opacity = Program.FormOpacity;
522
523             switch (e.KeyCode)
524             {
525                 case Keys.Up:
526                     if ((Keys.Control & Control.ModifierKeys) == Keys.Control)
527                     {
528                         //検索エンジンの切替
529                         this.SelectedEngineIndex--;
530                         if(this.SelectedEngineIndex == -1)
531                             this.SelectedEngineIndex = Program.DefaultEngineList.Count + Program.EngineList.Count - 1;
532                         this.SetSearchEngine(Program.GetEngineInfo(this.SelectedEngineIndex));
533                     }
534                     else
535                     {
536                         if (this.SelectedEngineType == 0)
537                         {
538                             if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
539                             {
540                                 if (Program.CommandHistoryList.Count > 0)
541                                 {
542                                     if (Program.CommandHistoryList.Count > Program.CommandHistoryIndex)
543                                         Program.CommandHistoryIndex++;
544                                     this.showDropdownSupport = false;
545                                     this.SearchTextBox.TextBox.Text = Program.CommandHistoryList[Program.CommandHistoryIndex - 1];
546                                     this.SearchTextBox.TextBox.SelectionStart = this.SearchTextBox.TextBox.Text.Length;
547                                     this.showDropdownSupport = true;
548                                 }
549                             }
550                         }
551                     }
552                     break;
553
554                 case Keys.Down:
555                     if ((Keys.Control & Control.ModifierKeys) == Keys.Control)
556                     {
557                         //検索エンジンの切替
558                         this.SelectedEngineIndex++;
559                         int count = Program.DefaultEngineList.Count + Program.EngineList.Count;
560                         if (this.SelectedEngineIndex == count)
561                             this.SelectedEngineIndex = 0;
562                         this.SetSearchEngine(Program.GetEngineInfo(this.SelectedEngineIndex));
563                     }
564                     else
565                     {
566                         switch(this.SelectedEngineType)
567                         {
568                             case 0:
569                                 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
570                                 {
571                                     if (Program.CommandHistoryIndex > 0)
572                                     {
573                                         Program.CommandHistoryIndex--;
574                                         this.showDropdownSupport = false;
575                                         if (Program.CommandHistoryIndex == 0)
576                                             this.SearchTextBox.TextBox.Text = "";
577                                         else
578                                             this.SearchTextBox.TextBox.Text = Program.CommandHistoryList[Program.CommandHistoryIndex - 1];
579                                         this.SearchTextBox.TextBox.SelectionStart = this.SearchTextBox.TextBox.Text.Length;
580                                         this.showDropdownSupport = true;
581                                     }
582                                     else
583                                     {
584                                         this.ShowDropdownForm(false);
585                                     }
586                                 }
587                                 break;
588
589                             case 2:
590                                 if (!this.SearchTextBox.TextBox.DropdownForm.Visible)
591                                 {
592                                     this.suggestString = "";
593                                     this.textChanged = true;
594                                 }
595                                 break;
596                         }
597                     }
598                     break;
599             }
600         }
601         
602         private void textBox_cmd_TextChanged(object sender, EventArgs e)
603         {
604             this.latestKeyTime = DateTime.Now.Ticks;
605             this.searchTextBox.TextBox.ImeText = this.searchTextBox.TextBox.Text;
606             if (!this.showDropdownSupport)
607                 return;
608
609             Size s = TextRenderer.MeasureText(this.searchTextBox.TextBox.Text, this.searchTextBox.TextBox.Font);
610             if (s.Width > this.searchTextBox.TextBox.Width)
611             {
612                 //MessageBox.Show("!!!");
613             }
614
615             if(!this.searchTextBox.TextBox.Complemented)
616                 this.ShowDropdownForm(true);
617         }
618
619         private void textBox_cmd_Complement(IconListBoxType type)
620         {
621             //this.ShowFileList();
622         }
623
624         private void textBox_cmd_ImeComposition(int type, string text)
625         {
626             if(!String.IsNullOrEmpty(this.searchTextBox.TextBox.Text))
627             {
628                 string str = this.searchTextBox.TextBox.Text;
629                 text = str.Substring(0, this.searchTextBox.TextBox.SelectionStart)
630                      + text
631                      + str.Substring(this.searchTextBox.TextBox.SelectionStart);
632             }
633             this.searchTextBox.TextBox.ImeText = text;
634
635             if (type == 0 && String.IsNullOrEmpty(text))
636             {
637                 this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
638                 this.suggestString = "";
639             }
640             else
641             {
642                 if ((type & Win32.GCS_RESULTSTR) != Win32.GCS_RESULTSTR)
643                 {
644                     this.latestKeyTime = DateTime.Now.Ticks;
645                     this.textChanged = true;
646                 }
647             }
648         }
649
650         private void dropdownListBox_SelectedIndexChanged(object sender, EventArgs e)
651         {
652             Program.HideToolTip();
653             if (!this.searchTextBox.TextBox.DropdownForm.Visible)
654                 return;
655
656             IconListBox listBox = this.searchTextBox.TextBox.DropdownForm.DropdownListBox;
657             if (listBox.SelectedIndex == -1)
658                 return;
659
660             string text = listBox.Text;
661             if (text.Equals(this.dropdownListBoxText))
662                 return;
663
664             if (!(text.StartsWith(":") || Program.CommandDic.ContainsKey(text)))
665                 return;
666
667             int lastIndex = listBox.ClientRectangle.Height / listBox.ItemHeight;
668             if (listBox.TopIndex > listBox.SelectedIndex || (listBox.TopIndex + lastIndex) <= listBox.SelectedIndex)
669                 return;
670
671             IconListBoxItem item = (IconListBoxItem)listBox.SelectedItem;
672             DropdownListForm dropdownForm = this.searchTextBox.TextBox.DropdownForm;
673
674             Rectangle r = dropdownForm.Bounds;
675             r.Y = dropdownForm.Location.Y + listBox.GetItemRectangle(listBox.SelectedIndex).Y;
676             if (item.ToolTipText == null || item.ToolTipText.Length == 0)
677             {
678                 CommandInfo info = Program.CommandDic[text];
679                 text = info.Comment == null ? info.Name : info.Comment;
680             }
681             else
682             {
683                 text = item.ToolTipText;
684             }
685             Program.ShowToolTip(Util.CutText(text, 50, 10), r, 5000, false);
686         }
687
688         private void timer1_Tick(object sender, System.EventArgs e)
689         {
690             if (this.Visible)
691             {
692                 if (this.Opacity + Program.FadeInSpeed < Program.FormOpacity)
693                 {
694                     this.Opacity += Program.FadeInSpeed;
695                     this.searchTextBox.TextBox.DropdownForm.Opacity = this.Opacity;
696                     this.Update();
697                 }
698                 else
699                 {
700                     this.Opacity = Program.FormOpacity;
701                     this.searchTextBox.TextBox.DropdownForm.Opacity = this.Opacity;
702                     this.timer1.Stop();
703                 }
704             }
705         }
706
707         private void timer_keyRecoding_Tick(object sender, EventArgs e)
708         {
709             if (Program.Status == ProgramStatus.KeyRecoding && Program.Main_ShowBalloonWhileRecoding && Program.BallonWindowHandle != IntPtr.Zero)
710                 Win32.PostMessage(Program.BallonWindowHandle, Win32.WM_MOUSEMOVE, (IntPtr)0, (IntPtr)0);
711         }
712
713         private void timer_suggest_Tick(object sender, EventArgs e)
714         {
715             if (this.SelectedEngineType == 2 && this.textChanged)
716             {
717                 string text = this.searchTextBox.TextBox.ImeText;
718                 if (String.IsNullOrEmpty(text))
719                     return;
720
721                 if (DateTime.Now.Ticks > this.latestKeyTime + 000000 && !this.suggestString.Equals(text))
722                 {
723                     this.textChanged = false;
724                     this.SetEngineDropdownList(text);
725                 }
726             }
727         }
728
729         private void toolTip_Popup(object sender, PopupEventArgs e)
730         {
731        
732         }
733
734         private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
735         {
736             if (e.Button == MouseButtons.Left)
737             {
738                 switch (Program.Status)
739                 {
740                     case ProgramStatus.Loading:
741                     case ProgramStatus.Waiting:
742                     case ProgramStatus.MainFormOpen:
743                         HotKeyProcessExecuter.OpenMainForm();
744                         break;
745                 }
746             }
747         }
748
749         private void DropdownListView_MouseDoubleClick(object sender, MouseEventArgs e)
750         {
751             this.searchTextBox.TextBox.Text = this.searchTextBox.TextBox.DropdownForm.DropdownListBox.Text;
752             this.searchTextBox.TextBox.Select(this.searchTextBox.TextBox.Text.Length, 0);
753             this.searchTextBox.TextBox.DropdownForm.DoVisibleChange(false);
754         }
755
756         private void 表示ToolStripMenuItem_Click(object sender, EventArgs e)
757         {
758             switch (Program.Status)
759             {
760                 case ProgramStatus.Loading:
761                 case ProgramStatus.Waiting:
762                 case ProgramStatus.MainFormOpen:
763                     HotKeyProcessExecuter.OpenMainForm();
764                     break;
765             }
766         }
767
768         private void リスト設定ToolStripMenuItem_Click(object sender, EventArgs e)
769         {
770             if (!Program.SettingForm.Visible)
771             {
772                 this.DoVisibleChange(false);
773                 Program.SettingForm.DoVisibleChange(true);
774             }
775         }
776
777         private void バージョン情報ToolStripMenuItem_Click(object sender, EventArgs e)
778         {
779             if (Program.Status == ProgramStatus.Waiting)
780             {
781                 Program.Status = ProgramStatus.VersionFormOpen;
782                 VersionForm f = new VersionForm();
783                 f.ShowDialog();
784                 Program.Status = ProgramStatus.Waiting;
785             }
786         }
787
788         private void 終了ToolStripMenuItem_Click(object sender, EventArgs e)
789         {
790             this.Close();
791             Application.Exit();
792         }
793     }
794 }