EControl Ltd. Forum Index EControl Ltd.
VCL libraries and software support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Custom highlighting using OnGetStyleEntry event

 
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor
View previous topic :: View next topic  
Author Message
econtrol
Site Admin


Joined: 09 Jun 2006
Posts: 202

PostPosted: Fri Jun 16, 2006 10:40 am    Post subject: Custom highlighting using OnGetStyleEntry event Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group