From 810d3c4e27fe5c18abf8e83af9487c81eb0a4a52 Mon Sep 17 00:00:00 2001 From: dmitry Date: Wed, 18 Dec 2019 19:18:15 +0000 Subject: [PATCH] cocoa: restoring the use of CocoaLoopOverride for a better control of the message loop. bug #36405 git-svn-id: trunk@62413 - --- lcl/interfaces/cocoa/cocoadefines.inc | 2 +- lcl/interfaces/cocoa/cocoaint.pas | 5 +++-- lcl/interfaces/cocoa/cocoaobject.inc | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoadefines.inc b/lcl/interfaces/cocoa/cocoadefines.inc index b10efacba1..95387b712d 100644 --- a/lcl/interfaces/cocoa/cocoadefines.inc +++ b/lcl/interfaces/cocoa/cocoadefines.inc @@ -20,7 +20,7 @@ // the first request to process an event, and run LCL loop from there. // Such approach is some what an ugly solution, yet it's reliable, in a sense // that Cocoa performs ALL of this methods. -{.$define COCOALOOPOVERRIDE} +{$define COCOALOOPOVERRIDE} // Not override "run" method. Catch any FPC exception // The biggest problem of the Native approach - LCL "runloop" method is not called diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 652666e2fa..4c5d9d0a3d 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -86,6 +86,7 @@ type modals : NSMutableDictionary; inputclient : TCocoaInputClient; inputctx : NSTextInputContext; + isfinishLaunch: Boolean; procedure dealloc; override; {$ifdef COCOALOOPOVERRIDE} @@ -120,7 +121,7 @@ type TCocoaWidgetSet = class(TWidgetSet) private FTerminating: Boolean; - FNSApp: NSApplication; + FNSApp: TCocoaApplication; FNSApp_Delegate: TAppDelegate; FCurrentCursor: HCursor; FCaptureControl: HWND; @@ -224,7 +225,7 @@ type function RawImage_DescriptionToBitmapType(ADesc: TRawImageDescription; out bmpType: TCocoaBitmapType): Boolean; function GetImagePixelData(AImage: CGImageRef; out bitmapByteCount: PtrUInt): Pointer; class function Create32BitAlphaBitmap(ABitmap, AMask: TCocoaBitmap): TCocoaBitmap; - property NSApp: NSApplication read FNSApp; + property NSApp: TCocoaApplication read FNSApp; property CurrentCursor: HCursor read FCurrentCursor write FCurrentCursor; property CaptureControl: HWND read FCaptureControl; // the winapi compatibility methods diff --git a/lcl/interfaces/cocoa/cocoaobject.inc b/lcl/interfaces/cocoa/cocoaobject.inc index f067ef8ea0..7aa06a74ca 100644 --- a/lcl/interfaces/cocoa/cocoaobject.inc +++ b/lcl/interfaces/cocoa/cocoaobject.inc @@ -38,7 +38,7 @@ begin ScreenInfo.PixelsPerInchY := CocoaBasePPI; { Creates the application NSApp object } - FNSApp := TCocoaApplication.sharedApplication; + FNSApp := TCocoaApplication(TCocoaApplication.sharedApplication); FNSApp_Delegate := TAppDelegate.alloc.init; FNSApp.setDelegate(FNSApp_Delegate); @@ -69,9 +69,6 @@ end; ------------------------------------------------------------------------------} procedure TCocoaWidgetSet.AppRun(const ALoop: TApplicationMainLoop); begin - {$ifdef COCOALOOPOVERRIDE} - NSApp.finishLaunching; - {$endif} if Assigned(ALoop) then begin TCocoaApplication(NSApp).aloop:=ALoop; @@ -84,6 +81,14 @@ var event: NSEvent; pool:NSAutoReleasePool; begin + {$ifdef COCOALOOPOVERRIDE} + if not fNSApp.isfinishLaunch then + begin + FNSApp.finishLaunching; + FNSApp.isfinishLaunch := true; + end; + {$endif} + repeat pool := NSAutoreleasePool.alloc.init; {$ifdef BOOLFIX}