- if (format == wxDF_UNICODETEXT)
- SetText( wxConvUTF8.cMB2WX( (const char*) buf ) );
- else
- SetText( wxConvLibc.cMB2WX( (const char*) buf ) );
-
- return TRUE;
+ if ( buf == NULL )
+ return false;
+
+ wxWCharBuffer buffer = GetConv(format).cMB2WX( (const char*)buf );
+
+ SetText( buffer );
+
+ return true;
+}
+
+#elif wxUSE_UNICODE && defined(__WXMAC__)
+
+static wxMBConvUTF16 sUTF16Converter;
+
+static inline wxMBConv& GetConv(const wxDataFormat& format)
+{
+ return
+ format == wxDF_UNICODETEXT
+ ? (wxMBConv&) sUTF16Converter
+ : (wxMBConv&) wxConvLocal;
+}
+
+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;
+}
+
+bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
+{
+ if ( buf == NULL )
+ return false;
+
+ 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 );
+
+ return true;
+}
+
+bool wxTextDataObject::SetData(const wxDataFormat& format,
+ size_t WXUNUSED(len), const void *buf)
+{
+ if ( buf == NULL )
+ return false;
+
+ wxWCharBuffer buffer = GetConv(format).cMB2WX( (const char*)buf );
+
+ SetText( buffer );
+
+ return true;