summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-05-18 20:14:32 +0000
committerGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-05-18 20:14:32 +0000
commit36fc30e611da6008a0cb48bb65491dfe2f7d9f8d (patch)
tree3a2c14474e59e857bca9a5cec14e6b06c0161394
parent788ae16a47c2bd345ee1542b0bd6e4b2278258f6 (diff)
downloadfpGUI-36fc30e611da6008a0cb48bb65491dfe2f7d9f8d.tar.xz
* Removed the old Xlib Font support form fpGFX/X11
* Fixed the Xtf font support in fpGFX/X11 to use the UTF-8 Xtf functions instead of the UTF-16 functions. * Fixed the GUI TFEdit by removing all usage of the WideString type
-rw-r--r--examples/gui/widgettest/widgettest.pas7
-rw-r--r--gfx/fputf8utils.pas6
-rw-r--r--gfx/x11/gfx_x11.pas149
-rw-r--r--gfx/x11/unitxft.pas13
-rw-r--r--gui/fpguiedit.inc33
5 files changed, 45 insertions, 163 deletions
diff --git a/examples/gui/widgettest/widgettest.pas b/examples/gui/widgettest/widgettest.pas
index 704e1619..2435200e 100644
--- a/examples/gui/widgettest/widgettest.pas
+++ b/examples/gui/widgettest/widgettest.pas
@@ -666,7 +666,11 @@ end;
procedure TEditForm.GrayCheckBox2Click(Sender: TObject);
begin
- Edit2.Enabled := not GrayCheckBox2.Checked;
+// Edit2.Enabled := not GrayCheckBox2.Checked;
+ if GrayCheckBox2.Checked then
+ Edit2.PasswordChar := #0
+ else
+ Edit2.PasswordChar := '*';
end;
procedure TEditForm.cbBorderStyleClick(Sender: TObject);
@@ -695,6 +699,7 @@ begin
inherited Create(AOwner);
LoadForm(self);
Edit1.Text := 'Gráficas Magnificacion! Teste';
+ Edit2.Text := 'Gráficas';
Edit2.PasswordChar := '*';
end;
diff --git a/gfx/fputf8utils.pas b/gfx/fputf8utils.pas
index 0bad5380..f04c4212 100644
--- a/gfx/fputf8utils.pas
+++ b/gfx/fputf8utils.pas
@@ -16,6 +16,7 @@ uses
function UTF8Pos(const SearchForText, SearchInText: string): integer;
function UTF8Copy(const s: string; StartCharIndex, CharCount: integer): string;
+function UTF8Length(const s: string): integer;
function UTF8Length(p: PChar; ByteCount: integer): integer;
function UTF8CharStart(UTF8Str: PChar; Len, Index: integer): PChar;
function UTF8CharacterLength(p: PChar): integer;
@@ -55,6 +56,11 @@ begin
end;
end;
+function UTF8Length(const s: string): integer;
+begin
+ Result := UTF8Length(PChar(s),length(s));
+end;
+
function UTF8Length(p: PChar; ByteCount: integer): integer;
var
CharLen: LongInt;
diff --git a/gfx/x11/gfx_x11.pas b/gfx/x11/gfx_x11.pas
index 1deba25a..862ea1e5 100644
--- a/gfx/x11/gfx_x11.pas
+++ b/gfx/x11/gfx_x11.pas
@@ -23,17 +23,13 @@ unit GFX_X11;
{$mode objfpc}{$H+}
{$endif}
-{ Disable this, if you do not want Xft to be used for drawing text }
-{$Define XftSupport}
interface
uses
SysUtils, Classes, // FPC units
X, XLib, XUtil, // X11 units
- {$IFDEF XftSupport}
unitxft, // Xft font support
- {$ENDIF}
GfxBase, // fpGFX units
GELDirty; // fpGFX emulation layer
@@ -64,22 +60,14 @@ type
TX11FontResourceImpl = class(TObject)
private
- {$IFDEF XftSupport}
FFontData: PXftFont;
- {$ELSE}
- FFontData: PXFontStruct;
- {$ENDIF}
public
constructor Create(const Descriptor: String);
destructor Destroy; override;
function GetAscent: integer;
function GetDescent: integer;
function GetHeight: integer;
- {$IFDEF XftSupport}
property FontData: PXftFont read FFontData;
- {$ELSE}
- property FontData: PXFontStruct read FFontData write FFontData;
- {$ENDIF}
end;
@@ -115,9 +103,7 @@ type
FRegion: TRegion;
FDefaultFont: TX11FontResourceImpl;
FFontStruct: TX11FontResourceImpl;
- {$IFDEF XftSupport}
FXftDraw: PXftDraw;
- {$ENDIF}
FStateStackpointer: PX11CanvasState;
FColormap: TColormap;
FCurColor: TGfxPixel;
@@ -286,9 +272,7 @@ implementation
uses
GELImage
,fpGFX
- {$IFDEF XftSupport}
-// ,schar16 // Unicode support
- {$ENDIF}
+ ,fpUTF8Utils
;
resourcestring
@@ -344,14 +328,9 @@ begin
LineSolid, CapNotLast, JoinMiter);
FFontStruct := FDefaultFont;
- {$IFDEF XftSupport}
- FXftDraw := XftDrawCreate(GFApplication.Handle, Handle,
- XDefaultVisual(GFApplication.Handle, XDefaultScreen(GFApplication.Handle)),
- XDefaultColormap(GFApplication.Handle, XDefaultScreen(GFApplication.Handle)));
- {$ELSE}
- if Assigned(FFontStruct.FontData) then
- XSetFont(GFApplication.Handle, GC, FFontStruct.FontData^.FID);
- {$ENDIF}
+ FXftDraw := XftDrawCreate(GFApplication.Handle, Handle,
+ XDefaultVisual(GFApplication.Handle, XDefaultScreen(GFApplication.Handle)),
+ XDefaultColormap(GFApplication.Handle, XDefaultScreen(GFApplication.Handle)));
FRegion := XCreateRegion;
Resized(Width, Height); // Set up a proper clipping region
@@ -359,10 +338,9 @@ end;
destructor TX11Canvas.Destroy;
begin
- {$IFDEF XftSupport}
if FXftDraw <> nil then
XftDrawDestroy(FXftDraw);
- {$ENDIF}
+
XDestroyRegion(Region);
if Assigned(GC) then
XFreeGC(GFApplication.Handle, GC);
@@ -499,12 +477,7 @@ begin
Exit; //==>
FFontStruct := TX11Font(AFont).FontStruct;
end;
- {$IFDEF XftSupport}
- {$Note Still needs testing }
- FFontStruct := TX11Font(AFont).FontStruct;
- {$ELSE}
- XSetFont(GFApplication.Handle, GC, FFontStruct.FontData^.FID);
- {$ENDIF}
+ FFontStruct := TX11Font(AFont).FontStruct;
end;
procedure TX11Canvas.SetLineStyle(ALineStyle: TGfxLineStyle);
@@ -526,7 +499,6 @@ begin
end;
end;
-
procedure TX11Canvas.DoDrawArc(const ARect: TRect; StartAngle, EndAngle: Single);
begin
with ARect do
@@ -535,7 +507,6 @@ begin
Round(StartAngle * 64), Round((EndAngle - StartAngle) * 64));
end;
-
procedure TX11Canvas.DoDrawCircle(const ARect: TRect);
begin
with ARect do
@@ -543,13 +514,11 @@ begin
Left, Top, Right - Left - 1, Bottom - Top - 1, 0, 23040);
end;
-
procedure TX11Canvas.DoDrawLine(const AFrom, ATo: TPoint);
begin
XDrawLine(GFApplication.Handle, Handle, GC, AFrom.x, AFrom.y, ATo.x, ATo.y);
end;
-
procedure TX11Canvas.DrawPolyLine(const Coords: array of TPoint);
var
Points: PXPoint;
@@ -573,7 +542,6 @@ begin
FreeMem(Points);
end;
-
procedure TX11Canvas.DoDrawRect(const ARect: TRect);
begin
with ARect do
@@ -581,13 +549,11 @@ begin
Right - Left - 1, Bottom - Top - 1);
end;
-
procedure TX11Canvas.DoDrawPoint(const APoint: TPoint);
begin
XDrawPoint(GFApplication.Handle, Handle, GC, APoint.x, APoint.y);
end;
-
procedure TX11Canvas.DoFillRect(const ARect: TRect);
begin
with ARect do
@@ -610,22 +576,14 @@ begin
XFillPolygon(GFApplication.Handle, Handle, GC, @pts, 3, 0, CoordModeOrigin);
end;
-
function TX11Canvas.FontCellHeight: Integer;
begin
Result := FFontStruct.GetHeight;
end;
-
function TX11Canvas.TextExtent(const AText: String): TSize;
var
- {$IFDEF XftSupport}
- extents : TXGlyphInfo;
- WideText: WideString;
- {$ELSE}
- Direction, FontAscent, FontDescent: LongInt;
- CharStruct: TXCharStruct;
- {$ENDIF}
+ extents: TXGlyphInfo;
begin
if Length(AText) = 0 then
begin
@@ -634,29 +592,16 @@ begin
end
else
begin
- {$IFDEF XftSupport}
- WideText := Utf8Decode(AText);
-// XftTextExtents8(GFApplication.Handle, FFontStruct.FontData, PChar(AText), Length(AText), extents);
- XftTextExtents16(GFApplication.Handle, FFontStruct.FontData, PChar(WideText), Length(WideText), extents);
+ XftTextExtentsUtf8(GFApplication.Handle, FFontStruct.FontData, PChar(AText), Length(AText), extents);
Result.cx := extents.xOff;
Result.cy := extents.yOff;
- {$ELSE}
- XQueryTextExtents(GFApplication.Handle, XGContextFromGC(GC),
- PChar(AText), Length(AText),
- @Direction, @FontAscent, @FontDescent, @CharStruct);
- Result.cx := CharStruct.Width;
- Result.cy := CharStruct.Ascent + CharStruct.Descent;
- {$ENDIF}
end;
end;
-
procedure TX11Canvas.DoTextOut(const APosition: TPoint; const AText: String);
- {$IFDEF XftSupport}
var
fntColor: TXftColor;
- WideText: WideString;
-
+ //--------------
procedure SetXftColor(c: TGfxPixel; var colxft: TXftColor);
begin
colxft.color.blue := (c and $000000FF) shl 8;
@@ -669,33 +614,16 @@ var
colxft.pixel := 0;
end;
- {$ENDIF}
begin
- if Length(AText) < 1 then
+ if UTF8Length(AText) < 1 then
Exit; //==>
- {$IFDEF XftSupport}
- WideText := Utf8Decode(AText);
-
SetXftColor(FCurColor,fntColor);
XftDrawSetClip(FXftDraw, FRegion);
-// XftDrawString8(FXftDraw, fntColor, FFontStruct.FontData, APosition.x,
-// Aposition.y + FFontStruct.GetAscent, PChar(AText), Length(AText));
-
- XftDrawString16(FXftDraw, fntColor, FFontStruct.FontData, APosition.x,
- Aposition.y + FFontStruct.GetAscent, PChar(WideText), Length(WideText));
-
-// pasgf implementation
-// XftDrawString16(FXftDraw, FColorTextXft, FCurFontRes.Handle, x,
-// y+FCurFontRes.GetAscent, @txt[1], Length(txt) )
-
- {$ELSE}
- XDrawString(GFApplication.Handle, Handle, GC, APosition.x,
- APosition.y + FFontStruct.GetAscent, PChar(AText), Length(AText));
- {$ENDIF}
+ XftDrawStringUtf8(FXftDraw, fntColor, FFontStruct.FontData, APosition.x,
+ Aposition.y + FFontStruct.GetAscent, PChar(AText), Length(AText));
end;
-
procedure TX11Canvas.DoCopyRect(ASource: TFCustomCanvas; const ASourceRect: TRect;
const ADestPos: TPoint);
var
@@ -725,7 +653,6 @@ begin
ASourceRect.Bottom - ASourceRect.Top, ADestPos.x, ADestPos.y);
end;
-
procedure TX11Canvas.DoMaskedCopyRect(ASource, AMask: TFCustomCanvas;
const ASourceRect: TRect; const AMaskPos, ADestPos: TPoint);
var
@@ -1211,13 +1138,11 @@ begin
DoBreakRun := False;
end;
-
procedure TX11Application.Quit;
begin
DoBreakRun := True;
end;
-
function TX11Application.FindWindowByXID(XWindowID: X.TWindow): TFCustomWindow;
var
i: Integer;
@@ -1278,21 +1203,11 @@ begin
if not Assigned(Handle) then
raise EX11Error.CreateFmt(SOpenDisplayFailed, [DisplayName]);
- {$IFDEF XftSupport}
// FDefaultFont := TX11FontResourceImpl.Create('Arial-10');
- FDefaultFont := TX11FontResourceImpl.Create('Sans-9');
- {$ELSE}
- FDefaultFont := TX11FontResourceImpl.Create('-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1');
- {$ENDIF}
+ FDefaultFont := TX11FontResourceImpl.Create('Sans-10');
if not Assigned(FDefaultFont) then
- begin
- {$IFNDEF XftSupport}
- FDefaultFont := TX11FontResourceImpl.Create('-*-fixed-*-*-*-*-*-*-*-*-*-*-iso8859-*');
- {$ENDIF}
- if not Assigned(FDefaultFont) then
- raise EX11Error.Create(SNoDefaultFont);
- end;
+ raise EX11Error.Create(SNoDefaultFont);
end;
{ TX11Window }
@@ -1435,7 +1350,6 @@ begin
// XSetTransientForHint(GFApplication.Handle, Handle, Handle);
end;
-
destructor TX11Window.Destroy;
begin
if Assigned(OnClose) then
@@ -1454,7 +1368,6 @@ begin
inherited Destroy;
end;
-
procedure TX11Window.SetPosition(const APosition: TPoint);
var
Supplied: PtrInt;
@@ -1496,7 +1409,6 @@ begin
XMoveWindow(GFApplication.Handle, Handle, lx, ly);
end;
-
procedure TX11Window.SetSize(const ASize: TSize);
begin
// !!!: Implement this properly
@@ -1504,7 +1416,6 @@ begin
SetClientSize(ASize);
end;
-
procedure TX11Window.SetMinMaxSize(const AMinSize, AMaxSize: TSize);
begin
// !!!: Implement this properly
@@ -1512,7 +1423,6 @@ begin
SetMinMaxClientSize(AMinSize, AMaxSize);
end;
-
procedure TX11Window.SetClientSize(const ASize: TSize);
var
ChangeMask: Cardinal;
@@ -1536,7 +1446,6 @@ begin
XConfigureWindow(GFApplication.Handle, Handle, ChangeMask, @Changes);
end;
-
procedure TX11Window.SetMinMaxClientSize(const AMinSize, AMaxSize: TSize);
var
Supplied: PtrInt;
@@ -1577,7 +1486,6 @@ begin
XFree(SizeHints);
end;
-
{ Makes the window visible and raises it to the top of the stack. }
procedure TX11Window.Show;
begin
@@ -1585,7 +1493,6 @@ begin
XMapRaised(GFApplication.Handle, Handle);
end;
-
procedure TX11Window.Invalidate(const ARect: TRect);
begin
GFApplication.DirtyList.AddRect(Self, ARect);
@@ -1755,9 +1662,6 @@ begin
end;
end;
-
-// protected methods
-
function TX11Window.GetTitle: String;
var
s: PChar;
@@ -1767,13 +1671,11 @@ begin
XFree(s);
end;
-
procedure TX11Window.SetTitle(const ATitle: String);
begin
XStoreName(GFApplication.Handle, Handle, PChar(ATitle));
end;
-
procedure TX11Window.DoSetCursor;
const
CursorTable: array[TFCursor] of Integer = (
@@ -1802,7 +1704,6 @@ begin
XDefineCursor(GFApplication.Handle, Handle, FCurCursorHandle);
end;
-
function TX11Window.ConvertShiftState(AState: Cardinal): TShiftState;
begin
Result := [];
@@ -1898,7 +1799,6 @@ begin
{$ENDIF}
end;
-
procedure TX11Window.UpdateMotifWMHints;
type
PMotifWmHints = ^TMotifWmHints;
@@ -1967,10 +1867,6 @@ begin
XFree(Hints);
end;
-
-{ private methods }
-
-
function TX11Window.StartComposing(const Event: TFEvent): TKeySym;
begin
SetLength(FComposeBuffer,
@@ -1978,7 +1874,6 @@ begin
SizeOf(FComposeBuffer) - 1, @Result, @FComposeStatus));
end;
-
procedure TX11Window.EndComposing;
var
i: Integer;
@@ -1988,7 +1883,6 @@ begin
OnKeyChar(Self, FComposeBuffer[i]);
end;
-
procedure TX11Window.Expose(var Event: TXExposeEvent);
{var
IsNotEmpty: Boolean;
@@ -2046,7 +1940,6 @@ begin
end;
end;
-
procedure TX11Window.ClientMessage(var Event: TXClientMessageEvent);
begin
if Event.message_type = GFApplication.FWMProtocols then
@@ -2070,7 +1963,6 @@ begin
Result.height := ARect.Bottom - ARect.Top;
end;
-
function XRectToRect(const ARect: TXRectangle): TRect;
begin
Result.Left := ARect.x;
@@ -2079,7 +1971,6 @@ begin
Result.Bottom := ARect.y + ARect.height;
end;
-
function GetXEventName(Event: LongInt): String;
const
EventNames: array[2..34] of String = (
@@ -2102,11 +1993,7 @@ end;
constructor TX11FontResourceImpl.Create(const Descriptor: String);
begin
- {$IFDEF XftSupport}
FFontData := XftFontOpenName(GFApplication.Handle, XDefaultScreen(GFApplication.Handle), PChar(Descriptor));
- {$ELSE}
- FFontData := XLoadQueryFont(GFApplication.Handle, PChar(Descriptor));
- {$ENDIF}
if not Assigned(FFontData) then
raise EX11Error.CreateFmt(SFontCreationFailed, [Descriptor]);
end;
@@ -2114,15 +2001,7 @@ end;
destructor TX11FontResourceImpl.Destroy;
begin
if Assigned(FFontData) then
- begin
- {$IFDEF XftSupport}
XftFontClose(GFApplication.Handle, FFontData);
- {$ELSE}
- if FFontData^.fid <> 0 then
- XUnloadFont(GFApplication.Handle, FFontData^.fid);
- XFreeFontInfo(nil, FFontData, 0);
- {$ENDIF}
- end;
inherited Destroy;
end;
diff --git a/gfx/x11/unitxft.pas b/gfx/x11/unitxft.pas
index 10958261..a4b1f6c0 100644
--- a/gfx/x11/unitxft.pas
+++ b/gfx/x11/unitxft.pas
@@ -1,6 +1,6 @@
{
fpGFX - Free Pascal Graphics Library
- Copyright (C) 2006 by Graeme Geldenhuys
+ Copyright (C) 2006-2007 by Graeme Geldenhuys
member of the fpGFX development team.
Xft interface functions
@@ -108,11 +108,13 @@ function XftDrawPicture(draw : PXftDraw) : TPicture; cdecl;
function XftFontOpenName(display : PXDisplay; scr : integer; par3 : PChar) : PXftFont; cdecl;
procedure XftFontClose(display : PXDisplay; fnt : PXftFont); cdecl;
+procedure XftDrawStringUtf8(draw : PXftDraw; var col : TXftColor; fnt : PXftFont; x,y : integer; txt : PChar; len : integer); cdecl;
procedure XftDrawString8(draw : PXftDraw; var col : TXftColor; fnt : PXftFont; x,y : integer; txt : PChar; len : integer); cdecl;
procedure XftDrawString16(draw : PXftDraw; var col : TXftColor; fnt : PXftFont; x,y : integer; txt : PChar; len : integer); cdecl;
-procedure XftTextExtents16(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl;
+procedure XftTextExtentsUtf8(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl;
procedure XftTextExtents8(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl;
+procedure XftTextExtents16(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl;
//function XftGlyphExists(display : PXDisplay; fnt : PXftFont; ch : integer) : longbool; cdecl;
@@ -124,8 +126,11 @@ function XftListFonts(display : PXDisplay; screen : integer; params : array of c
function XftNameUnparse(pat : PFcPattern; dest : PChar; destlen : integer) : boolean; cdecl;
procedure FcFontSetDestroy(fsp : PFcFontSet); cdecl;
+
+
implementation
+
function XftDrawCreate(display : PXDisplay; win : TXID; vis : PVisual; colorm : longint) : PXftDraw; cdecl; external;
procedure XftDrawChange(xftd : PXftDraw; win : TXID); cdecl; external;
procedure XftDrawDestroy(draw : PXftDraw); cdecl; external;
@@ -135,11 +140,13 @@ function XftDrawPicture(draw : PXftDraw) : TPicture; cdecl; external;
function XftFontOpenName(display : PXDisplay; scr : integer; par3 : PChar) : PXftFont; cdecl; external;
procedure XftFontClose(display : PXDisplay; fnt : PXftFont); cdecl; external;
+procedure XftDrawStringUtf8(draw : PXftDraw; var col : TXftColor; fnt : PXftFont; x,y : integer; txt : PChar; len : integer); cdecl; external;
procedure XftDrawString8(draw : PXftDraw; var col : TXftColor; fnt : PXftFont; x,y : integer; txt : PChar; len : integer); cdecl; external;
procedure XftDrawString16(draw : PXftDraw; var col : TXftColor; fnt : PXftFont; x,y : integer; txt : PChar; len : integer); cdecl; external;
-procedure XftTextExtents16(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl; external;
+procedure XftTextExtentsUtf8(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl; external;
procedure XftTextExtents8(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl; external;
+procedure XftTextExtents16(display : PXDisplay; fnt : PXftFont; txt : PChar; len : integer; var extents : TXGlyphInfo); cdecl; external;
//function XftGlyphExists(display : PXDisplay; fnt : PXftFont; ch : integer) : longbool; cdecl; external;
diff --git a/gui/fpguiedit.inc b/gui/fpguiedit.inc
index 6ad17cb7..79bb2a70 100644
--- a/gui/fpguiedit.inc
+++ b/gui/fpguiedit.inc
@@ -204,24 +204,21 @@ 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(WideText) then
+ if CursorPos < UTF8Length(FText) then
CursorPos := CursorPos + 1;
keyHome:
CursorPos := 0;
keyEnd:
- CursorPos := Length(WideText);
+ CursorPos := UTF8Length(FText);
else
inherited EvKeyPressed(Key, Shift);
end;
@@ -255,27 +252,23 @@ end;
procedure TFCustomEdit.EvKeyChar(KeyChar: Char);
-var
- WideText: WideString;
begin
- WideText := UTF8Decode(FText);
-
case KeyChar of
#8: { Backspace }
if FCursorPos > 0 then
begin
- FText := UTF8Copy(FText, 1, FCursorPos - 1) + UTF8Copy(FText, FCursorPos + 1, Length(WideText));
+ FText := UTF8Copy(FText, 1, FCursorPos - 1) + UTF8Copy(FText, FCursorPos + 1, UTF8Length(FText));
FCursorPos := FCursorPos - 1;
end;
#127: { Del }
- if FCursorPos < Length(WideText) then
+ if FCursorPos < UTF8Length(FText) then
begin
- FText := UTF8Copy(FText, 1, FCursorPos) + UTF8Copy(FText, FCursorPos + 2, Length(WideText));
+ FText := UTF8Copy(FText, 1, FCursorPos) + UTF8Copy(FText, FCursorPos + 2, UTF8Length(FText));
Redraw;
end;
#32..#126, #128..#255:
begin
- FText := UTF8Copy(FText, 1, FCursorPos) + KeyChar + UTF8Copy(FText, CursorPos + 1, Length(WideText));
+ FText := UTF8Copy(FText, 1, FCursorPos) + KeyChar + UTF8Copy(FText, CursorPos + 1, UTF8Length(FText));
FCursorPos := FCursorPos + 1;
end;
else
@@ -301,13 +294,10 @@ begin
end;
procedure TFCustomEdit.SetText(const AText: String);
-var
- WideText: WideString;
begin
inherited SetText(AText);
- WideText := Utf8Decode(FText);
FSelOffset := 0;
- FCursorPos := Length(WideText);
+ FCursorPos := UTF8Length(FText);
FSelStart := FCursorPos;
FDrawOffset := 0;
AdjustCursor;
@@ -346,7 +336,6 @@ var
n: integer;
cx: integer;
lText: string;
- WideText: WideString;
begin
if (pEvent.Button = mbLeft) then
begin
@@ -356,12 +345,11 @@ begin
// Make sure we work with the correct displayed text
lText := GetDrawText;
- WideText := UTF8Decode(lText);
cp := FCursorPos;
cpx := FindForm.Wnd.Canvas.TextWidth(UTF8Copy(lText, 1, FCursorPos)) - FDrawOffset + lSideMargin;
- for n := 0 to Length(WideText) do
+ for n := 0 to UTF8Length(lText) do
begin
cx := FindForm.Wnd.Canvas.TextWidth(UTF8Copy(lText, 1, n)) - FDrawOffset + lSideMargin;
if abs(cx - pEvent.Position.x) < abs(cpx - pEvent.Position.x) then
@@ -430,15 +418,12 @@ end;
// Return the correct text to be displayed
function TFCustomEdit.GetDrawText: string;
-var
- WideText: WideString;
begin
if FPasswordChar = #0 then
Result := FText
else
begin
- WideText := Utf8Decode(FText);
- Result := StringOfChar(FPasswordChar, Length(WideText));
+ Result := StringOfChar(FPasswordChar, UTF8Length(FText));
end;
end;