mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-28 15:39:10 +00:00
clipboard: add SDL_ClipboardMimeTypes
This function allows to retrieve the available mime types without doing any synthesizing.
This commit is contained in:
parent
0befa7d8e9
commit
f32e96f5e2
5 changed files with 58 additions and 1 deletions
|
@ -42,6 +42,20 @@ extern "C" {
|
|||
|
||||
/* Function prototypes */
|
||||
|
||||
/**
|
||||
* Retrieve the list of mime types available in the clipboard.
|
||||
*
|
||||
* \param num_mime_types a pointer filled with the number of mime types. May be NULL.
|
||||
* \returns a null terminated array of strings with mime types, or NULL on
|
||||
* failure; call SDL_GetError() for more information. This should be
|
||||
* freed with SDL_free() when it is no longer needed.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_SetClipboardData
|
||||
*/
|
||||
extern SDL_DECLSPEC char ** SDLCALL SDL_GetClipboardMimeTypes(size_t *num_mime_types);
|
||||
|
||||
/**
|
||||
* Put UTF-8 text into the clipboard.
|
||||
*
|
||||
|
|
|
@ -248,6 +248,7 @@ SDL3_0.0.0 {
|
|||
SDL_GetCameraSupportedFormats;
|
||||
SDL_GetCameras;
|
||||
SDL_GetClipboardData;
|
||||
SDL_GetClipboardMimeTypes;
|
||||
SDL_GetClipboardText;
|
||||
SDL_GetClosestFullscreenDisplayMode;
|
||||
SDL_GetCurrentAudioDriver;
|
||||
|
|
|
@ -273,6 +273,7 @@
|
|||
#define SDL_GetCameraSupportedFormats SDL_GetCameraSupportedFormats_REAL
|
||||
#define SDL_GetCameras SDL_GetCameras_REAL
|
||||
#define SDL_GetClipboardData SDL_GetClipboardData_REAL
|
||||
#define SDL_GetClipboardMimeTypes SDL_GetClipboardMimeTypes_REAL
|
||||
#define SDL_GetClipboardText SDL_GetClipboardText_REAL
|
||||
#define SDL_GetClosestFullscreenDisplayMode SDL_GetClosestFullscreenDisplayMode_REAL
|
||||
#define SDL_GetCurrentAudioDriver SDL_GetCurrentAudioDriver_REAL
|
||||
|
|
|
@ -294,6 +294,7 @@ SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetCameraProperties,(SDL_Camera *a),(a),ret
|
|||
SDL_DYNAPI_PROC(SDL_CameraSpec**,SDL_GetCameraSupportedFormats,(SDL_CameraID a, int *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_CameraID*,SDL_GetCameras,(int *a),(a),return)
|
||||
SDL_DYNAPI_PROC(void*,SDL_GetClipboardData,(const char *a, size_t *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(char **,SDL_GetClipboardMimeTypes,(size_t *a),(a),return)
|
||||
SDL_DYNAPI_PROC(char*,SDL_GetClipboardText,(void),(),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_GetClosestFullscreenDisplayMode,(SDL_DisplayID a, int b, int c, float d, bool e, SDL_DisplayMode *f),(a,b,c,d,e,f),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return)
|
||||
|
|
|
@ -53,6 +53,46 @@ void SDL_CancelClipboardData(Uint32 sequence)
|
|||
_this->clipboard_userdata = NULL;
|
||||
}
|
||||
|
||||
char **SDL_GetClipboardMimeTypes(size_t *num_mime_types)
|
||||
{
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
if (!_this) {
|
||||
SDL_SetError("Video subsystem must be initialized to query clipboard mime types");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t allocSize = sizeof(char *);
|
||||
for (size_t i = 0; i < _this->num_clipboard_mime_types; i++) {
|
||||
allocSize += strlen(_this->clipboard_mime_types[i]) + 1 + sizeof(char *);
|
||||
}
|
||||
|
||||
char *ret = SDL_malloc(allocSize);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
char **pointers = (char **)ret;
|
||||
ret += (_this->num_clipboard_mime_types + 1) * sizeof(char *);
|
||||
|
||||
for (size_t i = 0; i < _this->num_clipboard_mime_types; i++) {
|
||||
pointers[i] = ret;
|
||||
|
||||
char *mime_type = _this->clipboard_mime_types[i];
|
||||
/* copy the whole string including the terminating null char */
|
||||
char c;
|
||||
do {
|
||||
c = *mime_type;
|
||||
*ret = c;
|
||||
ret++;
|
||||
mime_type++;
|
||||
} while (c != 0);
|
||||
}
|
||||
|
||||
pointers[_this->num_clipboard_mime_types] = NULL;
|
||||
if (num_mime_types)
|
||||
*num_mime_types = _this->num_clipboard_mime_types;
|
||||
return pointers;
|
||||
}
|
||||
|
||||
bool SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types)
|
||||
{
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue