Cocoa: simplify the code related to Focus

This commit is contained in:
rich2014 2023-07-18 19:04:32 +08:00
parent 3542056197
commit 890ae752ca
2 changed files with 6 additions and 28 deletions

View File

@ -2551,35 +2551,20 @@ end;
function TCocoaWidgetSet.SetFocus(Handle: HWND): HWND;
var
Obj: NSObject;
lView: NSView;
cb: ICommonCallback;
begin
if Handle <> 0 then
begin
Result := GetFocus;
if Result = Handle then
Exit;
Obj := NSObject(Handle);
if Obj.isKindOfClass(NSWindow) then
lView := NSObject(Handle).lclContentView;
if Assigned(lView) and Assigned(lView.window) then
begin
NSWindow(Obj).makeKeyWindow;
NSWindow(Obj).makeFirstResponder(nil);
end
else
begin
lView := obj.lclContentView;
if lView <> nil then
begin
if lView.window <> nil then
begin
lView.window.makeKeyWindow;
lView.window.makeFirstResponder(lView.lclContentView);
end else
Result := 0; // the view is on window, cannot set focus. Fail
end else
Result := 0;
end;
lView.window.makeKeyWindow;
lView.window.makeFirstResponder(lView.lclContentView);
end else
Result := 0;
end
else
Result := 0;

View File

@ -785,13 +785,6 @@ begin
if Assigned(callback) then
callback.Activate;
// LCL didn't change focus. TCocoaWindow should not keep the focus for itself
// and it should pass it to it's content view
if (firstResponder = self)
and Assigned(contentView)
and (contentView.isKindOfClass(TCocoaWindowContent)) then
self.makeFirstResponder( TCocoaWindowContent(contentView).documentView );
performSelector_withObject_afterDelay( ObjCSelector('DoWindowDidBecomeKey'), nil, 0.1 );
end;