OSDN Git Service

This commit was manufactured by cvs2svn to create branch 'Bb52'.
[gikonavigoeson/gikonavi.git] / InputAssist.pas
1 unit InputAssist;
2
3 interface
4
5 uses
6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7   Dialogs, StdCtrls, ComCtrls, GikoListView, Menus, ExtCtrls, ImgList,
8   InputAssistDataModule, StdActns, ActnList, GikoSystem;
9
10 type
11   TInputAssistForm = class(TForm)
12     Panel1: TPanel;
13     Panel2: TPanel;
14     GikoListView1: TGikoListView;
15     Panel3: TPanel;
16     KeyNameEdit: TLabeledEdit;
17     CategoryNameEdit: TLabeledEdit;
18         Panel4: TPanel;
19         TextMemo: TMemo;
20     ColumnImageList: TImageList;
21     InputAssistFormActionList: TActionList;
22     EditCut1: TEditCut;
23     EditCopy1: TEditCopy;
24     EditPaste1: TEditPaste;
25     EditSelectAll1: TEditSelectAll;
26     EditUndo1: TEditUndo;
27     EditDelete1: TEditDelete;
28     GroupBox1: TGroupBox;
29     Panel5: TPanel;
30     CloseButton: TButton;
31     ApplyButton: TButton;
32     DeleteButton: TButton;
33     AddButton: TButton;
34     Panel6: TPanel;
35     Panel7: TPanel;
36     CategoryComboBox: TComboBox;
37     CategoryComboLabel: TLabel;
38     InsertButton: TButton;
39     InsertButtonAction: TAction;
40     CloseAction: TAction;
41     procedure FormCreate(Sender: TObject);
42     procedure GikoListView1SelectItem(Sender: TObject; Item: TListItem;
43       Selected: Boolean);
44     procedure AddButtonClick(Sender: TObject);
45     procedure DeleteButtonClick(Sender: TObject);
46     procedure ApplyButtonClick(Sender: TObject);
47     procedure FormClose(Sender: TObject; var Action: TCloseAction);
48     procedure GikoListView1Compare(Sender: TObject; Item1,
49       Item2: TListItem; Data: Integer; var Compare: Integer);
50     procedure GikoListView1ColumnClick(Sender: TObject;
51       Column: TListColumn);
52     procedure CloseButtonClick(Sender: TObject);
53     procedure CategoryComboBoxKeyPress(Sender: TObject; var Key: Char);
54     procedure CategoryComboBoxChange(Sender: TObject);
55     procedure InsertButtonActionUpdate(Sender: TObject);
56     procedure InsertButtonActionExecute(Sender: TObject);
57     procedure CloseActionExecute(Sender: TObject);
58   private
59         { Private \90é\8c¾ }
60         FSortColumn : Integer;
61         FInsertText : String;
62         procedure AddListViewItem(ResWord : TResistWord);
63   public
64         { Public \90é\8c¾ }
65         procedure SetUpFromEditor();
66         procedure SetUpFromMain();
67         function GetInsertText(): String;
68   end;
69
70 var
71   InputAssistForm: TInputAssistForm;
72
73 implementation
74
75 uses Setting, MojuUtils;
76
77
78 {$R *.dfm}
79 //! \83t\83H\81[\83\80\90\90¬\82Ì\83C\83x\83\93\83g
80 procedure TInputAssistForm.FormCreate(Sender: TObject);
81 var
82         wp: TWindowPlacement;
83         i : Integer;
84         column: TListColumn;
85 begin
86         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
87         wp.length := sizeof(wp);
88         wp.rcNormalPosition.Top := GikoSys.Setting.InputAssistFormTop;
89         wp.rcNormalPosition.Left := GikoSys.Setting.InputAssistFormLeft;
90
91         wp.rcNormalPosition.Bottom := GikoSys.Setting.InputAssistFormTop
92                                                                         + GikoSys.Setting.InputAssistFormHeight;
93         wp.rcNormalPosition.Right := GikoSys.Setting.InputAssistFormLeft
94                                                                         + GikoSys.Setting.InputAssistFormWidth;
95         wp.showCmd := SW_HIDE;
96         SetWindowPlacement(Handle, @wp);
97
98         FSortColumn := 0;
99         GikoListView1.Columns.Clear;
100         column := GikoListView1.Columns.Add;
101         column.ImageIndex := 0;
102         column.Caption := '\83L\81[';
103         column.Width := 150;
104         column := GikoListView1.Columns.Add;
105         column.Caption := '\83J\83e\83S\83\8a';
106         column.Width := 80;
107         for i := 0 to InputAssistDM.ResistWordCount - 1 do begin
108                 AddListViewItem(InputAssistDM.GetResistWord(i));
109         end;
110         //\83\\81[\83g\8fó\91Ô\82ð\89ð\8f\9c (\89ð\8f\9c\82µ\82È\82¢\82Æ\83A\83C\83e\83\80\82Ì\83L\81[\96¼\82ð\95Ï\8dX\82Å\82«\82È\82¢)
111         InputAssistDM.Sorted := False;
112 end;
113 //! \88ê\97\97\82É\83A\83C\83e\83\80\82ð\92Ç\89Á\82·\82é\8f\88\97\9d
114 procedure TInputAssistForm.AddListViewItem(ResWord : TResistWord);
115 var
116         item: TListItem;
117 begin
118         item := GikoListView1.Items.Add;
119         item.ImageIndex := -1;
120         item.Caption := resWord.GetKey;
121         item.SubItems.Add(resWord.GetCategory);
122         item.Data := resWord;
123 end;
124 //! \93o\98^\92P\8cê\88ê\97\97\82©\82ç\83A\83C\83e\83\80\82ð\91I\91ð\82µ\82½\82Æ\82«\82Ì\83C\83x\83\93\83g
125 procedure TInputAssistForm.GikoListView1SelectItem(Sender: TObject;
126   Item: TListItem; Selected: Boolean);
127 begin
128         if (Item <> nil) and (Item.Data <> nil) then begin
129                 KeyNameEdit.Text := TResistWord(Item.Data).GetKey;
130                 CategoryNameEdit.Text := TResistWord(Item.Data).GetCategory;
131                 TextMemo.Lines.Text := TResistWord(Item.Data).GetText;
132         end else begin
133                 TextMemo.Lines.Text := '';
134         end;
135 end;
136 //! \92Ç\89Á\83{\83^\83\93\89\9f\89º\8e\9e\82Ì\83C\83x\83\93\83g
137 procedure TInputAssistForm.AddButtonClick(Sender: TObject);
138 var
139         resWord : TResistWord;
140 begin
141         if (Length(KeyNameEdit.Text) = 0) then begin
142                 ShowMessage('\83L\81[\96¼\82ð\90Ý\92è\82µ\82Ä\82­\82¾\82³\82¢\81B');
143         end else begin
144                 resWord := InputAssistDM.Add(KeyNameEdit.Text);
145                 resWord.SetCategory(CategoryNameEdit.Text);
146                 resWord.SetText(TextMemo.Text);
147                 AddListViewItem(resWord);
148                 GikoListView1.AlphaSort;
149         end;
150 end;
151 //! \8dí\8f\9c\83{\83^\83\93\89\9f\89º\8e\9e\82Ì\83C\83x\83\93\83g
152 procedure TInputAssistForm.DeleteButtonClick(Sender: TObject);
153 begin
154         if GikoListView1.Selected <> nil then begin
155                 InputAssistDM.DeleteResistWord(GikoListView1.Selected.Data);
156                 GikoListView1.Selected.Data := nil;
157                 GikoListView1.DeleteSelected;
158         end;
159 end;
160 //! \93K\97p\83{\83^\83\93\89\9f\89º\8e\9e\82Ì\83C\83x\83\93\83g
161 procedure TInputAssistForm.ApplyButtonClick(Sender: TObject);
162 var
163         resWord : TResistWord;
164 begin
165         if GikoListView1.Selected <> nil then begin
166                 if (Length(KeyNameEdit.Text) = 0) then begin
167                         ShowMessage('\83L\81[\96¼\82ð\96³\82µ\82É\82Í\82Å\82«\82Ü\82¹\82ñ\81B');
168                 end else begin
169                         resWord := TResistWord(GikoListView1.Selected.Data);
170                         resWord.SetKey(KeyNameEdit.Text);
171                         resWord.SetCategory(CategoryNameEdit.Text);
172                         resWord.SetText(TextMemo.Text);
173                         // \88ê\97\97\82Ì\8dX\90V
174                         GikoListView1.Selected.Caption := resWord.GetKey;
175                         GikoListView1.Selected.SubItems[0] := resWord.GetCategory;
176                         GikoListView1.AlphaSort;
177                 end;
178         end;
179 end;
180 //! \83t\83H\81[\83\80\82ð\95Â\82\82é\82Æ\82«\82Ì\83C\83x\83\93\83g
181 procedure TInputAssistForm.FormClose(Sender: TObject;
182   var Action: TCloseAction);
183 begin
184         GikoSys.Setting.InputAssistFormTop := Self.Top;
185         GikoSys.Setting.InputAssistFormLeft := Self.Left;
186         GikoSys.Setting.InputAssistFormHeight := Self.Height;
187         GikoSys.Setting.InputAssistFormWidth := Self.Width;
188         //\83\\81[\83g\8fó\91Ô\82Ì\90Ý\92è
189         InputAssistDM.Sorted := True;
190 end;
191 //! \93o\98^\92P\8cê\88ê\97\97\82Ì\83\\81[\83g\97p\82Ì\94ä\8ar\8f\88\97\9d
192 procedure TInputAssistForm.GikoListView1Compare(Sender: TObject; Item1,
193   Item2: TListItem; Data: Integer; var Compare: Integer);
194 begin
195         if ((FSortColumn and 2) > 0) then begin
196                 // \83J\83e\83S\83\8a\82Å\83\\81[\83g
197                 Compare := CompareStr(
198                         ZenToHan(Item1.SubItems[0]), ZenToHan(Item2.SubItems[0]));
199                 if (Compare = 0) then begin
200                         Compare := CompareStr(
201                                 ZenToHan(Item1.Caption), ZenToHan(Item2.Caption));
202                 end;
203         end else begin
204                 // \83L\81[\82Å\83\\81[\83g
205                 Compare := CompareStr(
206                         ZenToHan(Item1.Caption), ZenToHan(Item2.Caption));
207                 if (Compare = 0) then begin
208                         Compare := CompareStr(
209                                 ZenToHan(Item1.SubItems[0]), ZenToHan(Item2.SubItems[0]));
210                 end;
211         end;
212         // \8f¸\8f\87\8d~\8f\87\82Ì\94½\93]
213         if ((FSortColumn and 1) > 0) then begin
214                 Compare := Compare * -1;
215         end;
216         ;
217 end;
218 //! \93o\98^\92P\8cê\88ê\97\97\82Ì\83\8a\83X\83g\82Ì\83J\83\89\83\80\83N\83\8a\83b\83N\83C\83x\83\93\83g
219 procedure TInputAssistForm.GikoListView1ColumnClick(Sender: TObject;
220   Column: TListColumn);
221 var
222         i : Integer;
223 begin
224         if Column <> nil then begin
225                 // \83C\83\81\81[\83W\82Ì\8dí\8f\9c
226                 for i := 0 to GikoListView1.Columns.Count - 1 do begin
227                         GikoListView1.Column[i].ImageIndex := -1;
228                 end;
229
230                 // FSortColumn \8bô\90\94:\8f¸\8f\87 \8aï\90\94\81F\8d~\8f\87
231                 if Column.Caption = '\83L\81[' then begin
232                         if FSortColumn = 0 then begin
233                                 FSortColumn := 1;
234                         end else begin
235                                 FSortColumn := 0;
236                         end;
237                 end else begin
238                         if FSortColumn = 2 then begin
239                                 FSortColumn := 3;
240                         end else begin
241                                 FSortColumn := 2;
242                         end;
243                 end;
244                 Column.ImageIndex := (FSortColumn and 1);
245                 GikoListView1.AlphaSort;
246         end;
247
248 end;
249 //! \8fI\97¹\83{\83^\83\93\82ð\89\9f\89º\8e\9e\82Ì\83C\83x\83\93\83g
250 procedure TInputAssistForm.CloseButtonClick(Sender: TObject);
251 begin
252         Close();
253 end;
254 //! \83J\83e\83S\83\8a\8di\8d\9e\82Ý\83R\83\93\83{\83{\83b\83N\83X\82ð\93Ç\8eæ\90ê\97p\82É\82·\82é\82½\82ß\82Ì\83C\83x\83\93\83g\8f\88\97\9d
255 procedure TInputAssistForm.CategoryComboBoxKeyPress(Sender: TObject;
256   var Key: Char);
257 begin
258         Key := #0;
259 end;
260 //! \83J\83e\83S\83\8a\8di\8d\9e\82Ý\83R\83\93\83{\83{\83b\83N\83X\82Å\82Ì\83J\83e\83S\83\8a\95Ï\8dX\8f\88\97\9d
261 procedure TInputAssistForm.CategoryComboBoxChange(Sender: TObject);
262 var
263         i : Integer;
264         key : String;
265 begin
266         LockWindowUpdate(GikoListView1.Handle);
267         GikoListView1.Clear;
268         if (CategoryComboBox.ItemIndex <= 0) then begin
269                 for i := 0 to InputAssistDM.ResistWordCount - 1 do begin
270                         AddListViewItem(InputAssistDM.GetResistWord(i));
271                 end;
272         end else begin
273                 key := CategoryComboBox.Items[CategoryComboBox.ItemIndex];
274                 for i := 0 to InputAssistDM.ResistWordCount - 1 do begin
275                         if (key = InputAssistDM.GetResistWord(i).GetCategory) then begin
276                                 AddListViewItem(InputAssistDM.GetResistWord(i));
277                         end;
278                 end;
279         end;
280         LockWindowUpdate(0);
281 end;
282
283 procedure TInputAssistForm.SetUpFromMain();
284 begin
285         Self.Caption := '\93ü\97Í\83A\83V\83X\83g\90Ý\92è';
286         Panel3.Visible := True;
287         Panel5.Visible := True;
288         Panel7.Visible := False;
289         TextMemo.ReadOnly := False;
290         FInsertText := '';
291         CloseAction.ShortCut := TShortCut(0);
292 end;
293 procedure TInputAssistForm.SetUpFromEditor();
294 var
295         cat : TStringList;
296 begin
297         Self.Caption := '\93ü\97Í\83A\83V\83X\83g';
298         Panel3.Visible := False;
299         Panel5.Visible := False;
300         Panel7.Visible := True;
301         TextMemo.ReadOnly := True;
302         FInsertText := '';
303         CloseAction.ShortCut := ShortCut(VK_ESCAPE, []);
304         // \8c\9f\8dõ\97p
305         cat := TStringList.Create;
306         try
307                 InputAssistDM.GetCategoryList(cat);
308                 CategoryComboBox.Items.Clear;
309                 CategoryComboBox.Items.Add('');
310                 CategoryComboBox.Items.AddStrings(cat);
311                 CategoryComboBox.ItemIndex := 0;
312         finally
313                 cat.Free;
314         end;
315 end;
316 function TInputAssistForm.GetInsertText(): String;
317 begin
318         Result := FInsertText;
319 end;
320
321 procedure TInputAssistForm.InsertButtonActionUpdate(Sender: TObject);
322 begin
323         InsertButtonAction.Enabled := (GikoListView1.Selected <> nil);
324 end;
325
326 procedure TInputAssistForm.InsertButtonActionExecute(Sender: TObject);
327 begin
328         if (GikoListView1.Selected = nil) then begin
329                 FInsertText := '';
330                 Self.ModalResult := mrNone;
331         end else begin
332                 FInsertText :=  TResistWord(GikoListView1.Selected.Data).GetText;
333                 Self.ModalResult := mrOk;
334         end;
335 end;
336
337 procedure TInputAssistForm.CloseActionExecute(Sender: TObject);
338 begin
339         Self.ModalResult := mrCancel;
340 end;
341
342 end.