OSDN Git Service

TWebBrowserの参照カウントが正しくなるように修正
[gikonavigoeson/gikonavi.git] / Gesture.pas
index b664681..75e7a52 100644 (file)
@@ -9,7 +9,7 @@ uses
 type
        TMouseGesture = class(TObject)
        private
-               FHook: Integer;
+               FHook: Cardinal;
                FHandle: THandle;
                FGestureItemList: TStringList;
                FBeginGesture: Boolean;
@@ -25,7 +25,6 @@ type
                function CheckAction(Message: Integer; x, y: Integer): Boolean;
                procedure AddAction(sx, sy: Integer);
                function AddGesture(Item: string): Integer;
-               procedure ClearGesture;
                function Get(Index: integer): string;
                procedure Put(Index: integer; Item: string);
        public
@@ -37,6 +36,7 @@ type
                property GestureCount: Integer read GetGestureCount;
                property Margin: Integer read FMargin write FMargin;
                function GetGestureStr: string;
+               procedure Clear;
                property OnGestureStart: TNotifyEvent read FOnGestureStart write FOnGestureStart;
                property OnGestureMove: TNotifyEvent read FOnGestureMove write FOnGestureMove;
                property OnGestureEnd: TNotifyEvent read FOnGestureEnd write FOnGestureEnd;
@@ -49,6 +49,9 @@ var
 
 implementation
 
+uses
+       GikoSystem;
+
 constructor TMouseGesture.Create;
 begin
        inherited;
@@ -62,7 +65,7 @@ end;
 destructor TMouseGesture.Destroy;
 begin
        UnHook;
-       ClearGesture;
+       Clear;
        FGestureItemList.Free;
        inherited;
 end;
@@ -105,47 +108,64 @@ function TMouseGesture.CheckAction(Message: Integer; x, y: Integer): Boolean;
 var
        dp: TPoint;
        sp: TPoint;
+       hwnd: THandle;
 begin
        Result := False;
        case Message of
                WM_MOUSEMOVE: begin
                        if FBeginGesture then begin
-                               SetCapture(FHandle);
+                               //\8d¡\83}\83E\83X\82ð\83L\83\83\83v\83`\83\83\81[\82µ\82Ä\82¢\82é\82Ì\82ð\93¾\82é
+                               hwnd := GetCapture;
+                               //\83}\83E\83X\83W\83F\83X\83`\83\83\81[\82Ì\91Î\8fÛ\82Æ\88á\82¤\82Æ\82«\82Í\81A\8aJ\95ú\82·\82é
+                               if (hwnd <> 0) and (hwnd <> FHandle) then begin
+                                       ReleaseCapture;
+                    SetCapture(FHandle);
+                               end;
                                dp := Point(x - FLastPoint.X, y - FLastPoint.Y);
                                sp := Point(Sign(dp.X), Sign(dp.Y));
-                               if Sqrt(dp.X * dp.X + dp.Y * dp.Y) > FMargin then begin
+                               if (dp.X * dp.X + dp.Y * dp.Y) > (FMargin * FMargin) then begin
                                        dp := Point(Abs(dp.X), Abs(dp.Y));
-                                       if dp.X > dp.Y / 3 then
+                                       if dp.X > dp.Y div 3 then
                                                sp.Y := 0;
-                                       if dp.Y > dp.X / 3 then
+                                       if dp.Y > dp.X div 3 then
                                                sp.X := 0;
                                        AddAction(sp.X, sp.Y);
                                        FLastTime := GetTickCount;
                                        FLastPoint := Point(x, y);
                                end;
-                               Result := True;
-                       end;
+                Result := True;
+               end;
                end;
                WM_RBUTTONDOWN: begin
-                       if not FCancelMode then begin
+                       if (not FCancelMode)  then begin
+                if ( GikoSys.Setting.GestureIgnoreContext ) then begin
+                               //\8d¡\83}\83E\83X\82ð\83L\83\83\83v\83`\83\83\81[\82µ\82Ä\82¢\82é\82Ì\82ð\93¾\82é
+                               hwnd := GetCapture;
+                               //\83}\83E\83X\83W\83F\83X\83`\83\83\81[\82Ì\91Î\8fÛ\82Æ\88á\82¤\82Æ\82«\82Í\81A\8aJ\95ú\82·\82é
+                               if (hwnd <> 0) and (hwnd <> FHandle) then begin
+                        Exit;
+                    end;
+                end;
                                FBeginGesture := True;
                                FLastTime := 0;
                                FLastPoint := Point(x, y);
                                FStartPoint := Point(x, y);
-                               CheckAction := True;
+                               Result := True;
                                SetCapture(FHandle);
                        end;
                end;
                WM_RBUTTONUP: begin
                        if FCancelMode then
                                FCancelMode := False
-                       else begin
+                       else if (FBeginGesture) then begin
                                FBeginGesture := False;
                                ReleaseCapture;
                                if FGestureItemList.Count <> 0 then begin
-                                       if Assigned(FOnGestureEnd) then
+                                       if Assigned(FOnGestureEnd) then begin
                                                FOnGestureEnd(Self);
-                                       ClearGesture;
+                    end else begin
+                        Clear;
+                    end;
                                end else begin
                                        FCancelMode := True;
                                        //\83W\83F\83X\83`\83\83\81[\82\82á\82È\82©\82Á\82½\8fê\8d\87\81A\83}\83E\83XDOWN,UP\82ð\83G\83~\83\85\83\8c\81[\83g
@@ -221,7 +241,7 @@ begin
 end;
 
 //\83W\83F\83X\83`\83\83\81[\82ð\83N\83\8a\83A\82·\82é
-procedure TMouseGesture.ClearGesture;
+procedure TMouseGesture.Clear;
 begin
        FGestureItemList.Clear;
 end;