mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-13 07:57:52 +00:00
Merge branch 'osx_text_paste' of https://github.com/alexey-lysiuk/gzdoom
This commit is contained in:
commit
0ae74b844d
1 changed files with 32 additions and 17 deletions
|
@ -603,6 +603,15 @@ int I_FindAttr (findstate_t *fileinfo)
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static PasteboardRef s_clipboard;
|
static PasteboardRef s_clipboard;
|
||||||
|
|
||||||
|
static CFDataRef GetPasteboardData(const PasteboardItemID itemID, const CFStringRef flavorType)
|
||||||
|
{
|
||||||
|
CFDataRef data = NULL;
|
||||||
|
|
||||||
|
const OSStatus result = PasteboardCopyItemFlavorData(s_clipboard, itemID, flavorType, &data);
|
||||||
|
|
||||||
|
return noErr == result ? data : NULL;
|
||||||
|
}
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
// Clipboard support requires GTK+
|
// Clipboard support requires GTK+
|
||||||
|
@ -688,35 +697,41 @@ FString I_GetFromClipboard (bool use_primary_selection)
|
||||||
return FString();
|
return FString();
|
||||||
}
|
}
|
||||||
|
|
||||||
CFArrayRef flavorTypeArray;
|
if (CFDataRef data = GetPasteboardData(itemID, kUTTypeUTF8PlainText))
|
||||||
|
|
||||||
if (0 != PasteboardCopyItemFlavors(s_clipboard, itemID, &flavorTypeArray))
|
|
||||||
{
|
{
|
||||||
return FString();
|
const CFIndex bufferLength = CFDataGetLength(data);
|
||||||
|
char* const buffer = result.LockNewBuffer(bufferLength);
|
||||||
|
|
||||||
|
memcpy(buffer, CFDataGetBytePtr(data), bufferLength);
|
||||||
|
|
||||||
|
result.UnlockBuffer();
|
||||||
|
}
|
||||||
|
else if (CFDataRef data = GetPasteboardData(itemID, kUTTypeUTF16PlainText))
|
||||||
|
{
|
||||||
|
#ifdef __LITTLE_ENDIAN__
|
||||||
|
static const CFStringEncoding ENCODING = kCFStringEncodingUTF16LE;
|
||||||
|
#else // __BIG_ENDIAN__
|
||||||
|
static const CFStringEncoding ENCODING = kCFStringEncodingUTF16BE;
|
||||||
|
#endif // __LITTLE_ENDIAN__
|
||||||
|
|
||||||
|
if (const CFStringRef utf16 = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, data, ENCODING))
|
||||||
|
{
|
||||||
|
const CFRange range = { 0, CFStringGetLength(utf16) };
|
||||||
|
CFIndex bufferLength = 0;
|
||||||
|
|
||||||
|
if (CFStringGetBytes(utf16, range, kCFStringEncodingUTF8, '?', false, NULL, 0, &bufferLength) > 0)
|
||||||
|
{
|
||||||
|
UInt8* const buffer = reinterpret_cast<UInt8*>(result.LockNewBuffer(bufferLength));
|
||||||
|
|
||||||
|
CFStringGetBytes(utf16, range, kCFStringEncodingUTF8, '?', false, buffer, bufferLength, NULL);
|
||||||
|
|
||||||
|
result.UnlockBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CFIndex flavorCount = CFArrayGetCount(flavorTypeArray);
|
CFRelease(utf16);
|
||||||
|
|
||||||
for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; ++flavorIndex)
|
|
||||||
{
|
|
||||||
const CFStringRef flavorType = static_cast<const CFStringRef>(
|
|
||||||
CFArrayGetValueAtIndex(flavorTypeArray, flavorIndex));
|
|
||||||
|
|
||||||
if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text")))
|
|
||||||
{
|
|
||||||
CFDataRef flavorData;
|
|
||||||
|
|
||||||
if (0 == PasteboardCopyItemFlavorData(s_clipboard, itemID, flavorType, &flavorData))
|
|
||||||
{
|
|
||||||
result += reinterpret_cast<const char*>(CFDataGetBytePtr(flavorData));
|
|
||||||
}
|
|
||||||
|
|
||||||
CFRelease(flavorData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(flavorTypeArray);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
#endif
|
#endif
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in a new issue