Update SDL3 from 3.2.4 to 3.2.20
This commit is contained in:
@@ -27,6 +27,37 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <UniformTypeIdentifiers/UTType.h>
|
||||
|
||||
extern void Cocoa_SetWindowHasModalDialog(SDL_Window *window, bool has_modal);
|
||||
|
||||
static void AddFileExtensionType(NSMutableArray *types, const char *pattern_ptr)
|
||||
{
|
||||
if (!*pattern_ptr) {
|
||||
return; // in case the string had an extra ';' at the end.
|
||||
}
|
||||
|
||||
// -[UTType typeWithFilenameExtension] will return nil if there's a period in the string. It's better to
|
||||
// allow too many files than not allow the one the user actually needs, so just take the part after the '.'
|
||||
const char *dot = SDL_strrchr(pattern_ptr, '.');
|
||||
NSString *extstr = [NSString stringWithFormat: @"%s", dot ? (dot + 1) : pattern_ptr];
|
||||
if (@available(macOS 11.0, *)) {
|
||||
UTType *uttype = [UTType typeWithFilenameExtension:extstr];
|
||||
if (uttype) { // still failed? Don't add the pattern. This is what the pre-macOS11 path does internally anyhow.
|
||||
[types addObject:uttype];
|
||||
}
|
||||
} else {
|
||||
[types addObject:extstr];
|
||||
}
|
||||
}
|
||||
|
||||
static void ReactivateAfterDialog(void)
|
||||
{
|
||||
for (NSRunningApplication *i in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) {
|
||||
[i activateWithOptions:0];
|
||||
break;
|
||||
}
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props)
|
||||
{
|
||||
SDL_Window* window = SDL_GetPointerProperty(props, SDL_PROP_FILE_DIALOG_WINDOW_POINTER, NULL);
|
||||
@@ -87,7 +118,7 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
|
||||
|
||||
if (filters) {
|
||||
// On macOS 11.0 and up, this is an array of UTType. Prior to that, it's an array of NSString
|
||||
NSMutableArray *types = [[NSMutableArray alloc] initWithCapacity:nfilters ];
|
||||
NSMutableArray *types = [[NSMutableArray alloc] initWithCapacity:nfilters];
|
||||
|
||||
int has_all_files = 0;
|
||||
for (int i = 0; i < nfilters; i++) {
|
||||
@@ -102,21 +133,14 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
|
||||
for (char *c = pattern; *c; c++) {
|
||||
if (*c == ';') {
|
||||
*c = '\0';
|
||||
if(@available(macOS 11.0, *)) {
|
||||
[types addObject: [UTType typeWithFilenameExtension:[NSString stringWithFormat: @"%s", pattern_ptr]]];
|
||||
} else {
|
||||
[types addObject: [NSString stringWithFormat: @"%s", pattern_ptr]];
|
||||
}
|
||||
AddFileExtensionType(types, pattern_ptr);
|
||||
pattern_ptr = c + 1;
|
||||
} else if (*c == '*') {
|
||||
has_all_files = 1;
|
||||
}
|
||||
}
|
||||
if(@available(macOS 11.0, *)) {
|
||||
[types addObject: [UTType typeWithFilenameExtension:[NSString stringWithFormat: @"%s", pattern_ptr]]];
|
||||
} else {
|
||||
[types addObject: [NSString stringWithFormat: @"%s", pattern_ptr]];
|
||||
}
|
||||
|
||||
AddFileExtensionType(types, pattern_ptr); // get the last piece of the string.
|
||||
|
||||
SDL_free(pattern);
|
||||
}
|
||||
@@ -141,6 +165,9 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
|
||||
|
||||
if (window) {
|
||||
w = (__bridge NSWindow *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
|
||||
if (w) {
|
||||
Cocoa_SetWindowHasModalDialog(window, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (w) {
|
||||
@@ -163,6 +190,9 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
|
||||
const char *files[1] = { NULL };
|
||||
callback(userdata, files, -1);
|
||||
}
|
||||
|
||||
Cocoa_SetWindowHasModalDialog(window, false);
|
||||
ReactivateAfterDialog();
|
||||
}];
|
||||
} else {
|
||||
if ([dialog runModal] == NSModalResponseOK) {
|
||||
@@ -182,6 +212,8 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
|
||||
const char *files[1] = { NULL };
|
||||
callback(userdata, files, -1);
|
||||
}
|
||||
|
||||
ReactivateAfterDialog();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ void windows_ShowFileDialog(void *ptr)
|
||||
|
||||
chosen_files_list[nfiles] = NULL;
|
||||
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, file_ptr, -1, chosen_folder, MAX_PATH, NULL, NULL) >= MAX_PATH) {
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, file_ptr, -1, chosen_folder, MAX_PATH, NULL, NULL) == 0) {
|
||||
SDL_SetError("Path too long or invalid character in path");
|
||||
SDL_free(chosen_files_list);
|
||||
callback(userdata, NULL, -1);
|
||||
@@ -273,7 +273,7 @@ void windows_ShowFileDialog(void *ptr)
|
||||
SDL_strlcpy(chosen_file, chosen_folder, MAX_PATH);
|
||||
chosen_file[chosen_folder_size] = '\\';
|
||||
|
||||
file_ptr += SDL_strlen(chosen_folder) + 1;
|
||||
file_ptr += SDL_wcslen(file_ptr) + 1;
|
||||
|
||||
while (*file_ptr) {
|
||||
nfiles++;
|
||||
@@ -295,7 +295,7 @@ void windows_ShowFileDialog(void *ptr)
|
||||
|
||||
int diff = ((int) chosen_folder_size) + 1;
|
||||
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, file_ptr, -1, chosen_file + diff, MAX_PATH - diff, NULL, NULL) >= MAX_PATH - diff) {
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, file_ptr, -1, chosen_file + diff, MAX_PATH - diff, NULL, NULL) == 0) {
|
||||
SDL_SetError("Path too long or invalid character in path");
|
||||
|
||||
for (size_t i = 0; i < nfiles - 1; i++) {
|
||||
@@ -308,7 +308,7 @@ void windows_ShowFileDialog(void *ptr)
|
||||
return;
|
||||
}
|
||||
|
||||
file_ptr += SDL_strlen(chosen_file) + 1 - diff;
|
||||
file_ptr += SDL_wcslen(file_ptr) + 1;
|
||||
|
||||
chosen_files_list[nfiles - 1] = SDL_strdup(chosen_file);
|
||||
|
||||
@@ -516,6 +516,14 @@ static void ShowFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_
|
||||
|
||||
filters_str = win_get_filters(filters, nfilters);
|
||||
|
||||
DWORD flags = 0;
|
||||
if (allow_many) {
|
||||
flags |= OFN_ALLOWMULTISELECT;
|
||||
}
|
||||
if (is_save) {
|
||||
flags |= OFN_OVERWRITEPROMPT;
|
||||
}
|
||||
|
||||
if (!filters_str && filters) {
|
||||
callback(userdata, NULL, -1);
|
||||
SDL_free(args);
|
||||
@@ -526,7 +534,7 @@ static void ShowFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_
|
||||
args->filters_str = filters_str;
|
||||
args->default_file = default_location ? SDL_strdup(default_location) : NULL;
|
||||
args->parent = window;
|
||||
args->flags = allow_many ? OFN_ALLOWMULTISELECT : 0;
|
||||
args->flags = flags;
|
||||
args->callback = callback;
|
||||
args->userdata = userdata;
|
||||
args->title = title ? SDL_strdup(title) : NULL;
|
||||
|
||||
Reference in New Issue
Block a user