Mercurial > dwindows
comparison mac/dw.m @ 1903:b94b4ad26a05
Minor fixes and changes to remove deprecation warnings in 10.10 and
still support earlier versions of Mac OS X.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 30 Sep 2014 22:13:25 +0000 |
parents | 74f50459c530 |
children | 2e456850e027 |
comparison
equal
deleted
inserted
replaced
1902:74f50459c530 | 1903:b94b4ad26a05 |
---|---|
44 /* Macros to handle local auto-release pools */ | 44 /* Macros to handle local auto-release pools */ |
45 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \ | 45 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \ |
46 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \ | 46 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \ |
47 localpool = [[NSAutoreleasePool alloc] init]; | 47 localpool = [[NSAutoreleasePool alloc] init]; |
48 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain]; | 48 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain]; |
49 | |
50 /* Handle deprecation of several response constants in 10.10... | |
51 * the replacements are not available in earlier versions. | |
52 */ | |
53 #if defined(MAC_OS_X_VERSION_10_9) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED)) | |
54 #define DWModalResponseOK NSModalResponseOK | |
55 #define DWModalResponseCancel NSModalResponseCancel | |
56 #define DWPaperOrientationPortrait NSPaperOrientationPortrait | |
57 #else | |
58 #define DWModalResponseOK NSOKButton | |
59 #define DWModalResponseCancel NSCancelButton | |
60 #define DWPaperOrientationPortrait NSPortraitOrientation | |
61 #endif | |
49 | 62 |
50 unsigned long _colors[] = | 63 unsigned long _colors[] = |
51 { | 64 { |
52 0x00000000, /* 0 black */ | 65 0x00000000, /* 0 black */ |
53 0x000000bb, /* 1 red */ | 66 0x000000bb, /* 1 red */ |
3530 [openDlg setAllowsMultipleSelection:NO]; | 3543 [openDlg setAllowsMultipleSelection:NO]; |
3531 | 3544 |
3532 /* Display the dialog. If the OK button was pressed, | 3545 /* Display the dialog. If the OK button was pressed, |
3533 * process the files. | 3546 * process the files. |
3534 */ | 3547 */ |
3535 if([openDlg runModal] == NSOKButton) | 3548 if([openDlg runModal] == DWModalResponseOK) |
3536 { | 3549 { |
3537 /* Get an array containing the full filenames of all | 3550 /* Get an array containing the full filenames of all |
3538 * files and directories selected. | 3551 * files and directories selected. |
3539 */ | 3552 */ |
3540 NSArray *files = [openDlg URLs]; | 3553 NSArray *files = [openDlg URLs]; |
7907 DW_LOCAL_POOL_IN; | 7920 DW_LOCAL_POOL_IN; |
7908 | 7921 |
7909 snprintf(buffer, 100, "%04d-%02d-%02d", year, month, day); | 7922 snprintf(buffer, 100, "%04d-%02d-%02d", year, month, day); |
7910 | 7923 |
7911 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; | 7924 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; |
7912 dateFormatter.dateFormat = @"yy-mm-dd"; | 7925 dateFormatter.dateFormat = @"yyyy-mm-dd"; |
7913 | 7926 |
7914 date = [dateFormatter dateFromString:[NSString stringWithUTF8String:buffer]]; | 7927 date = [dateFormatter dateFromString:[NSString stringWithUTF8String:buffer]]; |
7915 [calendar setDateValue:date]; | 7928 [calendar setDateValue:date]; |
7916 [date release]; | 7929 [date release]; |
7917 DW_LOCAL_POOL_OUT; | 7930 DW_LOCAL_POOL_OUT; |
8093 DW_LOCAL_POOL_IN; | 8106 DW_LOCAL_POOL_IN; |
8094 [thismenu release]; | 8107 [thismenu release]; |
8095 DW_LOCAL_POOL_OUT; | 8108 DW_LOCAL_POOL_OUT; |
8096 } | 8109 } |
8097 | 8110 |
8111 /* Handle deprecation of convertScreenToBase in 10.10 yet still supporting | |
8112 * 10.6 and earlier since convertRectFromScreen was introduced in 10.7. | |
8113 */ | |
8114 NSPoint _windowPointFromScreen(NSWindow *window, NSPoint p) | |
8115 { | |
8116 SEL crfs = NSSelectorFromString(@"convertRectFromScreen"); | |
8117 | |
8118 if([window respondsToSelector:crfs]) | |
8119 { | |
8120 NSRect (* icrfs)(id, SEL, NSRect) = (NSRect (*)(id, SEL, NSRect))[window methodForSelector:crfs]; | |
8121 NSRect rect = icrfs(window, crfs, NSMakeRect(p.x, p.y, 1, 1)); | |
8122 return rect.origin; | |
8123 } | |
8124 else | |
8125 { | |
8126 SEL cstb = NSSelectorFromString(@"convertScreenToBase"); | |
8127 | |
8128 if([window respondsToSelector:cstb]) | |
8129 { | |
8130 NSPoint (* icstb)(id, SEL, NSPoint) = (NSPoint (*)(id, SEL, NSPoint))[window methodForSelector:cstb]; | |
8131 return icstb(window, cstb, p); | |
8132 } | |
8133 } | |
8134 return NSMakePoint(0,0); | |
8135 } | |
8136 | |
8098 /* | 8137 /* |
8099 * Pops up a context menu at given x and y coordinates. | 8138 * Pops up a context menu at given x and y coordinates. |
8100 * Parameters: | 8139 * Parameters: |
8101 * menu: The handle the the existing menu. | 8140 * menu: The handle the the existing menu. |
8102 * parent: Handle to the window initiating the popup. | 8141 * parent: Handle to the window initiating the popup. |
8113 if(!window) | 8152 if(!window) |
8114 window = [event window]; | 8153 window = [event window]; |
8115 [thismenu autorelease]; | 8154 [thismenu autorelease]; |
8116 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); | 8155 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); |
8117 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown | 8156 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown |
8118 location:[window convertScreenToBase:p] | 8157 location:_windowPointFromScreen(window, p) |
8119 modifierFlags:0 | 8158 modifierFlags:0 |
8120 timestamp:[event timestamp] | 8159 timestamp:[event timestamp] |
8121 windowNumber:[window windowNumber] | 8160 windowNumber:[window windowNumber] |
8122 context:[NSGraphicsContext currentContext] | 8161 context:[NSGraphicsContext currentContext] |
8123 eventNumber:1 | 8162 eventNumber:1 |
11333 pi = [NSPrintInfo sharedPrintInfo]; | 11372 pi = [NSPrintInfo sharedPrintInfo]; |
11334 [pi setHorizontalPagination:NSFitPagination]; | 11373 [pi setHorizontalPagination:NSFitPagination]; |
11335 [pi setHorizontallyCentered:YES]; | 11374 [pi setHorizontallyCentered:YES]; |
11336 [pi setVerticalPagination:NSFitPagination]; | 11375 [pi setVerticalPagination:NSFitPagination]; |
11337 [pi setVerticallyCentered:YES]; | 11376 [pi setVerticallyCentered:YES]; |
11338 [pi setOrientation:NSPaperOrientationPortrait]; | 11377 [pi setOrientation:DWPaperOrientationPortrait]; |
11339 [pi setLeftMargin:0.0]; | 11378 [pi setLeftMargin:0.0]; |
11340 [pi setRightMargin:0.0]; | 11379 [pi setRightMargin:0.0]; |
11341 [pi setTopMargin:0.0]; | 11380 [pi setTopMargin:0.0]; |
11342 [pi setBottomMargin:0.0]; | 11381 [pi setBottomMargin:0.0]; |
11343 | 11382 |
11348 PMPrintSettingsSetJobName(settings, (CFStringRef)[NSString stringWithUTF8String:jobname]); | 11387 PMPrintSettingsSetJobName(settings, (CFStringRef)[NSString stringWithUTF8String:jobname]); |
11349 [pi updateFromPMPrintSettings]; | 11388 [pi updateFromPMPrintSettings]; |
11350 | 11389 |
11351 /* Create and show the print panel */ | 11390 /* Create and show the print panel */ |
11352 panel = [NSPrintPanel printPanel]; | 11391 panel = [NSPrintPanel printPanel]; |
11353 if(!panel || [panel runModalWithPrintInfo:pi] == NSCancelButton) | 11392 if(!panel || [panel runModalWithPrintInfo:pi] == DWModalResponseCancel) |
11354 { | 11393 { |
11355 free(print); | 11394 free(print); |
11356 return NULL; | 11395 return NULL; |
11357 } | 11396 } |
11358 /* Put the print info from the panel into the operation */ | 11397 /* Put the print info from the panel into the operation */ |