
{ ********** Window Management Services Demonstration ********** }
{ **********           Version 1.0  8/6/84            ********** }

{ (c) Copyright 1984  Timothy E. Ide  All commercial rights reserved }

{$C-}
{$V-}

{$I WINDOW.PAS}  { Window Management Services }

const
  MenuId = 201;
  MenuX = 10;
  MenuY = 1;
  MenuW = 62;
  MenuH = 12;
  NoOfFunc = 24;
  SelectId = 202;
  SelectX = 1;
  SelectY = 23;
  SelectW = 78;
  SelectH = 1;
  BorderPrompt = 203;
  BorderPromptW = 20;
  BorderPromptH = 5;
  ClearPrompt = 204;
  ClearPromptW = 20;
  ClearPromptH = 4;
  ClosePrompt = 205;
  ClosePromptW = 20;
  ClosePromptH = 4;
  ClreolPrompt = 206;
  ClreolPromptW = 20;
  ClreolPromptH = 4;
  DellnPrompt = 207;
  DellnPromptW = 20;
  DellnPromptH = 5;
  ErasePrompt = 208;
  ErasePromptW = 20;
  ErasePromptH = 4;
  GetPrompt = 209;
  GetPromptW = 20;
  GetPromptH = 6;
  GetlnPrompt = 210;
  GetlnPromptW = 20;
  GetlnPromptH = 6;
  GetorgPrompt = 211;
  GetorgPromptW = 20;
  GetorgPromptH = 6;
  GetposPrompt = 212;
  GetposPromptW = 20;
  GetposPromptH = 6;
  HomePrompt = 213;
  HomePromptW = 20;
  HomePromptH = 4;
  InslnPrompt = 214;
  InslnPromptW = 20;
  InslnPromptH = 5;
  OpenPrompt = 215;
  OpenPromptW = 20;
  OpenPromptH = 9;
  PutPrompt = 216;
  PutPromptW = 20;
  PutPromptH = 5;
  PutlnPrompt = 217;
  PutlnPromptW = 20;
  PutlnPromptH = 5;
  ReadPrompt = 218;
  ReadPromptW = 20;
  ReadPromptH = 6;
  ReadlnPrompt = 219;
  ReadlnPromptW = 20;
  ReadlnPromptH = 6;
  SetorgPrompt = 220;
  SetorgPromptW = 21;
  SetorgPromptH = 6;
  SetposPrompt = 220;
  SetposPromptW = 21;
  SetposPromptH = 6;
  ShowPrompt = 222;
  ShowPromptW = 20;
  ShowPromptH = 4;
  WritePrompt = 223;
  WritePromptW = 20;
  WritePromptH = 5;
  WritelnPrompt = 224;
  WritelnPromptW = 20;
  WritelnPromptH = 5;
  BorderParam = 225;
  BorderParamW = 8;
  BorderParamH = 4;
  ClearParam = 226;
  ClearParamW = 6;
  ClearParamH = 3;
  CloseParam = 227;
  CloseParamW = 6;
  CloseParamH = 3;
  ClreolParam = 228;
  ClreolParamW = 6;
  ClreolParamH = 3;
  DellnParam = 229;
  DellnParamW = 8;
  DellnParamH = 4;
  EraseParam = 230;
  EraseParamW = 6;
  EraseParamH = 3;
  GetParam = 231;
  GetParamW = 42;
  GetParamH = 5;
  GetlnParam = 232;
  GetlnParamW = 42;
  GetlnParamH = 5;
  GetorgParam = 233;
  GetorgParamW = 6;
  GetorgParamH = 5;
  GetposParam = 234;
  GetposParamW = 6;
  GetposParamH = 5;
  HomeParam = 235;
  HomeParamW = 6;
  HomeParamH = 3;
  InslnParam = 236;
  InslnParamW = 6;
  InslnParamH = 4;
  OpenParam = 237;
  OpenParamW = 6;
  OpenParamH = 8;
  PutParam = 238;
  PutParamW = 42;
  PutParamH = 5;
  PutlnParam = 239;
  PutlnParamW = 42;
  PutlnParamH = 5;
  ReadParam = 240;
  ReadParamW = 42;
  ReadParamH = 5;
  ReadlnParam = 241;
  ReadlnParamW = 42;
  ReadlnParamH = 5;
  SetorgParam = 242;
  SetorgParamW = 6;
  SetorgParamH = 5;
  SetposParam = 243;
  SetposParamW = 6;
  SetposParamH = 5;
  ShowParam = 244;
  ShowParamW = 6;
  ShowParamH = 3;
  WriteParam = 245;
  WriteParamW = 42;
  WriteParamH = 4;
  WritelnParam = 246;
  WritelnParamW = 42;
  WritelnParamH = 4;
  StatusId = 247;
  StatusX = 1;
  StatusY = 22;
  StatusW = 79;
  StatusH = 1;
  FuncBorder = 1;
  FuncClear = 2;
  FuncClose =3;
  FuncClreol = 4;
  FuncDelln = 5;
  FuncErase = 6;
  FuncGet = 7;
  FuncGetln = 8;
  FuncGetorg = 9;
  FuncGetpos = 10;
  FuncHome = 11;
  FuncInsln = 12;
  FuncOpen = 13;
  FuncPut = 14;
  FuncPutln = 15;
  FuncRead = 16;
  FuncReadln = 17;
  FuncSetorg = 18;
  FuncSetpos = 19;
  FuncShow = 20;
  FuncWrite = 21;
  FuncWriteln = 22;
  FuncClrscr = 23;
  FuncExit = 24;
  NumLen = 2;
  BordLen = 4;

Type
  NumberString = string[2];
  BooleanString = string[5];

Var
  MenuFunc : array [1..NoOfFunc] of string[16];
  Row,
  Column : integer;
  StatusWindowPos,
  StatusStatusPos,
  StatusEolnPos,
  StatusEowPos : integer;
  SelectServicePos : integer;
  FuncNo : integer;
  BorderPos,
  ClearPos,
  ClosePos,
  ClreolPos,
  DellnPos,
  ErasePos,
  GetPos,
  GetlnPos,
  GetorgPos,
  GetposPos,
  HomePos,
  InslnPos,
  OpenPos,
  PutPos,
  PutlnPos,
  ReadPos,
  ReadlnPos,
  SetorgPos,
  SetposPos,
  ShowPos,
  WritePos,
  WritelnPos : integer;
  DemoId,
  DemoX,
  DemoY,
  DemoW,
  DemoH : integer;
  NumStr : NumberString;
  BordStr : string[4];
  OutStr,
  InpStr : string[80];
  InpLen : integer;


function NumVal(NumString : NumberString) : integer;
var
  Number,
  NumFlag : integer;
begin
  Number := 0;
  val(NumString,Number,NumFlag);
  if (NumFlag = 2) then begin
    val(NumString[1],Number,NumFlag);
    if (NumFlag = 1) then begin
      val(NumString[2],Number,NumFlag);
      if (NumFlag = 1) then begin
        Number := 0;
      end;
    end;
  end;
  NumVal := Number;
end;

function StrVal(Number : integer) : NumberString;
var
  NStr : NumberString;
begin
  Str(Number,NStr);
  StrVal := NStr;
end;

function StrBool(flag : boolean) : BooleanString;
begin
  if (flag) then
    StrBool := 'true '
  else
    StrBool := 'false';
end;

procedure InitMenu;
Var
  i, j ,k : integer;
  funcst : string[2];
begin
  MenuFunc[1] := 'wi_border';
  MenuFunc[2] := 'wi_clear';
  MenuFunc[3] := 'wi_close';
  MenuFunc[4] := 'wi_clreol';
  MenuFunc[5] := 'wi_delln';
  MenuFunc[6] := 'wi_erase';
  MenuFunc[7] := 'wi_get';
  MenuFunc[8] := 'wi_getln';
  MenuFunc[9] := 'wi_getorg';
  MenuFunc[10] := 'wi_getpos';
  MenuFunc[11] := 'wi_home';
  MenuFunc[12] := 'wi_insln';
  MenuFunc[13] := 'wi_open';
  MenuFunc[14] := 'wi_put';
  MenuFunc[15] := 'wi_putln';
  MenuFunc[16] := 'wi_read';
  MenuFunc[17] := 'wi_readln';
  MenuFunc[18] := 'wi_setorg';
  MenuFunc[19] := 'wi_setpos';
  MenuFunc[20] := 'wi_show';
  MenuFunc[21] := 'wi_write';
  MenuFunc[22] := 'wi_writeln';
  MenuFunc[23] := 'clrscr';
  MenuFunc[24] := 'exit';

  wi_open(MenuId,MenuX,MenuY,MenuW,MenuH,'|-');
  wi_putln(MenuId,'  Demonstration Functions:');
  wi_putln(MenuId,'');
  for j := 1 to 8 do begin
    for i := 1 to 3 do begin
      k := ((i-1)*8+j);
      if (k <= NoOfFunc) then begin
        wi_setpos(MenuId,((i-1)*20)+3,j+2);
        str(k,funcst);
        wi_put(MenuId,(funcst+' - '+MenuFunc[k]));
      end;
    end;
  end;
end;

procedure InitStatus;
begin
  wi_open(StatusId,StatusX,StatusY,StatusW,StatusY,'');
  wi_put(StatusId,'    ');
  wi_put(StatusId,'window = ');
  wi_getpos(StatusId,StatusWindowPos,Row);
  wi_put(StatusId,'     ');
  wi_put(StatusId,'wi_status = ');
  wi_getpos(StatusId,StatusStatusPos,Row);
  wi_put(StatusId,'        ');
  wi_put(StatusId,'wi_eoln = ');
  wi_getpos(StatusId,StatusEolnPos,Row);
  wi_put(StatusId,'        ');
  wi_put(StatusId,'wi_eow = ');
  wi_getpos(StatusId,StatusEowPos,Row);
  wi_put(StatusId,'        ');
end;

procedure InitSelect;
begin
  wi_open(SelectId,SelectX,SelectY,SelectW,SelectH,'');
  wi_put(SelectId,'Enter function number: ');
  wi_getpos(SelectId,SelectServicePos,Row);
end;

procedure DemoStatus;
var
  SaveStatus,
  SaveEoln,
  SaveEow : boolean;
begin
  SaveStatus := wi_status;
  SaveEoln := wi_eoln;
  SaveEow := wi_eow;
  wi_setpos(StatusId,StatusWindowPos,1);
  wi_put(StatusId,StrVal(DemoId));
  wi_setpos(StatusId,StatusStatusPos,1);
  wi_put(StatusId,StrBool(SaveStatus));
  wi_setpos(StatusId,StatusEolnPos,1);
  wi_put(StatusId,StrBool(SaveEoln));
  wi_setpos(StatusId,StatusEowPos,1);
  wi_put(StatusId,StrBool(SaveEow));
  wi_show(StatusId);
end;

procedure WaitForAny;
var
  AnyChar : char;
begin
  gotoxy(1,24);
  clreol;
  write('Press any key to continue ');
  read(kbd,AnyChar);
  gotoxy(1,24);
  clreol;
end;

{ (c) Copyright 1984  Timothy E. Ide  All commercial rights reserved }

procedure Copyright;
begin
  clrscr;
  gotoxy(1,1);
  writeln('Window Management Services Version 1.0');
  writeln('(c) Copyright 1984 Timothy E. Ide  All commercial rights reserved');
  delay(500);
end;


{$I DEMO1.PAS}   { service window initialization }
{$I DEMO2.PAS}   { service demonstration routines }


begin
  Copyright;
  InitMenu;
  InitStatus;
  InitSelect;
  InitBorder;
  InitClear;
  InitClose;
  InitClreol;
  InitDelln;
  InitErase;
  InitGet;
  InitGetln;
  InitGetorg;
  InitGetpos;
  InitHome;
  InitInsln;
  InitOpen;
  InitPut;
  InitPutln;
  InitRead;
  InitReadln;
  InitSetorg;
  InitSetpos;
  InitShow;
  InitWrite;
  Initwriteln;
  clrscr;
  repeat
    wi_show(MenuId);
    wi_erase(StatusId);
    wi_setpos(SelectId,SelectServicePos,1);
    wi_clreol(SelectId);
    wi_show(SelectId);
    NumStr := '';
    wi_read(SelectId,NumLen,NumStr);
    FuncNo := NumVal(NumStr);
    case FuncNo of
      FuncBorder :  DemoBorder;
      FuncClear :   DemoClear;
      FuncClose :   DemoClose;
      FuncClreol :  DemoClreol;
      FuncDelln :   DemoDelln;
      FuncErase :   DemoErase;
      FuncGet :     DemoGet;
      FuncGetln :   DemoGetln;
      FuncGetorg :  DemoGetorg;
      FuncGetpos :  DemoGetpos;
      FuncHome :    DemoHome;
      FuncInsln :   DemoInsln;
      FuncOpen :    DemoOpen;
      FuncPut :     DemoPut;
      FuncPutln :   DemoPutln;
      FuncRead :    DemoRead;
      FuncReadln :  DemoReadln;
      FuncSetorg :  DemoSetorg;
      FuncSetpos :  DemoSetpos;
      FuncShow :    DemoShow;
      FuncWrite :   DemoWrite;
      FuncWriteln : DemoWriteln;
      FuncClrscr :  clrscr;
    end;
  until FuncNo = FuncExit;
end.
