docs
Loading...
Searching...
No Matches
CAPI_Clipboard.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5
6///
7/// @file CAPI_Clipboard.h
8///
9/// User-defined clipboard interface.
10///
11/// `#include <Ultralight/CAPI/CAPI_Clipboard.h>`
12///
13/// The library uses this to read and write data to the system's clipboard, as whole
14/// multi-format payloads (ULClipboardData: an ordered set of (type, value) entries keyed by a
15/// MIME type or an application-defined type string).
16///
17/// The library currently reads and writes these well-known types: `text/plain`, `text/html`,
18/// and `text/uri-list`. Your implementation should map each type it supports to the matching OS
19/// clipboard format and simply skip types it doesn't recognize.
20///
21/// @note The library only calls the ULClipboard callbacks on the thread you created the Renderer
22/// or App on, so your implementation doesn't need to be safe to call from more than one
23/// thread.
24///
25/// @see ulPlatformSetClipboard()
26///
27#ifndef ULTRALIGHT_CAPI_CLIPBOARD_H
28#define ULTRALIGHT_CAPI_CLIPBOARD_H
29
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/******************************************************************************
37 * ClipboardData
38 *****************************************************************************/
39
40///
41/// Create an empty clipboard payload.
42///
43/// @return Returns a payload you own; call ulDestroyClipboardData() when finished (unless
44/// you return it from a ULClipboardReadCallback, where the library consumes it).
45///
47
48///
49/// Create a clipboard payload holding a single `text/plain` entry.
50///
51/// @return Returns a payload you own; call ulDestroyClipboardData() when finished (unless
52/// you return it from a ULClipboardReadCallback, where the library consumes it).
53///
55
56///
57/// Create another owned reference to an existing clipboard payload.
58///
59/// You can use this to keep a payload that was passed to you as a borrowed handle (eg, the
60/// payload passed to your ULClipboardWriteCallback) beyond the call that provided it.
61///
62/// @return Returns a new owned reference; call ulDestroyClipboardData() when finished.
63///
65
66///
67/// Destroy a clipboard payload (you should only destroy payloads you have explicitly created
68/// via the functions above).
69///
71
72///
73/// Set the text value for a type, replacing any existing entry with the same type.
74///
75/// Use bare MIME types (`text/plain`, not `text/plain;charset=utf-8`)-- the library normalizes
76/// charset-suffixed spellings at its own boundaries.
77///
79
80///
81/// Set the bytes value for a type, replacing any existing entry with the same type.
82///
83/// @note The payload retains `bytes`; you can still destroy your ULBuffer afterwards.
84///
86
87///
88/// Get the text value for a type.
89///
90/// @return Returns a new string, or NULL when there is no entry for `type` or its value isn't
91/// text. Destroy the returned string via ulDestroyString() when done.
92///
94
95///
96/// Get the bytes value for a type.
97///
98/// @return Returns a new buffer, or NULL when there is no entry for `type` or its value isn't
99/// bytes. Destroy the returned buffer via ulDestroyBuffer() when done.
100///
102
103///
104/// Whether or not the entry for a type holds text.
105///
107
108///
109/// Whether or not an entry exists for a type.
110///
112
113///
114/// Remove the entry for a type (does nothing if no such entry exists).
115///
117
118///
119/// Get the number of entries.
120///
122
123///
124/// Get the type of the entry at a certain index, in insertion order.
125///
126/// @return Returns a new string, or NULL when `index` is out of range. Destroy the returned
127/// string via ulDestroyString() when done.
128///
130
131///
132/// Get the URL of the document this payload came from (can be empty).
133///
134/// @return Returns a new string. Destroy the returned string via ulDestroyString() when done.
135///
137
138///
139/// Set the URL of the document this payload came from.
140///
141/// The library sets this when copying page content; on Windows it becomes the HTML clipboard
142/// format's SourceURL.
143///
145
146/******************************************************************************
147 * Clipboard
148 *****************************************************************************/
149
150///
151/// The callback invoked when the library wants to clear the system's clipboard.
152///
153typedef void (*ULClipboardClearCallback)(void* user_data);
154
155///
156/// The callback invoked when the library wants to read from the system's clipboard.
157///
158/// You should return a payload you created via ulCreateClipboardData() holding one entry per
159/// format you can read (at minimum the `text/plain` entry, if the clipboard holds text). The
160/// library takes ownership of the result and will call ulDestroyClipboardData() when done.
161///
162/// You can return NULL for an empty clipboard.
163///
164typedef ULClipboardData (*ULClipboardReadCallback)(void* user_data);
165
166///
167/// The callback invoked when the library wants to write a payload to the system's clipboard,
168/// replacing its previous contents.
169///
170/// You should write all of the payload's entries in one atomic clipboard transaction (on
171/// Windows: one OpenClipboard / EmptyClipboard / SetClipboardData per entry / CloseClipboard
172/// cycle), skipping any types you don't support.
173///
174/// @note `data` is borrowed: valid only until the callback returns. Use
175/// ulCreateClipboardDataRef() to keep it beyond that (eg, for delayed rendering).
176///
177typedef void (*ULClipboardWriteCallback)(void* user_data, ULClipboardData data);
178
179///
180/// User-defined clipboard interface.
181///
182/// You should implement each of these callbacks, then pass an instance of this struct containing
183/// your callbacks to ulPlatformSetClipboard().
184///
185typedef struct {
186 ///
187 /// A user-defined pointer passed to every callback (can be NULL).
188 ///
190
191 ///
192 /// Called to clear the system's clipboard.
193 ///
195
196 ///
197 /// Called to read the system clipboard's current contents.
198 ///
200
201 ///
202 /// Called to write a payload to the system's clipboard.
203 ///
206
207#ifdef __cplusplus
208} // extern "C"
209#endif
210
211#endif // ULTRALIGHT_CAPI_CLIPBOARD_H
ULClipboardData ulCreateClipboardDataFromText(ULString text)
Create a clipboard payload holding a single text/plain entry.
bool ulClipboardDataHas(ULClipboardData data, ULString type)
Whether or not an entry exists for a type.
ULClipboardData ulCreateClipboardData(void)
Create an empty clipboard payload.
void ulClipboardDataSetText(ULClipboardData data, ULString type, ULString text)
Set the text value for a type, replacing any existing entry with the same type.
void ulClipboardDataRemove(ULClipboardData data, ULString type)
Remove the entry for a type (does nothing if no such entry exists).
void ulClipboardDataSetSourceURL(ULClipboardData data, ULString url)
Set the URL of the document this payload came from.
ULBuffer ulClipboardDataGetBytes(ULClipboardData data, ULString type)
Get the bytes value for a type.
size_t ulClipboardDataGetSize(ULClipboardData data)
Get the number of entries.
ULString ulClipboardDataGetSourceURL(ULClipboardData data)
Get the URL of the document this payload came from (can be empty).
void ulDestroyClipboardData(ULClipboardData data)
Destroy a clipboard payload (you should only destroy payloads you have explicitly created via the fun...
ULString ulClipboardDataGetText(ULClipboardData data, ULString type)
Get the text value for a type.
bool ulClipboardDataIsText(ULClipboardData data, ULString type)
Whether or not the entry for a type holds text.
ULClipboardData(*) ULClipboardReadCallback(void *user_data)
The callback invoked when the library wants to read from the system's clipboard.
Definition CAPI_Clipboard.h:164
ULString ulClipboardDataGetTypeAt(ULClipboardData data, size_t index)
Get the type of the entry at a certain index, in insertion order.
void(*) ULClipboardClearCallback(void *user_data)
The callback invoked when the library wants to clear the system's clipboard.
Definition CAPI_Clipboard.h:153
ULClipboardData ulCreateClipboardDataRef(ULClipboardData data)
Create another owned reference to an existing clipboard payload.
void(*) ULClipboardWriteCallback(void *user_data, ULClipboardData data)
The callback invoked when the library wants to write a payload to the system's clipboard,...
Definition CAPI_Clipboard.h:177
void ulClipboardDataSetBytes(ULClipboardData data, ULString type, ULBuffer bytes)
Set the bytes value for a type, replacing any existing entry with the same type.
Various defines and utility functions for the C API.
struct C_ClipboardData * ULClipboardData
Definition CAPI_Defines.h:101
struct C_String * ULString
Opaque handle to a String object.
Definition CAPI_Defines.h:96
#define ULExport
Definition CAPI_Defines.h:42
struct C_Buffer * ULBuffer
Opaque handle to a Buffer object.
Definition CAPI_Defines.h:99
User-defined clipboard interface.
Definition CAPI_Clipboard.h:185
void * user_data
A user-defined pointer passed to every callback (can be NULL).
Definition CAPI_Clipboard.h:189
ULClipboardWriteCallback write
Called to write a payload to the system's clipboard.
Definition CAPI_Clipboard.h:204
ULClipboardClearCallback clear
Called to clear the system's clipboard.
Definition CAPI_Clipboard.h:194
ULClipboardReadCallback read
Called to read the system clipboard's current contents.
Definition CAPI_Clipboard.h:199