Don't add spurious NULs at the end of wxTextDataObject text under OS X.

For some reason we added an extra NUL character to the data copied from
wxTextDataObject but this doesn't seem necessary because the Pasteboard API
is passed the correct data size and so the string doesn't need to be
NUL-terminated.

In fact, adding this NUL broke drag and drop between wx and native controls,
including the case of dropping text in our own wxTextCtrl as this uses its
built in support for dnd and not our code (the fact that we can't even set a
drop target for a wxTextCtrl is a separate bug). In this case we got a string
with an extra NUL in the control resulting in all sorts of hard to debug
problems.

So simply don't add the extra bytes, dnd works fine without them both between
wx windows and from/to another OS X applications.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65510 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-09-10 19:28:52 +00:00
parent 3e4f133a43
commit 5dea30b309

View File

@@ -355,22 +355,22 @@ bool wxTextDataObject::SetData(const wxDataFormat& format,
#elif defined(wxNEEDS_UTF16_FOR_TEXT_DATAOBJ)
static wxMBConvUTF16 sUTF16Converter;
static inline wxMBConv& GetConv(const wxDataFormat& format)
namespace
{
return
format == wxDF_UNICODETEXT
? (wxMBConv&) sUTF16Converter
: (wxMBConv&) wxConvLocal;
inline wxMBConv& GetConv(const wxDataFormat& format)
{
static wxMBConvUTF16 s_UTF16Converter;
return format == wxDF_UNICODETEXT ? static_cast<wxMBConv&>(s_UTF16Converter)
: static_cast<wxMBConv&>(wxConvLocal);
}
} // anonymous namespace
size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
{
size_t len = GetConv(format).WC2MB( NULL, GetText().c_str(), 0 );
len += (format == wxDF_UNICODETEXT ? 2 : 1);
return len;
return GetConv(format).WC2MB(NULL, GetText().wc_str(), 0);
}
bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
@@ -378,26 +378,21 @@ bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
if ( buf == NULL )
return false;
wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() );
wxCharBuffer buffer(GetConv(format).cWX2MB(GetText().c_str()));
size_t len = GetConv(format).WC2MB( NULL, GetText().c_str(), 0 );
len += (format == wxDF_UNICODETEXT ? 2 : 1);
// trailing (uni)char 0
memcpy( (char*)buf, (const char*)buffer, len );
memcpy(buf, buffer.data(), buffer.length());
return true;
}
bool wxTextDataObject::SetData(const wxDataFormat& format,
size_t WXUNUSED(len), const void *buf)
size_t WXUNUSED(len),
const void *buf)
{
if ( buf == NULL )
return false;
wxWCharBuffer buffer = GetConv(format).cMB2WX( (const char*)buf );
SetText( buffer );
SetText(GetConv(format).cMB2WX(static_cast<const char*>(buf)));
return true;
}