Mercurial > dwindows
comparison mac/dw.m @ 1940:38a50e0820b1
Mac: Moved all 10.12 related constants to the top of the source, vastly reducing the number of #ifdefs.
Found potentially a couple of errors in the existing #ifdefs ... will test more thoroughly.
Also that last fix for WKWebKit didn't seem to work, so just using WKWebKit on Mojave an higher now.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 21 Jun 2019 22:07:30 +0000 |
parents | 83148aaa35a5 |
children | b498fb0360fc |
comparison
equal
deleted
inserted
replaced
1939:83148aaa35a5 | 1940:38a50e0820b1 |
---|---|
50 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \ | 50 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \ |
51 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \ | 51 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \ |
52 localpool = [[NSAutoreleasePool alloc] init]; | 52 localpool = [[NSAutoreleasePool alloc] init]; |
53 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain]; | 53 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain]; |
54 | 54 |
55 /* For some reason WKWebView is undefined on some versions that supposed to support it */ | |
56 #ifdef WKWebView | |
57 #define DWWebView WKWebView | |
58 #else | |
59 #define DWWebView WebView | |
60 #endif | |
61 | |
62 /* Handle deprecation of several constants in 10.10... | 55 /* Handle deprecation of several constants in 10.10... |
63 * the replacements are not available in earlier versions. | 56 * the replacements are not available in earlier versions. |
64 */ | 57 */ |
65 #if defined(MAC_OS_X_VERSION_10_10) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED)) | 58 #if defined(MAC_OS_X_VERSION_10_10) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED)) |
66 #define DWModalResponseOK NSModalResponseOK | 59 #define DWModalResponseOK NSModalResponseOK |
80 #define DWButtonTypeSwitch NSButtonTypeSwitch | 73 #define DWButtonTypeSwitch NSButtonTypeSwitch |
81 #define DWButtonTypeRadio NSButtonTypeRadio | 74 #define DWButtonTypeRadio NSButtonTypeRadio |
82 #define DWButtonTypeMomentaryPushIn NSButtonTypeMomentaryPushIn | 75 #define DWButtonTypeMomentaryPushIn NSButtonTypeMomentaryPushIn |
83 #define DWBezelStyleRegularSquare NSBezelStyleRegularSquare | 76 #define DWBezelStyleRegularSquare NSBezelStyleRegularSquare |
84 #define DWBezelStyleRounded NSBezelStyleRounded | 77 #define DWBezelStyleRounded NSBezelStyleRounded |
78 #define DWEventTypeApplicationDefined NSEventTypeApplicationDefined | |
79 #define DWCompositingOperationSourceOver NSCompositingOperationSourceOver | |
80 #define DWEventTypeKeyDown NSEventTypeKeyDown | |
81 #define DWEventModifierFlagControl NSEventModifierFlagControl | |
82 #define DWEventModifierFlagCommand NSEventModifierFlagCommand | |
83 #define DWEventModifierFlagOption NSEventModifierFlagOption | |
84 #define DWEventTypeRightMouseDown NSEventTypeRightMouseDown | |
85 #define DWEventTypeRightMouseUp NSEventTypeRightMouseUp | |
86 #define DWEventTypeLeftMouseDown NSEventTypeLeftMouseDown | |
87 #define DWEventTypeLeftMouseUp NSEventTypeLeftMouseUp | |
88 #define DWEventTypeOtherMouseDown NSEventTypeOtherMouseDown | |
89 #define DWEventTypeOtherMouseUp NSEventTypeOtherMouseUp | |
90 #define DWEventModifierFlagDeviceIndependentFlagsMask NSEventModifierFlagDeviceIndependentFlagsMask | |
91 #define DWEventMaskAny NSEventMaskAny | |
92 #define DWAlertStyleCritical NSAlertStyleCritical | |
93 #define DWAlertStyleInformational NSAlertStyleInformational | |
94 #define DWAlertStyleWarning NSAlertStyleWarning | |
95 #define DWTextAlignmentCenter NSTextAlignmentCenter | |
96 #define DWTextAlignmentRight NSTextAlignmentRight | |
97 #define DWTextAlignmentLeft NSTextAlignmentLeft | |
98 #define DWEventMaskLeftMouseUp NSEventMaskLeftMouseUp | |
99 #define DWEventMaskLeftMouseDown NSEventMaskLeftMouseDown | |
100 #define DWEventMaskRightMouseUp NSEventMaskRightMouseUp | |
101 #define DWEventMaskRightMouseDown NSEventMaskRightMouseDown | |
102 #define DWWindowStyleMaskResizable NSWindowStyleMaskResizable | |
85 #define BUILDING_FOR_SIERRA | 103 #define BUILDING_FOR_SIERRA |
86 #else | 104 #else |
87 #define DWButtonTypeSwitch NSSwitchButton | 105 #define DWButtonTypeSwitch NSSwitchButton |
88 #define DWButtonTypeRadio NSRadioButton | 106 #define DWButtonTypeRadio NSRadioButton |
89 #define DWButtonTypeMomentaryPushIn NSMomentaryPushInButton | 107 #define DWButtonTypeMomentaryPushIn NSMomentaryPushInButton |
90 #define DWBezelStyleRegularSquare NSRegularSquareBezelStyle | 108 #define DWBezelStyleRegularSquare NSRegularSquareBezelStyle |
91 #define DWBezelStyleRounded NSRoundedBezelStyle | 109 #define DWBezelStyleRounded NSRoundedBezelStyle |
110 #define DWEventTypeApplicationDefined NSApplicationDefined | |
111 #define DWCompositingOperationSourceOver NSCompositeSourceOver | |
112 #define DWEventTypeKeyDown NSKeyDown | |
113 #define DWEventModifierFlagControl NSControlKeyMask | |
114 #define DWEventModifierFlagCommand NSCommandKeyMask | |
115 #define DWEventModifierFlagOption NSAlternateKeyMask | |
116 #define DWEventTypeRightMouseDown NSRightMouseDown | |
117 #define DWEventTypeRightMouseUp NSRightMouseUp | |
118 #define DWEventTypeLeftMouseDown NSLeftMouseDown | |
119 #define DWEventTypeLeftMouseUp NSLeftMouseUp | |
120 #define DWEventTypeOtherMouseDown NSOtherMouseDown | |
121 #define DWEventTypeOtherMouseUp NSOtherMouseUp | |
122 #define DWEventModifierFlagDeviceIndependentFlagsMask NSDeviceIndependentModifierFlagsMask | |
123 #define DWEventMaskAny NSAnyEventMask | |
124 #define DWAlertStyleCritical NSCriticalAlertStyle | |
125 #define DWAlertStyleInformational NSInformationalAlertStyle | |
126 #define DWAlertStyleWarning NSWarningAlertStyle | |
127 #define DWTextAlignmentCenter NSCenterTextAlignment | |
128 #define DWTextAlignmentRight NSRightTextAlignment | |
129 #define DWTextAlignmentLeft NSLeftTextAlignment | |
130 #define DWEventMaskLeftMouseUp NSLeftMouseUpMask | |
131 #define DWEventMaskLeftMouseDown NSLeftMouseDownMask | |
132 #define DWEventMaskRightMouseUp NSRightMouseUpMask | |
133 #define DWEventMaskRightMouseDown NSRightMouseDownMask | |
134 #define DWWindowStyleMaskResizable NSResizableWindowMask | |
92 #endif | 135 #endif |
93 | 136 |
94 /* Handle deprecation of several constants in 10.13... | 137 /* Handle deprecation of several constants in 10.13... |
95 * the replacements are not available in earlier versions. | 138 * the replacements are not available in earlier versions. |
96 */ | 139 */ |
99 #define DWControlStateValueOn NSControlStateValueOn | 142 #define DWControlStateValueOn NSControlStateValueOn |
100 #define BUILDING_FOR_HIGH_SIERRA | 143 #define BUILDING_FOR_HIGH_SIERRA |
101 #else | 144 #else |
102 #define DWControlStateValueOff NSOffState | 145 #define DWControlStateValueOff NSOffState |
103 #define DWControlStateValueOn NSOnState | 146 #define DWControlStateValueOn NSOnState |
147 #endif | |
148 | |
149 /* Handle deprecation of several constants in 10.14... | |
150 * the replacements are not available in earlier versions. | |
151 */ | |
152 #if defined(MAC_OS_X_VERSION_10_14) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED)) | |
153 #define DWWebView WKWebView | |
154 #define BUILDING_FOR_MOJAVE | |
155 #else | |
156 #define DWWebView WebView | |
104 #endif | 157 #endif |
105 | 158 |
106 unsigned long _colors[] = | 159 unsigned long _colors[] = |
107 { | 160 { |
108 0x00000000, /* 0 black */ | 161 0x00000000, /* 0 black */ |
351 id view = [[[event window] contentView] superview]; | 404 id view = [[[event window] contentView] superview]; |
352 NSEventType type = [event type]; | 405 NSEventType type = [event type]; |
353 | 406 |
354 p = [view convertPoint:[event locationInWindow] toView:object]; | 407 p = [view convertPoint:[event locationInWindow] toView:object]; |
355 | 408 |
356 #ifdef MAC_OS_X_VERSION_10_12 | 409 if(type == DWEventTypeRightMouseDown || type == DWEventTypeRightMouseUp) |
357 if(type == NSEventTypeRightMouseDown || type == NSEventTypeRightMouseUp) | |
358 #else | |
359 if(type == NSRightMouseDown || type == NSRightMouseUp) | |
360 #endif | |
361 { | 410 { |
362 button = 2; | 411 button = 2; |
363 } | 412 } |
364 #ifdef MAC_OS_X_VERSION_10_12 | 413 else if(type == DWEventTypeOtherMouseDown || type == DWEventTypeOtherMouseUp) |
365 else if(type == NSEventTypeOtherMouseDown || type == NSEventTypeOtherMouseDown) | |
366 #else | |
367 else if(type == NSOtherMouseDown || type == NSOtherMouseUp) | |
368 #endif | |
369 { | 414 { |
370 button = 3; | 415 button = 3; |
371 } | 416 } |
372 #ifdef MAC_OS_X_VERSION_10_12 | 417 else if([event modifierFlags] & DWEventModifierFlagControl) |
373 else if([event modifierFlags] & NSEventModifierFlagControl) | |
374 #else | |
375 else if([event modifierFlags] & NSControlKeyMask) | |
376 #endif | |
377 { | 418 { |
378 button = 2; | 419 button = 2; |
379 } | 420 } |
380 } | 421 } |
381 | 422 |
569 DWTID _dw_mutex_locked = (DWTID)-1; | 610 DWTID _dw_mutex_locked = (DWTID)-1; |
570 | 611 |
571 /* Send fake event to make sure the loop isn't stuck */ | 612 /* Send fake event to make sure the loop isn't stuck */ |
572 void _dw_wakeup_app() | 613 void _dw_wakeup_app() |
573 { | 614 { |
574 #ifdef MAC_OS_X_VERSION_10_12 | 615 [DWApp postEvent:[NSEvent otherEventWithType:DWEventTypeApplicationDefined |
575 [DWApp postEvent:[NSEvent otherEventWithType:NSEventTypeApplicationDefined | |
576 #else | |
577 [DWApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined | |
578 #endif | |
579 location:NSMakePoint(0, 0) | 616 location:NSMakePoint(0, 0) |
580 modifierFlags:0 | 617 modifierFlags:0 |
581 timestamp:0 | 618 timestamp:0 |
582 windowNumber:0 | 619 windowNumber:0 |
583 context:NULL | 620 context:NULL |
667 if([bltsrc isMemberOfClass:[NSBitmapImageRep class]]) | 704 if([bltsrc isMemberOfClass:[NSBitmapImageRep class]]) |
668 { | 705 { |
669 NSBitmapImageRep *rep = bltsrc; | 706 NSBitmapImageRep *rep = bltsrc; |
670 NSImage *image = [NSImage alloc]; | 707 NSImage *image = [NSImage alloc]; |
671 SEL siwc = NSSelectorFromString(@"initWithCGImage"); | 708 SEL siwc = NSSelectorFromString(@"initWithCGImage"); |
672 #ifdef MAC_OS_X_VERSION_10_12 | 709 NSCompositingOperation op = DWCompositingOperationSourceOver; |
673 NSCompositingOperation op = NSCompositingOperationSourceOver; | |
674 #else | |
675 NSCompositingOperation op = NSCompositeSourceOver; | |
676 #endif | |
677 | 710 |
678 if([image respondsToSelector:siwc]) | 711 if([image respondsToSelector:siwc]) |
679 { | 712 { |
680 IMP iiwc = [image methodForSelector:siwc]; | 713 IMP iiwc = [image methodForSelector:siwc]; |
681 image = iiwc(image, siwc, [rep CGImage], NSZeroSize); | 714 image = iiwc(image, siwc, [rep CGImage], NSZeroSize); |
885 | 918 |
886 @implementation DWWindow | 919 @implementation DWWindow |
887 -(void)sendEvent:(NSEvent *)theEvent | 920 -(void)sendEvent:(NSEvent *)theEvent |
888 { | 921 { |
889 int rcode = -1; | 922 int rcode = -1; |
890 #ifdef MAC_OS_X_VERSION_10_12 | 923 if([theEvent type] == DWEventTypeKeyDown) |
891 if([theEvent type] == NSEventTypeKeyDown) | |
892 #else | |
893 if([theEvent type] == NSKeyDown) | |
894 #endif | |
895 { | 924 { |
896 rcode = _event_handler(self, theEvent, 2); | 925 rcode = _event_handler(self, theEvent, 2); |
897 } | 926 } |
898 if ( rcode != TRUE ) | 927 if ( rcode != TRUE ) |
899 [super sendEvent:theEvent]; | 928 [super sendEvent:theEvent]; |
938 -(NSFont *)font { return font; } | 967 -(NSFont *)font { return font; } |
939 -(void)setSize:(NSSize)input { size = input; } | 968 -(void)setSize:(NSSize)input { size = input; } |
940 -(NSSize)size { return size; } | 969 -(NSSize)size { return size; } |
941 -(void)mouseDown:(NSEvent *)theEvent | 970 -(void)mouseDown:(NSEvent *)theEvent |
942 { | 971 { |
943 #ifdef MAC_OS_X_VERSION_10_12 | 972 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & DWEventModifierFlagControl)) |
944 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & NSEventModifierFlagControl)) | |
945 #else | |
946 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & NSControlKeyMask)) | |
947 #endif | |
948 _event_handler(self, theEvent, 3); | 973 _event_handler(self, theEvent, 3); |
949 } | 974 } |
950 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 975 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
951 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } | 976 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } |
952 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 977 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
1326 [super keyUp:theEvent]; | 1351 [super keyUp:theEvent]; |
1327 } | 1352 } |
1328 } | 1353 } |
1329 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent | 1354 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent |
1330 { | 1355 { |
1331 #ifdef MAC_OS_X_VERSION_10_12 | 1356 if(([theEvent modifierFlags] & DWEventModifierFlagDeviceIndependentFlagsMask) == DWEventModifierFlagCommand) |
1332 if(([theEvent modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask) == NSEventModifierFlagCommand) | |
1333 #else | |
1334 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) | |
1335 #endif | |
1336 { | 1357 { |
1337 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) | 1358 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) |
1338 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; | 1359 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; |
1339 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) | 1360 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) |
1340 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; | 1361 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; |
1394 [super keyUp:theEvent]; | 1415 [super keyUp:theEvent]; |
1395 } | 1416 } |
1396 } | 1417 } |
1397 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent | 1418 -(BOOL)performKeyEquivalent:(NSEvent *)theEvent |
1398 { | 1419 { |
1399 #ifdef MAC_OS_X_VERSION_10_12 | 1420 if(([theEvent modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask) == DWEventModifierFlagCommand) |
1400 if(([theEvent modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask) == NSEventModifierFlagControl) | |
1401 #else | |
1402 if(([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) | |
1403 #endif | |
1404 { | 1421 { |
1405 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) | 1422 if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"x"]) |
1406 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; | 1423 return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self]; |
1407 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) | 1424 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"c"]) |
1408 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; | 1425 return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self]; |
1800 if(image != nil) | 1817 if(image != nil) |
1801 { | 1818 { |
1802 NSSize imageSize; | 1819 NSSize imageSize; |
1803 NSRect imageFrame; | 1820 NSRect imageFrame; |
1804 SEL sdir = NSSelectorFromString(@"drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); | 1821 SEL sdir = NSSelectorFromString(@"drawInRect:fromRect:operation:fraction:respectFlipped:hints:"); |
1805 #ifdef MAC_OS_X_VERSION_10_12 | 1822 NSCompositingOperation op = DWCompositingOperationSourceOver; |
1806 NSCompositingOperation op = NSCompositingOperationSourceOver; | |
1807 #else | |
1808 NSCompositingOperation op = NSCompositeSourceOver; | |
1809 #endif | |
1810 | 1823 |
1811 imageSize = [image size]; | 1824 imageSize = [image size]; |
1812 NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge); | 1825 NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge); |
1813 if ([self drawsBackground]) | 1826 if ([self drawsBackground]) |
1814 { | 1827 { |
2691 -(void)setParent:(id)input { parent = input; } | 2704 -(void)setParent:(id)input { parent = input; } |
2692 -(id)parent { return parent; } | 2705 -(id)parent { return parent; } |
2693 -(void)mouseDown:(NSEvent *)event | 2706 -(void)mouseDown:(NSEvent *)event |
2694 { | 2707 { |
2695 [super mouseDown:event]; | 2708 [super mouseDown:event]; |
2696 #ifdef MAC_OS_X_VERSION_10_12 | 2709 if([[NSApp currentEvent] type] == DWEventTypeLeftMouseUp) |
2697 if([[NSApp currentEvent] type] == NSEventTypeLeftMouseUp) | |
2698 #else | |
2699 if([[NSApp currentEvent] type] == NSLeftMouseUp) | |
2700 #endif | |
2701 [self mouseUp:event]; | 2710 [self mouseUp:event]; |
2702 } | 2711 } |
2703 -(void)mouseUp:(NSEvent *)event | 2712 -(void)mouseUp:(NSEvent *)event |
2704 { | 2713 { |
2705 [textfield takeIntValueFrom:self]; | 2714 [textfield takeIntValueFrom:self]; |
3272 [item setTarget:DWApp]; | 3281 [item setTarget:DWApp]; |
3273 | 3282 |
3274 item = [menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil) | 3283 item = [menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil) |
3275 action:@selector(hideOtherApplications:) | 3284 action:@selector(hideOtherApplications:) |
3276 keyEquivalent:@"h"]; | 3285 keyEquivalent:@"h"]; |
3277 #ifdef MAC_OS_X_VERSION_10_12 | 3286 [item setKeyEquivalentModifierMask:DWEventModifierFlagCommand | DWEventModifierFlagOption]; |
3278 [item setKeyEquivalentModifierMask:NSEventModifierFlagCommand | NSEventModifierFlagOption]; | |
3279 #else | |
3280 [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask]; | |
3281 #endif | |
3282 [item setTarget:DWApp]; | 3287 [item setTarget:DWApp]; |
3283 | 3288 |
3284 item = [menu addItemWithTitle:NSLocalizedString(@"Show All", nil) | 3289 item = [menu addItemWithTitle:NSLocalizedString(@"Show All", nil) |
3285 action:@selector(unhideAllApplications:) | 3290 action:@selector(unhideAllApplications:) |
3286 keyEquivalent:@""]; | 3291 keyEquivalent:@""]; |
3358 } | 3363 } |
3359 | 3364 |
3360 /* Internal version that doesn't lock the run mutex */ | 3365 /* Internal version that doesn't lock the run mutex */ |
3361 int _dw_main_iteration(NSDate *date) | 3366 int _dw_main_iteration(NSDate *date) |
3362 { | 3367 { |
3363 #ifdef MAC_OS_X_VERSION_10_12 | 3368 NSEvent *event = [DWApp nextEventMatchingMask:DWEventMaskAny |
3364 NSEvent *event = [DWApp nextEventMatchingMask:NSEventMaskAny | |
3365 #else | |
3366 NSEvent *event = [DWApp nextEventMatchingMask:NSAnyEventMask | |
3367 #endif | |
3368 untilDate:date | 3369 untilDate:date |
3369 inMode:NSDefaultRunLoopMode | 3370 inMode:NSDefaultRunLoopMode |
3370 dequeue:YES]; | 3371 dequeue:YES]; |
3371 if(event) | 3372 if(event) |
3372 { | 3373 { |
3521 [alert addButtonWithTitle:button2]; | 3522 [alert addButtonWithTitle:button2]; |
3522 if(button3) | 3523 if(button3) |
3523 [alert addButtonWithTitle:button3]; | 3524 [alert addButtonWithTitle:button3]; |
3524 va_end(args); | 3525 va_end(args); |
3525 | 3526 |
3526 #ifdef MAC_OS_X_VERSION_10_12 | |
3527 if(flags & DW_MB_ERROR) | 3527 if(flags & DW_MB_ERROR) |
3528 [alert setAlertStyle:NSAlertStyleCritical]; | 3528 [alert setAlertStyle:DWAlertStyleCritical]; |
3529 else if(flags & DW_MB_INFORMATION) | 3529 else if(flags & DW_MB_INFORMATION) |
3530 [alert setAlertStyle:NSAlertStyleInformational]; | 3530 [alert setAlertStyle:DWAlertStyleInformational]; |
3531 else | 3531 else |
3532 [alert setAlertStyle:NSAlertStyleWarning]; | 3532 [alert setAlertStyle:DWAlertStyleWarning]; |
3533 #else | |
3534 if(flags & DW_MB_ERROR) | |
3535 [alert setAlertStyle:NSCriticalAlertStyle]; | |
3536 else if(flags & DW_MB_INFORMATION) | |
3537 [alert setAlertStyle:NSInformationalAlertStyle]; | |
3538 else | |
3539 [alert setAlertStyle:NSWarningAlertStyle]; | |
3540 #endif | |
3541 iResponse = [alert runModal]; | 3533 iResponse = [alert runModal]; |
3542 [alert release]; | 3534 [alert release]; |
3543 | 3535 |
3544 switch(iResponse) | 3536 switch(iResponse) |
3545 { | 3537 { |
4552 } | 4544 } |
4553 [button setTarget:button]; | 4545 [button setTarget:button]; |
4554 [button setAction:@selector(buttonClicked:)]; | 4546 [button setAction:@selector(buttonClicked:)]; |
4555 [button setTag:cid]; | 4547 [button setTag:cid]; |
4556 [button setButtonType:DWButtonTypeMomentaryPushIn]; | 4548 [button setButtonType:DWButtonTypeMomentaryPushIn]; |
4557 #ifdef MAC_OS_X_VERSION_10_12 | 4549 [button setBezelStyle:DWBezelStyleRegularSquare]; |
4558 [button setBezelStyle:NSBezelStyleRegularSquare]; | |
4559 #else | |
4560 [button setBezelStyle:NSThickerSquareBezelStyle]; | |
4561 #endif | |
4562 /* TODO: Reenable scaling in the future if it is possible on other platforms. | 4550 /* TODO: Reenable scaling in the future if it is possible on other platforms. |
4563 [[button cell] setImageScaling:NSImageScaleProportionallyDown]; */ | 4551 [[button cell] setImageScaling:NSImageScaleProportionallyDown]; */ |
4564 if(DWDefaultFont) | 4552 if(DWDefaultFont) |
4565 { | 4553 { |
4566 [[button cell] setFont:DWDefaultFont]; | 4554 [[button cell] setFont:DWDefaultFont]; |
4578 { | 4566 { |
4579 DWButton *button = _button_new(text, cid); | 4567 DWButton *button = _button_new(text, cid); |
4580 [button setButtonType:DWButtonTypeMomentaryPushIn]; | 4568 [button setButtonType:DWButtonTypeMomentaryPushIn]; |
4581 [button setBezelStyle:DWBezelStyleRounded]; | 4569 [button setBezelStyle:DWBezelStyleRounded]; |
4582 [button setImagePosition:NSNoImage]; | 4570 [button setImagePosition:NSNoImage]; |
4583 #ifdef MAC_OS_X_VERSION_10_12 | 4571 [button setAlignment:DWTextAlignmentCenter]; |
4584 [button setAlignment:NSTextAlignmentCenter]; | |
4585 #else | |
4586 [button setAlignment:NSCenterTextAlignment]; | |
4587 #endif | |
4588 [[button cell] setControlTint:NSBlueControlTint]; | 4572 [[button cell] setControlTint:NSBlueControlTint]; |
4589 return button; | 4573 return button; |
4590 } | 4574 } |
4591 | 4575 |
4592 /* | 4576 /* |
6686 DWImageAndTextCell *browsercell = [[DWImageAndTextCell alloc] init]; | 6670 DWImageAndTextCell *browsercell = [[DWImageAndTextCell alloc] init]; |
6687 [column setDataCell:browsercell]; | 6671 [column setDataCell:browsercell]; |
6688 [browsercell release]; | 6672 [browsercell release]; |
6689 } | 6673 } |
6690 /* Defaults to left justified so just handle right and center */ | 6674 /* Defaults to left justified so just handle right and center */ |
6691 #ifdef MAC_OS_X_VERSION_10_12 | |
6692 if(flags[z] & DW_CFA_RIGHT) | 6675 if(flags[z] & DW_CFA_RIGHT) |
6693 { | 6676 { |
6694 [(NSCell *)[column dataCell] setAlignment:NSTextAlignmentRight]; | 6677 [(NSCell *)[column dataCell] setAlignment:DWTextAlignmentRight]; |
6695 [(NSCell *)[column headerCell] setAlignment:NSTextAlignmentRight]; | 6678 [(NSCell *)[column headerCell] setAlignment:DWTextAlignmentRight]; |
6696 } | 6679 } |
6697 else if(flags[z] & DW_CFA_CENTER) | 6680 else if(flags[z] & DW_CFA_CENTER) |
6698 { | 6681 { |
6699 [(NSCell *)[column dataCell] setAlignment:NSTextAlignmentCenter]; | 6682 [(NSCell *)[column dataCell] setAlignment:DWTextAlignmentCenter]; |
6700 [(NSCell *)[column headerCell] setAlignment:NSTextAlignmentCenter]; | 6683 [(NSCell *)[column headerCell] setAlignment:DWTextAlignmentCenter]; |
6701 } | 6684 } |
6702 #else | |
6703 if(flags[z] & DW_CFA_RIGHT) | |
6704 { | |
6705 [(NSCell *)[column dataCell] setAlignment:NSRightTextAlignment]; | |
6706 [(NSCell *)[column headerCell] setAlignment:NSRightTextAlignment]; | |
6707 } | |
6708 else if(flags[z] & DW_CFA_CENTER) | |
6709 { | |
6710 [(NSCell *)[column dataCell] setAlignment:NSCenterTextAlignment]; | |
6711 [(NSCell *)[column headerCell] setAlignment:NSCenterTextAlignment]; | |
6712 } | |
6713 #endif | |
6714 [column setEditable:NO]; | 6685 [column setEditable:NO]; |
6715 [cont addTableColumn:column]; | 6686 [cont addTableColumn:column]; |
6716 [cont addColumn:column andType:(int)flags[z]]; | 6687 [cont addColumn:column andType:(int)flags[z]]; |
6717 [column release]; | 6688 [column release]; |
6718 } | 6689 } |
7437 if(bubbletext) | 7408 if(bubbletext) |
7438 [item setToolTip:[NSString stringWithUTF8String:bubbletext]]; | 7409 [item setToolTip:[NSString stringWithUTF8String:bubbletext]]; |
7439 [item setTarget:handle]; | 7410 [item setTarget:handle]; |
7440 [item setEnabled:YES]; | 7411 [item setEnabled:YES]; |
7441 [item setHighlightMode:YES]; | 7412 [item setHighlightMode:YES]; |
7442 #ifdef MAC_OS_X_VERSION_10_12 | 7413 [item sendActionOn:(DWEventMaskLeftMouseUp|DWEventMaskLeftMouseDown|DWEventMaskRightMouseUp|DWEventMaskRightMouseDown)]; |
7443 [item sendActionOn:(NSEventMaskLeftMouseUp|NSEventMaskLeftMouseDown|NSEventMaskRightMouseUp|NSEventMaskRightMouseDown)]; | |
7444 #else | |
7445 [item sendActionOn:(NSLeftMouseUpMask|NSLeftMouseDownMask|NSRightMouseUpMask|NSRightMouseDownMask)]; | |
7446 #endif | |
7447 [item setAction:@selector(mouseDown:)]; | 7414 [item setAction:@selector(mouseDown:)]; |
7448 dw_window_set_data(handle, "_dw_taskbar", item); | 7415 dw_window_set_data(handle, "_dw_taskbar", item); |
7449 } | 7416 } |
7450 | 7417 |
7451 /* | 7418 /* |
7746 } | 7713 } |
7747 | 7714 |
7748 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */ | 7715 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */ |
7749 void _flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size) | 7716 void _flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size) |
7750 { | 7717 { |
7751 #ifdef MAC_OS_X_VERSION_10_12 | 7718 NSCompositingOperation op = DWCompositingOperationSourceOver; |
7752 NSCompositingOperation op =NSCompositingOperationSourceOver; | |
7753 #else | |
7754 NSCompositingOperation op =NSCompositeSourceOver; | |
7755 #endif | |
7756 [NSGraphicsContext saveGraphicsState]; | 7719 [NSGraphicsContext saveGraphicsState]; |
7757 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; | 7720 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; |
7758 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease]; | 7721 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease]; |
7759 /* Make a new transform */ | 7722 /* Make a new transform */ |
7760 NSAffineTransform *t = [NSAffineTransform transform]; | 7723 NSAffineTransform *t = [NSAffineTransform transform]; |
8184 * 0 on success. | 8147 * 0 on success. |
8185 */ | 8148 */ |
8186 int API dw_html_raw(HWND handle, char *string) | 8149 int API dw_html_raw(HWND handle, char *string) |
8187 { | 8150 { |
8188 DWWebView *html = handle; | 8151 DWWebView *html = handle; |
8189 #ifdef WKWebKit | 8152 #ifdef BUILDING_FOR_MOJAVE |
8190 [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; | 8153 [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; |
8191 #else | 8154 #else |
8192 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; | 8155 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; |
8193 #endif | 8156 #endif |
8194 return 0; | 8157 return 0; |
8204 * 0 on success. | 8167 * 0 on success. |
8205 */ | 8168 */ |
8206 int API dw_html_url(HWND handle, char *url) | 8169 int API dw_html_url(HWND handle, char *url) |
8207 { | 8170 { |
8208 DWWebView *html = handle; | 8171 DWWebView *html = handle; |
8209 #ifdef WKWebKit | 8172 #ifdef BUILDING_FOR_MOJAVE |
8210 [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; | 8173 [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; |
8211 #else | 8174 #else |
8212 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; | 8175 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; |
8213 #endif | 8176 #endif |
8214 return 0; | 8177 return 0; |
8345 NSEvent *event = [DWApp currentEvent]; | 8308 NSEvent *event = [DWApp currentEvent]; |
8346 if(!window) | 8309 if(!window) |
8347 window = [event window]; | 8310 window = [event window]; |
8348 [thismenu autorelease]; | 8311 [thismenu autorelease]; |
8349 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); | 8312 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); |
8350 #ifdef MAC_OS_X_VERSION_10_12 | 8313 NSEvent* fake = [NSEvent mouseEventWithType:DWEventTypeRightMouseDown |
8351 NSEvent* fake = [NSEvent mouseEventWithType:NSEventTypeRightMouseDown | |
8352 #else | |
8353 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown | |
8354 #endif | |
8355 location:_windowPointFromScreen(window, p) | 8314 location:_windowPointFromScreen(window, p) |
8356 modifierFlags:0 | 8315 modifierFlags:0 |
8357 timestamp:[event timestamp] | 8316 timestamp:[event timestamp] |
8358 windowNumber:[window windowNumber] | 8317 windowNumber:[window windowNumber] |
8359 context:[NSGraphicsContext currentContext] | 8318 context:[NSGraphicsContext currentContext] |
8840 [window setShown:YES]; | 8799 [window setShown:YES]; |
8841 } | 8800 } |
8842 [[window contentView] showWindow]; | 8801 [[window contentView] showWindow]; |
8843 [window makeKeyAndOrderFront:nil]; | 8802 [window makeKeyAndOrderFront:nil]; |
8844 | 8803 |
8845 #ifdef MAC_OS_X_VERSION_10_12 | 8804 if(!([window styleMask] & DWWindowStyleMaskResizable)) |
8846 if(!([window styleMask] & NSWindowStyleMaskResizable)) | |
8847 #else | |
8848 if(!([window styleMask] & NSResizableWindowMask)) | |
8849 #endif | |
8850 { | 8805 { |
8851 /* Fix incorrect repeat in displaying textured windows */ | 8806 /* Fix incorrect repeat in displaying textured windows */ |
8852 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge]; | 8807 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge]; |
8853 [window setContentBorderThickness:0.0 forEdge:NSMinYEdge]; | 8808 [window setContentBorderThickness:0.0 forEdge:NSMinYEdge]; |
8854 } | 8809 } |