OSDN Git Service

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