lcl: more utf8 fixes

git-svn-id: trunk@16479 -
This commit is contained in:
paul 2008-09-08 07:34:25 +00:00
parent 8ae1d62bbe
commit 0e46060ced
2 changed files with 39 additions and 33 deletions

View File

@ -279,7 +279,7 @@ function TCustomComboBox.GetSelText: string;
begin begin
//debugln('TCustomComboBox.GetSelText '); //debugln('TCustomComboBox.GetSelText ');
if FStyle in [csDropDown, csSimple] then if FStyle in [csDropDown, csSimple] then
Result:= Copy(Text, SelStart + 1, SelLength) Result:= UTF8Copy(Text, SelStart + 1, SelLength)
else else
Result:= ''; Result:= '';
end; end;
@ -297,14 +297,16 @@ var
OldSelStart: integer; OldSelStart: integer;
begin begin
//debugln('TCustomComboBox.SetSelText ',Val); //debugln('TCustomComboBox.SetSelText ',Val);
if FStyle in [csDropDown, csSimple] then begin if FStyle in [csDropDown, csSimple] then
OldText:=Text; begin
OldSelStart:=SelStart; OldText := Text;
NewText:=LeftStr(OldText,OldSelStart)+Val OldSelStart := SelStart;
+RightStr(OldText,length(OldText)-SelStart-SelLength); NewText := UTF8Copy(OldText, 1, OldSelStart) +
Text:=NewText; Val +
SelStart:=OldSelStart; UTF8Copy(OldText, UTF8Length(OldText) - SelStart - SelLength, MaxInt);
SelLength:=length(Val); Text := NewText;
SelStart := OldSelStart;
SelLength := UTF8Length(Val);
end; end;
end; end;
@ -318,8 +320,8 @@ end;
function TCustomComboBox.GetSelStart : integer; function TCustomComboBox.GetSelStart : integer;
begin begin
if HandleAllocated then if HandleAllocated then
fSelStart:=TWSCustomComboBoxClass(WidgetSetClass).GetSelStart(Self); FSelStart := TWSCustomComboBoxClass(WidgetSetClass).GetSelStart(Self);
Result:=fSelStart; Result := FSelStart;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -331,7 +333,7 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomComboBox.SetSelStart(Val : integer); procedure TCustomComboBox.SetSelStart(Val : integer);
begin begin
fSelStart:=Val; FSelStart := Val;
if HandleAllocated then if HandleAllocated then
TWSCustomComboBoxClass(WidgetSetClass).SetSelStart(Self, Val); TWSCustomComboBoxClass(WidgetSetClass).SetSelStart(Self, Val);
end; end;
@ -346,8 +348,8 @@ end;
function TCustomComboBox.GetSelLength : integer; function TCustomComboBox.GetSelLength : integer;
begin begin
if HandleAllocated then if HandleAllocated then
fSelLength := TWSCustomComboBoxClass(WidgetSetClass).GetSelLength(Self); FSelLength := TWSCustomComboBoxClass(WidgetSetClass).GetSelLength(Self);
Result:=fSelLength; Result := FSelLength;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -359,7 +361,7 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomComboBox.SetSelLength(Val : integer); procedure TCustomComboBox.SetSelLength(Val : integer);
begin begin
fSelLength:=Val; FSelLength := Val;
if HandleAllocated then if HandleAllocated then
TWSCustomComboBoxClass(WidgetSetClass).SetSelLength(Self, Val); TWSCustomComboBoxClass(WidgetSetClass).SetSelLength(Self, Val);
end; end;
@ -376,11 +378,13 @@ var
CurText: String; CurText: String;
begin begin
//debugln('TCustomComboBox.SelectAll '); //debugln('TCustomComboBox.SelectAll ');
if (FStyle in [csDropDown, csSimple]) then begin if (FStyle in [csDropDown, csSimple]) then
CurText:=Text; begin
if (CurText <> '') then begin CurText := Text;
if (CurText <> '') then
begin
SetSelStart(0); SetSelStart(0);
SetSelLength(Length(CurText)); SetSelLength(UTF8Length(CurText));
end; end;
end; end;
end; end;
@ -539,8 +543,8 @@ procedure TCustomComboBox.KeyPress(var Key: char);
begin begin
//Convert character cases if FCharCase is not ecNormalCase //Convert character cases if FCharCase is not ecNormalCase
case FCharCase of case FCharCase of
ecLowerCase: Key := lowerCase(Key); ecLowerCase: Key := LowerCase(Key);
ecUpperCase: Key := upCase(Key); ecUpperCase: Key := UpCase(Key);
end; end;
inherited KeyPress(Key); inherited KeyPress(Key);
end; end;
@ -562,10 +566,10 @@ begin
//AutoSelect when left mouse is clicked for the 1st time after having focus //AutoSelect when left mouse is clicked for the 1st time after having focus
if (Button = mbLeft) then if (Button = mbLeft) then
begin begin
if (FAutoSelect and not FAutoSelected) then if (FAutoSelect and not FAutoSelected) then
begin begin
SelectAll; SelectAll;
if (SelText = Text) then FAutoSelected := True; if (SelText = Text) then FAutoSelected := True;
end; end;
end; end;
end; end;

View File

@ -81,7 +81,7 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCustomEdit.GetSelText : string; function TCustomEdit.GetSelText : string;
begin begin
Result := Copy(Text, SelStart + 1, SelLength) Result := UTF8Copy(Text, SelStart + 1, SelLength)
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -112,11 +112,12 @@ var
OldPos: Integer; OldPos: Integer;
begin begin
OldPos := SelStart; OldPos := SelStart;
OldText:=Text; OldText := Text;
NewText:=LeftStr(OldText,SelStart)+Val NewText := UTF8Copy(OldText, 1, SelStart) +
+RightStr(OldText,length(OldText)-SelStart-SelLength); Val +
Text:=NewText; UTF8Copy(OldText, UTF8Length(OldText) - SelStart - SelLength, MaxInt);
SelStart := OldPos + Length(Val); Text := NewText;
SelStart := OldPos + UTF8Length(Val);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -185,9 +186,10 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomEdit.SelectAll; procedure TCustomEdit.SelectAll;
begin begin
if Text <> '' then begin if Text <> '' then
begin
SetSelStart(0); SetSelStart(0);
SetSelLength(Length(Text)); SetSelLength(UTF8Length(Text));
end; end;
end; end;
@ -368,7 +370,7 @@ end;
procedure TCustomEdit.RealSetText(const Value: TCaption); procedure TCustomEdit.RealSetText(const Value: TCaption);
begin begin
if (MaxLength > 0) and (Length(Value) > MaxLength) then if (MaxLength > 0) and (Length(Value) > MaxLength) then
inherited RealSetText(Copy(Value, 1, MaxLength)) inherited RealSetText(UTF8Copy(Value, 1, MaxLength))
else else
inherited RealSetText(Value); inherited RealSetText(Value);
end; end;