From a21894d597e6be4c1b6ea4271d80bdf0b99b9394 Mon Sep 17 00:00:00 2001 From: dmitry Date: Tue, 17 Dec 2019 03:41:03 +0000 Subject: [PATCH] cocoa: forcing focus set on Showing window through WS ShowHide method git-svn-id: trunk@62407 - --- lcl/interfaces/cocoa/cocoawsforms.pas | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lcl/interfaces/cocoa/cocoawsforms.pas b/lcl/interfaces/cocoa/cocoawsforms.pas index c52a5b994e..9ef10d963c 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pas +++ b/lcl/interfaces/cocoa/cocoawsforms.pas @@ -331,9 +331,20 @@ end; { TLCLWindowCallback } +type + TWinControlAccess = class(TWinControl) + end; + function TLCLWindowCallback.CanActivate: Boolean; begin Result := Enabled; + // it's possible that a Modal window requests this (target) window + // to become visible (i.e. when modal is closing) + // All other Windows are disabled while modal is active. + // Thus must check wcfUpdateShowing flag (which set when changing window visibility) + // And if it's used, then we allow the window to become Key window + if not Result and (Target is TWinControl) then + Result := wcfUpdateShowing in TWinControlAccess(Target).FWinControlFlags; end; constructor TLCLWindowCallback.Create(AOwner: NSObject; ATarget: TWinControl; AHandleView: NSView); @@ -1101,11 +1112,11 @@ begin end else begin + w := TCocoaWindowContent(AWinControl.Handle).lclOwnWindow; if not lShow then begin // macOS 10.6. If a window with a parent window is hidden, then parent is also hidden. // Detaching from the parent first! - w := TCocoaWindowContent(AWinControl.Handle).lclOwnWindow; if Assigned(w) and Assigned(w.parentWindow) then w.parentWindow.removeChildWindow(w); // if the same control needs to be shown again, it will be redrawn @@ -1113,6 +1124,10 @@ begin TCocoaWindowContent(AWinControl.Handle).documentView.setNeedsDisplay_(true); end; TCocoaWSWinControl.ShowHide(AWinControl); + + // ShowHide() also actives (sets focus to) the window + if lShow and Assigned(w) then + w.makeKeyWindow; end; if (lShow) then