summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-05-18 14:50:52 +0000
committerGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-05-18 14:50:52 +0000
commit788ae16a47c2bd345ee1542b0bd6e4b2278258f6 (patch)
treef9ea535fd45f8926f50df3281ccc38c714dd73e5 /gui
parenta0918f9ac872f34e4781264374ce451be608742f (diff)
downloadfpGUI-788ae16a47c2bd345ee1542b0bd6e4b2278258f6.tar.xz
* Added a new UTF8 Utils unit with some handy functions.
* Modified TFEdit to be UTF8 friendly. Needs testing. * Modified the WidgetTest - Edit Fields form to show UTF8 text in the TFEdit component for testing.
Diffstat (limited to 'gui')
-rw-r--r--gui/fpgui.pas1
-rw-r--r--gui/fpguiedit.inc45
2 files changed, 33 insertions, 13 deletions
diff --git a/gui/fpgui.pas b/gui/fpgui.pas
index 285c4c3b..ac69f788 100644
--- a/gui/fpgui.pas
+++ b/gui/fpgui.pas
@@ -159,6 +159,7 @@ implementation
uses
Math
,StyleManager
+ ,fpUTF8Utils
;
diff --git a/gui/fpguiedit.inc b/gui/fpguiedit.inc
index 8cd3268c..6ad17cb7 100644
--- a/gui/fpguiedit.inc
+++ b/gui/fpguiedit.inc
@@ -142,11 +142,13 @@ begin
BoundsSize.cx - Borders.Right - 1, BoundsSize.cy - Borders.Bottom - 1)) then
exit;
+ // setup the correct font color
if wsEnabled in WidgetState then
Canvas.SetColor(Style.GetUIColor(FFontColor))
else
Canvas.SetColor(Style.GetUIColor(clGrayText));
+ // paint the text
s := GetDrawText;
Canvas.TextOut(Point(-FDrawOffset + Borders.Left+2, 3), s);
@@ -176,7 +178,7 @@ begin
// drawing cursor
Canvas.SetColor(Style.GetUIColor(clWindowText));
// Style.SetUIColor(Canvas, clWindowText);
- tw := Canvas.TextWidth(Copy(s, 1, FCursorPos));
+ tw := Canvas.TextWidth(UTF8Copy(s, 1, FCursorPos));
// 2 pixel cursor line
// ItemRect.Top := Borders.Top;
@@ -202,21 +204,24 @@ begin
end;
procedure TFCustomEdit.EvKeyPressed(Key: Word; Shift: TShiftState);
+var
+ WideText: WideString;
begin
if Shift * [ssShift, ssAlt, ssCtrl, ssMeta, ssSuper, ssHyper, ssAltGr] = [] then
begin
+ WideText := UTF8Decode(Text);
// Normal typing - no selections
case Key of
keyLeft, keyUp:
if CursorPos > 0 then
CursorPos := CursorPos - 1;
keyRight, keyDown:
- if CursorPos < Length(Text) then
+ if CursorPos < Length(WideText) then
CursorPos := CursorPos + 1;
keyHome:
CursorPos := 0;
keyEnd:
- CursorPos := Length(Text);
+ CursorPos := Length(WideText);
else
inherited EvKeyPressed(Key, Shift);
end;
@@ -250,23 +255,27 @@ end;
procedure TFCustomEdit.EvKeyChar(KeyChar: Char);
+var
+ WideText: WideString;
begin
+ WideText := UTF8Decode(FText);
+
case KeyChar of
#8: { Backspace }
if FCursorPos > 0 then
begin
- FText := Copy(FText, 1, FCursorPos - 1) + Copy(FText, FCursorPos + 1, Length(FText));
+ FText := UTF8Copy(FText, 1, FCursorPos - 1) + UTF8Copy(FText, FCursorPos + 1, Length(WideText));
FCursorPos := FCursorPos - 1;
end;
#127: { Del }
- if FCursorPos < Length(FText) then
+ if FCursorPos < Length(WideText) then
begin
- FText := Copy(FText, 1, FCursorPos) + Copy(FText, FCursorPos + 2, Length(FText));
+ FText := UTF8Copy(FText, 1, FCursorPos) + UTF8Copy(FText, FCursorPos + 2, Length(WideText));
Redraw;
end;
#32..#126, #128..#255:
begin
- FText := Copy(FText, 1, FCursorPos) + KeyChar + Copy(FText, CursorPos + 1, Length(FText));
+ FText := UTF8Copy(FText, 1, FCursorPos) + KeyChar + UTF8Copy(FText, CursorPos + 1, Length(WideText));
FCursorPos := FCursorPos + 1;
end;
else
@@ -292,10 +301,13 @@ begin
end;
procedure TFCustomEdit.SetText(const AText: String);
+var
+ WideText: WideString;
begin
inherited SetText(AText);
+ WideText := Utf8Decode(FText);
FSelOffset := 0;
- FCursorPos := Length(FText);
+ FCursorPos := Length(WideText);
FSelStart := FCursorPos;
FDrawOffset := 0;
AdjustCursor;
@@ -334,6 +346,7 @@ var
n: integer;
cx: integer;
lText: string;
+ WideText: WideString;
begin
if (pEvent.Button = mbLeft) then
begin
@@ -343,13 +356,14 @@ begin
// Make sure we work with the correct displayed text
lText := GetDrawText;
+ WideText := UTF8Decode(lText);
cp := FCursorPos;
- cpx := FindForm.Wnd.Canvas.TextWidth(Copy(lText, 1, FCursorPos)) - FDrawOffset + lSideMargin;
+ cpx := FindForm.Wnd.Canvas.TextWidth(UTF8Copy(lText, 1, FCursorPos)) - FDrawOffset + lSideMargin;
- for n := 0 to Length(lText) do
+ for n := 0 to Length(WideText) do
begin
- cx := FindForm.Wnd.Canvas.TextWidth(Copy(lText, 1, n)) - FDrawOffset + lSideMargin;
+ cx := FindForm.Wnd.Canvas.TextWidth(UTF8Copy(lText, 1, n)) - FDrawOffset + lSideMargin;
if abs(cx - pEvent.Position.x) < abs(cpx - pEvent.Position.x) then
begin
cpx := cx;
@@ -396,7 +410,7 @@ begin
Exit; //==>
Canvas := FindForm.Wnd.Canvas;
- tw := Canvas.TextWidth(Copy(GetDrawText, 1, FCursorPos));
+ tw := Canvas.TextWidth(UTF8Copy(GetDrawText, 1, FCursorPos));
lBorders := Style.GetEditBoxBorders;
lSideMargins := lBorders.Left + lBorders.Right;
@@ -416,11 +430,16 @@ end;
// Return the correct text to be displayed
function TFCustomEdit.GetDrawText: string;
+var
+ WideText: WideString;
begin
if FPasswordChar = #0 then
Result := FText
else
- Result := StringOfChar(FPasswordChar, Length(FText));
+ begin
+ WideText := Utf8Decode(FText);
+ Result := StringOfChar(FPasswordChar, Length(WideText));
+ end;
end;
{$ENDIF read_implementation}