Cocoa: Cursor: compatible with system controls that change the cursor by themselves, such as NSTextField

This commit is contained in:
rich2014 2023-06-15 21:41:29 +08:00
parent c3e5af4513
commit 40e7dd7854

View File

@ -20,8 +20,12 @@ type
{ TCursorHelper } { TCursorHelper }
TCursorHelper = class TCursorHelper = class
private
_lastCursor: NSCursor;
private private
procedure DoSetCursorOnActive( data:IntPtr ); procedure DoSetCursorOnActive( data:IntPtr );
public
procedure SetNewCursor( newCursor:TCocoaCursor );
public public
class procedure SetCursorOnActive; class procedure SetCursorOnActive;
class procedure SetCurrentControlCursor; class procedure SetCurrentControlCursor;
@ -368,8 +372,21 @@ begin
SetCurrentControlCursor; SetCurrentControlCursor;
end; end;
procedure TCursorHelper.SetNewCursor( newCursor:TCocoaCursor );
var
currentCursor: NSCursor;
begin
currentCursor:= NSCursor.currentCursor;
if (_lastCursor=nil) or (currentCursor=NSCursor.arrowCursor) or (currentCursor=_lastCursor) then
begin
newCursor.SetCursor;
_lastCursor:= newCursor.Cursor;
end;
end;
class procedure TCursorHelper.SetCursorOnActive; class procedure TCursorHelper.SetCursorOnActive;
begin begin
CursorHelper._lastCursor:= nil;
Application.QueueAsyncCall( @CursorHelper.DoSetCursorOnActive, 0 ); Application.QueueAsyncCall( @CursorHelper.DoSetCursorOnActive, 0 );
end; end;
@ -1843,7 +1860,7 @@ begin
if control<>AWinControl then if control<>AWinControl then
exit; exit;
TCocoaCursor(ACursor).SetCursor; CursorHelper.SetNewCursor( TCocoaCursor(ACursor) );
end; end;
type type