comparison mac/dw.m @ 2838:30b554c34198

Mac: Add initial support for MacOS 13 Ventura. Add two preliminary macros for disabling deprecation warnings on the fallback code. _DW_ELSE_AVAILABLE and _DW_END_AVAILABLE.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 15 Sep 2022 09:07:09 +0000
parents b1ff739d0dbc
children 0f92f7641d04
comparison
equal deleted inserted replaced
2837:444031116159 2838:30b554c34198
174 #define DWPrintingPaginationModeFit NSFitPagination 174 #define DWPrintingPaginationModeFit NSFitPagination
175 #define DWDatePickerModeSingle NSSingleDateMode 175 #define DWDatePickerModeSingle NSSingleDateMode
176 #define DWDatePickerStyleClockAndCalendar NSClockAndCalendarDatePickerStyle 176 #define DWDatePickerStyleClockAndCalendar NSClockAndCalendarDatePickerStyle
177 #define DWDatePickerElementFlagYearMonthDay NSYearMonthDayDatePickerElementFlag 177 #define DWDatePickerElementFlagYearMonthDay NSYearMonthDayDatePickerElementFlag
178 #endif 178 #endif
179
180 /* Handle deprecation of constants in 12.0 */
181 #if defined(MAC_OS_VERSION_12_0) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_12_0) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED))
182 #import <UniformTypeIdentifiers/UTDefines.h>
183 #import <UniformTypeIdentifiers/UTType.h>
184 #import <UniformTypeIdentifiers/UTCoreTypes.h>
185 #define BUILDING_FOR_MONTEREY
186 #endif
187
188 /* Handle deprecation of constants in 13.0 */
189 #if defined(MAC_OS_VERSION_13_0) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_13_0) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED))
190 #define BUILDING_FOR_VENTURA
191 #endif
192
193 #define _DW_ELSE_AVAILABLE \
194 _Pragma("clang diagnostic push") \
195 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
196
197 #define _DW_END_AVAILABLE _Pragma("clang diagnostic pop")
179 198
180 /* Macros to encapsulate running functions on the main thread 199 /* Macros to encapsulate running functions on the main thread
181 * on Mojave or later... and locking mutexes on earlier versions. 200 * on Mojave or later... and locking mutexes on earlier versions.
182 */ 201 */
183 #ifdef BUILDING_FOR_MOJAVE 202 #ifdef BUILDING_FOR_MOJAVE
4482 /* Enable the selection of files in the dialog. */ 4501 /* Enable the selection of files in the dialog. */
4483 if(flags == DW_FILE_OPEN) 4502 if(flags == DW_FILE_OPEN)
4484 { 4503 {
4485 [openDlg setCanChooseFiles:YES]; 4504 [openDlg setCanChooseFiles:YES];
4486 [openDlg setCanChooseDirectories:NO]; 4505 [openDlg setCanChooseDirectories:NO];
4506
4507 /* Handle file types */
4508 if(ext && *ext)
4509 {
4510 #ifdef BUILDING_FOR_BIG_SUR
4511 if (@available(macOS 11.0, *)) {
4512 UTType *extuti = ext ? [UTType typeWithFilenameExtension:[NSString stringWithUTF8String:ext]] : nil;
4513 NSArray *UTIs;
4514
4515 /* Try to generate a UTI for our passed extension */
4516 if(extuti)
4517 UTIs = [NSArray arrayWithObjects:extuti, UTTypeText, nil];
4518 else
4519 UTIs = @[UTTypeText];
4520 [openDlg setAllowedContentTypes:UTIs];
4521 } else
4522 #endif
4523 {
4524 _DW_ELSE_AVAILABLE
4525 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease];
4526 [openDlg setAllowedFileTypes:fileTypes];
4527 _DW_END_AVAILABLE
4528 }
4529 }
4487 } 4530 }
4488 else 4531 else
4489 { 4532 {
4490 [openDlg setCanChooseFiles:NO]; 4533 [openDlg setCanChooseFiles:NO];
4491 [openDlg setCanChooseDirectories:YES]; 4534 [openDlg setCanChooseDirectories:YES];
4492 } 4535 #ifdef BUILDING_FOR_BIG_SUR
4493 4536 if (@available(macOS 11.0, *)) {
4494 /* Handle file types */ 4537 [openDlg setAllowedContentTypes:@[UTTypeFolder]];
4495 if(ext && *ext) 4538 }
4496 { 4539 #endif
4497 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease];
4498 [openDlg setAllowedFileTypes:fileTypes];
4499 } 4540 }
4500 4541
4501 /* Disable multiple selection */ 4542 /* Disable multiple selection */
4502 [openDlg setAllowsMultipleSelection:NO]; 4543 [openDlg setAllowsMultipleSelection:NO];
4503 4544
4549 [saveDlg setCanCreateDirectories:YES]; 4590 [saveDlg setCanCreateDirectories:YES];
4550 4591
4551 /* Handle file types */ 4592 /* Handle file types */
4552 if(ext && *ext) 4593 if(ext && *ext)
4553 { 4594 {
4554 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease]; 4595 #ifdef BUILDING_FOR_BIG_SUR
4555 [saveDlg setAllowedFileTypes:fileTypes]; 4596 if (@available(macOS 11.0, *)) {
4597 UTType *extuti = ext ? [UTType typeWithFilenameExtension:[NSString stringWithUTF8String:ext]] : nil;
4598 NSArray *UTIs;
4599
4600 /* Try to generate a UTI for our passed extension */
4601 if(extuti)
4602 UTIs = [NSArray arrayWithObjects:extuti, UTTypeText, nil];
4603 else
4604 UTIs = @[UTTypeText];
4605 [saveDlg setAllowedContentTypes:UTIs];
4606 } else
4607 #endif
4608 {
4609 _DW_ELSE_AVAILABLE
4610 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease];
4611 [saveDlg setAllowedFileTypes:fileTypes];
4612 _DW_END_AVAILABLE
4613 }
4556 } 4614 }
4557 4615
4558 /* Display the dialog. If the OK button was pressed, 4616 /* Display the dialog. If the OK button was pressed,
4559 * process the files. 4617 * process the files.
4560 */ 4618 */
13295 if([basicAppearance isEqualToString:NSAppearanceNameDarkAqua]) 13353 if([basicAppearance isEqualToString:NSAppearanceNameDarkAqua])
13296 return DW_DARK_MODE_FORCED; 13354 return DW_DARK_MODE_FORCED;
13297 if([basicAppearance isEqualToString:NSAppearanceNameAqua]) 13355 if([basicAppearance isEqualToString:NSAppearanceNameAqua])
13298 return DW_FEATURE_DISABLED; 13356 return DW_FEATURE_DISABLED;
13299 } 13357 }
13300 appearance = [NSAppearance currentAppearance]; 13358 #ifdef BUILDING_FOR_BIG_SUR
13359 /* Configure the notification's payload. */
13360 if (@available(macOS 11.0, *)) {
13361 appearance = [NSAppearance currentDrawingAppearance];
13362 } else
13363 #endif
13364 {
13365 _DW_ELSE_AVAILABLE
13366 appearance = [NSAppearance currentAppearance];
13367 _DW_END_AVAILABLE
13368 }
13301 basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, 13369 basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua,
13302 NSAppearanceNameDarkAqua]]; 13370 NSAppearanceNameDarkAqua]];
13303 if([basicAppearance isEqualToString:NSAppearanceNameDarkAqua]) 13371 if([basicAppearance isEqualToString:NSAppearanceNameDarkAqua])
13304 return DW_DARK_MODE_FULL; 13372 return DW_DARK_MODE_FULL;
13305 return DW_DARK_MODE_BASIC; 13373 return DW_DARK_MODE_BASIC;