home *** CD-ROM | disk | FTP | other *** search
- { PullDE15.inc - Data entry window module for Pull15.inc ver 1.5, 08-31-87 }
- { (c) 1987 James H. LeMay }
- type
- DataPadRec = record
- StoreMode,Valid,DataStored,NewData: boolean;
- case TypeOfData: TypeOfDataType of
- Bytes: (Bdata: byte);
- Integers: (Idata: integer);
- Reals: (Rdata: real);
- UserNums: (UNdata: MaxString);
- Chars: (Cdata: char);
- Strings: (Sdata: MaxString);
- UserStrings: (USdata: MaxString);
- end;
-
- var
- DataPad, OldDataPad: DataPadRec;
- DataWndwWattr, DataWndwBattr: byte;
- DataWndwBrdr: Borders;
- AutoNumLock: boolean;
- NumLockCol: byte;
- LastKeyStat: byte;
- Null: boolean;
- DataEntryStr: MaxString; { Global variable for Work window (not affected by
- DataWndw entries). }
- OldWorkWndwStep: integer;
- UserCharSet: set of char;
-
- const
- DelKey = #83;
- BSKey = #08;
- NullKey= #00;
-
- { This is a forward procedure for access outside of PULLDE15.INC. }
- procedure DataTransfer (VAR ErrMsg: integer); forward;
-
- procedure NumLock (Switch: Toggle);
- var KeyStat: byte absolute $0000:$0417;
- begin
- case Switch of
- On: begin
- LastKeyStat:=KeyStat;
- KeyStat:=LastKeyStat or $20
- end;
- Off: KeyStat:=(KeyStat and $DF) or (LastKeyStat and $20);
- end
- end;
-
- procedure ShowDataWndw (VAR Menu: MenuRec; VAR DWndw: DataWndwRec);
- var DataPadStr: MaxString;
- PadStrCol: integer;
-
- {}procedure FindRowCol;
- {}begin
- {} with DWndw do
- {} if RowAlt+ColAlt=0 then
- {} begin
- {} Row:=Menu.Row+HiLited;
- {} if (Row+Rows)>CRTrows-2 then Row:=pred(CRTrows-Rows);
- {} case Menu.LinkDir of
- {} Right: Col:=Menu.Col+(Menu.Cols-2);
- {} Left: Col:=Menu.Col-(Cols-2)
- {} end
- {} end
- {} else
- {} begin
- {} Row:=RowAlt;
- {} Col:=ColAlt
- {} end;
- {}end;
-
- {}procedure ConvertDataToStr;
- {}var i,Lead: integer;
- {}begin
- {} with DataPad,DWndw do
- {} begin
- {} DataPad.TypeOfData := DWndw.TypeOfData;
- {} StoreMode := false;
- {} DataTransfer (i); { No error messages needed }
- {} case TypeOfData of
- {} Bytes: Str(Bdata:Field,DataPadStr);
- {} Integers: Str(Idata:Field,DataPadStr);
- {} Reals: if Decimals<0 then Str(Rdata:Field,DataPadStr)
- {} else
- {} begin
- {} Str(Rdata:Field:Decimals,DataPadStr);
- {} if ord(DataPadStr[0])>Field then
- {} Str(Rdata:Field,DataPadStr)
- {} end;
- {} UserNums: DataPadStr:=UNdata;
- {} Chars: DataPadStr:='"'+Cdata+'"';
- {} else DataPadStr:='"'+Sdata+'"';
- {} end;
- {} PadStrCol:=Col+FirstCol;
- {} if Justify=Left then
- {} case TypeOfData of Bytes..Reals:
- {} begin
- {} i:=1;
- {} while (DataPadStr[i]=' ') and (i<Field) do i:=succ(i);
- {} DataPadStr[0]:=char(succ(Field-i));
- {} move (DataPadStr[i],DataPadStr[1],ord(DataPadStr[0]));
- {} end;
- {} end
- {} else { Right justified }
- {} begin
- {} Lead:=Field-ord(DataPadStr[0]);
- {} case TypeOfData of
- {} UserNums: PadStrCol:=PadStrCol+Lead;
- {} Strings,UserStrings: PadStrCol:=PadStrCol+Lead+2;
- {} end;
- {} end;
- {} case TypeOfData of Chars..UserStrings:
- {} PadStrCol:=pred(PadStrCol);
- {} end; { case }
- {} end; { with }
- {}end;
-
- begin
- with DWndw do
- begin
- FindRowCol;
- MakeWindow (Row,Col,Rows,Cols,Wattr,Battr,Border);
- for i:=1 to 2 do
- QwriteV (Row+i,Col+2,-1,Line[i]);
- ConvertDataToStr;
- QwriteV (succ(Row),PadStrCol,-1,DataPadStr);
- ShowMsg (MsgLineNum);
- end
- end;
-
- procedure PutDataOnPad (VAR DataEntryStr: MaxString);
- var Errors: integer;
- begin
- DataPad.Valid:=false;
- if ((DataEntryStr<>'') or Null) then
- with DataPad do
- begin
- Errors:=0;
- case TypeOfData of
- Bytes..Reals:
- begin
- case TypeOfData of
- Bytes: begin
- val(DataEntryStr,Idata,Errors);
- if (Errors=0)and(Idata>255) then Errors:=1;
- end;
- Integers: val(DataEntryStr,Idata,Errors);
- Reals: val(DataEntryStr,Rdata,Errors);
- end; { case }
- if Errors<>0 then ShowErrorMsg (1);
- end;
- Chars: if Null then
- Cdata:=#00
- else Cdata:=DataEntryStr[1];
- else Sdata:=DataEntryStr;
- end; { case }
- if Errors=0 then Valid:=true
- end
- end;
-
- procedure Transfer (VAR UserVariable);
- var Size: integer;
- StrLength: byte absolute UserVariable;
- begin
- with DataPad do
- begin
- case TypeOfData of
- Bytes,Chars: Size:=1;
- Integers: Size:=2;
- Reals: Size:=sizeof(Rdata);
- else
- if StoreMode then
- Size:=succ(ord(Sdata[0]))
- else Size:=succ(StrLength);
- end;
- if StoreMode then
- Move (Bdata,UserVariable,Size)
- else Move (UserVariable,Bdata,Size);
- end
- end;
-
- procedure StoreMenuData;
- var Errors: integer;
- begin
- with DataPad do
- begin
- Errors:=0;
- StoreMode:=true;
- DataTransfer (Errors);
- if Errors<>0 then
- begin
- ShowErrorMsg (Errors);
- DataStored:=false
- end
- else DataStored:=true
- end { with }
- end;
-
- procedure EnterData (Row,Col,Field: integer; VAR DataEntryStr: MaxString;
- TypeOfData: TypeOfDataType; Justify: DirType;
- HelpWndwNum: integer; HelpTitle: MaxString);
- var ValidCharSet: set of char;
- {}procedure MonitorNumLock;
- {}var KeyStat: byte absolute $0040:$0017;
- {} NumStr: string[7];
- {}begin
- {} repeat
- {} if (KeyStat and $20)=$20 then
- {} NumStr:='NUMLOCK'
- {} else NumStr:=' ';
- {} QwriteV (CRTrows,NumLockCol,-1,NumStr)
- {} until keypressed;
- {}end;
-
- {}procedure DisplayStrAndCursor;
- {}var L,Index,CursorCol: integer;
- {} VideoStr: MaxString;
- {}begin
- {} L:=ord(DataEntryStr[0]);
- {} fillchar (VideoStr[1],Field,' ');
- {} VideoStr[0]:=char(Field);
- {} case Justify of
- {} Left: begin
- {} Index:=1;
- {} CursorCol:=Col+L;
- {} end;
- {} Right: begin
- {} Index:=succ(Field)-L;
- {} CursorCol:=Col+pred(Field);
- {} end;
- {} end;
- {} move (DataEntryStr[1],VideoStr[Index],L);
- {} QwriteV (Row,Col,-1,VideoStr);
- {} GotoRC (Row,CursorCol);
- {}end;
-
- {}procedure AppendStr;
- {}var L: integer;
- {}begin
- {} L:=ord(DataEntryStr[0]);
- {} Null:=false;
- {} if Key=BSKey then
- {} begin
- {} if L>0 then
- {} DataEntryStr[0]:=pred(DataEntryStr[0]);
- {} end
- {} else
- {} if L<Field then DataEntryStr:=DataEntryStr+Key;
- {}end;
-
- begin
- case TypeOfData of
- Bytes: ValidCharSet:=['0'..'9',BSKey];
- Integers: ValidCharSet:=['0'..'9','-','+',BSKey];
- Reals: ValidCharSet:=['0'..'9','-','+','.','E','e',BSKey];
- Chars, Strings: ValidCharSet:=[' '..'~',BSKey,NullKey]
- else ValidCharSet:=UserCharSet; { UserNums and UserStrings }
- end;
- case TypeOfData of
- Bytes..UserNums: if AutoNumLock then NumLock(On);
- end; { case }
- if WorkWndwStep<>OldWorkWndwStep then DataPad.NewData:=true;
- if DataPad.NewData then
- begin
- DataEntryStr:='';
- Null:=false;
- DataPad.NewData:=false;
- OldWorkWndwStep:=WorkWndwStep
- end;
- Qwrite (Row,pred(Col) ,-1,'»');
- Qwrite (Row, Col+Field,-1,'«');
- DisplayStrAndCursor;
- repeat
- MonitorNumLock;
- ReadKB (ExtKey,Key);
- if ExtKey then
- case Key of
- HelpKey: PullHelpWndw (HelpWndwNum,HelpTitle); { F1 }
- DelKey: if NullKey in ValidCharSet then
- begin
- DataEntryStr:='';
- DisplayStrAndCursor;
- Null:=true;
- end;
- PopKey: PopToWorkWndw:=true; { F2 }
- TopKey1: PopToTop:=true; { F10 }
- end { end case }
- else
- if Key in ValidCharSet then
- begin
- AppendStr;
- DisplayStrAndCursor;
- end
- else
- if TopKeyPressed then PopToTop:=true;
- if (Key=RetKey) then PutDataOnPad (DataEntryStr);
- until (Key=RetKey) or (Key=EscKey) or PopToWorkWndw or PopToTop;
- case TypeOfData of
- Bytes..UserNums: if AutoNumLock then NumLock(Off);
- end; { case }
- end;
-
- procedure PullDataWndw; { (VAR Menu: MenuRec; WndwNum: integer) }
- var DataEntryStr: MaxString;
- begin
- TurnArrows (On,Menu);
- ShowDataWndw (Menu,DataWndw[WndwNum]);
- CursorOn;
- with Menu,DataPad do
- begin
- CmdSeq:=CmdSeq+CmdLtrs[HiLited];
- Pull:=false;
- NewData:=true;
- repeat
- with DataWndw[WndwNum] do
- { DataEntryStr is LOCAL here! }
- EnterData (Row+2,Col+FirstCol,Field,DataEntryStr,TypeOfData,Justify,
- HelpWndwNum,Menu.Line[HiLited]);
- if (Key=RetKey) and Valid then
- begin
- StoreMenuData; { Sets Key:=' ' if there's a range error. }
- if DataStored then Changed:=true;
- end;
- until DataStored or (Key<>' ');
- CheckForPop;
- CmdSeq[0]:=pred(CmdSeq[0]);
- if (Key=RetKey) then
- if (MenuMode<=ExecMultipleChoice) or (LineMode[HiLited]=ExecOnly) then
- Process(MPulled,SPulled,HiLited);
- end;
- Key:=' ';
- CursorOff;
- RemoveWindow;
- TurnArrows (Off,Menu)
- end;
-
- procedure RestoreData (VAR UserVariable; ErrMsg: integer);
- { RestoreData is used for WorkWndw Data Entries in the main program. }
- begin
- ShowErrorMsg (ErrMsg); { Makes Key:=' '. }
- DataPad:=OldDataPad;
- with DataPad do
- begin
- DataStored:=false;
- NewData:=false;
- StoreMode:=true
- end;
- Transfer (UserVariable);
- end;
-
- procedure WorkWndwEntry (Row,Col,Field: integer; VAR UserVariable;
- TOD: TypeOfDataType; Justify: DirType;
- HelpWndwNum: integer; HelpTitle: MaxString);
- begin
- with DataPad do
- begin
- StoreMode:=false;
- TypeOfData:=TOD;
- Transfer (UserVariable);
- OldDataPad:=DataPad;
- ShowMsg (9);
- { DataEntryStr is GLOBAL here! }
- EnterData (Row,Col,Field,DataEntryStr,TOD,Justify,HelpWndwNum,HelpTitle);
- if (Key=RetKey) and Valid then
- begin
- StoreMode:=true;
- Transfer (UserVariable);
- DataStored:=true
- end
- else DataStored:=false;
- end;
- if PopToWorkWndw or (Key=EscKey) or PopToTop then
- Pull:=true; { PTWW really means pull menus here. }
- if not Pull then ShowMsg (1);
- end;
-
- { The following procedures are only used once and never used again. }
-
- procedure InitDataWndwSize;
- var Lmax,L,L2: integer;
- begin
- for i:=1 to NumOfDataWndws do
- with DataWndw[i] do
- begin
- Rows := 4;
- L := ord(Line[1][0]);
- L2 := ord(Line[2][0]);
- if L>=L2 then Lmax:=L else Lmax:=L2;
- Cols := Lmax+7+Field;
- FirstCol := Lmax+4;
- Border := DataWndwBrdr;
- { specify justification if omitted }
- case Justify of
- Left,Right: ;
- else
- case TypeOfData of
- Bytes..UserNums: Justify:=Right;
- else Justify:=Left;
- end;
- end { case Justify }
- end
- end;
-
- procedure InitDataWndwColor;
- begin
- for i:=1 to NumOfDataWndws do
- with DataWndw[i] do
- begin
- Wattr := DataWndwWattr;
- Battr := DataWndwBattr;
- end
- end;