mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 16:29:32 +02:00
cocoa: adding support for an image in the pastebin. #34960
git-svn-id: trunk@61472 -
This commit is contained in:
parent
b06a651094
commit
8ca71151f9
@ -86,6 +86,7 @@ const
|
|||||||
// thus for earlier systems must be redeclared
|
// thus for earlier systems must be redeclared
|
||||||
_NSPasteboardTypeString : NSString = nil;
|
_NSPasteboardTypeString : NSString = nil;
|
||||||
_NSPasteboardTypePNG : NSString = nil;
|
_NSPasteboardTypePNG : NSString = nil;
|
||||||
|
_NSPasteboardTypeTiff : NSString = nil;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -93,6 +94,7 @@ procedure InitConst;
|
|||||||
begin
|
begin
|
||||||
_NSPasteboardTypeString := NSSTR('public.utf8-plain-text');
|
_NSPasteboardTypeString := NSSTR('public.utf8-plain-text');
|
||||||
_NSPasteboardTypePNG := NSSTR('public.png');
|
_NSPasteboardTypePNG := NSSTR('public.png');
|
||||||
|
_NSPasteboardTypeTiff := NSSTR('public.tiff');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSClipboard }
|
{ TCocoaWSClipboard }
|
||||||
@ -160,6 +162,17 @@ begin
|
|||||||
Result := TCocoaClipboardData(AFormat);
|
Result := TCocoaClipboardData(AFormat);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function PasteboardToPngData(pb: NSPasteboard): NSData;
|
||||||
|
var
|
||||||
|
rep : NSBitmapImageRep;
|
||||||
|
begin
|
||||||
|
rep := NSBitmapImageRep.imageRepWithPasteboard(pb);
|
||||||
|
if Assigned(rep) then
|
||||||
|
Result := rep.representationUsingType_properties(NSPNGFileType, nil)
|
||||||
|
else
|
||||||
|
Result := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCocoaWSClipboard.GetData(ClipboardType: TClipboardType;
|
function TCocoaWSClipboard.GetData(ClipboardType: TClipboardType;
|
||||||
FormatID: TClipboardFormat; Stream: TStream): boolean;
|
FormatID: TClipboardFormat; Stream: TStream): boolean;
|
||||||
var
|
var
|
||||||
@ -207,7 +220,10 @@ begin
|
|||||||
ccdtBitmap:
|
ccdtBitmap:
|
||||||
begin
|
begin
|
||||||
lNSData := pasteboard.dataForType(lFormat.CocoaFormat);
|
lNSData := pasteboard.dataForType(lFormat.CocoaFormat);
|
||||||
if lNSData = nil then Exit;
|
if lNSData = nil then begin
|
||||||
|
lNSData := PasteboardToPngData(pasteboard);
|
||||||
|
if not Assigned(lNSData) then Exit;
|
||||||
|
end;
|
||||||
lNSbytes := lNSData.bytes;
|
lNSbytes := lNSData.bytes;
|
||||||
|
|
||||||
Image := TFPMemoryImage.Create(10, 10);
|
Image := TFPMemoryImage.Create(10, 10);
|
||||||
@ -239,6 +255,11 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
pb : NSPasteboard;
|
pb : NSPasteboard;
|
||||||
tp : NSString;
|
tp : NSString;
|
||||||
|
hasBmp: Boolean;
|
||||||
|
hasImage: Boolean; // this a default macOS sharing format
|
||||||
|
imgArr: NSArray;
|
||||||
|
const
|
||||||
|
ImgBmpFmt : string = 'image/bmp';
|
||||||
begin
|
begin
|
||||||
pb := Pasteboards[ClipboardType].pasteboard;
|
pb := Pasteboards[ClipboardType].pasteboard;
|
||||||
Result := Assigned(pb);
|
Result := Assigned(pb);
|
||||||
@ -246,10 +267,27 @@ begin
|
|||||||
|
|
||||||
i := 0;
|
i := 0;
|
||||||
SetLength(List, pb.types.count);
|
SetLength(List, pb.types.count);
|
||||||
|
hasImage := false;
|
||||||
|
hasBmp := false;
|
||||||
|
imgArr := NSBitmapImageRep.imagePasteboardTypes;
|
||||||
|
|
||||||
for tp in pb.types do
|
for tp in pb.types do
|
||||||
begin
|
begin
|
||||||
List[i]:=RegisterCocoaType(tp);
|
List[i]:=RegisterCocoaType(tp);
|
||||||
inc(i);
|
inc(i);
|
||||||
|
if not hasImage and Assigned(imgArr) then
|
||||||
|
begin
|
||||||
|
hasImage := (imgArr.indexOfObject(tp) <> NSNotFound);
|
||||||
|
end;
|
||||||
|
if (tp.UTF8String = ImgBmpFmt) then
|
||||||
|
hasBmp := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if hasImage and not hasBmp then
|
||||||
|
begin
|
||||||
|
inc(i);
|
||||||
|
SetLength(List, i);
|
||||||
|
List[i-1] := RegisterFormat(ImgBmpFmt);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Count := i;
|
Count := i;
|
||||||
|
Loading…
Reference in New Issue
Block a user