From f43707413ac4f7ffbf7385df09c1e3d60aeca455 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 22 Nov 2004 17:37:58 +0000 Subject: [PATCH] (blind) fix for GTK2/Unicode crashes when copying text to the clipboard git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30696 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/dobjcmn.cpp | 44 +++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/common/dobjcmn.cpp b/src/common/dobjcmn.cpp index 483eab6d59..ac306c2d90 100644 --- a/src/common/dobjcmn.cpp +++ b/src/common/dobjcmn.cpp @@ -239,34 +239,25 @@ bool wxDataObjectComposite::SetData(const wxDataFormat& format, #if defined(__WXGTK20__) && wxUSE_UNICODE +static inline wxMBConv& GetConv(const wxDataFormat& format) +{ + // use UTF8 for wxDF_UNICODETEXT and UCS4 for wxDF_TEXT + return format == wxDF_UNICODETEXT ? wxConvUTF8 : wxConvLibc; +} + size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const { - if (format == wxDF_UNICODETEXT) - { - // Use UTF8 not UCS4 - wxCharBuffer buffer = wxConvUTF8.cWX2MB( GetText().c_str() ); - return strlen( (const char*) buffer ) + 1; - } - else // == wxDF_TEXT - { - wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() ); - return strlen( (const char*) buffer ) + 1; - } + wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() ); + return buffer ? strlen(buffer) + 1 : 0; } bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const { - if (format == wxDF_UNICODETEXT) - { - // Use UTF8 not UCS4 - wxCharBuffer buffer = wxConvUTF8.cWX2MB( GetText().c_str() ); - strcpy( (char*) buf, (const char*) buffer ); - } - else - { - wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() ); - strcpy( (char*) buf, (const char*) buffer ); - } + wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() ); + if ( !buffer ) + return false; + + strcpy( (char*) buf, buffer ); return true; } @@ -274,10 +265,11 @@ bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const bool wxTextDataObject::SetData(const wxDataFormat& format, size_t WXUNUSED(len), const void *buf) { - if (format == wxDF_UNICODETEXT) - SetText( wxConvUTF8.cMB2WX( (const char*) buf ) ); - else - SetText( wxConvLibc.cMB2WX( (const char*) buf ) ); + wxWCharBuffer buffer = GetConv(format).cMB2WX((const char *)buf); + if ( !buffer ) + return false; + + SetText(buffer); return true; } -- 2.45.2