v/vlib/clipboard/clipboard_darwin.c.v

69 lines
1.3 KiB
V
Raw Normal View History

module clipboard
#include <libkern/OSAtomic.h>
#include <Cocoa/Cocoa.h>
#flag -framework Cocoa
2020-11-20 01:08:39 +01:00
#include "@VROOT/vlib/clipboard/clipboard_darwin.m"
pub struct Clipboard {
pb voidptr
last_cb_serial i64
mut:
foo int // TODO remove, for mut hack
}
2020-11-20 01:08:39 +01:00
fn C.darwin_new_pasteboard() voidptr
2020-11-20 03:28:28 +01:00
fn C.darwin_get_pasteboard_text(voidptr) byteptr
fn C.darwin_set_pasteboard_text(string) bool
2020-11-20 01:08:39 +01:00
fn new_clipboard() &Clipboard {
cb := &Clipboard{
2020-11-20 01:08:39 +01:00
pb: C.darwin_new_pasteboard()// pb
}
return cb
}
fn (cb &Clipboard) check_availability() bool {
return cb.pb != C.NULL
}
fn (mut cb Clipboard) clear() {
cb.foo = 0
cb.set_text('')
2020-11-20 11:58:53 +01:00
//#[cb->pb clearContents];
}
fn (mut cb Clipboard) free() {
cb.foo = 0
// nothing to free
}
fn (cb &Clipboard) has_ownership() bool {
if cb.last_cb_serial == 0 {
return false
}
2020-11-20 23:49:52 +01:00
//#return [cb->pb changeCount] == cb->last_cb_serial;
return false
}
2019-11-24 04:27:02 +01:00
fn C.OSAtomicCompareAndSwapLong()
2020-05-17 13:51:18 +02:00
fn (mut cb Clipboard) set_text(text string) bool {
2020-11-20 03:28:28 +01:00
return C.darwin_set_pasteboard_text(cb.pb, text)
}
2020-05-17 13:51:18 +02:00
fn (mut cb Clipboard) get_text() string {
cb.foo = 0
2020-11-20 01:08:39 +01:00
if isnil(cb.pb) {
return ''
}
utf8_clip := C.darwin_get_pasteboard_text(cb.pb)
return unsafe {utf8_clip.vstring()}
2019-11-18 11:10:31 +01:00
}
pub fn new_primary() &Clipboard {
panic('Primary clipboard is not supported on non-Linux systems.')
}