cocoa: getting rid of code duplication in event processing

git-svn-id: trunk@61208 -
This commit is contained in:
dmitry 2019-05-12 01:20:44 +00:00
parent e1fb95fb10
commit daa05e2732
3 changed files with 15 additions and 26 deletions

View File

@ -156,6 +156,7 @@ type
procedure AppInit(var ScreenInfo: TScreenInfo); override; procedure AppInit(var ScreenInfo: TScreenInfo); override;
procedure AppRun(const ALoop: TApplicationMainLoop); override; procedure AppRun(const ALoop: TApplicationMainLoop); override;
procedure AppRunMessages(onlyOne: Boolean);
procedure AppWaitMessage; override; procedure AppWaitMessage; override;
procedure AppProcessMessages; override; procedure AppProcessMessages; override;
procedure AppTerminate; override; procedure AppTerminate; override;

View File

@ -89,12 +89,7 @@ begin
end; end;
end; end;
{------------------------------------------------------------------------------ procedure TCocoaWidgetSet.AppRunMessages(onlyOne: Boolean);
Method: TCocoaWidgetSet.AppProcessMessages
Handle all pending messages
------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppProcessMessages;
var var
event: NSEvent; event: NSEvent;
pool:NSAutoReleasePool; pool:NSAutoReleasePool;
@ -116,7 +111,17 @@ begin
// Thus we have to check the clipboard on every loop // Thus we have to check the clipboard on every loop
pool.release; pool.release;
until event = nil; until onlyOne or (event = nil);
end;
{------------------------------------------------------------------------------
Method: TCocoaWidgetSet.AppProcessMessages
Handle all pending messages
------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppProcessMessages;
begin
AppRunMessages(false);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -125,25 +130,8 @@ end;
Passes execution control to Cocoa Passes execution control to Cocoa
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppWaitMessage; procedure TCocoaWidgetSet.AppWaitMessage;
var
event : NSEvent;
pool:NSAutoReleasePool;
begin begin
pool := NSAutoreleasePool.alloc.init; AppRunMessages(true);
{$ifdef BOOLFIX}
event := NSApp.nextEventMatchingMask_untilDate_inMode_dequeue_(NSAnyEventMask, NSDate.distantFuture, NSDefaultRunLoopMode, Ord(true));
{$else}
event := NSApp.nextEventMatchingMask_untilDate_inMode_dequeue(NSAnyEventMask, NSDate.distantFuture, NSDefaultRunLoopMode, true);
{$endif}
if event <> nil then
begin
NSApp.sendEvent(event);
NSApp.updateWindows;
end;
SyncClipboard(); // NSPasteboard doesn't provide any notifications regarding the change
// Thus we have to check the clipboard on every loop
pool.release;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -2247,7 +2247,7 @@ begin
Result:=inherited SetCaretRespondToFocus(handle, ShowHideOnFocus); Result:=inherited SetCaretRespondToFocus(handle, ShowHideOnFocus);
end; end;
function TCocoaWidgetSet.RectVisible(dc: HDC; const ARect: TRect): Boolean; function TCocoaWidgetSet.RectVisible(dc: hdc; const ARect: TRect): Boolean;
var var
ClipBox: CGRect; ClipBox: CGRect;
ctx : TCocoaContext; ctx : TCocoaContext;