Cocoa: Cursor: Improve support for Window/Application switching

This commit is contained in:
rich2014 2023-06-10 23:05:36 +08:00
parent da41c019a6
commit cdbab01c2d
2 changed files with 32 additions and 2 deletions

View File

@ -27,7 +27,7 @@ uses
Types, Classes, SysUtils,
CGGeometry,
// Libs
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects,
MacOSAll, CocoaAll, CocoaUtils, CocoaWScommon,
cocoa_extra, CocoaPrivate, CocoaTextEdits, CocoaScrollers,
// LCL
//Forms,
@ -776,6 +776,8 @@ begin
and Assigned(contentView)
and (contentView.isKindOfClass(TCocoaWindowContent)) then
self.makeFirstResponder( TCocoaWindowContent(contentView).documentView );
CursorHelper.SetCursorOnActive;
end;
procedure TCocoaWindow.windowDidResignKey(notification: NSNotification);

View File

@ -12,7 +12,7 @@ uses
CGGeometry, CocoaAll, cocoa_extra,
Classes, Controls, SysUtils,
//
WSControls, LCLType, LMessages, LCLProc, Graphics, Forms,
WSControls, LCLType, LMessages, LCLProc, LCLIntf, Graphics, Forms,
CocoaPrivate, CocoaGDIObjects, CocoaCaret, CocoaUtils, LCLMessageGlue,
CocoaScrollers;
@ -20,7 +20,11 @@ type
{ TCursorHelper }
TCursorHelper = class
private
procedure CallSetCurrentControlCursor( data:IntPtr );
public
class procedure SetCursorOnActive;
class procedure SetCurrentControlCursor;
class procedure SetScreenCursor;
class procedure SetScreenCursorWhenNotDefault;
end;
@ -356,6 +360,30 @@ end;
{ TCursorHelper }
procedure TCursorHelper.CallSetCurrentControlCursor( data:IntPtr );
begin
SetCurrentControlCursor;
end;
class procedure TCursorHelper.SetCursorOnActive;
begin
if Screen.Cursor<>crDefault then
SetScreenCursor
else
Application.QueueAsyncCall( @CursorHelper.CallSetCurrentControlCursor, 0 );
end;
class procedure TCursorHelper.SetCurrentControlCursor;
var
P: TPoint;
control: TControl;
begin
GetCursorPos(P);
control:= FindControlAtPosition(P, true);;
if Assigned(control) then
TCocoaCursor(Screen.Cursors[control.Cursor]).SetCursor;
end;
class procedure TCursorHelper.SetScreenCursor;
begin
TCocoaCursor(Screen.Cursors[Screen.Cursor]).SetCursor;