unit prglabel;
{
   Tässä tiedostossa on logiikkaohjelmien hyppypaikka-käskyt

   Author:  Vesa Lappalainen
   Date:    15.3.1997
   Changes: 26.3.1997

   Explanation:
}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,PrgSteps, ExtCtrls, kComp, KParam;

type
  TStepLabel = class (TStepBasic)
  public
    function Ask:boolean; override;
    function Name : string; override;
    function Expl : string; override;
    function GetStr : string; override;
    procedure SetStr(const s:string); override;
    function Level : Integer;      override;
    function Color : TColor;       override;
    function TextColor : TColor;   override;
    function Style : TFontStyles;  override;
  end;

  TStepComment = class (TStepBasic)
  private
    comstr : string;
  public
    function Ask:boolean; override;
    function Name : string; override;
    function Expl : string; override;
    function GetStr : string; override;
    procedure SetStr(const s:string); override;
    function Style : TFontStyles;  override;
  end;

  TStepProgComment = class (TStepComment)
  public
    function Ask:boolean; override;
    function Name : string; override;
    function Expl : string; override;
    function Level : Integer;      override;
    function Color : TColor;       override;
    function TextColor : TColor;   override;
    function Style : TFontStyles;  override;
  end;

  TStepBlockComment = class (TStepComment)
    FLevel : integer;
  public
    constructor Create;  override;
    function Ask:boolean; override;
    function Name : string; override;
    function Expl : string; override;
    function GetStr : string; override;
    procedure SetStr(const s:string); override;
    function Level : Integer;      override;
    function Color : TColor;       override;
    function TextColor : TColor;   override;
    function Style : TFontStyles;  override;
  end;

type
  TFormAskLabel = class(TForm)
    EditId: TEdit;
    LabelId: TLabel;
    ButtonOK: TButton;
    ButtonCancel: TButton;
    ParamLevel: TkParam;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  function DoAskLabel(const q:string;l:TStepBasic;w:integer):boolean;
  function DoAskComment(const q:string;l:TStepComment;w:integer):boolean;


implementation
uses KFormPrg,kstring;

{$R *.DFM}
function DoAskLabel(const q:string;l:TStepBasic;w:integer):boolean;
var FormAskLabel: TFormAskLabel;
begin
  FormAskLabel := TFormAskLabel.Create(NIL);
  FormAskLabel.EditId.Width := w;
  FormAskLabel.EditId.Text := l.id;
  FormAskLabel.Caption := q;
  Result := false;
  CenterForm(FormAskLabel,'ButtonOK');
  if ( FormAskLabel.ShowModal <> mrCancel ) then begin
    Result := true;
    l.id := FormAskLabel.EditId.Text;
  end;
  FormAskLabel.Free;
end;

function DoAskComment(const q:string;l:TStepComment;w:integer):boolean;
var FormAskLabel: TFormAskLabel; co : TStepBlockComment;
begin
  co := nil;
  FormAskLabel := TFormAskLabel.Create(NIL);
  FormAskLabel.EditId.Width := w;
  FormAskLabel.EditId.Text := l.comstr;
  FormAskLabel.Caption := q;
  CenterForm(FormAskLabel,'ButtonOK');
  Result := false;
  if ( l is TStepBlockComment ) then begin
    co := l as TStepBlockComment;
    FormAskLabel.ParamLevel.Value := co.Level;
    FormAskLabel.ParamLevel.Visible := true;
  end;
  if ( FormAskLabel.ShowModal <> mrCancel ) then begin
    Result := true;
    l.comstr := FormAskLabel.EditId.Text;
    if ( co <> nil ) then co.FLevel := FormAskLabel.ParamLevel.AsInteger;
  end;
  FormAskLabel.Free;
end;

//------------------------------------------------------------------------------
Function TStepLabel.Ask:boolean;
begin Result := DoAskLabel('Give name for the label',self,80); end;

function TStepLabel.Name : string; begin Result := 'Label'; end;

function TStepLabel.Expl : string;
begin Result := 'Place where to jump'; end;

procedure TStepLabel.SetStr(const s:string);
begin id := s; end;

function TStepLabel.GetStr : string;
begin Result := id; end;

function TStepLabel.Level : Integer;     begin Result := 0;        end;
function TStepLabel.Color : TColor;      begin Result := $00DFDFDF end;
function TStepLabel.TextColor : TColor;  begin Result := 0;        end;
function TStepLabel.Style : TFontStyles; begin Result :=[fsBold];  end;

//------------------------------------------------------------------------------
Function TStepComment.Ask:boolean;
begin Result := DoAskComment('Give the comment',self,200); end;

function TStepComment.Name : string; begin Result := '-'; end;

function TStepComment.Expl : string;
begin Result := 'Pure comment'; end;

procedure TStepComment.SetStr(const s:string);
begin comstr := s; end;

function TStepComment.GetStr : string;
begin Result := comstr; end;

function TStepComment.Style : TFontStyles; begin Result :=[fsItalic]; end;

//------------------------------------------------------------------------------
Function TStepProgComment.Ask:boolean;
begin Result := DoAskComment('Give the program comment',self,200); end;

function TStepProgComment.Name : string; begin Result := '--'; end;

function TStepProgComment.Expl : string;
begin Result := 'Comment for one program'; end;

function TStepProgComment.Level : Integer;     begin Result := 1;       end;
function TStepProgComment.Color : TColor;      begin Result := 0;       end;
function TStepProgComment.TextColor : TColor;  begin Result := 0;       end;
function TStepProgComment.Style : TFontStyles; begin Result :=[fsItalic]; end;

//------------------------------------------------------------------------------
constructor TStepBlockComment.Create;
begin FLevel := 2; end;

function TStepBlockComment.Ask:boolean;
begin Result := DoAskComment('Give the block comment',self,200); end;

function TStepBlockComment.Name : string; begin Result := '---'; end;

function TStepBlockComment.Expl : string;
begin Result := 'Comment for many programs'; end;

procedure TStepBlockComment.SetStr(const s:string);
var parts:TStringList;
begin
  parts := nil;
  split(s,'|',Parts);
  comstr := Trim(Parts[0]);
  FLevel := StrToIntDef(Parts[1],2);
  Parts.Free;
end;

function TStepBlockComment.GetStr : string;
begin
  if ( Level = 2 ) then Result := comstr
  else             Result := comstr + '   |   ' + IntToStr(Level);
end;

function TStepBlockComment.Level : Integer;     begin Result := FLevel;    end;
function TStepBlockComment.Color : TColor;      begin Result := $00FFFF80  end;
function TStepBlockComment.TextColor : TColor;  begin Result := 0;         end;
function TStepBlockComment.Style : TFontStyles; begin Result :=[fsItalic]; end;

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
initialization begin
  StepAdd(TStepBlockComment.Create);
  StepAdd(TStepProgComment.Create);
  StepAdd(TStepComment.Create);
  StepAdd(TStepLabel.Create);
end;

end.
