mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-26 20:28:49 -05:00
Added initial implementation for Cocoa.
This commit is contained in:
parent
8390121869
commit
15e8af1f79
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user