OSDN Git Service

1.60.2.794
[gikonavigoeson/gikonavi.git] / KeySetting.pas
1 unit KeySetting;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7         Dialogs, ComCtrls, StdCtrls, ExtCtrls, ActnList, Menus,
8         Editor;
9
10 type
11         TKeySettingItem = class(TObject)
12         private
13                 FAction: TAction;
14                 FShortCut: TShortCut;
15                 FGesture        : string;
16         public
17                 property Action: TAction read FAction write FAction;
18                 property ShortCut: TShortCut read FShortCut write FShortCut;
19                 property Gesture : string read FGesture write FGesture;
20         end;
21
22         TKeySettingForm = class(TForm)
23     Panel1: TPanel;
24     Panel2: TPanel;
25     Panel3: TPanel;
26     OkBotton: TButton;
27     CancelBotton: TButton;
28     Label1: TLabel;
29     Label2: TLabel;
30     HotKey: THotKey;
31     SetButton: TButton;
32     StatusBar: TStatusBar;
33     Panel4: TPanel;
34     PageControl1: TPageControl;
35     TabSheet1: TTabSheet;
36     TabSheet2: TTabSheet;
37     ListView: TListView;
38     ListView1: TListView;
39     GestureLabel: TLabel;
40     GestureEdit: TEdit;
41     GestureSetButton: TButton;
42     GestureCheckBox: TCheckBox;
43                 procedure FormCreate(Sender: TObject);
44                 procedure FormDestroy(Sender: TObject);
45     procedure ListViewSelectItem(Sender: TObject; Item: TListItem;
46       Selected: Boolean);
47     procedure HotKeyEnter(Sender: TObject);
48     procedure HotKeyExit(Sender: TObject);
49     procedure FormKeyDown(Sender: TObject; var Key: Word;
50       Shift: TShiftState);
51     procedure SetButtonClick(Sender: TObject);
52     procedure OkBottonClick(Sender: TObject);
53     procedure ListViewCompare(Sender: TObject; Item1, Item2: TListItem;
54       Data: Integer; var Compare: Integer);
55     procedure GestureSetButtonClick(Sender: TObject);
56                 procedure OnGestureStart(Sender: TObject);
57                 procedure OnGestureMove(Sender: TObject);
58                 procedure OnGestureEnd(Sender: TObject);
59     procedure GestureCheckBoxClick(Sender: TObject);
60     procedure GestureEditChange(Sender: TObject);
61     procedure GestureEditKeyDown(Sender: TObject; var Key: Word;
62       Shift: TShiftState);
63         private
64                 { Private \90é\8c¾ }
65         public
66                 { Public \90é\8c¾ }
67                 EditorForm: TEditorForm;
68         end;
69
70 //var
71 //      KeySettingForm: TKeySettingForm;
72
73 implementation
74
75 uses
76         Giko, GikoUtil, Gesture, GikoDataModule, GikoSystem;
77
78 const
79         GUESTURE_NOTHING        = '\82È\82µ';
80
81 {$R *.dfm}
82
83 procedure TKeySettingForm.FormCreate(Sender: TObject);
84 var
85         i: Integer;
86         ListItem: TListItem;
87         KeyItem: TKeySettingItem;
88
89 begin
90         //for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
91         for i := 0 to GikoDM.GikoFormActionList.ActionCount - 1 do begin
92                 //if GikoForm.ActionList.Actions[i] is TAction then begin
93                 if GikoDM.GikoFormActionList.Actions[i] is TAction then begin
94                         if GikoDM.GikoFormActionList.Actions[i].Tag <> 0 then
95                                 Continue;
96                         ListItem := ListView.Items.Add;
97                         ListItem.Caption := TAction(GikoDM.GikoFormActionList.Actions[i]).Hint;
98                         ListItem.SubItems.Add(TAction(GikoDM.GikoFormActionList.Actions[i]).Category);
99                         ListItem.SubItems.Add(ShortCutToText(TAction(GikoDM.GikoFormActionList.Actions[i]).ShortCut));
100                         ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
101                                 TAction( GikoDM.GikoFormActionList.Actions[i] ) ) );
102                         ListItem.ImageIndex := TAction(GikoDM.GikoFormActionList.Actions[i]).ImageIndex;
103                         KeyItem := TKeySettingItem.Create;
104                         KeyItem.Action := TAction(GikoDM.GikoFormActionList.Actions[i]);
105                         KeyItem.ShortCut := TAction(GikoDM.GikoFormActionList.Actions[i]).ShortCut;
106                         KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
107                                 TAction( GikoDM.GikoFormActionList.Actions[i] ) );
108                         ListItem.Data := KeyItem;
109                 end;
110         end;
111         if ListView.Items.Count > 0 then
112                 ListView.Selected := ListView.Items[0];
113         EditorForm := TEditorForm.Create(Self);
114         try
115                 for i := 0 to EditorForm.ActionList.ActionCount - 1 do begin
116                         if EditorForm.ActionList.Actions[i] is TAction then begin
117                                 if EditorForm.ActionList.Actions[i].Tag <> 0 then
118                                         Continue;
119                                 ListItem := ListView1.Items.Add;
120                                 ListItem.Caption := TAction(EditorForm.ActionList.Actions[i]).Hint;
121                                 ListItem.SubItems.Add(TAction(EditorForm.ActionList.Actions[i]).Category);
122                                 ListItem.SubItems.Add(ShortCutToText(TAction(EditorForm.ActionList.Actions[i]).ShortCut));
123                                 ListItem.ImageIndex := TAction(EditorForm.ActionList.Actions[i]).ImageIndex;
124                                 ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
125                                         TAction( EditorForm.ActionList.Actions[i] ) ) );
126                                 KeyItem := TKeySettingItem.Create;
127                                 KeyItem.Action := TAction(EditorForm.ActionList.Actions[i]);
128                                 KeyItem.ShortCut := TAction(EditorForm.ActionList.Actions[i]).ShortCut;
129                                 KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
130                                         TAction( EditorForm.ActionList.Actions[i] ) );
131                                 ListItem.Data := KeyItem;
132                         end;
133                 end;
134                 ListView1.SmallImages := EditorForm.HotToobarImageList;
135         finally
136
137         end;
138 //      ActionListView.SortType := stText;
139         StatusBar.Height := 21;
140         StatusBar.Width := 21;
141         PageControl1.ActivePageIndex := 0;
142         GestureCheckBox.Checked := GikoSys.Setting.GestureEnabled;
143         GestureCheckBoxClick( Sender );
144
145         MouseGesture.UnHook;
146         MouseGesture.OnGestureStart := OnGestureStart;
147         MouseGesture.OnGestureMove := OnGestureMove;
148         MouseGesture.OnGestureEnd := OnGestureEnd;
149         MouseGesture.SetHook( Handle );
150 end;
151
152 procedure TKeySettingForm.FormDestroy(Sender: TObject);
153 var
154         i: Integer;
155 begin
156         for i := 0 to ListView.Items.Count - 1 do begin
157                 if TObject(ListView.Items[i].Data) is TKeySettingItem then
158                         TKeySettingItem(ListView.Items[i].Data).Free;
159         end;
160         for i := 0 to ListView1.Items.Count - 1 do begin
161                 if TObject(ListView1.Items[i].Data) is TKeySettingItem then
162                         TKeySettingItem(ListView1.Items[i].Data).Free;
163         end;
164          EditorForm.Release;
165 end;
166
167 procedure TKeySettingForm.ListViewSelectItem(Sender: TObject;
168   Item: TListItem; Selected: Boolean);
169 var
170         KeyItem: TKeySettingItem;
171 begin
172         if not Selected then Exit;
173
174         if TObject(Item.Data) is TKeySettingItem then begin
175                 KeyItem := TKeySettingItem(Item.Data);
176                 HotKey.HotKey := KeyItem.ShortCut;
177                 GestureEdit.Text := KeyItem.Gesture;
178         end;
179 end;
180
181 procedure TKeySettingForm.HotKeyEnter(Sender: TObject);
182 begin
183         OkBotton.Default := False;
184         CancelBotton.Cancel := False;
185 end;
186
187 procedure TKeySettingForm.HotKeyExit(Sender: TObject);
188 begin
189         OkBotton.Default := True;
190         CancelBotton.Cancel := True;
191 end;
192
193 procedure TKeySettingForm.FormKeyDown(Sender: TObject; var Key: Word;
194   Shift: TShiftState);
195 begin
196         if Key in [8, 27, 32, 46] then begin
197                 HotKey.HotKey := ShortCut(Key, Shift);
198                 Key := 0;
199         end;
200 end;
201
202 procedure TKeySettingForm.SetButtonClick(Sender: TObject);
203 const
204         ERR_ENT = 'Enter\83L\81[\82Í\83V\83\87\81[\83g\83J\83b\83g\82Æ\82µ\82Ä\8eg\97p\82Å\82«\82Ü\82¹\82ñ';
205         ERR_MSG = '\93ü\97Í\82µ\82½\83V\83\87\81[\83g\83J\83b\83g\82Í\8aù\82É\8eg\97p\82³\82ê\82Ä\82¢\82Ü\82·';
206         ERR_TITLE = '\83G\83\89\81[';
207 var
208         i: Integer;
209         Item: TListItem;
210         KeyItem: TKeySettingItem;
211     ActiveListView: TListView;
212 begin
213                 if PageControl1.ActivePage.TabIndex <> 0 then
214         ActiveListView := ListView1
215     else
216         ActiveListView := ListView;
217
218         if ActiveListView.Selected = nil then Exit;
219         if HotKey.HotKey = 13 then begin
220                 MsgBox(Handle, ERR_ENT, ERR_TITLE, MB_OK or MB_ICONSTOP);
221                 HotKey.SetFocus;
222                 Exit;
223         end;
224
225         //\8c»\8dÝ\91I\91ð\82³\82ê\82Ä\82¢\82éAction\88È\8aO\82Å\93¯\82\83V\83\87\81[\83g\83J\83b\83g\82ª\82 \82ê\82Î\83G\83\89\81[\82Æ\82·\82é
226         for i := 0 to ActiveListView.Items.Count - 1 do begin
227                 if ActiveListView.Selected = ActiveListView.Items[i] then
228                         Continue;
229                 Item := ActiveListView.Items[i];
230                 if TObject(Item.Data) is TKeySettingItem then begin
231                         KeyItem := TKeySettingItem(Item.Data);
232                         if (HotKey.HotKey <> 0) and (KeyItem.ShortCut = HotKey.HotKey) then begin
233                                 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
234                                 HotKey.SetFocus;
235                                 Exit;
236                         end;
237                 end;
238         end;
239         //\83V\83\87\81[\83g\83J\83b\83g\90Ý\92è
240         if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
241                 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
242                 KeyItem.ShortCut := HotKey.HotKey;
243                 ActiveListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
244         end;
245 end;
246
247 procedure TKeySettingForm.OkBottonClick(Sender: TObject);
248 var
249         i: Integer;
250         Item: TListItem;
251         KeyItem: TKeySettingItem;
252 begin
253
254         GikoSys.Setting.GestureEnabled := GestureCheckBox.Checked;
255         GikoSys.Setting.Gestures.ClearGesture;
256         for i := 0 to ListView.Items.Count - 1 do begin
257                 Item := ListView.Items[i];
258                 if TObject(Item.Data) is TKeySettingItem then begin
259                         KeyItem := TKeySettingItem(Item.Data);
260                         KeyItem.Action.ShortCut := KeyItem.ShortCut;
261                         GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
262                 end;
263         end;
264         for i := 0 to ListView1.Items.Count - 1 do begin
265                 Item := ListView1.Items[i];
266                 if TObject(Item.Data) is TKeySettingItem then begin
267                         KeyItem := TKeySettingItem(Item.Data);
268                         KeyItem.Action.ShortCut := KeyItem.ShortCut;
269                         GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
270                 end;
271         end;
272
273 end;
274
275 procedure TKeySettingForm.ListViewCompare(Sender: TObject; Item1,
276   Item2: TListItem; Data: Integer; var Compare: Integer);
277 begin
278         if Item1.SubItems[0] > Item2.SubItems[0] then
279                 Compare := 1
280         else if Item1.SubItems[0] < Item2.SubItems[0] then
281                 Compare := -1
282         else
283                 Compare := 0;
284 end;
285
286 procedure TKeySettingForm.GestureSetButtonClick(Sender: TObject);
287 const
288         ERR_MSG = '\93ü\97Í\82µ\82½\83W\83F\83X\83`\83\83\81[\82Í\8aù\82É\8eg\97p\82³\82ê\82Ä\82¢\82Ü\82·';
289         ERR_TITLE = '\83G\83\89\81[';
290 var
291         i, j: Integer;
292         Item: TListItem;
293         KeyItem: TKeySettingItem;
294         ActiveListView: TListView;
295         chechList : TListView;
296 begin
297         if PageControl1.ActivePage.TabIndex <> 0 then
298                 ActiveListView := ListView1
299         else
300                 ActiveListView := ListView;
301
302         if ActiveListView.Selected = nil then Exit;
303         if (GetKeyState( VK_SHIFT ) and $80000000) <> 0 then begin
304                 GestureEdit.Text := '';
305                 Item := ActiveListView.Selected;
306                 Item.SubItems[2] := '';
307                 if TObject(Item.Data) is TKeySettingItem then begin
308                         KeyItem := TKeySettingItem(Item.Data);
309                         KeyItem.Gesture := '';
310                 end;
311                 Exit;
312         end;
313
314         // \8c»\8dÝ\91I\91ð\82³\82ê\82Ä\82¢\82éAction\88È\8aO\82Å\93¯\82\83W\83F\83X\83`\83\83\81[\82ª\82 \82ê\82Î\83G\83\89\81[\82Æ\82·\82é
315         chechList := ListView;
316         for j := 0 to 1 do begin
317                 if j <> 0 then begin
318                         chechList := ListView1;
319                 end;
320
321                 for i := 0 to chechList.Items.Count - 1 do begin
322                         if ActiveListView.Selected = chechList.Items[i] then
323                                 Continue;
324                         Item := chechList.Items[i];
325                         if TObject(Item.Data) is TKeySettingItem then begin
326                                 KeyItem := TKeySettingItem(Item.Data);
327                                 if (GestureEdit.Text <> GUESTURE_NOTHING)
328                                 and (KeyItem.Gesture = GestureEdit.Text) then begin
329                                         MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
330                                         HotKey.SetFocus;
331                                         Exit;
332                                 end;
333                         end;
334                 end;
335         end;
336
337         // \83W\83F\83X\83`\83\83\81[\90Ý\92è
338         if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
339                 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
340                 KeyItem.Gesture := GestureEdit.Text;
341                 if GestureEdit.Text = GUESTURE_NOTHING then
342                         ActiveListView.Selected.SubItems[2] := ''
343                 else
344                         ActiveListView.Selected.SubItems[2] := GestureEdit.Text;
345         end;
346 end;
347
348 procedure TKeySettingForm.OnGestureStart(Sender: TObject);
349 begin
350         GestureEdit.Text := '';
351 end;
352
353 procedure TKeySettingForm.OnGestureMove(Sender: TObject);
354 begin
355         GestureEdit.Text := MouseGesture.GetGestureStr;
356 end;
357
358 procedure TKeySettingForm.OnGestureEnd(Sender: TObject);
359 begin
360         GestureEdit.Text := MouseGesture.GetGestureStr;
361     MouseGesture.Clear;
362 end;
363
364 procedure TKeySettingForm.GestureCheckBoxClick(Sender: TObject);
365 begin
366         GestureEdit.Enabled := GestureCheckBox.Checked;
367         GestureSetButton.Enabled := GestureCheckBox.Checked;
368 end;
369
370 procedure TKeySettingForm.GestureEditChange(Sender: TObject);
371 begin
372
373         if GestureEdit.Text = '' then
374                 GestureEdit.Text := GUESTURE_NOTHING;
375
376 end;
377
378 procedure TKeySettingForm.GestureEditKeyDown(Sender: TObject;
379   var Key: Word; Shift: TShiftState);
380 begin
381         if (ssShift in Shift) and (MouseGesture.GetGestureStr = '') then
382         GestureEdit.Text := '';
383 end;
384
385 end.