unit MemoEx;
{...}
implementation
{...}
function CountVisibleLines(
const Memo: TMemo): Integer;
var
OldFont: HFont;
DC: THandle;
TextMetric: TTextMetric;
begin
Result := 0;
DC := GetDC(Memo.Handle);
try
OldFont := SelectObject(
DC, Memo.Font.Handle);
try
GetTextMetrics(
DC, TextMetric);
Result := (Memo.ClientRect.Bottom - Memo.ClientRect.Top)
div
(TextMetric.tmHeight + TextMetric.tmExternalLeading);
finally
SelectObject(
DC, OldFont);
end;
finally
ReleaseDC(Memo.Handle,
DC);
end;
end;
procedure CalcRect(
var R: TRect; aScrollBars: TScrollStyle);
begin
if aScrollBars = ssBoth
then
begin
R.Right := R.Right - GetSystemMetrics(SM_CYVSCROLL);
R.Bottom := R.Bottom - GetSystemMetrics(SM_CYHSCROLL);
end else
if aScrollBars = ssHorizontal
then
begin
R.Bottom := R.Bottom - GetSystemMetrics(SM_CYHSCROLL);
end else
if aScrollBars = ssVertical
then
R.Right := R.Right - GetSystemMetrics(SM_CYVSCROLL);
end;
procedure TMemoEx.WMPaint(
var Msg: TWMPaint);
var
canv: Tcanvas;
r: trect;
i, h, y: Integer;
FirstVisibleLine,
VisibleLines: Integer;
begin
inherited;
canv := tcanvas.Create;
canv.Handle := GetWindowDC(
Handle);
r := ClientRect;
if self.BorderStyle = bsSingle
then
begin
r.Top := +GetSystemmetrics(SM_CXEDGE);
r.Left := +GetSystemmetrics(SM_CXEDGE);
r.Bottom := r.Bottom + GetSystemmetrics(SM_CXEDGE);
end;
FirstVisibleLine := SendMessage(self.Handle, EM_GETFIRSTVISIBLELINE, 0, 0);
VisibleLines := CountVisibleLines(Self);
with canv
do
begin
r.Right := FGutterSize;
brush.Color := clbtnface;
if FGutterType = gtLine
then
begin
brush.Color := clWindow;
pen.Color := cl3DDkShadow;
canv.MoveTo(r.Right - 2, r.Top);
canv.LineTo(r.Right - 2, r.Bottom);
end else
begin
FillRect(r);
Frame3D(canv, r, clBtnHighlight, clBtnShadow, 1);
end;
Font := self.Font;
Font.Color := clBtnText;
if self.Lines.Count < VisibleLines
then h := self.Lines.Count
else h := FirstVisibleLine + (VisibleLines - 1);
y := 0;
for i := FirstVisibleLine
to h
do
begin
TextOut(r.Left + 8, r.Top + (y * textheight('
X')),
format('
%4.4d', [i + 1]));
inc(y);
end;
end;
canv.Free;
end;
{...}