|
|
commit 97d2836f5e72054f640289a93c4f2dd776c4fd00
Author: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sat Mar 23 17:16:57 2024 +0100
Commit: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sat Mar 23 17:16:57 2024 +0100
macOS: remove deprecated use of property allowedFileTypes in class NSSavePanel
The recommended replacement requires macos â?¥ 11.0 and a new framework: UniformTypeIdentifiers
CMake/fl_add_library.cmake | 5 +++++
CMake/setup.cmake | 6 ++++++
CMake/variables.cmake | 5 +++++
configure.ac | 4 ++++
src/Fl_Native_File_Chooser_MAC.mm | 25 ++++++++++++++++++++++---
5 files changed, 42 insertions(+), 3 deletions(-)
diff --git CMake/fl_add_library.cmake CMake/fl_add_library.cmake
index d33b4d8..3f57e7a 100644
--- CMake/fl_add_library.cmake
+++ 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 CMake/setup.cmake CMake/setup.cmake
index b663813..69835fc 100644
--- CMake/setup.cmake
+++ 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 CMake/variables.cmake CMake/variables.cmake
index 3d37aec..981cd07 100644
--- CMake/variables.cmake
+++ 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 configure.ac configure.ac
index a4816b3..586aec5 100644
--- configure.ac
+++ 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 src/Fl_Native_File_Chooser_MAC.mm src/Fl_Native_File_Chooser_MAC.mm
index 4272a0d..a10aa6c 100644
--- src/Fl_Native_File_Chooser_MAC.mm
+++ 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);
}
}
[ Direct Link to Message ] | |
|
| |