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

View File

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