summaryrefslogtreecommitdiff
path: root/cocoa
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-01-08 17:06:37 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-01-08 17:06:37 +0000
commit94f13d85551f45d323ed8658f8e849214a5c60e6 (patch)
treee49f9de8b04081fba2bd0faa2c7673ecb40c7703 /cocoa
parent0bfc40618a7c9d40cacc5de3c34306c19ebaef1e (diff)
downloadnetsurf-94f13d85551f45d323ed8658f8e849214a5c60e6.tar.gz
netsurf-94f13d85551f45d323ed8658f8e849214a5c60e6.tar.bz2
Untested update for new clipboard API.
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/selection.m67
1 files changed, 47 insertions, 20 deletions
diff --git a/cocoa/selection.m b/cocoa/selection.m
index 6bba74d34..69707ba33 100644
--- a/cocoa/selection.m
+++ b/cocoa/selection.m
@@ -36,47 +36,74 @@ void gui_clear_selection(struct gui_window *g)
}
-void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
+/**
+ * Core asks front end for clipboard contents.
+ *
+ * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
+ * \param length Byte length of UTF-8 text in buffer
+ */
+void gui_get_clipboard(char **buffer, size_t *length)
{
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSString *string = [pb stringForType: NSStringPboardType];
+
+ *buffer = NULL;
+ *length = 0;
+
if (string) {
const char *text = [string UTF8String];
- browser_window_paste_text( [(BrowserViewController *)g browser], text, strlen(text), true );
+ *length = strlen(text);
+
+ *buffer = malloc(gui_clipboard.length);
+
+ if (*buffer != NULL) {
+ memcpy(*buffer, text, *length);
+ } else {
+ *length = 0;
+ }
}
}
-bool gui_empty_clipboard(void)
+/**
+ * Core tells front end to put given text in clipboard
+ *
+ * \param buffer UTF-8 text, owned by core
+ * \param length Byte length of UTF-8 text in buffer
+ * \param styles Array of styles given to text runs, owned by core, or NULL
+ * \param n_styles Number of text run styles in array
+ */
+void gui_set_clipboard(const char *buffer, size_t length,
+ nsclipboard_styles styles[], int n_styles)
{
+ /* Empty clipboard string */
if (nil == cocoa_clipboard_string) {
cocoa_clipboard_string = [[NSMutableString alloc] init];
} else {
[cocoa_clipboard_string setString: @""];
}
- return true;
-}
-bool gui_add_to_clipboard(const char *text, size_t length, bool space,
- const plot_font_style_t *fstyle)
-{
+ /* Add text to clipboard string */
if (nil == cocoa_clipboard_string) return false;
- [cocoa_clipboard_string appendString: [[[NSString alloc] initWithBytes: text
- length: length
- encoding: NSUTF8StringEncoding]
- autorelease]];
- if (space) [cocoa_clipboard_string appendString: @" "];
+ [cocoa_clipboard_string appendString: [[[NSString alloc]
+ initWithBytes: buffer
+ length: length
+ encoding: NSUTF8StringEncoding]
+ autorelease]];
- return true;
-}
-
-bool gui_commit_clipboard(void)
-{
+ /* Stick it on the pasteboard */
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
bool result = [pb setString: cocoa_clipboard_string forType: NSStringPboardType];
- if (result) gui_empty_clipboard();
- return result;
+
+ if (result) {
+ /* Empty clipboard string */
+ if (nil == cocoa_clipboard_string) {
+ cocoa_clipboard_string = [[NSMutableString alloc] init];
+ } else {
+ [cocoa_clipboard_string setString: @""];
+ }
+ }
}
bool gui_copy_to_clipboard(struct selection *s)