SynGutter: Cleanup (Moved common properties to base)

git-svn-id: trunk@18326 -
This commit is contained in:
martin 2009-01-18 13:47:10 +00:00
parent ef58282110
commit d75f642632
5 changed files with 82 additions and 92 deletions

View File

@ -78,27 +78,34 @@ type
TSynGutterPartBase = class(TPersistent)
private
FSynEdit: TSynEditBase;
FAutoSize : boolean;
FColor : TColor;
FMarkupInfo: TSynSelectedColor;
FCursor: TCursor;
FVisible: Boolean;
FWidth : integer;
FOnChange: TNotifyEvent;
FOnGutterClick: TGutterClickEvent;
procedure SetMarkupInfo(const AValue: TSynSelectedColor);
protected
procedure SetAutoSize(const AValue : boolean); virtual;
procedure SetColor(const AValue : TColor); virtual;
procedure SetVisible(const AValue : boolean); virtual;
procedure SetWidth(const AValue : integer); virtual;
procedure DoChange(Sender: TObject); virtual;
property SynEdit:TSynEditBase read FSynEdit;
public
constructor Create;
constructor Create(AOwner : TSynEditBase);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer);
virtual abstract;
function RealGutterWidth(CharWidth: integer): integer; virtual; abstract;
// X/Y are relative to the gutter, not the gutter part
procedure DoOnGutterClick(X, Y: integer); virtual;
property MarkupInfo: TSynSelectedColor read FMarkupInfo write SetMarkupInfo;
property AutoSize: boolean read FAutoSize write SetAutoSize default False;
property Color: TColor read FColor write SetColor default clBtnFace;
property Cursor: TCursor read FCursor write FCursor default crDefault;
@ -521,7 +528,7 @@ end;
function TSynGutter.GetMarkupInfoCodeFoldingTree: TSynSelectedColor;
begin
Result := TSynGutterCodeFolding(FCodeFoldGutter).MarkupInfoCodeFoldingTree;
Result := TSynGutterCodeFolding(FCodeFoldGutter).MarkupInfo;
end;
procedure TSynGutter.SetAllowSkipGutterSeparatorDraw(const AValue: Boolean);
@ -562,7 +569,7 @@ end;
function TSynGutter.GetMarkupInfoModifiedLine: TSynSelectedColor;
begin
Result := TSynGutterChanges(FChangesGutter).MarkupInfoModifiedLine;
Result := TSynGutterChanges(FChangesGutter).MarkupInfo;
end;
procedure TSynGutter.SetAutoSize(const Value: boolean);
@ -709,6 +716,11 @@ end;
{ TSynGutterPartBase }
procedure TSynGutterPartBase.SetMarkupInfo(const AValue: TSynSelectedColor);
begin
FMarkupInfo.Assign(AValue);
end;
procedure TSynGutterPartBase.SetAutoSize(const AValue : boolean);
begin
if FAutoSize=AValue then exit;
@ -743,14 +755,28 @@ begin
FOnChange(Self);
end;
constructor TSynGutterPartBase.Create;
constructor TSynGutterPartBase.Create(AOwner : TSynEditBase);
begin
inherited Create;
Inherited Create;
FColor := clBtnFace;
FSynEdit := TSynEdit(AOwner);
FMarkupInfo := TSynSelectedColor.Create;
FMarkupInfo.Background := clBtnFace;
FMarkupInfo.Foreground := clNone;
FMarkupInfo.FrameColor := clNone;
FMarkupInfo.OnChange := {$IFDEF FPC}@{$ENDIF}DoChange;
FVisible := True;
FWidth := 10;
end;
destructor TSynGutterPartBase.Destroy;
begin
inherited Destroy;
FreeAndNil(FMarkupInfo);
end;
procedure TSynGutterPartBase.Assign(Source : TPersistent);
var
Src: TSynGutterPartBase;
@ -762,6 +788,7 @@ begin
FVisible := Src.FVisible;
FWidth := Src.FWidth;
FAutoSize := Src.FAutoSize;
MarkupInfo.Assign(Src.MarkupInfo);
DoChange(Self);
end else
inherited;
@ -769,14 +796,15 @@ end;
procedure TSynGutterPartBase.DoOnGutterClick(X, Y : integer);
begin
FOnGutterClick(Self, X, Y, 0, nil);
if Assigned(FOnGutterClick) then
FOnGutterClick(Self, X, Y, 0, nil);
end;
{ Forward to Line Number }
function TSynGutter.GetMarkupInfoLineNumber : TSynSelectedColor;
begin
Result := TSynGutterLineNumber(FLineNumGutter).MarkupInfoLineNumber;
Result := TSynGutterLineNumber(FLineNumGutter).MarkupInfo;
end;
function TSynGutter.GetDigitCount : Integer;
@ -866,7 +894,7 @@ end;
constructor TSynGutterSeparator.Create(AOwner: TSynEditBase; AFoldView: TSynEditFoldedView);
begin
Inherited Create;
Inherited Create(AOwner);
Width := 2;
end;

View File

@ -13,18 +13,15 @@ type
TSynGutterChanges = class(TSynGutterPartBase)
private
FEdit: TSynEditBase;
FFoldView: TSynEditFoldedView;
FMarkupInfoModifiedLine: TSynSelectedColor;
public
constructor Create(AOwner: TSynEditBase; AFoldView: TSynEditFoldedView);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer); override;
function RealGutterWidth(CharWidth: integer): integer; override;
public
property MarkupInfoModifiedLine: TSynSelectedColor read FMarkupInfoModifiedLine;
end;
implementation
@ -35,37 +32,21 @@ uses
constructor TSynGutterChanges.Create(AOwner : TSynEditBase; AFoldView : TSynEditFoldedView);
begin
inherited Create;
FEdit := AOwner;
inherited Create(AOwner);
FFoldView := AFoldView;
FMarkupInfoModifiedLine := TSynSelectedColor.Create;
FMarkupInfoModifiedLine.Background := clNone;
FMarkupInfoModifiedLine.Foreground := clGreen;
FMarkupInfoModifiedLine.FrameColor := $00E9FC;
FMarkupInfoModifiedLine.OnChange := @DoChange;
MarkupInfo.Background := clNone;
MarkupInfo.Foreground := clGreen;
MarkupInfo.FrameColor := $00E9FC;
Width := 6;
end;
destructor TSynGutterChanges.Destroy;
begin
FMarkupInfoModifiedLine.Free;
inherited Destroy;
end;
procedure TSynGutterChanges.Assign(Source : TPersistent);
var
Src: TSynGutterChanges;
begin
if Assigned(Source) and (Source is TSynGutterChanges) then
begin
Src := TSynGutterChanges(Source);
FMarkupInfoModifiedLine.Assign(Src.FMarkupInfoModifiedLine);
end;
inherited;
end;
function TSynGutterChanges.RealGutterWidth(CharWidth: integer): integer;
begin
if not Visible then
@ -87,11 +68,11 @@ var
begin
if not Visible then exit;
LineHeight := TSynEdit(FEdit).LineHeight;
LineHeight := TSynEdit(SynEdit).LineHeight;
if MarkupInfoModifiedLine.Background <> clNone then
if MarkupInfo.Background <> clNone then
begin
Canvas.Brush.Color := MarkupInfoModifiedLine.Background;
Canvas.Brush.Color := MarkupInfo.Background;
Canvas.FillRect(AClip);
end;
@ -108,16 +89,16 @@ begin
rcLine.Top := rcLine.Bottom;
Inc(rcLine.Bottom, LineHeight);
case TCustomSynEdit(FEdit).GetLineState(iLine) of
case TCustomSynEdit(SynEdit).GetLineState(iLine) of
slsNone: ;
slsSaved:
begin
Canvas.Pen.Color := MarkupInfoModifiedLine.Foreground;
Canvas.Pen.Color := MarkupInfo.Foreground;
Canvas.Line(rcLine.Left, rcLine.Top, rcLine.Left, rcLine.Bottom);
end;
slsUnsaved:
begin
Canvas.Pen.Color := MarkupInfoModifiedLine.FrameColor;
Canvas.Pen.Color := MarkupInfo.FrameColor;
Canvas.Line(rcLine.Left, rcLine.Top, rcLine.Left, rcLine.Bottom);
end;
end;

View File

@ -14,9 +14,7 @@ type
TSynGutterCodeFolding = class(TSynGutterPartBase)
private
FEdit: TSynEditBase;
FFoldView: TSynEditFoldedView;
FMarkupInfoCodeFoldingTree: TSynSelectedColor;
public
constructor Create(AOwner : TSynEditBase; AFoldView : TSynEditFoldedView);
destructor Destroy; override;
@ -25,8 +23,6 @@ type
override;
function RealGutterWidth(CharWidth: integer): integer; override;
procedure DoOnGutterClick(X, Y: integer); override;
public
property MarkupInfoCodeFoldingTree: TSynSelectedColor read FMarkupInfoCodeFoldingTree;
end;
implementation
@ -38,22 +34,18 @@ uses
constructor TSynGutterCodeFolding.Create(AOwner : TSynEditBase;
AFoldView : TSynEditFoldedView);
begin
inherited Create;
FEdit := AOwner;
inherited Create(AOwner);
FFoldView := AFoldView;
FMarkupInfoCodeFoldingTree := TSynSelectedColor.Create;
FMarkupInfoCodeFoldingTree.Background := clNone;
FMarkupInfoCodeFoldingTree.Foreground := clDkGray;
FMarkupInfoCodeFoldingTree.FrameColor := clNone;
FMarkupInfoCodeFoldingTree.OnChange := @DoChange;
MarkupInfo.Background := clNone;
MarkupInfo.Foreground := clDkGray;
MarkupInfo.FrameColor := clNone;
Width := 10;
end;
destructor TSynGutterCodeFolding.Destroy;
begin
FMarkupInfoCodeFoldingTree.Free;
inherited Destroy;
end;
@ -69,9 +61,9 @@ procedure TSynGutterCodeFolding.DoOnGutterClick(X, Y : integer);
var
line : integer;
begin
line := TSynEdit(FEdit).PixelsToRowColumn(Point(X, Y)).Y;
if line <= TSynEdit(FEdit).Lines.Count then
TSynEdit(FEdit).CodeFoldAction(line);
line := TSynEdit(SynEdit).PixelsToRowColumn(Point(X, Y)).Y;
if line <= TSynEdit(SynEdit).Lines.Count then
TSynEdit(SynEdit).CodeFoldAction(line);
end;
procedure TSynGutterCodeFolding.Paint(Canvas : TCanvas; AClip : TRect; FirstLine, LastLine : integer);
@ -145,15 +137,15 @@ var
begin
if not Visible then exit;
LineHeight := TSynEdit(FEdit).LineHeight;
LineHeight := TSynEdit(SynEdit).LineHeight;
LineOffset := 0;
if (FirstLine > 0) and (FFoldView.FoldType[FirstLine-1] = cfEnd) then
LineOffset := 2;
BoxSize := Min(Width, LineHeight - cNodeOffset*2);
if MarkupInfoCodeFoldingTree.Background <> clNone then
if MarkupInfo.Background <> clNone then
begin
Canvas.Brush.Color := MarkupInfoCodeFoldingTree.Background;
Canvas.Brush.Color := MarkupInfo.Background;
{$IFDEF SYN_LAZARUS}
LCLIntf.SetBkColor(Canvas.Handle, Canvas.Brush.Color);
{$ENDIF}
@ -162,7 +154,7 @@ begin
with Canvas do
begin
Pen.Color := MarkupInfoCodeFoldingTree.Foreground;
Pen.Color := MarkupInfo.Foreground;
Pen.Width := 1;
rcLine.Bottom := FirstLine * LineHeight;

View File

@ -14,10 +14,8 @@ type
TSynGutterLineNumber = class(TSynGutterPartBase)
private
FEdit: TSynEditBase;
FFoldView: TSynEditFoldedView;
FTextDrawer: TheTextDrawer;
FMarkupInfoLineNumber: TSynSelectedColor;
FDigitCount: integer;
FAutoSizeDigitCount: integer;
@ -41,7 +39,6 @@ type
procedure AutoSizeDigitCount(LinesCount: integer);
function RealGutterWidth(CharWidth: integer): integer; override;
public
property MarkupInfoLineNumber: TSynSelectedColor read FMarkupInfoLineNumber;
property DigitCount: integer read FDigitCount write SetDigitCount;
property ShowOnlyLineNumbersMultiplesOf: integer
read FShowOnlyLineNumbersMultiplesOf
@ -59,8 +56,7 @@ uses
constructor TSynGutterLineNumber.Create(AOwner : TSynEditBase;
AFoldView : TSynEditFoldedView; ATextDrawer : TheTextDrawer);
begin
inherited Create;
FEdit := AOwner;
inherited Create(AOwner);
FFoldView := AFoldView;
FTextDrawer := ATextDrawer;
@ -69,15 +65,12 @@ begin
FShowOnlyLineNumbersMultiplesOf := 1;
FLeadingZeros := false;
FZeroStart := False;
FMarkupInfoLineNumber := TSynSelectedColor.Create;
FMarkupInfoLineNumber.Background := clNone;
FMarkupInfoLineNumber.Foreground := clNone;
FMarkupInfoLineNumber.OnChange := @DoChange;
MarkupInfo.Background := clNone;
MarkupInfo.Foreground := clNone;
end;
destructor TSynGutterLineNumber.Destroy;
begin
FMarkupInfoLineNumber.Free;
inherited Destroy;
end;
@ -93,7 +86,6 @@ begin
FDigitCount := Src.FDigitCount;
FAutoSizeDigitCount := Src.FAutoSizeDigitCount;
FShowOnlyLineNumbersMultiplesOf := Src.FShowOnlyLineNumbersMultiplesOf;
FMarkupInfoLineNumber.Assign(Src.MarkupInfoLineNumber);
end;
inherited;
end;
@ -201,27 +193,27 @@ var
begin
if not Visible then exit;
LineHeight := TSynEdit(FEdit).LineHeight;
LineHeight := TSynEdit(SynEdit).LineHeight;
// Changed to use fTextDrawer.BeginDrawing and fTextDrawer.EndDrawing only
// when absolutely necessary. Note: Never change brush / pen / font of the
// canvas inside of this block (only through methods of fTextDrawer)!
Canvas.Brush.Color := Color;
dc := Canvas.Handle;
{$IFDEF SYN_LAZARUS}
LCLIntf.SetBkColor(dc,Canvas.Brush.Color);
LCLIntf.SetBkColor(dc, Canvas.Brush.Color);
{$ENDIF}
fTextDrawer.BeginDrawing(dc);
try
if MarkupInfoLineNumber.Background <> clNone then
fTextDrawer.SetBackColor(MarkupInfoLineNumber.Background)
if MarkupInfo.Background <> clNone then
FTextDrawer.SetBackColor(MarkupInfo.Background)
else
fTextDrawer.SetBackColor(Color);
if MarkupInfoLineNumber.Foreground <> clNone then
fTextDrawer.SetForeColor(MarkupInfoLineNumber.Foreground)
FTextDrawer.SetBackColor(Color);
if MarkupInfo.Foreground <> clNone then
fTextDrawer.SetForeColor(MarkupInfo.Foreground)
else
fTextDrawer.SetForeColor(TSynEdit(FEdit).Font.Color);
fTextDrawer.SetFrameColor(MarkupInfoLineNumber.FrameColor);
fTextDrawer.Style := MarkupInfoLineNumber.Style;
fTextDrawer.SetForeColor(TSynEdit(SynEdit).Font.Color);
fTextDrawer.SetFrameColor(MarkupInfo.FrameColor);
fTextDrawer.Style := MarkupInfo.Style;
// prepare the rect initially
rcLine := AClip;
rcLine.Bottom := FirstLine * LineHeight;
@ -234,8 +226,8 @@ begin
// line number is not the first, the last, the current line
// or a multiple of ShowOnlyLineNumbersMultiplesOf
ShowDot := ((iLine mod ShowOnlyLineNumbersMultiplesOf) <> 0)
and (iLine <> TSynEdit(FEdit).CaretY) and (iLine <> 1)
and (iLine <> TSynEdit(FEdit).Lines.Count);
and (iLine <> TSynEdit(SynEdit).CaretY) and (iLine <> 1)
and (iLine <> TSynEdit(SynEdit).Lines.Count);
// Get the formatted line number or dot
s := FormatLineNumber(iLine, ShowDot);
Inc(rcLine.Bottom, LineHeight);
@ -254,7 +246,7 @@ begin
end;
// restore original style
fTextDrawer.SetBackColor(Color);
fTextDrawer.SetForeColor(TSynEdit(FEdit).Font.Color);
fTextDrawer.SetForeColor(TSynEdit(SynEdit).Font.Color);
fTextDrawer.SetFrameColor(clNone);
if AClip.Left < rcLine.Left then
begin

View File

@ -14,7 +14,6 @@ type
TSynGutterMarks = class(TSynGutterPartBase)
private
FEdit: TSynEditBase;
FFoldView: TSynEditFoldedView;
FBookMarkOpt: TSynBookMarkOpt;
FInternalImage: TSynInternalImage;
@ -26,7 +25,6 @@ type
procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer);
override;
function RealGutterWidth(CharWidth: integer): integer; override;
public
end;
implementation
@ -39,8 +37,7 @@ uses
constructor TSynGutterMarks.Create(AOwner : TSynEditBase;
AFoldView : TSynEditFoldedView; ABookMarkOpt: TSynBookMarkOpt);
begin
inherited Create;
FEdit := AOwner;
inherited Create(AOwner);
FFoldView := AFoldView;
FBookMarkOpt := ABookMarkOpt;
@ -76,8 +73,8 @@ var
CurMark: TSynEditMark;
begin
iTop := 0;
CurMark := TSynEdit(FEdit).Marks[iMark];
if (CurMark.Line<1) or (CurMark.Line>TSynEdit(FEdit).Lines.Count) then exit;
CurMark := TSynEdit(SynEdit).Marks[iMark];
if (CurMark.Line<1) or (CurMark.Line>TSynEdit(SynEdit).Lines.Count) then exit;
if FFoldView.FoldedAtTextIndex[CurMark.Line-1] then exit;
iLine := FFoldView.TextIndexToScreenLine(CurMark.Line-1);
@ -114,7 +111,7 @@ var
begin
if not Visible then exit;
LineHeight := TSynEdit(FEdit).LineHeight;
LineHeight := TSynEdit(SynEdit).LineHeight;
Canvas.Brush.Color := Color;
dc := Canvas.Handle;
{$IFDEF SYN_LAZARUS}
@ -123,7 +120,7 @@ begin
// now the gutter marks
if FBookMarkOpt.GlyphsVisible and (TSynEdit(FEdit).Marks.Count > 0)
if FBookMarkOpt.GlyphsVisible and (TSynEdit(SynEdit).Marks.Count > 0)
and (LastLine >= FirstLine)
then begin
aGutterOffs := AllocMem((LastLine+1{$IFNDEF SYN_LAZARUS}-TopLine{$ENDIF}) * SizeOf(integer));
@ -131,7 +128,7 @@ begin
// Instead of making a two pass loop we look while drawing the bookmarks
// whether there is any other mark to be drawn
bHasOtherMarks := FALSE;
for i := 0 to TSynEdit(FEdit).Marks.Count - 1 do with TSynEdit(FEdit).Marks[i] do
for i := 0 to TSynEdit(SynEdit).Marks.Count - 1 do with TSynEdit(SynEdit).Marks[i] do
{$IFDEF SYN_LAZARUS}
if Visible and (Line >= FFoldView.TextIndex[FirstLine]+1) and (Line <= FFoldView.TextIndex[LastLine]+1) then
{$ELSE}
@ -144,7 +141,7 @@ begin
DrawMark(i);
end;
if bHasOtherMarks then
for i := 0 to TSynEdit(FEdit).Marks.Count - 1 do with TSynEdit(FEdit).Marks[i] do
for i := 0 to TSynEdit(SynEdit).Marks.Count - 1 do with TSynEdit(SynEdit).Marks[i] do
begin
if Visible and (IsBookmark <> FBookMarkOpt.DrawBookmarksFirst) //mh 2000-10-12
{$IFDEF SYN_LAZARUS}