From f309770945e38584971cc551119d441b14492f4e Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 19 Apr 2006 14:37:08 +0000 Subject: [PATCH] mb2wc fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38843 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/textctrl.cpp | 4 +++- src/mac/carbon/toplevel.cpp | 19 ++++++++++++------- src/mac/corefoundation/cfstring.cpp | 4 +++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 95729897ce..36a9d22ced 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -1574,9 +1574,11 @@ wxString wxMacMLTEControl::GetStringValue() const (((UniChar*)*theText)[actualSize]) = 0 ; wxMBConvUTF16 converter ; size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; + wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); ptr = new wxChar[noChars + 1] ; - noChars = converter.MB2WC( ptr , (const char*)*theText , noChars ) ; + noChars = converter.MB2WC( ptr , (const char*)*theText , noChars + 1 ) ; + wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); ptr[noChars] = 0 ; HUnlock( theText ) ; #endif diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index c7c49f7f2b..d0519c95c6 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -122,7 +122,10 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event focus = (wxTopLevelWindowMac*) data ; unsigned char charCode ; - wxChar uniChar = 0 ; + wxChar uniChar[2] ; + uniChar[0] = 0; + uniChar[1] = 0; + UInt32 keyCode ; UInt32 modifiers ; Point point ; @@ -133,21 +136,23 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr ) { UniChar buf[2] ; + int numChars = dataSize / sizeof( UniChar) + 1; UniChar* charBuf = buf ; - if ( dataSize > 4 ) - charBuf = new UniChar[ dataSize / sizeof( UniChar) ] ; + if ( numChars * 2 > 4 ) + charBuf = new UniChar[ numChars ] ; GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; + charBuf[ numChars - 1 ] = 0; #if SIZEOF_WCHAR_T == 2 uniChar = charBuf[0] ; #else wxMBConvUTF16 converter ; - converter.MB2WC( &uniChar , (const char*)charBuf , 1 ) ; + converter.MB2WC( &uniChar , (const char*)charBuf , 2 ) ; #endif - if ( dataSize > 4 ) + if ( numChars * 2 > 4 ) delete[] charBuf ; } #endif @@ -167,7 +172,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; wxTheApp->MacSetCurrentEvent( event , handler ) ; if ( /* focus && */ wxTheApp->MacSendKeyDownEvent( - focus , message , modifiers , when , point.h , point.v , uniChar ) ) + focus , message , modifiers , when , point.h , point.v , uniChar[0] ) ) { result = noErr ; } @@ -177,7 +182,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event case kEventRawKeyUp : if ( /* focus && */ wxTheApp->MacSendKeyUpEvent( - focus , message , modifiers , when , point.h , point.v , uniChar ) ) + focus , message , modifiers , when , point.h , point.v , uniChar[0] ) ) { result = noErr ; } diff --git a/src/mac/corefoundation/cfstring.cpp b/src/mac/corefoundation/cfstring.cpp index 11b0f6d4ff..078df1e308 100644 --- a/src/mac/corefoundation/cfstring.cpp +++ b/src/mac/corefoundation/cfstring.cpp @@ -681,8 +681,10 @@ wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding) unibuf[cflen] = 0 ; wxMBConvUTF16 converter ; noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ; + wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); buf = new wxChar[ noChars + 1 ] ; - converter.MB2WC( buf , (const char*)unibuf , noChars ) ; + noChars = converter.MB2WC( buf , (const char*)unibuf , noChars + 1 ) ; + wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); delete[] unibuf ; #endif #else -- 2.45.2