cocoa: restoring the use of CocoaLoopOverride for a better control of the message loop. bug #36405

git-svn-id: trunk@62413 -
This commit is contained in:
dmitry 2019-12-18 19:18:15 +00:00
parent a896e7f941
commit 810d3c4e27
3 changed files with 13 additions and 7 deletions

View File

@ -20,7 +20,7 @@
// the first request to process an event, and run LCL loop from there. // 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 // Such approach is some what an ugly solution, yet it's reliable, in a sense
// that Cocoa performs ALL of this methods. // that Cocoa performs ALL of this methods.
{.$define COCOALOOPOVERRIDE} {$define COCOALOOPOVERRIDE}
// Not override "run" method. Catch any FPC exception // Not override "run" method. Catch any FPC exception
// The biggest problem of the Native approach - LCL "runloop" method is not called // The biggest problem of the Native approach - LCL "runloop" method is not called

View File

@ -86,6 +86,7 @@ type
modals : NSMutableDictionary; modals : NSMutableDictionary;
inputclient : TCocoaInputClient; inputclient : TCocoaInputClient;
inputctx : NSTextInputContext; inputctx : NSTextInputContext;
isfinishLaunch: Boolean;
procedure dealloc; override; procedure dealloc; override;
{$ifdef COCOALOOPOVERRIDE} {$ifdef COCOALOOPOVERRIDE}
@ -120,7 +121,7 @@ type
TCocoaWidgetSet = class(TWidgetSet) TCocoaWidgetSet = class(TWidgetSet)
private private
FTerminating: Boolean; FTerminating: Boolean;
FNSApp: NSApplication; FNSApp: TCocoaApplication;
FNSApp_Delegate: TAppDelegate; FNSApp_Delegate: TAppDelegate;
FCurrentCursor: HCursor; FCurrentCursor: HCursor;
FCaptureControl: HWND; FCaptureControl: HWND;
@ -224,7 +225,7 @@ type
function RawImage_DescriptionToBitmapType(ADesc: TRawImageDescription; out bmpType: TCocoaBitmapType): Boolean; function RawImage_DescriptionToBitmapType(ADesc: TRawImageDescription; out bmpType: TCocoaBitmapType): Boolean;
function GetImagePixelData(AImage: CGImageRef; out bitmapByteCount: PtrUInt): Pointer; function GetImagePixelData(AImage: CGImageRef; out bitmapByteCount: PtrUInt): Pointer;
class function Create32BitAlphaBitmap(ABitmap, AMask: TCocoaBitmap): TCocoaBitmap; 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 CurrentCursor: HCursor read FCurrentCursor write FCurrentCursor;
property CaptureControl: HWND read FCaptureControl; property CaptureControl: HWND read FCaptureControl;
// the winapi compatibility methods // the winapi compatibility methods

View File

@ -38,7 +38,7 @@ begin
ScreenInfo.PixelsPerInchY := CocoaBasePPI; ScreenInfo.PixelsPerInchY := CocoaBasePPI;
{ Creates the application NSApp object } { Creates the application NSApp object }
FNSApp := TCocoaApplication.sharedApplication; FNSApp := TCocoaApplication(TCocoaApplication.sharedApplication);
FNSApp_Delegate := TAppDelegate.alloc.init; FNSApp_Delegate := TAppDelegate.alloc.init;
FNSApp.setDelegate(FNSApp_Delegate); FNSApp.setDelegate(FNSApp_Delegate);
@ -69,9 +69,6 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppRun(const ALoop: TApplicationMainLoop); procedure TCocoaWidgetSet.AppRun(const ALoop: TApplicationMainLoop);
begin begin
{$ifdef COCOALOOPOVERRIDE}
NSApp.finishLaunching;
{$endif}
if Assigned(ALoop) then if Assigned(ALoop) then
begin begin
TCocoaApplication(NSApp).aloop:=ALoop; TCocoaApplication(NSApp).aloop:=ALoop;
@ -84,6 +81,14 @@ var
event: NSEvent; event: NSEvent;
pool:NSAutoReleasePool; pool:NSAutoReleasePool;
begin begin
{$ifdef COCOALOOPOVERRIDE}
if not fNSApp.isfinishLaunch then
begin
FNSApp.finishLaunching;
FNSApp.isfinishLaunch := true;
end;
{$endif}
repeat repeat
pool := NSAutoreleasePool.alloc.init; pool := NSAutoreleasePool.alloc.init;
{$ifdef BOOLFIX} {$ifdef BOOLFIX}