Hi,

I am sending the patch to the mailling list just in case there is a
need to discuss it.

Now TForm.Caption, TEdit.Text and TButton.Caption should all work
correctly with unicode.

TLabel.Caption doesn´t work perfectly. It shows the text followed by
some trash characters.

thanks,
--
Felipe Monteiro de Carvalho
Index: lcl/interfaces/win32/win32proc.pp
===================================================================
--- lcl/interfaces/win32/win32proc.pp	(revision 10209)
+++ lcl/interfaces/win32/win32proc.pp	(working copy)
@@ -1130,10 +1130,35 @@
 function GetControlText(AHandle: HWND): string;
 var
   TextLen: dword;
+  AnsiBuffer: string;
+  WideBuffer: WideString;
 begin
+ {$ifdef WindowsUnicodeSupport}
+
+  if UnicodeEnabledOS then
+  begin
+    TextLen := Windows.GetWindowTextLengthW(AHandle);
+    SetLength(WideBuffer, TextLen);
+    TextLen := Windows.GetWindowTextW(AHandle, @WideBuffer[1], TextLen + 1);
+    SetLength(WideBuffer, TextLen);
+    Result := Utf8Encode(WideBuffer);
+  end
+  else
+  begin
+    TextLen := Windows.GetWindowTextLength(AHandle);
+    SetLength(AnsiBuffer, TextLen);
+    TextLen := Windows.GetWindowText(AHandle, @AnsiBuffer[1], TextLen + 1);
+    SetLength(AnsiBuffer, TextLen);
+    Result := AnsiToUtf8(AnsiBuffer);
+  end;
+
+ {$else}
+
   TextLen := GetWindowTextLength(AHandle);
   SetLength(Result, TextLen);
   GetWindowText(AHandle, PChar(Result), TextLen + 1);
+
+ {$endif}
 end;
 
 function Utf8PCharToPWideChar(param: PChar): PWideChar;
Index: lcl/interfaces/win32/win32winapi.inc
===================================================================
--- lcl/interfaces/win32/win32winapi.inc	(revision 10209)
+++ lcl/interfaces/win32/win32winapi.inc	(working copy)
@@ -1117,7 +1117,14 @@
 begin
   Assert(False, Format('trace:> [TWin32WidgetSet.DrawText] DC:0x%x, Str:''%s'', Count: %d, Rect = %d,%d,%d,%d, Flags:%d',
     [DC, Str, Count, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom, Flags]));
+
+ {$ifdef WindowsUnicodeSupport}
+  if UnicodeEnabledOS then Result := Windows.DrawTextW(DC, Utf8ToPWideChar(Str), Count, @Rect, Flags)
+  else Result := Windows.DrawText(DC, PChar(Utf8ToAnsi(Str)), Count, @Rect, Flags);
+ {$else}
   Result := Windows.DrawText(DC, Str, Count, @Rect, Flags);
+ {$endif}
+ 
   Assert(False, Format('trace:> [TWin32WidgetSet.DrawText] DC:0x%x, Str:''%s'', Count: %d, Rect = %d,%d,%d,%d, Flags:%d',
     [DC, Str, Count, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom, Flags]));
 end;
@@ -1254,7 +1261,15 @@
 Function TWin32WidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
 Begin
   Assert(False, Format('trace:> [TWin32WidgetSet.ExtTextOut] DC:0x%x, X:%d, Y:%d, Options:%d, Str:''%s'', Count: %d', [DC, X, Y, Options, Str, Count]));
+
+{$ifdef WindowsUnicodeSupport}
+  if UnicodeEnabledOS
+  then Result := Boolean(Windows.ExtTextOutW(DC, X, Y, Options, LPRECT(Rect), Utf8ToPWideChar(Str), Count, Dx))
+  else Result := Boolean(Windows.ExtTextOut(DC, X, Y, Options, LPRECT(Rect), PChar(Utf8ToAnsi(Str)), Count, Dx));
+ {$else}
   Result := Boolean(Windows.ExtTextOut(DC, X, Y, Options, LPRECT(Rect), Str, Count, Dx));
+ {$endif}
+
   Assert(False, Format('trace:< [TWin32WidgetSet.ExtTextOut] DC:0x%x, X:%d, Y:%d, Options:%d, Str:''%s'', Count: %d', [DC, X, Y, Options, Str, Count]));
 End;
 
@@ -2045,7 +2060,11 @@
 Function TWin32WidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; Var Size: TSize): Boolean;
 Begin
   Assert(False, 'Trace:[TWin32WidgetSet.GetTextExtentPoint] - Start');
-  Result := Boolean(Windows.GetTextExtentPoint32(DC, Str, Count, @Size));
+  {$ifdef WindowsUnicodeSupport}
+    Result := Boolean(Windows.GetTextExtentPoint32W(DC, PWideChar(Utf8Decode(Str)), Count, @Size));
+  {$else}
+    Result := Boolean(Windows.GetTextExtentPoint32(DC, Str, Count, @Size));
+  {$endif}
   Assert(False, 'Trace:[TWin32WidgetSet.GetTextExtentPoint] - Exit');
 End;
 

Reply via email to