winemac: Implement GetClipboardData() with support for text formats.

oldstable
Ken Thomases 2013-03-10 22:58:18 -05:00 committed by Alexandre Julliard
parent 7cf3e0596f
commit 764a8edb09
4 changed files with 97 additions and 0 deletions

View File

@ -737,6 +737,73 @@ UINT CDECL macdrv_EnumClipboardFormats(UINT prev_format)
}
/**************************************************************************
* GetClipboardData (MACDRV.@)
*/
HANDLE CDECL macdrv_GetClipboardData(UINT desired_format)
{
CFArrayRef types;
CFIndex count;
CFIndex i;
CFStringRef type, best_type;
WINE_CLIPFORMAT* best_format = NULL;
HANDLE data = NULL;
TRACE("desired_format %s\n", debugstr_format(desired_format));
types = macdrv_copy_pasteboard_types();
if (!types)
{
WARN("Failed to copy pasteboard types\n");
return NULL;
}
count = CFArrayGetCount(types);
TRACE("got %ld types\n", count);
for (i = 0; (!best_format || best_format->synthesized) && i < count; i++)
{
WINE_CLIPFORMAT* format;
type = CFArrayGetValueAtIndex(types, i);
format = NULL;
while ((!best_format || best_format->synthesized) && (format = format_for_type(format, type)))
{
TRACE("for type %s got format %p/%s\n", debugstr_cf(type), format, debugstr_format(format ? format->format_id : 0));
if (format->format_id == desired_format)
{
/* The best format is the matching one which is not synthesized. Failing that,
the best format is the first matching synthesized format. */
if (!format->synthesized || !best_format)
{
best_type = type;
best_format = format;
}
}
}
}
if (best_format)
{
CFDataRef pasteboard_data = macdrv_copy_pasteboard_data(best_type);
TRACE("got pasteboard data for type %s: %s\n", debugstr_cf(best_type), debugstr_cf(pasteboard_data));
if (pasteboard_data)
{
data = best_format->import_func(pasteboard_data);
CFRelease(pasteboard_data);
}
}
CFRelease(types);
TRACE(" -> %p\n", data);
return data;
}
/**************************************************************************
* IsClipboardFormatAvailable (MACDRV.@)
*/

View File

@ -50,3 +50,31 @@ CFArrayRef macdrv_copy_pasteboard_types(void)
[pool release];
return ret;
}
/***********************************************************************
* macdrv_copy_pasteboard_data
*
* Returns the pasteboard data for a specified type, or NULL on error or
* if there's no such type on the pasteboard. The caller is responsible
* for releasing the returned data object with CFRelease().
*/
CFDataRef macdrv_copy_pasteboard_data(CFStringRef type)
{
__block NSData* ret = nil;
OnMainThread(^{
@try
{
NSPasteboard* pb = [NSPasteboard generalPasteboard];
if ([pb availableTypeFromArray:[NSArray arrayWithObject:(NSString*)type]])
ret = [[pb dataForType:(NSString*)type] copy];
}
@catch (id e)
{
ERR(@"Exception discarded while copying pasteboard types: %@\n", e);
}
});
return (CFDataRef)ret;
}

View File

@ -275,6 +275,7 @@ extern CFDataRef macdrv_copy_keyboard_layout(CGEventSourceKeyboardType* keyboard
/* clipboard */
extern CFArrayRef macdrv_copy_pasteboard_types(void) DECLSPEC_HIDDEN;
extern CFDataRef macdrv_copy_pasteboard_data(CFStringRef type) DECLSPEC_HIDDEN;
/* opengl */

View File

@ -16,6 +16,7 @@
@ cdecl EnumClipboardFormats(long) macdrv_EnumClipboardFormats
@ cdecl EnumDisplayMonitors(long ptr ptr long) macdrv_EnumDisplayMonitors
@ cdecl EnumDisplaySettingsEx(ptr long ptr long) macdrv_EnumDisplaySettingsEx
@ cdecl GetClipboardData(long) macdrv_GetClipboardData
@ cdecl GetCursorPos(ptr) macdrv_GetCursorPos
@ cdecl GetKeyboardLayout(long) macdrv_GetKeyboardLayout
@ cdecl GetKeyboardLayoutName(ptr) macdrv_GetKeyboardLayoutName