Initial implementation of a unicode clipboard on windows.

git-svn-id: trunk@13730 -
This commit is contained in:
sekelsenmat 2008-01-12 09:46:39 +00:00
parent 7d9636e8cf
commit 214c8287f7
2 changed files with 52 additions and 14 deletions

View File

@ -416,6 +416,31 @@ var
Size: integer; Size: integer;
DbgFormatID: integer; DbgFormatID: integer;
Bitmap: TBitmap; 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 begin
Assert(False, 'TWin32WidgetSet.ClipboardGetData - Start'); Assert(False, 'TWin32WidgetSet.ClipboardGetData - Start');
Result := false; Result := false;
@ -436,7 +461,8 @@ begin
if Windows.OpenClipboard(Windows.HWND(nil)) then if Windows.OpenClipboard(Windows.HWND(nil)) then
try try
if FormatID=Windows.CF_BITMAP then begin if FormatID=Windows.CF_BITMAP then
begin
Bitmap:= TBitmap.Create; Bitmap:= TBitmap.Create;
Bitmap.TransparentColor := clNone; Bitmap.TransparentColor := clNone;
DataHandle := Windows.GetClipboardData(FormatID); DataHandle := Windows.GetClipboardData(FormatID);
@ -445,20 +471,32 @@ begin
Bitmap.Free; Bitmap.Free;
Result := true; Result := true;
end end
else begin else
DataHandle := Windows.GetClipboardData(FormatID); {$IFDEF WindowsUnicodeSupport}
if DataHandle<>HWND(0) then begin { In the case of unicode text, it's necessary to
Size := Windows.GlobalSize(DataHandle); convert it from UTF-16 to UTF-8 }
if Size>0 then begin if FormatID=Windows.CF_UNICODETEXT then
Data := Windows.GlobalLock(DataHandle); begin
try BufferStream := TMemoryStream.Create;
Stream.Write(Data^, Size); try
finally Result := ReadClipboardToStream(BufferStream);
Windows.GlobalUnlock(DataHandle);
end; if Size>0 then
Result := true; begin
BufferStream.Position := 0;
SetLength(BufferWideString, Size div 2);
BufferStream.Read(BufferWideString[1], Size);
BufferString := Utf8Encode(BufferWideString);
Stream.Write(BufferString[1], Length(BufferString));
end; end;
finally
BufferStream.Free;
end; end;
end
else
{$ENDIF}
begin
Result := ReadClipboardToStream(Stream);
end; end;
finally finally
Windows.CloseClipboard; Windows.CloseClipboard;

View File

@ -1441,7 +1441,7 @@ begin
end; end;
// Guesture recognition process to enable popup menus. // Guesture recognition process to enable popup menus.
if lWinControl.PopupMenu<>nil then if (lWinControl.PopupMenu <> nil) then
begin begin
Info.cbSize := SizeOf(SHRGINFO); Info.cbSize := SizeOf(SHRGINFO);
Info.dwFlags := SHRG_RETURNCMD; Info.dwFlags := SHRG_RETURNCMD;