Added SDL_CleanupEvent()

This is used to free any dynamically allocated memory in events.
This commit is contained in:
Sam Lantinga
2023-11-04 00:55:55 -07:00
parent c4bf05fd9d
commit 7e445da569
20 changed files with 146 additions and 232 deletions

View File

@@ -2191,33 +2191,19 @@ static void text_input_preedit_string(void *data,
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
text_input->has_preedit = SDL_TRUE;
if (text) {
if (SDL_GetHintBoolean(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, SDL_FALSE)) {
int cursor_begin_utf8 = cursor_begin >= 0 ? (int)SDL_utf8strnlen(text, cursor_begin) : -1;
int cursor_end_utf8 = cursor_end >= 0 ? (int)SDL_utf8strnlen(text, cursor_end) : -1;
int cursor_size_utf8;
if (cursor_end_utf8 >= 0) {
if (cursor_begin_utf8 >= 0) {
cursor_size_utf8 = cursor_end_utf8 - cursor_begin_utf8;
} else {
cursor_size_utf8 = cursor_end_utf8;
}
int cursor_begin_utf8 = cursor_begin >= 0 ? (int)SDL_utf8strnlen(text, cursor_begin) : -1;
int cursor_end_utf8 = cursor_end >= 0 ? (int)SDL_utf8strnlen(text, cursor_end) : -1;
int cursor_size_utf8;
if (cursor_end_utf8 >= 0) {
if (cursor_begin_utf8 >= 0) {
cursor_size_utf8 = cursor_end_utf8 - cursor_begin_utf8;
} else {
cursor_size_utf8 = -1;
cursor_size_utf8 = cursor_end_utf8;
}
SDL_SendEditingText(text, cursor_begin_utf8, cursor_size_utf8);
} else {
int text_bytes = (int)SDL_strlen(text), i = 0;
int cursor = 0;
do {
const int sz = (int)SDL_utf8strlcpy(buf, text + i, sizeof(buf));
const int chars = (int)SDL_utf8strlen(buf);
SDL_SendEditingText(buf, cursor, chars);
i += sz;
cursor += chars;
} while (i < text_bytes);
cursor_size_utf8 = -1;
}
SDL_SendEditingText(text, cursor_begin_utf8, cursor_size_utf8);
} else {
buf[0] = '\0';
SDL_SendEditingText(buf, 0, 0);