ui/cocoa/toolkit.m

changeset 26
a137277f9173
parent 25
78ae3efe463f
child 29
c96169444d88
equal deleted inserted replaced
25:78ae3efe463f 26:a137277f9173
84 [NSApp run]; 84 [NSApp run];
85 [pool release]; 85 [pool release];
86 } 86 }
87 87
88 88
89 void ui_clipboard_set(char *str) {
90 NSString *string = [[NSString alloc] initWithUTF8String:str];
91 NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard];
92 [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
93 [pasteBoard setString:string forType:NSStringPboardType];
94 }
95
96 char* ui_clipboard_get() {
97 NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard];
98 NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil];
99 NSDictionary *options = [NSDictionary dictionary];
100 NSArray *data = [pasteBoard readObjectsForClasses:classes options:options];
101
102 if(data != nil) {
103 NSString *str = [data componentsJoinedByString: @""];
104
105 // copy C string
106 size_t length = [str lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
107 const char *cstr = [str UTF8String];
108 char *value = malloc(length + 1);
109 memcpy(value, cstr, length);
110 value[length] = '\0';
111
112 return value;
113 } else {
114 return NULL;
115 }
116 }
89 117
90 @implementation EventWrapper 118 @implementation EventWrapper
91 119
92 - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f { 120 - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f {
93 data = d; 121 data = d;

mercurial