X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/536732e4822cc89c41a3b753c2a7f83abf98793d..b77b87881bae2e6306366d79e7fe160334b3d4a2:/src/mac/carbon/utils.cpp diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index 345bbe9a4e..0a0735d4a7 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -18,7 +18,10 @@ #include "wx/utils.h" #include "wx/app.h" #include "wx/apptrait.h" -#include "wx/mac/uma.h" + +#if wxUSE_GUI + #include "wx/mac/uma.h" +#endif #include @@ -43,14 +46,38 @@ #include "TextCommon.h" #include "TextEncodingConverter.h" -#if defined(__WXMAC__) - #include "wx/mac/private.h" // includes mac headers -#endif +#include "wx/mac/private.h" // includes mac headers #if defined(__MWERKS__) && wxUSE_UNICODE #include #endif +// --------------------------------------------------------------------------- +// code used in both base and GUI compilation +// --------------------------------------------------------------------------- + +// our OS version is the same in non GUI and GUI cases +static int DoGetOSVersion(int *majorVsn, int *minorVsn) +{ + long theSystem ; + + // are there x-platform conventions ? + + Gestalt(gestaltSystemVersion, &theSystem) ; + if (minorVsn != NULL) { + *minorVsn = (theSystem & 0xFF ) ; + } + if (majorVsn != NULL) { + *majorVsn = (theSystem >> 8 ) ; + } +#ifdef __DARWIN__ + return wxMAC_DARWIN; +#else + return wxMAC; +#endif +} + +#if wxUSE_BASE #ifndef __DARWIN__ // defined in unix/utilsunx.cpp for Mac OS X @@ -193,31 +220,31 @@ void wxBell() SysBeep(30); } -#if defined(__WXMAC__) && !defined(__DARWIN__) -int wxAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) -#else -int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) -#endif +wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() { - long theSystem ; + static wxToolkitInfo info; + info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); + info.name = _T("wxBase"); + return info; +} - // are there x-platform conventions ? +#endif // wxUSE_BASE - Gestalt(gestaltSystemVersion, &theSystem) ; - if (minorVsn != NULL) { - *minorVsn = (theSystem & 0xFF ) ; - } - if (majorVsn != NULL) { - *majorVsn = (theSystem >> 8 ) ; - } -#ifdef __DARWIN__ - return wxMAC_DARWIN; -#else - return wxMAC; +#if wxUSE_GUI + +wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +{ + static wxToolkitInfo info; + info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); + info.shortName = _T("mac"); + info.name = _T("wxMac"); +#ifdef __WXUNIVERSAL__ + info.shortName << _T("univ"); + info.name << _T("/wxUniversal"); #endif + return info; } - // Reading and writing resources (eg WIN.INI, .Xdefaults) #if wxUSE_RESOURCES bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) @@ -330,6 +357,10 @@ bool wxIsBusy() return (gs_wxBusyCursorCount > 0); } +#endif // wxUSE_GUI + +#if wxUSE_BASE + wxString wxMacFindFolder( short vol, OSType folderType, Boolean createFolder) @@ -349,47 +380,9 @@ wxString wxMacFindFolder( short vol, return strDir ; } -#ifndef __DARWIN__ -wxChar *wxGetUserHome (const wxString& user) -{ - // TODO - return NULL; -} - -bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) -{ - if ( path.empty() ) - return FALSE; - - wxString p = path ; - if (p[0] == ':' ) { - p = wxGetCwd() + p ; - } +#endif // wxUSE_BASE - int pos = p.Find(':') ; - if ( pos != wxNOT_FOUND ) { - p = p.Mid(1,pos) ; - } - - p = p + wxT(":") ; - - Str255 volumeName ; - XVolumeParam pb ; - - wxMacStringToPascal( p , volumeName ) ; - OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ; - if ( err == noErr ) { - if ( pTotal ) { - (*pTotal) = wxLongLong( pb.ioVTotalBytes ) ; - } - if ( pFree ) { - (*pFree) = wxLongLong( pb.ioVFreeBytes ) ; - } - } - - return err == noErr ; -} -#endif +#if wxUSE_GUI // Check whether this window wants to process messages, e.g. Stop button // in long calculations. @@ -491,20 +484,68 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt) return wxGenericFindWindowAtPoint(pt); } +#endif // wxUSE_GUI + +#if wxUSE_BASE + wxString wxGetOsDescription() { #ifdef WXWIN_OS_DESCRIPTION // use configure generated description if available - return wxString("MacOS (") + WXWIN_OS_DESCRIPTION + wxString(")"); + return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); #else return wxT("MacOS") ; //TODO:define further #endif } +#ifndef __DARWIN__ +wxChar *wxGetUserHome (const wxString& user) +{ + // TODO + return NULL; +} + +bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) +{ + if ( path.empty() ) + return FALSE; + + wxString p = path ; + if (p[0] == ':' ) { + p = wxGetCwd() + p ; + } + + int pos = p.Find(':') ; + if ( pos != wxNOT_FOUND ) { + p = p.Mid(1,pos) ; + } + + p = p + wxT(":") ; + + Str255 volumeName ; + XVolumeParam pb ; + + wxMacStringToPascal( p , volumeName ) ; + OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ; + if ( err == noErr ) { + if ( pTotal ) { + (*pTotal) = wxLongLong( pb.ioVTotalBytes ) ; + } + if ( pFree ) { + (*pFree) = wxLongLong( pb.ioVFreeBytes ) ; + } + } + + return err == noErr ; +} +#endif // !__DARWIN__ + //--------------------------------------------------------------------------- // wxMac Specific utility functions //--------------------------------------------------------------------------- +#if 0 + char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf" @@ -591,17 +632,17 @@ void wxMacConvertToPC( const char *from , char *to , int len ) TECObjectRef s_TECNativeCToUnicode = NULL ; TECObjectRef s_TECUnicodeToNativeC = NULL ; -TECObjectRef s_TECPlatformToNativeC = NULL ; -TECObjectRef s_TECNativeCToPlatform = NULL ; + void wxMacSetupConverters() { // if we assume errors are happening here we need low level debugging // since the high level assert will use the encoders that are not yet // setup... - const int kEncoding = wxApp::s_macDefaultEncodingIsPC - ? (int)kTextEncodingWindowsLatin1 - : (int)kTextEncodingMacRoman; - +#if TARGET_CARBON + const TextEncodingBase kEncoding = CFStringGetSystemEncoding(); +#else + const TextEncodingBase kEncoding = kTextEncodingMacRoman; +#endif OSStatus status = noErr ; status = TECCreateConverter(&s_TECNativeCToUnicode, kEncoding, @@ -611,18 +652,6 @@ void wxMacSetupConverters() status = TECCreateConverter(&s_TECUnicodeToNativeC, kTextEncodingUnicodeDefault, kEncoding); - - if ( wxApp::s_macDefaultEncodingIsPC ) - { - status = TECCreateConverter(&s_TECPlatformToNativeC, - kTextEncodingMacRoman, - kTextEncodingWindowsLatin1); - - - status = TECCreateConverter(&s_TECNativeCToPlatform, - kTextEncodingWindowsLatin1, - kTextEncodingMacRoman); - } } void wxMacCleanupConverters() @@ -631,10 +660,6 @@ void wxMacCleanupConverters() status = TECDisposeConverter(s_TECNativeCToUnicode); status = TECDisposeConverter(s_TECUnicodeToNativeC); - - status = TECDisposeConverter(s_TECPlatformToNativeC); - - status = TECDisposeConverter(s_TECNativeCToPlatform); } wxWCharBuffer wxMacStringToWString( const wxString &from ) @@ -654,6 +679,7 @@ wxWCharBuffer wxMacStringToWString( const wxString &from ) return result ; } + wxString wxMacMakeStringFromCString( const char * from , int len ) { OSStatus status = noErr ; @@ -667,17 +693,7 @@ wxString wxMacMakeStringFromCString( const char * from , int len ) status = TECConvertText(s_TECNativeCToUnicode, (ConstTextPtr)from , byteInLen, &byteInLen, (TextPtr)buf, byteBufferLen, &byteOutLen); #else - if ( !wxApp::s_macDefaultEncodingIsPC ) - memcpy( buf , from , len ) ; - else - { - ByteCount byteOutLen ; - ByteCount byteInLen = len ; - ByteCount byteBufferLen = byteInLen ; - - status = TECConvertText(s_TECPlatformToNativeC, (ConstTextPtr)from , byteInLen, &byteInLen, - (TextPtr)buf, byteBufferLen, &byteOutLen); - } + memcpy( buf , from , len ) ; #endif buf[len] = 0 ; result.UngetWriteBuf() ; @@ -701,26 +717,14 @@ wxCharBuffer wxMacStringToCString( const wxString &from ) (TextPtr)result.data(), byteBufferLen, &byteOutLen); return result ; #else - if ( !wxApp::s_macDefaultEncodingIsPC ) - return wxCharBuffer( from.c_str() ) ; - else - { - wxCharBuffer result( from.Length() ) ; - OSStatus status = noErr ; - ByteCount byteOutLen ; - ByteCount byteInLen = from.Length() ; - ByteCount byteBufferLen = byteInLen ; - - status = TECConvertText(s_TECNativeCToPlatform, (ConstTextPtr)from.c_str() , byteInLen, &byteInLen, - (TextPtr)result.data(), byteBufferLen, &byteOutLen); - return result ; - } + return wxCharBuffer( from.c_str() ) ; #endif } +#endif void wxMacStringToPascal( const wxString&from , StringPtr to ) { - wxCharBuffer buf = wxMacStringToCString( from ) ; + wxCharBuffer buf = from.mb_str( wxConvLocal ) ; int len = strlen(buf) ; if ( len > 255 ) @@ -731,24 +735,30 @@ void wxMacStringToPascal( const wxString&from , StringPtr to ) wxString wxMacMakeStringFromPascal( ConstStringPtr from ) { - return wxMacMakeStringFromCString( (char*) &from[1] , from[0] ) ; + return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ; } +#endif // wxUSE_BASE + +#if wxUSE_GUI + + // // CFStringRefs (Carbon only) // #if TARGET_CARBON // converts this string into a carbon foundation string with optional pc 2 mac encoding -void wxMacCFStringHolder::Assign( const wxString &str ) +void wxMacCFStringHolder::Assign( const wxString &st ) { + wxString str = st ; + wxMacConvertNewlines13To10( &str ) ; #if wxUSE_UNICODE m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault, (const unsigned short*)str.wc_str(), str.Len() ); #else m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , - wxApp::s_macDefaultEncodingIsPC ? - kCFStringEncodingWindowsLatin1 : CFStringGetSystemEncoding() ) ; + CFStringGetSystemEncoding() ) ; #endif m_release = true ; } @@ -761,91 +771,86 @@ wxString wxMacCFStringHolder::AsString() #if wxUSE_UNICODE CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) buf ) ; #else - CFStringGetCString( m_cfs , buf , len+1 , wxApp::s_macDefaultEncodingIsPC ? - kCFStringEncodingWindowsLatin1 : CFStringGetSystemEncoding() ) ; + CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ; #endif buf[len] = 0 ; + wxMacConvertNewlines10To13( buf ) ; result.UngetWriteBuf() ; return result ; } -#if 0 +#endif //TARGET_CARBON -wxString wxMacMakeMacStringFromPC( const wxChar * p ) -{ - wxString result ; - int len = wxStrlen ( p ) ; - if ( len > 0 ) +void wxMacConvertNewlines13To10( char * data ) +{ + char * buf = data ; + while( (buf=strchr(buf,0x0d)) != NULL ) { - wxChar* ptr = result.GetWriteBuf(len) ; - wxMacConvertFromPC( p , ptr , len ) ; - ptr[len] = 0 ; - result.UngetWriteBuf( len ) ; + *buf = 0x0a ; + buf++ ; } - return result ; } -wxString wxMacMakePCStringFromMac( const wxChar * p ) -{ - wxString result ; - int len = wxStrlen ( p ) ; - if ( len > 0 ) +void wxMacConvertNewlines10To13( char * data ) +{ + char * buf = data ; + while( (buf=strchr(buf,0x0a)) != NULL ) { - wxChar* ptr = result.GetWriteBuf(len) ; - wxMacConvertToPC( p , ptr , len ) ; - ptr[len] = 0 ; - result.UngetWriteBuf( len ) ; + *buf = 0x0d ; + buf++ ; } - return result ; } -wxString wxMacMakeStringFromMacString( const wxChar* from , bool mac2pcEncoding ) -{ - if (mac2pcEncoding) - { - return wxMacMakePCStringFromMac( from ) ; - } - else - { - return wxString( from ) ; - } +void wxMacConvertNewlines13To10( wxString * data ) +{ + size_t len = data->Length() ; + + if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL) + return ; + + wxString temp(*data) ; + wxStringBuffer buf(*data,len ) ; + memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ; + + wxMacConvertNewlines13To10( buf ) ; } -// -// Pascal Strings -// +void wxMacConvertNewlines10To13( wxString * data ) +{ + size_t len = data->Length() ; -wxString wxMacMakeStringFromPascal( ConstStringPtr from , bool mac2pcEncoding ) -{ - // this is safe since a pascal string can never be larger than 256 bytes - char s[256] ; - CopyPascalStringToC( from , s ) ; - if (mac2pcEncoding) - { - return wxMacMakePCStringFromMac( s ) ; - } - else - { - return wxString( s ) ; - } + if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL) + return ; + + wxString temp(*data) ; + wxStringBuffer buf(*data,len ) ; + memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ; + wxMacConvertNewlines10To13( buf ) ; } -void wxMacStringToPascal( const wxChar * from , StringPtr to , bool pc2macEncoding ) -{ - if (pc2macEncoding) + +#if wxUSE_UNICODE +void wxMacConvertNewlines13To10( wxChar * data ) +{ + wxChar * buf = data ; + while( (buf=wxStrchr(buf,0x0d)) != NULL ) { - CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ; + *buf = 0x0a ; + buf++ ; } - else +} + +void wxMacConvertNewlines10To13( wxChar * data ) +{ + wxChar * buf = data ; + while( (buf=wxStrchr(buf,0x0a)) != NULL ) { - CopyCStringToPascal( from , to ) ; + *buf = 0x0d ; + buf++ ; } } #endif - -#endif //TARGET_CARBON - // ---------------------------------------------------------------------------- // debugging support // ---------------------------------------------------------------------------- @@ -986,3 +991,5 @@ extern bool WXDLLEXPORT wxIsDebuggerRunning() #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) +#endif // wxUSE_GUI +