- if ( dataFormat.GetType() == wxDF_TEXT )
- byteCount++ ;
-
- data = new char[ byteCount ] ;
- if (( err = GetScrapFlavorData( scrapRef, dataFormat.GetFormatId(), &byteCount , data )) == noErr )
- {
- *len = byteCount ;
- if ( dataFormat.GetType() == wxDF_TEXT )
- ((char*)data)[byteCount] = 0 ;
- }
- else
- {
- delete[] ((char *)data) ;
- data = NULL ;
- }
+ Size allocSize = byteCount;
+ if ( dataFormat.GetType() == wxDF_TEXT )
+ allocSize += 1;
+ else if ( dataFormat.GetType() == wxDF_UNICODETEXT )
+ allocSize += 2;
+
+ data = new char[ allocSize ];
+
+ if (( err = GetScrapFlavorData( scrapRef, dataFormat.GetFormatId(), &byteCount , data )) == noErr )
+ {
+ *len = allocSize;
+ if ( dataFormat.GetType() == wxDF_TEXT )
+ ((char*)data)[ byteCount ] = 0;
+ if ( dataFormat.GetType() == wxDF_UNICODETEXT )
+ {
+ // "data" format is UTF16, so 2 bytes = one character
+ // wxChar size depends on platform, so just clear last 2 bytes
+ ((char*)data)[ byteCount + 0 ] =
+ ((char*)data)[ byteCount + 1 ] = 0;
+ }
+ }
+ else
+ {
+ delete [] (char*)data;
+ data = NULL;
+ }