diff options
author | David Robillard <d@drobilla.net> | 2019-08-17 20:50:20 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-09-07 09:51:48 +0200 |
commit | 7162fa4f5656ad7dfe2d6fea02f9f33c5aa1b1cf (patch) | |
tree | 0f885354b2d75875003401379d5aaf9aadda226f /pugl/detail/mac.m | |
parent | 27e43183d89aad98f6000ee187b05547776ae4c2 (diff) | |
download | pugl-7162fa4f5656ad7dfe2d6fea02f9f33c5aa1b1cf.tar.gz pugl-7162fa4f5656ad7dfe2d6fea02f9f33c5aa1b1cf.tar.bz2 pugl-7162fa4f5656ad7dfe2d6fea02f9f33c5aa1b1cf.zip |
Add clipboard support
Diffstat (limited to 'pugl/detail/mac.m')
-rw-r--r-- | pugl/detail/mac.m | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m index 8570709..ab13452 100644 --- a/pugl/detail/mac.m +++ b/pugl/detail/mac.m @@ -1024,3 +1024,43 @@ puglSetAspectRatio(PuglView* const view, return PUGL_SUCCESS; } + +const void* +puglGetClipboard(PuglView* const view, + const char** const type, + size_t* const len) +{ + NSPasteboard* const pasteboard = [NSPasteboard generalPasteboard]; + + if ([[pasteboard types] containsObject:NSStringPboardType]) { + const NSString* str = [pasteboard stringForType:NSStringPboardType]; + const char* utf8 = [str UTF8String]; + + puglSetBlob(&view->clipboard, utf8, strlen(utf8) + 1); + } + + return puglGetInternalClipboard(view, type, len); +} + +PuglStatus +puglSetClipboard(PuglView* const view, + const char* const type, + const void* const data, + const size_t len) +{ + NSPasteboard* const pasteboard = [NSPasteboard generalPasteboard]; + const char* const str = (const char*)data; + + PuglStatus st = puglSetInternalClipboard(view, type, data, len); + if (st) { + return st; + } + + [pasteboard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] + owner:nil]; + + [pasteboard setString:[NSString stringWithUTF8String:str] + forType:NSStringPboardType]; + + return PUGL_SUCCESS; +} |