{$I-,O+,F+,X+}
unit About;

interface

uses Objects, Drivers, Views, Menus, Dialogs, App, Consts;

type
  PAboutDialog = ^TAboutDialog;
  TAboutDialog = object(TDialog)
    Count: Word;
    Ticks: Word;
    AboutText: PStaticText;
    TeamText: PStaticText;
    constructor Load(var S: TStream);
    procedure GetEvent(var Event: TEvent); virtual;
    procedure Store(var S: TStream);
  end;

procedure RSRAboutDialog(RSR: PResourceFile);
procedure LoadAboutDialog;
procedure SystemInfoDialog;

implementation

uses Dos, MsgBox, EditMsg, RMenus, SysInfo, Gauges, TPString, Defaults;

const
  TickDelta: Byte = 10;

constructor TAboutDialog.Load(var S: TStream);
var
  L: Longint;
  DT: DateTime;
  SS: String;
begin
  TDialog.Load(S);
  GetSubViewPtr(S, AboutText);
  GetSubViewPtr(S, TeamText);
  SS := AboutText^.Text^;
  Move(SS[50], L, SizeOf(Longint));
  System.Delete(SS, 50, SizeOf(Longint));
  UnpackTime(L, DT);
  with DT do System.Insert(
    FormatDateStr(Year, Month, Day) + ', ' +
    Trim(FormatTimeStr(Hour, Min, Sec)), SS, 50);
  DisposeStr(AboutText^.Text);
  AboutText^.Text := NewStr(SS);
end;

procedure TAboutDialog.GetEvent(var Event: TEvent);

procedure NewText;
var
  W: Word;
  S: String;
begin
  S := ^C;
  for W := $FEFA + Count to $FEFA + Count + 6 do
    S := S + PRStatusLine(StatusLine)^.HintsList^.Get(W) + ^M^C;
  TeamText^.Text := @S;
  TeamText^.DrawView;
  TeamText^.Text := nil;
end;

procedure CopyCompiled;
var
  S: String;
begin
  S := Copy(AboutText^.Text^, 38, 31);
  if S[Length(S)] = #13 then Dec(S[0]);
  Message(Desktop, evBroadcast, cmCopy, @S);
end;

begin
  TDialog.GetEvent(Event);
  if ((Event.What = evKeyDown) and (Event.KeyCode = kbAltI)) or
     ((Event.What = evMouseDown) and Event.Double) then
  begin
    if TeamText^.State and sfVisible <> 0 then TeamText^.Hide
    else
    begin
      TeamText^.Show;
      Count := $FFFF;
      Ticks := 0;
    end;
    Event.What := evNothing;
  end;
  if Event.What = evKeyDown then
  begin
    case CtrlToArrow(Event.KeyCode) of
      kbUp, kbGrayPlus: if TickDelta > 1 then Dec(TickDelta);
      kbDown, kbGrayMinus: if TickDelta < 18 then Inc(TickDelta);
      kbCtrlIns: CopyCompiled;
      else Exit;
    end;
    Event.What := evNothing;
  end;
  if (TeamText^.State and sfVisible <> 0) and
     (MemW[$40:$6C] - Ticks > TickDelta) then
  begin
    Inc(Count);
    if Count > $3D then Count := 0;
    NewText;
    Ticks := MemW[$40:$6C];
  end;
end;

procedure TAboutDialog.Store(var S: TStream);
begin
  TDialog.Store(S);
  PutSubViewPtr(S, AboutText);
  PutSubViewPtr(S, TeamText);
end;

procedure RSRAboutDialog(RSR: PResourceFile);
var
  D: PAboutDialog;
  R: TRect;
begin
  R.Assign(0, 0, 46, 15);
  D := New(PAboutDialog, Init(R, 'About'));
  with D^ do
  begin
    HelpCtx := hcSAbout;
    Options := Options or ofCentered;
    R.Grow(-1, -1);
    Dec(R.B.Y, 3);
    AboutText := New(PStaticText, Init(R, #13 +
      ^C'The IBM HandShaker'#13#13 +
      ^C'Version 7.5'#13#13 +
      ^C'Compiled on ????'#13#13 +
      ^C'Copyright (c) 1991,99 by'#13#13 + ^C'KHEMZ, Inc.'));
    Insert(AboutText);
    Inc(R.A.Y, 3);
    TeamText := New(PStaticText, Init(R, ''));
    Insert(TeamText);
    TeamText^.Hide;
    R.Assign(17, 12, 27, 14);
    StandardOkButton(R, D);
  end;
  RSR^.Put(D, 'ABOUT');
  Dispose(D, Done);
end;

procedure LoadAboutDialog;
var
  D: PDialog;
begin
  D := PDialog(Resource^.Get('ABOUT'));
  if D <> nil then Application^.ExecuteDialog(D, nil, False)
  else ResourceNotFoundMsgBox('About dialog');
end;

procedure SystemInfoDialog;
var
  Half, Right: Integer;
  L: Longint;
  Params: Array[0..2] of Longint;
  D: PDialog;
  R, IR: TRect;
  Rec: TSysinfoRec;
begin
  if DisableSysInfo then Exit;
{
  L := LinuxPresent;
  if L <> 0 then with LinuxVersion(L) do
  begin
    Params[0] := Version;
    Params[1] := SubLevel;
    Params[2] := PatchLevel;
    MessageBox(^C'Linux DOSEMU %d.%d.%d detected.',
      @Params, mfInformation + mfOkButton);
    Exit;
  end;
}
  DrawStatusLine('Detecting system resources.');
  FillChar(Rec, SizeOf(TSysinfoRec), 0);
  GetSysInfo(Rec);
  R.Assign(0, 0, Rec.InfoLen * 2 + 8, Rec.InfoCount + 6);
  if R.B.X > ScreenWidth then R.B.X := ScreenWidth;
  D := New(PDialog, Init(R, 'System information'));
  with D^, Rec do
  begin
    HelpCtx := hcSInfo;
    Options := Options or ofCentered;
    Half := Size.X div 2;
    Right := Size.X - 2;

    R.Assign(Half - 10, 2, Half, 3);
    Insert(New(PStaticText, Init(R, 'Processor:')));
    IR.Assign(Half + 1, R.A.Y, Right, R.B.Y +
      Byte(Length(CPUS) > MaxInfoWidth));
    Insert(New(PStaticText, Init(IR, CPUS)));

    R.A.Y := IR.B.Y; R.B.Y := R.A.Y + 1;
    R.A.X := Half - 10; R.B.X := Half;
    Insert(New(PStaticText, Init(R, 'CPU speed:')));
    IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
    Insert(New(PStaticText, Init(IR, CPURate)));

    Inc(R.A.Y); Inc(R.B.Y);
    R.A.X := Half - 18; R.B.X := Half;
    Insert(New(PStaticText, Init(R, 'Math Co-Processor:')));
    IR.Assign(Half + 1, R.A.Y, Right, R.B.Y +
      Byte(Length(CoCPUS) > MaxInfoWidth));
    Insert(New(PStaticText, Init(IR, CoCPUS)));

    R.A.Y := IR.B.Y; R.B.Y := R.A.Y + 1;
    R.A.X := Half - 7; R.B.X := Half;
    Insert(New(PStaticText, Init(R, 'Memory:')));
    IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
    Insert(New(PStaticText, Init(IR, Memory)));

    if ExMemory <> '' then
    begin
      Inc(R.A.Y); Inc(R.B.Y);
      R.A.X := Half - 9; R.B.X := Half;
      Insert(New(PStaticText, Init(R, 'Extended:')));
      IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
      Insert(New(PStaticText, Init(IR, ExMemory)));
    end;

    if EMS_Total <> '' then
    begin
      Inc(R.A.Y); Inc(R.B.Y);
      R.A.X := Half - 10; R.B.X := Half;
      Insert(New(PStaticText, Init(R, 'EMS total:')));
      IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
      Insert(New(PStaticText, Init(IR, EMS_Total)));

      Inc(R.A.Y); Inc(R.B.Y);
      R.A.X := Half - 14; R.B.X := Half;
      Insert(New(PStaticText, Init(R, 'EMS available:')));
      IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
      Insert(New(PStaticText, Init(IR, EMS_Available)));
    end;

    if XMS_Total <> '' then
    begin
      Inc(R.A.Y); Inc(R.B.Y);
      R.A.X := Half - 14; R.B.X := Half;
      Insert(New(PStaticText, Init(R, 'XMS available:')));
      IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
      Insert(New(PStaticText, Init(IR, XMS_Total)));
    end;

    if Video <> '' then
    begin
      Inc(R.A.Y); Inc(R.B.Y);
      R.A.X := Half - 14; R.B.X := Half;
      Insert(New(PStaticText, Init(R, 'Video adapter:')));
      IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
      Insert(New(PStaticText, Init(IR, Video)));
    end;

    Inc(R.A.Y); Inc(R.B.Y);
    R.A.X := Half - 18; R.B.X := Half;
    Insert(New(PStaticText, Init(R, 'Enhanced keyboard:')));
    IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
    Insert(New(PStaticText, Init(IR, EnhKbd)));

    Inc(R.A.Y); Inc(R.B.Y);
    R.A.X := Half - 12; R.B.X := Half;
    Insert(New(PStaticText, Init(R, 'DOS version:')));
    IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
    Insert(New(PStaticText, Init(IR, DOS_)));

    if Shell <> '' then
    begin
      Inc(R.A.Y); Inc(R.B.Y);
      R.A.X := Half - 12; R.B.X := Half;
      Insert(New(PStaticText, Init(R, 'Multitasker:')));
      IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
      Insert(New(PStaticText, Init(IR, Shell)));
    end;

    if NetWare <> '' then
    begin
      Inc(R.A.Y); Inc(R.B.Y);
      R.A.X := Half - 4; R.B.X := Half;
      Insert(New(PStaticText, Init(R, 'Net:')));
      IR.Assign(Half + 1, R.A.Y, Right, R.B.Y);
      Insert(New(PStaticText, Init(IR, NetWare)));
    end;

    R.Assign(Half - 5, Size.Y - 3, Half + 5, Size.Y - 1);
    StandardOkButton(R, D);
  end;
  Application^.ExecuteDialog(D, nil, False);
end;

end.