(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
This commit is contained in:
Vadim Zeitlin 2004-11-22 17:37:58 +00:00
parent 53638fe05b
commit f43707413a

View File

@ -239,34 +239,25 @@ bool wxDataObjectComposite::SetData(const wxDataFormat& format,
#if defined(__WXGTK20__) && wxUSE_UNICODE #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 size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
{ {
if (format == wxDF_UNICODETEXT) wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() );
{ return buffer ? strlen(buffer) + 1 : 0;
// 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;
}
} }
bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{ {
if (format == wxDF_UNICODETEXT) wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() );
{ if ( !buffer )
// Use UTF8 not UCS4 return false;
wxCharBuffer buffer = wxConvUTF8.cWX2MB( GetText().c_str() );
strcpy( (char*) buf, (const char*) buffer ); strcpy( (char*) buf, buffer );
}
else
{
wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() );
strcpy( (char*) buf, (const char*) buffer );
}
return true; return true;
} }
@ -274,10 +265,11 @@ bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
bool wxTextDataObject::SetData(const wxDataFormat& format, bool wxTextDataObject::SetData(const wxDataFormat& format,
size_t WXUNUSED(len), const void *buf) size_t WXUNUSED(len), const void *buf)
{ {
if (format == wxDF_UNICODETEXT) wxWCharBuffer buffer = GetConv(format).cMB2WX((const char *)buf);
SetText( wxConvUTF8.cMB2WX( (const char*) buf ) ); if ( !buffer )
else return false;
SetText( wxConvLibc.cMB2WX( (const char*) buf ) );
SetText(buffer);
return true; return true;
} }