18
18
#define COMPILING_FOR_10_10
19
19
#endif
20
20
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
21
55
22
56
/* CGFloat was defined in Mac OS X 10.5 */
23
57
#ifndef CGFLOAT_DEFINED
@@ -140,7 +174,7 @@ static int wait_for_stdin(void)
140
174
NSEvent * event;
141
175
while (true ) {
142
176
while (true ) {
143
- event = [NSApp nextEventMatchingMask: NSAnyEventMask
177
+ event = [NSApp nextEventMatchingMask: NSEventMaskAny
144
178
untilDate: [NSDate distantPast ]
145
179
inMode: NSDefaultRunLoopMode
146
180
dequeue: YES ];
@@ -486,11 +520,11 @@ static CGFloat _get_device_scale(CGContextRef cr)
486
520
(timeout > 0.0 ) ? [NSDate dateWithTimeIntervalSinceNow: timeout]
487
521
: [NSDate distantFuture ];
488
522
while (true )
489
- { NSEvent * event = [NSApp nextEventMatchingMask: NSAnyEventMask
523
+ { NSEvent * event = [NSApp nextEventMatchingMask: NSEventMaskAny
490
524
untilDate: date
491
525
inMode: NSDefaultRunLoopMode
492
526
dequeue: YES ];
493
- if (!event || [event type ]==NSApplicationDefined ) break ;
527
+ if (!event || [event type ]==NSEventTypeApplicationDefined ) break ;
494
528
[NSApp sendEvent: event];
495
529
}
496
530
@@ -506,7 +540,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
506
540
static PyObject*
507
541
FigureCanvas_stop_event_loop (FigureCanvas* self)
508
542
{
509
- NSEvent * event = [NSEvent otherEventWithType: NSApplicationDefined
543
+ NSEvent * event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
510
544
location: NSZeroPoint
511
545
modifierFlags: 0
512
546
timestamp: 0.0
@@ -666,10 +700,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
666
700
rect.size .width = width;
667
701
668
702
self->window = [self ->window initWithContentRect: rect
669
- styleMask: NSTitledWindowMask
670
- | NSClosableWindowMask
671
- | NSResizableWindowMask
672
- | NSMiniaturizableWindowMask
703
+ styleMask: NSWindowStyleMaskTitled
704
+ | NSWindowStyleMaskClosable
705
+ | NSWindowStyleMaskResizable
706
+ | NSWindowStyleMaskMiniaturizable
673
707
backing: NSBackingStoreBuffered
674
708
defer: YES
675
709
withManager: (PyObject*)self ];
@@ -1132,13 +1166,13 @@ -(void)save_figure:(id)sender
1132
1166
@selector (zoom: ),
1133
1167
@selector (configure_subplots: ),
1134
1168
@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 };
1142
1176
1143
1177
rect.origin .x = 0 ;
1144
1178
rect.origin .y = 0 ;
@@ -1164,7 +1198,7 @@ -(void)save_figure:(id)sender
1164
1198
NSImage * image = [[NSImage alloc ] initWithContentsOfFile: filename];
1165
1199
buttons[i] = [[NSButton alloc ] initWithFrame: rect];
1166
1200
[image setSize: size];
1167
- [buttons[i] setBezelStyle: NSShadowlessSquareBezelStyle ];
1201
+ [buttons[i] setBezelStyle: NSBezelStyleShadowlessSquare ];
1168
1202
[buttons[i] setButtonType: buttontypes[i]];
1169
1203
[buttons[i] setImage: image];
1170
1204
[buttons[i] scaleUnitSquareToSize: scale];
@@ -1494,10 +1528,10 @@ @implementation ToolWindow
1494
1528
- (ToolWindow*)initWithContentRect : (NSRect )rect master : (NSWindow *)window
1495
1529
{
1496
1530
[self initWithContentRect: rect
1497
- styleMask: NSTitledWindowMask
1498
- | NSClosableWindowMask
1499
- | NSResizableWindowMask
1500
- | NSMiniaturizableWindowMask
1531
+ styleMask: NSWindowStyleMaskTitled
1532
+ | NSWindowStyleMaskClosable
1533
+ | NSWindowStyleMaskResizable
1534
+ | NSWindowStyleMaskMiniaturizable
1501
1535
backing: NSBackingStoreBuffered
1502
1536
defer: YES ];
1503
1537
[self setTitle: @" Subplot Configuration Tool" ];
@@ -1624,7 +1658,7 @@ -(void)drawRect:(NSRect)rect
1624
1658
1625
1659
PyGILState_STATE gstate = PyGILState_Ensure ();
1626
1660
1627
- CGContextRef cr = [[NSGraphicsContext currentContext ] graphicsPort ];
1661
+ CGContextRef cr = [[NSGraphicsContext currentContext ] CGContext ];
1628
1662
1629
1663
double new_device_scale = _get_device_scale (cr);
1630
1664
@@ -1694,7 +1728,7 @@ - (void)windowWillClose:(NSNotification*)notification
1694
1728
- (BOOL )windowShouldClose : (NSNotification *)notification
1695
1729
{
1696
1730
NSWindow * window = [self window ];
1697
- NSEvent * event = [NSEvent otherEventWithType: NSApplicationDefined
1731
+ NSEvent * event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
1698
1732
location: NSZeroPoint
1699
1733
modifierFlags: 0
1700
1734
timestamp: 0.0
@@ -1760,12 +1794,12 @@ - (void)mouseDown:(NSEvent *)event
1760
1794
x = location.x * device_scale;
1761
1795
y = location.y * device_scale;
1762
1796
switch ([event type ])
1763
- { case NSLeftMouseDown :
1797
+ { case NSEventTypeLeftMouseDown :
1764
1798
{ unsigned int modifier = [event modifierFlags ];
1765
- if (modifier & NSControlKeyMask )
1799
+ if (modifier & NSEventModifierFlagControl )
1766
1800
/* emulate a right-button click */
1767
1801
num = 3 ;
1768
- else if (modifier & NSAlternateKeyMask )
1802
+ else if (modifier & NSEventModifierFlagOption )
1769
1803
/* emulate a middle-button click */
1770
1804
num = 2 ;
1771
1805
else
@@ -1776,8 +1810,8 @@ - (void)mouseDown:(NSEvent *)event
1776
1810
}
1777
1811
break ;
1778
1812
}
1779
- case NSOtherMouseDown : num = 2 ; break ;
1780
- case NSRightMouseDown : num = 3 ; break ;
1813
+ case NSEventTypeOtherMouseDown : num = 2 ; break ;
1814
+ case NSEventTypeRightMouseDown : num = 3 ; break ;
1781
1815
default : return ; /* Unknown mouse event */
1782
1816
}
1783
1817
if ([event clickCount ] == 2 ) {
@@ -1804,13 +1838,13 @@ - (void)mouseUp:(NSEvent *)event
1804
1838
x = location.x * device_scale;
1805
1839
y = location.y * device_scale;
1806
1840
switch ([event type ])
1807
- { case NSLeftMouseUp :
1841
+ { case NSEventTypeLeftMouseUp :
1808
1842
num = 1 ;
1809
1843
if ([NSCursor currentCursor ]==[NSCursor closedHandCursor ])
1810
1844
[[NSCursor openHandCursor ] set ];
1811
1845
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 ;
1814
1848
default : return ; /* Unknown mouse event */
1815
1849
}
1816
1850
gstate = PyGILState_Ensure ();
@@ -2039,17 +2073,17 @@ - (const char*)convertKeyEvent:(NSEvent*)event
2039
2073
];
2040
2074
2041
2075
NSMutableString * returnkey = [NSMutableString string ];
2042
- if ([event modifierFlags ] & NSControlKeyMask )
2076
+ if ([event modifierFlags ] & NSEventModifierFlagControl )
2043
2077
[returnkey appendString: @" ctrl+" ];
2044
- if ([event modifierFlags ] & NSAlternateKeyMask )
2078
+ if ([event modifierFlags ] & NSEventModifierFlagOption )
2045
2079
[returnkey appendString: @" alt+" ];
2046
- if ([event modifierFlags ] & NSCommandKeyMask )
2080
+ if ([event modifierFlags ] & NSEventModifierFlagCommand )
2047
2081
[returnkey appendString: @" cmd+" ];
2048
2082
2049
2083
unichar uc = [[event charactersIgnoringModifiers ] characterAtIndex: 0 ];
2050
2084
NSString * specialchar = [specialkeymappings objectForKey: [NSNumber numberWithUnsignedLong: uc]];
2051
2085
if (specialchar){
2052
- if ([event modifierFlags ] & NSShiftKeyMask )
2086
+ if ([event modifierFlags ] & NSEventModifierFlagShift )
2053
2087
[returnkey appendString: @" shift+" ];
2054
2088
[returnkey appendString: specialchar];
2055
2089
}
0 commit comments