IMPLEMENTATION MODULE Scrn2Ndx; (* * REPERTOIRE * Release 1.6 * By Charles Bradford and Cole Brecheen * (c) Copyright 1985-1992 PMI * Green Bay, Wisconsin * All rights reserved * (414) 468-6040 * * $Header: D:/logfiles/mods/scrn2ndx.mov 1.5 10 Mar 1991 15:32:02 coleb $ * *) IMPORT ControlUtils; IMPORT GenLists; IMPORT LowLevel; IMPORT M2Strings; IMPORT NdxBones; IMPORT NdxFiles; IMPORT NdxTypes; IMPORT ScrnTypes; IMPORT ScrnUtl1; IMPORT StrEdit; IMPORT SYSTEM; VAR Initialized : BOOLEAN; PROCEDURE Init(); BEGIN IF Initialized THEN RETURN; ELSE Initialized := TRUE; END; ControlUtils.Init(); GenLists.Init(); LowLevel.Init(); M2Strings.Init(); NdxBones.Init(); NdxFiles.Init(); NdxTypes.Init(); ScrnTypes.Init(); ScrnUtl1.Init(); StrEdit.Init(); END Init; PROCEDURE PutScrRec( VAR NdxFile: NdxTypes.NdxFileType; VAR TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR; KeyField: ARRAY OF CHAR): BOOLEAN; (* Puts current screen data in out as a record. If RecName is not null, it contains the record name to use. If RecName is null, KeyField contains the name of the field on the screen to use as the Record Name. RecName will always return the record name used. *) VAR FoundAny: BOOLEAN; FileStr: ARRAY [0..255] OF CHAR; TmpList, TmpList2: GenLists.GenList; FieldCount: CARDINAL; FieldRec: ScrnTypes.InputFieldRecord; ImageRec: ScrnTypes.ImageElement; BEGIN FoundAny := FALSE; IF M2Strings.Length( RecName) = 0 THEN (* read record name from field named in KeyField *) ControlUtils.ReadInput( TheFrame, RecName, KeyField); END; StrEdit.CrunchBlanks( RecName ); FieldCount := 1; REPEAT (* flip through the named fields on screen and put their values in the record if they are in the structure *) ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec ); ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec ); IF M2Strings.Length( FieldRec.fnam) # 0 THEN (* for each named field *) IF FieldRec.typ # ScrnTypes.GroupMember THEN (* for any field except a group *) IF FieldRec.typ = ScrnTypes.EditorCode THEN (*We store editor fields as sublists.*) IF ScrnUtl1.ListFromEdField( TheFrame, FieldCount, TmpList ) THEN GenLists.CopyList( TmpList, TmpList2 ); FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam, GenLists.ListCode, TmpList2) OR FoundAny; END; ELSE StrEdit.CutTrailingChars( ' ', ImageRec.text ); FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam, GenLists.StrCode, ImageRec.text ) OR FoundAny; END; ELSIF FieldRec.selected THEN (* for selected members of a group put a ONE *) FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam, GenLists.StrCode, '1') OR FoundAny; ELSE (* for non-selected members of a group put a NULL *) FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam, GenLists.StrCode, '') OR FoundAny; END; END; INC( FieldCount ); UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame ); RETURN FoundAny; END PutScrRec; PROCEDURE FillScr( VAR NdxFile: NdxTypes.NdxFileType; VAR TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR; KeyField: ARRAY OF CHAR): BOOLEAN; (* Fills the current screen with the data from the record named in RecName if RecName is not null. If RecName is null, KeyField contains the name of the field on the screen to use as the Record Name. RecName will always return the record name used.*) VAR FoundAny: BOOLEAN; FileStr, BlankStr: ARRAY [0..255] OF CHAR; FileLeng, ScrLeng, TheType: CARDINAL; TmpList, TmpList2: GenLists.GenList; FieldCount: CARDINAL; FieldRec: ScrnTypes.InputFieldRecord; ImageRec: ScrnTypes.ImageElement; BEGIN LowLevel.Fill( SYSTEM.ADR( BlankStr), HIGH(BlankStr) + 1, ' '); FoundAny := FALSE; IF M2Strings.Length( RecName) = 0 THEN (* read record name from field named in KeyField *) ControlUtils.ReadInput( TheFrame, RecName, KeyField); END; StrEdit.CrunchBlanks( RecName ); FieldCount := 1; REPEAT (* flip through the named fields on screen and extract their value from the file if they exist there *) ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec ); ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec ); IF (M2Strings.Length( FieldRec.fnam) # 0) AND NdxFiles.GetField( NdxFile, RecName, FieldRec.fnam, TheType, FileStr) THEN (* for each named field we can get from the file *) IF FieldRec.typ # ScrnTypes.GroupMember THEN (* for any field except a group *) FoundAny := TRUE; IF TheType = GenLists.StrCode THEN FileLeng := M2Strings.Length( FileStr); ScrLeng := M2Strings.Length( ImageRec.text); IF FileLeng < ScrLeng THEN (*We need to pad out stored string with blanks to match length of screen field.*) StrEdit.SetLength( BlankStr, ScrLeng - FileLeng); StrEdit.Append( FileStr, BlankStr); END; IF FieldRec.typ # ScrnTypes.EditorCode THEN StrEdit.AssignStr( FileStr, ImageRec.text); ELSE GenLists.NewList( TmpList ); GenLists.ListInsert( FileStr, GenLists.StrCode, TmpList, 1 ); IF NOT ScrnUtl1.ListToEdField( TmpList, TheFrame, FieldCount ) THEN HALT(); END; END; ELSIF TheType = GenLists.ListCode THEN IF FieldRec.typ = ScrnTypes.EditorCode THEN (*Make sure it's an editor field before we fill it with a list.*) IF NdxFiles.GetField( NdxFile, RecName, FieldRec.fnam, TheType, TmpList ) THEN GenLists.CopyList( TmpList, TmpList2 ); IF NOT ScrnUtl1.ListToEdField( TmpList2, TheFrame, FieldCount ) THEN HALT(); END; END; END; (*You could add additional data conversion operations here.*) END; ELSE (* for members of a group *) FoundAny := TRUE; FieldRec.selected := M2Strings.Length( FileStr) # 0; (* this simple logic assumes that the groups are the same on input and display screens *) END; ScrnUtl1.PutFieldImageRec( ImageRec, TheFrame, FieldCount ); ScrnUtl1.PutFieldRec( FieldRec, TheFrame, FieldCount ); END; INC( FieldCount ); UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame ); RETURN FoundAny; END FillScr; PROCEDURE PutScrFast( VAR NdxFile: NdxTypes.NdxFileType; VAR TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR; KeyField: ARRAY OF CHAR): BOOLEAN; (* Works like PutScrRec except that it requires an exact match between all named fields in the screen and the file record *) VAR Selctd: BOOLEAN; FileStr: ARRAY [0..255] OF CHAR; TmpList, TmpList2: GenLists.GenList; FileCntr, FileStructLen: CARDINAL; FieldCount: CARDINAL; FieldRec: ScrnTypes.InputFieldRecord; ImageRec: ScrnTypes.ImageElement; BEGIN IF M2Strings.Length( RecName) = 0 THEN (* read record name from field named in KeyField *) ControlUtils.ReadInput( TheFrame, RecName, KeyField); END; StrEdit.CrunchBlanks( RecName ); IF NOT NdxBones.InitBuffer( NdxFile, RecName) THEN (* Loads file buffer with desired record; false result probably indicates we're creating a new record, but could actually indicate an error. We trust that we will catch an error below. *) END; FieldCount := 1; FileCntr := 0; (* used to count fields written to record *) FileStructLen := GenLists.ListLength( NdxFile^.ListBuf); REPEAT (* flip through the named fields on screen and store each in the record *) ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec ); ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec ); IF M2Strings.Length( FieldRec.fnam) # 0 THEN (* for each named field *) INC( FileCntr); (* go to next field in file *) IF FileCntr > FileStructLen THEN RETURN FALSE; END; IF FieldRec.typ # ScrnTypes.GroupMember THEN (* for any field except a group *) IF FieldRec.typ = ScrnTypes.EditorCode THEN (*We store editor fields as sublists.*) IF ScrnUtl1.ListFromEdField( TheFrame, FieldCount, TmpList ) THEN GenLists.CopyList( TmpList, TmpList2 ); GenLists.ListReplace( TmpList2, GenLists.ListCode, NdxFile^.ListBuf, FileCntr); END; ELSE StrEdit.CutTrailingChars( ' ', ImageRec.text ); GenLists.ListReplace( ImageRec.text, GenLists.StrCode, NdxFile^.ListBuf, FileCntr); END; ELSIF FieldRec.selected THEN (* for selected members of a group put a ONE *) GenLists.ListReplace( '1', GenLists.StrCode, NdxFile^.ListBuf, FileCntr); ELSE (* for non-selected members of a group put a NULL *) GenLists.ListReplace( '', GenLists.StrCode, NdxFile^.ListBuf, FileCntr); END; END; INC( FieldCount ); UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame ); RETURN TRUE; END PutScrFast; PROCEDURE FillScrFast( VAR NdxFile: NdxTypes.NdxFileType; VAR TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR; KeyField: ARRAY OF CHAR): BOOLEAN; (* Fills the current screen with the data from a record. Works like FillScr except that it requires an exact match between all named fields in the screen and the fields in the file record *) VAR Selctd : BOOLEAN; FileStr, BlankStr: ARRAY [0..255] OF CHAR; FileLeng, ScrLeng, TheType, FileCntr, FileStructLen: CARDINAL; TmpList, TmpList2: GenLists.GenList; FieldCount: CARDINAL; FieldRec: ScrnTypes.InputFieldRecord; ImageRec: ScrnTypes.ImageElement; BEGIN LowLevel.Fill( SYSTEM.ADR( BlankStr), HIGH(BlankStr) + 1, ' '); IF M2Strings.Length( RecName) = 0 THEN (* read record name from field named in KeyField *) ControlUtils.ReadInput( TheFrame, RecName, KeyField); END; StrEdit.CrunchBlanks( RecName ); IF NOT NdxBones.InitBuffer( NdxFile, RecName) THEN (* loads file buffer with desired record *) RETURN FALSE; END; FieldCount := 1; FileCntr := 0; FileStructLen := GenLists.ListLength( NdxFile^.ListBuf); REPEAT (* flip through the named fields on screen and, for each, extract the next field in the file record *) ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec ); ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec ); IF M2Strings.Length( FieldRec.fnam) # 0 THEN (* for each named field *) INC( FileCntr); (* go to next field in file *) IF FileCntr > FileStructLen THEN RETURN FALSE; END; GenLists.GetElmt( NdxFile^.ListBuf, FileCntr, FileStr, TheType); (*Read file value.*) IF FieldRec.typ # ScrnTypes.GroupMember THEN (* for any field except a group *) IF TheType = GenLists.StrCode THEN FileLeng := M2Strings.Length( FileStr); ScrLeng := M2Strings.Length( ImageRec.text); IF FileLeng < ScrLeng THEN (*We need to pad out stored string with blanks to match length of screen field.*) StrEdit.SetLength( BlankStr, ScrLeng - FileLeng); StrEdit.Append( FileStr, BlankStr); END; IF FieldRec.typ # ScrnTypes.EditorCode THEN StrEdit.AssignStr( FileStr, ImageRec.text); ELSE GenLists.NewList( TmpList ); GenLists.ListInsert( FileStr, GenLists.StrCode, TmpList, 1 ); IF NOT ScrnUtl1.ListToEdField( TmpList, TheFrame, FieldCount ) THEN HALT(); END; END; ELSIF TheType = GenLists.ListCode THEN IF FieldRec.typ = ScrnTypes.EditorCode THEN (*Make sure it's an editor field before we fill it with a list.*) GenLists.GetChildList( NdxFile^.ListBuf, FileCntr, TmpList); GenLists.CopyList( TmpList, TmpList2 ); IF NOT ScrnUtl1.ListToEdField( TmpList2, TheFrame, FieldCount ) THEN HALT(); END; END; (*You could add additional data conversion operations here.*) END; ELSE (* for members of a group *) FieldRec.selected := M2Strings.Length( FileStr) # 0; (* this simple logic assumes that the groups are the same on input and display screens *) END; ScrnUtl1.PutFieldImageRec( ImageRec, TheFrame, FieldCount ); ScrnUtl1.PutFieldRec( FieldRec, TheFrame, FieldCount ); END; INC( FieldCount ); UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame ); RETURN TRUE; END FillScrFast; BEGIN Initialized := FALSE; Init(); END Scrn2Ndx.