From 25758297101c1b4be1164357efc60e69b1d1127a Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 15 May 2004 14:58:09 +0000 Subject: [PATCH] unicode conversion support for dataobjects git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27290 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataobj.h | 12 +++++++++ src/common/dobjcmn.cpp | 51 ++++++++++++++++++++++++++++++++++++++ src/mac/carbon/dataobj.cpp | 13 ++++++++++ 3 files changed, 76 insertions(+) diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h index 085487c62f..838f25f33b 100644 --- a/include/wx/dataobj.h +++ b/include/wx/dataobj.h @@ -345,6 +345,18 @@ public: virtual bool GetDataHere(void *buf) const { return GetDataHere(GetPreferredFormat(), buf); } virtual bool SetData(size_t len, const void *buf) { return SetData(GetPreferredFormat(), len, buf); } + size_t GetDataSize(const wxDataFormat& format) const; + bool GetDataHere(const wxDataFormat& format, void *pBuf) const; + bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf); +#elif wxUSE_UNICODE && defined(__WXMAC__) + virtual size_t GetFormatCount(Direction WXUNUSED(dir) = Get) const { return 2; } + virtual void GetAllFormats(wxDataFormat *formats, + wxDataObjectBase::Direction WXUNUSED(dir) = Get) const; + + virtual size_t GetDataSize() const { return GetDataSize(GetPreferredFormat()); } + virtual bool GetDataHere(void *buf) const { return GetDataHere(GetPreferredFormat(), buf); } + virtual bool SetData(size_t len, const void *buf) { return SetData(GetPreferredFormat(), len, buf); } + size_t GetDataSize(const wxDataFormat& format) const; bool GetDataHere(const wxDataFormat& format, void *pBuf) const; bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf); diff --git a/src/common/dobjcmn.cpp b/src/common/dobjcmn.cpp index c70c712265..3f145db321 100644 --- a/src/common/dobjcmn.cpp +++ b/src/common/dobjcmn.cpp @@ -282,6 +282,57 @@ bool wxTextDataObject::SetData(const wxDataFormat& format, return TRUE; } +#elif wxUSE_UNICODE && defined(__WXMAC__) + +size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const +{ + if (format == wxDF_UNICODETEXT) + { + // host native is UTF16 + wxMBConvUTF16BE converter ; + wxCharBuffer buffer = converter.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 +{ + if (format == wxDF_UNICODETEXT) + { + // host native is UTF16 + wxMBConvUTF16BE converter ; + wxCharBuffer buffer = converter.cWX2MB( GetText().c_str() ); + strcpy( (char*) buf, (const char*) buffer ); + } + else + { + wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() ); + strcpy( (char*) buf, (const char*) buffer ); + } + + return TRUE; +} + +bool wxTextDataObject::SetData(const wxDataFormat& format, + size_t WXUNUSED(len), const void *buf) +{ + if (format == wxDF_UNICODETEXT) + { + // host native is UTF16 + wxMBConvUTF16BE converter ; + SetText( converter.cMB2WX( (const char*) buf ) ); + } + else + SetText( wxConvLibc.cMB2WX( (const char*) buf ) ); + + return TRUE; +} + #else size_t wxTextDataObject::GetDataSize() const diff --git a/src/mac/carbon/dataobj.cpp b/src/mac/carbon/dataobj.cpp index cc6f7df020..bec4f2bd60 100644 --- a/src/mac/carbon/dataobj.cpp +++ b/src/mac/carbon/dataobj.cpp @@ -166,6 +166,19 @@ bool wxDataObject::IsSupportedFormat( } } +// ---------------------------------------------------------------------------- +// wxTextDataObject +// ---------------------------------------------------------------------------- + +#if wxUSE_UNICODE +void wxTextDataObject::GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Direction dir) const +{ + *formats++ = wxDataFormat( wxDF_TEXT ); + *formats = wxDataFormat( wxDF_UNICODETEXT ); +} + +#endif + // ---------------------------------------------------------------------------- // wxFileDataObject // ---------------------------------------------------------------------------- -- 2.45.2