diff options
| -rw-r--r-- | CMake/fl_add_library.cmake | 5 | ||||
| -rw-r--r-- | CMake/setup.cmake | 6 | ||||
| -rw-r--r-- | CMake/variables.cmake | 5 | ||||
| -rw-r--r-- | configure.ac | 4 | ||||
| -rw-r--r-- | src/Fl_Native_File_Chooser_MAC.mm | 25 |
5 files changed, 42 insertions, 3 deletions
diff --git a/CMake/fl_add_library.cmake b/CMake/fl_add_library.cmake index d33b4d8ba..3f57e7a3d 100644 --- a/CMake/fl_add_library.cmake +++ b/CMake/fl_add_library.cmake @@ -154,6 +154,11 @@ function(fl_add_library LIBNAME LIBTYPE SOURCES) if(APPLE AND NOT FLTK_BACKEND_X11) target_link_libraries(${TARGET_NAME} PUBLIC "-framework Cocoa") + if(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 20.0.0)) # a.k.a. macOS version ≥ 11.0 + if (NOT (CMAKE_OSX_ARCHITECTURES STREQUAL "ppc" OR CMAKE_OSX_ARCHITECTURES STREQUAL "i386")) + target_link_libraries(${TARGET_NAME} PUBLIC "-framework UniformTypeIdentifiers") + endif() + endif() endif() # we must link fltk with cairo if Cairo or Wayland is enabled (or both) diff --git a/CMake/setup.cmake b/CMake/setup.cmake index b663813be..69835fcb8 100644 --- a/CMake/setup.cmake +++ b/CMake/setup.cmake @@ -126,6 +126,12 @@ if(APPLE) else() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Cocoa") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework Cocoa") + if(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 20.0.0)) # a.k.a. macOS version ≥ 11.0 + if (NOT (CMAKE_OSX_ARCHITECTURES STREQUAL "ppc" OR CMAKE_OSX_ARCHITECTURES STREQUAL "i386")) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework UniformTypeIdentifiers") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework UniformTypeIdentifiers") + endif() + endif() endif(FLTK_BACKEND_X11) endif(APPLE) diff --git a/CMake/variables.cmake b/CMake/variables.cmake index 3d37aecad..981cd077c 100644 --- a/CMake/variables.cmake +++ b/CMake/variables.cmake @@ -44,6 +44,11 @@ if(WIN32) list(APPEND FLTK_LDLIBS -lole32 -luuid -lcomctl32 -lws2_32) elseif(APPLE AND NOT FLTK_BACKEND_X11) list(APPEND FLTK_LDLIBS "-framework Cocoa") + if(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 20.0.0)) # a.k.a. macOS version ≥ 11.0 + if (NOT (CMAKE_OSX_ARCHITECTURES STREQUAL "ppc" OR CMAKE_OSX_ARCHITECTURES STREQUAL "i386")) + list(APPEND FLTK_LDLIBS "-framework UniformTypeIdentifiers") + endif() + endif() elseif(FLTK_BACKEND_WAYLAND) list(APPEND FLTK_LDLIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldbus-1") if(USE_SYSTEM_LIBDECOR) diff --git a/configure.ac b/configure.ac index a4816b352..586aec5f4 100644 --- a/configure.ac +++ b/configure.ac @@ -1005,6 +1005,10 @@ AS_CASE([$host_os_gui], [cygwin* | mingw*], [ # MacOS X uses Cocoa for graphics. LIBS="$LIBS -framework Cocoa" + macosversion_maj=$(sw_vers -productVersion | cut -d. -f1) + AS_IF([test $macosversion_maj -ge 11], [ + LIBS="$LIBS -framework UniformTypeIdentifiers" + ]) AS_IF([test x$have_pthread = xyes], [ AC_DEFINE([HAVE_PTHREAD]) diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm index 4272a0d5a..a10aa6c9d 100644 --- a/src/Fl_Native_File_Chooser_MAC.mm +++ b/src/Fl_Native_File_Chooser_MAC.mm @@ -2,7 +2,7 @@ // FLTK native OS file chooser widget for macOS // // Copyright 2004 Greg Ercolano. -// Copyright 1998-2022 by Bill Spitzak and others. +// Copyright 1998-2024 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -28,6 +28,9 @@ #include <FL/fl_string_functions.h> #define MAXFILTERS 80 #import <Cocoa/Cocoa.h> +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 +# import <UniformTypeIdentifiers/UniformTypeIdentifiers.h> +#endif #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9 const NSInteger NSModalResponseOK = NSFileHandlingPanelOKButton; @@ -513,6 +516,7 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) { BOOL saveas_confirm; } - (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag; +- (void)control_allowed_types:(const char *)p; - (void)changedPopup:(id)sender; - (void)panel:(NSSavePanel*)p; - (void)option:(BOOL)o; @@ -525,6 +529,21 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) { // To get the latter, we need to change the name we return (hence the prefix): return [@ UNLIKELYPREFIX stringByAppendingString:filename]; } +- (void)control_allowed_types:(const char *)p +{ + NSString *ext = [NSString stringWithUTF8String:p]; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 + if (fl_mac_os_version >= 110000) { + UTType *type = [UTType typeWithFilenameExtension:ext]; // 11.0 + framework UniformTypeIdentifiers + [dialog setAllowedContentTypes:[NSArray arrayWithObject:type]]; // 11.0 + } + else +#endif + if (fl_mac_os_version >= 100900) { + [dialog performSelector:@selector(setAllowedFileTypes:) + withObject:[NSArray arrayWithObject:ext]]; + } +} - (void)changedPopup:(id)sender // runs when the save panel popup menu changes output file type // correspondingly changes the extension of the output file name @@ -545,7 +564,7 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) { NSString *ns = [NSString stringWithFormat:@"%@.%@", [[dialog performSelector:@selector(nameFieldStringValue)] stringByDeletingPathExtension], [NSString stringWithUTF8String:p]]; - if (fl_mac_os_version >= 100900) [dialog setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]]; + [self control_allowed_types:p]; free(s); [dialog performSelector:@selector(setNameFieldStringValue:) withObject:ns]; } @@ -785,7 +804,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() { do q++; while (*q==' ' || *q=='{'); p = fl_strdup(q); q = strchr(p, ','); if (q) *q = 0; - [_panel setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]]; + [saveDelegate control_allowed_types:p]; free(p); } } |
