#if wxUSE_GUI
#include "wx/mac/uma.h"
+ #include "wx/font.h"
+#else
+ #include "wx/intl.h"
#endif
#include <ctype.h>
wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
{
TextEncodingBase enc = 0 ;
+ if ( encoding == wxFONTENCODING_DEFAULT )
+ {
+#if wxUSE_GUI
+ encoding = wxFont::GetDefaultEncoding() ;
+#else
+ encoding = wxLocale::GetSystemEncoding() ;
+#endif
+ }
switch( encoding)
{
enc = wxFONTENCODING_BULGARIAN;
break ;
*/
- casekTextEncodingDOSLatinUS :
+ case kTextEncodingDOSLatinUS :
enc = wxFONTENCODING_CP437;
break ;
case kTextEncodingDOSLatin1 :
#if (wxUSE_UNICODE == 1) && (SIZEOF_WCHAR_T == 4)
-TECObjectRef s_TECUnicode32To16 = NULL ;
-TECObjectRef s_TECUnicode16To32 = NULL ;
-
-class wxMacUnicodeConverters
-{
-public :
- wxMacUnicodeConverters() ;
- ~wxMacUnicodeConverters() ;
-} ;
-
-wxMacUnicodeConverters guard ;
+wxMBConvUTF16BE gMacUTFConverter ;
-wxMacUnicodeConverters::wxMacUnicodeConverters()
-{
- OSStatus status = noErr ;
- TextEncoding kUnicode32 = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
- TextEncoding kUnicode16 = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
-
- status = TECCreateConverter(&s_TECUnicode16To32,
- kUnicode16,
- kUnicode32);
- status = TECCreateConverter(&s_TECUnicode32To16,
- kUnicode32,
- kUnicode16);
-}
-
-wxMacUnicodeConverters::~wxMacUnicodeConverters()
-{
- OSStatus status = noErr ;
- status = TECDisposeConverter(s_TECUnicode32To16);
- status = TECDisposeConverter(s_TECUnicode16To32);
-}
#endif
// converts this string into a carbon foundation string with optional pc 2 mac encoding
-void wxMacCFStringHolder::Assign( const wxString &st )
+void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
{
+ Release() ;
wxString str = st ;
wxMacConvertNewlines13To10( &str ) ;
- size_t len = str.Len() ;
#if wxUSE_UNICODE
+ size_t len = str.Len() ;
UniChar *unibuf ;
#if SIZEOF_WCHAR_T == 2
unibuf = (UniChar*)str.wc_str() ;
#else
- OSStatus status = noErr ;
- ByteCount byteOutLen ;
- ByteCount byteInLen = len * SIZEOF_WCHAR_T ;
ByteCount byteBufferLen = len * sizeof( UniChar ) ;
unibuf = (UniChar*) malloc(byteBufferLen) ;
- status = TECConvertText( s_TECUnicode32To16 , (ConstTextPtr)str.wc_str() , byteInLen, &byteInLen,
- (TextPtr)unibuf, byteBufferLen, &byteOutLen);
+ wxMBConvUTF16BE converter ;
+ converter.WC2MB( (char*) unibuf , str.wc_str() , byteBufferLen ) ;
#endif
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
unibuf , len );
#else // not wxUSE_UNICODE
m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
- CFStringGetSystemEncoding() ) ;
+ wxMacGetSystemEncFromFontEnc( encoding ) ) ;
#endif
m_release = true ;
}
-wxString wxMacCFStringHolder::AsString()
+wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
{
wxString result ;
Size len = CFStringGetLength( m_cfs ) ;
wxChar* buf = result.GetWriteBuf( len ) ;
#if wxUSE_UNICODE
- CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) buf ) ;
+ UniChar *unibuf ;
+#if SIZEOF_WCHAR_T == 2
+ unibuf = (UniChar*) buf ;
+#else
+ unibuf = (UniChar*) malloc( len * sizeof( UniChar ) ) ;
+#endif
+ CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) unibuf ) ;
+#if SIZEOF_WCHAR_T == 2
+ // as long as UniChar is the same as wchar_t nothing to do here
+#else
+ wxMBConvUTF16BE converter ;
+ converter.MB2WC( buf , (const char*)unibuf , len * sizeof( UniChar ) ) ;
+ free( unibuf ) ;
+#endif
#else
- CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
+ CFStringGetCString( m_cfs , buf , len+1 , wxMacGetSystemEncFromFontEnc( encoding ) ) ;
#endif
buf[len] = 0 ;
wxMacConvertNewlines10To13( buf ) ;