Cocoa: Cursor: completely refactored on LCL cursor infrastructure

This commit is contained in:
rich2014 2023-06-10 22:38:34 +08:00
parent d939016d4e
commit 7111681225
3 changed files with 19 additions and 27 deletions

View File

@ -311,9 +311,7 @@ type
constructor CreateFromBitmap(const ABitmap: TCocoaBitmap; const hotSpot: NSPoint);
constructor CreateFromCustomCursor(const ACursor: NSCursor);
destructor Destroy; override;
function Install: TCocoaCursor;
procedure SetCursor;
class procedure SetDefaultCursor;
property Cursor: NSCursor read FCursor;
property Standard: Boolean read FStandard;
end;
@ -1233,25 +1231,11 @@ begin
inherited;
end;
function TCocoaCursor.Install: TCocoaCursor;
begin
FCursor.push;
// also request form cursors invalidation
CocoaWidgetSet.NSApp.keyWindow.resetCursorRects;
Result := nil;
end;
procedure TCocoaCursor.SetCursor;
begin
FCursor.set_;
FCursor.set_;
end;
class procedure TCocoaCursor.SetDefaultCursor;
begin
NSCursor.arrowCursor.set_;
end;
{ TCocoaContext }
function TCocoaContext.CGContext: CGContextRef;

View File

@ -2519,8 +2519,9 @@ end;
function TCocoaWidgetSet.SetCursor(ACursor: HCURSOR): HCURSOR;
begin
if ACursor = 0 then Result := 0 else
Result := HCURSOR(TCocoaCursor(ACursor).Install);
if ACursor = 0 then ACursor:= Screen.Cursors[crDefault];
TCocoaCursor(ACursor).SetCursor;
Result := 0;
end;
function TCocoaWidgetSet.SetCursorPos(X, Y: Integer): Boolean;

View File

@ -1798,17 +1798,24 @@ end;
class procedure TCocoaWSWinControl.SetCursor(const AWinControl: TWinControl;
const ACursor: HCursor);
var
control: TControl;
begin
//debugln('SetCursor '+AWinControl.name+' '+dbgs(ACursor));
if CocoaWidgetSet.CurrentCursor<>ACursor then
begin
CocoaWidgetSet.CurrentCursor:= ACursor;
if ACursor<>0 then
TCocoaCursor(ACursor).SetCursor
else
TCocoaCursor.SetDefaultCursor;
end;
// screen cursor has higher priority than control cursor.
if Screen.Cursor<>crDefault
then exit;
// control cursor only need be set when mouse in AWinControl.
// suppose there is a Button, which is to set a Cursor of a ListBox.
// without the code here, it will be set to the Cursor of the ListBox
// after clicking the Button.
control:= Application.GetControlAtMouse;
if control<>AWinControl then
exit;
TCocoaCursor(ACursor).SetCursor;
end;
type