carbon: use unified multiclick mouse message handling

git-svn-id: trunk@51736 -
This commit is contained in:
ondrej 2016-02-28 06:30:19 +00:00
parent 7b141be77b
commit 95b3e6fd5c
3 changed files with 22 additions and 29 deletions

View File

@ -404,8 +404,10 @@ var SavedMouseUpMsg: TLMMouse;
var PostponedDownMsg: TLMMouse;
var PostponedDown: Boolean;
// Stores last mouse info for multiple clicks
var LastMouse: TLastMouseInfo;
// Stores last mouse pos to call mouse move only when it really has changed
var LastMousePos: TPoint;
var LastMousePos: TPoint; // in client coordinates
{$I carbonprivatecommon.inc}
{$I carbonprivatecontrol.inc}

View File

@ -206,8 +206,6 @@ end;
function CarbonCommon_Track(ANextHandler: EventHandlerCallRef;
AEvent: EventRef;
AWidget: TCarbonWidget): OSStatus; {$IFDEF darwin}mwpascal;{$ENDIF}
const
MSGKIND: array[1..3] of Integer = (LM_LBUTTONUP, LM_RBUTTONUP, LM_MBUTTONUP);
var
ActionUPP, OldActionUPP: ControlActionUPP;
P: TPoint;
@ -266,14 +264,13 @@ begin
FillChar(Msg{%H-}, SizeOf(Msg), 0);
if (MouseButton >= Low(MSGKIND)) and (MouseButton <= High(MSGKIND)) then
Msg.Msg := MSGKIND[MouseButton];
P := AWidget.GetMousePos;
Msg.XPos := P.X;
Msg.YPos := P.Y;
Msg.Keys := GetCarbonMsgKeyState;
case GetCarbonMouseClickCount(AEvent) of
Msg.Msg := CheckMouseButtonDownUp(AWidget.LCLObject, LastMouse,
AWidget.LCLObject.ClientToScreen(P), MouseButton, False);
case LastMouse.ClickCount of
2: Msg.Keys := msg.Keys or MK_DOUBLECLICK;
3: Msg.Keys := msg.Keys or MK_TRIPLECLICK;
4: Msg.Keys := msg.Keys or MK_QUADCLICK;

View File

@ -133,17 +133,8 @@ const
// handler functions
//
procedure HandleMouseDownEvent(var AMsg);
const
// array of clickcount x buttontype
MSGKIND: array[1..4, 1..3] of Integer = (
(LM_LBUTTONDOWN, LM_RBUTTONDOWN, LM_MBUTTONDOWN),
(LM_LBUTTONDBLCLK, LM_RBUTTONDBLCLK, LM_MBUTTONDBLCLK),
(LM_LBUTTONTRIPLECLK, LM_RBUTTONTRIPLECLK, LM_MBUTTONTRIPLECLK),
(LM_LBUTTONQUADCLK, LM_RBUTTONQUADCLK, LM_MBUTTONQUADCLK)
);
var
MouseButton: Integer;
ClickCount: Integer;
MousePoint: TPoint;
Msg: ^TLMMouse;
begin
@ -152,30 +143,28 @@ const
{$ENDIF}
Msg := @AMsg;
ClickCount := GetCarbonMouseClickCount(AEvent);
MouseButton := GetCarbonMouseButton(AEvent);
MousePoint := GetMousePoint;
if (ClickCount < Low(MSGKIND)) or (ClickCount > High(MSGKIND)) then
ClickCount := (ClickCount mod High(MSGKIND))+1;
if (MouseButton < Low(MSGKIND[1])) or (MouseButton > High(MSGKIND[1])) then Exit;
Msg^.Msg := MSGKIND[ClickCount, MouseButton];
Msg^.Msg := CheckMouseButtonDownUp(Widget.LCLObject, LastMouse,
Widget.LCLObject.ClientToScreen(MousePoint), MouseButton, True);
//debugln('HandleMouseDownEvent CliCount=',dbgs(ClickCount),' MouseButton=',dbgs(MouseButton),' Pos=',dbgs(MousePoint));
Msg^.XPos := MousePoint.X;
Msg^.YPos := MousePoint.Y;
Msg^.Keys := GetCarbonMsgKeyState;
case LastMouse.ClickCount of
2: Msg^.Keys := Msg^.Keys or MK_DOUBLECLICK;
3: Msg^.Keys := Msg^.Keys or MK_TRIPLECLICK;
4: Msg^.Keys := Msg^.Keys or MK_QUADCLICK;
end;
CarbonWidgetSet.SetCaptureWidget(HWND(Widget));
if ClickCount > 1 then Postpone := True;
if LastMouse.ClickCount > 1 then Postpone := True;
end;
procedure HandleMouseUpEvent(var AMsg);
const
MSGKIND: array[1..3] of Integer = (LM_LBUTTONUP, LM_RBUTTONUP, LM_MBUTTONUP);
var
MouseButton: Integer;
MousePoint: TPoint;
@ -191,13 +180,18 @@ const
MouseButton := GetCarbonMouseButton(AEvent);
MousePoint := GetMousePoint;
if (MouseButton >= Low(MSGKIND)) and (MouseButton <= High(MSGKIND)) then
Msg^.Msg := MSGKIND[MouseButton];
Msg^.Msg := CheckMouseButtonDownUp(Widget.LCLObject, LastMouse,
Widget.LCLObject.ClientToScreen(MousePoint), MouseButton, False);
Msg^.XPos := MousePoint.X;
Msg^.YPos := MousePoint.Y;
Msg^.Keys := GetCarbonMsgKeyState;
case LastMouse.ClickCount of
2: Msg^.Keys := Msg^.Keys or MK_DOUBLECLICK;
3: Msg^.Keys := Msg^.Keys or MK_TRIPLECLICK;
4: Msg^.Keys := Msg^.Keys or MK_QUADCLICK;
end;
CarbonWidgetSet.SetCaptureWidget(0);
end;