Large unicode improvements for Windows CE.

git-svn-id: trunk@14164 -
This commit is contained in:
sekelsenmat 2008-02-16 21:38:56 +00:00
parent dbdbd492a7
commit 9e54486ffa
17 changed files with 192 additions and 215 deletions

View File

@ -124,6 +124,7 @@ procedure BlendRect(ADC: HDC; const ARect: TRect; Color: ColorRef);
function GetLastErrorText(AErrorCode: Cardinal): String;
function BitmapToRegion(hBmp: HBITMAP; cTransparentColor: COLORREF = 0; cTolerance: COLORREF = $101010): HRGN;
{ String functions that may be moved to the RTL in the future }
function WideStrLCopy(dest, source: PWideChar; maxlen: SizeInt): PWideChar;
type

View File

@ -1066,7 +1066,7 @@ end;
function TWin32WidgetSet.DrawText(DC: HDC; Str: PChar; Count: Integer; var Rect: TRect; Flags: Cardinal): Integer;
{$ifdef WindowsUnicodeSupport}
var
s: String;
s: AnsiString;
w: WideString;
{$endif}
begin
@ -1075,20 +1075,22 @@ begin
{$ifdef WindowsUnicodeSupport}
// use temp buffer, if count is set, there might be no null terminator
if count = -1
then s := str
else begin
if count = -1 then
s := str
else
begin
SetLength(s, count);
move(str^, s[1], count);
end;
// the length of utf8 vs Wide/Ansi the strings differ, so recalc.
if UnicodeEnabledOS
then begin
if UnicodeEnabledOS then
begin
// TODO: use the real number of chars (and not the lenght)
W := Utf8Decode(S);
Result := Windows.DrawTextW(DC, PWideChar(W), Length(W), @Rect, Flags);
end
else begin
else
begin
S := Utf8ToAnsi(S);
Result := Windows.DrawText(DC, PChar(S), Length(S), @Rect, Flags);
end;
@ -1232,7 +1234,7 @@ end;
function TWin32WidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
{$ifdef WindowsUnicodeSupport}
var
s: String;
s: AnsiString;
w: WideString;
{$ENDIF}
begin
@ -1828,7 +1830,7 @@ end;
function TWin32WidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; Var Size: TSize): Boolean;
{$ifdef WindowsUnicodeSupport}
var
s: String;
s: AnsiString;
w: WideString;
{$ENDIF}
begin

View File

@ -169,7 +169,6 @@ begin
Parent := TWin32WidgetSet(WidgetSet).AppHandle;
SubClassWndProc := @WindowProc;
WindowTitle := nil;
StrCaption := PChar(AWinControl.Caption);
WindowTitle := nil;
Height := AWinControl.Height;
@ -473,8 +472,8 @@ end;
class procedure TWin32WSWinControl.SetText(const AWinControl: TWinControl; const AText: string);
Begin
if not WSCheckHandleAllocated(AWincontrol, 'SetText')
then Exit;
if not WSCheckHandleAllocated(AWincontrol, 'SetText') then Exit;
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS
then Windows.SetWindowTextW(AWinControl.Handle, PWideChar(Utf8Decode(AText)))

View File

@ -230,7 +230,7 @@ Var
PageHandle: HWND;
begin
Notebook := GetWindowInfo(NotebookHandle)^.WinControl as TCustomNotebook;
PageIndex := Windows.SendMessage(NotebookHandle, TCM_GETCURSEL, 0, 0);
PageIndex := Windows.SendMessageW(NotebookHandle, TCM_GETCURSEL, 0, 0);
//PageIndex := NotebookPageRealToLCLIndex(Notebook, PageIndex);
if PageIndex = -1 then exit;
PageHandle := Notebook.CustomPage(PageIndex).Handle;
@ -438,7 +438,7 @@ Var
// tabpage parent and got a dc to draw in, divert paint to parent
DCIndex := Windows.SaveDC(PaintMsg.DC);
MoveWindowOrgEx(PaintMsg.DC, -parLeft, -parTop);
Windows.SendMessage(ParentPaintWindow, WM_PAINT, PaintMsg.DC, 0);
Windows.SendMessageW(ParentPaintWindow, WM_PAINT, PaintMsg.DC, 0);
Windows.RestoreDC(PaintMsg.DC, DCIndex);
end;
if (WParam = 0) or not needParentPaint then
@ -487,9 +487,9 @@ Var
begin
MousePos.X := LMMouse.Pos.X;
MousePos.Y := LMMouse.Pos.Y;
for I := 0 to Windows.SendMessage(Window, LB_GETCOUNT, 0, 0) - 1 do
for I := 0 to Windows.SendMessageW(Window, LB_GETCOUNT, 0, 0) - 1 do
begin
Windows.SendMessage(Window, LB_GETITEMRECT, I, PtrInt(@ItemRect));
Windows.SendMessageW(Window, LB_GETITEMRECT, I, PtrInt(@ItemRect));
ItemRect.Right := ItemRect.Left + ItemRect.Bottom - ItemRect.Top;
if Windows.PtInRect(ItemRect, MousePos) then
begin
@ -518,7 +518,7 @@ Var
Sibling := Parent.Controls[i];
if (Sibling is TRadioButton) and (Sibling<>RadioButton) and
(TRadioButton(Sibling).HandleAllocated) then
Windows.SendMessage(TRadioButton(Sibling).Handle, BM_SETCHECK,
Windows.SendMessageW(TRadioButton(Sibling).Handle, BM_SETCHECK,
Windows.WParam(BST_UNCHECKED), 0);
end;
end;
@ -541,7 +541,7 @@ Var
var
Buddy: HWND;
begin
Buddy := SendMessage(SpinEditHandle, UDM_GETBUDDY, 0, 0);
Buddy := SendMessageW(SpinEditHandle, UDM_GETBUDDY, 0, 0);
DestroyWindow(Buddy);
end;
@ -549,7 +549,7 @@ Var
var
Buddy: HWND;
begin
Buddy := SendMessage(SpinEditHandle, UDM_GETBUDDY, 0, 0);
Buddy := SendMessageW(SpinEditHandle, UDM_GETBUDDY, 0, 0);
Windows.EnableWindow(Buddy, Enable);
end;
@ -723,7 +723,7 @@ Var
begin
prevFocus := Windows.GetFocus;
Windows.SetFocus(targetWindow);
PLMsg^.Result := Windows.SendMessage(targetWindow, WM_SYSCOMMAND, WParam, LParam);
PLMsg^.Result := Windows.SendMessageW(targetWindow, WM_SYSCOMMAND, WParam, LParam);
Windows.SetFocus(prevFocus);
WinProcess := false;
end;

View File

@ -136,7 +136,7 @@ Var
S: TStrings;
Counter: Integer;
AnIndex: Integer;
tmpStr : PWideChar;
tmpStr : widestring;
Begin
{ Do not call inherited Assign as it does things we do not want to happen }
If Source Is TStrings Then
@ -148,9 +148,9 @@ Begin
Windows.SendMessage(FWinCEList, FFlagResetContent, 0, 0);
For Counter := 0 To (TStrings(Source).Count - 1) Do
Begin
tmpStr := LCLStringToPWideChar(s[Counter]);
AnIndex := Windows.SendMessage(FWinCEList, FFlagAddString, 0, LPARAM(PWideChar(tmpStr))); //Insert
FreeMem(tmpStr);
tmpStr := UTF8Decode(s[Counter]);
AnIndex := Windows.SendMessageW(FWinCEList, FFlagAddString, 0,
LPARAM(PWideChar(tmpStr))); //Insert
PutObject(AnIndex, S.Objects[Counter]);
end;
End
@ -181,17 +181,16 @@ end;
------------------------------------------------------------------------------}
Function TWinCEListStringList.Get(Index: Integer): String;
Var
Item: PWideChar;
w: widestring;
Begin
If (Index < 0) Or (Index >= Count) Then
Raise Exception.Create('Out of bounds.')
Else
Begin
Item := PWideChar(SysAllocStringLen(nil,Windows.SendMessage(FWinCEList, FFlagGetTextLen, Index, 0)));
Windows.SendMessage(FWinCEList, FFlagGetText, Index, LPARAM(Item));
SetLength(w, Windows.SendMessageW(FWinCEList, FFlagGetTextLen, Index, 0));
Windows.SendMessageW(FWinCEList, FFlagGetText, Index, LPARAM(PWideChar(w)));
Result := UTF8Encode(w);
End;
Result := String(WideString(Item));//roozbeh:maybe WideStringToString?
SysFreeString(Item);
End;
{------------------------------------------------------------------------------
@ -235,7 +234,7 @@ End;
------------------------------------------------------------------------------}
Function TWinCEListStringList.GetObject(Index: Integer): TObject;
Begin
HWND(Result) := Windows.SendMessage(FWinCEList, FFlagGetItemData, Index, 0);
HWND(Result) := Windows.SendMessageW(FWinCEList, FFlagGetItemData, Index, 0);
End;
{------------------------------------------------------------------------------
@ -245,16 +244,12 @@ End;
------------------------------------------------------------------------------}
Procedure TWinCEListStringList.Insert(Index: Integer; Const S: String);
var
tmpS : PWideChar;
Begin
FLastInsertedIndex := Index;
tmpS := LCLStringToPWideChar(s);
If FSorted Then
FLastInsertedIndex := Windows.SendMessage(FWinCEList, FFlagAddString, 0, LPARAM(PWideChar(tmpS)))
Else
Windows.SendMessage(FWinCEList, FFlagInsertString, Index, LPARAM(PWideChar(tmpS)));
FreeMem(tmpS);
if FSorted then
FLastInsertedIndex := Windows.SendMessageW(FWinCEList, FFlagAddString, 0, LPARAM(PWideChar(Utf8Decode(S))))
else
Windows.SendMessageW(FWinCEList, FFlagInsertString, Index, LPARAM(PWideChar(Utf8Decode(S))));
End;
procedure TWinCEListStringList.Put(Index: integer; const S: string);
@ -266,14 +261,14 @@ begin
lItemIndex := -1;
if FFlagGetSelected <> 0 then
begin
lItemIndex := SendMessage(FWinCEList, FFlagGetSelected, Index, 0);
lItemIndex := SendMessageW(FWinCEList, FFlagGetSelected, Index, 0);
lSelected := lItemIndex > 0;
if lItemIndex <> LB_ERR then
lItemIndex := Index;
end;
if lItemIndex = -1 then
begin
lItemIndex := SendMessage(FWinCEList, FFlagGetItemIndex, 0, 0);
lItemIndex := SendMessageW(FWinCEList, FFlagGetItemIndex, 0, 0);
lSelected := true;
end;
@ -282,9 +277,9 @@ begin
if lSelected then
begin
if (FFlagSetSelected = 0)
or (SendMessage(FWinCEList, FFlagSetSelected, Windows.WParam(true), lItemIndex) = -1) then
or (SendMessageW(FWinCEList, FFlagSetSelected, Windows.WParam(true), lItemIndex) = -1) then
begin
SendMessage(FWinCEList, FFlagSetItemIndex, lItemIndex, 0);
SendMessageW(FWinCEList, FFlagSetItemIndex, lItemIndex, 0);
end;
end;
end;
@ -617,15 +612,12 @@ End;
------------------------------------------------------------------------------}
Procedure TWinCECListStringList.Insert(Index: Integer; Const S: String);
var
tmpS : PWideChar;
Begin
tmpS := LCLStringToPWideChar(S);
If FSorted Then
Windows.SendMessage(FWinCECList,LB_ADDSTRING, 0, LPARAM(PWideChar(tmpS)))
Else
Windows.SendMessage(FWinCECList,LB_INSERTSTRING, Index, LPARAM(PWideChar(tmpS)));
FreeMem(tmpS);
FLastInsertedIndex := Index;
if FSorted then
FLastInsertedIndex := Windows.SendMessageW(FWinCECList, LB_ADDSTRING, 0, LPARAM(PWideChar(Utf8Decode(S))))
else
Windows.SendMessageW(FWinCECList, LB_INSERTSTRING, Index, LPARAM(PWideChar(Utf8Decode(S))));
End;
{------------------------------------------------------------------------------

View File

@ -118,6 +118,7 @@ Type
FWinCECList: HWND;
FSender: TWinControl; // Needed to recreate the window
FSorted: Boolean;
FlastInsertedIndex: Integer;
Protected
Function Get(Index: Integer): String; Override;
Function GetCount: Integer; Override;

View File

@ -121,17 +121,14 @@ procedure TWinCEMemoStrings.Insert(Index: integer; const S: string);
var
LineStart: Integer;
NewLine: String;
tmpNewLine : PWideChar;
begin
LineStart := GetLineStart(Index);
if Index < GetRealCount then begin
//insert with LineEnding
LineStart := GetLineStart(Index);
NewLine := S+LineEnding;
tmpNewLine := LCLStringToPWideChar(NewLine);
SendMessage(fHandle, EM_SETSEL, LineStart, LineStart);
SendMessage(fHandle, EM_REPLACESEL,0 , lparam(PWideChar(tmpNewLine)));
FreeMem(tmpNewLine);
SendMessageW(fHandle, EM_SETSEL, LineStart, LineStart);
SendMessageW(fHandle, EM_REPLACESEL, 0, lparam(PWideChar(Utf8Decode(NewLine))))
end
else begin
//append with a preceding LineEnding
@ -141,19 +138,13 @@ begin
NewLine := LineEnding+S+LineEnding
else
NewLine := S+LineEnding;
tmpNewLine := LCLStringToPWideChar(NewLine);
SendMessage(fHandle, EM_REPLACESEL,0 , lparam(PWideChar(tmpNewLine)));
FreeMem(tmpNewLine);
SendMessageW(fHandle, EM_REPLACESEL, 0, lparam(PWideChar(Utf8Decode(NewLine))))
end;
end;
procedure TWinCEMemoStrings.SetText(TheText: PChar);
var
tmpTheText : PWideChar;
begin
tmpTheText := LCLStringToPWideChar(TheText);
SendMessage(fHandle, WM_SETTEXT, 0, LPARAM(tmpTheText));
FreeMem(tmpTheText);
Windows.SetWindowTextW(fHandle, PWideChar(Utf8Decode(TheText)))
end;
{$ENDIF}

View File

@ -144,8 +144,9 @@ begin
// Create parent of all windows, 'button on taskbar'
// does this work on wince?!
FAppHandle := CreateWindowExW(0, @ClsName, LCLStringToPWideChar(Application.Title),
WS_POPUP or WS_CLIPSIBLINGS or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX,
FAppHandle := CreateWindowExW(0, @ClsName,
PWideChar(UTF8Decode(Application.Title)),
WS_POPUP or WS_CLIPSIBLINGS or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX,
0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,}
0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,}
0, 0, HWND(nil), HMENU(nil), HInstance, nil);
@ -428,12 +429,8 @@ end;
procedure TWinCEWidgetSet.AppSetTitle(const ATitle: string);
var
tmpText: PWideChar;
begin
tmpText := LCLStringToPWideChar(ATitle);
Windows.SetWindowText(FAppHandle, @tmpText);
FreeMem(tmpText);
Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8Decode(ATitle)));
end;

View File

@ -96,6 +96,9 @@ procedure RedrawMenus;
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
function GetControlText(AHandle: HWND): string;
{ String functions that may be moved to the RTL in the future }
function WideStrLCopy(dest, source: PWideChar; maxlen: SizeInt): PWideChar;
type
PDisableWindowsInfo = ^TDisableWindowsInfo;
TDisableWindowsInfo = record
@ -124,12 +127,9 @@ uses
and the caller is responsible for freeing it with FreeMem
}
function LCLStringToPWideChar(inString: string): PWideChar;
{$ifdef WindowsUnicodeSupport}
var
WideBuffer: widestring;
{$endif}
begin
{$ifdef WindowsUnicodeSupport}
{ Converts to a buffer }
WideBuffer := Utf8Decode(inString);
@ -137,10 +137,7 @@ begin
Result := GetMem(Length(WideBuffer) * 2 + 2);
{ Copies to the final destination }
Move(WideBuffer[1], Result^, Length(WideBuffer) * 2 + 2);
{$else}
Result := StringToPWideChar(inString);
{$endif}
WideStrLCopy(PWideChar(WideBuffer), Result, Length(WideBuffer));
end;
{ well this is different from normal string(widestring)
@ -1311,16 +1308,13 @@ var
winHandle: HWND;
canvasHandle: HDC;
oldFontHandle: HFONT;
tmpText : PWideChar;
begin
winHandle := AWinControl.Handle;
canvasHandle := GetDC(winHandle);
oldFontHandle := SelectObject(canvasHandle, Windows.SendMessage(winHandle, WM_GetFont, 0, 0));
DeleteAmpersands(Text);
tmpText := LCLStringToPWideChar(Text);
Result := Windows.GetTextExtentPoint32W(canvasHandle, PWideChar(tmpText), Length(Text), textSize);
FreeMem(tmpText);
Result := LCLIntf.GetTextExtentPoint32(canvasHandle, PChar(Text), Length(Text), textSize);
if Result then
begin
@ -1343,6 +1337,25 @@ begin
SysFreeString(tmpWideStr);
end;
{ Exactly equal to StrLCopy but for PWideChars
Copyes a widestring up to a maximal length, in WideChars }
function WideStrLCopy(dest, source: PWideChar; maxlen: SizeInt): PWideChar;
var
counter: SizeInt;
begin
counter := 0;
while (Source[counter] <> #0) and (counter < MaxLen) do
begin
Dest[counter] := Source[counter];
Inc(counter);
end;
{ terminate the string }
Dest[counter] := #0;
Result := Dest;
end;
{-------------------------------------------------------------------------------
procedure AddToChangedMenus(Window: HWnd);

View File

@ -159,7 +159,7 @@ var
Details: TThemedElementDetails;
OldColor: COLORREF;
OldBackColor: COLORREF;
WideBuffer: PWideChar;
WideBuffer: widestring;
begin
Selected := (Data^.itemState AND ODS_SELECTED)>0;
Enabled := CheckListBox.Enabled;
@ -211,10 +211,9 @@ var
OldBackColor := Windows.SetBkColor(Data^._HDC, LCLIntf.GetSysColor(COLOR_WINDOW)); // $00FFFFFF
end;
WideBuffer := LCLStringToPWideChar(CheckListBox.Items[Data^.ItemID]);
Windows.DrawTextW(Data^._HDC, WideBuffer, -1,
WideBuffer := UTF8Decode(CheckListBox.Items[Data^.ItemID]);
Windows.DrawTextW(Data^._HDC, PWideChar(WideBuffer), -1,
Rect, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
FreeMem(WideBuffer);
// Return to default text and background colors
Windows.SetTextColor(Data^._HDC, OldColor);
@ -328,7 +327,7 @@ end;
): string;
begin
Result:=inherited ClipboardFormatToMimeType(FormatID);
end;
end; }
{------------------------------------------------------------------------------
Method: ClipboardGetData
Params: ClipboardType - clipboard type
@ -337,11 +336,11 @@ end;
stream
Returns: true on success
------------------------------------------------------------------------------}
function TWinCEWidgetSet.ClipboardGetData(ClipboardType: TClipboardType;
{function TWinCEWidgetSet.ClipboardGetData(ClipboardType: TClipboardType;
FormatID: TClipboardFormat; Stream: TStream): boolean;
begin
Result:=inherited ClipboardGetData(ClipboardType, FormatID, Stream);
end;
end; }
{------------------------------------------------------------------------------
Method: ClipboardGetFormats
Params: ClipboardType - the type of clipboard operation (GTK only; ignored here)
@ -350,11 +349,11 @@ end;
(you must free it yourself)
Returns: true on success
------------------------------------------------------------------------------}
function TWinCEWidgetSet.ClipboardGetFormats(ClipboardType: TClipboardType;
{function TWinCEWidgetSet.ClipboardGetFormats(ClipboardType: TClipboardType;
var Count: integer; var List: PClipboardFormat): boolean;
begin
Result:=inherited ClipboardGetFormats(ClipboardType, Count, List);
end;
end; }
{------------------------------------------------------------------------------
Method: ClipboardGetOwnerShip
@ -374,13 +373,13 @@ end;
if someone else requests the ownership, the OnRequestProc will be executed
with the invalid FormatID 0 to notify the old owner of the lost of ownership.
------------------------------------------------------------------------------}
function TWinCEWidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
{function TWinCEWidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
OnRequestProc: TClipboardRequestEvent; FormatCount: integer;
Formats: PClipboardFormat): boolean;
begin
Result:=inherited ClipboardGetOwnerShip(ClipboardType, OnRequestProc,
FormatCount, Formats);
end;
end; }
{------------------------------------------------------------------------------
Method: ClipboardRegisterFormat
@ -388,7 +387,7 @@ end;
type to register
Returns: the registered Format identifier (TClipboardFormat)
------------------------------------------------------------------------------}
function TWinCEWidgetSet.ClipboardRegisterFormat(const AMimeType: string
{function TWinCEWidgetSet.ClipboardRegisterFormat(const AMimeType: string
): TClipboardFormat;
begin
Result:=inherited ClipboardRegisterFormat(AMimeType);
@ -776,13 +775,26 @@ end;
------------------------------------------------------------------------------}
function TWinCEWidgetSet.DrawText(DC: HDC; Str: PChar; Count: Integer; var Rect: TRect; Flags: Cardinal): Integer;
var
WideStr : PWideChar;
s: AnsiString;
w: WideString;
begin
Assert(False, Format('trace:> [TWinCEWidgetSet.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]));
WideStr := LCLStringToPWideChar(String(str));
Result := Windows.DrawTextW(DC, WideStr, Count, @Rect, Flags);
FreeMem(WideStr);
// use temp buffer, if count is set, there might be no null terminator
if count = -1 then
s := str
else
begin
SetLength(s, count);
move(str^, s[1], count);
end;
// the length of utf8 vs Wide/Ansi the strings differ, so recalc.
// TODO: use the real number of chars (and not the lenght)
W := Utf8Decode(S);
Result := Windows.DrawTextW(DC, PWideChar(W), Length(W), @Rect, Flags);
// Result := Windows.DrawTextW(DC, WideStr, Count, @Rect, Flags);
Assert(False, Format('trace:> [TWinCEWidgetSet.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;
@ -898,12 +910,25 @@ end;
------------------------------------------------------------------------------}
function TWinCEWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
var
pWideStr : PWideChar;
s: AnsiString;
w: WideString;
begin
Assert(False, Format('trace:> [TWinCEWidgetSet.ExtTextOut] DC:0x%x, X:%d, Y:%d, Options:%d, Str:''%s'', Count: %d', [DC, X, Y, Options, Str, Count]));
pWideStr := LCLStringToPWideChar(string(Str));
Result := Boolean(Windows.ExtTextOutW(DC, X, Y, Options, LPRECT(Rect), pWideStr, Count, Dx));
FreeMem(pWideStr);
// use temp buffer, if count is set, there might be no null terminator
if count = -1 then
s := str
else
begin
SetLength(s, count);
move(str^, s[1], count);
end;
// the length of utf8 vs Wide/Ansi the strings differ, so recalc.
// TODO: use the real number of chars (and not the lenght)
W := Utf8Decode(S);
Result := Windows.ExtTextOutW(DC, X, Y, Options, LPRECT(Rect), PWideChar(W), Length(W), Dx);
// Result := Boolean(Windows.ExtTextOutW(DC, X, Y, Options, LPRECT(Rect), pWideStr, Count, Dx));
Assert(False, Format('trace:< [TWinCEWidgetSet.ExtTextOut] DC:0x%x, X:%d, Y:%d, Options:%d, Str:''%s'', Count: %d', [DC, X, Y, Options, Str, Count]));
end;
@ -1399,15 +1424,14 @@ end;
------------------------------------------------------------------------------}
function TWinCEWidgetSet.GetProp(Handle: hwnd; Str: PChar): Pointer;
var
WideStr: PWideChar;
WideStr: widestring;
begin
WideStr := LCLStringToPWideChar(String(str));
WideStr := UTF8Decode(String(str));
{$ifdef win32}
Result := Pointer(Windows.GetPropW(Handle, WideStr));
Result := Pointer(Windows.GetPropW(Handle, PWideChar(WideStr)));
{$else}
Result := Pointer(Windows.GetProp(Handle, WideStr));
Result := Pointer(Windows.GetProp(Handle, PWideChar(WideStr)));
{$endif}
FreeMem(WideStr);
end;
{function TWinCEWidgetSet.GetRawImageFromDevice(SrcDC: HDC;
@ -1536,13 +1560,24 @@ end;
function TWinCEWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
var
WideStr : PWideChar;
s: AnsiString;
w: WideString;
begin
Assert(False, 'Trace:[TWinCEWidgetSet.GetTextExtentPoint] - Start');
Result := false;
WideStr := LCLStringToPWideChar(String(Str));
Result := Boolean(Windows.GetTextExtentExPointW(DC, WideStr, Count, 0,nil,nil,@Size));
FreeMem(WideStr);
if count = -1 then
s := str
else
begin
SetLength(s, count);
move(str^, s[1], count);
end;
// the length of utf8 vs Wide/Ansi the strings differ, so recalc.
// TODO: use the real number of chars (and not the lenght)
w := Utf8Decode(S);
Result := Windows.GetTextExtentPoint32W(DC, PWideChar(W), Length(W),
{$ifdef Win32}@Size{$else}Size{$endif});
// Result := Boolean(Windows.GetTextExtentExPointW(DC, WideStr, Count, 0,nil,nil,@Size));
Assert(False, 'Trace:[TWinCEWidgetSet.GetTextExtentPoint] - Exit');
end;
@ -1865,13 +1900,13 @@ end;
------------------------------------------------------------------------------}
function TWinCEWidgetSet.MessageBox(HWnd: HWND; LPText, LPCaption: PChar; UType: Cardinal): Integer;
var
LPWCaption,LPWText : PWideChar;
WideLPText, WideLPCaption: widestring;
begin
LPWCaption := LCLStringToPWideChar(String(LPCaption));
LPWText := LCLStringToPWideChar(String(LPText));
Result := Windows.MessageBoxW(HWnd, LPWText, LPWCaption, UType);
FreeMem(LPWCaption);
FreeMem(LPWText);
WideLPText := UTF8Decode(string(LPText));
WideLPCaption := UTF8Decode(string(LPCaption));
Result := Windows.MessageBoxW(HWnd, PWideChar(WideLPText),
PWideChar(WideLPCaption), UType);
end;
{------------------------------------------------------------------------------
@ -2385,15 +2420,14 @@ end;
------------------------------------------------------------------------------}
function TWinCEWidgetSet.SetProp(Handle: hwnd; Str: PChar; Data: Pointer): Boolean;
var
WideStr: PWideChar;
WideStr: widestring;
begin
WideStr := LCLStringToPWideChar(String(str));
WideStr := UTF8Decode(String(str));
{$ifdef win32}
Result := Boolean(Windows.SetPropW(Handle, WideStr, Windows.HANDLE(Data)));
Result := Boolean(Windows.SetPropW(Handle, PWideChar(WideStr), Windows.HANDLE(Data)));
{$else}
Result := Boolean(Windows.SetProp(Handle, WideStr, Windows.HANDLE(Data)));
Result := Boolean(Windows.SetProp(Handle, PWideChar(WideStr), Windows.HANDLE(Data)));
{$endif}
FreeMem(WideStr);
end;
{------------------------------------------------------------------------------
Method: SetROP2

View File

@ -247,7 +247,6 @@ procedure UpdateStatusBarPanel(const StatusPanel: TStatusPanel);
var
BevelType: integer;
Text: string;
pwText : PWideChar;
begin
Text := StatusPanel.Text;
case StatusPanel.Alignment of
@ -259,9 +258,8 @@ begin
pbLowered: BevelType := 0;
pbRaised: BevelType := Windows.SBT_POPOUT;
end;
pwText := LCLStringToPWideChar(Text);
Windows.SendMessage(StatusPanel.StatusBar.Handle, SB_SETTEXT, StatusPanel.Index or BevelType, LPARAM(pwText));
FreeMem(pwText);
Windows.SendMessageW(StatusPanel.StatusBar.Handle, SB_SETTEXT,
StatusPanel.Index or BevelType, LPARAM(PWideChar(UTF8Decode(Text))));
end;
procedure UpdateStatusBarPanelWidths(const StatusBar: TStatusBar);
@ -272,8 +270,8 @@ var
begin
if StatusBar.Panels.Count=0 then begin
// SETPARTS 0,0 does not work :S
Windows.SendMessage(StatusBar.Handle, SB_SIMPLE, 1, 0);
Windows.SendMessage(StatusBar.Handle, SB_SETTEXT, 255, WPARAM(PWideChar('')));
Windows.SendMessageW(StatusBar.Handle, SB_SIMPLE, 1, 0);
Windows.SendMessageW(StatusBar.Handle, SB_SETTEXT, 255, WPARAM(PWideChar('')));
exit;
end;
Getmem(Rights, StatusBar.Panels.Count * sizeof(integer));
@ -355,7 +353,7 @@ begin
if AStatusBar.SimplePanel then
begin
tmpSimpleText := LCLStringToPWideChar(AStatusBar.SimpleText);
Windows.SendMessage(AStatusBar.Handle, SB_SETTEXT, 255, LPARAM(PWideChar(tmpSimpleText)));
Windows.SendMessageW(AStatusBar.Handle, SB_SETTEXT, 255, LPARAM(PWideChar(tmpSimpleText)));
FreeMem(tmpSimpleText);
end
else

View File

@ -145,7 +145,7 @@ type
MenuHandle: HMENU;
Flags, FlagsEx: dword;
SubClassWndProc: pointer;
WindowTitle, StrCaption: PWideChar;
WindowTitle, StrCaption: PChar;
pClassName: PWideChar;
end;
@ -181,9 +181,8 @@ begin
SubClassWndProc := @WindowProc;
WindowTitle := nil;
StrCaption := PChar(AWinControl.Caption);
StrCaption := LCLStringToPWideChar(AWinControl.Caption);
WindowTitle := nil;
Height := AWinControl.Height;
Left := AWinControl.Left;
//Parent := AWinControl.Parent;
@ -229,7 +228,7 @@ begin
Window := CreateWindowExW(
FlagsEx, // Extra Flags
pClassName, // Name of the registered class
WindowTitle, // Title of the window
PWideChar(UTF8Decode(WindowTitle)),// Title of the window
Flags, // Style of the window
Left, // x-position (at beginning)
Top, // y-position (at beginning)
@ -242,9 +241,8 @@ begin
if Window = 0 then
begin
// Writeln('failed to create wince control, error: '+ IntToStr(GetLastError()));
raise exception.create('failed to create win32 control, error: '+IntToStr(GetLastError())
+ ' control: ' + WindowTitle);
+ ' WindowTitle: ' + WindowTitle);
end;
end;
{ after creating a child window the following happens:
@ -449,14 +447,10 @@ begin
end;
class procedure TWinCEWSWinControl.SetText(const AWinControl: TWinControl; const AText: string);
var
tmpStr : PWideChar;
begin
if not WSCheckHandleAllocated(AWincontrol, 'SetText')
then Exit;
tmpStr := LCLStringToPWideChar(AText);
Windows.SetWindowTextW(AWinControl.Handle, PWideChar(tmpStr));
FreeMem(tmpStr);
if not WSCheckHandleAllocated(AWincontrol, 'SetText') then Exit;
Windows.SetWindowTextW(AWinControl.Handle, PWideChar(UTF8Decode(AText)));
end;
class procedure TWinCEWSWinControl.ConstraintsChange(const AWinControl: TWinControl);

View File

@ -205,7 +205,7 @@ begin
{$ifdef Win32}
lvc.pszText := PChar(LCLStringToPWideChar(ACaption));
SendMessage(ALV.Handle, LVM_SETCOLUMNW, WPARAM(AIndex), LPARAM(@lvc));
SendMessageW(ALV.Handle, LVM_SETCOLUMNW, WPARAM(AIndex), LPARAM(@lvc));
{$else}
lvc.pszText := LCLStringToPWideChar(ACaption);
ListView_SetColumn(ALV.Handle, AIndex, lvc);
@ -317,7 +317,7 @@ begin
{$ifdef Win32}
lvi.pszText := PChar(LCLStringToPWideChar(AItem.Caption));
SendMessage(ALV.Handle, LVM_INSERTITEMW, 0, LPARAM(@lvi));
SendMessageW(ALV.Handle, LVM_INSERTITEMW, 0, LPARAM(@lvi));
{$else}
lvi.pszText := LCLStringToPWideChar(AItem.Caption);
ListView_InsertItem(ALV.Handle, lvi);
@ -369,7 +369,7 @@ begin
_gnu_lvi.iSubItem := ASubIndex;
_gnu_lvi.pszText := PChar(PWideChar(Utf8Decode(AText)));
SendMessage(ALV.Handle, LVM_SETITEMTEXTW, WPARAM(AIndex), LPARAM(@_gnu_lvi));
SendMessageW(ALV.Handle, LVM_SETITEMTEXTW, WPARAM(AIndex), LPARAM(@_gnu_lvi));
{$else}
tmpAText := LCLStringToPWideChar(AText);
ListView_SetItemText(ALV.Handle, AIndex, ASubIndex, tmpAText);

View File

@ -334,17 +334,17 @@ begin
begin
// retrieve page handle from tab as extra check (in case page isn't added yet).
TCI.mask := TCIF_PARAM;
Windows.SendMessage(NotebookHandle, TCM_GETITEM, PageIndex, LPARAM(@TCI));
Windows.SendMessageW(NotebookHandle, TCM_GETITEMW, PageIndex, LPARAM(@TCI));
if PtrUInt(TCI.lParam)=PtrUInt(AWinControl) then
begin
Assert(False, Format('Trace:TWinCEWSCustomPage.SetText --> %S', [AText]));
TCI.mask := TCIF_TEXT;
{$ifdef Win32}
TCI.pszText := PChar(LCLStringToPWideChar(AText));
TCI.pszText := PChar(PWideChar(UTF8Decode(AText)));
{$else}
TCI.pszText := LCLStringToPWideChar(AText);
TCI.pszText := PWideChar(UTF8Decode(AText));
{$endif}
Windows.SendMessage(NotebookHandle, TCM_SETITEMW, PageIndex, LPARAM(@TCI));
Windows.SendMessageW(NotebookHandle, TCM_SETITEMW, PageIndex, LPARAM(@TCI));
FreeMem(TCI.pszText);
end;
end;
@ -399,13 +399,13 @@ begin
begin
TCI.Mask := TCIF_TEXT or TCIF_PARAM;
{$ifdef Win32}
TCI.pszText := PChar(LCLStringToPWideChar(AChild.Caption));
TCI.pszText := PChar(PWideChar(UTF8Decode((AChild.Caption))));
{$else}
TCI.pszText := LCLStringToPWideChar(AChild.Caption);
TCI.pszText := PWideChar(UTF8Decode(AChild.Caption));
{$endif}
// store object as extra, so we can verify we got the right page later
TCI.lParam := PtrUInt(AChild);
Windows.SendMessage(Handle, TCM_INSERTITEMW, AIndex, LPARAM(@TCI));
Windows.SendMessageW(Handle, TCM_INSERTITEMW, AIndex, LPARAM(@TCI));
FreeMem(TCI.pszText);
// clientrect possible changed, adding first tab, or deleting last
// windows should send a WM_SIZE message because of this, but it doesn't
@ -456,11 +456,11 @@ begin
TCI.Mask := TCIF_TEXT or TCIF_PARAM;
TCI.lParam := PtrUInt(lPage);
{$ifdef Win32}
TCI.pszText := PChar(LCLStringToPWideChar(lPage.Caption));
TCI.pszText := PChar(PWideChar(UTF8Decode(lPage.Caption)));
{$else}
TCI.pszText := LCLStringToPWideChar(lPage.Caption);
TCI.pszText := PWideChar(UTF8Decode(lPage.Caption));
{$endif}
Windows.SendMessage(WinHandle, TCM_INSERTITEMW, RealIndex, LPARAM(@TCI));
Windows.SendMessageW(WinHandle, TCM_INSERTITEMW, RealIndex, LPARAM(@TCI));
end;
Inc(RealIndex);
end;

View File

@ -262,6 +262,7 @@ begin
pClassName := @ClsName;
FlagsEx := 0;
Flags := WS_OVERLAPPEDWINDOW;
WindowTitle := StrCaption;
lForm := TCustomForm(AWinControl);
CalcFormWindowFlags(lForm, Flags, FlagsEx);
SubClassWndProc := nil;

View File

@ -103,13 +103,10 @@ procedure UpdateFloatSpinEditText(const ASpinHandle: HWND; const ANewValue: sing
var
editHandle: HWND;
newValueText: string;
pwnewValueText : PWideChar;
begin
editHandle := GetBuddyWindow(ASpinHandle);
newValueText := FloatToStrF(ANewValue, ffFixed, 20, ADecimalPlaces);
pwnewValueText := LCLStringToPWideChar(newValueText);
Windows.SendMessage(editHandle, WM_SETTEXT, 0, Windows.LPARAM(PWideChar(pwnewValueText)));
FreeMem(pwnewValueText);
Windows.SendMessageW(editHandle, WM_SETTEXT, 0, Windows.LPARAM(PWideChar(UTF8Decode(newValueText))));
end;
class function TWinCEWSCustomFloatSpinEdit.CreateHandle(const AWinControl: TWinControl;
@ -122,7 +119,11 @@ begin
// customization of Params
with Params do
begin
Buddy := CreateWindowExW(WS_EX_CLIENTEDGE, 'EDIT', StrCaption, Flags Or ES_AUTOHSCROLL, Left, Top, Width, Height, Parent, HMENU(Nil), HInstance, Nil);
Buddy := CreateWindowExW(WS_EX_CLIENTEDGE, 'EDIT',
PWideChar(UTF8Decode(StrCaption)),
Flags Or ES_AUTOHSCROLL,
Left, Top, Width, Height,
Parent, HMENU(Nil), HInstance, Nil);
{Window := CreateUpDownControl(Flags or DWORD(WS_BORDER or UDS_ALIGNRIGHT or UDS_ARROWKEYS),
0, 0, // pos - ignored for buddy
0, 0, // size - ignored for buddy

View File

@ -233,11 +233,8 @@ type
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
// class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override;
// class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut, NewShortcut: TShortcut); override;
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
// class procedure GetPreferredSize(const AWinControl: TWinControl;
// var PreferredWidth, PreferredHeight: integer); override;
end;
@ -771,16 +768,15 @@ end;
class procedure TWinCEWSCustomComboBox.SetText(const AWinControl: TWinControl; const AText: string);
var
Handle: HWND;
pwAText : pWideChar;
pwAText: widestring;
begin
Assert(False, Format('Trace:TWinCEWSCustomComboBox.SetText --> %S', [AText]));
Handle := AWinControl.Handle;
pwAText := LCLStringToPWideChar(AText);
pwAText := UTF8Decode(AText);
if TCustomComboBox(AWinControl).ReadOnly then
Windows.SendMessage(Handle, CB_SELECTSTRING, -1, LPARAM(pwAText))
Windows.SendMessageW(Handle, CB_SELECTSTRING, -1, LPARAM(PWideChar(pwAText)))
else
Windows.SendMessage(Handle, WM_SETTEXT, 0, LPARAM(pwAText));
FreeMem(pwAText);
Windows.SendMessageW(Handle, WM_SETTEXT, 0, LPARAM(PWideChar(pwAText)));
end;
class function TWinCEWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox): TStrings;
@ -982,12 +978,8 @@ begin
end;
class procedure TWinCEWSCustomMemo.SetText(const AWinControl: TWinControl; const AText: string);
var
tmpWideStr : PWideChar;
begin
tmpWideStr := LCLStringToPWideChar(AText);
SendMessage(AWinControl.Handle, WM_SETTEXT, 0, LPARAM(PWideChar(tmpWideStr)));
FreeMem(tmpWideStr);
SendMessageW(AWinControl.Handle, WM_SETTEXT, 0, LPARAM(PWideChar(UTF8Decode(AText))));
end;
class procedure TWinCEWSCustomMemo.SetWordWrap(const ACustomMemo: TCustomMemo; const NewWordWrap: boolean);
@ -1021,7 +1013,7 @@ begin
with Params do
begin
pClassName := @LabelClsName;
WindowTitle := LCLStringToPWideChar(AWinControl.Caption);//roozbeh..we already have this in strcaptiob..whats the diffrence?
WindowTitle := StrCaption;
Flags := WS_CHILD or WS_VISIBLE or WS_TABSTOP or SS_LEFT;//Flags or CalcStaticTextFlags(TCustomStaticText(AWinControl).Alignment);//is ws_child included?
end;
@ -1079,7 +1071,7 @@ begin
// Flags := Flags or BS_PUSHBUTTON;
Flags := WS_CHILD or WS_VISIBLE;
pClassName := @ButtonClsName;
WindowTitle := LCLStringToPWideChar(StrCaption);
WindowTitle := StrCaption;
Left := AWinControl.Left;
Top := AWinControl.Top;
Width := AWinControl.Width;
@ -1102,44 +1094,6 @@ begin
{$endif}
end;
{------------------------------------------------------------------------------
Function: TWinCEWSButton.DestroyHandle
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TWinCEWSButton.DestroyHandle(const AWinControl: TWinControl);
begin
end;
{------------------------------------------------------------------------------
Function: TWinCEWSButton.GetText
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TWinCEWSButton.GetText(const AWinControl: TWinControl; var AText: String): Boolean;
var
tmpStr : PWideChar;
begin
tmpstr := PWideChar(SysAllocStringLen(nil,256));
Result := Boolean(Windows.GetWindowTextW(AWinControl.Handle,tmpStr,256));
AText := String(tmpStr);
SysFreeString(tmpStr);
end;
{------------------------------------------------------------------------------
Function: TWinCEWSButton.SetText
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TWinCEWSButton.SetText(const AWinControl: TWinControl; const AText: String);
var
tmpStr : PWideChar;
begin
tmpstr := LCLStringToPWideChar(AText);
Windows.SetWindowTextW(AWinControl.Handle, tmpStr);
FreeMem(tmpStr);
end;
{ TWinCEWSCustomCheckBox }
class function TWinCEWSCustomCheckBox.CreateHandle(const AWinControl: TWinControl;
@ -1156,7 +1110,7 @@ begin
with Params do
begin
pClassName := @ButtonClsName;
WindowTitle := LCLStringToPWideChar(AWinControl.Caption);
WindowTitle := StrCaption;
if TCustomCheckBox(AWinControl).AllowGrayed then
Flags := Flags Or BS_AUTO3STATE
else
@ -1164,7 +1118,6 @@ begin
end;
// create window
FinishCreateWindow(AWinControl, Params, false);
FreeMem(Params.WindowTitle);
Result := Params.Window;
end;