1818#define COMPILING_FOR_10_10
1919#endif
2020
21+ #if __MAC_OS_X_VERSION_MAX_ALLOWED < 101200
22+ /* A lot of symbols were renamed in Sierra and cause deprecation warnings
23+ so define macros for the new names if we are compiling on an older SDK */
24+ #define NSEventMaskAny NSAnyEventMask
25+ #define NSEventTypeApplicationDefined NSApplicationDefined
26+ #define NSEventModifierFlagCommand NSCommandKeyMask
27+ #define NSEventModifierFlagControl NSControlKeyMask
28+ #define NSEventModifierFlagOption NSAlternateKeyMask
29+ #define NSEventModifierFlagShift NSShiftKeyMask
30+ #define NSEventTypeKeyUp NSKeyUp
31+ #define NSEventTypeKeyDown NSKeyDown
32+ #define NSEventTypeMouseMoved NSMouseMoved
33+ #define NSEventTypeLeftMouseDown NSLeftMouseDown
34+ #define NSEventTypeRightMouseDown NSRightMouseDown
35+ #define NSEventTypeOtherMouseDown NSOtherMouseDown
36+ #define NSEventTypeLeftMouseDragged NSLeftMouseDragged
37+ #define NSEventTypeRightMouseDragged NSRightMouseDragged
38+ #define NSEventTypeOtherMouseDragged NSOtherMouseDragged
39+ #define NSEventTypeLeftMouseUp NSLeftMouseUp
40+ #define NSEventTypeRightMouseUp NSRightMouseUp
41+ #define NSEventTypeOtherMouseUp NSOtherMouseUp
42+ #define NSWindowStyleMaskClosable NSClosableWindowMask
43+ #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
44+ #define NSWindowStyleMaskResizable NSResizableWindowMask
45+ #define NSWindowStyleMaskTitled NSTitledWindowMask
46+ #endif
47+
48+ #if __MAC_OS_X_VERSION_MAX_ALLOWED < 101400
49+ /* A few more deprecations in Mojave */
50+ #define NSButtonTypeMomentaryLight NSMomentaryLightButton
51+ #define NSButtonTypePushOnPushOff NSPushOnPushOffButton
52+ #define NSBezelStyleShadowlessSquare NSShadowlessSquareBezelStyle
53+ #define CGContext graphicsPort
54+ #endif
2155
2256/* CGFloat was defined in Mac OS X 10.5 */
2357#ifndef CGFLOAT_DEFINED
@@ -140,7 +174,7 @@ static int wait_for_stdin(void)
140174 NSEvent * event;
141175 while (true ) {
142176 while (true ) {
143- event = [NSApp nextEventMatchingMask: NSAnyEventMask
177+ event = [NSApp nextEventMatchingMask: NSEventMaskAny
144178 untilDate: [NSDate distantPast ]
145179 inMode: NSDefaultRunLoopMode
146180 dequeue: YES ];
@@ -486,11 +520,11 @@ static CGFloat _get_device_scale(CGContextRef cr)
486520 (timeout > 0.0 ) ? [NSDate dateWithTimeIntervalSinceNow: timeout]
487521 : [NSDate distantFuture ];
488522 while (true )
489- { NSEvent * event = [NSApp nextEventMatchingMask: NSAnyEventMask
523+ { NSEvent * event = [NSApp nextEventMatchingMask: NSEventMaskAny
490524 untilDate: date
491525 inMode: NSDefaultRunLoopMode
492526 dequeue: YES ];
493- if (!event || [event type ]==NSApplicationDefined ) break ;
527+ if (!event || [event type ]==NSEventTypeApplicationDefined ) break ;
494528 [NSApp sendEvent: event];
495529 }
496530
@@ -506,7 +540,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
506540static PyObject*
507541FigureCanvas_stop_event_loop (FigureCanvas* self)
508542{
509- NSEvent * event = [NSEvent otherEventWithType: NSApplicationDefined
543+ NSEvent * event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
510544 location: NSZeroPoint
511545 modifierFlags: 0
512546 timestamp: 0.0
@@ -666,10 +700,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
666700 rect.size .width = width;
667701
668702 self->window = [self ->window initWithContentRect: rect
669- styleMask: NSTitledWindowMask
670- | NSClosableWindowMask
671- | NSResizableWindowMask
672- | NSMiniaturizableWindowMask
703+ styleMask: NSWindowStyleMaskTitled
704+ | NSWindowStyleMaskClosable
705+ | NSWindowStyleMaskResizable
706+ | NSWindowStyleMaskMiniaturizable
673707 backing: NSBackingStoreBuffered
674708 defer: YES
675709 withManager: (PyObject*)self ];
@@ -1132,13 +1166,13 @@ -(void)save_figure:(id)sender
11321166 @selector (zoom: ),
11331167 @selector (configure_subplots: ),
11341168 @selector (save_figure: )};
1135- NSButtonType buttontypes[7 ] = {NSMomentaryLightButton ,
1136- NSMomentaryLightButton ,
1137- NSMomentaryLightButton ,
1138- NSPushOnPushOffButton ,
1139- NSPushOnPushOffButton ,
1140- NSMomentaryLightButton ,
1141- NSMomentaryLightButton };
1169+ NSButtonType buttontypes[7 ] = {NSButtonTypeMomentaryLight ,
1170+ NSButtonTypeMomentaryLight ,
1171+ NSButtonTypeMomentaryLight ,
1172+ NSButtonTypePushOnPushOff ,
1173+ NSButtonTypePushOnPushOff ,
1174+ NSButtonTypeMomentaryLight ,
1175+ NSButtonTypeMomentaryLight };
11421176
11431177 rect.origin .x = 0 ;
11441178 rect.origin .y = 0 ;
@@ -1164,7 +1198,7 @@ -(void)save_figure:(id)sender
11641198 NSImage * image = [[NSImage alloc ] initWithContentsOfFile: filename];
11651199 buttons[i] = [[NSButton alloc ] initWithFrame: rect];
11661200 [image setSize: size];
1167- [buttons[i] setBezelStyle: NSShadowlessSquareBezelStyle ];
1201+ [buttons[i] setBezelStyle: NSBezelStyleShadowlessSquare ];
11681202 [buttons[i] setButtonType: buttontypes[i]];
11691203 [buttons[i] setImage: image];
11701204 [buttons[i] scaleUnitSquareToSize: scale];
@@ -1494,10 +1528,10 @@ @implementation ToolWindow
14941528- (ToolWindow*)initWithContentRect : (NSRect )rect master : (NSWindow *)window
14951529{
14961530 [self initWithContentRect: rect
1497- styleMask: NSTitledWindowMask
1498- | NSClosableWindowMask
1499- | NSResizableWindowMask
1500- | NSMiniaturizableWindowMask
1531+ styleMask: NSWindowStyleMaskTitled
1532+ | NSWindowStyleMaskClosable
1533+ | NSWindowStyleMaskResizable
1534+ | NSWindowStyleMaskMiniaturizable
15011535 backing: NSBackingStoreBuffered
15021536 defer: YES ];
15031537 [self setTitle: @" Subplot Configuration Tool" ];
@@ -1624,7 +1658,7 @@ -(void)drawRect:(NSRect)rect
16241658
16251659 PyGILState_STATE gstate = PyGILState_Ensure ();
16261660
1627- CGContextRef cr = [[NSGraphicsContext currentContext ] graphicsPort ];
1661+ CGContextRef cr = [[NSGraphicsContext currentContext ] CGContext ];
16281662
16291663 double new_device_scale = _get_device_scale (cr);
16301664
@@ -1694,7 +1728,7 @@ - (void)windowWillClose:(NSNotification*)notification
16941728- (BOOL )windowShouldClose : (NSNotification *)notification
16951729{
16961730 NSWindow * window = [self window ];
1697- NSEvent * event = [NSEvent otherEventWithType: NSApplicationDefined
1731+ NSEvent * event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
16981732 location: NSZeroPoint
16991733 modifierFlags: 0
17001734 timestamp: 0.0
@@ -1760,12 +1794,12 @@ - (void)mouseDown:(NSEvent *)event
17601794 x = location.x * device_scale;
17611795 y = location.y * device_scale;
17621796 switch ([event type ])
1763- { case NSLeftMouseDown :
1797+ { case NSEventTypeLeftMouseDown :
17641798 { unsigned int modifier = [event modifierFlags ];
1765- if (modifier & NSControlKeyMask )
1799+ if (modifier & NSEventModifierFlagControl )
17661800 /* emulate a right-button click */
17671801 num = 3 ;
1768- else if (modifier & NSAlternateKeyMask )
1802+ else if (modifier & NSEventModifierFlagOption )
17691803 /* emulate a middle-button click */
17701804 num = 2 ;
17711805 else
@@ -1776,8 +1810,8 @@ - (void)mouseDown:(NSEvent *)event
17761810 }
17771811 break ;
17781812 }
1779- case NSOtherMouseDown : num = 2 ; break ;
1780- case NSRightMouseDown : num = 3 ; break ;
1813+ case NSEventTypeOtherMouseDown : num = 2 ; break ;
1814+ case NSEventTypeRightMouseDown : num = 3 ; break ;
17811815 default : return ; /* Unknown mouse event */
17821816 }
17831817 if ([event clickCount ] == 2 ) {
@@ -1804,13 +1838,13 @@ - (void)mouseUp:(NSEvent *)event
18041838 x = location.x * device_scale;
18051839 y = location.y * device_scale;
18061840 switch ([event type ])
1807- { case NSLeftMouseUp :
1841+ { case NSEventTypeLeftMouseUp :
18081842 num = 1 ;
18091843 if ([NSCursor currentCursor ]==[NSCursor closedHandCursor ])
18101844 [[NSCursor openHandCursor ] set ];
18111845 break ;
1812- case NSOtherMouseUp : num = 2 ; break ;
1813- case NSRightMouseUp : num = 3 ; break ;
1846+ case NSEventTypeOtherMouseUp : num = 2 ; break ;
1847+ case NSEventTypeRightMouseUp : num = 3 ; break ;
18141848 default : return ; /* Unknown mouse event */
18151849 }
18161850 gstate = PyGILState_Ensure ();
@@ -2039,17 +2073,17 @@ - (const char*)convertKeyEvent:(NSEvent*)event
20392073 ];
20402074
20412075 NSMutableString * returnkey = [NSMutableString string ];
2042- if ([event modifierFlags ] & NSControlKeyMask )
2076+ if ([event modifierFlags ] & NSEventModifierFlagControl )
20432077 [returnkey appendString: @" ctrl+" ];
2044- if ([event modifierFlags ] & NSAlternateKeyMask )
2078+ if ([event modifierFlags ] & NSEventModifierFlagOption )
20452079 [returnkey appendString: @" alt+" ];
2046- if ([event modifierFlags ] & NSCommandKeyMask )
2080+ if ([event modifierFlags ] & NSEventModifierFlagCommand )
20472081 [returnkey appendString: @" cmd+" ];
20482082
20492083 unichar uc = [[event charactersIgnoringModifiers ] characterAtIndex: 0 ];
20502084 NSString * specialchar = [specialkeymappings objectForKey: [NSNumber numberWithUnsignedLong: uc]];
20512085 if (specialchar){
2052- if ([event modifierFlags ] & NSShiftKeyMask )
2086+ if ([event modifierFlags ] & NSEventModifierFlagShift )
20532087 [returnkey appendString: @" shift+" ];
20542088 [returnkey appendString: specialchar];
20552089 }
0 commit comments