mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 04:02:45 +02:00
customdrawn: UTF-8 fixes for TCDEdit
git-svn-id: trunk@33273 -
This commit is contained in:
parent
038fb195c1
commit
d1616cf968
@ -7,6 +7,8 @@ interface
|
||||
uses
|
||||
// RTL
|
||||
Classes, SysUtils, Types,
|
||||
// LazUtils
|
||||
lazutf8,
|
||||
// LCL -> Use only TForm, TWinControl, TCanvas and TLazIntfImage
|
||||
Graphics, Controls, LCLType,
|
||||
// Others only for types
|
||||
@ -88,14 +90,12 @@ var
|
||||
ATabsStateEx: TCDCTabControlStateEx absolute AStateEx;
|
||||
lCaption: String;
|
||||
begin
|
||||
ADest.Font.Assign(AStateEx.Font);
|
||||
|
||||
case AMeasureID of
|
||||
TCDCONTROL_CAPTION_WIDTH: Result := ADest.TextWidth(AStateEx.Caption);
|
||||
TCDCONTROL_CAPTION_HEIGHT: Result := ADest.TextHeight('ŹÇ')+3;
|
||||
TCDCTABCONTROL_TAB_HEIGHT:
|
||||
begin
|
||||
if AStateEx.Font.Size = 0 then Result := ADest.TextHeight('Z')+14
|
||||
else Result := AStateEx.Font.Size + 14;
|
||||
end;
|
||||
TCDCTABCONTROL_TAB_HEIGHT: Result := ADest.TextHeight('ŹÇ')+10;
|
||||
TCDCTABCONTROL_TAB_WIDTH:
|
||||
begin
|
||||
lCaption := ATabsStateEx.Tabs.Strings[ATabsStateEx.CurTabIndex];
|
||||
@ -115,6 +115,16 @@ begin
|
||||
PreferredHeight := 0;
|
||||
|
||||
case AControlId of
|
||||
cidEdit:
|
||||
begin
|
||||
{ if AStateEx.AutoSize then
|
||||
PreferredWidth :=
|
||||
TCDEDIT_LEFT_TEXT_SPACING: Result := 4;
|
||||
TCDEDIT_RIGHT_TEXT_SPACING: Result := 3;
|
||||
+ GetMeasuresEx(ADest, TCDCONTROL_CAPTION_WIDTH, AState, AStateEx);}
|
||||
|
||||
PreferredHeight := GetMeasuresEx(ADest, TCDCONTROL_CAPTION_HEIGHT, AState, AStateEx)+5;
|
||||
end;
|
||||
cidCheckBox:
|
||||
begin
|
||||
if AStateEx.AutoSize then
|
||||
@ -261,17 +271,19 @@ var
|
||||
lHeight: Integer;
|
||||
lSelLeftPos, lSelLeftPixelPos, lSelLength, lSelRightPos: Integer;
|
||||
lTextWidth: Integer;
|
||||
lControlTextLen: PtrInt;
|
||||
begin
|
||||
DrawEditBackground(ADest, ADestPos, ASize, AState, AStateEx);
|
||||
|
||||
lControlText := AStateEx.Caption;
|
||||
lControlTextLen := UTF8Length(AStateEx.Caption);
|
||||
ADest.Brush.Style := bsClear;
|
||||
ADest.Font.Assign(AStateEx.Font);
|
||||
|
||||
// The text without selection
|
||||
if AStateEx.SelLength = 0 then
|
||||
begin
|
||||
lVisibleText := Copy(lControlText, AStateEx.VisibleTextStart, Length(lControlText));
|
||||
lVisibleText := UTF8Copy(lControlText, AStateEx.VisibleTextStart, lControlTextLen);
|
||||
ADest.TextOut(4, 1, lVisibleText);
|
||||
end
|
||||
// Text and Selection
|
||||
@ -285,12 +297,12 @@ begin
|
||||
if lSelLength < 0 then lSelLength := lSelLength * -1;
|
||||
|
||||
// Text left of the selection
|
||||
lVisibleText := Copy(lControlText, AStateEx.VisibleTextStart, lSelLeftPos-AStateEx.VisibleTextStart);
|
||||
lVisibleText := UTF8Copy(lControlText, AStateEx.VisibleTextStart, lSelLeftPos-AStateEx.VisibleTextStart);
|
||||
ADest.TextOut(4, 1, lVisibleText);
|
||||
lSelLeftPixelPos := ADest.TextWidth(lVisibleText)+4;
|
||||
|
||||
// The selection background
|
||||
lVisibleText := Copy(lControlText, lSelLeftPos, lSelLength);
|
||||
lVisibleText := UTF8Copy(lControlText, lSelLeftPos, lSelLength);
|
||||
lTextWidth := ADest.TextWidth(lVisibleText);
|
||||
ADest.Brush.Color := clBlue;
|
||||
ADest.Brush.Style := bsSolid;
|
||||
@ -305,14 +317,14 @@ begin
|
||||
// Text right of the selection
|
||||
ADest.Brush.Color := clWhite;
|
||||
ADest.Font.Color := AStateEx.Font.Color;
|
||||
lVisibleText := Copy(lControlText, lSelLeftPos+lSelLength+1, Length(lControlText));
|
||||
lVisibleText := UTF8Copy(lControlText, lSelLeftPos+lSelLength+1, lControlTextLen);
|
||||
ADest.TextOut(lSelLeftPixelPos, 1, lVisibleText);
|
||||
end;
|
||||
|
||||
// And the caret
|
||||
if AStateEx.CaretIsVisible then
|
||||
begin
|
||||
lTmpText := Copy(lControlText, 1, AStateEx.CaretPos-AStateEx.VisibleTextStart+1);
|
||||
lTmpText := UTF8Copy(lControlText, 1, AStateEx.CaretPos-AStateEx.VisibleTextStart+1);
|
||||
lCaretPixelPos := ADest.TextWidth(lTmpText) + 3;
|
||||
lHeight := ASize.cy;
|
||||
ADest.Line(lCaretPixelPos, 2, lCaretPixelPos, lHeight-2);
|
||||
|
@ -16,10 +16,10 @@ interface
|
||||
uses
|
||||
// FPC
|
||||
Classes, SysUtils, contnrs, Math, types,
|
||||
// fpimage
|
||||
fpcanvas, fpimgcanv, fpimage,
|
||||
// LazUtils
|
||||
lazutf8,
|
||||
// LCL -> Use only TForm, TWinControl, TCanvas, TLazIntfImage
|
||||
Graphics, Controls, LCLType, LCLIntf, IntfGraphics,
|
||||
Graphics, Controls, LCLType, LCLIntf,
|
||||
LMessages, Messages, LCLProc, Forms,
|
||||
// Other LCL units are only for types
|
||||
StdCtrls, ExtCtrls, ComCtrls,
|
||||
@ -451,7 +451,7 @@ begin
|
||||
FEditState.VisibleTextStart := Min(FEditState.CaretPos+1, FEditState.VisibleTextStart);
|
||||
|
||||
// Moved to the right and we need to adjust the text start
|
||||
lText := Copy(Text, FEditState.VisibleTextStart, Length(Text));
|
||||
lText := UTF8Copy(Text, FEditState.VisibleTextStart, Length(Text));
|
||||
lAvailableWidth := Width
|
||||
- FDrawer.GetMeasures(TCDEDIT_LEFT_TEXT_SPACING)
|
||||
- FDrawer.GetMeasures(TCDEDIT_RIGHT_TEXT_SPACING);
|
||||
@ -485,10 +485,12 @@ end;
|
||||
procedure TCDEdit.KeyDown(var Key: word; Shift: TShiftState);
|
||||
var
|
||||
lLeftText, lRightText, lOldText: String;
|
||||
lOldTextLength: PtrInt;
|
||||
begin
|
||||
inherited KeyDown(Key, Shift);
|
||||
|
||||
lOldText := Text;
|
||||
lOldTextLength := UTF8Length(Text);
|
||||
|
||||
case Key of
|
||||
// Backspace
|
||||
@ -500,8 +502,8 @@ begin
|
||||
// Normal backspace
|
||||
else if FEditState.CaretPos > 0 then
|
||||
begin
|
||||
lLeftText := Copy(lOldText, 1, FEditState.CaretPos-1);
|
||||
lRightText := Copy(lOldText, FEditState.CaretPos+1, Length(lOldText));
|
||||
lLeftText := UTF8Copy(lOldText, 1, FEditState.CaretPos-1);
|
||||
lRightText := UTF8Copy(lOldText, FEditState.CaretPos+1, lOldTextLength);
|
||||
Text := lLeftText + lRightText;
|
||||
Dec(FEditState.CaretPos);
|
||||
DoManageVisibleTextStart();
|
||||
@ -515,10 +517,10 @@ begin
|
||||
if FEditState.SelLength > 0 then
|
||||
DoDeleteSelection()
|
||||
// Normal delete
|
||||
else if FEditState.CaretPos < Length(lOldText) then
|
||||
else if FEditState.CaretPos < lOldTextLength then
|
||||
begin
|
||||
lLeftText := Copy(lOldText, 1, FEditState.CaretPos);
|
||||
lRightText := Copy(lOldText, FEditState.CaretPos+2, Length(lOldText));
|
||||
lLeftText := UTF8Copy(lOldText, 1, FEditState.CaretPos);
|
||||
lRightText := UTF8Copy(lOldText, FEditState.CaretPos+2, lOldTextLength);
|
||||
Text := lLeftText + lRightText;
|
||||
Invalidate;
|
||||
end;
|
||||
@ -544,7 +546,7 @@ begin
|
||||
end;
|
||||
VK_RIGHT:
|
||||
begin
|
||||
if FEditState.CaretPos < Length(lOldText) then
|
||||
if FEditState.CaretPos < lOldTextLength then
|
||||
begin
|
||||
// Selecting to the right
|
||||
if ssShift in Shift then
|
||||
@ -584,8 +586,8 @@ begin
|
||||
|
||||
// Normal characters
|
||||
lOldText := Text;
|
||||
lLeftText := Copy(lOldText, 1, FEditState.CaretPos);
|
||||
lRightText := Copy(lOldText, FEditState.CaretPos+1, Length(lOldText));
|
||||
lLeftText := UTF8Copy(lOldText, 1, FEditState.CaretPos);
|
||||
lRightText := UTF8Copy(lOldText, FEditState.CaretPos+1, UTF8Length(lOldText));
|
||||
Text := lLeftText + UTF8Key + lRightText;
|
||||
Inc(FEditState.CaretPos);
|
||||
FEditState.CaretIsVisible := True;
|
||||
|
Loading…
Reference in New Issue
Block a user