unit usListMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ecSyntAnal, ecSyntMemo, ImgList;

type
  TForm1 = class(TForm)
    SyntaxMemo1: TSyntaxMemo;
    SyntStyles1: TSyntStyles;
    ImageList1: TImageList;
    procedure SyntaxMemo1TGutterObjects0CheckLine(Sender: TObject;
      Line: Integer; var Show: Boolean);
    procedure SyntaxMemo1TGutterObjects1CheckLine(Sender: TObject;
      Line: Integer; var Show: Boolean);
    procedure SyntaxMemo1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SyntaxMemo1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SyntaxMemo1TGutterObjects0Click(Sender: TObject;
      Line: Integer; Shift: TShiftState);
  private
    procedure ClickLine(Line: integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

var
  CheckSel: LongWord = 0;
  RadioSel: LongWord = 0;

implementation

{$R *.dfm}

procedure TForm1.SyntaxMemo1TGutterObjects0CheckLine(Sender: TObject;
  Line: Integer; var Show: Boolean);
begin
  Show := (Line > 0) and (Line < 5);
  if Show then
   with Sender as TCustomGutterObject do
    if RadioSel = Line then ImageIndex := 4
                       else ImageIndex := 3;
end;

procedure TForm1.SyntaxMemo1TGutterObjects1CheckLine(Sender: TObject;
  Line: Integer; var Show: Boolean);
begin
  Show := (Line > 5) and (Line <= 12);
  if Show then
   with Sender as TCustomGutterObject do
    if (CheckSel and (1 shl (Line - 6))) <> 0 then ImageIndex := 1
                                              else ImageIndex := 0;
end;

procedure TForm1.ClickLine(Line: integer);
var t: LongWord;
begin
  if (Line > 0) and (Line < 5) then RadioSel := Line else
  if (Line > 5) and (Line <= 12) then
   begin
    t := 1 shl (Line - 6);
    if (CheckSel and t) <> 0 then CheckSel := CheckSel and (not t)
                             else CheckSel := CheckSel or t;
   end else SyntaxMemo1.ToggleCollapse(Line);
  SyntaxMemo1.Invalidate;
end;

procedure TForm1.SyntaxMemo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_SPACE then
   ClickLine(SyntaxMemo1.CaretPos.Y);
end;

procedure TForm1.SyntaxMemo1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if ssDouble in Shift then
   with SyntaxMemo1 do
    ClickLine(MouseToCaret(X, Y).Y);
end;

procedure TForm1.SyntaxMemo1TGutterObjects0Click(Sender: TObject;
  Line: Integer; Shift: TShiftState);
begin
  ClickLine(Line);
end;

end.

