SynEdit, fix drawing of Frame-Highlights

git-svn-id: trunk@18071 -
This commit is contained in:
martin 2009-01-03 02:00:34 +00:00
parent d5955b6de5
commit 6e84e44ae3
9 changed files with 73 additions and 12 deletions

View File

@ -3085,6 +3085,8 @@ var
' "',copy(TokenAccu.s,1,TokenAccu.Len),'"');}
end;
var
LastFSX, LastFEX: integer;
procedure DrawHiLightMarkupToken(attr: TSynHighlighterAttributes;
sToken: PChar; nTokenByteLen: integer);
var
@ -3185,6 +3187,20 @@ var
else FG := DefaultBGCol;
end;
if assigned(MarkupInfo) and
((MarkupInfo.StartX <> LastFSX) or (MarkupInfo.EndX <> LastFEX)) and
((TokenAccu.FC <> clNone) or (FC <> clNone))
then begin
// force Paint
PaintHighlightToken(FALSE);
TokenAccu.Len := 0;
// Set Frame Boundaries
LastFSX := MarkupInfo.StartX;
LastFEX := MarkupInfo.EndX;
FTextDrawer.FrameStartX := ScreenColumnToXValue(MarkupInfo.StartX);
FTextDrawer.FrameEndX := ScreenColumnToXValue(MarkupInfo.EndX+1);
end;
// Add to TokenAccu
AddHighlightToken(sToken, SubTokenByteLen,
PhysicalStartPos, PhysicalEndPos, FG, BG, FC, Style);
@ -3218,6 +3234,10 @@ var
CurLine := FirstLine-1;
while CurLine<LastLine do begin
inc(CurLine);
FTextDrawer.FrameStartX := -1;
FTextDrawer.FrameEndX := -1;
LastFSX := -1;
LastFEX := -1;
fMarkupManager.PrepareMarkupForRow(fTextView.TextIndex[CurLine]+1);
// Get the line.

View File

@ -370,6 +370,11 @@ begin
sMask := c.StyleMask + (fsNot(c.StyleMask) * c.Style); // Styles to be taken from c
Result.Style:= (Result.Style * fsNot(sMask)) + (c.Style * sMask);
Result.StyleMask:= (Result.StyleMask * fsNot(sMask)) + (c.StyleMask * sMask);
if c.FrameColor <> clNone then begin
// Only frames need start/end info => copy *here* to separate fields if needed
Result.StartX := C.StartX;
Result.EndX := C.EndX;
end;
end;
end;
end;

View File

@ -213,7 +213,11 @@ begin
Result := nil;
if ((FBracketHighlightPos.y = aRow) and (FBracketHighlightPos.x = aCol))
or ((FBracketHighlightAntiPos.y = aRow) and (FBracketHighlightAntiPos.x = aCol))
then Result := MarkupInfo;
then begin
Result := MarkupInfo;
MarkupInfo.StartX := aCol;
MarkupInfo.EndX := aCol;
end;
end;
function TSynEditMarkupBracket.GetNextMarkupColAfterRowCol(const aRow, aCol: Integer) : Integer;

View File

@ -99,6 +99,8 @@ begin
if (aRow <> FCtrlMouseLine) or ((aCol < FCurX1) or (aCol >= FCurX2))
then exit;
Result := MarkupInfo;
MarkupInfo.StartX := FCurX1;
MarkupInfo.EndX := FCurX2;
end;
function TSynEditMarkupCtrlMouseLink.GetNextMarkupColAfterRowCol(const aRow, aCol: Integer) : Integer;

View File

@ -482,6 +482,14 @@ begin
then exit;
//debugLN('+++>MARUP *ON* ',dbgs(@result),' / ',dbgs(ARow), ' at index ', dbgs(Pos));
if fMatches.Point[Pos-1].y < aRow then
MarkupInfo.StartX := -1
else
MarkupInfo.StartX := fMatches.Point[Pos-1].x;
if fMatches.Point[Pos].y > aRow then
MarkupInfo.EndX := -1
else
MarkupInfo.EndX := fMatches.Point[Pos].x-1;
result := MarkupInfo;
end;

View File

@ -129,6 +129,8 @@ begin
then nSelEnd := p2.x;
end;
end;
MarkupInfo.StartX := nSelStart;
MarkupInfo.EndX := nSelEnd;
end;
function TSynEditMarkupSelection.GetMarkupAttributeAtRowCol(const aRow, aCol : Integer) : TSynSelectedColor;

View File

@ -177,6 +177,8 @@ end;
function TSynEditMarkupSpecialLine.GetMarkupAttributeAtRowCol(const ARow, ACol : Integer): TSynSelectedColor;
begin
Result := nil;
MarkupInfo.StartX := -1;
MarkupInfo.EndX := -1;
if FSpecialLine then
Result := MarkupInfo;
end;

View File

@ -67,6 +67,8 @@ type
// StyleMask = 0 => Invert where Style Bit = 1
FStyleMask: TFontStyles;
FOnChange: TNotifyEvent;
// 0 or -1 start/end before/after line // 1 first char
FStartX, FEndX: Integer;
procedure SetBG(Value: TColor);
procedure SetFG(Value: TColor);
procedure SetFrameColor(const AValue: TColor);
@ -86,6 +88,8 @@ type
property FrameColor: TColor read FFrameColor write SetFrameColor default clNone;
property Style: TFontStyles read FStyle write SetStyle default [];
property StyleMask: TFontStyles read fStyleMask write SetStyleMask default [];
property StartX: Integer read FStartX write FStartX;
property EndX: Integer read FEndX write FEndX;
property OnChange: TNotifyEvent read fOnChange write fOnChange;
end;
@ -286,6 +290,8 @@ begin
FFrameColor := Source.FFrameColor;
FStyle := Source.FStyle;
FStyleMask := Source.FStyleMask;
FStartX := Source.FStartX;
FEndX := Source.FEndX;
DoChange; {TODO: only if really changed}
end;
end;
@ -297,6 +303,8 @@ begin
FFrameColor := clNone;
FStyle := [];
FStyleMask := [];
FStartX := -1;
FEndX := -1;
end;
function TSynSelectedColor.IsEnabled: boolean;

View File

@ -211,6 +211,7 @@ type
FColor: TColor;
FBkColor: TColor;
FFrameColor: TColor;
FFrameStartX, FFrameEndX: Integer;
FCharExtra: Integer;
// Begin/EndDrawing calling count
@ -256,6 +257,9 @@ type
property ForeColor: TColor write SetForeColor;
property BackColor: TColor write SetBackColor;
property FrameColor: TColor write SetFrameColor;
property FrameStartX: Integer read FFrameStartX write FFrameStartX;
property FrameEndX: Integer read FFrameEndX write FFrameEndX;
property Style: TFontStyles write SetStyle;
property CharExtra: Integer read FCharExtra write SetCharExtra;
{$IFDEF SYN_LAZARUS}
@ -1217,7 +1221,7 @@ var
NeedDistArray: Boolean;
DistArray: PInteger;
Pen, OldPen: HPen;
Points: array[0..4] of TPoint;
old : TPoint;
begin
{$IFDEF SYN_LAZARUS}
NeedDistArray:= (FCharExtra > 0) or not MonoSpace;
@ -1241,18 +1245,24 @@ begin
{$ENDIF}
if FFrameColor <> clNone then
begin
with ARect do
begin
Points[0] := TopLeft;
Points[1] := Point(Right - 1, Top);
Points[2] := Point(Right - 1, Bottom - 1);
Points[3] := Point(Left, Bottom - 1);
Points[4] := TopLeft;
end;
Pen := CreateColorPen(FFrameColor);
OldPen := SelectObject(FDC, Pen);
Polyline(FDC, @Points, 5);
MoveToEx(FDC, ARect.Left, ARect.Top, @old);
if ARect.Right = FFrameEndX then begin
LineTo(FDC, ARect.Right-1, ARect.Top);
LineTo(FDC, ARect.Right-1, ARect.Bottom-1);
end else begin
// Last point of the line may not be drawn, so paint one more
LineTo(FDC, ARect.Right, ARect.Top);
MoveToEx(FDC, ARect.Right-1, ARect.Bottom-1, @old);
end;
if ARect.Left = FFrameStartX then begin
LineTo(FDC, ARect.Left, ARect.Bottom-1);
LineTo(FDC, ARect.Left, ARect.Top);
end else begin
MoveToEx(FDC, ARect.Left, ARect.Bottom-1, @old);
LineTo(FDC, ARect.Right, ARect.Bottom-1);
end;
DeleteObject(SelectObject(FDC, OldPen));
end;
end;