From 3cba1d3b82e665667ec1dda9194f6c7e646a5222 Mon Sep 17 00:00:00 2001 From: dmitry Date: Mon, 17 Jun 2019 15:14:59 +0000 Subject: [PATCH] cocoa: adding cocoaloopnative approach - use Cocoa natively and catch FPC exceptions within cocoa-ws git-svn-id: trunk@61406 - --- lcl/interfaces/cocoa/cocoadefines.inc | 5 +++++ lcl/interfaces/cocoa/cocoaint.pas | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lcl/interfaces/cocoa/cocoadefines.inc b/lcl/interfaces/cocoa/cocoadefines.inc index e731b538bf..b10efacba1 100644 --- a/lcl/interfaces/cocoa/cocoadefines.inc +++ b/lcl/interfaces/cocoa/cocoadefines.inc @@ -22,6 +22,11 @@ // that Cocoa performs ALL of this methods. {.$define COCOALOOPOVERRIDE} +// Not override "run" method. Catch any FPC exception +// The biggest problem of the Native approach - LCL "runloop" method is not called +// at all. Thus if LCL implementation is changed, CocoaWS needs to be updated +{.$define COCOALOOPNATIVE} + {$if not defined(COCOALOOPOVERRIDE) and not defined(COCOALOOPNATIVE)} // the first call to nextEventMatchingMask_untilDate_inMode_dequeue would // cause an LCL event processing loop to be called. diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 5c7e800053..9f770d76a5 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -483,6 +483,9 @@ var win : NSWindow; cbnew : ICommonCallback; begin + {$ifdef COCOALOOPNATIVE} + try + {$endif} idx := CocoaWidgetSet.RetainToCollect; win := theEvent.window; if not Assigned(win) then win := self.keyWindow; @@ -542,6 +545,14 @@ begin CocoaWidgetSet.ReleaseToCollect(idx); end; + {$ifdef COCOALOOPNATIVE} + except + if Assigned(Application) and Application.CaptureExceptions then + Application.HandleException(Application) + else + raise; + end; + {$endif} end; function isMouseMoveEvent(tp: NSEventType): Boolean; inline;