6 Windows, Messages, SysUtils, Classes, Controls, StrUtils, IniFiles,
10 TGestureModel = class(TObject)
12 FGestureList: TStringList;
14 function CheckGestureStr(Gesture: string): Boolean;
15 function GetActionItem(ActionList: TActionList; ActionStr: string): TAction;
16 function Get(Index: Integer): string;
17 function GetObject(Index: Integer): TObject;
18 function GetCount: Integer;
21 destructor Destroy; override;
22 procedure AddGesture(Gesture: string; Action: TAction);
23 procedure DeleteGesture(Gesture: string);
24 procedure ClearGesture;
25 function GetGestureAction(Gesture: string): TAction;
26 function GetActionGesture( action : TAction ) : string;
27 property Margin: Integer read FMargin write FMargin;
28 procedure LoadGesture(FileName: string; ActionList: TActionList);
29 procedure SaveGesture(FileName: string);
31 property Items[Index: Integer]: string read Get; default;
32 property Objects[Index: Integer]: TObject read GetObject;
33 property Count: Integer read GetCount;
38 constructor TGestureModel.Create;
41 FGestureList := TStringList.Create;
44 destructor TGestureModel.Destroy;
46 FreeAndNil(FGestureList);
50 //
\8ew
\92è
\82³
\82ê
\82½index
\82Ì
\83W
\83F
\83X
\83`
\83\83\81[
\95¶
\8e\9a\97ñ
\82ð
\95Ô
\82·
51 function TGestureModel.Get(Index: Integer): string;
53 if (Index < 0) or (Index >= FGestureList.Count) then
54 raise Exception.Create('ERR');
55 Result := FGestureList[Index];
58 //
\8ew
\92è
\82³
\82ê
\82½index
\82Ì
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\95Ô
\82·
59 function TGestureModel.GetObject(Index: Integer): TObject;
61 if (Index < 0) or (Index >= FGestureList.Count) then
62 raise Exception.Create('ERR');
63 Result := FGestureList.Objects[Index];
66 //
\83W
\83F
\83X
\83`
\83\83\81[
\82Ì
\95¶
\8e\9a\97ñ
\82É
\95Ï
\82È
\95¶
\8e\9a\82ª
\93ü
\82Á
\82Ä
\82È
\82¢
\82©
\83`
\83F
\83b
\83N
\82ð
\8ds
\82¤
67 function TGestureModel.CheckGestureStr(Gesture: string): Boolean;
69 G_STR: array[0..3] of string = ('
\81ª', '
\81©', '
\81«', '
\81¨');
76 if Length(Gesture) = 0 then
78 for i := 0 to (Length(Gesture) div 2) - 1 do begin
80 for j := 0 to Length(G_STR) - 1 do begin
81 if MidStr(Gesture, i + 1, 1) = G_STR[j] then begin
92 //
\83W
\83F
\83X
\83`
\83\83\81[
\83\8a\83X
\83g
\82Ì
\83T
\83C
\83Y
\82ð
\95Ô
\82·
93 function TGestureModel.GetCount: Integer;
95 Result := FGestureList.Count;
98 //
\83W
\83F
\83X
\83`
\83\83\81[
\82Æ
\81A
\82»
\82ê
\82É
\8c\8b\82Ñ
\82Â
\82
\83A
\83N
\83V
\83\87\83\93\82ð
\83\8a\83X
\83g
\82É
\93o
\98^
\82·
\82é
99 procedure TGestureModel.AddGesture(Gesture: string; Action: TAction);
101 if (not CheckGestureStr(Gesture)) or (Action = nil) then
103 DeleteGesture(Gesture);
104 FGestureList.AddObject(Gesture, Action);
107 //
\8ew
\92è
\82³
\82ê
\82½
\83W
\83F
\83X
\83`
\83\83\81[
\82ð
\8dí
\8f\9c
108 procedure TGestureModel.DeleteGesture(Gesture: string);
112 idx := FGestureList.IndexOf(Gesture);
114 FGestureList.Delete(idx);
117 //
\83W
\83F
\83X
\83`
\83\83\81[
\83\8a\83X
\83g
\82ð
\83N
\83\8a\83A
118 procedure TGestureModel.ClearGesture;
123 //
\83W
\83F
\83X
\83`
\83\83\81[
\95¶
\8e\9a\97ñ
\82©
\82ç
\8aY
\93\96\82·
\82é
\83A
\83N
\83V
\83\87\83\93\82ð
\95Ô
\82·
124 function TGestureModel.GetGestureAction(Gesture: string): TAction;
129 idx := FGestureList.IndexOf(Gesture);
131 if FGestureList.Objects[idx] is TAction then
132 Result := TAction(FGestureList.Objects[idx]);
135 //
\83A
\83N
\83V
\83\87\83\93\82©
\82ç
\8aY
\93\96\82·
\82é
\83W
\83F
\83X
\83`
\83\83\81[
\95¶
\8e\9a\97ñ
\82ð
\95Ô
\82·
136 function TGestureModel.GetActionGesture( action : TAction ) : string;
141 for i := 0 to FGestureList.Count - 1 do begin
142 if FGestureList.Objects[ i ] = action then begin
143 Result := FGestureList[ i ];
149 //ini
\82©
\82ç
\83W
\83F
\83X
\83`
\83\83\81[
\88ê
\97\97\82ð
\93Ç
\82Ý
\8d\9e\82Þ
150 procedure TGestureModel.LoadGesture(FileName: string; ActionList: TActionList);
159 ini := TMemIniFile.Create(FileName);
162 while (True) do begin
163 key := 'Gesture' + IntToStr(i);
164 GestureStr := ini.ReadString('MouseGesture', key, '');
165 key := 'Action' + IntToStr(i);
166 ActionStr := ini.ReadString('MouseGesture', key, '');
167 if (GestureStr = '') or (ActionStr = '') then
169 Action := GetActionItem(ActionList, ActionStr);
170 if Action <> nil then begin
171 AddGesture(GestureStr, Action);
175 FMargin := ini.ReadInteger('MouseGesture', 'Margin', 15);
181 //
\83W
\83F
\83X
\83`
\83\83\81[
\88ê
\97\97\82ðini
\82É
\8f\91\82«
\8d\9e\82Þ
182 procedure TGestureModel.SaveGesture(FileName: string);
188 ini := TMemIniFile.Create(FileName);
190 ini.EraseSection('MouseGesture');
191 for i := 0 to FGestureList.Count - 1 do begin
192 if CheckGestureStr(FGestureList[i]) and (FGestureList.Objects[i] is TAction) then begin
193 key := 'Gesture' + IntToStr(i);
194 ini.WriteString('MouseGesture', key, FGestureList[i]);
195 key := 'Action' + IntToStr(i);
196 ini.WriteString('MouseGesture', key, TAction(FGestureList.Objects[i]).Name);
199 ini.WriteInteger('MouseGesture', 'Margin', FMargin);
206 //
\83A
\83N
\83V
\83\87\83\93\95¶
\8e\9a\97ñ
\82©
\82ç
\83A
\83N
\83V
\83\87\83\93\82ð
\95Ô
\82·
207 function TGestureModel.GetActionItem(ActionList: TActionList; ActionStr: string): TAction;
212 for i := 0 to ActionList.ActionCount - 1 do begin
213 if ActionList.Actions[i].Name = ActionStr then begin
214 if ActionList.Actions[i] is TAction then begin
215 Result := TAction(ActionList.Actions[i]);