From 214c8287f70468fb0cc27172f4da18349ec8b1ba Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Sat, 12 Jan 2008 09:46:39 +0000 Subject: [PATCH] Initial implementation of a unicode clipboard on windows. git-svn-id: trunk@13730 - --- lcl/interfaces/win32/win32winapi.inc | 64 ++++++++++++++++++++------ lcl/interfaces/wince/wincecallback.inc | 2 +- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/lcl/interfaces/win32/win32winapi.inc b/lcl/interfaces/win32/win32winapi.inc index 3b3f9ea8c1..d232d586cc 100644 --- a/lcl/interfaces/win32/win32winapi.inc +++ b/lcl/interfaces/win32/win32winapi.inc @@ -416,6 +416,31 @@ var Size: integer; DbgFormatID: integer; Bitmap: TBitmap; + BufferStream: TMemoryStream; + BufferWideString: widestring; + BufferString: ansistring; + + function ReadClipboardToStream(DestStream: TStream): Boolean; + begin + Result := false; + + DataHandle := Windows.GetClipboardData(FormatID); + if DataHandle<>HWND(0) then + begin + Size := Windows.GlobalSize(DataHandle); + if Size>0 then + begin + Data := Windows.GlobalLock(DataHandle); + try + DestStream.Write(Data^, Size); + finally + Windows.GlobalUnlock(DataHandle); + end; + Result := true; + end; + end; + end; + begin Assert(False, 'TWin32WidgetSet.ClipboardGetData - Start'); Result := false; @@ -436,7 +461,8 @@ begin if Windows.OpenClipboard(Windows.HWND(nil)) then try - if FormatID=Windows.CF_BITMAP then begin + if FormatID=Windows.CF_BITMAP then + begin Bitmap:= TBitmap.Create; Bitmap.TransparentColor := clNone; DataHandle := Windows.GetClipboardData(FormatID); @@ -445,20 +471,32 @@ begin Bitmap.Free; Result := true; end - else begin - DataHandle := Windows.GetClipboardData(FormatID); - if DataHandle<>HWND(0) then begin - Size := Windows.GlobalSize(DataHandle); - if Size>0 then begin - Data := Windows.GlobalLock(DataHandle); - try - Stream.Write(Data^, Size); - finally - Windows.GlobalUnlock(DataHandle); - end; - Result := true; + else + {$IFDEF WindowsUnicodeSupport} + { In the case of unicode text, it's necessary to + convert it from UTF-16 to UTF-8 } + if FormatID=Windows.CF_UNICODETEXT then + begin + BufferStream := TMemoryStream.Create; + try + Result := ReadClipboardToStream(BufferStream); + + if Size>0 then + begin + BufferStream.Position := 0; + SetLength(BufferWideString, Size div 2); + BufferStream.Read(BufferWideString[1], Size); + BufferString := Utf8Encode(BufferWideString); + Stream.Write(BufferString[1], Length(BufferString)); end; + finally + BufferStream.Free; end; + end + else + {$ENDIF} + begin + Result := ReadClipboardToStream(Stream); end; finally Windows.CloseClipboard; diff --git a/lcl/interfaces/wince/wincecallback.inc b/lcl/interfaces/wince/wincecallback.inc index 4dc27ef3d9..b5f9d03290 100644 --- a/lcl/interfaces/wince/wincecallback.inc +++ b/lcl/interfaces/wince/wincecallback.inc @@ -1441,7 +1441,7 @@ begin end; // Guesture recognition process to enable popup menus. - if lWinControl.PopupMenu<>nil then + if (lWinControl.PopupMenu <> nil) then begin Info.cbSize := SizeOf(SHRGINFO); Info.dwFlags := SHRG_RETURNCMD;