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