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.4 - (show annotations) (download) (as text)
Mon Oct 11 15:59:17 2004 UTC (19 years, 6 months ago) by yoffy
Branch: MAIN
Changes since 1.3: +21 -7 lines
File MIME type: text/x-pascal
- マウスジェスチャーを使うか設定できるようになった。
- レスエディタもマウスジェスチャに対応。
※todo:メインとレスエディタの両方のジェスチャを混在させると AV が発生するので、
 GikoSys.Setting.Gestures をそれぞれのウィンドウ用に用意する必要がありそう。

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, GikoSystem, GikoUtil,
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 private
61 { Private 鐃緒申鐃緒申 }
62 public
63 { Public 鐃緒申鐃緒申 }
64 EditorForm: TEditorForm;
65 end;
66
67 //var
68 // KeySettingForm: TKeySettingForm;
69
70 implementation
71
72 uses Giko, Gesture;
73
74 {$R *.dfm}
75
76 procedure TKeySettingForm.FormCreate(Sender: TObject);
77 var
78 i: Integer;
79 ListItem: TListItem;
80 KeyItem: TKeySettingItem;
81
82 begin
83 for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
84 if GikoForm.ActionList.Actions[i] is TAction then begin
85 if GikoForm.ActionList.Actions[i].Tag <> 0 then
86 Continue;
87 ListItem := ListView.Items.Add;
88 ListItem.Caption := TAction(GikoForm.ActionList.Actions[i]).Hint;
89 ListItem.SubItems.Add(TAction(GikoForm.ActionList.Actions[i]).Category);
90 ListItem.SubItems.Add(ShortCutToText(TAction(GikoForm.ActionList.Actions[i]).ShortCut));
91 ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
92 TAction( GikoForm.ActionList.Actions[i] ) ) );
93 ListItem.ImageIndex := TAction(GikoForm.ActionList.Actions[i]).ImageIndex;
94 KeyItem := TKeySettingItem.Create;
95 KeyItem.Action := TAction(GikoForm.ActionList.Actions[i]);
96 KeyItem.ShortCut := TAction(GikoForm.ActionList.Actions[i]).ShortCut;
97 KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
98 TAction( GikoForm.ActionList.Actions[i] ) );
99 ListItem.Data := KeyItem;
100 end;
101 end;
102 if ListView.Items.Count > 0 then
103 ListView.Selected := ListView.Items[0];
104 EditorForm := TEditorForm.Create(Self);
105 GikoSys.LoadEditorKeySetting(EditorForm.ActionList);
106 try
107 for i := 0 to EditorForm.ActionList.ActionCount - 1 do begin
108 if EditorForm.ActionList.Actions[i] is TAction then begin
109 if EditorForm.ActionList.Actions[i].Tag <> 0 then
110 Continue;
111 ListItem := ListView1.Items.Add;
112 ListItem.Caption := TAction(EditorForm.ActionList.Actions[i]).Hint;
113 ListItem.SubItems.Add(TAction(EditorForm.ActionList.Actions[i]).Category);
114 ListItem.SubItems.Add(ShortCutToText(TAction(EditorForm.ActionList.Actions[i]).ShortCut));
115 ListItem.ImageIndex := TAction(EditorForm.ActionList.Actions[i]).ImageIndex;
116 ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
117 TAction( GikoForm.ActionList.Actions[i] ) ) );
118 KeyItem := TKeySettingItem.Create;
119 KeyItem.Action := TAction(EditorForm.ActionList.Actions[i]);
120 KeyItem.ShortCut := TAction(EditorForm.ActionList.Actions[i]).ShortCut;
121 KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
122 TAction( GikoForm.ActionList.Actions[i] ) );
123 ListItem.Data := KeyItem;
124 end;
125 end;
126 ListView1.SmallImages := EditorForm.HotToobarImageList;
127 finally
128
129 end;
130 // ActionListView.SortType := stText;
131 StatusBar.Height := 21;
132 StatusBar.Width := 21;
133 PageControl1.ActivePageIndex := 0;
134 GestureCheckBox.Checked := GikoSys.Setting.GestureEnabled;
135 GestureCheckBoxClick( Sender );
136
137 MouseGesture.UnHook;
138 MouseGesture.OnGestureStart := OnGestureStart;
139 MouseGesture.OnGestureMove := OnGestureMove;
140 MouseGesture.OnGestureEnd := OnGestureEnd;
141 MouseGesture.SetHook( Handle );
142 end;
143
144 procedure TKeySettingForm.FormDestroy(Sender: TObject);
145 var
146 i: Integer;
147 begin
148 for i := 0 to ListView.Items.Count - 1 do begin
149 if TObject(ListView.Items[i].Data) is TKeySettingItem then
150 TKeySettingItem(ListView.Items[i].Data).Free;
151 end;
152 for i := 0 to ListView1.Items.Count - 1 do begin
153 if TObject(ListView1.Items[i].Data) is TKeySettingItem then
154 TKeySettingItem(ListView1.Items[i].Data).Free;
155 end;
156 EditorForm.Release;
157 end;
158
159 procedure TKeySettingForm.ListViewSelectItem(Sender: TObject;
160 Item: TListItem; Selected: Boolean);
161 var
162 KeyItem: TKeySettingItem;
163 begin
164 if not Selected then Exit;
165
166 if TObject(Item.Data) is TKeySettingItem then begin
167 KeyItem := TKeySettingItem(Item.Data);
168 HotKey.HotKey := KeyItem.ShortCut;
169 end;
170 end;
171
172 procedure TKeySettingForm.HotKeyEnter(Sender: TObject);
173 begin
174 OkBotton.Default := False;
175 CancelBotton.Cancel := False;
176 end;
177
178 procedure TKeySettingForm.HotKeyExit(Sender: TObject);
179 begin
180 OkBotton.Default := True;
181 CancelBotton.Cancel := True;
182 end;
183
184 procedure TKeySettingForm.FormKeyDown(Sender: TObject; var Key: Word;
185 Shift: TShiftState);
186 begin
187 if Key in [8, 27, 32, 46] then begin
188 HotKey.HotKey := ShortCut(Key, Shift);
189 Key := 0;
190 end;
191 end;
192
193 procedure TKeySettingForm.SetButtonClick(Sender: TObject);
194 const
195 ERR_ENT = 'Enter鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申';
196 ERR_MSG = '鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申';
197 ERR_TITLE = '鐃?鐃緒申鐃?';
198 var
199 i: Integer;
200 Item: TListItem;
201 KeyItem: TKeySettingItem;
202 ActiveListView: TListView;
203 begin
204 if PageControl1.ActivePage.TabIndex <> 0 then
205 ActiveListView := ListView1
206 else
207 ActiveListView := ListView;
208
209 if ActiveListView.Selected = nil then Exit;
210 if HotKey.HotKey = 13 then begin
211 MsgBox(Handle, ERR_ENT, ERR_TITLE, MB_OK or MB_ICONSTOP);
212 HotKey.SetFocus;
213 Exit;
214 end;
215
216 //鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申Action鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申
217 for i := 0 to ActiveListView.Items.Count - 1 do begin
218 if ActiveListView.Selected = ActiveListView.Items[i] then
219 Continue;
220 Item := ActiveListView.Items[i];
221 if TObject(Item.Data) is TKeySettingItem then begin
222 KeyItem := TKeySettingItem(Item.Data);
223 if (HotKey.HotKey <> 0) and (KeyItem.ShortCut = HotKey.HotKey) then begin
224 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
225 HotKey.SetFocus;
226 Exit;
227 end;
228 end;
229 end;
230 //鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申
231 if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
232 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
233 KeyItem.ShortCut := HotKey.HotKey;
234 ActiveListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
235 end;
236 end;
237
238 procedure TKeySettingForm.OkBottonClick(Sender: TObject);
239 var
240 i: Integer;
241 Item: TListItem;
242 KeyItem: TKeySettingItem;
243 begin
244
245 GikoSys.Setting.GestureEnabled := GestureCheckBox.Checked;
246 GikoSys.Setting.Gestures.ClearGesture;
247 for i := 0 to ListView.Items.Count - 1 do begin
248 Item := ListView.Items[i];
249 if TObject(Item.Data) is TKeySettingItem then begin
250 KeyItem := TKeySettingItem(Item.Data);
251 KeyItem.Action.ShortCut := KeyItem.ShortCut;
252 GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
253 end;
254 end;
255 for i := 0 to ListView1.Items.Count - 1 do begin
256 Item := ListView1.Items[i];
257 if TObject(Item.Data) is TKeySettingItem then begin
258 KeyItem := TKeySettingItem(Item.Data);
259 KeyItem.Action.ShortCut := KeyItem.ShortCut;
260 GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
261 end;
262 end;
263
264 end;
265
266 procedure TKeySettingForm.ListViewCompare(Sender: TObject; Item1,
267 Item2: TListItem; Data: Integer; var Compare: Integer);
268 begin
269 if Item1.SubItems[0] > Item2.SubItems[0] then
270 Compare := 1
271 else if Item1.SubItems[0] < Item2.SubItems[0] then
272 Compare := -1
273 else
274 Compare := 0;
275 end;
276
277 procedure TKeySettingForm.GestureSetButtonClick(Sender: TObject);
278 const
279 ERR_MSG = '鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申';
280 ERR_TITLE = '鐃?鐃緒申鐃?';
281 var
282 i: Integer;
283 Item: TListItem;
284 KeyItem: TKeySettingItem;
285 ActiveListView: TListView;
286 begin
287 if PageControl1.ActivePage.TabIndex <> 0 then
288 ActiveListView := ListView1
289 else
290 ActiveListView := ListView;
291
292 if ActiveListView.Selected = nil then Exit;
293 if (GetKeyState( VK_SHIFT ) and $80000000) <> 0 then begin
294 GestureEdit.Text := '';
295 Exit;
296 end;
297
298 // 鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申Action鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申
299 for i := 0 to ActiveListView.Items.Count - 1 do begin
300 if ActiveListView.Selected = ActiveListView.Items[i] then
301 Continue;
302 Item := ActiveListView.Items[i];
303 if TObject(Item.Data) is TKeySettingItem then begin
304 KeyItem := TKeySettingItem(Item.Data);
305 if KeyItem.Gesture = GestureEdit.Text then begin
306 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
307 HotKey.SetFocus;
308 Exit;
309 end;
310 end;
311 end;
312 // 鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申
313 if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
314 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
315 KeyItem.Gesture := GestureEdit.Text;
316 ActiveListView.Selected.SubItems[2] := GestureEdit.Text;
317 end;
318 end;
319
320 procedure TKeySettingForm.OnGestureStart(Sender: TObject);
321 begin
322 GestureEdit.Text := '';
323 end;
324
325 procedure TKeySettingForm.OnGestureMove(Sender: TObject);
326 begin
327 GestureEdit.Text := MouseGesture.GetGestureStr;
328 end;
329
330 procedure TKeySettingForm.OnGestureEnd(Sender: TObject);
331 begin
332 GestureEdit.Text := MouseGesture.GetGestureStr;
333 end;
334
335 procedure TKeySettingForm.GestureCheckBoxClick(Sender: TObject);
336 begin
337 GestureEdit.Enabled := GestureCheckBox.Checked;
338 GestureSetButton.Enabled := GestureCheckBox.Checked;
339 end;
340
341 end.

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