home *** CD-ROM | disk | FTP | other *** search
- { MENU.INC }
-
- { *************************************************************************** }
- { * * }
- { * TURBO SCREEN INPUT PRE-PROCESSOR TOOLKIT * }
- { * * }
- { * MENU SUBPROGRAM INCLUDE FILE * }
- { * * }
- { * Version 1.07 * }
- { * * }
- { * * }
- { * This include file contains the modules necessary to support as many * }
- { * menu pages as your application program requires. * }
- { * * }
- { * Note that further documentation on menu support can be found in * }
- { * the documentation file 'Tsipp.Doc'. * }
- { * * }
- { *************************************************************************** }
-
-
-
- Const { Menu Data Structure Constants }
-
- MENU_RECORD_LIMIT=40; { maximum number of entries allowed in any given menu }
-
- MAX_SIZE_OF_MENU_PROMPT=40; { size of menu prompt string }
-
-
-
- Type { Menu Data Structure }
-
- MenuRecordPtr=^MenuRecord; { pointer to a menu template record stored in the heap }
- MenuRecord= { record type used for menu templates used to store }
- Record { specific information about a particular menu prompt }
- PromptCol,
- PromptRow,
- UpKeyPointer,
- DownKeyPointer,
- LeftKeyPointer,
- RightKeyPointer:Integer;
- Prompt:String[MAX_SIZE_OF_MENU_PROMPT];
- End; { MenuRecord }
-
- TypicalMenuPage= { an record data type which stores }
- Record { for each menu: }
- Image:TextScreenPtr; { a menu screen image }
- Template:Array[1..MENU_RECORD_LIMIT] Of MenuRecordPtr; { a menu screen template }
- End; { TypicalMenuPage }
-
-
-
- Var { Menu Data Structure Variables }
-
- Menus:
- Array[1..MAX_NUM_OF_MENU_PAGES] Of TypicalMenuPage; { an array constructed of the data type TypicalMenuPage }
-
-
-
- Procedure ReadMenuFiles;
-
- { This procedure reads the menu screen page images and templates and stores
- them into the proper Menus[MenuPage] record. Note that menu screen page
- images are stored under the file names 'Menu##.Col(or Mon)', where ##
- refers to the menu page number, 'Col' refers to a color screen page, and
- 'Mon' refers to a monochrome screen page. Note that menu templates are
- stored under the file names 'Menu##.@@@', where ## refers to the menu page
- number and '@@@' refers to template file extension constant previously
- defined in the file 'Main.Mod'.
-
- Note that the template records are pointed to by the template array (an
- array of pointers), and if there are not enough records from the template
- file to fill the template array of pointers for a particular menu page,
- those empty array pointers are set to Nil. }
-
- Var
- MenuPage:Integer; { an index to a particular menu page }
- RecordNumber:Integer; { an index to a particular menu template record }
- Page:String[2]; { a string used in determining the current menu page file number }
- MenuTemplateFile:File Of MenuRecord; { menu file template type }
-
- Begin { ReadMenuFiles }
- For MenuPage:=1 To MAX_NUM_OF_MENU_PAGES Do
- With Menus[MenuPage] Do
- Begin
-
- { determine file number portion of menu page file name }
- Str(MenuPage,Page); { convert integer file number into a string }
- If MenuPage<=9 Then
- Page:='0'+Page;
-
- { initializing screen page pointer }
- Image:=Nil;
-
- { read menu page screen image }
- ReadScreenPageFromFile('Menu_'+Page,Image);
-
- { read menu page template }
- Assign(MenuTemplateFile,'Menu_'+Page+TEMPLATE_FILE_NAME_EXTENSION); { assign to a disk file }
- Reset(MenuTemplateFile); { open the file for reading }
- For RecordNumber:=1 To MENU_RECORD_LIMIT Do
- If Not Eof(MenuTemplateFile) Then
- Begin
- New(Template[RecordNumber]); { allocate space in heap for template record }
- Read(MenuTemplateFile,Template[RecordNumber]^); { read record off of disk }
- End { If Not Eof }
- Else
- Template[RecordNumber]:=Nil; { no record to read, set pointer in template array to Nil }
- Close(MenuTemplateFile); { close the file }
-
- End; { With Menus[MenuPage] }
- End; { ReadMenuFiles }
-
-
-
- Procedure DisposeOfMenuDynamicMemory;
-
- { This procedure releases all the dynamically allocated memory used in for
- menu pages back to the operating system. }
-
- Var
- MenuPage:Integer; { an index to a particular MenuPage }
- Entry:Integer; { an index to a particular MenuPage template entry }
-
- Begin { DisposeOfMenuDynamicMemory }
- For MenuPage:=1 To MAX_NUM_OF_MENU_PAGES Do
- Begin
- Dispose(Menus[MenuPage].Image); { dispose screen page image }
- For Entry:=1 To MENU_RECORD_LIMIT Do
- If Menus[MenuPage].Template[Entry]<>Nil Then
- Dispose(Menus[MenuPage].Template[Entry]); { dispose of template entry }
- End; { For MenuPage }
- End; { DisposeOfMenuDynamicMemory }
-
-
-
- Procedure MoveHighlightedMenuPromptModule( OldPrompt,
- NewPrompt:Integer);
-
- { *************************************************************************** }
- { * * }
- { * MOVE HIGHLIGHTED MENU PROMPT MODULE * }
- { * * }
- { * This module controls the movement of the highlighted prompt for * }
- { * the passed old and new menu prompt for the current menu page. * }
- { * * }
- { *************************************************************************** }
-
- Procedure ShowMenuPrompt( MenuPrompt,
- PromptColor,
- PromptBackground:Integer);
-
- { This procedure is used exclusively to highlight the current menu prompt and
- also to de-highlight the previous menu prompt, depending upon the screen
- colors that are passed to this procedure. }
-
- Begin { ShowMenuPrompt }
- With Menus[MenuPage].Template[MenuPrompt]^ Do
- Begin
- TextColor(PromptColor);
- TextBackground(PromptBackground);
- GotoXY(PromptCol,PromptRow);
- Write(Prompt);
- End; { With Menus }
- End; { ShowMenuPrompt }
-
-
-
- Begin { MoveHighlightedMenuPromptModule }
- ShowMenuPrompt(OldPrompt,ForegroundColor,0); { de-highlight old menu prompt }
- ShowMenuPrompt(NewPrompt,HighlightColor,0); { highlight new menu prompt }
- End; { MoveHighlightedMenuPromptModule }
-
-
-
- Procedure DrawMenuPagesModule;
-
- { *************************************************************************** }
- { * * }
- { * DRAW MENU PAGES MODULE * }
- { * * }
- { * This module controls the display of particular menu pages. Note that * }
- { * the case statement below only supports 4 menu pages, but this can * }
- { * easily be added to inorder for this module to support additional * }
- { * menu pages. * }
- { * * }
- { * Note that within this module there is an example procedure that * }
- { * was used during program development to construct a screen page. * }
- { * Later, the screen pages are read from screen files and stored in the * }
- { * heap for more rapid display. * }
- { * * }
- { *************************************************************************** }
-
-
-
- Procedure WriteMenuPrompts;
-
- { This procedure locates and prints on the screen all the menu prompts for
- the current menu page. This procedure looks at the menu template to
- determine the required information for locating and printing out each menu
- prompt. }
-
- Var
- Entry:Integer; { index counter used in listing out the menu prompts from the menu template }
-
- Begin { WriteMenuPrompts }
- TextColor(ForegroundColor);
- TextBackground(MenuBackgroundColor);
- Entry:=1; { initialize menu prompt entry counter }
- While Menus[MenuPage].Template[Entry]<>Nil Do { check that there is a menu template record available to use }
- Begin { print out the menu prompt }
- With Menus[MenuPage].Template[Entry]^ Do
- Begin
- GotoXY(PromptCol,PromptRow);
- Write(Prompt);
- End; { With Menus }
- Entry:=Entry+1; { increment menu prompt entry counter }
- End; { While Menus }
- End; { WriteMenuPrompts }
-
-
-
- Procedure DrawMenuPage01;
-
- { This part of the procedure was used during program development of the
- example application of the input pre-processor to construct a screen page.
- This screen page is now stored in a screen file and thus the application
- program no longer needs this code. The screen page is read from a file and
- stored in the heap for display.
-
- You may want to write a similar procedure during your application program
- development. }
-
- Var
- TextString:WorkString; { string variable used in passing text to another procedure }
-
- Begin { DrawMenuPage01 }
-
- { draw outer screen boundary }
- TextColor(ForegroundColor);
- TextBackground(MenuBackgroundColor);
- DrawWindow2(1,1,80,25);
-
- { display program title }
- TextBackground(BackgroundColor);
- DrawWindow2(20,3,60,13);
- TextColor(HighlightColor);
- WriteCenterText(5,'COMPOSITE BEAM');
- WriteCenterText(7,'DESIGN PROGRAM');
- TextColor(ForegroundColor);
- WriteCenterText(9,'version 1.07');
- WriteCenterText(11,'written in Turbo Pascal');
-
- { display command menu on screen bottom }
- TextBackground(MenuBackgroundColor);
- TextString:='Make selection with '+Chr(24)+' '+Chr(25)+' and then press <ENTER>';
- WriteCenterText(25,TextString);
-
- WriteMenuPrompts;
- (* WriteScreenPageToFile('MENU_01'); { write the screen page off to a screen file } *)
- End; { DrawMenuPage01 }
-
-
-
- Begin { DrawMenuPagesModule }
- Case MenuPage Of
- 1 : Begin
- (* DrawMenuPage01; { this line was used during program development } *)
- DisplayScreenPage(Menus[MenuPage].Image); { display screen page that is stored in the heap }
- End; { page 1 }
- 2 : Begin
- End; { page 2 }
- 3 : Begin
- End; { page 3 }
- 4 : Begin
- End; { page 4 }
- End; { Case MenuPage }
- MoveHighlightedMenuPromptModule(1,1);
- End; { DrawMenuPagesModule }
-
-
-
- Procedure MenuModule;
-
- { *************************************************************************** }
- { * * }
- { * MENU MODULE * }
- { * * }
- { * This module takes care of the display and user interaction with * }
- { * the program's menus. This menu module uses menu templates in * }
- { * controlling the interaction between the user and the displayed * }
- { * menu. * }
- { * * }
- { * A menu template is simply a file containing information about the * }
- { * prompts (or descriptors) to be displayed when a particular menu is * }
- { * shown. A menu template is a series of records where each record * }
- { * describes one particular prompt in that menu. For more information * }
- { * on menu templates see the toolkit documentation file 'TOOLKIT.DOC'. * }
- { * * }
- { *************************************************************************** }
-
-
- Var { modular variables, i.e. global only to this module }
- CurrentMenuPrompt:Integer; { current menu prompt record being highlighted }
- OldMenuPrompt:Integer; { previous menu prompt that was highlighted }
-
-
-
- Procedure InitMenuVariables;
-
- { This procedure initializes the menu module's variables. }
-
- Begin { InitMenuVariables }
- OldMenuPrompt:=2;
- CurrentMenuPrompt:=1;
- End; { InitMenuVariables }
-
-
-
-
-
- Procedure Escape;
-
- { This procedure controls the entry of a escape command. Note that the
- case statement below only supports 4 menu pages, but can easily be added to
- inorder to support additional menu pages. }
-
- Begin { Escape }
- Case MenuPage Of
- 1 : Begin
- SoundError;
- End; { page 1 }
- 2 : Begin
- End; { page 2 }
- 3 : Begin
- End; { page 3 }
- 4 : Begin
- End; { page 4 }
- End; { Case MenuPage }
- End; { Escape }
-
-
-
- Procedure PageUp;
-
- { This procedure controls the entry of a page up command. Note that the
- case statement below only supports 4 menu pages, but can easily be added to
- inorder to support additional menu pages. }
-
- Begin { PageUp }
- Case MenuPage Of
- 1 : Begin
- SoundError;
- End; { page 1 }
- 2 : Begin
- End; { page 2 }
- 3 : Begin
- End; { page 3 }
- 4 : Begin
- End; { page 4 }
- End; { Case MenuPage }
- End; { PageUp }
-
-
-
- Procedure PageDown;
-
- { This procedure controls the entry of a page down command. Note that the
- case statement below only supports 4 menu pages, but can easily be added to
- inorder to support additional menu pages. }
-
- Begin { PageDown }
- Case MenuPage Of
- 1 : Begin
- SoundError;
- End; { page 1 }
- 2 : Begin
- End; { page 2 }
- 3 : Begin
- End; { page 3 }
- 4 : Begin
- End; { page 4 }
- End; { Case MenuPage }
- End; { PageDown }
-
-
-
- Procedure CurseUp;
-
- { This procedure controls the cursor's upward movement in the current menu.
- It checks the menu template for the current menu page to see if the
- requested cursor move is legal. }
-
- Begin { CurseUp }
- With Menus[MenuPage].Template[CurrentMenuPrompt]^ Do
- Begin
- If UpKeyPointer<>0 Then { check if legal move }
- Begin { legal move }
- OldMenuPrompt:=CurrentMenuPrompt;
- CurrentMenuPrompt:=UpKeyPointer;
- MoveHighlightedMenuPromptModule(OldMenuPrompt,CurrentMenuPrompt);
- End { If UpKeyPointer }
- Else { not a legal move }
- SoundError;
- End; { With Menus }
- End; { CurseUp }
-
-
-
- Procedure CurseDown;
-
- { This procedure controls the cursor's downward movement in the current
- menu. It checks the menu template for the current menu page to see if the
- requested cursor move is legal. }
-
- Begin { CurseDown }
- With Menus[MenuPage].Template[CurrentMenuPrompt]^ Do
- Begin
- If DownKeyPointer<>0 Then { check if legal move }
- Begin { legal move }
- OldMenuPrompt:=CurrentMenuPrompt;
- CurrentMenuPrompt:=DownKeyPointer;
- MoveHighlightedMenuPromptModule(OldMenuPrompt,CurrentMenuPrompt);
- End { If DownKeyPointer }
- Else { not a legal move }
- SoundError;
- End; { With Menus }
- End; { CurseDown }
-
-
-
- Procedure CurseLeft;
-
- { This procedure controls the cursor's leftward movement in the current
- menu. It checks the menu template for the current menu page to see if the
- requested cursor move is legal. }
-
- Begin { CurseLeft }
- With Menus[MenuPage].Template[CurrentMenuPrompt]^ Do
- Begin
- If LeftKeyPointer<>0 Then { check if legal move }
- Begin { legal move }
- OldMenuPrompt:=CurrentMenuPrompt;
- CurrentMenuPrompt:=LeftKeyPointer;
- MoveHighlightedMenuPromptModule(OldMenuPrompt,CurrentMenuPrompt);
- End { If LeftKeyPointer }
- Else { not a legal move }
- SoundError;
- End; { With Menus }
- End; { CurseLeft }
-
-
-
- Procedure CurseRight;
-
- { This procedure controls the cursor's rightward movement in the current
- menu. It checks the menu template for the current menu page to see if the
- requested cursor move is legal. }
-
- Begin { CurseRight }
- With Menus[MenuPage].Template[CurrentMenuPrompt]^ Do
- Begin
- If RightKeyPointer<>0 Then { check if legal move }
- Begin { legal move }
- OldMenuPrompt:=CurrentMenuPrompt;
- CurrentMenuPrompt:=RightKeyPointer;
- MoveHighlightedMenuPromptModule(OldMenuPrompt,CurrentMenuPrompt);
- End { If RightKeyPointer }
- Else { not a legal move }
- SoundError;
- End; { With Menus }
- End; { CurseRight }
-
-
-
- Procedure ProgramControl;
-
- { This procedure is used by the example application of the input
- pre-processor to give an example of a menu control. You may want to write
- a similar procedure for your application.
-
- This procedure follows the user's system command from the program's menu:
-
- Input Member Data
- Execute Analysis and Design
- Print Design Results
- Exit Program
-
- Note that this procedure is setup to pass control to G_I_Page 1 or to
- exit the pre-processor. }
-
- Begin { ProgramControl }
- Case CurrentMenuPrompt Of
- 1 : Begin { Input Member Data }
- CurrentPage:=G_I; { pass control to G_I_Page 1 }
- G_I_Page:=1;
- End; { Input Member Data }
- 2 : Begin { Execute Analysis and Design }
- CurrentPage:=G_I; { pass control to G_I_Page 1 }
- G_I_Page:=1;
- End; { Execute Analysis and Design }
- 3 : Begin { Print Design Results }
- CurrentPage:=G_I; { pass control to G_I_Page 1 }
- G_I_Page:=1;
- End; { Print Design Results }
- 4 : Begin { Exit Program }
- CurrentPage:=Exit; { exit program back to operating system }
- End; { Exit Program }
- End; { Case CurrentMenuPrompt }
- End; { ProgramControl }
-
-
-
- Procedure MenuControl;
-
- { This procedure is used in the passing of control to specific procedures for
- the control of particular menus. Note that the below Case statement only
- supports 4 menu pages, but this can easily be added to inorder to support
- additional menu pages. }
-
- Begin { MenuControl }
- Case MenuPage Of
- 1 : Begin
- ProgramControl;
- End; { page 1 }
- 2 : Begin
- End; { page 2 }
- 3 : Begin
- End; { page 3 }
- 4 : Begin
- End; { page 4 }
- End; { Case MenuPage }
- End; { MenuControl }
-
-
-
- Procedure ReadKeyboard;
-
- { This procedure determines what the user's keyboard entry is. It then
- passes control to specific procedures as screen commands are called upon. }
-
- Var
- KeyboardEntry:Char; { character variable used in reading the keyboard }
-
- Begin { ReadKeyboard }
- Repeat
- Read(Kbd,KeyboardEntry);
- If (KeyboardEntry=Chr(27)) And Keypressed Then { read a character, check for a double character entry }
- Begin { double character entry }
- Read(Kbd,KeyboardEntry);
- Case Ord(KeyboardEntry) Of
- 73 : PageUp;
- 81 : PageDown;
- 72 : CurseUp;
- 80 : CurseDown;
- 75 : CurseLeft;
- 77 : CurseRight;
- Else { illegal keystroke }
- SoundError;
- End; { Else }
- End { If KeyboardEntry }
- Else { single character entry }
- Case Ord(KeyBoardEntry) Of
- 27 : Escape;
- 13 : Begin { absorb the return keystroke }
- End;
- Else { illegal keystroke }
- SoundError;
- End; { Case KeyBoardEntry }
- Until KeyboardEntry=Chr(13); { until received carriage return }
- End; { ReadKeyboard }
-
-
-
- Begin { MenuModule }
- InitMenuVariables;
- DrawMenuPagesModule;
- ReadKeyboard;
- MenuControl;
- End; { MenuModule }