cocoa: adding the track of clipboard changes and notificaiton of LCL. #33801

git-svn-id: trunk@58294 -
This commit is contained in:
dmitry 2018-06-17 04:53:34 +00:00
parent ee472d8593
commit f2b4051e3e
4 changed files with 48 additions and 0 deletions

View File

@ -85,6 +85,13 @@ type
procedure sendEvent(theEvent: NSEvent); override;
end;
TCocoaPasteboardsRef = record
pasteboard : NSPasteboard;
changeCount: NSInteger;
dataProc : TClipboardRequestEvent;
isOwned : Boolean;
end;
{ TCocoaWidgetSet }
TCocoaWidgetSet = class(TWidgetSet)
@ -118,9 +125,12 @@ type
PrimarySelection: NSPasteboard;
SecondarySelection: NSPasteboard;
ClipboardFormats: TFPObjectList; // of TCocoaClipboardData
ClipboardChangeCount: NSInteger;
Pasteboards: array [TClipboardType] of TCocoaPasteboardsRef;
procedure InitClipboard();
procedure FreeClipboard();
procedure SyncClipboard();
function GetClipboardDataForFormat(AFormat: TClipboardFormat): TCocoaClipboardData;
function PromptUser(const DialogCaption, DialogMessage: String;

View File

@ -163,6 +163,27 @@ begin
ClipboardFormats.Free;
end;
procedure TCocoaWidgetSet.SyncClipboard();
var
ct : TClipboardType;
pb : NSPasteboard;
begin
for ct := low(TClipboardType) to high(TClipboardType) do begin
if not Pasteboards[ct].isOwned then Continue;
pb := Pasteboards[ct].pasteboard;
if not Assigned(pb) then Continue;
if (pb.changeCount <> Pasteboards[ct].changeCount) then
begin
Pasteboards[ct].isOwned:=false;
if Assigned(Pasteboards[ct].dataProc) then
// notifying about the loss of ownership
Pasteboards[ct].dataProc(0, nil);
end;
end;
end;
function TCocoaWidgetSet.GetClipboardDataForFormat(AFormat: TClipboardFormat): TCocoaClipboardData;
begin
Result := TCocoaClipboardData(AFormat);

View File

@ -106,6 +106,10 @@ 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;
until event = nil;
end;
@ -130,6 +134,9 @@ 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;

View File

@ -361,6 +361,16 @@ begin
DataStream.Free;
end;
Pasteboards[ClipboardType].pasteboard:=pasteboard;
Pasteboards[ClipboardType].dataProc:=OnRequestProc;
if Assigned(pasteboard) then
begin
Pasteboards[ClipboardType].changeCount:=pasteboard.changeCount;
Pasteboards[ClipboardType].isOwned:=true;
end else
Pasteboards[ClipboardType].isOwned:=false;
Result := True;
end;