+
+ return true;
+}
+
+bool wxTextDataObject::SetData(const wxDataFormat& format,
+ size_t len, const void *buf_)
+{
+ const char * const buf = static_cast<const char *>(buf_);
+
+ if ( buf == NULL )
+ return false;
+
+ if ( format == wxDF_UNICODETEXT || wxLocaleIsUtf8 )
+ {
+ // normally the data is in UTF-8 so we could use FromUTF8Unchecked()
+ // but it's not absolutely clear what GTK+ does if the clipboard data
+ // is not in UTF-8 so do an extra check for tranquility, it shouldn't
+ // matter much if we lose a bit of performance when pasting from
+ // clipboard
+ m_text = wxString::FromUTF8(buf, len);
+ }
+ else // wxDF_TEXT, convert from current (non-UTF8) locale
+ {
+ m_text = wxConvLocal.cMB2WC(buf, len, NULL);
+ }
+
+ return true;
+}
+
+#endif // wxUSE_UNICODE_WCHAR/wxUSE_UNICODE_UTF8
+
+#elif defined(wxNEEDS_UTF16_FOR_TEXT_DATAOBJ)
+
+namespace
+{
+
+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
+{
+ return GetConv(format).WC2MB(NULL, GetText().wc_str(), 0);
+}
+
+bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
+{
+ if ( buf == NULL )
+ return false;
+
+ wxCharBuffer buffer(GetConv(format).cWX2MB(GetText().c_str()));
+
+ memcpy(buf, buffer.data(), buffer.length());
+
+ return true;
+}
+
+bool wxTextDataObject::SetData(const wxDataFormat& format,
+ size_t WXUNUSED(len),
+ const void *buf)
+{
+ if ( buf == NULL )
+ return false;
+
+ SetText(GetConv(format).cMB2WX(static_cast<const char*>(buf)));
+
+ return true;
+}
+
+#else // !wxNEEDS_UTF{8,16}_FOR_TEXT_DATAOBJ
+
+size_t wxTextDataObject::GetDataSize() const
+{
+ return GetTextLength() * sizeof(wxChar);
+}
+
+bool wxTextDataObject::GetDataHere(void *buf) const
+{
+ // NOTE: use wxTmemcpy() instead of wxStrncpy() to allow
+ // retrieval of strings with embedded NULLs
+ wxTmemcpy( (wxChar*)buf, GetText().c_str(), GetTextLength() );
+
+ return true;