cocoa: Prepares the clipboard for non-standard types

git-svn-id: trunk@47796 -
This commit is contained in:
sekelsenmat 2015-02-15 11:37:36 +00:00
parent 83a8aed14d
commit 2e57cfe36f
3 changed files with 19 additions and 11 deletions

View File

@ -49,12 +49,14 @@ type
class function initWithFunc(afunc: TWSTimerProc): TCocoaTimerObject; message 'initWithFunc:';
end;
TCocoaClipboardDataType = (ccdtText, ccdtCocoaStandard, ccdtNonStandard);
TClipboardData = class(TObject) // TClipboardFormat is a reference to a TClipboardData
public
MimeType: string;
CocoaFormat: NSString;
IsText: Boolean;
constructor Create(AMimeType: string; ACocoaFormat: NSString; AIsText: Boolean);
DataType: TCocoaClipboardDataType;
constructor Create(AMimeType: string; ACocoaFormat: NSString; ADataType: TCocoaClipboardDataType);
end;

View File

@ -493,11 +493,11 @@ end;
{ TClipboardData }
constructor TClipboardData.Create(AMimeType: string; ACocoaFormat: NSString; AIsText: Boolean);
constructor TClipboardData.Create(AMimeType: string; ACocoaFormat: NSString; ADataType: TCocoaClipboardDataType);
begin
MimeType := AMimeType;
CocoaFormat := ACocoaFormat;
IsText := AIsText;
DataType := ADataType;
end;
{------------------------------------------------------------------------------

View File

@ -153,7 +153,8 @@ begin
lFormat := GetClipboardDataForFormat(FormatID);
if lFormat = nil then Exit;
if lFormat.IsText then
case lFormat.DataType of
ccdtText:
begin
lNSStr := pasteboard.stringForType(lFormat.CocoaFormat);
if lNSStr = nil then Exit;
@ -162,8 +163,8 @@ begin
{$IFDEF VerboseClipboard}
DebugLn('TCocoaWidgetSet.ClipboardGetData IsText Result=' + lStr);
{$ENDIF}
end
else
end;
ccdtCocoaStandard:
begin
lNSData := pasteboard.dataForType(lFormat.CocoaFormat);
if lNSData = nil then Exit;
@ -171,6 +172,11 @@ begin
for i := 0 to lNSData.length-1 do
Stream.WriteByte(lNSbytes[i]);
end;
ccdtNonStandard:
begin
end;
end;
Result := True;
end;
@ -248,7 +254,7 @@ var
i: Integer;
lCurData: TClipboardData;
lNSStr: NSString = nil;
lIsText: Boolean;
lDataType: TCocoaClipboardDataType;
begin
Result := 0;
@ -269,13 +275,13 @@ begin
// if none was found, we need to register it
lIsText := False;
lDataType := ccdtNonStandard;
// See PredefinedClipboardMimeTypes for the most common mime-types
case AMimeType of
'text/plain':
begin
lNSStr := NSPasteboardTypeString;
lIsText := True;
lDataType := ccdtText;
end;
{'image/bmp', 'image/xpm', 'image/delphi.bitmap':
begin
@ -288,7 +294,7 @@ begin
if lNSStr <> nil then
begin
lCurData := TClipboardData.Create(AMimeType, NSPasteboardTypeString, True);
lCurData := TClipboardData.Create(AMimeType, lNSStr, lDataType);
ClipboardFormats.Add(lCurData);
Result := TClipboardFormat(lCurData);
end;