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 AppRun(const ALoop: TApplicationMainLoop); override;
procedure AppRunMessages(onlyOne: Boolean);
procedure AppWaitMessage; override;
procedure AppProcessMessages; override;
procedure AppTerminate; override;

View File

@ -89,12 +89,7 @@ begin
end;
end;
{------------------------------------------------------------------------------
Method: TCocoaWidgetSet.AppProcessMessages
Handle all pending messages
------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppProcessMessages;
procedure TCocoaWidgetSet.AppRunMessages(onlyOne: Boolean);
var
event: NSEvent;
pool:NSAutoReleasePool;
@ -116,7 +111,17 @@ begin
// Thus we have to check the clipboard on every loop
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;
{------------------------------------------------------------------------------
@ -125,25 +130,8 @@ end;
Passes execution control to Cocoa
------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppWaitMessage;
var
event : NSEvent;
pool:NSAutoReleasePool;
begin
pool := NSAutoreleasePool.alloc.init;
{$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;
AppRunMessages(true);
end;
{------------------------------------------------------------------------------

View File

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