synedit: add a special color for current line highlighting, reorder markups to make more priority of brackets highlight

git-svn-id: trunk@17523 -
This commit is contained in:
paul 2008-11-22 17:44:11 +00:00
parent d6f552defe
commit 6c27b28a2d
2 changed files with 77 additions and 3 deletions

View File

@ -519,6 +519,7 @@ type
function GetCaretY : Integer;
function GetHighlightAllColor : TSynSelectedColor;
function GetIncrementColor : TSynSelectedColor;
function GetLineHighlightColor: TSynSelectedColor;
function GetLineNumberColor: TSynSelectedColor;
function GetSelectedColor : TSynSelectedColor;
function GetBracketMatchColor : TSynSelectedColor;
@ -978,6 +979,7 @@ type
property BracketMatchColor: TSynSelectedColor read GetBracketMatchColor;
property MouseLinkColor: TSynSelectedColor read GetMouseLinkColor;
property LineNumberColor: TSynSelectedColor read GetLineNumberColor;
property LineHighlightColor: TSynSelectedColor read GetLineHighlightColor;
//property Color: TSynSelectedColor read GetSelectedColor;
{$ELSE}
property SelectedColor: TSynSelectedColor
@ -1120,6 +1122,7 @@ type
property BracketMatchColor;
property MouseLinkColor;
property LineNumberColor;
property LineHighlightColor;
{$ENDIF}
property SelectionMode;
property TabWidth;
@ -1529,9 +1532,9 @@ begin
fMarkupManager := TSynEditMarkupManager.Create(self);
fMarkupManager.AddMarkUp(fMarkupHighAll);
fMarkupManager.AddMarkUp(fMarkupBracket);
fMarkupManager.AddMarkUp(fMarkupCtrlMouse);
fMarkupManager.AddMarkUp(fMarkupSpecialLine);
fMarkupManager.AddMarkUp(fMarkupBracket);
fMarkupManager.AddMarkUp(fMarkupSelection);
fMarkupManager.Lines := TSynEditStrings(Lines);
fMarkupManager.InvalidateLinesMethod := @InvalidateLines;
@ -1668,8 +1671,12 @@ begin
UpdateScrollbars;
if sfCaretChanged in fStateFlags then
UpdateCaret
else if not(sfPainting in fStateFlags) and assigned(fMarkupBracket)
then fMarkupBracket.InvalidateBracketHighlight;
else
if not(sfPainting in fStateFlags) and assigned(fMarkupBracket) then
begin
fMarkupBracket.InvalidateBracketHighlight;
fMarkupSpecialLine.InvalidateLineHighlight;
end;
if fStatusChanges <> [] then
DoOnStatusChange(fStatusChanges);
end;
@ -1796,6 +1803,11 @@ begin
result := fMarkupSelection.MarkupInfoIncr;
end;
function TCustomSynEdit.GetLineHighlightColor: TSynSelectedColor;
begin
Result := fMarkupSpecialLine.MarkupLineHighlightInfo;
end;
function TCustomSynEdit.GetLineNumberColor: TSynSelectedColor;
begin
Result := fGutter.MarkupInfoLineNumber;
@ -5638,6 +5650,7 @@ begin
Include(fStateFlags, sfCaretChanged);
{$IFDEF SYN_LAZARUS}
if assigned(fMarkupBracket) then fMarkupBracket.InvalidateBracketHighlight;
if assigned(fMarkupSpecialLine) then fMarkupSpecialLine.InvalidateLineHighlight;
{$ENDIF}
end else begin
Exclude(fStateFlags, sfCaretChanged);
@ -5670,6 +5683,7 @@ begin
end;
{$IFDEF SYN_LAZARUS}
if assigned(fMarkupBracket) then fMarkupBracket.InvalidateBracketHighlight;
if assigned(fMarkupSpecialLine) then fMarkupSpecialLine.InvalidateLineHighlight;
{$ENDIF}
{$IFDEF SYN_MBCSSUPPORT}
if HandleAllocated then begin

View File

@ -39,16 +39,25 @@ type
TSynEditMarkupSpecialLine = class(TSynEditMarkup)
private
FMarkupLineHighlightInfo: TSynSelectedColor;
FOnSpecialLineColors: TSpecialLineColorsEvent;
FOnSpecialLineMarkup: TSpecialLineMarkupEvent;
FSpecialLine : Boolean;
FHighlightedLine: Integer;
protected
procedure DoMarkupLineHighlightInfoChange(Sender: TObject);
public
constructor Create(ASynEdit: TCustomControl);
destructor Destroy; override;
procedure PrepareMarkupForRow(ARow: Integer); override;
function GetMarkupAttributeAtRowCol(const ARow, ACol: Integer): TSynSelectedColor; override;
function GetNextMarkupColAfterRowCol(const ARow, ACol: Integer): Integer; override;
procedure InvalidateLineHighlight;
property MarkupLineHighlightInfo: TSynSelectedColor read FMarkupLineHighlightInfo;
property OnSpecialLineColors: TSpecialLineColorsEvent
read FOnSpecialLineColors write FOnSpecialLineColors;
property OnSpecialLineMarkup: TSpecialLineMarkupEvent
@ -56,16 +65,38 @@ type
end;
implementation
uses
SynEdit;
{ TSynEditMarkupBracket }
procedure TSynEditMarkupSpecialLine.DoMarkupLineHighlightInfoChange(
Sender: TObject);
begin
if FHighlightedLine > 0 then
InvalidateSynLines(FHighlightedLine, FHighlightedLine);
end;
constructor TSynEditMarkupSpecialLine.Create(ASynEdit: TCustomControl);
begin
inherited Create(ASynEdit);
FHighlightedLine := -1;
FMarkupLineHighlightInfo := TSynSelectedColor.Create;
FMarkupLineHighlightInfo.Background := clNone;
FMarkupLineHighlightInfo.Foreground := clNone;
FMarkupLineHighlightInfo.OnChange := @DoMarkupLineHighlightInfoChange;
MarkupInfo.Style := [];
MarkupInfo.StyleMask := [];
end;
destructor TSynEditMarkupSpecialLine.Destroy;
begin
FMarkupLineHighlightInfo.Free;
inherited Destroy;
end;
procedure TSynEditMarkupSpecialLine.PrepareMarkupForRow(ARow: Integer);
var
colFg, colBg: TColor;
@ -89,6 +120,18 @@ begin
MarkupInfo.Foreground := colFg;
MarkupInfo.Background := colBg;
end;
// if line is not special then check whether it is a current line
// if it is so then use own bg,fg colors to setup highlight
if not FSpecialLine then
begin
if FHighlightedLine = ARow then
begin
FSpecialLine := True;
MarkupInfo.Foreground := FMarkupLineHighlightInfo.Foreground;
MarkupInfo.Background := FMarkupLineHighlightInfo.Background;
end;
end;
end;
function TSynEditMarkupSpecialLine.GetMarkupAttributeAtRowCol(const ARow, ACol : Integer): TSynSelectedColor;
@ -103,5 +146,22 @@ begin
Result := -1; // always valid for the whole line
end;
procedure TSynEditMarkupSpecialLine.InvalidateLineHighlight;
var
NewLine: Integer;
begin
NewLine := TSynEdit(SynEdit).CaretY;
// invalidate old line highlighting, if changed
if (FHighlightedLine > 0) and (NewLine <> FHighlightedLine) then
InvalidateSynLines(FHighlightedLine, FHighlightedLine);
// invalidate new line highlighting, if changed
if (NewLine > 0) and (NewLine <> FHighlightedLine) then
InvalidateSynLines(NewLine, NewLine);
FHighlightedLine := NewLine;
end;
end.