1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
|
unit SynGutterBase;
{$I synedit.inc}
interface
uses
Classes, SysUtils, math,
// LCL
LCLProc, Graphics, Controls, Menus,
// LazUtils
LazMethodList,
// SynEdit
SynEditMarks, SynEditMiscClasses, SynTextDrawer, SynEditMouseCmds, SynEditFoldedView;
type
TGutterClickEvent = procedure(Sender: TObject; X, Y, Line: integer;
mark: TSynEditMark) of object;
TSynGutterPartBase = class;
TSynGutterPartBaseClass = class of TSynGutterPartBase;
TSynGutterPartListBase = class;
{ TSynGutterBase }
TSynGutterSide = (gsLeft, gsRight);
TSynGutterBase = class(TPersistent)
private
FGutterPartList: TSynGutterPartListBase;
FSide: TSynGutterSide;
FSynEdit: TSynEditBase;
FTextDrawer: TheTextDrawer;
FColor: TColor;
FLeft, FWidth, FHeight, FTop: Integer;
FVisible: boolean;
FAutoSize: boolean;
FRightOffset, FLeftOffset: integer;
FInDoChange: Boolean;
FChangeLock: Integer;
FNeedOnChange, FNeedOnResize: Boolean;
FFlags: set of (gfNeedChildBounds);
FOnResize: TNotifyEvent;
FOnChange: TNotifyEvent;
FMouseActions: TSynEditMouseInternalActions;
FOnResizeHandler: TMethodList;
FOnChangeHandler: TMethodList;
function GetMouseActions: TSynEditMouseActions;
procedure SetAutoSize(const AValue: boolean);
procedure SetColor(const Value: TColor);
procedure SetGutterParts(const AValue: TSynGutterPartListBase);
procedure SetLeftOffset(const AValue: integer);
procedure SetMouseActions(const AValue: TSynEditMouseActions);
procedure SetRightOffset(const AValue: integer);
procedure SetVisible(const AValue: boolean);
procedure SetWidth(Value: integer);
protected
procedure SetChildBounds;
procedure DoChange(Sender: TObject);
procedure DoResize(Sender: TObject);
procedure IncChangeLock;
procedure DecChangeLock;
procedure DoDefaultGutterClick(Sender: TObject; X, Y, Line: integer;
mark: TSynEditMark); virtual;
procedure RegisterNewGutterPartList(APartList: TSynGutterPartListBase);
function PartCount: integer;
function CreatePartList: TSynGutterPartListBase; virtual; abstract;
function CreateMouseActions: TSynEditMouseInternalActions; virtual;
procedure Clear;
function GetOwner: TPersistent; override;
public
constructor Create(AOwner : TSynEditBase; ASide: TSynGutterSide; ATextDrawer: TheTextDrawer);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure RecalcBounds;
procedure ScalePPI(const AScaleFactor: Double);
procedure DoAutoSize;
function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean; virtual;
procedure ResetMouseActions; virtual; // set mouse-actions according to current Options / may clear them
procedure RegisterResizeHandler(AHandler: TNotifyEvent);
procedure UnregisterResizeHandler(AHandler: TNotifyEvent);
procedure RegisterChangeHandler(AHandler: TNotifyEvent);
procedure UnregisterChangeHandler(AHandler: TNotifyEvent);
property Left: Integer read FLeft;
property Top: Integer read FTop;
property Height:Integer read FHeight;
property Width: integer read FWidth write SetWidth;
property Side:TSynGutterSide read FSide;
property AutoSize: boolean read FAutoSize write SetAutoSize default True;
property Visible: boolean read FVisible write SetVisible default True;
property LeftOffset: integer read FLeftOffset write SetLeftOffset
default 0;
property RightOffset: integer read FRightOffset write SetRightOffset
default 0;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnResize: TNotifyEvent read FOnResize write FOnResize;
public
property Parts: TSynGutterPartListBase read FGutterPartList write SetGutterParts;
public
// properties available for the GutterPartClasses
property SynEdit: TSynEditBase read FSynEdit;
property TextDrawer: TheTextDrawer read FTextDrawer;
property Color: TColor read FColor write SetColor default clBtnFace;
property MouseActions: TSynEditMouseActions
read GetMouseActions write SetMouseActions;
end;
{ TSynGutterPartListBase }
TSynGutterPartListBase = class(TSynObjectList)
private
FGutter: TSynGutterBase;
function GetByClass(AClass: TSynGutterPartBaseClass; Index: Integer): TSynGutterPartBase;
function GetByClassCount(AClass: TSynGutterPartBaseClass): Integer;
function GetPart(Index: Integer): TSynGutterPartBase;
function GetSynEdit: TSynEditBase;
procedure PutPart(Index: Integer; const AValue: TSynGutterPartBase);
protected
function FindGutter: TSynGutterBase; virtual; abstract;
procedure RegisterItem(AnItem: TSynObjectListItem); override;
property Gutter: TSynGutterBase read FGutter;
property SynEdit:TSynEditBase read GetSynEdit;
public
constructor Create(AOwner: TComponent); override;
constructor Create(AOwner: TComponent; AGutter: TSynGutterBase);
destructor Destroy; override;
property Part[Index: Integer]: TSynGutterPartBase
read GetPart write PutPart; default;
property ByClassCount[AClass: TSynGutterPartBaseClass]: Integer
read GetByClassCount;
property ByClass[AClass: TSynGutterPartBaseClass; Index: Integer]: TSynGutterPartBase
read GetByClass;
end;
{ TSynGutterPartList
GutterPartList for the left side Gutter. Historically the left Gutter is reffered to as Gutter without prefix }
TSynGutterPartList = class(TSynGutterPartListBase)
protected
function FindGutter: TSynGutterBase; override;
end;
{ TSynRightGutterPartList
GutterPartList for the right side Gutter. }
TSynRightGutterPartList = class(TSynGutterPartListBase)
protected
function FindGutter: TSynGutterBase; override;
end;
{ TSynGutterPartBase }
TSynGutterPartBase = class(TSynObjectListItem)
private
FLeft, FWidth, FHeight, FTop: Integer;
FAutoSize : boolean;
FVisible: Boolean;
FSynEdit: TSynEditBase;
FGutter: TSynGutterBase;
FMarkupInfo: TSynSelectedColor;
FCursor: TCursor;
FOnChange: TNotifyEvent;
FOnGutterClick: TGutterClickEvent;
FMouseActions: TSynEditMouseInternalActions;
function GetFoldView: TSynEditFoldedView;
function GetGutterParts: TSynGutterPartListBase;
function GetMouseActions: TSynEditMouseActions;
procedure SetMarkupInfo(const AValue: TSynSelectedColor);
procedure SetMouseActions(const AValue: TSynEditMouseActions);
protected
function CreateMouseActions: TSynEditMouseInternalActions; virtual;
function Scale96ToFont(const ASize: Integer): Integer;
function PreferedWidth: Integer; virtual; // at PPI 96
function PreferedWidthAtCurrentPPI: Integer; virtual;
procedure SetBounds(ALeft, ATop, AHeight: Integer);
procedure DoAutoSize;
procedure SetAutoSize(const AValue : boolean); virtual;
procedure SetVisible(const AValue : boolean); virtual;
procedure GutterVisibilityChanged; virtual;
procedure SetWidth(const AValue : integer); virtual;
procedure Init; override;
procedure VisibilityOrSize(aCallDoChange: Boolean = False);
procedure DoResize(Sender: TObject); virtual;
procedure DoChange(Sender: TObject); virtual;
property GutterParts: TSynGutterPartListBase read GetGutterParts;
property Gutter: TSynGutterBase read FGutter;
property SynEdit:TSynEditBase read FSynEdit;
property FoldView: TSynEditFoldedView read GetFoldView;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property Left: Integer read FLeft;
property Top: Integer read FTop;
property Height:Integer read FHeight;
procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer);
virtual abstract;
procedure ScalePPI(const AScaleFactor: Double); virtual;
public
// X/Y are relative to the gutter, not the gutter part
function HasCustomPopupMenu(out PopMenu: TPopupMenu): Boolean; virtual;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean; virtual;
function DoHandleMouseAction(AnAction: TSynEditMouseAction;
var AnInfo: TSynEditMouseActionInfo): Boolean; virtual;
procedure ResetMouseActions; virtual; // set mouse-actions according to current Options / may clear them
procedure DoOnGutterClick(X, Y: integer); virtual;
property OnGutterClick: TGutterClickEvent
read FOnGutterClick write FOnGutterClick;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Cursor: TCursor read FCursor write FCursor default crDefault;
property MarkupInfo: TSynSelectedColor read FMarkupInfo write SetMarkupInfo;
published
property AutoSize: boolean read FAutoSize write SetAutoSize default True;
property Width: integer read FWidth write SetWidth default 10;
property Visible: boolean read FVisible write SetVisible default True;
property MouseActions: TSynEditMouseActions
read GetMouseActions write SetMouseActions;
end;
implementation
uses SynEdit;
{ TSynGutterBase }
constructor TSynGutterBase.Create(AOwner: TSynEditBase; ASide: TSynGutterSide;
ATextDrawer: TheTextDrawer);
begin
FOnResizeHandler := TMethodList.Create;
FOnChangeHandler := TMethodList.Create;
inherited Create;
FSide := ASide;
FSynEdit := AOwner;
CreatePartList;
FMouseActions := CreateMouseActions;
FInDoChange := False;
FChangeLock := 0;
FTextDrawer := ATextDrawer;
FWidth := -1;
FLeftOffset := 0;
FRightOffset := 0;
FColor := clBtnFace;
FVisible := True;
AutoSize := True;
end;
destructor TSynGutterBase.Destroy;
begin
FOnChange := nil;
FOnResize := nil;
FreeAndNil(FGutterPartList);
FreeAndNil(FMouseActions);
FreeAndNil(FOnChangeHandler);
FreeAndNil(FOnResizeHandler);
inherited Destroy;
end;
procedure TSynGutterBase.Assign(Source: TPersistent);
begin
if Source is TSynGutterBase then
begin
IncChangeLock;
try
FGutterPartList.Assign(TSynGutterBase(Source).FGutterPartList);
Color := TSynGutterBase(Source).FColor;
Visible := TSynGutterBase(Source).FVisible;
AutoSize := TSynGutterBase(Source).FAutoSize;
Width := TSynGutterBase(Source).FWidth;
LeftOffset := TSynGutterBase(Source).FLeftOffset;
RightOffset := TSynGutterBase(Source).FRightOffset;
finally
DecChangeLock;
end;
end else
inherited;
end;
procedure TSynGutterBase.RecalcBounds;
var
NewTop, NewLeft, NewHeight: Integer;
begin
// gutters act as alLeft or alRight, so Width is not computed here
NewTop := 0;
case FSide of
gsLeft:
begin
NewLeft := 0;
NewHeight := SynEdit.ClientHeight;
end;
gsRight:
begin
NewLeft := SynEdit.ClientWidth - Width - ScrollBarWidth;
NewHeight := SynEdit.ClientHeight;
end;
end;
if (NewLeft = FLeft) and (NewTop = FTop) and (NewHeight = FHeight) then
exit;
FLeft := NewLeft;
FTop := NewTop;
FHeight := NewHeight;
//Resize parts
IncChangeLock;
try
SetChildBounds;
DoResize(Self);
finally
DecChangeLock;
end;
end;
function TSynGutterBase.MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean;
begin
Result := HandleActionProc(FMouseActions.GetActionsForOptions(TCustomSynEdit(SynEdit).MouseOptions), AnInfo);
end;
procedure TSynGutterBase.ResetMouseActions;
begin
FMouseActions.Options := TCustomSynEdit(SynEdit).MouseOptions;
FMouseActions.ResetUserActions;
end;
procedure TSynGutterBase.ScalePPI(const AScaleFactor: Double);
var
I: Integer;
begin
for I := 0 to PartCount-1 do
Parts[I].ScalePPI(AScaleFactor);
end;
procedure TSynGutterBase.RegisterResizeHandler(AHandler: TNotifyEvent);
begin
FOnResizeHandler.Add(TMethod(AHandler));
end;
procedure TSynGutterBase.UnregisterResizeHandler(AHandler: TNotifyEvent);
begin
FOnResizeHandler.Remove(TMethod(AHandler));
end;
procedure TSynGutterBase.RegisterChangeHandler(AHandler: TNotifyEvent);
begin
FOnChangeHandler.Add(TMethod(AHandler));
end;
procedure TSynGutterBase.UnregisterChangeHandler(AHandler: TNotifyEvent);
begin
FOnChangeHandler.Remove(TMethod(AHandler));
end;
procedure TSynGutterBase.SetColor(const Value: TColor);
begin
if FColor <> Value then
begin
FColor := Value;
DoChange(Self);
end;
end;
procedure TSynGutterBase.SetAutoSize(const AValue: boolean);
begin
if FAutoSize = AValue then exit;
FAutoSize := AValue;
if FAutoSize then
DoAutoSize;
end;
function TSynGutterBase.GetMouseActions: TSynEditMouseActions;
begin
Result := FMouseActions.UserActions;
end;
procedure TSynGutterBase.SetGutterParts(const AValue: TSynGutterPartListBase);
begin
FGutterPartList.Assign(AValue);
end;
procedure TSynGutterBase.SetLeftOffset(const AValue: integer);
begin
if FLeftOffset <> AValue then
begin
FLeftOffset := Max(0, AValue);
DoChange(Self);
end;
end;
procedure TSynGutterBase.SetMouseActions(const AValue: TSynEditMouseActions);
begin
FMouseActions.UserActions := AValue;
end;
procedure TSynGutterBase.SetRightOffset(const AValue: integer);
begin
if FRightOffset <> AValue then
begin
FRightOffset := Max(0, AValue);
DoChange(Self);
end;
end;
procedure TSynGutterBase.SetVisible(const AValue: boolean);
var
i: Integer;
begin
if FVisible <> AValue then
begin
FVisible := AValue;
DoResize(Self);
DoChange(Self);
for i := 0 to PartCount - 1 do
Parts[i].GutterVisibilityChanged;
end;
end;
procedure TSynGutterBase.SetWidth(Value: integer);
begin
Value := Max(0, Value);
if (FWidth=Value) or (FAutoSize) then exit;
FWidth := Value;
DoResize(Self);
end;
procedure TSynGutterBase.DoAutoSize;
var
NewWidth, i: Integer;
begin
NewWidth := FLeftOffset + FRightOffset;
for i := PartCount-1 downto 0 do
if Parts[i].Visible then
begin
if Parts[i].AutoSize then
Parts[i].DoAutoSize;
NewWidth := NewWidth + Parts[i].Width;
end;
if FWidth = NewWidth then exit;
IncChangeLock;
try
FWidth := NewWidth;
Include(FFlags, gfNeedChildBounds);
RecalcBounds;
if gfNeedChildBounds in FFlags then
SetChildBounds;
DoResize(Self);
finally
DecChangeLock;
end;
end;
procedure TSynGutterBase.SetChildBounds;
var
i, NewLeft: Integer;
begin
NewLeft := Left + LeftOffset;
for i := 0 to PartCount - 1 do
if Parts[i].Visible then begin
Parts[i].SetBounds(NewLeft, Top, Height);
NewLeft := NewLeft + Parts[i].Width;
end;
Exclude(FFlags, gfNeedChildBounds);
end;
function TSynGutterBase.PartCount: integer;
begin
if FGutterPartList <> nil then
result := FGutterPartList.Count
else
Result := 0;
end;
function TSynGutterBase.CreateMouseActions: TSynEditMouseInternalActions;
begin
Result := TSynEditMouseInternalActions.Create(Self);
end;
procedure TSynGutterBase.DoChange(Sender: TObject);
begin
if FInDoChange then exit;
if FChangeLock > 0 then begin;
FNeedOnChange := True;
exit;
end;
FNeedOnChange := False;
If FAutoSize then begin
FInDoChange := True;
try
DoAutoSize;
finally
FInDoChange := False;
end;
end;
FOnChangeHandler.CallNotifyEvents(Self);
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TSynGutterBase.DoResize(Sender: TObject);
begin
if FChangeLock > 0 then begin;
FNeedOnResize := True;
exit;
end;
FNeedOnResize := False;
FOnResizeHandler.CallNotifyEvents(Self);
if Assigned(FOnResize) then
FOnResize(Self)
else
DoChange(Self);
end;
procedure TSynGutterBase.IncChangeLock;
begin
inc(FChangeLock);
end;
procedure TSynGutterBase.DecChangeLock;
begin
dec(FChangeLock);
if FChangeLock = 0 then begin
if FNeedOnResize then
DoResize(Self);
if FNeedOnChange then
DoChange(Self);
end;
end;
procedure TSynGutterBase.DoDefaultGutterClick(Sender: TObject; X, Y, Line: integer; mark: TSynEditMark);
begin
end;
procedure TSynGutterBase.RegisterNewGutterPartList(APartList: TSynGutterPartListBase);
begin
if (APartList = nil) or (APartList = FGutterPartList) then
exit;
if FGutterPartList <> nil then
FreeAndNil(FGutterPartList);
FGutterPartList := APartList;
FGutterPartList.OnChange := @DoChange;
end;
procedure TSynGutterBase.Clear;
var
i: Integer;
begin
if FGutterPartList = nil then exit;
for i := FGutterPartList.Count - 1 downto 0 do
FGutterPartList[i].Free;
FGutterPartList.Clear;
end;
function TSynGutterBase.GetOwner: TPersistent;
begin
Result := FSynEdit;
end;
{ TSynGutterPartBase }
function TSynGutterPartBase.GetGutterParts: TSynGutterPartListBase;
begin
Result := TSynGutterPartListBase(Owner);
end;
function TSynGutterPartBase.GetMouseActions: TSynEditMouseActions;
begin
Result := FMouseActions.UserActions;
end;
function TSynGutterPartBase.GetFoldView: TSynEditFoldedView;
begin
Result := TSynEditFoldedView(FoldedTextBuffer);
end;
procedure TSynGutterPartBase.SetMarkupInfo(const AValue: TSynSelectedColor);
begin
FMarkupInfo.Assign(AValue);
end;
procedure TSynGutterPartBase.SetMouseActions(const AValue: TSynEditMouseActions);
begin
FMouseActions.UserActions := AValue;
end;
function TSynGutterPartBase.PreferedWidth: Integer;
begin
Result := 12;
end;
function TSynGutterPartBase.PreferedWidthAtCurrentPPI: Integer;
begin
Result := Scale96ToFont(PreferedWidth);
end;
procedure TSynGutterPartBase.SetBounds(ALeft, ATop, AHeight: Integer);
begin
if (ALeft = FLeft) and (ATop = FTop) and (AHeight = FHeight) then
exit;
FLeft := ALeft;
FTop := ATop;
FHeight := AHeight;
DoResize(Self);
end;
procedure TSynGutterPartBase.DoAutoSize;
var
NewWidth: Integer;
begin
NewWidth := PreferedWidthAtCurrentPPI;
if FWidth = NewWidth then exit;
FWidth := NewWidth;
VisibilityOrSize;
end;
procedure TSynGutterPartBase.SetAutoSize(const AValue : boolean);
var
OldSize: Integer;
begin
if FAutoSize=AValue then exit;
FAutoSize:=AValue;
OldSize := FWidth;
if FAutoSize then
DoAutoSize;
if FWidth = OldSize then
DoChange(Self); // Size Did not Change
end;
procedure TSynGutterPartBase.SetVisible(const AValue : boolean);
begin
if FVisible=AValue then exit;
FVisible:=AValue;
VisibilityOrSize(True);
end;
procedure TSynGutterPartBase.GutterVisibilityChanged;
begin
//
end;
procedure TSynGutterPartBase.SetWidth(const AValue : integer);
begin
if (FWidth=AValue) or (FAutoSize) then exit;
FWidth:=AValue;
VisibilityOrSize;
end;
procedure TSynGutterPartBase.DoChange(Sender : TObject);
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
function TSynGutterPartBase.CreateMouseActions: TSynEditMouseInternalActions;
begin
Result := TSynEditMouseInternalActions.Create(Self);
end;
function TSynGutterPartBase.Scale96ToFont(const ASize: Integer): Integer;
begin
Result := ASize;
if SynEdit<>nil then
Result := SynEdit.Scale96ToFont(Result);
end;
constructor TSynGutterPartBase.Create(AOwner: TComponent);
begin
FMarkupInfo := TSynSelectedColor.Create;
FMarkupInfo.Background := clBtnFace;
FMarkupInfo.Foreground := clNone;
FMarkupInfo.FrameColor := clNone;
FMarkupInfo.OnChange := @DoChange;
FMouseActions := CreateMouseActions;
FVisible := True;
FAutoSize := True;
Inherited Create(AOwner); // Todo: Lock the DoChange from RegisterItem, and call DoChange at the end (after/in autosize)
end;
procedure TSynGutterPartBase.Init;
begin
inherited Init;
FGutter := GutterParts.Gutter;
FSynEdit := GutterParts.SynEdit;
FriendEdit := FSynEdit;
end;
procedure TSynGutterPartBase.VisibilityOrSize(aCallDoChange: Boolean);
begin
Gutter.IncChangeLock;
try
if Gutter.AutoSize then
Gutter.DoAutoSize; // Calculate new total width of gutter
DoResize(Self);
if aCallDoChange then
DoChange(Self);
finally
Gutter.DecChangeLock;
end;
end;
procedure TSynGutterPartBase.DoResize(Sender: TObject);
begin
DoChange(Sender);
end;
destructor TSynGutterPartBase.Destroy;
begin
inherited Destroy;
FreeAndNil(FMouseActions);
FreeAndNil(FMarkupInfo);
end;
procedure TSynGutterPartBase.Assign(Source : TPersistent);
var
Src: TSynGutterPartBase;
begin
if Source is TSynGutterPartBase then
begin
Src := TSynGutterPartBase(Source);
FVisible := Src.FVisible;
FWidth := Src.FWidth;
FAutoSize := Src.FAutoSize;
MarkupInfo.Assign(Src.MarkupInfo);
DoChange(Self);
// Todo, maybe on Resize?
end else
inherited;
end;
function TSynGutterPartBase.HasCustomPopupMenu(out PopMenu: TPopupMenu): Boolean;
begin
Result := False;
end;
procedure TSynGutterPartBase.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
end;
procedure TSynGutterPartBase.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
end;
procedure TSynGutterPartBase.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
end;
function TSynGutterPartBase.MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean;
begin
Result := HandleActionProc(FMouseActions.GetActionsForOptions(TCustomSynEdit(SynEdit).MouseOptions), AnInfo);
end;
function TSynGutterPartBase.DoHandleMouseAction(AnAction: TSynEditMouseAction;
var AnInfo: TSynEditMouseActionInfo): Boolean;
begin
Result := False;
end;
procedure TSynGutterPartBase.ResetMouseActions;
begin
FMouseActions.Options := TCustomSynEdit(SynEdit).MouseOptions;
FMouseActions.ResetUserActions;
end;
procedure TSynGutterPartBase.ScalePPI(const AScaleFactor: Double);
begin
if not FAutoSize then
Width := Round(Width*AScaleFactor)
else
DoAutoSize;
end;
procedure TSynGutterPartBase.DoOnGutterClick(X, Y : integer);
begin
if Assigned(FOnGutterClick) then
FOnGutterClick(Self, X, Y, 0, nil);
end;
{ TSynGutterPartListBase }
constructor TSynGutterPartListBase.Create(AOwner: TComponent);
begin
Inherited Create(AOwner);
include(FComponentStyle, csTransient);
if FindGutter <> nil then
FGutter := FindGutter;
Gutter.RegisterNewGutterPartList(self);
end;
constructor TSynGutterPartListBase.Create(AOwner: TComponent; AGutter: TSynGutterBase);
begin
FGutter := AGutter;
Create(AOwner);
end;
destructor TSynGutterPartListBase.Destroy;
begin
FGutter.FGutterPartList := nil;
OnChange := nil;
inherited Destroy;
end;
procedure TSynGutterPartListBase.RegisterItem(AnItem: TSynObjectListItem);
begin
TSynGutterPartBase(AnItem).OnChange := @DoChange;
TSynGutterPartBase(AnItem).OnGutterClick := @Gutter.DoDefaultGutterClick;
inherited RegisterItem(AnItem);
end;
function TSynGutterPartListBase.GetSynEdit: TSynEditBase;
begin
Result := TSynEditBase(Owner);
end;
function TSynGutterPartListBase.GetPart(Index: Integer): TSynGutterPartBase;
begin
Result := TSynGutterPartBase(BaseItems[Index]);
end;
procedure TSynGutterPartListBase.PutPart(Index: Integer; const AValue: TSynGutterPartBase);
begin
BaseItems[Index] := TSynObjectListItem(AValue);
end;
function TSynGutterPartListBase.GetByClass(AClass: TSynGutterPartBaseClass; Index: Integer): TSynGutterPartBase;
var
i: Integer;
begin
for i := 0 to Count -1 do
if Part[i] is AClass then begin
if Index = 0 then
exit(Part[i]);
dec(Index);
end;
Result := nil;
end;
function TSynGutterPartListBase.GetByClassCount(AClass: TSynGutterPartBaseClass): Integer;
var
i: Integer;
begin
Result := 0;
for i := 0 to Count -1 do
if Part[i] is AClass then
inc(Result);
end;
{ TSynGutterPartList }
function TSynGutterPartList.FindGutter: TSynGutterBase;
begin
Result := TCustomSynEdit(SynEdit).Gutter;
end;
{ TSynRightGutterPartList }
function TSynRightGutterPartList.FindGutter: TSynGutterBase;
begin
Result := TCustomSynEdit(SynEdit).RightGutter;
end;
end.
|