OSDN Git Service

・スレタイの特定ワードを非表示にする機能に「©bbspink.com」も追加
[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     CenterForm: TCustomForm;
89
90 begin
91         //for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
92         for i := 0 to GikoDM.GikoFormActionList.ActionCount - 1 do begin
93                 //if GikoForm.ActionList.Actions[i] is TAction then begin
94                 if GikoDM.GikoFormActionList.Actions[i] is TAction then begin
95                         if GikoDM.GikoFormActionList.Actions[i].Tag <> 0 then
96                                 Continue;
97                         ListItem := ListView.Items.Add;
98                         ListItem.Caption := TAction(GikoDM.GikoFormActionList.Actions[i]).Hint;
99                         ListItem.SubItems.Add(TAction(GikoDM.GikoFormActionList.Actions[i]).Category);
100                         ListItem.SubItems.Add(ShortCutToText(TAction(GikoDM.GikoFormActionList.Actions[i]).ShortCut));
101                         ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
102                                 TAction( GikoDM.GikoFormActionList.Actions[i] ) ) );
103                         ListItem.ImageIndex := TAction(GikoDM.GikoFormActionList.Actions[i]).ImageIndex;
104                         KeyItem := TKeySettingItem.Create;
105                         KeyItem.Action := TAction(GikoDM.GikoFormActionList.Actions[i]);
106                         KeyItem.ShortCut := TAction(GikoDM.GikoFormActionList.Actions[i]).ShortCut;
107                         KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
108                                 TAction( GikoDM.GikoFormActionList.Actions[i] ) );
109                         ListItem.Data := KeyItem;
110                 end;
111         end;
112         if ListView.Items.Count > 0 then
113                 ListView.Selected := ListView.Items[0];
114         EditorForm := TEditorForm.Create(Self);
115         try
116                 for i := 0 to EditorForm.ActionList.ActionCount - 1 do begin
117                         if EditorForm.ActionList.Actions[i] is TAction then begin
118                                 if EditorForm.ActionList.Actions[i].Tag <> 0 then
119                                         Continue;
120                                 ListItem := ListView1.Items.Add;
121                                 ListItem.Caption := TAction(EditorForm.ActionList.Actions[i]).Hint;
122                                 ListItem.SubItems.Add(TAction(EditorForm.ActionList.Actions[i]).Category);
123                                 ListItem.SubItems.Add(ShortCutToText(TAction(EditorForm.ActionList.Actions[i]).ShortCut));
124                                 ListItem.ImageIndex := TAction(EditorForm.ActionList.Actions[i]).ImageIndex;
125                                 ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
126                                         TAction( EditorForm.ActionList.Actions[i] ) ) );
127                                 KeyItem := TKeySettingItem.Create;
128                                 KeyItem.Action := TAction(EditorForm.ActionList.Actions[i]);
129                                 KeyItem.ShortCut := TAction(EditorForm.ActionList.Actions[i]).ShortCut;
130                                 KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
131                                         TAction( EditorForm.ActionList.Actions[i] ) );
132                                 ListItem.Data := KeyItem;
133                         end;
134                 end;
135                 ListView1.SmallImages := EditorForm.HotToobarImageList;
136         finally
137
138         end;
139 //      ActionListView.SortType := stText;
140         StatusBar.Height := 21;
141         StatusBar.Width := 21;
142         PageControl1.ActivePageIndex := 0;
143         GestureCheckBox.Checked := GikoSys.Setting.GestureEnabled;
144         GestureCheckBoxClick( Sender );
145
146         MouseGesture.UnHook;
147         MouseGesture.OnGestureStart := OnGestureStart;
148         MouseGesture.OnGestureMove := OnGestureMove;
149         MouseGesture.OnGestureEnd := OnGestureEnd;
150         MouseGesture.SetHook( Handle );
151
152     CenterForm := TCustomForm(Owner);
153     if Assigned(CenterForm) then begin
154         Left := ((CenterForm.Width - Width) div 2) + CenterForm.Left;
155         Top := ((CenterForm.Height - Height) div 2) + CenterForm.Top;
156     end else begin
157         Left := (Screen.Width - Width) div 2;
158         Top := (Screen.Height - Height) div 2;
159     end;
160 end;
161
162 procedure TKeySettingForm.FormDestroy(Sender: TObject);
163 var
164         i: Integer;
165 begin
166         for i := 0 to ListView.Items.Count - 1 do begin
167                 if TObject(ListView.Items[i].Data) is TKeySettingItem then
168                         TKeySettingItem(ListView.Items[i].Data).Free;
169         end;
170         for i := 0 to ListView1.Items.Count - 1 do begin
171                 if TObject(ListView1.Items[i].Data) is TKeySettingItem then
172                         TKeySettingItem(ListView1.Items[i].Data).Free;
173         end;
174          EditorForm.Release;
175 end;
176
177 procedure TKeySettingForm.ListViewSelectItem(Sender: TObject;
178   Item: TListItem; Selected: Boolean);
179 var
180         KeyItem: TKeySettingItem;
181 begin
182         if not Selected then Exit;
183
184         if TObject(Item.Data) is TKeySettingItem then begin
185                 KeyItem := TKeySettingItem(Item.Data);
186                 HotKey.HotKey := KeyItem.ShortCut;
187                 GestureEdit.Text := KeyItem.Gesture;
188         end;
189 end;
190
191 procedure TKeySettingForm.HotKeyEnter(Sender: TObject);
192 begin
193         OkBotton.Default := False;
194         CancelBotton.Cancel := False;
195 end;
196
197 procedure TKeySettingForm.HotKeyExit(Sender: TObject);
198 begin
199         OkBotton.Default := True;
200         CancelBotton.Cancel := True;
201 end;
202
203 procedure TKeySettingForm.FormKeyDown(Sender: TObject; var Key: Word;
204   Shift: TShiftState);
205 begin
206         if Key in [8, 27, 32, 46] then begin
207                 HotKey.HotKey := ShortCut(Key, Shift);
208                 Key := 0;
209         end;
210 end;
211
212 procedure TKeySettingForm.SetButtonClick(Sender: TObject);
213 const
214         ERR_ENT = 'Enter\83L\81[\82Í\83V\83\87\81[\83g\83J\83b\83g\82Æ\82µ\82Ä\8eg\97p\82Å\82«\82Ü\82¹\82ñ';
215         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·';
216         ERR_TITLE = '\83G\83\89\81[';
217 var
218         i: Integer;
219         Item: TListItem;
220         KeyItem: TKeySettingItem;
221     ActiveListView: TListView;
222 begin
223                 if PageControl1.ActivePage.TabIndex <> 0 then
224         ActiveListView := ListView1
225     else
226         ActiveListView := ListView;
227
228         if ActiveListView.Selected = nil then Exit;
229         if HotKey.HotKey = 13 then begin
230                 MsgBox(Handle, ERR_ENT, ERR_TITLE, MB_OK or MB_ICONSTOP);
231                 HotKey.SetFocus;
232                 Exit;
233         end;
234
235         //\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é
236         for i := 0 to ActiveListView.Items.Count - 1 do begin
237                 if ActiveListView.Selected = ActiveListView.Items[i] then
238                         Continue;
239                 Item := ActiveListView.Items[i];
240                 if TObject(Item.Data) is TKeySettingItem then begin
241                         KeyItem := TKeySettingItem(Item.Data);
242                         if (HotKey.HotKey <> 0) and (KeyItem.ShortCut = HotKey.HotKey) then begin
243                                 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
244                                 HotKey.SetFocus;
245                                 Exit;
246                         end;
247                 end;
248         end;
249         //\83V\83\87\81[\83g\83J\83b\83g\90Ý\92è
250         if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
251                 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
252                 KeyItem.ShortCut := HotKey.HotKey;
253                 ActiveListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
254         end;
255 end;
256
257 procedure TKeySettingForm.OkBottonClick(Sender: TObject);
258 var
259         i: Integer;
260         Item: TListItem;
261         KeyItem: TKeySettingItem;
262 begin
263
264         GikoSys.Setting.GestureEnabled := GestureCheckBox.Checked;
265         GikoSys.Setting.Gestures.ClearGesture;
266         for i := 0 to ListView.Items.Count - 1 do begin
267                 Item := ListView.Items[i];
268                 if TObject(Item.Data) is TKeySettingItem then begin
269                         KeyItem := TKeySettingItem(Item.Data);
270                         KeyItem.Action.ShortCut := KeyItem.ShortCut;
271                         GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
272                 end;
273         end;
274         for i := 0 to ListView1.Items.Count - 1 do begin
275                 Item := ListView1.Items[i];
276                 if TObject(Item.Data) is TKeySettingItem then begin
277                         KeyItem := TKeySettingItem(Item.Data);
278                         KeyItem.Action.ShortCut := KeyItem.ShortCut;
279                         GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
280                 end;
281         end;
282
283 end;
284
285 procedure TKeySettingForm.ListViewCompare(Sender: TObject; Item1,
286   Item2: TListItem; Data: Integer; var Compare: Integer);
287 begin
288         if Item1.SubItems[0] > Item2.SubItems[0] then
289                 Compare := 1
290         else if Item1.SubItems[0] < Item2.SubItems[0] then
291                 Compare := -1
292         else
293                 Compare := 0;
294 end;
295
296 procedure TKeySettingForm.GestureSetButtonClick(Sender: TObject);
297 const
298         ERR_MSG = '\93ü\97Í\82µ\82½\83W\83F\83X\83`\83\83\81[\82Í\8aù\82É\8eg\97p\82³\82ê\82Ä\82¢\82Ü\82·';
299         ERR_TITLE = '\83G\83\89\81[';
300 var
301         i, j: Integer;
302         Item: TListItem;
303         KeyItem: TKeySettingItem;
304         ActiveListView: TListView;
305         chechList : TListView;
306 begin
307         if PageControl1.ActivePage.TabIndex <> 0 then
308                 ActiveListView := ListView1
309         else
310                 ActiveListView := ListView;
311
312         if ActiveListView.Selected = nil then Exit;
313         if (GetKeyState( VK_SHIFT ) and $80000000) <> 0 then begin
314                 GestureEdit.Text := '';
315                 Item := ActiveListView.Selected;
316                 Item.SubItems[2] := '';
317                 if TObject(Item.Data) is TKeySettingItem then begin
318                         KeyItem := TKeySettingItem(Item.Data);
319                         KeyItem.Gesture := '';
320                 end;
321                 Exit;
322         end;
323
324         // \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é
325         chechList := ListView;
326         for j := 0 to 1 do begin
327                 if j <> 0 then begin
328                         chechList := ListView1;
329                 end;
330
331                 for i := 0 to chechList.Items.Count - 1 do begin
332                         if ActiveListView.Selected = chechList.Items[i] then
333                                 Continue;
334                         Item := chechList.Items[i];
335                         if TObject(Item.Data) is TKeySettingItem then begin
336                                 KeyItem := TKeySettingItem(Item.Data);
337                                 if (GestureEdit.Text <> GUESTURE_NOTHING)
338                                 and (KeyItem.Gesture = GestureEdit.Text) then begin
339                                         MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
340                                         HotKey.SetFocus;
341                                         Exit;
342                                 end;
343                         end;
344                 end;
345         end;
346
347         // \83W\83F\83X\83`\83\83\81[\90Ý\92è
348         if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
349                 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
350                 KeyItem.Gesture := GestureEdit.Text;
351                 if GestureEdit.Text = GUESTURE_NOTHING then
352                         ActiveListView.Selected.SubItems[2] := ''
353                 else
354                         ActiveListView.Selected.SubItems[2] := GestureEdit.Text;
355         end;
356 end;
357
358 procedure TKeySettingForm.OnGestureStart(Sender: TObject);
359 begin
360         GestureEdit.Text := '';
361 end;
362
363 procedure TKeySettingForm.OnGestureMove(Sender: TObject);
364 begin
365         GestureEdit.Text := MouseGesture.GetGestureStr;
366 end;
367
368 procedure TKeySettingForm.OnGestureEnd(Sender: TObject);
369 begin
370         GestureEdit.Text := MouseGesture.GetGestureStr;
371     MouseGesture.Clear;
372 end;
373
374 procedure TKeySettingForm.GestureCheckBoxClick(Sender: TObject);
375 begin
376         GestureEdit.Enabled := GestureCheckBox.Checked;
377         GestureSetButton.Enabled := GestureCheckBox.Checked;
378 end;
379
380 procedure TKeySettingForm.GestureEditChange(Sender: TObject);
381 begin
382
383         if GestureEdit.Text = '' then
384                 GestureEdit.Text := GUESTURE_NOTHING;
385
386 end;
387
388 procedure TKeySettingForm.GestureEditKeyDown(Sender: TObject;
389   var Key: Word; Shift: TShiftState);
390 begin
391         if (ssShift in Shift) and (MouseGesture.GetGestureStr = '') then
392         GestureEdit.Text := '';
393 end;
394
395 end.