[dasher: 5/217] Fixed Win32 CopyToClipboard bug.
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 5/217] Fixed Win32 CopyToClipboard bug.
- Date: Sat, 27 Feb 2016 12:00:45 +0000 (UTC)
commit 53083e3b121b1487c0f636ca9438a55238206224
Author: ipomoena <ipomoena users noreply github com>
Date: Mon Jun 22 14:16:28 2015 -0700
Fixed Win32 CopyToClipboard bug.
UTF8 buffer was copied as unicode data.
Src/Win32/Dasher.cpp | 16 +++++++---------
Src/Win32/Widgets/Edit.cpp | 13 -------------
2 files changed, 7 insertions(+), 22 deletions(-)
---
diff --git a/Src/Win32/Dasher.cpp b/Src/Win32/Dasher.cpp
index 5de3756..a3d2e63 100644
--- a/Src/Win32/Dasher.cpp
+++ b/Src/Win32/Dasher.cpp
@@ -18,9 +18,6 @@
#include "Common/WinOptions.h"
-//ACL not sure what headers we need to include to get clipboard operations, but may need:
-//#include <afxpriv.h>
-
#ifndef _WIN32_WCE
#include <sys/stat.h>
#endif
@@ -312,23 +309,24 @@ void CDasher::CopyToClipboard(const string &strText) {
if (OpenClipboard(m_hParent))
{
EmptyClipboard(); //also frees memory containing any previous data
-
+ Tstring wideText;
+ UTF8string_to_wstring(strText, wideText);
+
//Allocate global memory for string - enough for characters + NULL.
- HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, strText.length()+1);
+ HGLOBAL hClipboardData = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, sizeof(WCHAR)*(wideText.length()+1));
//GlobalLock returns a pointer to the data associated with the handle returned from GlobalAlloc
- char * pchData = (char*)GlobalLock(hClipboardData);
+ LPWSTR pchData = (LPWSTR)GlobalLock(hClipboardData);
//now fill it...
- strcpy(pchData, strText.c_str());
+ wcscpy(pchData, wideText.c_str());
- //Unlock memory, i.e. release our access to it -
+ // Unlock memory, i.e. release our access to it -
// but don't free it (with GlobalFree), as it will "belong"
// to the clipboard.
GlobalUnlock(hClipboardData);
//Now, point the clipboard at that global memory...
- //ACL may have to use CF_TEXT or CF_OEMTEXT prior to WinNT/2K???
SetClipboardData(CF_UNICODETEXT,hClipboardData);
//Finally, unlock the clipboard (i.e. a pointer to the data on it!)
diff --git a/Src/Win32/Widgets/Edit.cpp b/Src/Win32/Widgets/Edit.cpp
index 27c78e8..6525f4e 100644
--- a/Src/Win32/Widgets/Edit.cpp
+++ b/Src/Win32/Widgets/Edit.cpp
@@ -356,19 +356,6 @@ void CEdit::Cut() {
void CEdit::Copy() {
SendMessage(WM_COPY, 0, 0);
-/*
-#ifndef _UNICODE
- HGLOBAL handle;
- DWORD* foo;
- handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, sizeof(DWORD));
- foo = (DWORD*) GlobalLock(handle);
- *foo = MAKELCID(MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), SORT_DEFAULT);
- GlobalUnlock(handle);
- OpenClipboard(m_hwnd);
- SetClipboardData(CF_LOCALE, handle);
- CloseClipboard();
-#endif
-*/
}
void CEdit::Paste() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]