econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Fri Jun 16, 2006 10:40 am Post subject: Custom highlighting using OnGetStyleEntry event |
|
|
OnGetStyleEntry allows to perform any lexer independent highlighting.
Code: | property OnGetStyleEntry: TGetStyleEntryEvent;
TGetStyleEntryEvent = procedure(Sender: TObject; CurPos: integer;
StyleList: TList; var NextPos: integer) of object; |
Example below shows how to highlight all text after any specified position (OFFSET). To test this example add this code to EditFrm.pas of the main demo and assign this handler to EditorMaster.OnGetStyleEntry.
Code: | procedure TEditorFrame.EditorMasterGetStyleEntry(Sender: TObject;
CurPos: Integer; StyleList: TList; var NextPos: Integer);
const OFFSET = 20;
var p: TPoint;
L: integer;
begin
with EditorMaster do
begin
p := StrPosToCaretPos(CurPos);
L := Lines.LineLength(p.Y);
if (p.X >= OFFSET) and (p.X < L) then
begin
NextPos := CurPos + L - p.X;
StyleList.Add(TStyleEntry.Create(HyperlinkHighlighter1.Style,
CurPos + L - OFFSET, NextPos));
end else
begin
p.X := 20;
while (p.Y < Lines.Count) and (Lines.LineLength(p.Y) < OFFSET) do
Inc(p.Y);
if p.Y = Lines.Count then NextPos := -1
else NextPos := CaretPosToStrPos(p);
end;
end;
end; |
Insteed of HyperlinkHighlighter1.Style you may use any style from any storage.
Michael. |
|