mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 07:42:59 +02:00
customdrawn: TCDEdit: Advances the support for moving the caret to the right
git-svn-id: trunk@33216 -
This commit is contained in:
parent
2ce733728d
commit
194bd3d594
@ -215,7 +215,6 @@ type
|
|||||||
|
|
||||||
TCDEditDrawer = class(TCDControlDrawer)
|
TCDEditDrawer = class(TCDControlDrawer)
|
||||||
public
|
public
|
||||||
function GetVisibleCharCount(CDEdit: TCDEdit): Integer; virtual;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@
|
{@@
|
||||||
@ -604,12 +603,12 @@ end;
|
|||||||
|
|
||||||
function TCDControlDrawer.GetMeasures(AMeasureID: Integer): Integer;
|
function TCDControlDrawer.GetMeasures(AMeasureID: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCDControlDrawer.GetColor(AColorID: Integer): TColor;
|
function TCDControlDrawer.GetColor(AColorID: Integer): TColor;
|
||||||
begin
|
begin
|
||||||
|
Result := clBlack;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCDControlDrawer.DrawToIntfImage(ADest: TFPImageCanvas;
|
procedure TCDControlDrawer.DrawToIntfImage(ADest: TFPImageCanvas;
|
||||||
@ -623,35 +622,6 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCDEditDrawer }
|
|
||||||
|
|
||||||
function TCDEditDrawer.GetVisibleCharCount(CDEdit: TCDEdit): Integer;
|
|
||||||
var
|
|
||||||
lMaxWidth: Integer;
|
|
||||||
lText, lLastSearchedText: String;
|
|
||||||
begin
|
|
||||||
{ lText := CDEdit.Text;
|
|
||||||
lText := Copy(lText, CDEdit.FVisibleTextStart, Length(lText));
|
|
||||||
lMaxWidth := CDEdit.Width - GetMeasures(TCDEDIT_LEFT_TEXT_SPACING)
|
|
||||||
- GetMeasures(TCDEDIT_RIGHT_TEXT_SPACING);
|
|
||||||
|
|
||||||
// First the simplest case: less chars are to the right then the width of the control
|
|
||||||
if CDEdit.Canvas.TextWidth(lText) <= lMaxWidth then Exit(Length(lText));
|
|
||||||
|
|
||||||
// Now the more complex case
|
|
||||||
lLastSearchedText := '';
|
|
||||||
while lLastSearchedText <> lText do
|
|
||||||
begin
|
|
||||||
lLastSearchedText := lText;
|
|
||||||
lTextWidth := CDEdit.Canvas.TextWidth(lText);
|
|
||||||
if lTextWidth < lMaxWidth then
|
|
||||||
lText := Copy(lLastSearchedText, 1, Length(lLastSearchedText) div 2)
|
|
||||||
else if lTextWidth > lMaxWidth then
|
|
||||||
lText := Copy(lLastSearchedText, 1, Length(lLastSearchedText) div 2)
|
|
||||||
else Exit(Length(lText));
|
|
||||||
end;}
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCDListView }
|
{ TCDListView }
|
||||||
|
|
||||||
procedure TCDListView.PrepareCurrentDrawer;
|
procedure TCDListView.PrepareCurrentDrawer;
|
||||||
@ -753,14 +723,19 @@ end;
|
|||||||
|
|
||||||
procedure TCDEdit.DoManageVisibleTextStart;
|
procedure TCDEdit.DoManageVisibleTextStart;
|
||||||
var
|
var
|
||||||
lTextWidth: Integer;
|
lText: String;
|
||||||
|
lVisibleTextCharCount: Integer;
|
||||||
|
lAvailableWidth: Integer;
|
||||||
begin
|
begin
|
||||||
// Moved to the left and we need to adjust the text start
|
// Moved to the left and we need to adjust the text start
|
||||||
FVisibleTextStart := Min(FCaretPos+1, FVisibleTextStart);
|
FVisibleTextStart := Min(FCaretPos+1, FVisibleTextStart);
|
||||||
|
|
||||||
// Moved to the right and we need to adjust the text start
|
// Moved to the right and we need to adjust the text start
|
||||||
// lTextWidth := TCDEditDrawer(FCurrentDrawer).GetVisibleCharCount(Self);
|
lText := Copy(Text, FVisibleTextStart, Length(Text));
|
||||||
// FVisibleTextStart := Max(FCaretPos-lTextWidth, FVisibleTextStart);
|
lAvailableWidth := Width - FCurrentDrawer.GetMeasures(TCDEDIT_LEFT_TEXT_SPACING)
|
||||||
|
- FCurrentDrawer.GetMeasures(TCDEDIT_RIGHT_TEXT_SPACING);
|
||||||
|
lVisibleTextCharCount := Canvas.TextFitInfo(lText, lAvailableWidth);
|
||||||
|
FVisibleTextStart := Max(FCaretPos-lVisibleTextCharCount, FVisibleTextStart);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCDEdit.PrepareCurrentDrawer;
|
procedure TCDEdit.PrepareCurrentDrawer;
|
||||||
|
Loading…
Reference in New Issue
Block a user