Cocoa: fix the issue that Modal Form may disappear when switching back from other apps

the issue fixed:
1. run your app, open Modal Form
2. switch to other apps
3. in the dock, right click your app ico and select "Show All Window", and select a window
4. the Modal Form is disappear (actually ordered behind the selected Form)
This commit is contained in:
rich2014 2023-07-16 23:00:29 +08:00
parent 27f6e20118
commit b184a37dbe

View File

@ -122,6 +122,8 @@ type
private
// for the reentrancy of makeFirstResponder()
makeFirstResponderCount: Integer;
private
procedure DoWindowDidBecomeKey(); message 'DoWindowDidBecomeKey';
protected
fieldEditor: TCocoaFieldEditor;
firedMouseEvent: Boolean;
@ -235,6 +237,9 @@ type
implementation
uses
CocoaInt;
{ TCocoaDesignOverlay }
procedure TCocoaDesignOverlay.drawRect(r: NSRect);
@ -756,6 +761,13 @@ begin
callback.Close;
end;
procedure TCocoaWindow.DoWindowDidBecomeKey();
begin
if Assigned(CocoaWidgetSet.CurModalForm) then
CocoaWidgetSet.CurModalForm.orderFront(nil);
CursorHelper.SetCursorOnActive();
end;
procedure TCocoaWindow.windowDidBecomeKey(notification: NSNotification);
begin
// forcing to keep the level as all other LCL windows
@ -780,7 +792,7 @@ begin
and (contentView.isKindOfClass(TCocoaWindowContent)) then
self.makeFirstResponder( TCocoaWindowContent(contentView).documentView );
CursorHelper.SetCursorOnActive;
performSelector_withObject_afterDelay( ObjCSelector('DoWindowDidBecomeKey'), nil, 0.1 );
end;
procedure TCocoaWindow.windowDidResignKey(notification: NSNotification);