/****************************************************************
Turbo Prolog Toolbox
(C) Copyright 1987 Borland International.
menu
Implements a popup menu with at most 23
possible choices.
For more than 23 possible choices use
longmenu.
The up and down arrow keys can be used to
move the bar.
RETURN or F10 will select an indicated item.
Pressing Esc aborts menu selection and
returns zero.
The arguments to menu are:
menu(ROW,COL,WINDOWATTR,FRAMEATTR,STRINGLIST,HEADER,STARTCHOICE,SELECTION)
ROW and COL determines the position of the
window
WATTR and FATTR determine the attributes
for the window
and its frame - if FATTR is zero
there
will be no frame around the window.
STRINGLIST is the list of menu items
HEADER is the text to appear at the top of
the menu window
STARTCHOICE determines where the bar
should be placed.
Ex:
menu(5,5,7,7,[this,is,a,test],"select word",0,CHOICE)
****************************************************************/
PREDICATES
menu2(char(C),LIST,_,_,CH,selection):-tryletter(C,LIST,CH),!.
/*menu2(fkey(1),_,_,ROW,ROW,cont):-!,help. If a help system is used */
menu2(cr,_,_,ROW,CH,selection):-!,CH=ROW.
menu2(pgdn,_,MAXROW,_,NEXT,cont):-!,NEXT=MAXROW-1.
menu2(home,_,_,_,0,cont):-!.
menu2(pgup,_,_,_,0,cont):-!.
menu2(_,_,_,ROW,ROW,cont).
/****************************************************************/
/* menu_leave */
/* As
menu but the window is not removed on return. */
/****************************************************************/
PREDICATES
menu_leave(ROW,COL,WATTR,FATTR,LIST,HEADER,STARTCHOICE,CHOICE) :-
menuinit(ROW,COL,WATTR,FATTR,LIST,HEADER,NOOFROW,NOOFCOL),
ST1=STARTCHOICE-1,max(0,ST1,ST2),MAX=NOOFROW-1,min(ST2,MAX,STARTROW),
menu1(cont,STARTROW,WATTR,LIST,NOOFROW,NOOFCOL,CHOICE).
/****************************************************************
menu_mult
Implements a popup-menu which allows a
multiple number of
selections.
Each selection is made by pressing RETURN.
All selections are
then activated by pressing F10.
The arguments to menu_mult are:
menu(ROW,COL,WINDOWATTR,FRAMEATTR,STRINGLIST,HEADER,STARTLIST,NEWLIST)
ROW and COL determine the position of the
window
WATTR and FATTR determine the attributes
for the window
and its frame - if FATTR is zero
there
will be no frame around the window.
STRINGLIST is the list of menu items
HEADER is the text to appear at the top of
the menu window
STARTLIST determines the items to be
highlighted when
the menu is first displayed
NEWLIST
contains the list of selections
Ex:
menu_mult(5,5,7,7,[this,is,a,test],"select words",[1],NEWLIST)
****************************************************************/
PREDICATES
handle_selection(SELECTION,OLDCHIN,[SELECTION|OLDCHIN],_,_).
/****************************************************************/
/* In
order to use the tools, the following domain declarations */
/*
should be included in the start of your program */
/****************************************************************/
GLOBAL
DOMAINS
ROW, COL, LEN, ATTR = INTEGER
STRINGLIST = STRING*
INTEGERLIST = INTEGER*
KEY
= cr; esc; break; tab; btab; del; bdel; ctrlbdel; ins;
end ; home ; fkey(INTEGER) ; up ; down ;
left ; right ;
ctrlleft; ctrlright; ctrlend; ctrlhome;
pgup; pgdn;
ctrlpgup; ctrlpgdn; char(CHAR) ; otherspec
/****************************************************************/
/* This
module includes some routines which are used in nearly */
/* all
menu and screen tools. */
/****************************************************************/
/****************************************************************/
/* repeat */
/****************************************************************/
PREDICATES
nondeterm repeat
CLAUSES
repeat.
repeat:-repeat.
/****************************************************************/
/* miscellaneous */
/****************************************************************/
PREDICATES
maxlen(STRINGLIST,COL,COL) /* The length of the longest string */
listlen(STRINGLIST,ROW) /* The length of a list
*/
writelist(ROW,COL,STRINGLIST) /* used in the menu predicates
*/
reverseattr(ATTR,ATTR) /* Returns the reversed
attribute */
min(ROW,ROW,ROW) min(COL,COL,COL)
min(LEN,LEN,LEN) min(INTEGER,INTEGER,INTEGER)
max(ROW,ROW,ROW) max(COL,COL,COL)
max(LEN,LEN,LEN) max(INTEGER,INTEGER,INTEGER)
CLAUSES
maxlen([H|T],MAX,MAX1) :-
str_len(H,LENGTH),
LENGTH>MAX,!,
maxlen(T,LENGTH,MAX1).
maxlen([_|T],MAX,MAX1) :-
maxlen(T,MAX,MAX1).
maxlen([],LENGTH,LENGTH).
listlen([],0).
listlen([_|T],N):-
listlen(T,X),
N=X+1.
writelist(_,_,[]).
writelist(LI,ANTKOL,[H|T]):-
field_str(LI,0,ANTKOL,H),
LI1=LI+1,
writelist(LI1,ANTKOL,T).
min(X,Y,X):-X<=Y,!.
min(_,X,X).
max(X,Y,X):-X>=Y,!.
max(_,X,X).
reverseattr(A1,A2):-
bitand(A1,$07,H11),
bitleft(H11,4,H12),
bitand(A1,$70,H21),
bitright(H21,4,H22),
bitand(A1,$08,H31),
A2=H12+H22+H31.
/****************************************************************/
/* Find letter selection in a list of strings */
/* Look initially for first uppercase
letter. */
/* Then try with first letter of each
string. */
/****************************************************************/
PREDICATES
upc(CHAR,CHAR) lowc(CHAR,CHAR)
try_upper(CHAR,STRING)
tryfirstupper(CHAR,STRINGLIST,ROW,ROW)
tryfirstletter(CHAR,STRINGLIST,ROW,ROW)
tryletter(CHAR,STRINGLIST,ROW)
CLAUSES
upc(CHAR,CH):-
CHAR>='a',CHAR<='z',!,
char_int(CHAR,CI), CI1=CI-32,
char_int(CH,CI1).
upc(CH,CH).
lowc(CHAR,CH):-
CHAR>='A',CHAR<='Z',!,
char_int(CHAR,CI), CI1=CI+32,
char_int(CH,CI1).
lowc(CH,CH).
try_upper(CHAR,STRING):-
frontchar(STRING,CH,_),
CH>='A',CH<='Z',!,
CH=CHAR.
try_upper(CHAR,STRING):-
frontchar(STRING,_,REST),
try_upper(CHAR,REST).
tryfirstupper(CHAR,[W|_],N,N) :-
try_upper(CHAR,W),!.
tryfirstupper(CHAR,[_|T],N1,N2) :-
N3 = N1+1,
tryfirstupper(CHAR,T,N3,N2).
tryfirstletter(CHAR,[W|_],N,N) :-
frontchar(W,CHAR,_),!.
tryfirstletter(CHAR,[_|T],N1,N2) :-
N3 = N1+1,
tryfirstletter(CHAR,T,N3,N2).
tryletter(CHAR,LIST,SELECTION):-
upc(CHAR,CH),tryfirstupper(CH,LIST,0,SELECTION),!.
tryletter(CHAR,LIST,SELECTION):-
lowc(CHAR,CH),tryfirstletter(CH,LIST,0,SELECTION).
/*****************************************************************/
/*
adjustwindow takes a windowstart and a windowsize and adjusts */
/* the
windowstart so the window can be placed on the screen. */
/*
adjframe looks at the frameattribute: if it is different from */
/*
zero, two is added to the size of the window
*/
/****************************************************************/
PREDICATES
adjustwindow(ROW,COL,ROW,COL,ROW,COL)
adjframe(ATTR,ROW,COL,ROW,COL)
CLAUSES
adjustwindow(LI,KOL,DLI,DKOL,ALI,AKOL):-
LI<25-DLI,KOL<80-DKOL,!,ALI=LI,AKOL=KOL.
adjustwindow(LI,_,DLI,DKOL,ALI,AKOL):-
LI<25-DLI,!,ALI=LI,AKOL=80-DKOL.
adjustwindow(_,KOL,DLI,DKOL,ALI,AKOL):-
KOL<80-DKOL,!,ALI=25-DLI,
AKOL=KOL.
adjustwindow(_,_,DLI,DKOL,ALI,AKOL):-
ALI=25-DLI, AKOL=80-DKOL.
adjframe(0,R,C,R,C):-!.
adjframe(_,R1,C1,R2,C2):-R2=R1+2, C2=C1+2.
/****************************************************************/
/* Readkey */
/*
Returns a symbolic key from the KEY domain */
/****************************************************************/
PREDICATES
readkey(KEY)
readkey1(KEY,CHAR,INTEGER)
readkey2(KEY,INTEGER)
CLAUSES