1#ifndef SDL3PP_CLIPBOARD_H_
2#define SDL3PP_CLIPBOARD_H_
4#include <SDL3/SDL_clipboard.h>
5#include "SDL3pp_stdinc.h"
134 CheckError(SDL_SetPrimarySelectionText(text));
278 std::span<const char*> mime_types)
281 callback, cleanup, userdata, mime_types.data(), mime_types.size()));
313 std::span<const char*> mime_types)
318 s_callback = callback;
321 [](
void*,
const char* mime_type,
size_t* size) ->
const void* {
322 auto source = s_callback(mime_type);
323 *size = source.size_bytes;
327 if (s_cleanup) s_cleanup();
366 auto data = SDL_GetClipboardData(mime_type, &count);
367 if (!data)
return {};
392 auto data = SDL_GetClipboardData(mime_type, &count);
393 if (!data)
return {};
394 return OwnArray<T>{
static_cast<T*
>(data), count /
sizeof(T)};
413 return SDL_HasClipboardData(mime_type);
431 auto data = SDL_GetClipboardMimeTypes(&count);
432 if (!data)
return {};
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
StringResult GetClipboardText()
Get UTF-8 text from the clipboard.
Definition SDL3pp_clipboard.h:100
OwnArray< char * > GetClipboardMimeTypes()
Retrieve the list of mime types available in the clipboard.
Definition SDL3pp_clipboard.h:428
bool HasClipboardText()
Query whether the clipboard exists and contains a non-empty text string.
Definition SDL3pp_clipboard.h:117
SDL_ClipboardCleanupCallback ClipboardCleanupCallback
Callback function that will be called when the clipboard is cleared, or new data is set.
Definition SDL3pp_clipboard.h:232
OwnArray< T > GetClipboardDataAs(StringParam mime_type)
Get the data from clipboard for a given mime type.
Definition SDL3pp_clipboard.h:389
bool HasClipboardData(StringParam mime_type)
Query whether there is data in the clipboard for the provided mime type.
Definition SDL3pp_clipboard.h:411
void ClearClipboardData()
Clear the clipboard data.
Definition SDL3pp_clipboard.h:344
StringResult GetPrimarySelectionText()
Get UTF-8 text from the primary selection.
Definition SDL3pp_clipboard.h:153
void SetClipboardText(StringParam text)
Put UTF-8 text into the clipboard.
Definition SDL3pp_clipboard.h:79
std::function< void()> ClipboardCleanupCB
Callback function that will be called when the clipboard is cleared, or new data is set.
Definition SDL3pp_clipboard.h:245
void SetClipboardData(ClipboardDataCallback callback, ClipboardCleanupCallback cleanup, void *userdata, std::span< const char * > mime_types)
Offer clipboard data to the OS.
Definition SDL3pp_clipboard.h:275
bool HasPrimarySelectionText()
Query whether the primary selection exists and contains a non-empty text string.
Definition SDL3pp_clipboard.h:171
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:220
void SetPrimarySelectionText(StringParam text)
Put UTF-8 text into the primary selection.
Definition SDL3pp_clipboard.h:132
StringResult GetClipboardData(StringParam mime_type)
Get the data from clipboard for a given mime type.
Definition SDL3pp_clipboard.h:363
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:195
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
Source byte stream.
Definition SDL3pp_strings.h:239
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:153