| 9 |
type |
type |
| 10 |
TMouseGesture = class(TObject) |
TMouseGesture = class(TObject) |
| 11 |
private |
private |
| 12 |
FHook: Integer; |
FHook: Cardinal; |
| 13 |
FHandle: THandle; |
FHandle: THandle; |
| 14 |
FGestureItemList: TStringList; |
FGestureItemList: TStringList; |
| 15 |
FBeginGesture: Boolean; |
FBeginGesture: Boolean; |
| 25 |
function CheckAction(Message: Integer; x, y: Integer): Boolean; |
function CheckAction(Message: Integer; x, y: Integer): Boolean; |
| 26 |
procedure AddAction(sx, sy: Integer); |
procedure AddAction(sx, sy: Integer); |
| 27 |
function AddGesture(Item: string): Integer; |
function AddGesture(Item: string): Integer; |
|
procedure ClearGesture; |
|
| 28 |
function Get(Index: integer): string; |
function Get(Index: integer): string; |
| 29 |
procedure Put(Index: integer; Item: string); |
procedure Put(Index: integer; Item: string); |
| 30 |
public |
public |
| 36 |
property GestureCount: Integer read GetGestureCount; |
property GestureCount: Integer read GetGestureCount; |
| 37 |
property Margin: Integer read FMargin write FMargin; |
property Margin: Integer read FMargin write FMargin; |
| 38 |
function GetGestureStr: string; |
function GetGestureStr: string; |
| 39 |
|
procedure Clear; |
| 40 |
property OnGestureStart: TNotifyEvent read FOnGestureStart write FOnGestureStart; |
property OnGestureStart: TNotifyEvent read FOnGestureStart write FOnGestureStart; |
| 41 |
property OnGestureMove: TNotifyEvent read FOnGestureMove write FOnGestureMove; |
property OnGestureMove: TNotifyEvent read FOnGestureMove write FOnGestureMove; |
| 42 |
property OnGestureEnd: TNotifyEvent read FOnGestureEnd write FOnGestureEnd; |
property OnGestureEnd: TNotifyEvent read FOnGestureEnd write FOnGestureEnd; |
| 49 |
|
|
| 50 |
implementation |
implementation |
| 51 |
|
|
| 52 |
|
uses |
| 53 |
|
GikoSystem; |
| 54 |
|
|
| 55 |
constructor TMouseGesture.Create; |
constructor TMouseGesture.Create; |
| 56 |
begin |
begin |
| 57 |
inherited; |
inherited; |
| 65 |
destructor TMouseGesture.Destroy; |
destructor TMouseGesture.Destroy; |
| 66 |
begin |
begin |
| 67 |
UnHook; |
UnHook; |
| 68 |
ClearGesture; |
Clear; |
| 69 |
FGestureItemList.Free; |
FGestureItemList.Free; |
| 70 |
inherited; |
inherited; |
| 71 |
end; |
end; |
| 119 |
//マウスジェスチャーの対象と違うときは、開放する |
//マウスジェスチャーの対象と違うときは、開放する |
| 120 |
if (hwnd <> 0) and (hwnd <> FHandle) then begin |
if (hwnd <> 0) and (hwnd <> FHandle) then begin |
| 121 |
ReleaseCapture; |
ReleaseCapture; |
| 122 |
|
SetCapture(FHandle); |
| 123 |
end; |
end; |
|
SetCapture(FHandle); |
|
| 124 |
dp := Point(x - FLastPoint.X, y - FLastPoint.Y); |
dp := Point(x - FLastPoint.X, y - FLastPoint.Y); |
| 125 |
sp := Point(Sign(dp.X), Sign(dp.Y)); |
sp := Point(Sign(dp.X), Sign(dp.Y)); |
| 126 |
if (dp.X * dp.X + dp.Y * dp.Y) > (FMargin * FMargin) then begin |
if (dp.X * dp.X + dp.Y * dp.Y) > (FMargin * FMargin) then begin |
| 133 |
FLastTime := GetTickCount; |
FLastTime := GetTickCount; |
| 134 |
FLastPoint := Point(x, y); |
FLastPoint := Point(x, y); |
| 135 |
end; |
end; |
| 136 |
//マウスを再設定 |
Result := True; |
| 137 |
if (hwnd <> 0) and (hwnd <> FHandle) then |
end; |
|
SetCapture(hwnd); |
|
|
|
|
|
Result := True; |
|
|
end; |
|
| 138 |
end; |
end; |
| 139 |
WM_RBUTTONDOWN: begin |
WM_RBUTTONDOWN: begin |
| 140 |
if not FCancelMode then begin |
if (not FCancelMode) then begin |
| 141 |
|
if ( GikoSys.Setting.GestureIgnoreContext ) then begin |
| 142 |
|
//今マウスをキャプチャーしているのを得る |
| 143 |
|
hwnd := GetCapture; |
| 144 |
|
//マウスジェスチャーの対象と違うときは、開放する |
| 145 |
|
if (hwnd <> 0) and (hwnd <> FHandle) then begin |
| 146 |
|
Exit; |
| 147 |
|
end; |
| 148 |
|
end; |
| 149 |
FBeginGesture := True; |
FBeginGesture := True; |
| 150 |
FLastTime := 0; |
FLastTime := 0; |
| 151 |
FLastPoint := Point(x, y); |
FLastPoint := Point(x, y); |
| 152 |
FStartPoint := Point(x, y); |
FStartPoint := Point(x, y); |
| 153 |
CheckAction := True; |
Result := True; |
| 154 |
SetCapture(FHandle); |
SetCapture(FHandle); |
| 155 |
end; |
end; |
| 156 |
end; |
end; |
| 157 |
WM_RBUTTONUP: begin |
WM_RBUTTONUP: begin |
| 158 |
if FCancelMode then |
if FCancelMode then |
| 159 |
FCancelMode := False |
FCancelMode := False |
| 160 |
else begin |
else if (FBeginGesture) then begin |
| 161 |
FBeginGesture := False; |
FBeginGesture := False; |
| 162 |
ReleaseCapture; |
ReleaseCapture; |
| 163 |
if FGestureItemList.Count <> 0 then begin |
if FGestureItemList.Count <> 0 then begin |
| 164 |
if Assigned(FOnGestureEnd) then |
if Assigned(FOnGestureEnd) then begin |
| 165 |
FOnGestureEnd(Self); |
FOnGestureEnd(Self); |
| 166 |
ClearGesture; |
end else begin |
| 167 |
|
Clear; |
| 168 |
|
end; |
| 169 |
end else begin |
end else begin |
| 170 |
FCancelMode := True; |
FCancelMode := True; |
| 171 |
//ジェスチャーじゃなかった場合、マウスDOWN,UPをエミュレート |
//ジェスチャーじゃなかった場合、マウスDOWN,UPをエミュレート |
| 241 |
end; |
end; |
| 242 |
|
|
| 243 |
//ジェスチャーをクリアする |
//ジェスチャーをクリアする |
| 244 |
procedure TMouseGesture.ClearGesture; |
procedure TMouseGesture.Clear; |
| 245 |
begin |
begin |
| 246 |
FGestureItemList.Clear; |
FGestureItemList.Clear; |
| 247 |
end; |
end; |