NetSurf
clipboard.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Michael Drake <tlsa@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/** \file
20 * nsfb internal clipboard handling
21 */
22
23#include <assert.h>
24#include <stdint.h>
25#include <string.h>
26#include <stdlib.h>
27
28#include "utils/log.h"
30#include "netsurf/clipboard.h"
31
32#include "framebuffer/gui.h"
34
35
36static struct gui_clipboard {
37 char *buffer;
38 size_t buffer_len;
39 size_t length;
41
42
43/**
44 * Core asks front end for clipboard contents.
45 *
46 * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
47 * \param length Byte length of UTF-8 text in buffer
48 */
49static void gui_get_clipboard(char **buffer, size_t *length)
50{
51 *buffer = NULL;
52 *length = 0;
53
54 if (gui_clipboard.length > 0) {
55 assert(gui_clipboard.buffer != NULL);
56 NSLOG(netsurf, INFO, "Pasting %zd bytes: \"%s\"\n",
58
59 *buffer = malloc(gui_clipboard.length);
60
61 if (*buffer != NULL) {
64 *length = gui_clipboard.length;
65 }
66 }
67}
68
69
70/**
71 * Core tells front end to put given text in clipboard
72 *
73 * \param buffer UTF-8 text, owned by core
74 * \param length Byte length of UTF-8 text in buffer
75 * \param styles Array of styles given to text runs, owned by core, or NULL
76 * \param n_styles Number of text run styles in array
77 */
78static void gui_set_clipboard(const char *buffer, size_t length,
79 nsclipboard_styles styles[], int n_styles)
80{
81 if (gui_clipboard.buffer_len < length + 1) {
82 /* Make buffer big enough */
83 char *new_buff;
84
85 new_buff = realloc(gui_clipboard.buffer, length + 1);
86 if (new_buff == NULL)
87 return;
88
89 gui_clipboard.buffer = new_buff;
90 gui_clipboard.buffer_len = length + 1;
91 }
92
94
95 memcpy(gui_clipboard.buffer, buffer, length);
96 gui_clipboard.length = length;
98}
99
102 .set = gui_set_clipboard,
103};
104
Browser window creation and manipulation interface.
static osspriteop_area * buffer
The buffer characteristics.
Definition: buffer.c:55
static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles)
Core tells front end to put given text in clipboard.
Definition: clipboard.c:78
static void gui_get_clipboard(char **buffer, size_t *length)
Core asks front end for clipboard contents.
Definition: clipboard.c:49
struct gui_clipboard_table * framebuffer_clipboard_table
Definition: clipboard.c:105
static struct gui_clipboard_table clipboard_table
Definition: clipboard.c:100
static struct gui_clipboard gui_clipboard
Interface to platform-specific clipboard operations.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
Interface to utility string handling.
function table for clipboard operations.
Definition: clipboard.h:42
void(* get)(char **buffer, size_t *length)
Core asks front end for clipboard contents.
Definition: clipboard.h:49
char * buffer
Definition: clipboard.c:37
size_t length
Definition: clipboard.c:39
size_t buffer_len
Definition: clipboard.c:38