Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/KeySetting.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Sat Dec 10 11:01:53 2005 UTC (18 years, 4 months ago) by h677
Branch: MAIN
CVS Tags: v1_51_1_639, v1_51_0_626, v1_51_0_634, v1_51_0_635, v1_51_0_636, v1_51_0_637, v1_51_0_632, v1_51_0_633, v1_51_0_638, v1_51_0_630, v1_51_0_631, v1_51_0_628, root-of-Bb51, v1_51_0_629, v1_51_0_627
Branch point for: Bb51
Changes since 1.10: +6 -5 lines
File MIME type: text/x-pascal
リファクタリング中

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 鐃緒申鐃緒申 }
65 public
66 { Public 鐃緒申鐃緒申 }
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 = '鐃緒申鐃緒申';
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 GikoSys.LoadKeySetting(EditorForm.ActionList, GikoSys.GetEditorKeyFileName);
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 end;
152
153 procedure TKeySettingForm.FormDestroy(Sender: TObject);
154 var
155 i: Integer;
156 begin
157 for i := 0 to ListView.Items.Count - 1 do begin
158 if TObject(ListView.Items[i].Data) is TKeySettingItem then
159 TKeySettingItem(ListView.Items[i].Data).Free;
160 end;
161 for i := 0 to ListView1.Items.Count - 1 do begin
162 if TObject(ListView1.Items[i].Data) is TKeySettingItem then
163 TKeySettingItem(ListView1.Items[i].Data).Free;
164 end;
165 EditorForm.Release;
166 end;
167
168 procedure TKeySettingForm.ListViewSelectItem(Sender: TObject;
169 Item: TListItem; Selected: Boolean);
170 var
171 KeyItem: TKeySettingItem;
172 begin
173 if not Selected then Exit;
174
175 if TObject(Item.Data) is TKeySettingItem then begin
176 KeyItem := TKeySettingItem(Item.Data);
177 HotKey.HotKey := KeyItem.ShortCut;
178 GestureEdit.Text := KeyItem.Gesture;
179 end;
180 end;
181
182 procedure TKeySettingForm.HotKeyEnter(Sender: TObject);
183 begin
184 OkBotton.Default := False;
185 CancelBotton.Cancel := False;
186 end;
187
188 procedure TKeySettingForm.HotKeyExit(Sender: TObject);
189 begin
190 OkBotton.Default := True;
191 CancelBotton.Cancel := True;
192 end;
193
194 procedure TKeySettingForm.FormKeyDown(Sender: TObject; var Key: Word;
195 Shift: TShiftState);
196 begin
197 if Key in [8, 27, 32, 46] then begin
198 HotKey.HotKey := ShortCut(Key, Shift);
199 Key := 0;
200 end;
201 end;
202
203 procedure TKeySettingForm.SetButtonClick(Sender: TObject);
204 const
205 ERR_ENT = 'Enter鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申';
206 ERR_MSG = '鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申';
207 ERR_TITLE = '鐃?鐃緒申鐃?';
208 var
209 i: Integer;
210 Item: TListItem;
211 KeyItem: TKeySettingItem;
212 ActiveListView: TListView;
213 begin
214 if PageControl1.ActivePage.TabIndex <> 0 then
215 ActiveListView := ListView1
216 else
217 ActiveListView := ListView;
218
219 if ActiveListView.Selected = nil then Exit;
220 if HotKey.HotKey = 13 then begin
221 MsgBox(Handle, ERR_ENT, ERR_TITLE, MB_OK or MB_ICONSTOP);
222 HotKey.SetFocus;
223 Exit;
224 end;
225
226 //鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申Action鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申
227 for i := 0 to ActiveListView.Items.Count - 1 do begin
228 if ActiveListView.Selected = ActiveListView.Items[i] then
229 Continue;
230 Item := ActiveListView.Items[i];
231 if TObject(Item.Data) is TKeySettingItem then begin
232 KeyItem := TKeySettingItem(Item.Data);
233 if (HotKey.HotKey <> 0) and (KeyItem.ShortCut = HotKey.HotKey) then begin
234 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
235 HotKey.SetFocus;
236 Exit;
237 end;
238 end;
239 end;
240 //鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申
241 if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
242 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
243 KeyItem.ShortCut := HotKey.HotKey;
244 ActiveListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
245 end;
246 end;
247
248 procedure TKeySettingForm.OkBottonClick(Sender: TObject);
249 var
250 i: Integer;
251 Item: TListItem;
252 KeyItem: TKeySettingItem;
253 begin
254
255 GikoSys.Setting.GestureEnabled := GestureCheckBox.Checked;
256 GikoSys.Setting.Gestures.ClearGesture;
257 for i := 0 to ListView.Items.Count - 1 do begin
258 Item := ListView.Items[i];
259 if TObject(Item.Data) is TKeySettingItem then begin
260 KeyItem := TKeySettingItem(Item.Data);
261 KeyItem.Action.ShortCut := KeyItem.ShortCut;
262 GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
263 end;
264 end;
265 for i := 0 to ListView1.Items.Count - 1 do begin
266 Item := ListView1.Items[i];
267 if TObject(Item.Data) is TKeySettingItem then begin
268 KeyItem := TKeySettingItem(Item.Data);
269 KeyItem.Action.ShortCut := KeyItem.ShortCut;
270 GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
271 end;
272 end;
273
274 end;
275
276 procedure TKeySettingForm.ListViewCompare(Sender: TObject; Item1,
277 Item2: TListItem; Data: Integer; var Compare: Integer);
278 begin
279 if Item1.SubItems[0] > Item2.SubItems[0] then
280 Compare := 1
281 else if Item1.SubItems[0] < Item2.SubItems[0] then
282 Compare := -1
283 else
284 Compare := 0;
285 end;
286
287 procedure TKeySettingForm.GestureSetButtonClick(Sender: TObject);
288 const
289 ERR_MSG = '鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申';
290 ERR_TITLE = '鐃?鐃緒申鐃?';
291 var
292 i, j: Integer;
293 Item: TListItem;
294 KeyItem: TKeySettingItem;
295 ActiveListView: TListView;
296 chechList : TListView;
297 begin
298 if PageControl1.ActivePage.TabIndex <> 0 then
299 ActiveListView := ListView1
300 else
301 ActiveListView := ListView;
302
303 if ActiveListView.Selected = nil then Exit;
304 if (GetKeyState( VK_SHIFT ) and $80000000) <> 0 then begin
305 GestureEdit.Text := '';
306 Item := ActiveListView.Selected;
307 Item.SubItems[2] := '';
308 if TObject(Item.Data) is TKeySettingItem then begin
309 KeyItem := TKeySettingItem(Item.Data);
310 KeyItem.Gesture := '';
311 end;
312 Exit;
313 end;
314
315 // 鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申Action鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申
316 chechList := ListView;
317 for j := 0 to 1 do begin
318 if j <> 0 then begin
319 chechList := ListView1;
320 end;
321
322 for i := 0 to chechList.Items.Count - 1 do begin
323 if ActiveListView.Selected = chechList.Items[i] then
324 Continue;
325 Item := chechList.Items[i];
326 if TObject(Item.Data) is TKeySettingItem then begin
327 KeyItem := TKeySettingItem(Item.Data);
328 if (GestureEdit.Text <> GUESTURE_NOTHING)
329 and (KeyItem.Gesture = GestureEdit.Text) then begin
330 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
331 HotKey.SetFocus;
332 Exit;
333 end;
334 end;
335 end;
336 end;
337
338 // 鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申
339 if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
340 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
341 KeyItem.Gesture := GestureEdit.Text;
342 if GestureEdit.Text = GUESTURE_NOTHING then
343 ActiveListView.Selected.SubItems[2] := ''
344 else
345 ActiveListView.Selected.SubItems[2] := GestureEdit.Text;
346 end;
347 end;
348
349 procedure TKeySettingForm.OnGestureStart(Sender: TObject);
350 begin
351 GestureEdit.Text := '';
352 end;
353
354 procedure TKeySettingForm.OnGestureMove(Sender: TObject);
355 begin
356 GestureEdit.Text := MouseGesture.GetGestureStr;
357 end;
358
359 procedure TKeySettingForm.OnGestureEnd(Sender: TObject);
360 begin
361 GestureEdit.Text := MouseGesture.GetGestureStr;
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.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26