mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-26 14:40:29 +02:00
Cocoa: simplify the code related to Focus
This commit is contained in:
parent
3542056197
commit
890ae752ca
@ -2551,35 +2551,20 @@ end;
|
|||||||
|
|
||||||
function TCocoaWidgetSet.SetFocus(Handle: HWND): HWND;
|
function TCocoaWidgetSet.SetFocus(Handle: HWND): HWND;
|
||||||
var
|
var
|
||||||
Obj: NSObject;
|
|
||||||
lView: NSView;
|
lView: NSView;
|
||||||
cb: ICommonCallback;
|
|
||||||
begin
|
begin
|
||||||
if Handle <> 0 then
|
if Handle <> 0 then
|
||||||
begin
|
begin
|
||||||
Result := GetFocus;
|
Result := GetFocus;
|
||||||
if Result = Handle then
|
if Result = Handle then
|
||||||
Exit;
|
Exit;
|
||||||
Obj := NSObject(Handle);
|
lView := NSObject(Handle).lclContentView;
|
||||||
if Obj.isKindOfClass(NSWindow) then
|
if Assigned(lView) and Assigned(lView.window) then
|
||||||
begin
|
begin
|
||||||
NSWindow(Obj).makeKeyWindow;
|
lView.window.makeKeyWindow;
|
||||||
NSWindow(Obj).makeFirstResponder(nil);
|
lView.window.makeFirstResponder(lView.lclContentView);
|
||||||
end
|
end else
|
||||||
else
|
Result := 0;
|
||||||
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;
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Result := 0;
|
Result := 0;
|
||||||
|
@ -785,13 +785,6 @@ begin
|
|||||||
if Assigned(callback) then
|
if Assigned(callback) then
|
||||||
callback.Activate;
|
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 );
|
performSelector_withObject_afterDelay( ObjCSelector('DoWindowDidBecomeKey'), nil, 0.1 );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user