customdrawn: Initial code for TCDEdit to move beyond the right/left borders of the control with the caret

git-svn-id: trunk@33214 -
This commit is contained in:
sekelsenmat 2011-11-02 08:13:29 +00:00
parent 8a21fcc894
commit ee45c154a1
2 changed files with 98 additions and 3 deletions

View File

@ -27,6 +27,8 @@ type
TCDEditDrawerWinCE = class(TCDEditDrawer) TCDEditDrawerWinCE = class(TCDEditDrawer)
public public
function GetMeasures(AMeasureID: Integer): Integer; override;
//function GetColor(AColorID: Integer): TColor; virtual;
procedure DrawToIntfImage(ADest: TFPImageCanvas; CDControl: TCDControl); override; procedure DrawToIntfImage(ADest: TFPImageCanvas; CDControl: TCDControl); override;
procedure DrawToCanvas(ADest: TCanvas; CDControl: TCDControl); override; procedure DrawToCanvas(ADest: TCanvas; CDControl: TCDControl); override;
end; end;
@ -106,6 +108,16 @@ end;
{ TCDEditDrawerWinCE } { TCDEditDrawerWinCE }
function TCDEditDrawerWinCE.GetMeasures(AMeasureID: Integer): Integer;
begin
case AMeasureID of
TCDEDIT_LEFT_TEXT_SPACING: Result := 4;
TCDEDIT_RIGHT_TEXT_SPACING: Result := 3;
else
Result := inherited GetMeasures(AMeasureID);
end;
end;
procedure TCDEditDrawerWinCE.DrawToIntfImage(ADest: TFPImageCanvas; procedure TCDEditDrawerWinCE.DrawToIntfImage(ADest: TFPImageCanvas;
CDControl: TCDControl); CDControl: TCDControl);
begin begin

View File

@ -29,6 +29,9 @@ uses
const const
CDDRAWSTYLE_COUNT = 12; CDDRAWSTYLE_COUNT = 12;
TCDEDIT_LEFT_TEXT_SPACING = $400;
TCDEDIT_RIGHT_TEXT_SPACING = $401;
type type
TCDDrawStyle = ( TCDDrawStyle = (
@ -69,12 +72,16 @@ type
end; end;
TCDControlClass = class of TCDControl; TCDControlClass = class of TCDControl;
{ TCDControlDrawer }
TCDControlDrawer = class TCDControlDrawer = class
public public
function GetClientRect(AControl: TCDControl): TRect; virtual; abstract; function GetClientRect(AControl: TCDControl): TRect; virtual;
function GetMeasures(AMeasureID: Integer): Integer; virtual;
function GetColor(AColorID: Integer): TColor; virtual;
procedure DrawToIntfImage(ADest: TFPImageCanvas; AControl: TCDControl); procedure DrawToIntfImage(ADest: TFPImageCanvas; AControl: TCDControl);
virtual; abstract; virtual;
procedure DrawToCanvas(ADest: TCanvas; AControl: TCDControl); virtual; abstract; procedure DrawToCanvas(ADest: TCanvas; AControl: TCDControl); virtual;
end; end;
// =================================== // ===================================
@ -170,6 +177,7 @@ type
FCaretTimer: TTimer; FCaretTimer: TTimer;
procedure HandleCaretTimer(Sender: TObject); procedure HandleCaretTimer(Sender: TObject);
procedure DoDeleteSelection; procedure DoDeleteSelection;
procedure DoManageVisibleTextStart;
procedure PrepareCurrentDrawer(); override; procedure PrepareCurrentDrawer(); override;
function GetText: string; function GetText: string;
procedure SetText(AValue: string); procedure SetText(AValue: string);
@ -203,8 +211,11 @@ type
property Text: string read GetText write SetText; property Text: string read GetText write SetText;
end; end;
{ TCDEditDrawer }
TCDEditDrawer = class(TCDControlDrawer) TCDEditDrawer = class(TCDControlDrawer)
public public
function GetVisibleCharCount(CDEdit: TCDEdit): Integer; virtual;
end; end;
{@@ {@@
@ -584,6 +595,63 @@ begin
RegisteredCustomTabControlDrawers[AStyle] := ADrawer; RegisteredCustomTabControlDrawers[AStyle] := ADrawer;
end; end;
{ TCDControlDrawer }
function TCDControlDrawer.GetClientRect(AControl: TCDControl): TRect;
begin
Result := AControl.BoundsRect;
end;
function TCDControlDrawer.GetMeasures(AMeasureID: Integer): Integer;
begin
end;
function TCDControlDrawer.GetColor(AColorID: Integer): TColor;
begin
end;
procedure TCDControlDrawer.DrawToIntfImage(ADest: TFPImageCanvas;
AControl: TCDControl);
begin
end;
procedure TCDControlDrawer.DrawToCanvas(ADest: TCanvas; AControl: TCDControl);
begin
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;
@ -683,6 +751,18 @@ begin
FSelLength := 0; FSelLength := 0;
end; end;
procedure TCDEdit.DoManageVisibleTextStart;
var
lTextWidth: Integer;
begin
// Moved to the left and we need to adjust the text start
FVisibleTextStart := Min(FCaretPos+1, FVisibleTextStart);
// Moved to the right and we need to adjust the text start
// lTextWidth := TCDEditDrawer(FCurrentDrawer).GetVisibleCharCount(Self);
// FVisibleTextStart := Max(FCaretPos-lTextWidth, FVisibleTextStart);
end;
procedure TCDEdit.PrepareCurrentDrawer; procedure TCDEdit.PrepareCurrentDrawer;
var var
lDrawStyle: TCDDrawStyle; lDrawStyle: TCDDrawStyle;
@ -739,6 +819,7 @@ begin
lRightText := Copy(lOldText, FCaretPos+1, Length(lOldText)); lRightText := Copy(lOldText, FCaretPos+1, Length(lOldText));
Text := lLeftText + lRightText; Text := lLeftText + lRightText;
Dec(FCaretPos); Dec(FCaretPos);
DoManageVisibleTextStart();
Invalidate; Invalidate;
end; end;
end; end;
@ -771,6 +852,7 @@ begin
else FSelLength := 0; else FSelLength := 0;
Dec(FCaretPos); Dec(FCaretPos);
DoManageVisibleTextStart();
FCaretIsVisible := True; FCaretIsVisible := True;
Invalidate; Invalidate;
end; end;
@ -789,6 +871,7 @@ begin
else FSelLength := 0; else FSelLength := 0;
Inc(FCaretPos); Inc(FCaretPos);
DoManageVisibleTextStart();
FCaretIsVisible := True; FCaretIsVisible := True;
Invalidate; Invalidate;
end; end;