Use __builtin_available() when available in wxMac builds

The advantage of using this compiler builtin instead of our own platform
checks is that the compiler will warn us (if -Wunguarded-availability is
turned on for APIs introduced before 10.13 or by default for later ones)
if a check is forgotten, which is not the case for the manual checks.

Update the code to use WX_IS_MACOS_AVAILABLE() macro, which expands to
__builtin_available() when supported, and also use API_AVAILABLE() where
it makes sense to avoid having too many checks.
This commit is contained in:
Vadim Zeitlin
2019-04-17 23:35:08 +02:00
parent a8262abc11
commit fe311b9cc5
16 changed files with 174 additions and 63 deletions

View File

@@ -148,13 +148,21 @@ public :
virtual bool SetupCursor(NSEvent* event); virtual bool SetupCursor(NSEvent* event);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
virtual void PanGestureEvent(NSPanGestureRecognizer *panGestureRecognizer); #ifdef API_AVAILABLE
virtual void ZoomGestureEvent(NSMagnificationGestureRecognizer *magnificationGestureRecognizer); #define WX_AVAILABLE_10_10 API_AVAILABLE(macos(10.10))
virtual void RotateGestureEvent(NSRotationGestureRecognizer *rotationGestureRecognizer); #else
virtual void LongPressEvent(NSPressGestureRecognizer *pressGestureRecognizer); #define WX_AVAILABLE_10_10
virtual void TouchesBegan(NSEvent *event); #endif
virtual void TouchesMoved(NSEvent *event);
virtual void TouchesEnded(NSEvent *event); WX_AVAILABLE_10_10 virtual void PanGestureEvent(NSPanGestureRecognizer *panGestureRecognizer);
WX_AVAILABLE_10_10 virtual void ZoomGestureEvent(NSMagnificationGestureRecognizer *magnificationGestureRecognizer);
WX_AVAILABLE_10_10 virtual void RotateGestureEvent(NSRotationGestureRecognizer *rotationGestureRecognizer);
WX_AVAILABLE_10_10 virtual void LongPressEvent(NSPressGestureRecognizer *pressGestureRecognizer);
WX_AVAILABLE_10_10 virtual void TouchesBegan(NSEvent *event);
WX_AVAILABLE_10_10 virtual void TouchesMoved(NSEvent *event);
WX_AVAILABLE_10_10 virtual void TouchesEnded(NSEvent *event);
#undef WX_AVAILABLE_10_10
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
#if !wxOSX_USE_NATIVE_FLIPPED #if !wxOSX_USE_NATIVE_FLIPPED

View File

@@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/private/available.h
// Purpose: Helper for checking API availability under macOS.
// Author: Vadim Zeitlin
// Created: 2019-04-17
// Copyright: (c) 2019 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OSX_PRIVATE_AVAILABLE_H_
#define _WX_OSX_PRIVATE_AVAILABLE_H_
// Xcode 9 adds new @available keyword and the corresponding __builtin_available
// builtin which should be used instead of manually checks for API availability
// as using this builtin suppresses the compiler -Wunguarded-availability
// warnings, so use it if possible for the implementation of our own macro.
#if defined(__clang__) && __has_builtin(__builtin_available)
#define WX_IS_MACOS_AVAILABLE(major, minor) \
__builtin_available(macOS major ## . ## minor, *)
// Note that we can't easily forward to API_AVAILABLE macro here, so go
// directly to its expansion instead.
#define WX_API_AVAILABLE_MACOS(major, minor) \
__attribute__((availability(macos,introduced=major ## . ## minor)))
#else // Not clang or old clang version without __builtin_available
#include "wx/platinfo.h"
#define WX_IS_MACOS_AVAILABLE(major, minor) \
wxPlatformInfo::Get().CheckOSVersion(major, minor)
#define WX_API_AVAILABLE_MACOS(major, minor)
#endif
#endif // _WX_OSX_PRIVATE_AVAILABLE_H_

View File

@@ -33,6 +33,7 @@
#include "wx/splitter.h" #include "wx/splitter.h"
#include "wx/time.h" #include "wx/time.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
#include "wx/image.h" #include "wx/image.h"
@@ -172,7 +173,7 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win,
wxHeaderSortIconType sortArrow, wxHeaderSortIconType sortArrow,
wxHeaderButtonParams* params ) wxHeaderButtonParams* params )
{ {
if ( wxPlatformInfo::Get().CheckOSVersion(10, 14) ) if ( WX_IS_MACOS_AVAILABLE(10, 14) )
{ {
if ( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).Red() < 128 ) if ( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).Red() < 128 )
return wxRendererNative::GetGeneric().DrawHeaderButton(win, dc, rect, flags, sortArrow, params); return wxRendererNative::GetGeneric().DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
@@ -339,7 +340,15 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win,
wxOrientation orient, wxOrientation orient,
int WXUNUSED(flags) ) int WXUNUSED(flags) )
{ {
bool hasMetal = win->MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL && !wxPlatformInfo::Get().CheckOSVersion(10, 14); // Note that we can't use ternary ?: operator or any other construct with
// logical operators here, WX_IS_MACOS_AVAILABLE() must appear inside an
// "if" statement to avoid -Wunsupported-availability-guard with Xcode 10.
bool hasMetal;
if (WX_IS_MACOS_AVAILABLE(10, 14))
hasMetal = false;
else
hasMetal = win->MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL;
SInt32 height; SInt32 height;
height = wxRendererNative::Get().GetSplitterParams(win).widthSash; height = wxRendererNative::Get().GetSplitterParams(win).widthSash;
@@ -382,7 +391,13 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win,
if ( win->HasFlag(wxSP_3DSASH) ) if ( win->HasFlag(wxSP_3DSASH) )
{ {
if ( !wxPlatformInfo::Get().CheckOSVersion(10, 14) || wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).Red() > 128 ) bool doDraw;
if ( WX_IS_MACOS_AVAILABLE(10, 14) )
doDraw = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).Red() > 128;
else
doDraw = true;
if ( doDraw )
{ {
HIThemeSplitterDrawInfo drawInfo; HIThemeSplitterDrawInfo drawInfo;
drawInfo.version = 0; drawInfo.version = 0;

View File

@@ -24,6 +24,7 @@
#endif #endif
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
// Margin between the field text and the field rect // Margin between the field text and the field rect
#define wxFIELD_TEXT_MARGIN 2 #define wxFIELD_TEXT_MARGIN 2
@@ -75,33 +76,9 @@ bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id,
void wxStatusBarMac::InitColours() void wxStatusBarMac::InitColours()
{ {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000 if ( WX_IS_MACOS_AVAILABLE(10, 10) )
if ( !wxPlatformInfo::Get().CheckOSVersion(10, 10) )
{ {
// 10.9 Mavericks and older: if ( WX_IS_MACOS_AVAILABLE(10, 14) )
m_textActive = wxColour(0x2F, 0x2F, 0x2F);
m_textInactive = wxColour(0x4D, 0x4D, 0x4D);
m_bgActiveFrom = wxColour(0xDA, 0xDA, 0xDA);
m_bgActiveTo = wxColour(0xA0, 0xA0, 0xA0);
m_borderActive = wxColour(0x6E, 0x6E, 0x6E);
m_borderInactive = wxColour(0xA3, 0xA3, 0xA3);
SetBackgroundColour(wxColour(0xE1, 0xE1, 0xE1)); // inactive bg
}
else
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 101000
{
if (!wxPlatformInfo::Get().CheckOSVersion(10, 14))
{
// 10.10 Yosemite to 10.13 :
m_textActive = wxColour(0x40, 0x40, 0x40);
m_textInactive = wxColour(0x4B, 0x4B, 0x4B);
m_bgActiveFrom = wxColour(0xE9, 0xE7, 0xEA);
m_bgActiveTo = wxColour(0xCD, 0xCB, 0xCE);
m_borderActive = wxColour(0xBA, 0xB8, 0xBB);
m_borderInactive = wxColour(0xC3, 0xC3, 0xC3);
SetBackgroundColour(wxColour(0xF4, 0xF4, 0xF4)); // inactive bg
}
else
{ {
// FIXME: None of this is correct and is only very loose // FIXME: None of this is correct and is only very loose
// approximation. 10.14's dark mode uses dynamic colors that // approximation. 10.14's dark mode uses dynamic colors that
@@ -129,7 +106,31 @@ void wxStatusBarMac::InitColours()
} }
SetBackgroundColour(bg); // inactive bg SetBackgroundColour(bg); // inactive bg
} }
else
{
// 10.10 Yosemite to 10.13 :
m_textActive = wxColour(0x40, 0x40, 0x40);
m_textInactive = wxColour(0x4B, 0x4B, 0x4B);
m_bgActiveFrom = wxColour(0xE9, 0xE7, 0xEA);
m_bgActiveTo = wxColour(0xCD, 0xCB, 0xCE);
m_borderActive = wxColour(0xBA, 0xB8, 0xBB);
m_borderInactive = wxColour(0xC3, 0xC3, 0xC3);
SetBackgroundColour(wxColour(0xF4, 0xF4, 0xF4)); // inactive bg
}
} }
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000
else
{
// 10.9 Mavericks and older:
m_textActive = wxColour(0x2F, 0x2F, 0x2F);
m_textInactive = wxColour(0x4D, 0x4D, 0x4D);
m_bgActiveFrom = wxColour(0xDA, 0xDA, 0xDA);
m_bgActiveTo = wxColour(0xA0, 0xA0, 0xA0);
m_borderActive = wxColour(0x6E, 0x6E, 0x6E);
m_borderInactive = wxColour(0xA3, 0xA3, 0xA3);
SetBackgroundColour(wxColour(0xE1, 0xE1, 0xE1)); // inactive bg
}
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 101000
} }
void wxStatusBarMac::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int textHeight) void wxStatusBarMac::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int textHeight)

View File

@@ -23,6 +23,7 @@
#ifdef __WXMAC__ #ifdef __WXMAC__
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#endif #endif
#include "wx/fontutil.h" #include "wx/fontutil.h"
@@ -624,7 +625,7 @@ NSString* wxNSStringWithWxString(const wxString &wxstring)
wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter() wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter()
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
if ( wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) if ( WX_IS_MACOS_AVAILABLE(10, 14 ) )
{ {
formerAppearance = NSAppearance.currentAppearance; formerAppearance = NSAppearance.currentAppearance;
NSAppearance.currentAppearance = NSApp.effectiveAppearance; NSAppearance.currentAppearance = NSApp.effectiveAppearance;
@@ -637,7 +638,7 @@ wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter()
wxOSXEffectiveAppearanceSetter::~wxOSXEffectiveAppearanceSetter() wxOSXEffectiveAppearanceSetter::~wxOSXEffectiveAppearanceSetter()
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
if ( wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) if ( WX_IS_MACOS_AVAILABLE(10, 14 ) )
NSAppearance.currentAppearance = (NSAppearance*) formerAppearance; NSAppearance.currentAppearance = (NSAppearance*) formerAppearance;
#endif #endif
} }

View File

@@ -12,6 +12,7 @@
#include "wx/colour.h" #include "wx/colour.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
class wxNSColorRefData : public wxColourRefData class wxNSColorRefData : public wxColourRefData
{ {
@@ -104,7 +105,7 @@ bool wxNSColorRefData::IsSolid() const
CGColorRef wxNSColorRefData::GetCGColor() const CGColorRef wxNSColorRefData::GetCGColor() const
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
if (wxPlatformInfo::Get().CheckOSVersion(10, 8)) { if ( WX_IS_MACOS_AVAILABLE(10, 8) ) {
wxOSXEffectiveAppearanceSetter helper; wxOSXEffectiveAppearanceSetter helper;
return [m_nsColour CGColor]; return [m_nsColour CGColor];
} }

View File

@@ -25,6 +25,7 @@
#endif #endif
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#include "wx/osx/cocoa/dataview.h" #include "wx/osx/cocoa/dataview.h"
#include "wx/renderer.h" #include "wx/renderer.h"
#include "wx/stopwatch.h" #include "wx/stopwatch.h"
@@ -2956,14 +2957,14 @@ bool wxDataViewTextRenderer::MacRender()
// Tightening looks very ugly when combined with non-tightened rows, // Tightening looks very ugly when combined with non-tightened rows,
// so disabled it on OS X version where it's used: // so disabled it on OS X version where it's used:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_11) if ( WX_IS_MACOS_AVAILABLE(10, 11) )
{ {
[par setAllowsDefaultTighteningForTruncation:NO]; [par setAllowsDefaultTighteningForTruncation:NO];
} }
else else
#endif #endif
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_10) if ( WX_IS_MACOS_AVAILABLE(10, 10) )
{ {
[par setTighteningFactorForTruncation:0.0]; [par setTighteningFactorForTruncation:0.0];
} }

View File

@@ -31,6 +31,7 @@
#include "wx/mediactrl.h" #include "wx/mediactrl.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#if wxOSX_USE_COCOA && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 && defined(__LP64__) #if wxOSX_USE_COCOA && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 && defined(__LP64__)
#define wxOSX_USE_AVKIT 1 #define wxOSX_USE_AVKIT 1
@@ -276,6 +277,7 @@ private:
#if wxOSX_USE_AVKIT #if wxOSX_USE_AVKIT
WX_API_AVAILABLE_MACOS(10, 10)
@interface wxAVPlayerView : AVPlayerView @interface wxAVPlayerView : AVPlayerView
{ {
} }
@@ -395,7 +397,7 @@ bool wxAVMediaBackend::CreateControl(wxControl* inctrl, wxWindow* parent,
WXWidget view = NULL; WXWidget view = NULL;
#if wxOSX_USE_AVKIT #if wxOSX_USE_AVKIT
if ( NSClassFromString(@"AVPlayerView") ) if ( WX_IS_MACOS_AVAILABLE(10, 10) )
{ {
view = [[wxAVPlayerView alloc] initWithFrame: r player:m_player]; view = [[wxAVPlayerView alloc] initWithFrame: r player:m_player];
[(wxAVPlayerView*) view setControlsStyle:AVPlayerViewControlsStyleNone]; [(wxAVPlayerView*) view setControlsStyle:AVPlayerViewControlsStyleNone];
@@ -563,14 +565,17 @@ bool wxAVMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags)
void wxAVMediaBackend::DoShowPlayerControls(wxMediaCtrlPlayerControls flags) void wxAVMediaBackend::DoShowPlayerControls(wxMediaCtrlPlayerControls flags)
{ {
#if wxOSX_USE_AVKIT #if wxOSX_USE_AVKIT
NSView* view = m_ctrl->GetHandle(); if ( WX_IS_MACOS_AVAILABLE(10, 10) )
if ( [view isKindOfClass:[wxAVPlayerView class]] )
{ {
wxAVPlayerView* playerView = (wxAVPlayerView*) view; NSView* view = m_ctrl->GetHandle();
if (flags == wxMEDIACTRLPLAYERCONTROLS_NONE ) if ( [view isKindOfClass:[wxAVPlayerView class]] )
playerView.controlsStyle = AVPlayerViewControlsStyleNone; {
else wxAVPlayerView* playerView = (wxAVPlayerView*) view;
playerView.controlsStyle = AVPlayerViewControlsStyleDefault; if (flags == wxMEDIACTRLPLAYERCONTROLS_NONE )
playerView.controlsStyle = AVPlayerViewControlsStyleNone;
else
playerView.controlsStyle = AVPlayerViewControlsStyleDefault;
}
} }
#endif #endif
} }

View File

@@ -31,6 +31,7 @@
#endif // WX_PRECOMP #endif // WX_PRECOMP
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#include "wx/generic/notifmsg.h" #include "wx/generic/notifmsg.h"
#include "wx/private/notifmsg.h" #include "wx/private/notifmsg.h"
#include "wx/generic/private/notifmsg.h" #include "wx/generic/private/notifmsg.h"
@@ -43,6 +44,7 @@
#include "wx/utils.h" #include "wx/utils.h"
#include <map> #include <map>
WX_API_AVAILABLE_MACOS(10, 8)
@interface wxUserNotificationHandler : NSObject <NSUserNotificationCenterDelegate> @interface wxUserNotificationHandler : NSObject <NSUserNotificationCenterDelegate>
@end @end
@@ -51,7 +53,7 @@
// wxUserNotificationMsgImpl // wxUserNotificationMsgImpl
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class wxUserNotificationMsgImpl : public wxNotificationMessageImpl class WX_API_AVAILABLE_MACOS(10, 8) wxUserNotificationMsgImpl : public wxNotificationMessageImpl
{ {
public: public:
wxUserNotificationMsgImpl(wxNotificationMessageBase* notification) : wxUserNotificationMsgImpl(wxNotificationMessageBase* notification) :
@@ -121,7 +123,7 @@ public:
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
// Additional icon in the notification is only supported on OS X 10.9+ // Additional icon in the notification is only supported on OS X 10.9+
if ([NSUserNotification instancesRespondToSelector:@selector(setContentImage:)]) if ( WX_IS_MACOS_AVAILABLE(10, 9) )
m_notif.contentImage = icon.GetNSImage(); m_notif.contentImage = icon.GetNSImage();
#endif #endif
} }
@@ -247,7 +249,7 @@ void wxNotificationMessage::Init()
{ {
// Native notifications are not available prior to 10.8, fallback // Native notifications are not available prior to 10.8, fallback
// to generic ones on 10.7 // to generic ones on 10.7
if (wxPlatformInfo::Get().CheckOSVersion(10, 8)) if ( WX_IS_MACOS_AVAILABLE(10, 8) )
m_impl = new wxUserNotificationMsgImpl(this); m_impl = new wxUserNotificationMsgImpl(this);
else else
m_impl = new wxGenericNotificationMessageImpl(this); m_impl = new wxGenericNotificationMessageImpl(this);

View File

@@ -15,8 +15,8 @@
#include "wx/power.h" #include "wx/power.h"
#include "wx/atomic.h" #include "wx/atomic.h"
#include "wx/platinfo.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#include <IOKit/pwr_mgt/IOPMLib.h> #include <IOKit/pwr_mgt/IOPMLib.h>
@@ -38,7 +38,7 @@ bool UpdatePowerResourceUsage(wxPowerResourceKind kind, const wxString& reason)
cfreason = wxString("User Activity"); cfreason = wxString("User Activity");
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
if ( wxPlatformInfo::Get().CheckOSVersion(10, 9) ) if ( WX_IS_MACOS_AVAILABLE(10, 9) )
{ {
// Use NSProcessInfo for 10.9 and newer // Use NSProcessInfo for 10.9 and newer
if ( !g_processInfoActivity ) if ( !g_processInfoActivity )
@@ -83,7 +83,7 @@ bool UpdatePowerResourceUsage(wxPowerResourceKind kind, const wxString& reason)
{ {
// Release power assertion // Release power assertion
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
if ( wxPlatformInfo::Get().CheckOSVersion(10, 9) ) if ( WX_IS_MACOS_AVAILABLE(10, 9) )
{ {
// Use NSProcessInfo for 10.9 and newer // Use NSProcessInfo for 10.9 and newer
if ( g_processInfoActivity ) if ( g_processInfoActivity )

View File

@@ -19,6 +19,7 @@
#include "wx/osx/core/private.h" #include "wx/osx/core/private.h"
#include "wx/osx/cocoa/private.h" #include "wx/osx/cocoa/private.h"
#include "wx/osx/private/available.h"
#import <AppKit/NSColor.h> #import <AppKit/NSColor.h>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@@ -79,7 +80,7 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
sysColor = [NSColor controlBackgroundColor]; sysColor = [NSColor controlBackgroundColor];
break; break;
case wxSYS_COLOUR_BTNFACE: case wxSYS_COLOUR_BTNFACE:
if ( wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) if ( WX_IS_MACOS_AVAILABLE(10, 14 ) )
sysColor = [NSColor windowBackgroundColor]; sysColor = [NSColor windowBackgroundColor];
else else
sysColor = [NSColor controlColor]; sysColor = [NSColor controlColor];

View File

@@ -19,6 +19,7 @@
#include "wx/toolbar.h" #include "wx/toolbar.h"
#include "wx/app.h" #include "wx/app.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#include "wx/geometry.h" #include "wx/geometry.h"
#include "wx/sysopt.h" #include "wx/sysopt.h"
@@ -1674,8 +1675,14 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
wxRect rect(0,0,w,h); wxRect rect(0,0,w,h);
// TODO determine whether to use flat appearance in earlier system // TODO determine whether to use flat appearance in earlier system
if ( !wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) if ( WX_IS_MACOS_AVAILABLE(10, 14 ) )
{
// No gradient.
}
else
{
dc.GradientFillLinear( rect , wxColour( 0xCC,0xCC,0xCC ), wxColour( 0xA8,0xA8,0xA8 ) , wxSOUTH ); dc.GradientFillLinear( rect , wxColour( 0xCC,0xCC,0xCC ), wxColour( 0xA8,0xA8,0xA8 ) , wxSOUTH );
}
dc.SetPen( wxPen( wxColour( 0x51,0x51,0x51 ) ) ); dc.SetPen( wxPen( wxColour( 0x51,0x51,0x51 ) ) );
if ( HasFlag(wxTB_LEFT) ) if ( HasFlag(wxTB_LEFT) )

View File

@@ -26,6 +26,7 @@
#include "wx/apptrait.h" #include "wx/apptrait.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#if wxUSE_GUI #if wxUSE_GUI
#if wxOSX_USE_COCOA_OR_CARBON #if wxOSX_USE_COCOA_OR_CARBON
@@ -349,7 +350,7 @@ void wxBell()
ProcessSerialNumber psn = { 0, kCurrentProcess }; ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication); TransformProcessType(&psn, kProcessTransformToForegroundApplication);
if ( wxPlatformInfo::Get().CheckOSVersion(10, 9) ) if ( WX_IS_MACOS_AVAILABLE(10, 9) )
{ {
[[NSRunningApplication currentApplication] activateWithOptions: [[NSRunningApplication currentApplication] activateWithOptions:
(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)]; (NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];

View File

@@ -32,6 +32,13 @@
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro) wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro)
{ {
#ifdef wxHAS_NSPROCESSINFO #ifdef wxHAS_NSPROCESSINFO
// Note: we don't use WX_IS_MACOS_AVAILABLE() here because these properties
// are only officially supported since 10.10, but are actually available
// under 10.9 too, so we prefer to check for them explicitly and suppress
// the warnings that using without a __builtin_available() check around
// them generates.
wxCLANG_WARNING_SUPPRESS(unguarded-availability)
if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)])
{ {
NSOperatingSystemVersion osVer = [NSProcessInfo processInfo].operatingSystemVersion; NSOperatingSystemVersion osVer = [NSProcessInfo processInfo].operatingSystemVersion;
@@ -45,6 +52,9 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro)
if ( verMicro != NULL ) if ( verMicro != NULL )
*verMicro = osVer.patchVersion; *verMicro = osVer.patchVersion;
} }
wxCLANG_WARNING_RESTORE(unguarded-availability)
else else
#endif #endif
{ {
@@ -79,6 +89,10 @@ wxGCC_WARNING_RESTORE()
bool wxCheckOsVersion(int majorVsn, int minorVsn, int microVsn) bool wxCheckOsVersion(int majorVsn, int minorVsn, int microVsn)
{ {
#ifdef wxHAS_NSPROCESSINFO #ifdef wxHAS_NSPROCESSINFO
// As above, this API is effectively available earlier than its
// availability attribute indicates, so check for it manually.
wxCLANG_WARNING_SUPPRESS(unguarded-availability)
if ([NSProcessInfo instancesRespondToSelector:@selector(isOperatingSystemAtLeastVersion:)]) if ([NSProcessInfo instancesRespondToSelector:@selector(isOperatingSystemAtLeastVersion:)])
{ {
NSOperatingSystemVersion osVer; NSOperatingSystemVersion osVer;
@@ -88,6 +102,9 @@ bool wxCheckOsVersion(int majorVsn, int minorVsn, int microVsn)
return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:osVer] != NO; return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:osVer] != NO;
} }
wxCLANG_WARNING_RESTORE(unguarded-availability)
else else
#endif #endif
{ {

View File

@@ -21,6 +21,7 @@
#ifdef __WXMAC__ #ifdef __WXMAC__
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#endif #endif
#include "wx/evtloop.h" #include "wx/evtloop.h"
@@ -1092,6 +1093,7 @@ void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text)
} }
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
WX_API_AVAILABLE_MACOS(10, 10)
void wxOSX_panGestureEvent(NSView* self, SEL _cmd, NSPanGestureRecognizer* panGestureRecognizer) void wxOSX_panGestureEvent(NSView* self, SEL _cmd, NSPanGestureRecognizer* panGestureRecognizer)
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
@@ -1101,6 +1103,7 @@ void wxOSX_panGestureEvent(NSView* self, SEL _cmd, NSPanGestureRecognizer* panGe
impl->PanGestureEvent(panGestureRecognizer); impl->PanGestureEvent(panGestureRecognizer);
} }
WX_API_AVAILABLE_MACOS(10, 10)
void wxOSX_zoomGestureEvent(NSView* self, SEL _cmd, NSMagnificationGestureRecognizer* magnificationGestureRecognizer) void wxOSX_zoomGestureEvent(NSView* self, SEL _cmd, NSMagnificationGestureRecognizer* magnificationGestureRecognizer)
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
@@ -1110,6 +1113,7 @@ void wxOSX_zoomGestureEvent(NSView* self, SEL _cmd, NSMagnificationGestureRecogn
impl->ZoomGestureEvent(magnificationGestureRecognizer); impl->ZoomGestureEvent(magnificationGestureRecognizer);
} }
WX_API_AVAILABLE_MACOS(10, 10)
void wxOSX_rotateGestureEvent(NSView* self, SEL _cmd, NSRotationGestureRecognizer* rotationGestureRecognizer) void wxOSX_rotateGestureEvent(NSView* self, SEL _cmd, NSRotationGestureRecognizer* rotationGestureRecognizer)
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
@@ -1119,6 +1123,7 @@ void wxOSX_rotateGestureEvent(NSView* self, SEL _cmd, NSRotationGestureRecognize
impl->RotateGestureEvent(rotationGestureRecognizer); impl->RotateGestureEvent(rotationGestureRecognizer);
} }
WX_API_AVAILABLE_MACOS(10, 10)
void wxOSX_longPressEvent(NSView* self, SEL _cmd, NSPressGestureRecognizer* pressGestureRecognizer) void wxOSX_longPressEvent(NSView* self, SEL _cmd, NSPressGestureRecognizer* pressGestureRecognizer)
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
@@ -1128,6 +1133,7 @@ void wxOSX_longPressEvent(NSView* self, SEL _cmd, NSPressGestureRecognizer* pres
impl->LongPressEvent(pressGestureRecognizer); impl->LongPressEvent(pressGestureRecognizer);
} }
WX_API_AVAILABLE_MACOS(10, 10)
void wxOSX_touchesBegan(NSView* self, SEL _cmd, NSEvent *event) void wxOSX_touchesBegan(NSView* self, SEL _cmd, NSEvent *event)
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
@@ -1137,6 +1143,7 @@ void wxOSX_touchesBegan(NSView* self, SEL _cmd, NSEvent *event)
impl->TouchesBegan(event); impl->TouchesBegan(event);
} }
WX_API_AVAILABLE_MACOS(10, 10)
void wxOSX_touchesMoved(NSView* self, SEL _cmd, NSEvent *event) void wxOSX_touchesMoved(NSView* self, SEL _cmd, NSEvent *event)
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
@@ -1146,6 +1153,7 @@ void wxOSX_touchesMoved(NSView* self, SEL _cmd, NSEvent *event)
impl->TouchesMoved(event); impl->TouchesMoved(event);
} }
WX_API_AVAILABLE_MACOS(10, 10)
void wxOSX_touchesEnded(NSView* self, SEL _cmd, NSEvent *event) void wxOSX_touchesEnded(NSView* self, SEL _cmd, NSEvent *event)
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
@@ -1545,7 +1553,7 @@ void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
// Class containing data used for gestures support. // Class containing data used for gestures support.
class wxCocoaGesturesImpl class WX_API_AVAILABLE_MACOS(10, 10) wxCocoaGesturesImpl
{ {
public: public:
wxCocoaGesturesImpl(wxWidgetCocoaImpl* impl, NSView* view, int eventsMask) wxCocoaGesturesImpl(wxWidgetCocoaImpl* impl, NSView* view, int eventsMask)
@@ -1669,6 +1677,12 @@ private:
// itself because most windows don't need it and it seems wasteful to // itself because most windows don't need it and it seems wasteful to
// always increase their size unnecessarily. // always increase their size unnecessarily.
// wxCocoaGesturesImpl is only used under 10.10+ and so clang warns about
// wxCocoaGesturesImplMap not having 10.10 availability attribute, but there is
// no simple way to make it pass through the macro, so just suppress the
// warning instead.
wxCLANG_WARNING_SUPPRESS(unguarded-availability)
#include "wx/hashmap.h" #include "wx/hashmap.h"
WX_DECLARE_HASH_MAP(wxWidgetCocoaImpl*, wxCocoaGesturesImpl*, WX_DECLARE_HASH_MAP(wxWidgetCocoaImpl*, wxCocoaGesturesImpl*,
wxPointerHash, wxPointerEqual, wxPointerHash, wxPointerEqual,
@@ -1679,6 +1693,8 @@ typedef wxExternalField<wxWidgetCocoaImpl,
wxCocoaGesturesImpl, wxCocoaGesturesImpl,
wxCocoaGesturesImplMap> wxCocoaGestures; wxCocoaGesturesImplMap> wxCocoaGestures;
wxCLANG_WARNING_RESTORE(unguarded-availability)
void wxWidgetCocoaImpl::PanGestureEvent(NSPanGestureRecognizer* panGestureRecognizer) void wxWidgetCocoaImpl::PanGestureEvent(NSPanGestureRecognizer* panGestureRecognizer)
{ {
NSGestureRecognizerState gestureState; NSGestureRecognizerState gestureState;
@@ -2578,7 +2594,7 @@ void wxWidgetCocoaImpl::SetVisibility( bool visible )
// trigger redraw upon shown for layer-backed views // trigger redraw upon shown for layer-backed views
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
if ( wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) if ( WX_IS_MACOS_AVAILABLE(10, 14 ) )
if( !m_osxView.isHiddenOrHasHiddenAncestor ) if( !m_osxView.isHiddenOrHasHiddenAncestor )
SetNeedsDisplay(NULL); SetNeedsDisplay(NULL);
#endif #endif
@@ -3056,7 +3072,7 @@ void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
// their children implicitly redrawn with the parent. For compatibility, // their children implicitly redrawn with the parent. For compatibility,
// do it manually here: // do it manually here:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
if ( wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) if ( WX_IS_MACOS_AVAILABLE(10, 14 ) )
SetSubviewsNeedDisplay(m_osxView); SetSubviewsNeedDisplay(m_osxView);
#endif #endif
} }
@@ -3525,7 +3541,7 @@ void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
bool wxWidgetCocoaImpl::EnableTouchEvents(int eventsMask) bool wxWidgetCocoaImpl::EnableTouchEvents(int eventsMask)
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
if ( wxPlatformInfo::Get().CheckOSVersion(10, 10) ) if ( WX_IS_MACOS_AVAILABLE(10, 10) )
{ {
if ( HasUserMouseHandling() ) if ( HasUserMouseHandling() )
{ {

View File

@@ -17,6 +17,7 @@
#endif #endif
#include "wx/osx/private.h" #include "wx/osx/private.h"
#include "wx/osx/private/available.h"
CGColorSpaceRef wxMacGetGenericRGBColorSpace(); CGColorSpaceRef wxMacGetGenericRGBColorSpace();
@@ -118,7 +119,7 @@ wxCGColorRefData::wxCGColorRefData(CGColorRef col)
else if (model != kCGColorSpaceModelRGB) else if (model != kCGColorSpaceModelRGB)
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11
if (wxPlatformInfo::Get().CheckOSVersion(10, 11)) if ( WX_IS_MACOS_AVAILABLE(10, 11) )
{ {
rgbacol = CGColorCreateCopyByMatchingToColorSpace(wxMacGetGenericRGBColorSpace(), kCGRenderingIntentDefault, col, NULL); rgbacol = CGColorCreateCopyByMatchingToColorSpace(wxMacGetGenericRGBColorSpace(), kCGRenderingIntentDefault, col, NULL);
noComp = CGColorGetNumberOfComponents(rgbacol); noComp = CGColorGetNumberOfComponents(rgbacol);