synedit: add FrameStyle to the markup color and highlighter attribute

git-svn-id: trunk@27660 -
This commit is contained in:
paul 2010-10-12 03:20:52 +00:00
parent 5f0b5a99bc
commit 797b544a5e
6 changed files with 147 additions and 56 deletions

View File

@ -3089,6 +3089,7 @@ var
p: PChar;
FG, BG, FC: TColor;
Style: TFontStyles;
FrameStyle: TSynLineStyle;
end;
dc: HDC;
@ -3273,7 +3274,8 @@ var
nX1, eolx: integer;
NextPos : Integer;
MarkupInfo, FoldedCodeInfo: TSynSelectedColor;
FillFCol, FillBCol, FillFrame : TColor;
FillFCol, FillBCol, FillFrame: TColor;
FrameStyle: TSynLineStyle;
FillStyle: TFontStyles;
tok: TRect;
Attr: TSynHighlighterAttributes;
@ -3284,13 +3286,16 @@ var
' "',copy(TokenAccu.p,1,TokenAccu.Len),'"');}
// Any token chars accumulated?
if (TokenAccu.Len > 0) then begin
if (TokenAccu.Len > 0) then
begin
// Initialize the colors and the font style.
with fTextDrawer do begin
with fTextDrawer do
begin
SetBackColor(TokenAccu.BG);
SetForeColor(TokenAccu.FG);
SetFrameColor(TokenAccu.FC);
SetStyle(TokenAccu.Style);
SetFrameStyle(TokenAccu.FrameStyle);
end;
// Paint the chars
rcToken.Right := ScreenColumnToXValue(TokenAccu.PhysicalEndPos+1);
@ -3307,26 +3312,30 @@ var
Attr := fHighlighter.GetEndOfLineAttribute
else
Attr := nil;
Repeat
repeat
MarkupInfo := fMarkupManager.GetMarkupAttributeAtRowCol(FFoldedLinesView.TextIndex[CurLine]+1, NextPos);
NextPos := fMarkupManager.GetNextMarkupColAfterRowCol(FFoldedLinesView.TextIndex[CurLine]+1, NextPos);
if assigned(Attr) then begin
if Assigned(Attr) then
begin
FillFCol := Attr.Foreground;
FillBCol := Attr.Background;
FillFrame := Attr.FrameColor;
FillStyle := Attr.Style;
FrameStyle := Attr.FrameStyle;
if FillFCol = clNone then FillFCol := Font.Color;
if FillBCol = clNone then FillBCol := colEditorBG;
end else begin
end else
begin
FillFCol := Font.Color;
FillBCol := colEditorBG;
FillFrame := clNone;
FillStyle := Font.Style;
FrameStyle := slsSolid;
end;
if assigned(MarkupInfo) then
MarkupInfo.ModifyColors(FillFCol, FillBCol, FillFrame, FillStyle);
if Assigned(MarkupInfo) then
MarkupInfo.ModifyColors(FillFCol, FillBCol, FillFrame, FillStyle, FrameStyle);
fTextDrawer.BackColor := FillBCol;
//fTextDrawer.ForeColor := FillFCol; // for underline
@ -3366,13 +3375,14 @@ var
FillFCol := Font.Color;
FillBCol := colEditorBG;
FillFrame := Font.Color;
FrameStyle := slsSolid;
FillStyle := [];
MarkupInfo := fMarkupManager.GetMarkupAttributeAtRowCol(FFoldedLinesView.TextIndex[CurLine]+1, CurPhysPos + 3);
if MarkupInfo <> nil then
MarkupInfo.ModifyColors(FillFCol, FillBCol, FillFrame, FillStyle);
MarkupInfo.ModifyColors(FillFCol, FillBCol, FillFrame, FillStyle, FrameStyle);
FoldedCodeInfo := FoldedCodeColor;
If assigned(FoldedCodeInfo) then
FoldedCodeInfo.ModifyColors(FillFCol, FillBCol, FillFrame, FillStyle);
if Assigned(FoldedCodeInfo) then
FoldedCodeInfo.ModifyColors(FillFCol, FillBCol, FillFrame, FillStyle, FrameStyle);
if (FillBCol = FillFCol) then begin // or if diff(gb,fg) < x
if FillBCol = colEditorBG
then FillFCol := not(FillBCol) and $00ffffff // or maybe Font.color ?
@ -3383,11 +3393,12 @@ var
rcToken.Right := ScreenColumnToXValue(CurPhysPos+6);
FTextDrawer.FrameColor := FillFrame;
FTextDrawer.FrameStyle := FrameStyle;
FTextDrawer.ForeColor := FillFCol;
FTextDrawer.BackColor := FillBCol;
FTextDrawer.SetStyle(FillStyle);
If assigned(FoldedCodeInfo) and (FoldedCodeInfo.FrameColor <> clNone) then
if Assigned(FoldedCodeInfo) and (FoldedCodeInfo.FrameColor <> clNone) then
begin
FTextDrawer.FrameStartX := rcToken.Left;
FTextDrawer.FrameEndX := rcToken.Right;
@ -3406,7 +3417,7 @@ var
Token: PChar;
TokenLen, PhysicalStartPos, PhysicalEndPos: integer;
Foreground, Background, FrameColor: TColor;
Style: TFontStyles);
Style: TFontStyles; FrameStyle: TSynLineStyle);
var
bCanAppend: boolean;
bSpacesTest, bIsSpaces: boolean;
@ -3496,6 +3507,7 @@ var
TokenAccu.BG := Background;
TokenAccu.FC := FrameColor;
TokenAccu.Style := Style;
TokenAccu.FrameStyle := FrameStyle;
end;
{debugln('AddHighlightToken END bCanAppend=',dbgs(bCanAppend),
' Len=',dbgs(TokenAccu.Len),
@ -3521,8 +3533,10 @@ var
var
DefaultFGCol, DefaultBGCol, DefaultFCCol: TColor;
DefaultFrameStyle: TSynLineStyle;
DefaultStyle: TFontStyles;
BG, FG, FC : TColor;
FrameStyle: TSynLineStyle;
Style: TFontStyles;
PhysicalStartPos: integer;
PhysicalEndPos: integer;
@ -3566,10 +3580,12 @@ var
DefaultFGCol := attr.Foreground;
DefaultBGCol := attr.Background;
DefaultFCCol := attr.FrameColor;
DefaultFrameStyle := attr.FrameStyle;
DefaultStyle := attr.Style;
if DefaultBGCol = clNone then DefaultBGCol := colEditorBG;
if DefaultFGCol = clNone then DefaultFGCol := Font.Color;
if attr.FrameColor <> clNone then begin
if attr.FrameColor <> clNone then
begin
CurTokenFrameStart := PhysicalStartPos;
CurTokenFrameEnd := PhysicalStartPos + TokenCharLen - 1;
// force Paint
@ -3586,6 +3602,7 @@ var
DefaultFGCol := Font.Color;
DefaultBGCol := colEditorBG;
DefaultFCCol := clNone;
DefaultFrameStyle := slsSolid;
DefaultStyle := Font.Style;
end;
@ -3611,10 +3628,11 @@ var
BG := DefaultBGCol;
FG := DefaultFGCol;
FC := DefaultFCCol;
FrameStyle := DefaultFrameStyle;
Style := DefaultStyle;
MarkupInfo := fMarkupManager.GetMarkupAttributeAtRowCol(FFoldedLinesView.TextIndex[CurLine]+1, PhysicalStartPos);
if assigned(MarkupInfo)
then MarkupInfo.ModifyColors(FG, BG, FC, Style);
if Assigned(MarkupInfo) then
MarkupInfo.ModifyColors(FG, BG, FC, Style, FrameStyle);
// Deal with equal colors
if (BG = FG) then begin // or if diff(gb,fg) < x
if BG = DefaultBGCol
@ -3622,10 +3640,13 @@ var
else FG := DefaultBGCol;
end;
if not assigned(MarkupInfo) then begin
if (CurTokenFrameEnd > 0) then begin
if not Assigned(MarkupInfo) then
begin
if (CurTokenFrameEnd > 0) then
begin
LastFEX := CurTokenFrameEnd;
FC := DefaultFCCol;
FrameStyle := DefaultFrameStyle;
end;
FTextDrawer.FrameEndX := ScreenColumnToXValue(LastFEX+1);
end
@ -3637,14 +3658,18 @@ var
TokenAccu.Len := 0;
// Set Frame Boundaries
LastFSX := MarkupInfo.StartX;
if (CurTokenFrameStart = PhysicalStartPos) and (LastFSX < 1) then begin
if (CurTokenFrameStart = PhysicalStartPos) and (LastFSX < 1) then
begin
LastFSX := CurTokenFrameStart;
FC := DefaultFCCol;
FrameStyle := DefaultFrameStyle;
end;
LastFEX := MarkupInfo.EndX;
if (CurTokenFrameEnd > 0) and (LastFEX < 1) then begin
if (CurTokenFrameEnd > 0) and (LastFEX < 1) then
begin
LastFEX := CurTokenFrameEnd;
FC := DefaultFCCol;
FrameStyle := DefaultFrameStyle;
end;
FTextDrawer.FrameStartX := ScreenColumnToXValue(LastFSX);
FTextDrawer.FrameEndX := ScreenColumnToXValue(LastFEX+1);
@ -3657,7 +3682,7 @@ var
// Add to TokenAccu
AddHighlightToken(sToken, SubTokenByteLen,
PhysicalStartPos, PhysicalEndPos, FG, BG, FC, Style);
PhysicalStartPos, PhysicalEndPos, FG, BG, FC, Style, FrameStyle);
PhysicalStartPos:=PhysicalEndPos + 1;
dec(nTokenByteLen,SubTokenByteLen);

View File

@ -80,7 +80,7 @@ type
property NeedsReScanRealStartIndex: Integer read GetNeedsReScanRealStartIndex;
end;
TSynHighlighterAttrFeature = (hafBackColor, hafForeColor, hafFrameColor, hafStyle, hafStyleMask);
TSynHighlighterAttrFeature = (hafBackColor, hafForeColor, hafFrameColor, hafStyle, hafStyleMask, hafFrameStyle);
TSynHighlighterAttrFeatures = set of TSynHighlighterAttrFeature;
{ TSynHighlighterAttributes }
@ -92,6 +92,8 @@ type
FForegroundDefault: TColor;
FFrameColor: TColor;
FFrameColorDefault: TColor;
FFrameStyle: TSynLineStyle;
FFrameStyleDefault: TSynLineStyle;
FStyle: TFontStyles;
FStyleDefault: TFontStyles;
FStyleMask: TFontStyles;
@ -107,9 +109,11 @@ type
function GetFontStyleMaskStored : boolean;
function GetForegroundColorStored: boolean;
function GetFrameColorStored: boolean;
function GetFrameStyleStored: boolean;
procedure SetBackground(Value: TColor);
procedure SetForeground(Value: TColor);
procedure SetFrameColor(const AValue: TColor);
procedure SetFrameStyle(const AValue: TSynLineStyle);
procedure SetStyle(Value: TFontStyles);
function GetStyleFromInt: integer;
procedure SetStyleFromInt(const Value: integer);
@ -137,16 +141,12 @@ type
property OnChange: TNotifyEvent read fOnChange write fOnChange;
property Features: TSynHighlighterAttrFeatures read FFeatures write FFeatures;
published
property Background: TColor read fBackground write SetBackground
stored GetBackgroundColorStored;
property Foreground: TColor read fForeground write SetForeground
stored GetForegroundColorStored;
property FrameColor: TColor read FFrameColor write SetFrameColor
stored GetFrameColorStored;
property Style: TFontStyles read fStyle write SetStyle
stored GetFontStyleStored;
property StyleMask: TFontStyles read fStyleMask write SetStyleMask
stored GetFontStyleMaskStored;
property Background: TColor read fBackground write SetBackground stored GetBackgroundColorStored;
property Foreground: TColor read fForeground write SetForeground stored GetForegroundColorStored;
property FrameColor: TColor read FFrameColor write SetFrameColor stored GetFrameColorStored;
property FrameStyle: TSynLineStyle read FFrameStyle write SetFrameStyle stored GetFrameStyleStored;
property Style: TFontStyles read fStyle write SetStyle stored GetFontStyleStored;
property StyleMask: TFontStyles read fStyleMask write SetStyleMask stored GetFontStyleMaskStored;
end;
TSynHighlighterCapability = (
@ -496,6 +496,7 @@ begin
Background := src.FBackground;
Foreground := src.fForeground;
FrameColor := src.FFrameColor;
FrameStyle := src.FFrameStyle;
Style := src.fStyle;
StyleMask := src.fStyleMask;
FFeatures := src.FFeatures;
@ -523,10 +524,12 @@ begin
Background := clNone;
Foreground := clNone;
FFrameColor := clNone;
FFrameStyle := slsSolid;
FBackgroundDefault := clNone;
FForegroundDefault := clNone;
FFrameColorDefault := clNone;
FFeatures := [hafBackColor, hafForeColor, hafFrameColor, hafStyle];
FFrameStyleDefault := slsSolid;
FFeatures := [hafBackColor, hafForeColor, hafFrameColor, hafStyle, hafFrameStyle];
fName := attribName;
if aStoredName = '' then
FStoredName := attribName
@ -554,6 +557,11 @@ begin
Result := FFrameColor <> FFrameColorDefault;
end;
function TSynHighlighterAttributes.GetFrameStyleStored: boolean;
begin
Result := FFrameStyle <> FFrameStyleDefault;
end;
function TSynHighlighterAttributes.GetFontStyleStored: boolean;
begin
Result := fStyle <> fStyleDefault;
@ -563,9 +571,10 @@ procedure TSynHighlighterAttributes.InternalSaveDefaultValues;
(* Called once from TSynCustomHighlighter.Create (and only from there),
after all Attributes where created *)
begin
fForegroundDefault := fForeground;
fBackgroundDefault := fBackground;
fForegroundDefault := FForeground;
fBackgroundDefault := FBackground;
FFrameColorDefault := FFrameColor;
FFrameStyleDefault := FFrameStyle;
fStyleDefault := fStyle;
fStyleMaskDefault := fStyleMask;
end;
@ -746,16 +755,18 @@ end; { TSynHighlighterAttributes.LoadFromBorlandRegistry }
procedure TSynHighlighterAttributes.SetBackground(Value: TColor);
begin
if fBackGround <> Value then begin
fBackGround := Value;
if FBackGround <> Value then
begin
FBackGround := Value;
Changed;
end;
end;
procedure TSynHighlighterAttributes.SetForeground(Value: TColor);
begin
if fForeGround <> Value then begin
fForeGround := Value;
if FForeGround <> Value then
begin
FForeGround := Value;
Changed;
end;
end;
@ -769,6 +780,15 @@ begin
end;
end;
procedure TSynHighlighterAttributes.SetFrameStyle(const AValue: TSynLineStyle);
begin
if FFrameStyle <> AValue then
begin
FFrameStyle := AValue;
Changed;
end;
end;
procedure TSynHighlighterAttributes.SetStyle(Value: TFontStyles);
begin
if fStyle <> Value then begin

View File

@ -26,7 +26,7 @@ unit SynEditMarkup;
interface
uses
Classes, SysUtils, Graphics, SynEditTextBase, SynEditPointClasses,
Classes, SysUtils, Graphics, SynEditTypes, SynEditTextBase, SynEditPointClasses,
SynEditMiscClasses, SynEditMiscProcs, Controls, SynEditHighlighter;
type
@ -53,6 +53,7 @@ type
function GetEnabled: Boolean;
function GetFGColor : TColor;
function GetFrameColor: TColor;
function GetFrameStyle: TSynLineStyle;
function GetStyle : TFontStyles;
procedure SetBGColor(const AValue : TColor);
procedure SetEnabled(const AValue: Boolean);
@ -106,6 +107,7 @@ type
property FGColor : TColor read GetFGColor;
property BGColor : TColor read GetBGColor;
property FrameColor: TColor read GetFrameColor;
property FrameStyle: TSynLineStyle read GetFrameStyle;
property Style : TFontStyles read GetStyle;
property Enabled: Boolean read GetEnabled write SetEnabled;
property Lines : TSynEditStrings read fLines write SetLines;
@ -180,6 +182,11 @@ begin
Result := fMarkupInfo.FrameColor;
end;
function TSynEditMarkup.GetFrameStyle: TSynLineStyle;
begin
Result := FMarkupInfo.FrameStyle;
end;
function TSynEditMarkup.GetStyle : TFontStyles;
begin
Result := fMarkupInfo.Style;
@ -489,15 +496,17 @@ begin
end else begin
if c.Background <> clNone then Result.Background := c.Background;
if c.Foreground <> clNone then Result.Foreground := c.Foreground;
if c.FrameColor <> clNone then Result.FrameColor := c.FrameColor;
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
if c.FrameColor <> clNone then
begin
Result.FrameColor := c.FrameColor;
Result.FrameStyle := c.FrameStyle;
// Only frames need start/end info => copy *here* to separate fields if needed
Result.StartX := C.StartX;
Result.EndX := C.EndX;
end;
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);
end;
end;
end;

View File

@ -208,6 +208,7 @@ type
FBG: TColor;
FFG: TColor;
FFrameColor: TColor;
FFrameStyle: TSynLineStyle;
FStyle: TFontStyles;
// StyleMask = 1 => Copy Style Bits
// StyleMask = 0 => Invert where Style Bit = 1
@ -220,6 +221,7 @@ type
procedure SetBG(Value: TColor);
procedure SetFG(Value: TColor);
procedure SetFrameColor(const AValue: TColor);
procedure SetFrameStyle(const AValue: TSynLineStyle);
procedure SetStyle(const AValue : TFontStyles);
procedure SetStyleMask(const AValue : TFontStyles);
procedure DoChange;
@ -228,8 +230,9 @@ type
procedure Assign(aSource: TPersistent); override;
procedure Clear;
function IsEnabled: boolean;
function GetModifiedStyle(aStyle : TFontStyles): TFontStyles;
procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor; var AStyle: TFontStyles);
function GetModifiedStyle(aStyle: TFontStyles): TFontStyles;
procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor;
var AStyle: TFontStyles; var AFrameStyle: TSynLineStyle);
property StartX: Integer read FStartX write FStartX;
property EndX: Integer read FEndX write FEndX;
property OnChange: TNotifyEvent read fOnChange write fOnChange;
@ -239,6 +242,7 @@ type
property Background: TColor read FBG write SetBG default clHighLight;
property Foreground: TColor read FFG write SetFG default clHighLightText;
property FrameColor: TColor read FFrameColor write SetFrameColor default clNone;
property FrameStyle: TSynLineStyle read FFrameStyle write SetFrameStyle default slsSolid;
property Style: TFontStyles read FStyle write SetStyle default [];
property StyleMask: TFontStyles read fStyleMask write SetStyleMask default [];
end;
@ -461,9 +465,10 @@ end;
constructor TSynSelectedColor.Create;
begin
inherited Create;
fBG := clHighLight;
fFG := clHighLightText;
FBG := clHighLight;
FFG := clHighLightText;
FFrameColor:= clNone;
FFrameStyle := slsSolid;
FUpdateCount := 0;
end;
@ -474,11 +479,17 @@ begin
- (fsNot(FStyle)*FStyleMask); // Remove Styles
end;
procedure TSynSelectedColor.ModifyColors(var AForeground, ABackground, AFrameColor: TColor; var AStyle: TFontStyles);
procedure TSynSelectedColor.ModifyColors(var AForeground, ABackground,
AFrameColor: TColor; var AStyle: TFontStyles; var AFrameStyle: TSynLineStyle);
begin
if Foreground <> clNone then AForeground := Foreground;
if Background <> clNone then ABackground := Background;
if FrameColor <> clNone then AFrameColor := FrameColor;
if FrameColor <> clNone then
begin
AFrameColor := FrameColor;
AFrameStyle := FrameStyle;
end;
AStyle := GetModifiedStyle(AStyle);
end;
@ -521,6 +532,15 @@ begin
end;
end;
procedure TSynSelectedColor.SetFrameStyle(const AValue: TSynLineStyle);
begin
if FFrameStyle <> AValue then
begin
FFrameStyle := AValue;
DoChange;
end;
end;
procedure TSynSelectedColor.SetStyle(const AValue : TFontStyles);
begin
if (FStyle <> AValue) then
@ -559,6 +579,7 @@ begin
FBG := Source.FBG;
FFG := Source.FFG;
FFrameColor := Source.FFrameColor;
FFrameStyle := Source.FFrameStyle;
FStyle := Source.FStyle;
FStyleMask := Source.FStyleMask;
FStartX := Source.FStartX;
@ -572,6 +593,7 @@ begin
FBG := clNone;
FFG := clNone;
FFrameColor := clNone;
FFrameStyle := slsSolid;
FStyle := [];
FStyleMask := [];
FStartX := -1;

View File

@ -87,10 +87,16 @@ type
TSynStatusChanges = set of TSynStatusChange;
TSynLineStyle = (
slsSolid,
slsDashed,
slsDotted,
slsWaved
slsSolid, // PS_SOLID pen
slsDashed, // PS_DASH pen
slsDotted, // PS_DOT
slsWaved // solid wave
);
TSynFrameEdges = (
sfeAround, // frame around
sfeBottom, // bottom part of the frame
sfeLeft // left part of the frame
);
const

View File

@ -260,8 +260,9 @@ type
procedure SetFrameColor(Side: TSynFrameSide; AValue: TColor); virtual; overload;
procedure SetFrameColor(AValue: TColor); virtual; overload;
procedure SetFrameStyle(Side: TSynFrameSide; AValue: TSynLineStyle); virtual; overload;
procedure SetFrameStyle(AValue: TSynLineStyle); virtual; overload;
procedure SetFrameStyle(Side: TSynFrameSide; AValue: TSynLineStyle); virtual;
procedure SetCharExtra(Value: Integer); virtual;
procedure ReleaseTemporaryResources; virtual;
@ -1035,6 +1036,14 @@ begin
end;
end;
procedure TheTextDrawer.SetFrameStyle(AValue: TSynLineStyle);
var
Side: TSynFrameSide;
begin
for Side := Low(TSynFrameSide) to High(TSynFrameSide) do
SetFrameStyle(Side, AValue);
end;
procedure TheTextDrawer.ReleaseETODist;
begin
if Assigned(FETODist) then