]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't add spurious NULs at the end of wxTextDataObject text under OS X.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 10 Sep 2010 19:28:52 +0000 (19:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 10 Sep 2010 19:28:52 +0000 (19:28 +0000)
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

src/common/dobjcmn.cpp

index 271144ee7615bb6db4e49029cb9bb23e7918a817..f019177524dfc68224fee31247d3a8048552b3a8 100644 (file)
@@ -355,22 +355,22 @@ bool wxTextDataObject::SetData(const wxDataFormat& format,
 
 #elif defined(wxNEEDS_UTF16_FOR_TEXT_DATAOBJ)
 
-static wxMBConvUTF16 sUTF16Converter;
+namespace
+{
 
-static inline wxMBConv& GetConv(const wxDataFormat& format)
+inline wxMBConv& GetConv(const wxDataFormat& format)
 {
-    return
-        format == wxDF_UNICODETEXT
-        ? (wxMBConv&) sUTF16Converter
-        : (wxMBConv&) wxConvLocal;
+    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;
 }