mirror of https://github.com/fltk/fltk
macOS: remove deprecated use of property allowedFileTypes in class NSSavePanel
The recommended replacement requires macos ≥ 11.0 and a new framework: UniformTypeIdentifiers
This commit is contained in:
parent
f3640a7312
commit
97d2836f5e
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue