From a75680bebe9273a0337c0558c94a1d0d50dfa322 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 3 Nov 2025 18:30:28 +0100 Subject: [PATCH 42/48] modifications according to review --- include/wx/defs.h | 21 --------------------- include/wx/osx/core/private.h | 4 ++-- src/osx/cocoa/utils_base.mm | 12 +++++------- src/osx/core/uilocale.mm | 8 ++++---- src/osx/volume.mm | 4 ++-- src/unix/appunix.cpp | 2 +- 6 files changed, 14 insertions(+), 37 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index 6a57668673..0fa3c78e63 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -2854,27 +2854,6 @@ typedef WX_UIPasteboard WXOSXPasteboard; // Define a for loop macro to iterate over Objective-C collections that works also for // compilers like gcc that does not support the "for .. in" syntax. -#if defined(__OBJC__) - -#if defined( OBJC_API_VERSION ) && OBJC_API_VERSION >= 2 - - #define wxOBJC_FOR_LOOP(var, collection) \ - for (var in collection) \ - { - -#else - - #define wxOBJC_FOR_LOOP(var, collection) \ - for (NSUInteger wx_i = 0; wx_i < [collection count]; wx_i++) \ - { var = [collection objectAtIndex:wx_i]; - -#endif - -#define wxOBJC_END_FOR_LOOP \ - } - -#endif - #endif /* __DARWIN__ */ /* ABX: check __WIN32__ instead of __WXMSW__ for the same MSWBase in any Win32 port */ diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 5fd3242daa..aa9e6aab01 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -1056,11 +1056,11 @@ protected : // cocoa bridging utilities //--------------------------------------------------------------------------- -#if !defined(__WXOSX_IPHONE__) || !__WXOSX_IPHONE__ +#if !defined(__WXOSX_IPHONE__) bool WXDLLIMPEXP_BASE wxMacInitCocoa(); -#endif // !defined(__WXOSX_IPHONE__) || !__WXOSX_IPHONE__ +#endif // !defined(__WXOSX_IPHONE__) class WXDLLIMPEXP_BASE wxMacAutoreleasePool { diff --git a/src/osx/cocoa/utils_base.mm b/src/osx/cocoa/utils_base.mm index 74e4b78818..5976b37ffd 100644 --- a/src/osx/cocoa/utils_base.mm +++ b/src/osx/cocoa/utils_base.mm @@ -36,14 +36,12 @@ #if (defined(__APPLE__) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101000) \ || (defined(__WXOSX_IPHONE__) && defined(__IPHONE_8_0)) #define wxHAS_NSPROCESSINFO 1 -#else - #define wxHAS_NSPROCESSINFO 0 #endif // our OS version is the same in non GUI and GUI cases wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro) { -#if wxHAS_NSPROCESSINFO +#ifdef wxHAS_NSPROCESSINFO NSOperatingSystemVersion osVer = [NSProcessInfo processInfo].operatingSystemVersion; if ( verMaj != nullptr ) @@ -75,7 +73,7 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro) bool wxCheckOsVersion(int majorVsn, int minorVsn, int microVsn) { -#if wxHAS_NSPROCESSINFO +#ifdef wxHAS_NSPROCESSINFO NSOperatingSystemVersion osVer; osVer.majorVersion = majorVsn; osVer.minorVersion = minorVsn; @@ -381,13 +379,13 @@ wxString wxStringWithNSString(NSString *nsstring) // helper when starting as a command line tool without an NSApp running at all //---------------------------------------------------------------------------- -#if !defined(__WXOSX_IPHONE__) || !__WXOSX_IPHONE__ +#if !defined(__WXOSX_IPHONE__) bool wxMacInitCocoa() { bool cocoaLoaded = NSApplicationLoad(); - wxASSERT_MSG(cocoaLoaded,wxT("Couldn't load Cocoa in Carbon Environment")) ; + wxASSERT_MSG(cocoaLoaded,wxT("Couldn't load Cocoa Environment as console app")) ; return cocoaLoaded; } -#endif // !defined(__WXOSX_IPHONE__) || !__WXOSX_IPHONE__ +#endif // !defined(__WXOSX_IPHONE__) diff --git a/src/osx/core/uilocale.mm b/src/osx/core/uilocale.mm index da597080b7..962693d5a1 100644 --- a/src/osx/core/uilocale.mm +++ b/src/osx/core/uilocale.mm @@ -105,8 +105,9 @@ explicit wxUILocaleImplCF(NSLocale* nsloc) bool isAvailable = false; NSArray* availableLocaleIds = [NSLocale availableLocaleIdentifiers]; - wxOBJC_FOR_LOOP( NSString* nsLocId, availableLocaleIds ) + for (NSUInteger i = 0; i < [availableLocaleIds count]; i++) \ { + NSString* nsLocId = [availableLocaleIds objectAtIndex:i]; // We can't simply compare the names here because the list returned // by NSLocale is incomplete and doesn't contain all synonyms, e.g. // it only contains "zh_Hant_TW" but not "zh_TW" itself, so we need @@ -143,7 +144,6 @@ explicit wxUILocaleImplCF(NSLocale* nsloc) if ( isAvailable ) break; } - wxOBJC_END_FOR_LOOP if ( !isAvailable ) return nullptr; @@ -517,11 +517,11 @@ int CompareStrings(const wxString& lhs, const wxString& rhs, { wxVector preferred; NSArray* preferredLangs = [NSLocale preferredLanguages]; - wxOBJC_FOR_LOOP(NSString* preferredLang, preferredLangs) + for (NSUInteger i = 0; i < [preferredLangs count]; i++) \ { + NSString* preferredLang = [preferredLangs objectAtIndex:i]; preferred.push_back(wxCFStringRef::AsString(preferredLang)); } - wxOBJC_END_FOR_LOOP return preferred; } diff --git a/src/osx/volume.mm b/src/osx/volume.mm index f0d5737246..0d3e5f8988 100644 --- a/src/osx/volume.mm +++ b/src/osx/volume.mm @@ -65,14 +65,14 @@ } else { - wxOBJC_FOR_LOOP(NSURL* url, nativeVolumes) + for (NSUInteger i = 0; i < [nativeVolumes count]; i++) \ { + NSURL* url = [nativeVolumes objectAtIndex:i]; wxFSVolumeBase volume([[url path] fileSystemRepresentation]); int flags = volume.GetFlags(); if ((flags & flagsSet) == flagsSet && !(flags & flagsUnset)) volumePaths.push_back(volume.GetName()); } - wxOBJC_END_FOR_LOOP } return volumePaths; } diff --git a/src/unix/appunix.cpp b/src/unix/appunix.cpp index 3eb8d59144..2dfb0b643a 100644 --- a/src/unix/appunix.cpp +++ b/src/unix/appunix.cpp @@ -93,7 +93,7 @@ bool wxAppConsole::Initialize(int& argc_, wxChar** argv_) #ifdef __DARWIN__ // On command line apps on macOS we need to initialize Cocoa framework wxMacAutoreleasePool autoreleasepool; -#if !defined(__WXOSX_IPHONE__) || !__WXOSX_IPHONE__ +#if !defined(__WXOSX_IPHONE__) wxMacInitCocoa(); #endif #endif // __DARWIN__ -- 2.24.3 (Apple Git-128)