home *** CD-ROM | disk | FTP | other *** search
- { ******************* Start of EBMenu Function *************************}
-
- {EBMenu function: this function will do a menu in the form common to many
- of the better spreadsheet packages where a line in displayed
- and the user is allowed to select an item from that line
- by either using the left and right arrow keys followed by
- pressing the <Enter> key or may alternately press any
- character that matches the first letter of one of the words
- in the menu line (case does not matter). The function
- returns a byte argument that corresponds to the number
- of the field selected. There may be from 1 to 10 fields.
-
- Special features to make it even easier for your users
- are that the space-bar and tab act just like the
- right arrow. The backspace and reverse-tab act just
- like the left arrow. Home, Up and PgUp jump to
- beginning of the list and End, Down and PgDn jump to the
- end of the list.
-
- You may set options that either end the menu if the user
- presses the Escape key or, alternately, you may trap the
- Funtion keys (unshifted f1 thru f10 only).
-
- If Escape is allowed, the pressing Escape returns a zero,
- if function keys are allowed, the number returned is from
- 59 thry 68 for f1 thru f10 respectively.
-
- To test this program, compile and run the EBMDEMO.PAS
- program that should have been distributed with this
- function.
- }
- { Author: Ed Bachmann 5/28/85 version 1.00
- 9421 Mellenbrook Rd.
- Columbia,Md. , 21045
- Please send comments and suggestions to me on one
- of the following remote bulletin board systems:
- Elkridge-All-Purpose (301) 796-1223
- Capital PC Stat SIG (301) 596-3569
- Forbin Project (319) 266-8086
- }
-
- { My Apoligies, but the arguments for the functions get kind of complicated:
- Code = Byte : Special code that defines and allows for special
- keys to terminate the menu.
- 1 = End if user selects a field and also
- if user presses the <ESCape> key.
- 2 = End only when user selects a field. Does not
- recognize Escape key or function keys.
- 3 = End if user selects a field and also end if the
- user presses the Escape key or any of the 10
- function keys.
- 4 = Like 3 above but Escape is not recognized.
- Note: if an invalid number is passed, the default is 1.
- Line1 = Byte : The screen line # (1-25) that the menu will use to
- display the 1st line (menu line) on.
- Line2 = Byte : The screen line # (0-25) that the explanation line
- will be displayed on. If 0, then no 2nd line used.
- Forgrnd = byte : the forground color (0-15)
- Bkgrnd = byte : the background color (0-7)
- Note: if Forground and background are the same (or
- obvious illegal combos) the NormVideo and LowVideo
- commands will be used instead of the TextColor and
- TextBackground commands.
- Start = byte : the number of the menu item you want highlighted when
- the menu is first brought up.
- ItemCtr = byte : the number of menu items to use (1-10). Max of ten.
- Header = String : Max length 78 : The non-menu portion of the 1st line.
- TxtMenu = String : Max length 78 : The menu portion of the 1st line,
- a menu item is a word with one or more spaces before
- or behind it. The ItemCtr (above) must be equal or
- less than the number of words in the string.
- The total length of Header and TxtMenu really ought
- to be less than or equal to 79.
- ExpN : Explanation fields Exp1 thru Exp10
- = String : Max length 79 characters :
- These fields hold the descriptions or whatever you
- want displayed when the menu word is high-lighted.
- All of these strings must be passed to the function,
- this is true even if you don't want to use this field.
- Just use 2 single quotes or something to define a null
- field. If Line2 (above) is 0 or if the MenuCtr is less
- than the ExpN position, this line will not be
- displayed.
- }
-
- { usage: ByteVar:=EBMenu(Code,Line1,Line2,Forgrnd,Backgrnd,
- Start,NumberItems,
- Header,TextMenu,
- Exp1,Exp2,Exp3,Exp4,Exp5,
- Exp6,Exp7,Exp8,Exp9,Exp10);
- }
-
- { example: RetCode:=EBMenu(1,1,2,White,Black,
- RetCode,8,
- 'Header: ','1st 2nd 3rd 4th 5th 6th 7th 8th',
- 'Do the 1st thing','Do the 2nd thing',
- 'Do the 3rd thing','Do the 4th thing',
- 'Do the 5th thing','Do the 6th thing',
- 'Do the 7th thing','Do the 8th thing',
- '','');
- }
-
-
- type
- EBMstring80 = String[80];
-
- function EBMenu(Code,Line1,Line2,Forgrnd,Bkgrnd,
- StartAt,MenuCtr:Byte;
- Header,TxtMenu,
- Exp1,Exp2,Exp3,Exp4,Exp5,
- Exp6,Exp7,Exp8,Exp9,Exp10:
- EBMstring80):byte;
-
- var
- MI1,MI2,SIndx : byte;
- RevForgrnd,Revbkgrnd : byte;
- Ch1,Ch2 : char;
- ExitMenu : boolean;
- Choices : Array [1..10] of char;
- ChoiceStart,ChoiceEnd : array [1..10] of byte;
-
- begin
- if StartAt=0 then StartAt:=1;
- if MenuCtr < 1 then MenuCtr:=1; {validate counter}
- if MenuCtr > 10 then MenuCtr:=10;
- RevForgrnd:=(Bkgrnd + 8); {make reverse video forgound bright}
- Revbkgrnd:=(Forgrnd mod 8); {set rev video background color}
- if (Forgrnd=Bkgrnd) or (RevForgrnd=RevBkgrnd) then
- NormVideo {if colors are invalid then use normal video}
- else
- begin
- TextColor(Forgrnd);
- TextBackground(Bkgrnd);
- end;
- GotoXY(1,Line1); {clear the 2 lines to default colors}
- Write(Header);
- Write(TxtMenu);
- ClrEol;
- For MI1:=1 to 10 do {clear the choices table}
- begin
- Choices[MI1]:=' ';
- ChoiceStart[MI1]:=0;
- ChoiceEnd[MI1]:=0;
- end;
- MI1:=1;
- MI2:=0;
- while (MI2<MenuCtr) do {save the choices in a table}
- begin {by finding 1st character in each word}
- while (MI1<ord(TxtMenu[0])) and (TxtMenu[MI1]=' ') do
- MI1:=MI1+1;
- if (MI1<ord(TxtMenu[0])) then
- begin
- Choices[MI2+1]:=UpCase(TxtMenu[MI1]);
- ChoiceStart[MI2+1]:=MI1;
- while (MI1<ord(TxtMenu[0])+1) and (TxtMenu[MI1]<>' ') do
- MI1:=MI1+1;
- ChoiceEnd[MI2+1]:=MI1-1;
- end;
- MI2:=MI2+1;
- end;
- MenuCtr:=MI2;
- MI1:=StartAt;
- ExitMenu:=False;
- Ch1:=chr(221); {set to pass thru on the 1st time for display}
- while not ExitMenu do
- begin
- while Ch1=chr(222) do
- begin
- if keypressed then
- begin
- read(Kbd,Ch1);
- Ch1:=UpCase(Ch1);
- case ord(Ch1) of
- 08 : MI1:=MI1-1; {backspace}
- 09,32 : MI1:=MI1+1; {tab, space}
- 13 : ExitMenu:=True; {enter key - select current value}
- 27 : if keypressed then
- begin
- read(Kbd,Ch2);
- Case ord(Ch2) of
- 71,72,73 : MI1:=1; {Home, Up, PgUp keys}
- 75,15 : MI1:=MI1-1; {left arrow, rev-tab}
- 77 : MI1:=MI1+1; {right arrow}
- 79,80,81 : MI1:=MenuCtr; {End, down, PgDn keys}
- 59..68 : if (Code=3) or (Code=4) then
- begin
- MI1:=ord(ch2);
- ExitMenu:=True;
- end;
- end; {end of case}
- end
- else {if not keypressed - i.e. ESCape key}
- if (Code<>2) and (Code<>4) then
- begin
- MI1:=0;
- ExitMenu:=True;
- end;
- 33..125 : for MI2:=1 to MenuCtr do {check to see if in table}
- if Ch1=Choices[MI2] then
- begin
- MI1:=MI2; {if found then select & end}
- ExitMenu:=True;
- end;
- end; {end of case}
- end;
- end;
- EBMenu:=MI1;
- if (MI1<>0) or not ExitMenu then {display the choices line & description}
- begin
- if (Forgrnd=Bkgrnd) or (RevForgrnd=RevBkgrnd) then
- NormVideo {if colors are invalid then use normal video}
- else
- begin
- TextColor(Forgrnd);
- TextBackground(Bkgrnd);
- end;
- GotoXY(1+ord(Header[0]),Line1);
- Write(TxtMenu);
- ClrEol;
- if MI1<1 then MI1:=MenuCtr;
- if MI1>MenuCtr then MI1:=1;
- if Line2>0 then {description is skipped if line = 0 }
- begin
- GotoXY(1,Line2);
- case MI1 of
- 1 : Write(Exp1);
- 2 : Write(Exp2);
- 3 : Write(Exp3);
- 4 : Write(Exp4);
- 5 : Write(Exp5);
- 6 : Write(Exp6);
- 7 : Write(Exp7);
- 8 : Write(Exp8);
- 9 : Write(Exp9);
- 10 : Write(Exp10);
- end; {end of case}
- ClrEol;
- end; {end of if}
- if (Forgrnd=Bkgrnd) or (RevForgrnd=RevBkgrnd) then
- LowVideo {if colors are invalid then use low video}
- else
- begin
- TextColor(RevForgrnd); {reverse the colors for highlighting}
- TextBackground(RevBkgrnd);
- end;
- if (ChoiceStart[MI1]>0) then {display the currently selected word}
- begin
- GotoXY(ChoiceStart[MI1]+ord(Header[0]),Line1);
- for MI2:=ChoiceStart[MI1] to ChoiceEnd[MI1] do Write(TxtMenu[MI2]);
- GotoXY(ChoiceStart[MI1]+ord(Header[0]),Line1);
- end;
- end; {end of if MI1<>0}
- if (Forgrnd=Bkgrnd) or (RevForgrnd=RevBkgrnd) then
- NormVideo {if colors are invalid then use normal video}
- else
- begin
- TextColor(Forgrnd); {reset colors back to default colors}
- TextBackground(Bkgrnd);
- end;
- Ch1:=chr(222); {reset character for keyboard loop}
- end; {end of while not exitmenu}
- end;
-
- { ******************* End of EBMenu Function ***************************}
-