Skip to content

Change several deprecated symbols in _macosx.m #18128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 68 additions & 34 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@
#define COMPILING_FOR_10_10
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you not be checking for minimum required, like above?

/* A lot of symbols were renamed in Sierra and cause deprecation warnings
so define macros for the new names if we are compiling on an older SDK */
#define NSEventMaskAny NSAnyEventMask
#define NSEventTypeApplicationDefined NSApplicationDefined
#define NSEventModifierFlagCommand NSCommandKeyMask
#define NSEventModifierFlagControl NSControlKeyMask
#define NSEventModifierFlagOption NSAlternateKeyMask
#define NSEventModifierFlagShift NSShiftKeyMask
#define NSEventTypeKeyUp NSKeyUp
#define NSEventTypeKeyDown NSKeyDown
#define NSEventTypeMouseMoved NSMouseMoved
#define NSEventTypeLeftMouseDown NSLeftMouseDown
#define NSEventTypeRightMouseDown NSRightMouseDown
#define NSEventTypeOtherMouseDown NSOtherMouseDown
#define NSEventTypeLeftMouseDragged NSLeftMouseDragged
#define NSEventTypeRightMouseDragged NSRightMouseDragged
#define NSEventTypeOtherMouseDragged NSOtherMouseDragged
#define NSEventTypeLeftMouseUp NSLeftMouseUp
#define NSEventTypeRightMouseUp NSRightMouseUp
#define NSEventTypeOtherMouseUp NSOtherMouseUp
#define NSWindowStyleMaskClosable NSClosableWindowMask
#define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
#define NSWindowStyleMaskResizable NSResizableWindowMask
#define NSWindowStyleMaskTitled NSTitledWindowMask
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101400
/* A few more deprecations in Mojave */
#define NSButtonTypeMomentaryLight NSMomentaryLightButton
#define NSButtonTypePushOnPushOff NSPushOnPushOffButton
#define NSBezelStyleShadowlessSquare NSShadowlessSquareBezelStyle
#define CGContext graphicsPort
#endif

/* CGFloat was defined in Mac OS X 10.5 */
#ifndef CGFLOAT_DEFINED
Expand Down Expand Up @@ -140,7 +174,7 @@ static int wait_for_stdin(void)
NSEvent* event;
while (true) {
while (true) {
event = [NSApp nextEventMatchingMask: NSAnyEventMask
event = [NSApp nextEventMatchingMask: NSEventMaskAny
untilDate: [NSDate distantPast]
inMode: NSDefaultRunLoopMode
dequeue: YES];
Expand Down Expand Up @@ -486,11 +520,11 @@ static CGFloat _get_device_scale(CGContextRef cr)
(timeout > 0.0) ? [NSDate dateWithTimeIntervalSinceNow: timeout]
: [NSDate distantFuture];
while (true)
{ NSEvent* event = [NSApp nextEventMatchingMask: NSAnyEventMask
{ NSEvent* event = [NSApp nextEventMatchingMask: NSEventMaskAny
untilDate: date
inMode: NSDefaultRunLoopMode
dequeue: YES];
if (!event || [event type]==NSApplicationDefined) break;
if (!event || [event type]==NSEventTypeApplicationDefined) break;
[NSApp sendEvent: event];
}

Expand All @@ -506,7 +540,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
static PyObject*
FigureCanvas_stop_event_loop(FigureCanvas* self)
{
NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
location: NSZeroPoint
modifierFlags: 0
timestamp: 0.0
Expand Down Expand Up @@ -666,10 +700,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
rect.size.width = width;

self->window = [self->window initWithContentRect: rect
styleMask: NSTitledWindowMask
| NSClosableWindowMask
| NSResizableWindowMask
| NSMiniaturizableWindowMask
styleMask: NSWindowStyleMaskTitled
| NSWindowStyleMaskClosable
| NSWindowStyleMaskResizable
| NSWindowStyleMaskMiniaturizable
backing: NSBackingStoreBuffered
defer: YES
withManager: (PyObject*)self];
Expand Down Expand Up @@ -1132,13 +1166,13 @@ -(void)save_figure:(id)sender
@selector(zoom:),
@selector(configure_subplots:),
@selector(save_figure:)};
NSButtonType buttontypes[7] = {NSMomentaryLightButton,
NSMomentaryLightButton,
NSMomentaryLightButton,
NSPushOnPushOffButton,
NSPushOnPushOffButton,
NSMomentaryLightButton,
NSMomentaryLightButton};
NSButtonType buttontypes[7] = {NSButtonTypeMomentaryLight,
NSButtonTypeMomentaryLight,
NSButtonTypeMomentaryLight,
NSButtonTypePushOnPushOff,
NSButtonTypePushOnPushOff,
NSButtonTypeMomentaryLight,
NSButtonTypeMomentaryLight};

rect.origin.x = 0;
rect.origin.y = 0;
Expand All @@ -1164,7 +1198,7 @@ -(void)save_figure:(id)sender
NSImage* image = [[NSImage alloc] initWithContentsOfFile: filename];
buttons[i] = [[NSButton alloc] initWithFrame: rect];
[image setSize: size];
[buttons[i] setBezelStyle: NSShadowlessSquareBezelStyle];
[buttons[i] setBezelStyle: NSBezelStyleShadowlessSquare];
[buttons[i] setButtonType: buttontypes[i]];
[buttons[i] setImage: image];
[buttons[i] scaleUnitSquareToSize: scale];
Expand Down Expand Up @@ -1494,10 +1528,10 @@ @implementation ToolWindow
- (ToolWindow*)initWithContentRect:(NSRect)rect master:(NSWindow*)window
{
[self initWithContentRect: rect
styleMask: NSTitledWindowMask
| NSClosableWindowMask
| NSResizableWindowMask
| NSMiniaturizableWindowMask
styleMask: NSWindowStyleMaskTitled
| NSWindowStyleMaskClosable
| NSWindowStyleMaskResizable
| NSWindowStyleMaskMiniaturizable
backing: NSBackingStoreBuffered
defer: YES];
[self setTitle: @"Subplot Configuration Tool"];
Expand Down Expand Up @@ -1624,7 +1658,7 @@ -(void)drawRect:(NSRect)rect

PyGILState_STATE gstate = PyGILState_Ensure();

CGContextRef cr = [[NSGraphicsContext currentContext] graphicsPort];
CGContextRef cr = [[NSGraphicsContext currentContext] CGContext];

double new_device_scale = _get_device_scale(cr);

Expand Down Expand Up @@ -1694,7 +1728,7 @@ - (void)windowWillClose:(NSNotification*)notification
- (BOOL)windowShouldClose:(NSNotification*)notification
{
NSWindow* window = [self window];
NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
location: NSZeroPoint
modifierFlags: 0
timestamp: 0.0
Expand Down Expand Up @@ -1760,12 +1794,12 @@ - (void)mouseDown:(NSEvent *)event
x = location.x * device_scale;
y = location.y * device_scale;
switch ([event type])
{ case NSLeftMouseDown:
{ case NSEventTypeLeftMouseDown:
{ unsigned int modifier = [event modifierFlags];
if (modifier & NSControlKeyMask)
if (modifier & NSEventModifierFlagControl)
/* emulate a right-button click */
num = 3;
else if (modifier & NSAlternateKeyMask)
else if (modifier & NSEventModifierFlagOption)
/* emulate a middle-button click */
num = 2;
else
Expand All @@ -1776,8 +1810,8 @@ - (void)mouseDown:(NSEvent *)event
}
break;
}
case NSOtherMouseDown: num = 2; break;
case NSRightMouseDown: num = 3; break;
case NSEventTypeOtherMouseDown: num = 2; break;
case NSEventTypeRightMouseDown: num = 3; break;
default: return; /* Unknown mouse event */
}
if ([event clickCount] == 2) {
Expand All @@ -1804,13 +1838,13 @@ - (void)mouseUp:(NSEvent *)event
x = location.x * device_scale;
y = location.y * device_scale;
switch ([event type])
{ case NSLeftMouseUp:
{ case NSEventTypeLeftMouseUp:
num = 1;
if ([NSCursor currentCursor]==[NSCursor closedHandCursor])
[[NSCursor openHandCursor] set];
break;
case NSOtherMouseUp: num = 2; break;
case NSRightMouseUp: num = 3; break;
case NSEventTypeOtherMouseUp: num = 2; break;
case NSEventTypeRightMouseUp: num = 3; break;
default: return; /* Unknown mouse event */
}
gstate = PyGILState_Ensure();
Expand Down Expand Up @@ -2039,17 +2073,17 @@ - (const char*)convertKeyEvent:(NSEvent*)event
];

NSMutableString* returnkey = [NSMutableString string];
if ([event modifierFlags] & NSControlKeyMask)
if ([event modifierFlags] & NSEventModifierFlagControl)
[returnkey appendString:@"ctrl+" ];
if ([event modifierFlags] & NSAlternateKeyMask)
if ([event modifierFlags] & NSEventModifierFlagOption)
[returnkey appendString:@"alt+" ];
if ([event modifierFlags] & NSCommandKeyMask)
if ([event modifierFlags] & NSEventModifierFlagCommand)
[returnkey appendString:@"cmd+" ];

unichar uc = [[event charactersIgnoringModifiers] characterAtIndex:0];
NSString* specialchar = [specialkeymappings objectForKey:[NSNumber numberWithUnsignedLong:uc]];
if (specialchar){
if ([event modifierFlags] & NSShiftKeyMask)
if ([event modifierFlags] & NSEventModifierFlagShift)
[returnkey appendString:@"shift+" ];
[returnkey appendString:specialchar];
}
Expand Down