MACOSX: fix deprecation warnings

This commit is contained in:
Max Horn 2021-08-04 09:12:26 +02:00 committed by Eugene Sandulenko
parent b2fd07f191
commit 84de72ac76
2 changed files with 26 additions and 10 deletions

View File

@ -40,6 +40,19 @@
#include <Foundation/NSURL.h>
#include <Foundation/NSAutoreleasePool.h>
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101400
#ifndef NSControlStateValueOff
#define NSControlStateValueOff NSOffState
#endif
#ifndef NSControlStateValueOn
#define NSControlStateValueOn NSOnState
#endif
#define NSButtonTypeSwitch NSSwitchButton
#endif
@interface BrowserDialogPresenter : NSObject {
@public
@ -73,7 +86,7 @@
NSButton *showHiddenFilesButton = 0;
if ([panel respondsToSelector:@selector(setShowsHiddenFiles:)]) {
showHiddenFilesButton = [[NSButton alloc] init];
[showHiddenFilesButton setButtonType:NSSwitchButton];
[showHiddenFilesButton setButtonType:NSButtonTypeSwitch];
CFStringRef hiddenFilesString = CFStringCreateWithCString(0, _("Show hidden files").encode().c_str(), kCFStringEncodingUTF8);
[showHiddenFilesButton setTitle:(NSString*)hiddenFilesString];
@ -81,10 +94,10 @@
[showHiddenFilesButton sizeToFit];
if (ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain)) {
[showHiddenFilesButton setState:NSOnState];
[showHiddenFilesButton setState:NSControlStateValueOn];
[panel setShowsHiddenFiles: YES];
} else {
[showHiddenFilesButton setState:NSOffState];
[showHiddenFilesButton setState:NSControlStateValueOff];
[panel setShowsHiddenFiles: NO];
}
[panel setAccessoryView:showHiddenFilesButton];
@ -110,7 +123,7 @@
}
- (IBAction) showHiddenFiles : (id) sender {
if ([sender state] == NSOnState) {
if ([sender state] == NSControlStateValueOn) {
[_panel setShowsHiddenFiles: YES];
ConfMan.setBool("gui_browser_show_hidden", true, Common::ConfigManager::kApplicationDomain);
} else {

View File

@ -32,6 +32,10 @@
#include <AvailabilityMacros.h>
#include <CoreFoundation/CFString.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
#define NSPasteboardTypeString NSStringPboardType
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
typedef unsigned long NSUInteger;
@ -47,16 +51,15 @@ enum {
#endif
bool hasTextInClipboardMacOSX() {
return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]] != nil;
return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSPasteboardTypeString]] != nil;
}
Common::U32String getTextFromClipboardMacOSX() {
if (!hasTextInClipboardMacOSX())
return Common::U32String();
// Note: on OS X 10.6 and above it is recommended to use NSPasteboardTypeString rather than NSStringPboardType.
// But since we still target older version use NSStringPboardType.
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSString *str = [pb stringForType:NSStringPboardType];
NSString *str = [pb stringForType:NSPasteboardTypeString];
if (str == nil)
return Common::U32String();
@ -82,7 +85,7 @@ Common::U32String getTextFromClipboardMacOSX() {
bool setTextInClipboardMacOSX(const Common::U32String &text) {
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pb declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
#ifdef SCUMM_LITTLE_ENDIAN
NSStringEncoding stringEncoding = NSUTF32LittleEndianStringEncoding;
@ -90,7 +93,7 @@ bool setTextInClipboardMacOSX(const Common::U32String &text) {
NSStringEncoding stringEncoding = NSUTF32BigEndianStringEncoding;
#endif
NSString *nsstring = [[NSString alloc] initWithBytes:text.c_str() length:4*text.size() encoding: stringEncoding];
bool status = [pb setString:nsstring forType:NSStringPboardType];
bool status = [pb setString:nsstring forType:NSPasteboardTypeString];
[nsstring release];
return status;
}