trichview.com

trichview.support




Re: Display line numbers on the left (or right)


Return to index


Author

Message

Sergey Tkachenko

Posted: 06/04/2005 19:02:08


There is no good solution for this.

If you need to number paragraphs, you can use standard paragraph numbering.

But lines and paragraphs are the same only without line wrapping.


Below is the code drawing line numbers on the left margin using

RVStyle.OnDrawStyleText.

It uses undocumented properties (RVData.DrawItems).

And it has problems:

- unefficient (GetLineNo contains calculations)

- draws numbers only for lines started from text items


This code assumes that line numbers are drawn in RichViewEdit1.



procedure TForm3.RVStyle1DrawStyleText(Sender: TRVStyle; const s: String;

  Canvas: TCanvas; StyleNo, SpaceBefore, Left, Top, Width, Height: Integer;

  DrawState: TRVTextDrawStates; var DoDefault: Boolean);

var DrawItemNo, DrawItemOffs, LineNo: Integer;

    OldFont: TFont;

    BrushColor: TColor;

    BrushStyle: TBrushStyle;

begin

  if Sender.RVData<>RichViewEdit1.RVData then

    exit;

  if (rvtsDrawItemStart in DrawState) then begin

    TCustomRVFormattedData(Sender.RVData).Item2DrawItem(

      Sender.ItemNo, Sender.OffsetInItem, DrawItemNo, DrawItemOffs);

    if

TCustomRVFormattedData(Sender.RVData).DrawItems[DrawItemNo].FromNewLine then

begin

      LineNo :=

TCustomRVFormattedData(Sender.RVData).GetLineNo(Sender.ItemNo,

Sender.OffsetInItem);

      OldFont := TFont.Create;

      // storing font

      OldFont.Assign(Canvas.Font);

      BrushColor := Canvas.Brush.Color;

      BrushStyle := Canvas.Brush.Style;

      // making new font

      Canvas.Font.Name := 'Courier New';

      Canvas.Font.Style := [fsBold];

      Canvas.Font.Size := 8;

      Canvas.Font.Charset := ANSI_CHARSET;

      Canvas.Font.Color := clWindowText;

      Canvas.Brush.Style := bsClear;

      // drawing

      Canvas.TextOut(2-RichViewEdit1.HScrollPos, Top, IntToStr(LineNo));

      // resoring font

      Canvas.Brush.Color := BrushColor;

      Canvas.Brush.Style := BrushStyle;

      Canvas.Font.Assign(OldFont);

      OldFont.Free;

    end;

  end;

end;




>

> Hi

>

> I would like to know, if there is a quick and good way to display the

lines

> number for each line on the left or right side just like the way a

"normal"

> Texteditor does. Maybe a small piece of code for example would be nice.

>

> regards

> Mirko G�rgen





Powered by ABC Amber Outlook Express Converter