mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 03:21:24 +02:00
parent
6fe5b10fcc
commit
9fea3ea40c
@ -27,8 +27,9 @@ unit SynGutterCodeFolding;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, Classes, Controls, Graphics, Menus, LCLIntf, SynGutterBase, SynEditMiscProcs,
|
SysUtils, Classes, Controls, Graphics, Menus, LCLIntf, SynGutterBase,
|
||||||
SynEditFoldedView, SynEditMouseCmds, SynEditHighlighterFoldBase, LCLProc, LCLType, ImgList;
|
SynEditMiscProcs, SynEditFoldedView, SynEditMouseCmds,
|
||||||
|
SynEditHighlighterFoldBase, LCLProc, LCLType, ImgList, Forms;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -59,6 +60,11 @@ type
|
|||||||
|
|
||||||
TDrawNodeSymbolOptions = set of (nsoSubtype, nsoLostHl, nsoBlockSel);
|
TDrawNodeSymbolOptions = set of (nsoSubtype, nsoLostHl, nsoBlockSel);
|
||||||
|
|
||||||
|
TSynGutterImageList = class(TImageList)
|
||||||
|
public
|
||||||
|
InitPPI: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TSynGutterCodeFolding }
|
{ TSynGutterCodeFolding }
|
||||||
|
|
||||||
TSynGutterCodeFolding = class(TSynGutterPartBase)
|
TSynGutterCodeFolding = class(TSynGutterPartBase)
|
||||||
@ -68,8 +74,9 @@ type
|
|||||||
FPopUp: TPopupMenu;
|
FPopUp: TPopupMenu;
|
||||||
FMenuInf: Array of TFoldViewNodeInfo;
|
FMenuInf: Array of TFoldViewNodeInfo;
|
||||||
FIsFoldHidePreviousLine: Boolean;
|
FIsFoldHidePreviousLine: Boolean;
|
||||||
FPopUpImageList: TImageList;
|
FPopUpImageList: TSynGutterImageList;
|
||||||
FReversePopMenuOrder: Boolean;
|
FReversePopMenuOrder: Boolean;
|
||||||
|
procedure FPopUpOnPopup(Sender: TObject);
|
||||||
function GetMouseActionsCollapsed: TSynEditMouseActions;
|
function GetMouseActionsCollapsed: TSynEditMouseActions;
|
||||||
function GetMouseActionsExpanded: TSynEditMouseActions;
|
function GetMouseActionsExpanded: TSynEditMouseActions;
|
||||||
procedure SetMouseActionsCollapsed(const AValue: TSynEditMouseActions);
|
procedure SetMouseActionsCollapsed(const AValue: TSynEditMouseActions);
|
||||||
@ -77,7 +84,7 @@ type
|
|||||||
function FoldTypeForLine(AScreenLine: Integer): TSynEditFoldLineCapability;
|
function FoldTypeForLine(AScreenLine: Integer): TSynEditFoldLineCapability;
|
||||||
function IsFoldHidePreviousLine(AScreenLine: Integer): Boolean;
|
function IsFoldHidePreviousLine(AScreenLine: Integer): Boolean;
|
||||||
function IsSingleLineHide(AScreenLine: Integer): Boolean;
|
function IsSingleLineHide(AScreenLine: Integer): Boolean;
|
||||||
procedure InitPopUpImageList;
|
procedure InitPopUpImageList(const APPI: Integer);
|
||||||
procedure DrawNodeSymbol(Canvas: TCanvas; Rect: TRect;
|
procedure DrawNodeSymbol(Canvas: TCanvas; Rect: TRect;
|
||||||
NodeType: TSynEditFoldLineCapability;
|
NodeType: TSynEditFoldLineCapability;
|
||||||
SubType: TDrawNodeSymbolOptions);
|
SubType: TDrawNodeSymbolOptions);
|
||||||
@ -114,7 +121,7 @@ uses
|
|||||||
SynEdit;
|
SynEdit;
|
||||||
|
|
||||||
var
|
var
|
||||||
GlobalPopUpImageList: TImageList = nil;
|
GlobalPopUpImageList: TSynGutterImageList = nil;
|
||||||
|
|
||||||
|
|
||||||
{ TSynGutterCodeFolding }
|
{ TSynGutterCodeFolding }
|
||||||
@ -185,6 +192,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSynGutterCodeFolding.FPopUpOnPopup(Sender: TObject);
|
||||||
|
var
|
||||||
|
MonitorPPI: Integer;
|
||||||
|
begin
|
||||||
|
MonitorPPI := Screen.MonitorFromPoint(FPopUp.PopupPoint).PixelsPerInch;
|
||||||
|
if (FPopUpImageList.Count=0) or (FPopUpImageList.InitPPI<>MonitorPPI) then
|
||||||
|
InitPopUpImageList(MonitorPPI);
|
||||||
|
end;
|
||||||
|
|
||||||
function TSynGutterCodeFolding.IsFoldHidePreviousLine(AScreenLine: Integer): Boolean;
|
function TSynGutterCodeFolding.IsFoldHidePreviousLine(AScreenLine: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
FoldTypeForLine(AScreenLine);
|
FoldTypeForLine(AScreenLine);
|
||||||
@ -205,40 +221,49 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynGutterCodeFolding.InitPopUpImageList;
|
procedure TSynGutterCodeFolding.InitPopUpImageList(const APPI: Integer);
|
||||||
var
|
var
|
||||||
img: TBitmap;
|
img: TBitmap;
|
||||||
|
R: TRect;
|
||||||
procedure NewImg;
|
procedure NewImg;
|
||||||
begin
|
begin
|
||||||
img := TBitmap.Create;
|
img := TBitmap.Create;
|
||||||
img.SetSize(16, 16);
|
img.SetSize(FPopUpImageList.Width, FPopUpImageList.Height);
|
||||||
img.Canvas.Brush.Color := clWhite;
|
img.Canvas.Brush.Color := clWhite;
|
||||||
img.Canvas.FillRect(0,0,16,16);
|
img.Canvas.FillRect(img.Canvas.ClipRect);
|
||||||
img.TransparentColor := clWhite;
|
|
||||||
img.Canvas.Pen.Color := clBlack;
|
img.Canvas.Pen.Color := clBlack;
|
||||||
img.Canvas.Pen.Width := 1;
|
img.Canvas.Pen.Width := 1;
|
||||||
end;
|
end;
|
||||||
begin
|
begin
|
||||||
FPopUpImageList.DrawingStyle := dsTransparent;
|
FPopUpImageList.DrawingStyle := dsTransparent;
|
||||||
|
FPopUpImageList.Clear;
|
||||||
|
FPopUpImageList.Width := MulDiv(16, APPI, 96);
|
||||||
|
FPopUpImageList.Height := FPopUpImageList.Width;
|
||||||
|
FPopUpImageList.InitPPI := APPI;
|
||||||
|
|
||||||
|
R.Left := MulDiv(3, APPI, 96);
|
||||||
|
R.Top := R.Left;
|
||||||
|
R.Right := MulDiv(14, APPI, 96);
|
||||||
|
R.Bottom := R.Right;
|
||||||
|
|
||||||
NewImg;
|
NewImg;
|
||||||
DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfFoldStart, []); // [-]
|
DrawNodeSymbol(img.Canvas, R, cfFoldStart, []); // [-]
|
||||||
FPopUpImageList.Add(img, nil);
|
FPopUpImageList.AddMasked(img, img.TransparentColor);
|
||||||
img.Free;
|
img.Free;
|
||||||
|
|
||||||
NewImg;
|
NewImg;
|
||||||
DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfCollapsedFold, []); // [+]
|
DrawNodeSymbol(img.Canvas, R, cfCollapsedFold, []); // [+]
|
||||||
FPopUpImageList.Add(img, nil);
|
FPopUpImageList.AddMasked(img, img.TransparentColor);
|
||||||
img.Free;
|
img.Free;
|
||||||
|
|
||||||
NewImg;
|
NewImg;
|
||||||
DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfHideStart, []); // [.]
|
DrawNodeSymbol(img.Canvas, R, cfHideStart, []); // [.]
|
||||||
FPopUpImageList.Add(img, nil);
|
FPopUpImageList.AddMasked(img, img.TransparentColor);
|
||||||
img.Free;
|
img.Free;
|
||||||
|
|
||||||
NewImg;
|
NewImg;
|
||||||
DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfCollapsedHide, []); // [v]
|
DrawNodeSymbol(img.Canvas, R, cfCollapsedHide, []); // [v]
|
||||||
FPopUpImageList.Add(img, nil);
|
FPopUpImageList.AddMasked(img, img.TransparentColor);
|
||||||
img.Free;
|
img.Free;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
@ -268,15 +293,15 @@ begin
|
|||||||
if not assigned(GlobalPopUpImageList) then begin
|
if not assigned(GlobalPopUpImageList) then begin
|
||||||
// Todo: Add a flag, when using global list, or make list ref-counted
|
// Todo: Add a flag, when using global list, or make list ref-counted
|
||||||
// See Destroy
|
// See Destroy
|
||||||
GlobalPopUpImageList := TImageList.Create(nil);
|
GlobalPopUpImageList := TSynGutterImageList.Create(nil);
|
||||||
FPopUpImageList := GlobalPopUpImageList;
|
FPopUpImageList := GlobalPopUpImageList;
|
||||||
InitPopUpImageList;
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
FPopUpImageList := GlobalPopUpImageList;
|
FPopUpImageList := GlobalPopUpImageList;
|
||||||
|
|
||||||
APopUp := TPopupMenu.Create(nil);
|
APopUp := TPopupMenu.Create(nil);
|
||||||
APopUp.Images := FPopUpImageList;
|
APopUp.Images := FPopUpImageList;
|
||||||
|
APopUp.OnPopup := @FPopUpOnPopup;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
APopUp.Items.Clear;
|
APopUp.Items.Clear;
|
||||||
|
@ -1042,7 +1042,7 @@ var
|
|||||||
begin
|
begin
|
||||||
if FFirstTextLineChanged > 0 then ReScan;
|
if FFirstTextLineChanged > 0 then ReScan;
|
||||||
|
|
||||||
AClip.Right := Round((AClip.Right - AClip.Left) / 3);
|
AClip.Right := AClip.Left + Round((AClip.Right - AClip.Left) / 3);
|
||||||
i := AClip.Top - TopOffset;
|
i := AClip.Top - TopOffset;
|
||||||
imax := AClip.Bottom - TopOffset;
|
imax := AClip.Bottom - TopOffset;
|
||||||
if imax > high(FPixLineStates) then imax := high(FPixLineStates);
|
if imax > high(FPixLineStates) then imax := high(FPixLineStates);
|
||||||
|
Loading…
Reference in New Issue
Block a user