Cocoa: fix #40692, the bug of Modal Window

This commit is contained in:
rich2014 2024-01-12 23:06:09 +08:00
parent 7157791611
commit 6f8a824944
2 changed files with 14 additions and 7 deletions

View File

@ -171,7 +171,6 @@ type
procedure DoSetMainMenu(AMenu: NSMenu; ALCLMenu: TMenu);
public
// modal session
CurModalForm: NSWindow;
Modals : TList;
ModalCounter: Integer; // the cheapest way to determine if modal window was called
// used in mouse handling (in callbackobject)
@ -218,6 +217,7 @@ type
procedure SetMainMenu(const AMenu: HMENU; const ALCLMenu: TMenu);
function StartModal(awin: NSWindow; hasMenu: Boolean): Boolean;
procedure EndModal(awin: NSWindow);
function CurModalForm: NSWindow;
function isTopModalWin(awin: NSWindow): Boolean;
function isModalSession: Boolean;
@ -946,13 +946,22 @@ begin
wakeupEventLoop;
end;
function TCocoaWidgetSet.CurModalForm: NSWindow;
begin
if isModalSession then begin
Result := TModalSession(Modals[Modals.Count-1]).window;
end else begin
Result:= nil;
end;
end;
function TCocoaWidgetSet.isTopModalWin(awin: NSWindow): Boolean;
begin
if not isModalSession then begin
Result := false;
Exit;
if Assigned(awin) then begin
Result:= CurModalForm=awin;
end else begin
Result:= false;
end;
Result := TModalSession(Modals[Modals.Count-1]).window = awin;
end;
function TCocoaWidgetSet.isModalSession: Boolean;

View File

@ -411,7 +411,6 @@ begin
{$IFDEF COCOA_USE_NATIVE_MODAL}
NSApp.stopModal();
{$ENDIF}
CocoaWidgetSet.CurModalForm := nil;
{// Felipe: This code forces focusing another form, its a work around
// for a gdb issue, gdb doesn't start the app properly
//
@ -936,7 +935,6 @@ begin
if (not fullscreen) and (lWinContent.window.isKindOfClass(TCocoaWindow)) then
fullscreen := TCocoaWindow(lWinContent.window).lclIsFullScreen;
CocoaWidgetSet.CurModalForm := lWinContent.lclOwnWindow;
// LCL initialization code would cause the custom form to be disabled
// (due to the fact, ShowModal() has not been called yet, and a previous form
// might be disabled at the time.