From 3e17893434d4e1bc2d9c7352ad177dd10c7c4840 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 29 Oct 2025 20:39:18 +0100 Subject: [PATCH 31/48] move utilities to base --- src/osx/carbon/utilscocoa.mm | 47 ------------------------------ src/osx/cocoa/utils_base.mm | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 429f5c910f..14e45ff3b6 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -28,19 +28,6 @@ #include "wx/fontutil.h" #include "wx/private/bmpbndl.h" -#ifdef __WXMAC__ - -wxMacAutoreleasePool::wxMacAutoreleasePool() -{ - m_pool = [[NSAutoreleasePool alloc] init]; -} - -wxMacAutoreleasePool::~wxMacAutoreleasePool() -{ - [(NSAutoreleasePool*)m_pool release]; -} - -#endif #if wxOSX_USE_COCOA @@ -72,26 +59,6 @@ CGContextRef wxOSXGetContextFromCurrentContext() #endif -// ---------------------------------------------------------------------------- -// NSObject Utils -// ---------------------------------------------------------------------------- - -void wxMacCocoaRelease( void* obj ) -{ - [(NSObject*)obj release]; -} - -void wxMacCocoaAutorelease( void* obj ) -{ - [(NSObject*)obj autorelease]; -} - -void* wxMacCocoaRetain( void* obj ) -{ - [(NSObject*)obj retain]; - return obj; -} - // ---------------------------------------------------------------------------- // NSFont Utils // ---------------------------------------------------------------------------- @@ -699,20 +666,6 @@ wxPoint wxMacCocoaGetCursorHotSpot(WX_NSCursor cursor) } #endif -//--------------------------------------------------------- -// helper functions for NSString<->wxString conversion -//--------------------------------------------------------- - -wxString wxStringWithNSString(NSString *nsstring) -{ - return wxString([nsstring UTF8String], wxConvUTF8); -} - -NSString* wxNSStringWithWxString(const wxString &wxstring) -{ - return [NSString stringWithUTF8String: wxstring.mb_str(wxConvUTF8)]; -} - // ---------------------------------------------------------------------------- // helper class for getting the correct system colors according to the // appearance in effect diff --git a/src/osx/cocoa/utils_base.mm b/src/osx/cocoa/utils_base.mm index f5b7a888a7..ec03e99c95 100644 --- a/src/osx/cocoa/utils_base.mm +++ b/src/osx/cocoa/utils_base.mm @@ -325,3 +325,58 @@ int wxCMPFUNC_CONV wxCmpNatural(const wxString& s1, const wxString& s2) // expected return values of wxCmpNatural(), so we don't need to convert. return [wxCFStringRef(s1).AsNSString() localizedStandardCompare: wxCFStringRef(s2).AsNSString()]; } + +wxMacAutoreleasePool::wxMacAutoreleasePool() +{ + m_pool = [[NSAutoreleasePool alloc] init]; +} + +wxMacAutoreleasePool::~wxMacAutoreleasePool() +{ + [(NSAutoreleasePool*)m_pool release]; +} + +// ---------------------------------------------------------------------------- +// NSObject Utils +// ---------------------------------------------------------------------------- + +void wxMacCocoaRelease( void* obj ) +{ + [(NSObject*)obj release]; +} + +void wxMacCocoaAutorelease( void* obj ) +{ + [(NSObject*)obj autorelease]; +} + +void* wxMacCocoaRetain( void* obj ) +{ + [(NSObject*)obj retain]; + return obj; +} + +//--------------------------------------------------------- +// helper functions for NSString<->wxString conversion +//--------------------------------------------------------- + +wxString wxStringWithNSString(NSString *nsstring) +{ + return wxString([nsstring UTF8String], wxConvUTF8); +} + +NSString* wxNSStringWithWxString(const wxString &wxstring) +{ + return [NSString stringWithUTF8String: wxstring.mb_str(wxConvUTF8)]; +} + +//---------------------------------------------------------------------------- +// helper when starting as a command line tool without an NSApp running at all +//---------------------------------------------------------------------------- + +bool wxMacInitCocoa() +{ + bool cocoaLoaded = NSApplicationLoad(); + wxASSERT_MSG(cocoaLoaded,wxT("Couldn't load Cocoa in Carbon Environment")) ; + return cocoaLoaded; +} -- 2.24.3 (Apple Git-128)