From 587067bc684c0a7619a5ca0ec99ca40afa9c6a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Wed, 11 Jan 2017 16:48:19 +0100 Subject: [PATCH] Fix pasting multiline text in wxOSX to not use \r Use wxMacConvertNewlines13To10(), not wxMacConvertNewlines10To13() when copying content from native pasteboard. Perform this conversion not only for 8bit text, but for UTF-16 one (which is the one actually used on modern OS X versions) as well. --- include/wx/osx/core/cfstring.h | 1 + src/osx/carbon/dataobj.cpp | 6 ++++-- src/osx/core/cfstring.cpp | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/wx/osx/core/cfstring.h b/include/wx/osx/core/cfstring.h index 8b939a29a6..fad01b88d4 100644 --- a/include/wx/osx/core/cfstring.h +++ b/include/wx/osx/core/cfstring.h @@ -30,6 +30,7 @@ WXDLLIMPEXP_BASE void wxMacConvertNewlines13To10( wxString *data ) ; WXDLLIMPEXP_BASE void wxMacConvertNewlines10To13( wxString *data ) ; WXDLLIMPEXP_BASE void wxMacConvertNewlines13To10( char * data ) ; +WXDLLIMPEXP_BASE void wxMacConvertNewlines13To10( char * data, size_t len ) ; WXDLLIMPEXP_BASE void wxMacConvertNewlines10To13( char * data ) ; WXDLLIMPEXP_BASE wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) ; diff --git a/src/osx/carbon/dataobj.cpp b/src/osx/carbon/dataobj.cpp index edd62110b3..f6967ddbba 100644 --- a/src/osx/carbon/dataobj.cpp +++ b/src/osx/carbon/dataobj.cpp @@ -487,8 +487,10 @@ bool wxDataObject::GetFromPasteboard( void * pb ) memset( buf, 0, flavorDataSize + 4 ); memcpy( buf, CFDataGetBytePtr( flavorData ), flavorDataSize ); - if (dataFormat.GetType() == wxDF_TEXT) - wxMacConvertNewlines10To13( (char*) buf ); + if (dataFormat.GetType() == wxDF_TEXT || dataFormat.GetType() == wxDF_UNICODETEXT) + { + wxMacConvertNewlines13To10( (char*) buf, flavorDataSize ); + } SetData( flavorFormat, flavorDataSize, buf ); transferred = true; free( buf ); diff --git a/src/osx/core/cfstring.cpp b/src/osx/core/cfstring.cpp index 82b5808aa3..f44be612aa 100644 --- a/src/osx/core/cfstring.cpp +++ b/src/osx/core/cfstring.cpp @@ -34,6 +34,15 @@ void wxMacConvertNewlines13To10( char * data ) } } +void wxMacConvertNewlines13To10( char * data, size_t len ) +{ + for ( ; len; ++data, --len ) + { + if ( *data == 0x0d ) + *data = 0x0a; + } +} + void wxMacConvertNewlines10To13( char * data ) { char * buf = data ;