mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-16 23:06:03 +00:00
Minor cleanup
This commit is contained in:
@@ -42,21 +42,6 @@ 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.
|
||||
*
|
||||
@@ -255,6 +240,21 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetClipboardData(const char *mime_type, s
|
||||
*/
|
||||
extern SDL_DECLSPEC bool SDLCALL SDL_HasClipboardData(const char *mime_type);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -133,14 +133,13 @@ typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * cons
|
||||
* the selected filter.
|
||||
* \param userdata an optional pointer to pass extra data to the callback when
|
||||
* it will be invoked.
|
||||
* \param window the window that the dialog should be modal for. May be NULL.
|
||||
* \param window the window that the dialog should be modal for, may be NULL.
|
||||
* Not all platforms support this option.
|
||||
* \param filters a list of SDL_DialogFileFilter's. May be NULL. Not all
|
||||
* \param filters a list of SDL_DialogFileFilter's, may be NULL. Not all
|
||||
* platforms support this option, and platforms that do support
|
||||
* it may allow the user to ignore the filters.
|
||||
* \param nfilters the number of filters. Ignored if filters is NULL.
|
||||
* \param default_location the default folder or file to start the dialog at.
|
||||
* May be NULL. Not all platforms support this option.
|
||||
* \param default_location the default folder or file to start the dialog at, may be NULL. Not all platforms support this option.
|
||||
* \param allow_many if non-zero, the user will be allowed to select multiple
|
||||
* entries. Not all platforms support this option.
|
||||
*
|
||||
@@ -190,14 +189,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback c
|
||||
* the selected filter.
|
||||
* \param userdata an optional pointer to pass extra data to the callback when
|
||||
* it will be invoked.
|
||||
* \param window the window that the dialog should be modal for. May be NULL.
|
||||
* \param window the window that the dialog should be modal for, may be NULL.
|
||||
* Not all platforms support this option.
|
||||
* \param filters a list of SDL_DialogFileFilter's. May be NULL. Not all
|
||||
* \param filters a list of SDL_DialogFileFilter's, may be NULL. Not all
|
||||
* platforms support this option, and platforms that do support
|
||||
* it may allow the user to ignore the filters.
|
||||
* \param nfilters the number of filters. Ignored if filters is NULL.
|
||||
* \param default_location the default folder or file to start the dialog at.
|
||||
* May be NULL. Not all platforms support this option.
|
||||
* \param default_location the default folder or file to start the dialog at, may be NULL. Not all platforms support this option.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
@@ -241,10 +239,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback c
|
||||
* argument is always -1 for SDL_ShowOpenFolderDialog.
|
||||
* \param userdata an optional pointer to pass extra data to the callback when
|
||||
* it will be invoked.
|
||||
* \param window the window that the dialog should be modal for. May be NULL.
|
||||
* \param window the window that the dialog should be modal for, may be NULL.
|
||||
* Not all platforms support this option.
|
||||
* \param default_location the default folder or file to start the dialog at.
|
||||
* May be NULL. Not all platforms support this option.
|
||||
* \param default_location the default folder or file to start the dialog at, may be NULL. Not all platforms support this option.
|
||||
* \param allow_many if non-zero, the user will be allowed to select multiple
|
||||
* entries. Not all platforms support this option.
|
||||
*
|
||||
|
@@ -4048,7 +4048,7 @@ size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
|
||||
*
|
||||
* \param a the multiplicand.
|
||||
* \param b the multiplier.
|
||||
* \param ret on non-overflow output, stores the multiplication result. May
|
||||
* \param ret on non-overflow output, stores the multiplication result, may
|
||||
* not be NULL.
|
||||
* \returns false on overflow, true if result is multiplied without overflow.
|
||||
*
|
||||
@@ -4087,7 +4087,7 @@ SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, si
|
||||
*
|
||||
* \param a the first addend.
|
||||
* \param b the second addend.
|
||||
* \param ret on non-overflow output, stores the addition result. May not be
|
||||
* \param ret on non-overflow output, stores the addition result, may not be
|
||||
* NULL.
|
||||
* \returns false on overflow, true if result is added without overflow.
|
||||
*
|
||||
|
@@ -53,46 +53,6 @@ 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();
|
||||
@@ -272,6 +232,46 @@ bool SDL_HasClipboardData(const char *mime_type)
|
||||
}
|
||||
}
|
||||
|
||||
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 += sizeof(char *) + SDL_strlen(_this->clipboard_mime_types[i]) + 1;
|
||||
}
|
||||
|
||||
char *ret = (char *)SDL_malloc(allocSize);
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char **result = (char **)ret;
|
||||
ret += sizeof(char *) * (_this->num_clipboard_mime_types + 1);
|
||||
|
||||
for (size_t i = 0; i < _this->num_clipboard_mime_types; i++) {
|
||||
result[i] = ret;
|
||||
|
||||
const char *mime_type = _this->clipboard_mime_types[i];
|
||||
// Copy the whole string including the terminating null char
|
||||
char c;
|
||||
do {
|
||||
c = *ret++ = *mime_type++;
|
||||
} while (c != '\0');
|
||||
}
|
||||
result[_this->num_clipboard_mime_types] = NULL;
|
||||
|
||||
if (num_mime_types) {
|
||||
*num_mime_types = _this->num_clipboard_mime_types;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Clipboard text
|
||||
|
||||
bool SDL_IsTextMimeType(const char *mime_type)
|
||||
|
Reference in New Issue
Block a user