SynEdit: TextAttributes refactor class structure

git-svn-id: trunk@41167 -
This commit is contained in:
martin 2013-05-13 13:26:57 +00:00
parent 739984d131
commit 12d8184160
4 changed files with 189 additions and 164 deletions

View File

@ -425,7 +425,7 @@ type
private private
FFoldView: TSynEditFoldedView; FFoldView: TSynEditFoldedView;
FLineState: integer; FLineState: integer;
FTokenAttr: TSynHighlighterAttributes; FTokenAttr: TSynHighlighterAttributesModifier;
public public
constructor Create(AFoldView: TSynEditFoldedView); constructor Create(AFoldView: TSynEditFoldedView);
destructor Destroy; override; destructor Destroy; override;
@ -783,7 +783,7 @@ constructor TLazSynDisplayFold.Create(AFoldView: TSynEditFoldedView);
begin begin
inherited Create; inherited Create;
FFoldView := AFoldView; FFoldView := AFoldView;
FTokenAttr := TSynHighlighterAttributes.Create(''); FTokenAttr := TSynHighlighterAttributesModifier.Create('');
end; end;
destructor TLazSynDisplayFold.Destroy; destructor TLazSynDisplayFold.Destroy;

View File

@ -87,34 +87,24 @@ type
FFrameStyle: TSynLineStyle; FFrameStyle: TSynLineStyle;
fStyle: TFontStyles; fStyle: TFontStyles;
fStyleMask: TFontStyles; fStyleMask: TFontStyles;
FBackPriority: integer;
FForePriority: integer;
FFramePriority: integer;
FStylePriority: Array [TFontStyle] of integer;
function GetStylePriority(Index: TFontStyle): integer;
procedure SetBackground(AValue: TColor); procedure SetBackground(AValue: TColor);
procedure SetBackPriority(AValue: integer);
procedure SetForeground(AValue: TColor); procedure SetForeground(AValue: TColor);
procedure SetForePriority(AValue: integer);
procedure SetFrameColor(AValue: TColor); procedure SetFrameColor(AValue: TColor);
procedure SetFrameEdges(AValue: TSynFrameEdges); procedure SetFrameEdges(AValue: TSynFrameEdges);
procedure SetFramePriority(AValue: integer);
procedure SetFrameStyle(AValue: TSynLineStyle); procedure SetFrameStyle(AValue: TSynLineStyle);
procedure SetStyle(AValue: TFontStyles); procedure SetStyle(AValue: TFontStyles);
procedure SetStyleMask(AValue: TFontStyles); procedure SetStyleMask(AValue: TFontStyles);
procedure SetStylePriority(Index: TFontStyle; AValue: integer);
protected protected
procedure AssignFrom(Src: TLazSynCustomTextAttributes); virtual; procedure AssignFrom(Src: TLazSynCustomTextAttributes); virtual;
procedure DoClear; virtual;
procedure Changed; procedure Changed;
procedure DoChange; virtual; procedure DoChange; virtual;
procedure InitPriorities;
public public
constructor Create; constructor Create;
procedure Clear; virtual; procedure Clear;
procedure Assign(aSource: TPersistent); override; procedure Assign(aSource: TPersistent); override;
procedure BeginUpdate; procedure BeginUpdate;
procedure EndUpdate; procedure EndUpdate;
procedure SetAllPriorities(APriority: integer);
public public
property Background: TColor read FBackground write SetBackground; property Background: TColor read FBackground write SetBackground;
property Foreground: TColor read FForeground write SetForeground; property Foreground: TColor read FForeground write SetForeground;
@ -123,13 +113,6 @@ type
property FrameEdges: TSynFrameEdges read FFrameEdges write SetFrameEdges; property FrameEdges: TSynFrameEdges read FFrameEdges write SetFrameEdges;
property Style: TFontStyles read fStyle write SetStyle; property Style: TFontStyles read fStyle write SetStyle;
property StyleMask: TFontStyles read fStyleMask write SetStyleMask; property StyleMask: TFontStyles read fStyleMask write SetStyleMask;
property BackPriority: integer read FBackPriority write SetBackPriority;
property ForePriority: integer read FForePriority write SetForePriority;
property FramePriority: integer read FFramePriority write SetFramePriority;
property StylePriority[Index: TFontStyle]: integer read GetStylePriority write SetStylePriority;
property BoldPriority: integer index fsBold read GetStylePriority write SetStylePriority default 0;
property ItalicPriority: integer index fsItalic read GetStylePriority write SetStylePriority default 0;
property UnderlinePriority: integer index fsUnderline read GetStylePriority write SetStylePriority default 0;
end; end;
{ TSynHighlighterAttributes } { TSynHighlighterAttributes }
@ -187,6 +170,35 @@ type
property StyleMask stored GetFontStyleMaskStored; property StyleMask stored GetFontStyleMaskStored;
end; end;
{ TSynHighlighterAttributesModifier }
TSynHighlighterAttributesModifier = class(TSynHighlighterAttributes)
{strict} private
FBackPriority: integer;
FForePriority: integer;
FFramePriority: integer;
FStylePriority: Array [TFontStyle] of integer;
function GetStylePriority(Index: TFontStyle): integer;
procedure SetBackPriority(AValue: integer);
procedure SetForePriority(AValue: integer);
procedure SetFramePriority(AValue: integer);
procedure SetStylePriority(Index: TFontStyle; AValue: integer);
protected
procedure AssignFrom(Src: TLazSynCustomTextAttributes); override;
procedure DoClear; override;
procedure InitPriorities;
public
procedure SetAllPriorities(APriority: integer);
property StylePriority[Index: TFontStyle]: integer read GetStylePriority write SetStylePriority;
published
property BackPriority: integer read FBackPriority write SetBackPriority;
property ForePriority: integer read FForePriority write SetForePriority;
property FramePriority: integer read FFramePriority write SetFramePriority;
property BoldPriority: integer index fsBold read GetStylePriority write SetStylePriority default 0;
property ItalicPriority: integer index fsItalic read GetStylePriority write SetStylePriority default 0;
property UnderlinePriority: integer index fsUnderline read GetStylePriority write SetStylePriority default 0;
end;
TSynHighlighterCapability = ( TSynHighlighterCapability = (
hcUserSettings, // supports Enum/UseUserSettings hcUserSettings, // supports Enum/UseUserSettings
hcRegistry, // supports LoadFrom/SaveToRegistry hcRegistry, // supports LoadFrom/SaveToRegistry
@ -420,6 +432,94 @@ implementation
const const
IDLE_SCAN_CHUNK_SIZE = 2500; IDLE_SCAN_CHUNK_SIZE = 2500;
{ TSynHighlighterAttributesModifier }
function TSynHighlighterAttributesModifier.GetStylePriority(Index: TFontStyle
): integer;
begin
Result := FStylePriority[Index];
end;
procedure TSynHighlighterAttributesModifier.SetBackPriority(AValue: integer);
begin
if FBackPriority = AValue then Exit;
FBackPriority := AValue;
Changed;
end;
procedure TSynHighlighterAttributesModifier.SetForePriority(AValue: integer);
begin
if FForePriority = AValue then Exit;
FForePriority := AValue;
Changed;
end;
procedure TSynHighlighterAttributesModifier.SetFramePriority(AValue: integer);
begin
if FFramePriority = AValue then Exit;
FFramePriority := AValue;
Changed;
end;
procedure TSynHighlighterAttributesModifier.SetStylePriority(Index: TFontStyle;
AValue: integer);
begin
if FStylePriority[Index] = AValue then Exit;
FStylePriority[Index] := AValue;
Changed;
end;
procedure TSynHighlighterAttributesModifier.AssignFrom(
Src: TLazSynCustomTextAttributes);
var
Source: TSynHighlighterAttributesModifier;
j: TFontStyle;
begin
inherited AssignFrom(Src);
if Src is TSynHighlighterAttributesModifier then begin
Source := TSynHighlighterAttributesModifier(Src);
ForePriority := Source.ForePriority;
BackPriority := Source.BackPriority;
FramePriority := Source.FramePriority;
for j := Low(TFontStyle) to High(TFontStyle) do
StylePriority[j] := Source.StylePriority[j];
end
else
InitPriorities;
end;
procedure TSynHighlighterAttributesModifier.DoClear;
begin
inherited DoClear;
InitPriorities;
end;
procedure TSynHighlighterAttributesModifier.InitPriorities;
var
i: TFontStyle;
begin
BeginUpdate;
ForePriority := 0;
BackPriority := 0;
FramePriority := 0;
for i := Low(TFontStyle) to High(TFontStyle) do
StylePriority[i] := 0;
EndUpdate;
end;
procedure TSynHighlighterAttributesModifier.SetAllPriorities(APriority: integer);
var
i: TFontStyle;
begin
BeginUpdate;
ForePriority := APriority;
BackPriority := APriority;
FramePriority := APriority;
for i := Low(TFontStyle) to High(TFontStyle) do
StylePriority[i] := APriority;
EndUpdate;
end;
{$IFDEF _Gp_MustEnhanceRegistry} {$IFDEF _Gp_MustEnhanceRegistry}
function IsRelative(const Value: string): Boolean; function IsRelative(const Value: string): Boolean;
begin begin
@ -520,18 +620,6 @@ begin
Changed; Changed;
end; end;
function TLazSynCustomTextAttributes.GetStylePriority(Index: TFontStyle): integer;
begin
Result := FStylePriority[Index];
end;
procedure TLazSynCustomTextAttributes.SetBackPriority(AValue: integer);
begin
if FBackPriority = AValue then Exit;
FBackPriority := AValue;
Changed;
end;
procedure TLazSynCustomTextAttributes.SetForeground(AValue: TColor); procedure TLazSynCustomTextAttributes.SetForeground(AValue: TColor);
begin begin
if FForeground = AValue then Exit; if FForeground = AValue then Exit;
@ -539,13 +627,6 @@ begin
Changed; Changed;
end; end;
procedure TLazSynCustomTextAttributes.SetForePriority(AValue: integer);
begin
if FForePriority = AValue then Exit;
FForePriority := AValue;
Changed;
end;
procedure TLazSynCustomTextAttributes.SetFrameColor(AValue: TColor); procedure TLazSynCustomTextAttributes.SetFrameColor(AValue: TColor);
begin begin
if FFrameColor = AValue then Exit; if FFrameColor = AValue then Exit;
@ -560,13 +641,6 @@ begin
Changed; Changed;
end; end;
procedure TLazSynCustomTextAttributes.SetFramePriority(AValue: integer);
begin
if FFramePriority = AValue then Exit;
FFramePriority := AValue;
Changed;
end;
procedure TLazSynCustomTextAttributes.SetFrameStyle(AValue: TSynLineStyle); procedure TLazSynCustomTextAttributes.SetFrameStyle(AValue: TSynLineStyle);
begin begin
if FFrameStyle = AValue then Exit; if FFrameStyle = AValue then Exit;
@ -588,13 +662,6 @@ begin
Changed; Changed;
end; end;
procedure TLazSynCustomTextAttributes.SetStylePriority(Index: TFontStyle; AValue: integer);
begin
if FStylePriority[Index] = AValue then Exit;
FStylePriority[Index] := AValue;
Changed;
end;
procedure TLazSynCustomTextAttributes.Changed; procedure TLazSynCustomTextAttributes.Changed;
begin begin
FWasChanged := True; FWasChanged := True;
@ -609,24 +676,22 @@ begin
// //
end; end;
procedure TLazSynCustomTextAttributes.DoClear;
begin
Background := clNone;
Foreground := clNone;
FrameColor := clNone;
FrameStyle := slsSolid;
FrameEdges := sfeAround;
Style := [];
StyleMask := [];
end;
procedure TLazSynCustomTextAttributes.DoChange; procedure TLazSynCustomTextAttributes.DoChange;
begin begin
// //
end; end;
procedure TLazSynCustomTextAttributes.InitPriorities;
var
i: TFontStyle;
begin
BeginUpdate;
ForePriority := 0;
BackPriority := 0;
FramePriority := 0;
for i := Low(TFontStyle) to High(TFontStyle) do
StylePriority[i] := 0;
EndUpdate;
end;
constructor TLazSynCustomTextAttributes.Create; constructor TLazSynCustomTextAttributes.Create;
begin begin
inherited; inherited;
@ -638,26 +703,17 @@ end;
procedure TLazSynCustomTextAttributes.Clear; procedure TLazSynCustomTextAttributes.Clear;
begin begin
BeginUpdate; BeginUpdate;
Background := clNone; DoClear;
Foreground := clNone;
FrameColor := clNone;
FrameStyle := slsSolid;
FrameEdges := sfeAround;
Style := [];
StyleMask := [];
InitPriorities;
EndUpdate; EndUpdate;
end; end;
procedure TLazSynCustomTextAttributes.Assign(aSource: TPersistent); procedure TLazSynCustomTextAttributes.Assign(aSource: TPersistent);
var var
Source : TLazSynCustomTextAttributes; Source : TLazSynCustomTextAttributes;
j: TFontStyle;
begin begin
if Assigned(aSource) and (aSource is TLazSynCustomTextAttributes) then if Assigned(aSource) and (aSource is TLazSynCustomTextAttributes) then
begin begin
BeginUpdate; BeginUpdate;
InitPriorities;
Source := TLazSynCustomTextAttributes(aSource); Source := TLazSynCustomTextAttributes(aSource);
Foreground := Source.Foreground; Foreground := Source.Foreground;
Background := Source.Background; Background := Source.Background;
@ -666,11 +722,6 @@ begin
FrameEdges := Source.FrameEdges; FrameEdges := Source.FrameEdges;
Style := Source.FStyle; Style := Source.FStyle;
StyleMask := Source.FStyleMask; StyleMask := Source.FStyleMask;
ForePriority := Source.ForePriority;
BackPriority := Source.BackPriority;
FramePriority := Source.FramePriority;
for j := Low(TFontStyle) to High(TFontStyle) do
StylePriority[j] := Source.StylePriority[j];
AssignFrom(Source); AssignFrom(Source);
EndUpdate; EndUpdate;
end end
@ -690,19 +741,6 @@ begin
Changed; Changed;
end; end;
procedure TLazSynCustomTextAttributes.SetAllPriorities(APriority: integer);
var
i: TFontStyle;
begin
BeginUpdate;
ForePriority := APriority;
BackPriority := APriority;
FramePriority := APriority;
for i := Low(TFontStyle) to High(TFontStyle) do
StylePriority[i] := APriority;
EndUpdate;
end;
{ TSynHighlighterAttributes } { TSynHighlighterAttributes }
constructor TSynHighlighterAttributes.Create(attribName: string; aStoredName: String = ''); constructor TSynHighlighterAttributes.Create(attribName: string; aStoredName: String = '');

View File

@ -209,7 +209,7 @@ type
{ TSynSelectedColor } { TSynSelectedColor }
TSynSelectedColor = class(TLazSynCustomTextAttributes) TSynSelectedColor = class(TSynHighlighterAttributesModifier)
private private
FCurrentStartX: TLazSynDisplayTokenBound; FCurrentStartX: TLazSynDisplayTokenBound;
FCurrentEndX: TLazSynDisplayTokenBound; FCurrentEndX: TLazSynDisplayTokenBound;
@ -228,6 +228,7 @@ type
function IsMatching(ABound1, ABound2: TLazSynDisplayTokenBound): Boolean; function IsMatching(ABound1, ABound2: TLazSynDisplayTokenBound): Boolean;
protected protected
procedure DoChange; override; procedure DoChange; override;
procedure DoClear; override;
procedure AssignFrom(Src: TLazSynCustomTextAttributes); override; procedure AssignFrom(Src: TLazSynCustomTextAttributes); override;
property FrameSidePriority[Side: TLazSynBorderSide]: integer read GetFrameSidePriority; property FrameSidePriority[Side: TLazSynBorderSide]: integer read GetFrameSidePriority;
property FrameSideOrigin[Side: TLazSynBorderSide]: TSynFrameEdges read GetFrameSideOrigin; property FrameSideOrigin[Side: TLazSynBorderSide]: TSynFrameEdges read GetFrameSideOrigin;
@ -250,7 +251,6 @@ type
property CurrentEndX: TLazSynDisplayTokenBound read FCurrentEndX write FCurrentEndX; property CurrentEndX: TLazSynDisplayTokenBound read FCurrentEndX write FCurrentEndX;
public public
constructor Create; constructor Create;
procedure Clear; override;
function IsEnabled: boolean; function IsEnabled: boolean;
function GetModifiedStyle(aStyle: TFontStyles): TFontStyles; function GetModifiedStyle(aStyle: TFontStyles): TFontStyles;
procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor; procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor;
@ -624,7 +624,7 @@ end;
constructor TSynSelectedColor.Create; constructor TSynSelectedColor.Create;
begin begin
inherited Create; inherited Create('', '');
Clear; Clear;
MergeFinalStyle := False; MergeFinalStyle := False;
Background := clHighLight; Background := clHighLight;
@ -726,6 +726,31 @@ begin
OnChange(Self); OnChange(Self);
end; end;
procedure TSynSelectedColor.DoClear;
var
i: TLazSynBorderSide;
begin
inherited DoClear;
FFrameSidesInitialized := False;
for i := low(TLazSynBorderSide) to high(TLazSynBorderSide) do begin
FFrameSideColors[i] := clNone;
FFrameSideStyles[i] := slsSolid;
FFrameSideOrigin[i] := sfeNone;
end;
FStartX.Physical := -1;
FEndX.Physical := -1;
FStartX.Logical := -1;
FEndX.Logical := -1;
FStartX.Offset := 0;
FEndX.Offset := 0;
FCurrentStartX.Physical := -1;
FCurrentEndX.Physical := -1;
FCurrentStartX.Logical := -1;
FCurrentEndX.Logical := -1;
FCurrentStartX.Offset := 0;
FCurrentEndX.Offset := 0;
end;
procedure TSynSelectedColor.AssignFrom(Src: TLazSynCustomTextAttributes); procedure TSynSelectedColor.AssignFrom(Src: TLazSynCustomTextAttributes);
var var
i: TLazSynBorderSide; i: TLazSynBorderSide;
@ -881,33 +906,6 @@ begin
FEndX.Offset := AEndOffs; FEndX.Offset := AEndOffs;
end; end;
procedure TSynSelectedColor.Clear;
var
i: TLazSynBorderSide;
begin
BeginUpdate;
inherited Clear;
FFrameSidesInitialized := False;
for i := low(TLazSynBorderSide) to high(TLazSynBorderSide) do begin
FFrameSideColors[i] := clNone;
FFrameSideStyles[i] := slsSolid;
FFrameSideOrigin[i] := sfeNone;
end;
FStartX.Physical := -1;
FEndX.Physical := -1;
FStartX.Logical := -1;
FEndX.Logical := -1;
FStartX.Offset := 0;
FEndX.Offset := 0;
FCurrentStartX.Physical := -1;
FCurrentEndX.Physical := -1;
FCurrentStartX.Logical := -1;
FCurrentEndX.Logical := -1;
FCurrentStartX.Offset := 0;
FCurrentEndX.Offset := 0;
EndUpdate;
end;
function TSynSelectedColor.IsEnabled: boolean; function TSynSelectedColor.IsEnabled: boolean;
begin begin
Result := (Background <> clNone) or (Foreground <> clNone) or (FrameColor <> clNone) or Result := (Background <> clNone) or (Foreground <> clNone) or (FrameColor <> clNone) or

View File

@ -218,7 +218,7 @@ type
{ TColorSchemeAttribute } { TColorSchemeAttribute }
TColorSchemeAttribute = class(TSynHighlighterAttributes) TColorSchemeAttribute = class(TSynHighlighterAttributesModifier)
private private
FGroup: TAhaGroupName; FGroup: TAhaGroupName;
FOwner: TColorSchemeLanguage; FOwner: TColorSchemeLanguage;
@ -227,8 +227,7 @@ type
function OldAdditionalAttributeName(NewAha: String): string; function OldAdditionalAttributeName(NewAha: String): string;
public public
constructor Create(ASchemeLang: TColorSchemeLanguage; attribName: string; aStoredName: String = ''); constructor Create(ASchemeLang: TColorSchemeLanguage; attribName: string; aStoredName: String = '');
procedure ApplyTo(aDest: TSynHighlighterAttributes; aDefault: TColorSchemeAttribute); procedure ApplyTo(aDest: TSynHighlighterAttributes; aDefault: TColorSchemeAttribute = nil);
procedure ApplyTo(aDest: TSynSelectedColor);
procedure Assign(Src: TPersistent); override; procedure Assign(Src: TPersistent); override;
function Equals(Other: TColorSchemeAttribute): Boolean; reintroduce; function Equals(Other: TColorSchemeAttribute): Boolean; reintroduce;
function GetSchemeGlobal: TColorSchemeAttribute; function GetSchemeGlobal: TColorSchemeAttribute;
@ -5583,49 +5582,39 @@ begin
aDest.FrameEdges := Src.FrameEdges; aDest.FrameEdges := Src.FrameEdges;
aDest.FrameStyle := Src.FrameStyle; aDest.FrameStyle := Src.FrameStyle;
aDest.Style := Src.Style; aDest.Style := Src.Style;
aDest.StyleMask := Src.StyleMask; if hafStyleMask in Src.Features then
aDest.Features := Src.Features; aDest.StyleMask := Src.StyleMask
if aDefault <> nil then begin else
if aDefault.IsUsingSchemeGlobals then aDest.StyleMask := [low(TFontStyle)..high(TFontStyle)];
aDefault := aDefault.GetSchemeGlobal;
if Background = clDefault then if not (aDest is TSynSelectedColor) then begin
aDest.Background := aDefault.Background; aDest.Features := Src.Features;
if Foreground = clDefault then
aDest.Foreground := aDefault.Foreground; if aDefault <> nil then begin
if FrameColor = clDefault then begin if aDefault.IsUsingSchemeGlobals then
aDest.FrameColor := aDefault.FrameColor; aDefault := aDefault.GetSchemeGlobal;
aDest.FrameEdges := aDefault.FrameEdges; if Background = clDefault then
aDest.FrameStyle := aDefault.FrameStyle; aDest.Background := aDefault.Background;
if Foreground = clDefault then
aDest.Foreground := aDefault.Foreground;
if FrameColor = clDefault then begin
aDest.FrameColor := aDefault.FrameColor;
aDest.FrameEdges := aDefault.FrameEdges;
aDest.FrameStyle := aDefault.FrameStyle;
end;
end; end;
//if aDest is TSynHighlighterAttributesModifier then begin
//end
if aDest is TColorSchemeAttribute then
TColorSchemeAttribute(aDest).Group := Src.Group;
end; end;
if aDest is TColorSchemeAttribute then
TColorSchemeAttribute(aDest).Group := Src.Group;
finally finally
aDest.EndUpdate; aDest.EndUpdate;
end; end;
end; end;
procedure TColorSchemeAttribute.ApplyTo(aDest: TSynSelectedColor);
var
Src: TColorSchemeAttribute;
begin
Src := Self;
if IsUsingSchemeGlobals then
Src := GetSchemeGlobal;
aDest.BeginUpdate;
aDest.Foreground := Src.Foreground;
aDest.Background := Src.Background;
aDest.FrameColor := Src.FrameColor;
aDest.FrameEdges := Src.FrameEdges;
aDest.FrameStyle := Src.FrameStyle;
aDest.Style := Src.Style;
if hafStyleMask in Src.Features then
aDest.StyleMask := Src.StyleMask
else
aDest.StyleMask := [low(TFontStyle)..high(TFontStyle)];
aDest.EndUpdate;
end;
procedure TColorSchemeAttribute.Assign(Src: TPersistent); procedure TColorSchemeAttribute.Assign(Src: TPersistent);
begin begin
inherited Assign(Src); inherited Assign(Src);