From e958d2d8f496180da5e3cc6dc31be8b6bc80a6c2 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 1 May 2017 21:58:48 +0200 Subject: [PATCH] Add support for unicode text in wxClipboard when wxUSE_OLE==0 (wxMSW) wxDF_UNICODETEXT objects are handled using Win clipboard API. --- src/msw/clipbrd.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/msw/clipbrd.cpp b/src/msw/clipbrd.cpp index 37cfcc0d8f..1cab19ba1b 100644 --- a/src/msw/clipbrd.cpp +++ b/src/msw/clipbrd.cpp @@ -54,10 +54,6 @@ #include "wx/msw/dib.h" #endif -// wxDataObject is tied to OLE/drag and drop implementation, therefore so are -// the functions using wxDataObject in wxClipboard -//#define wxUSE_DATAOBJ wxUSE_DRAG_AND_DROP - #if wxUSE_OLE // use OLE clipboard #define wxUSE_OLE_CLIPBOARD 1 @@ -168,6 +164,7 @@ bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat) } +#if !wxUSE_OLE_CLIPBOARD bool wxSetClipboardData(wxDataFormat dataFormat, const void *data, int width, int height) @@ -340,6 +337,22 @@ bool wxSetClipboardData(wxDataFormat dataFormat, break; } + case wxDF_UNICODETEXT: + { + LPWSTR s = (LPWSTR)data; + DWORD size = sizeof(WCHAR) * (lstrlenW(s) + 1); + HANDLE hGlobalMemory = ::GlobalAlloc(GHND, size); + if ( hGlobalMemory ) + { + LPWSTR lpGlobalMemory = (LPWSTR)::GlobalLock(hGlobalMemory); + memcpy(lpGlobalMemory, s, size); + ::GlobalUnlock(hGlobalMemory); + } + + handle = ::SetClipboardData(CF_UNICODETEXT, hGlobalMemory); + } + break; + case wxDF_HTML: { char* html = (char *)data; @@ -506,6 +519,26 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) break; } + case wxDF_UNICODETEXT: + { + HANDLE hGlobalMemory = ::GetClipboardData(CF_UNICODETEXT); + if ( hGlobalMemory ) + { + DWORD size = ::GlobalSize(hGlobalMemory); + if ( len ) + *len = size; + WCHAR* s = new WCHAR[(size + 1) / sizeof(WCHAR)]; + if ( s ) + { + LPWSTR lpGlobalMemory = (LPWSTR)::GlobalLock(hGlobalMemory); + memcpy(s, lpGlobalMemory, size); + ::GlobalUnlock(hGlobalMemory); + retval = s; + } + } + } + break; + default: { HANDLE hGlobalMemory = ::GetClipboardData(dataFormat); @@ -538,6 +571,7 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) return retval; } +#endif // !wxUSE_OLE_CLIPBOARD wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat) { @@ -739,6 +773,14 @@ bool wxClipboard::AddData( wxDataObject *data ) } break; + case wxDF_UNICODETEXT: + { + wxTextDataObject* textDataObject = (wxTextDataObject*)data; + wxString str(textDataObject->GetText()); + bRet = wxSetClipboardData(format, str.wc_str()); + } + break; + case wxDF_BITMAP: case wxDF_DIB: { @@ -971,6 +1013,19 @@ bool wxClipboard::GetData( wxDataObject& data ) return true; } + case wxDF_UNICODETEXT: + { + wxTextDataObject& textDataObject = (wxTextDataObject &)data; + WCHAR* s = (WCHAR*)wxGetClipboardData(format); + if ( !s ) + return false; + + textDataObject.SetText(wxString(s)); + delete[] s; + + return true; + } + case wxDF_BITMAP: case wxDF_DIB: {