Vuo  2.0.0
VuoClipboard.m
Go to the documentation of this file.
1 
10 #include "VuoClipboard.h"
11 #include "module.h"
12 
13 #ifndef NS_RETURNS_INNER_POINTER
14 #define NS_RETURNS_INNER_POINTER
15 #endif
16 #import <Cocoa/Cocoa.h>
17 
18 #ifdef VUO_COMPILER
20  "title" : "VuoClipboard",
21  "dependencies" : [
22  "AppKit.framework"
23  ]
24  });
25 #endif
26 
30 @interface VuoClipboardReader : NSObject
31 @end
32 
33 @implementation VuoClipboardReader
34 
38 + (VuoText) getClipboardContents
39 {
40  NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
41  NSData* data = [pasteBoard dataForType:NSPasteboardTypeString];
42  NSString* str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
43  VuoText txt = VuoText_make([str UTF8String]);
44  [str release];
45  return txt;
46 }
47 
51 + (void) setClipboardContents:(const char*) text
52 {
53  NSString* str = [[NSString alloc] initWithUTF8String:text];
54 
55  if([str length] < 1)
56  {
57  [str release];
58  return;
59  }
60 
61  [[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
62  [[NSPasteboard generalPasteboard] setString:str forType:NSPasteboardTypeString];
63  [str release];
64 }
65 
66 @end
67 
73 {
74  return [VuoClipboardReader getClipboardContents];
75 }
76 
81 {
82  [VuoClipboardReader setClipboardContents:text];
83 }