Assume sizeof(wchar_t) is always 4 under OS X.

wchar_t used to be 2 bytes in Mach-O builds but they're not supported any
longer so remove the code checking for sizeof(wchar_t) and just assume it's
always 4.

Closes #10442.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66028 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-11-05 21:38:25 +00:00
parent f40377bedc
commit b7db378853
4 changed files with 5 additions and 39 deletions

View File

@@ -323,17 +323,13 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event
GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
charBuf[ numChars - 1 ] = 0; charBuf[ numChars - 1 ] = 0;
#if SIZEOF_WCHAR_T == 2
uniChar = charBuf[0] ;
#else
wxMBConvUTF16 converter ; wxMBConvUTF16 converter ;
converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ; converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ;
#endif
if ( numChars * 2 > 4 ) if ( numChars * 2 > 4 )
delete[] charBuf ; delete[] charBuf ;
} }
#endif #endif // wxUSE_UNICODE
GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode ); GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode );
GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );

View File

@@ -739,10 +739,6 @@ wxString wxMacMLTEControl::GetStringValue() const
{ {
wxChar *ptr = NULL ; wxChar *ptr = NULL ;
#if SIZEOF_WCHAR_T == 2
ptr = new wxChar[actualSize + 1] ;
wxStrncpy( ptr , (wxChar*)(*theText) , actualSize ) ;
#else
SetHandleSize( theText, (actualSize + 1) * sizeof(UniChar) ) ; SetHandleSize( theText, (actualSize + 1) * sizeof(UniChar) ) ;
HLock( theText ) ; HLock( theText ) ;
(((UniChar*)*theText)[actualSize]) = 0 ; (((UniChar*)*theText)[actualSize]) = 0 ;
@@ -755,7 +751,6 @@ wxString wxMacMLTEControl::GetStringValue() const
wxASSERT_MSG( noChars != wxCONV_FAILED, wxT("Conversion of string failed!") ); wxASSERT_MSG( noChars != wxCONV_FAILED, wxT("Conversion of string failed!") );
ptr[noChars] = 0 ; ptr[noChars] = 0 ;
HUnlock( theText ) ; HUnlock( theText ) ;
#endif
ptr[actualSize] = 0 ; ptr[actualSize] = 0 ;
result = wxString( ptr ) ; result = wxString( ptr ) ;
@@ -764,7 +759,7 @@ wxString wxMacMLTEControl::GetStringValue() const
DisposeHandle( theText ) ; DisposeHandle( theText ) ;
} }
#else #else // !wxUSE_UNICODE
Handle theText ; Handle theText ;
err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData );
@@ -785,7 +780,7 @@ wxString wxMacMLTEControl::GetStringValue() const
DisposeHandle( theText ) ; DisposeHandle( theText ) ;
} }
#endif #endif // wxUSE_UNICODE/!wxUSE_UNICODE
} }
#if '\n' == 10 #if '\n' == 10
@@ -1381,10 +1376,6 @@ void wxMacMLTEControl::ShowPosition( long pos )
void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffset end ) void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffset end )
{ {
#if wxUSE_UNICODE #if wxUSE_UNICODE
#if SIZEOF_WCHAR_T == 2
size_t len = st.length() ;
TXNSetData( m_txn, kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end );
#else
wxMBConvUTF16 converter ; wxMBConvUTF16 converter ;
ByteCount byteBufferLen = converter.WC2MB( NULL, st.wc_str(), 0 ) ; ByteCount byteBufferLen = converter.WC2MB( NULL, st.wc_str(), 0 ) ;
wxASSERT_MSG( byteBufferLen != wxCONV_FAILED, wxASSERT_MSG( byteBufferLen != wxCONV_FAILED,
@@ -1393,11 +1384,10 @@ void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffse
converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen + 2 ) ; converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen + 2 ) ;
TXNSetData( m_txn, kTXNUnicodeTextData, (void*)unibuf, byteBufferLen, start, end ) ; TXNSetData( m_txn, kTXNUnicodeTextData, (void*)unibuf, byteBufferLen, start, end ) ;
free( unibuf ) ; free( unibuf ) ;
#endif #else // !wxUSE_UNICODE
#else
wxCharBuffer text = st.mb_str( wxConvLocal ) ; wxCharBuffer text = st.mb_str( wxConvLocal ) ;
TXNSetData( m_txn, kTXNTextData, (void*)text.data(), strlen( text ), start, end ) ; TXNSetData( m_txn, kTXNTextData, (void*)text.data(), strlen( text ), start, end ) ;
#endif #endif // wxUSE_UNICODE/!wxUSE_UNICODE
} }
wxString wxMacMLTEControl::GetLineText(long lineNo) const wxString wxMacMLTEControl::GetLineText(long lineNo) const

View File

@@ -610,14 +610,9 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even
uniChars = new wchar_t[ numChars ] ; uniChars = new wchar_t[ numChars ] ;
GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
charBuf[ numChars - 1 ] = 0; charBuf[ numChars - 1 ] = 0;
#if SIZEOF_WCHAR_T == 2
uniChars = (wchar_t*) charBuf ;
/* memcpy( uniChars , charBuf , numChars * 2 ) ;*/ // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...)
#else
// the resulting string will never have more chars than the utf16 version, so this is safe // the resulting string will never have more chars than the utf16 version, so this is safe
wxMBConvUTF16 converter ; wxMBConvUTF16 converter ;
numChars = converter.MB2WC( uniChars , (const char*)charBuf , numChars ) ; numChars = converter.MB2WC( uniChars , (const char*)charBuf , numChars ) ;
#endif
} }
switch ( GetEventKind( event ) ) switch ( GetEventKind( event ) )

View File

@@ -696,10 +696,6 @@ wxString wxCFStringRef::AsString( NSString* ref, wxFontEncoding encoding )
wxMacUniCharBuffer::wxMacUniCharBuffer( const wxString &str ) wxMacUniCharBuffer::wxMacUniCharBuffer( const wxString &str )
{ {
m_chars = str.length() ;
m_ubuf = NULL ;
#if SIZEOF_WCHAR_T == 4
wxMBConvUTF16 converter ; wxMBConvUTF16 converter ;
#if wxUSE_UNICODE #if wxUSE_UNICODE
size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
@@ -712,17 +708,6 @@ wxMacUniCharBuffer::wxMacUniCharBuffer( const wxString &str )
converter.WC2MB( (char*) m_ubuf , wchar.data() , unicharlen + 2 ) ; converter.WC2MB( (char*) m_ubuf , wchar.data() , unicharlen + 2 ) ;
#endif #endif
m_chars = unicharlen / 2 ; m_chars = unicharlen / 2 ;
#else // SIZEOF_WCHAR_T is then 2
#if wxUSE_UNICODE
m_ubuf = malloc( m_chars * 2 + 2 ) ;
memcpy( m_ubuf , (UniChar*) str.wc_str() , m_chars * 2 + 2 ) ;
#else
wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
m_chars = wxWcslen( wchar.data() ) ;
m_ubuf = malloc( m_chars * 2 + 2 ) ;
memcpy( m_ubuf , (UniChar*) wchar.data() , m_chars * 2 + 2 ) ;
#endif
#endif
} }
wxMacUniCharBuffer::~wxMacUniCharBuffer() wxMacUniCharBuffer::~wxMacUniCharBuffer()