Vuo  2.3.2
VuoClipboard.m
Go to the documentation of this file.
1 
10 #include "VuoClipboard.h"
11 #include "module.h"
12 
13 #include "VuoMacOSSDKWorkaround.h"
14 #import <AppKit/AppKit.h>
15 
16 #ifdef VUO_COMPILER
18  "title" : "VuoClipboard",
19  "dependencies" : [
20  "AppKit.framework"
21  ]
22  });
23 #endif
24 
28 @interface VuoClipboardReader : NSObject
29 @end
30 
31 @implementation VuoClipboardReader
32 
36 + (VuoText) getClipboardContents
37 {
38  NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
39  NSData* data = [pasteBoard dataForType:NSPasteboardTypeString];
40  NSString* str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
41  VuoText txt = VuoText_make([str UTF8String]);
42  [str release];
43  return txt;
44 }
45 
49 + (void) setClipboardContents:(const char*) text
50 {
51  NSString* str = [[NSString alloc] initWithUTF8String:text];
52 
53  if([str length] < 1)
54  {
55  [str release];
56  return;
57  }
58 
59  [[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
60  [[NSPasteboard generalPasteboard] setString:str forType:NSPasteboardTypeString];
61  [str release];
62 }
63 
64 @end
65 
71 {
72  return [VuoClipboardReader getClipboardContents];
73 }
74 
79 {
80  [VuoClipboardReader setClipboardContents:text];
81 }