1#ifndef SDL3PP_CLIPBOARD_H_
2#define SDL3PP_CLIPBOARD_H_
4#include <SDL3/SDL_clipboard.h>
5#include "SDL3pp_stdinc.h"
133 CheckError(SDL_SetPrimarySelectionText(text));
273 std::span<const char*> mime_types)
276 callback, cleanup, userdata, mime_types.data(), mime_types.size()));
309 std::span<const char*> mime_types)
314 s_callback = callback;
317 [](
void*,
const char* mime_type,
size_t* size) ->
const void* {
318 auto source = s_callback(mime_type);
319 *size = source.size_bytes();
320 return source.data();
323 if (s_cleanup) s_cleanup();
362 auto data = SDL_GetClipboardData(mime_type, &count);
363 if (!data)
return {};
388 auto data = SDL_GetClipboardData(mime_type, &count);
389 if (!data)
return {};
390 return OwnArray<T>{
static_cast<T*
>(data), count /
sizeof(T)};
409 return SDL_HasClipboardData(mime_type);
427 auto data = SDL_GetClipboardMimeTypes(&count);
428 if (!data)
return {};
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
Source byte stream.
Definition: SDL3pp_strings.h:239
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
StringResult GetClipboardText()
Get UTF-8 text from the clipboard.
Definition: SDL3pp_clipboard.h:99
OwnArray< char * > GetClipboardMimeTypes()
Retrieve the list of mime types available in the clipboard.
Definition: SDL3pp_clipboard.h:424
bool HasClipboardText()
Query whether the clipboard exists and contains a non-empty text string.
Definition: SDL3pp_clipboard.h:116
SDL_ClipboardCleanupCallback ClipboardCleanupCallback
Callback function that will be called when the clipboard is cleared, or when new data is set.
Definition: SDL3pp_clipboard.h:228
OwnArray< T > GetClipboardDataAs(StringParam mime_type)
Get the data from the clipboard for a given mime type.
Definition: SDL3pp_clipboard.h:385
bool HasClipboardData(StringParam mime_type)
Query whether there is data in the clipboard for the provided mime type.
Definition: SDL3pp_clipboard.h:407
void ClearClipboardData()
Clear the clipboard data.
Definition: SDL3pp_clipboard.h:340
StringResult GetPrimarySelectionText()
Get UTF-8 text from the primary selection.
Definition: SDL3pp_clipboard.h:152
void SetClipboardText(StringParam text)
Put UTF-8 text into the clipboard.
Definition: SDL3pp_clipboard.h:78
std::function< void()> ClipboardCleanupCB
Callback function that will be called when the clipboard is cleared, or when new data is set.
Definition: SDL3pp_clipboard.h:239
void SetClipboardData(ClipboardDataCallback callback, ClipboardCleanupCallback cleanup, void *userdata, std::span< const char * > mime_types)
Offer clipboard data to the OS.
Definition: SDL3pp_clipboard.h:270
bool HasPrimarySelectionText()
Query whether the primary selection exists and contains a non-empty text string.
Definition: SDL3pp_clipboard.h:170
std::function< SourceBytes(const char *mime_type)> ClipboardDataCB
Callback function that will be called when data for the specified mime-type is requested by the OS.
Definition: SDL3pp_clipboard.h:216
void SetPrimarySelectionText(StringParam text)
Put UTF-8 text into the primary selection.
Definition: SDL3pp_clipboard.h:131
StringResult GetClipboardData(StringParam mime_type)
Get the data from the clipboard for a given mime type.
Definition: SDL3pp_clipboard.h:359
SDL_ClipboardDataCallback ClipboardDataCallback
Callback function that will be called when data for the specified mime-type is requested by the OS.
Definition: SDL3pp_clipboard.h:193
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
Main include header for the SDL3pp library.
A simple std::string-like interface for SDL allocated strings.
Definition: SDL3pp_strings.h:153