1#ifndef SDL3PP_CLIPBOARD_H_
2#define SDL3PP_CLIPBOARD_H_
4#include <SDL3/SDL_clipboard.h>
5#include "SDL3pp_stdinc.h"
132 CheckError(SDL_SetPrimarySelectionText(text));
194 const char* mime_type,
276 std::span<const char*> mime_types)
279 callback, cleanup, userdata, mime_types.data(), mime_types.size()));
312 std::span<const char*> mime_types)
317 s_callback = callback;
320 [](
void*,
const char* mime_type,
size_t* size) ->
const void* {
321 auto source = s_callback(mime_type);
322 *size = source.size_bytes();
323 return source.data();
326 if (s_cleanup) s_cleanup();
365 auto data = SDL_GetClipboardData(mime_type, &count);
366 if (!data)
return {};
391 auto data = SDL_GetClipboardData(mime_type, &count);
392 if (!data)
return {};
393 return OwnArray<T>{
static_cast<T*
>(data), count /
sizeof(T)};
412 return SDL_HasClipboardData(mime_type);
430 auto data = SDL_GetClipboardMimeTypes(&count);
431 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:98
OwnArray< char * > GetClipboardMimeTypes()
Retrieve the list of mime types available in the clipboard.
Definition: SDL3pp_clipboard.h:427
bool HasClipboardText()
Query whether the clipboard exists and contains a non-empty text string.
Definition: SDL3pp_clipboard.h:115
void(SDLCALL *)(void *userdata) ClipboardCleanupCallback
Callback function that will be called when the clipboard is cleared, or when new data is set.
Definition: SDL3pp_clipboard.h:230
OwnArray< T > GetClipboardDataAs(StringParam mime_type)
Get the data from the clipboard for a given mime type.
Definition: SDL3pp_clipboard.h:388
bool HasClipboardData(StringParam mime_type)
Query whether there is data in the clipboard for the provided mime type.
Definition: SDL3pp_clipboard.h:410
void ClearClipboardData()
Clear the clipboard data.
Definition: SDL3pp_clipboard.h:343
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:76
const void *(SDLCALL *)(void *userdata, const char *mime_type, size_t *size) ClipboardDataCallback
Callback function that will be called when data for the specified mime-type is requested by the OS.
Definition: SDL3pp_clipboard.h:195
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:242
void SetClipboardData(ClipboardDataCallback callback, ClipboardCleanupCallback cleanup, void *userdata, std::span< const char * > mime_types)
Offer clipboard data to the OS.
Definition: SDL3pp_clipboard.h:273
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:218
void SetPrimarySelectionText(StringParam text)
Put UTF-8 text into the primary selection.
Definition: SDL3pp_clipboard.h:130
StringResult GetClipboardData(StringParam mime_type)
Get the data from the clipboard for a given mime type.
Definition: SDL3pp_clipboard.h:362
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
Main include header for the SDL3pp library.
A simple std::string-like interface for SDL allocated strings.
Definition: SDL3pp_strings.h:153