diff --git a/modules/juce_core/native/juce_mac_Files.mm b/modules/juce_core/native/juce_mac_Files.mm index 029d34157a..cf7a269edb 100644 --- a/modules/juce_core/native/juce_mac_Files.mm +++ b/modules/juce_core/native/juce_mac_Files.mm @@ -285,13 +285,17 @@ bool File::moveToTrash() const JUCE_AUTORELEASEPOOL { - #if (defined (__IPHONE_11_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_11_0) \ - || (defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8) - NSError* error = nil; - return [[NSFileManager defaultManager] trashItemAtURL: createNSURLFromFile (*this) - resultingItemURL: nil - error: &error]; - #elif JUCE_IOS + #if JUCE_MAC || (JUCE_IOS && (defined (__IPHONE_11_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0)) + if (@available (macOS 10.8, iOS 11.0, *)) + { + NSError* error = nil; + return [[NSFileManager defaultManager] trashItemAtURL: createNSURLFromFile (*this) + resultingItemURL: nil + error: &error]; + } + #endif + + #if JUCE_IOS return deleteFile(); #else [[NSWorkspace sharedWorkspace] recycleURLs: [NSArray arrayWithObject: createNSURLFromFile (*this)] diff --git a/modules/juce_graphics/native/juce_mac_Fonts.mm b/modules/juce_graphics/native/juce_mac_Fonts.mm index d58d3a9ba3..4802dc492c 100644 --- a/modules/juce_graphics/native/juce_mac_Fonts.mm +++ b/modules/juce_graphics/native/juce_mac_Fonts.mm @@ -159,20 +159,30 @@ namespace CoreTextTypeLayout //============================================================================== static CTTextAlignment getTextAlignment (const AttributedString& text) { - switch (text.getJustification().getOnlyHorizontalFlags()) + const auto flags = text.getJustification().getOnlyHorizontalFlags(); + + if (@available (macOS 10.8, *)) + { + switch (flags) + { + case Justification::right: return kCTTextAlignmentRight; + case Justification::horizontallyCentred: return kCTTextAlignmentCenter; + case Justification::horizontallyJustified: return kCTTextAlignmentJustified; + default: return kCTTextAlignmentLeft; + } + } + + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") + + switch (flags) { - #if defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - case Justification::right: return kCTTextAlignmentRight; - case Justification::horizontallyCentred: return kCTTextAlignmentCenter; - case Justification::horizontallyJustified: return kCTTextAlignmentJustified; - default: return kCTTextAlignmentLeft; - #else case Justification::right: return kCTRightTextAlignment; case Justification::horizontallyCentred: return kCTCenterTextAlignment; case Justification::horizontallyJustified: return kCTJustifiedTextAlignment; default: return kCTLeftTextAlignment; - #endif } + + JUCE_END_IGNORE_WARNINGS_GCC_LIKE } static CTLineBreakMode getLineBreakMode (const AttributedString& text) @@ -572,10 +582,8 @@ public: if (fontRef != nullptr) { - #if JUCE_MAC && defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8 - if (SystemStats::getOperatingSystemType() >= SystemStats::OperatingSystemType::MacOSX_10_11) + if (@available (macOS 10.11, *)) canBeUsedForLayout = CTFontManagerRegisterGraphicsFont (fontRef, nullptr); - #endif ctFontRef.reset (CTFontCreateWithGraphicsFont (fontRef, referenceFontSize, nullptr, nullptr)); @@ -618,10 +626,9 @@ public: { if (fontRef != nullptr) { - #if JUCE_MAC && defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8 - if (dataCopy.getSize() != 0) - CTFontManagerUnregisterGraphicsFont (fontRef, nullptr); - #endif + if (@available (macOS 10.8, *)) + if (dataCopy.getSize() != 0) + CTFontManagerUnregisterGraphicsFont (fontRef, nullptr); CGFontRelease (fontRef); } diff --git a/modules/juce_gui_basics/native/accessibility/juce_mac_Accessibility.mm b/modules/juce_gui_basics/native/accessibility/juce_mac_Accessibility.mm index 2e81f7b1fd..aba1bba1dc 100644 --- a/modules/juce_gui_basics/native/accessibility/juce_mac_Accessibility.mm +++ b/modules/juce_gui_basics/native/accessibility/juce_mac_Accessibility.mm @@ -33,12 +33,6 @@ namespace juce using NSAccessibilityNotificationName = NSString*; #endif -#if (! defined MAC_OS_X_VERSION_10_9) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 - const NSAccessibilityNotificationName NSAccessibilityLayoutChangedNotificationJuce = @"AXLayoutChanged"; -#else - const NSAccessibilityNotificationName NSAccessibilityLayoutChangedNotificationJuce = NSAccessibilityLayoutChangedNotification; -#endif - #define JUCE_NATIVE_ACCESSIBILITY_INCLUDED 1 JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wunguarded-availability", "-Wunguarded-availability-new") @@ -887,6 +881,15 @@ static void sendHandlerNotification (const AccessibilityHandler& handler, } } +static NSAccessibilityNotificationName layoutChangedNotification() +{ + if (@available (macOS 10.9, *)) + return NSAccessibilityLayoutChangedNotification; + + static NSString* layoutChangedString = @"AXLayoutChanged"; + return layoutChangedString; +} + void notifyAccessibilityEventInternal (const AccessibilityHandler& handler, InternalAccessibilityEvent eventType) { auto notification = [eventType] @@ -895,7 +898,7 @@ void notifyAccessibilityEventInternal (const AccessibilityHandler& handler, Inte { case InternalAccessibilityEvent::elementCreated: return NSAccessibilityCreatedNotification; case InternalAccessibilityEvent::elementDestroyed: return NSAccessibilityUIElementDestroyedNotification; - case InternalAccessibilityEvent::elementMovedOrResized: return NSAccessibilityLayoutChangedNotificationJuce; + case InternalAccessibilityEvent::elementMovedOrResized: return layoutChangedNotification(); case InternalAccessibilityEvent::focusChanged: return NSAccessibilityFocusedUIElementChangedNotification; case InternalAccessibilityEvent::windowOpened: return NSAccessibilityWindowCreatedNotification; case InternalAccessibilityEvent::windowClosed: break; @@ -919,7 +922,7 @@ void AccessibilityHandler::notifyAccessibilityEvent (AccessibilityEvent eventTyp case AccessibilityEvent::textChanged: case AccessibilityEvent::valueChanged: return NSAccessibilityValueChangedNotification; case AccessibilityEvent::titleChanged: return NSAccessibilityTitleChangedNotification; - case AccessibilityEvent::structureChanged: return NSAccessibilityLayoutChangedNotificationJuce; + case AccessibilityEvent::structureChanged: return layoutChangedNotification(); } return NSAccessibilityNotificationName{}; diff --git a/modules/juce_gui_basics/native/juce_mac_FileChooser.mm b/modules/juce_gui_basics/native/juce_mac_FileChooser.mm index 01d97579be..032132243d 100644 --- a/modules/juce_gui_basics/native/juce_mac_FileChooser.mm +++ b/modules/juce_gui_basics/native/juce_mac_FileChooser.mm @@ -219,12 +219,15 @@ private: exitModalState (0); - if (panel != nil && result == - #if defined (MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 - NSModalResponseOK) - #else - NSFileHandlingPanelOKButton) - #endif + const auto okResult = []() -> NSInteger + { + if (@available (macOS 10.9, *)) + return NSModalResponseOK; + + return NSFileHandlingPanelOKButton; + }(); + + if (panel != nil && result == okResult) { auto addURLResult = [&chooserResults] (NSURL* urlToAdd) { diff --git a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm index 50d6944851..301db0a56d 100644 --- a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm +++ b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm @@ -364,11 +364,18 @@ private: { NSArray* array = nil; - #if (! defined (MAC_OS_X_VERSION_10_8)) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 - [menuNib instantiateNibWithOwner: NSApp topLevelObjects: &array]; - #else - [menuNib instantiateWithOwner: NSApp topLevelObjects: &array]; - #endif + if (@available (macOS 10.11, *)) + { + [menuNib instantiateWithOwner: NSApp + topLevelObjects: &array]; + } + else + { + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") + [menuNib instantiateNibWithOwner: NSApp + topLevelObjects: &array]; + JUCE_END_IGNORE_WARNINGS_GCC_LIKE + } for (id object in array) { diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 77bef14315..a05441ec5d 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -70,12 +70,14 @@ public: [view setPostsFrameChangedNotifications: YES]; - #if defined (MAC_OS_X_VERSION_10_8) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8) \ - && USE_COREGRAPHICS_RENDERING && JUCE_COREGRAPHICS_DRAW_ASYNC + #if USE_COREGRAPHICS_RENDERING && JUCE_COREGRAPHICS_DRAW_ASYNC if (! getComponentAsyncLayerBackedViewDisabled (component)) { - [view setWantsLayer: YES]; - [[view layer] setDrawsAsynchronously: YES]; + if (@available (macOS 10.8, *)) + { + [view setWantsLayer: YES]; + [[view layer] setDrawsAsynchronously: YES]; + } } #endif @@ -107,9 +109,8 @@ public: if (! [window isOpaque]) [window setBackgroundColor: [NSColor clearColor]]; - #if defined (MAC_OS_X_VERSION_10_9) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9) - [view setAppearance: [NSAppearance appearanceNamed: NSAppearanceNameAqua]]; - #endif + if (@available (macOS 10.9, *)) + [view setAppearance: [NSAppearance appearanceNamed: NSAppearanceNameAqua]]; [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)]; @@ -851,12 +852,13 @@ public: if (r.size.width < 1.0f || r.size.height < 1.0f) return; - auto cg = (CGContextRef) [[NSGraphicsContext currentContext] - #if (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10) - CGContext]; - #else - graphicsPort]; - #endif + auto cg = [] + { + if (@available (macOS 10.10, *)) + return (CGContextRef) [[NSGraphicsContext currentContext] CGContext]; + + return (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; + }(); if (! component.isOpaque()) CGContextClearRect (cg, CGContextGetClipBoundingBox (cg)); diff --git a/modules/juce_gui_basics/native/juce_mac_Windowing.mm b/modules/juce_gui_basics/native/juce_mac_Windowing.mm index 3ef0d85c44..68a4ed71d4 100644 --- a/modules/juce_gui_basics/native/juce_mac_Windowing.mm +++ b/modules/juce_gui_basics/native/juce_mac_Windowing.mm @@ -577,13 +577,12 @@ static void selectImageForDrawing (const Image& image) { [NSGraphicsContext saveGraphicsState]; - #if (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10) - [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithCGContext: juce_getImageContext (image) - flipped: false]]; - #else - [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: juce_getImageContext (image) - flipped: false]]; - #endif + if (@available (macOS 10.10, *)) + [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithCGContext: juce_getImageContext (image) + flipped: false]]; + else + [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: juce_getImageContext (image) + flipped: false]]; } static void releaseImageAfterDrawing() diff --git a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm index 4250001de5..975fc3e99f 100644 --- a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm +++ b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm @@ -27,41 +27,37 @@ namespace juce { #if JUCE_IOS || (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10) - #define JUCE_USE_WKWEBVIEW 1 +#endif - #if (defined (MAC_OS_X_VERSION_10_11) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11) - #define WKWEBVIEW_WEBVIEWDIDCLOSE_SUPPORTED 1 - #endif - - #if (defined (MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12) - #define WKWEBVIEW_OPENPANEL_SUPPORTED 1 - #endif - +#if (defined (MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12) + #define WKWEBVIEW_OPENPANEL_SUPPORTED 1 #endif static NSURL* appendParametersToFileURL (const URL& url, NSURL* fileUrl) { - #if JUCE_IOS || (defined (MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9) - const auto parameterNames = url.getParameterNames(); - const auto parameterValues = url.getParameterValues(); + if (@available (macOS 10.9, *)) + { + const auto parameterNames = url.getParameterNames(); + const auto parameterValues = url.getParameterValues(); - jassert (parameterNames.size() == parameterValues.size()); + jassert (parameterNames.size() == parameterValues.size()); - if (parameterNames.isEmpty()) - return fileUrl; + if (parameterNames.isEmpty()) + return fileUrl; - NSUniquePtr components ([[NSURLComponents alloc] initWithURL: fileUrl resolvingAgainstBaseURL: NO]); - NSUniquePtr queryItems ([[NSMutableArray alloc] init]); + NSUniquePtr components ([[NSURLComponents alloc] initWithURL: fileUrl resolvingAgainstBaseURL: NO]); + NSUniquePtr queryItems ([[NSMutableArray alloc] init]); - for (int i = 0; i < parameterNames.size(); ++i) - [queryItems.get() addObject: [NSURLQueryItem queryItemWithName: juceStringToNS (parameterNames[i]) - value: juceStringToNS (parameterValues[i])]]; + for (int i = 0; i < parameterNames.size(); ++i) + [queryItems.get() addObject: [NSURLQueryItem queryItemWithName: juceStringToNS (parameterNames[i]) + value: juceStringToNS (parameterValues[i])]]; - [components.get() setQueryItems: queryItems.get()]; + [components.get() setQueryItems: queryItems.get()]; + + return [components.get() URL]; + } - return [components.get() URL]; - #else const auto queryString = url.getQueryString(); if (queryString.isNotEmpty()) @@ -69,18 +65,22 @@ static NSURL* appendParametersToFileURL (const URL& url, NSURL* fileUrl) return [NSURL URLWithString: [fileUrlString stringByAppendingString: juceStringToNS (queryString)]]; return fileUrl; - #endif } static NSMutableURLRequest* getRequestForURL (const String& url, const StringArray* headers, const MemoryBlock* postData) { NSString* urlString = juceStringToNS (url); - #if JUCE_IOS || (defined (MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9) - urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLQueryAllowedCharacterSet]]; - #else - urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; - #endif + if (@available (macOS 10.9, *)) + { + urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLQueryAllowedCharacterSet]]; + } + else + { + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") + urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; + JUCE_END_IGNORE_WARNINGS_GCC_LIKE + } if (NSURL* nsURL = [NSURL URLWithString: urlString]) { @@ -177,11 +177,7 @@ struct WebViewDelegateClass : public ObjCClass addMethod (@selector (webView:didFinishNavigation:), didFinishNavigation, "v@:@@"); addMethod (@selector (webView:didFailNavigation:withError:), didFailNavigation, "v@:@@@"); addMethod (@selector (webView:didFailProvisionalNavigation:withError:), didFailProvisionalNavigation, "v@:@@@"); - - #if WKWEBVIEW_WEBVIEWDIDCLOSE_SUPPORTED addMethod (@selector (webViewDidClose:), webViewDidClose, "v@:@"); - #endif - addMethod (@selector (webView:createWebViewWithConfiguration:forNavigationAction: windowFeatures:), createWebView, "@@:@@@@"); @@ -233,12 +229,10 @@ private: displayError (getOwner (self), error); } - #if WKWEBVIEW_WEBVIEWDIDCLOSE_SUPPORTED static void webViewDidClose (id self, SEL, WKWebView*) { getOwner (self)->windowCloseRequest(); } - #endif static WKWebView* createWebView (id self, SEL, WKWebView*, WKWebViewConfiguration*, WKNavigationAction* navigationAction, WKWindowFeatures*)