Added initial implementation for Cocoa.

This commit is contained in:
Camilla Berglund 2012-04-10 00:34:08 +02:00
parent 8390121869
commit 15e8af1f79

View File

@ -43,6 +43,12 @@
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
{
NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil];
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:types owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:string]
forType:NSStringPboardType];
}
@ -52,6 +58,30 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size)
{
const char* source;
size_t targetSize;
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
if (![[pasteboard types] containsObject:NSStringPboardType])
{
_glfwSetError(GLFW_FORMAT_UNAVAILABLE, NULL);
return 0;
}
NSString* object = [pasteboard stringForType:NSStringPboardType];
if (!object)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSGL: Failed to retrieve object from pasteboard");
return 0;
}
source = [object UTF8String];
targetSize = strlen(source) + 1;
if (targetSize > size)
targetSize = size;
strlcpy(string, source, targetSize);
return 0;
}