home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l216 / 1.ddi / TREE.PRO < prev    next >
Encoding:
Prolog Source  |  1987-03-23  |  15.8 KB  |  479 lines

  1. /****************************************************************
  2.  
  3.      Turbo Prolog Toolbox
  4.      (C) Copyright 1987 Borland International.
  5.  
  6.         Treemenu
  7. ****************************************************************/
  8.  
  9. /*
  10. include "tdoms.pro"
  11.  
  12. DOMAINS
  13.   SELECTOR=INTEGER
  14.   TREE = tree(STRING,SELECTOR,TREELIST)
  15.   TREELIST = TREE*
  16.  
  17. DATABASE
  18.   treewindow(ROW,COL)
  19.   treechoice(SELECTOR)
  20. */
  21.  
  22. DOMAINS
  23.   ROWLIST=ROW*
  24.   COLLIST=COL*
  25.  
  26. PREDICATES
  27.   treemenu(SYMBOL,TREE,SELECTOR)
  28.   treeaction(SELECTOR)
  29.  
  30.   draw(symbol,TREE)
  31.  
  32.   writetext(ROW,COL,INTEGER,STRING,SELECTOR)
  33.   treeline_ver(ROW,ROW,COL)
  34.   treeline_ver1(ROW,ROW,COL)
  35.   treeline_hor(COL,COL,ROW)
  36.   treeline_hor1(COL,COL,ROW)
  37.   scr_ch(ROW,COL,CHAR)  
  38.  
  39.   lastinlist(ROW,ROWLIST)
  40.   lastinlist(COL,COLLIST)
  41.   incrow(ROW,ROW,COL,COL)
  42.   listsum(ROWLIST,ROW)
  43.   listsum(COLLIST,COL)
  44.   treekeyact(KEY)
  45.   just(ROW,COL)
  46.   just1(ROW,COL,ROW,COL)
  47.   just2(ROW,COL)
  48.   nodelistlen(ROWLIST,INTEGER)
  49.   nodelistlen(COLLIST,INTEGER)
  50.   remove_treechoice
  51.   newupdate(DBASEDOM)
  52.   treedrop(INTEGER,STRING,STRING)
  53.   
  54.  
  55. CLAUSES
  56. /* draw vertical lines connecting elements in the tree */
  57.   treeline_ver(R1,R2,C):-
  58.       treewindow(STROW,STCOL),           /* find the starting position */
  59.       makewindow(_,_,_,_,_,_,ROWS,COLS), /* returns the tree windows size */
  60.       C>=STCOL, C<STCOL+COLS-2, R1<STROW+ROWS-2,  
  61.       R2>=STROW, SLROW=STROW+ROWS-2,
  62.     max(STROW,R1,STROW1), min(R2,SLROW,SLROW1),
  63.     CC=C-STCOL, RR1=STROW1-STROW, RR2=SLROW1-STROW,
  64.     treeline_ver1(RR1,RR2,CC),fail.
  65.   treeline_ver(_,_,_).
  66.  
  67.   treeline_ver1(R1,R2,C):-
  68.     R2>R1, R=R1+1,
  69.     scr_char(R1,C,'│'),
  70.     treeline_ver1(R,R2,C).
  71.  
  72. /* draw horizontal lines connecting elements in the tree */
  73.   treeline_hor(C1,C2,R):-
  74.       treewindow(STROW,STCOL), makewindow(_,_,_,_,_,_,ROWS,COLS),
  75.     SLCOL=STCOL+COLS-2,
  76.       R>=STROW, R<STROW+ROWS-2, C1<SLCOL, C2>STCOL,
  77.     max(STCOL,C1,STCOL1), min(C2,SLCOL,SLCOL1),
  78.     RR=R-STROW, CC1=STCOL1-STCOL, CC2=SLCOL1-STCOL,
  79.     treeline_hor1(CC1,CC2,RR),fail.
  80.   treeline_hor(_,_,_).
  81.  
  82.   treeline_hor1(C1,C2,R):-
  83.     C2>C1, C=C1+1,
  84.     scr_char(R,C1,'─'),
  85.     treeline_hor1(C,C2,R).
  86.  
  87. /* write a character in a tree window  */
  88.   scr_ch(R,C,CH):-
  89.       treewindow(STROW,STCOL), makewindow(_,_,_,_,_,_,ROWS,COLS),
  90.       R>=STROW, R<STROW+ROWS-2, C>=STCOL, C<STCOL+COLS-2, !,
  91.     RR=R-STROW, CC=C-STCOL,
  92.     scr_char(RR,CC,CH).
  93.   scr_ch(_,_,_).
  94.  
  95.   treedrop(0,TEXT,TEXT):-!.
  96.   treedrop(N,TEXT,TEXT1):-frontstr(N,TEXT,_,TEXT1).
  97.  
  98.   writetext(ROW,COL,ATTR,TEXT,SELECT):-
  99.       str_len(TEXT,LEN),
  100.       treewindow(STROW,STCOL), makewindow(_,_,_,_,_,_,ROWS,COLS),
  101.       ROW>=STROW, ROW<STROW+ROWS-2, COL<STCOL+COLS-2, COL+LEN>STCOL,
  102.       REALROW=ROW-STROW,
  103.       RSTART=COL-STCOL,
  104.       REND=RSTART+LEN,
  105.     VST=STCOL-STCOL, VEND=VST+COLS-2,
  106.     max(RSTART,VST,RSTART1), min(REND,VEND,REND1),
  107.     REALLEN=REND1-RSTART1,
  108.     DROP=RSTART1-RSTART,
  109.     treedrop(DROP,TEXT,TEXT1),
  110.     field_str(REALROW,RSTART1,REALLEN,TEXT1),
  111.     field_attr(REALROW,RSTART1,REALLEN,ATTR),
  112.     cursor(R,C),
  113.     R=REALROW,
  114.     C>=RSTART1, C<RSTART1+REALLEN,!,
  115.     field_attr(R,RSTART1,REALLEN,1),
  116.     assert(treechoice(SELECT)).
  117.   writetext(_,_,_,_,_).
  118.  
  119.  
  120.   listsum(  [],0):-!.
  121.   listsum([H|T],N):-listsum(T,N1),N=N1+H.
  122.  
  123.   incrow(ROW,NEW,COL,COL):-!,NEW=ROW+2.
  124.   incrow(ROW,NEW,_,_):-NEW=ROW+2.
  125.     
  126.   lastinlist(RMAX,[RMAX]) :- !.
  127.   lastinlist(RMAX,[_|T]) :- lastinlist(RMAX,T).
  128.  
  129.   nodelistlen([],0).
  130.   nodelistlen([_|T],N):-
  131.     nodelistlen(T,X),
  132.     N=X+1.
  133.  
  134.   newupdate(_):-retract(treewindow(_,_)),fail.
  135.   newupdate(X):-assert(X).
  136.  
  137. /* Cursor window control */
  138.   just(R,C):-
  139.     cursor(ROW,COL),       /* current cursor pos */
  140.     RR=ROW+R, CC=COL+C,
  141.     makewindow(_,_,_,_,_,_,ROWS,COLS),
  142.     ROWSS=ROWS-3, COLSS=COLS-3,
  143.     just1(RR,CC,ROWSS,COLSS).
  144.  
  145. /* move cursor and control windows */
  146.   just1(R,C,_,_):-R<0,!,cursor(0,C),just2(R,0).
  147.   just1(R,C,_,_):-C<0,!,cursor(R,0),just2(0,C).
  148.   just1(R,C,ROWS,_):-R>ROWS,!,cursor(ROWS,C),DR=R-ROWS,just2(DR,0).
  149.   just1(R,C,_,COLS):-C>COLS,!,cursor(R,COLS),DC=C-COLS,just2(0,DC).
  150.   just1(R,C,_,_):-cursor(R,C),fail.
  151.  
  152. /* scroll tree in window with cursor and update tree position */
  153.   just2(DR,DC):-
  154.     scroll(DR,DC),  /* scroll is a Turbo Prolog standard predicate */
  155.       treewindow(R,C),!,
  156.     CC=C+DC, RR=R+DR,
  157.     newupdate(treewindow(RR,CC)), 
  158.     fail.
  159.  
  160. /* Tree input key action */
  161.   treekeyact(right)    :-just(0,1).
  162.   treekeyact(ctrlright)    :-just(0,5).
  163.   treekeyact(left)    :-just(0,-1).
  164.   treekeyact(ctrlleft)    :-just(0,-5).
  165.   treekeyact(up)    :-just(-1,0).
  166.   treekeyact(pgup)    :-just(-5,0).
  167.   treekeyact(down)    :-just(1,0).
  168.   treekeyact(pgdn)    :-just(5,0).
  169.   treekeyact(ctrlhome)    :-treewindow(R,C),!,RR=-R,CC=-C,just2(RR,CC).
  170.   treekeyact(end)    :-cursor(_,C),makewindow(_,_,_,_,_,_,_,COLS),
  171.               DC=COLS-3-C,just(0,DC).
  172.   treekeyact(home)    :-cursor(_,C),DC=-C,just(0,DC).
  173.   treekeyact(cr)    :-treechoice(CHOICE),!,treeaction(CHOICE).
  174.   treekeyact(esc).
  175.   treekeyact(fkey(10)).
  176.  
  177.  
  178. /*treekeyact(fkey(1)):-help.  If helpsystem is used */
  179.  
  180.   remove_treechoice:-retract(treechoice(_)),fail.
  181.   remove_treechoice.
  182.  
  183.  
  184. /****************************** DRAW RIGHT ****************************/
  185.  
  186. PREDICATES
  187.   draw_right(TREE,ROW,ROW,COL,COL,COL,COL,ROW)
  188.   draw_rightlist(TREELIST,ROWLIST,ROWLIST,ROW,ROW,COL,COL,COL,COL)
  189.   connect_nodesright(ROW,COL,INTEGER,COL,ROWLIST)
  190.   con_nodesright(ROW,COL,ROW,ROW,COL,ROWLIST)
  191.   cornerright(ROW,ROW,ROW,ROW,CHAR)
  192.   check_lastright(ROW,COL,ROWLIST)
  193.  
  194. CLAUSES
  195.  
  196.   draw_right(_,_,_,_,_,_,_,_):-keypressed,!,readkey(KEY),treekeyact(KEY),fail.
  197.   draw_right(tree(NAME,SELECT,[]),CURROW,NEWCURROW,LASTNAMECOL,CURCOL,CURCOL,_,RESROW):-!,
  198.     incrow(CURROW,NEWCURROW,LASTNAMECOL,CURCOL),
  199.     RESROW=NEWCURROW,
  200.     writetext(RESROW,CURCOL,112,NAME,SELECT).
  201.   draw_right(tree(NAME,SELECT,TREELIST),CURROW,NEWCURROW,LASTNAMECOL,NEXTNAMECOL,CURCOL,COLSTEP,RESROW):-
  202.     str_len(NAME,NAMELEN),
  203.     CURCOL1=1+NAMELEN+CURCOL+COLSTEP,
  204.     draw_rightlist(TREELIST,[],NODEROWLIST,CURROW,NEWCURROW,LASTNAMECOL,NEXTNAMECOL,CURCOL1,COLSTEP),
  205.     nodelistlen(NODEROWLIST,LEN),
  206.     listsum(NODEROWLIST,SUM),
  207.     RESROW=SUM div LEN,
  208.     COLAFTERNAME=1+CURCOL+NAMELEN,
  209.     connect_nodesright(RESROW,COLAFTERNAME,LEN,CURCOL1,NODEROWLIST),
  210.     writetext(RESROW,CURCOL,112,NAME,SELECT),
  211.     COLAFTERNAME1=CURCOL+NAMELEN,
  212.     scr_ch(RESROW,COLAFTERNAME1,'─'),
  213.     check_lastright(RESROW,COLAFTERNAME,NODEROWLIST).
  214.  
  215.   draw_rightlist([],NodeRowList,NodeRowList,CurRow,CurRow,NEXTNAMECOL,NEXTNAMECOL,_,_).
  216.   draw_rightlist([H|T],NodeRowList,ResNodeRowList,CurRow,CurRow2,LNCOL1,LNCOL3,CurCol,Colstep):-
  217.     draw_right(H,CurRow,Currow1,LNCOL1,LNCOL2,Curcol,Colstep,Noderow),
  218.     draw_rightlist(T,[Noderow|NodeRowList],ResNodeRowList,CurRow1,CurRow2,LNCOL2,LNCOL3,CurCol,Colstep).
  219.  
  220.   check_lastright(ROW,_,[ROW|_]):-!.
  221.   check_lastright(ROW,COL,[_|LIST]):-!,check_lastright(ROW,COL,LIST).
  222.   check_lastright(ROW,COL,_):-scr_ch(ROW,COL,'┤').
  223.  
  224.   connect_nodesright(ROW,COL,1,COL1,_) :-!,
  225.         treeline_hor(COL,COL1,ROW).
  226.   connect_nodesright(ROW,COL,_,COL1,[RMAX|L]):-
  227.         lastinlist(RMIN,[RMAX|L]),
  228.         con_nodesright(ROW,COL,RMIN,RMAX,COL1,[RMAX|L]).
  229.  
  230.   con_nodesright(_,_,_,_,_,[]).
  231.   con_nodesright(_,COL,_,_,_,[R1,R2|_]):-
  232.     R22=R2+1,
  233.     treeline_ver(R22,R1,COL), fail.
  234.   con_nodesright(ROW,COL,RMIN,RMAX,COL1,[ROW1|T]):-
  235.     CC=COL+1,
  236.     treeline_hor(CC,COL1,ROW1),
  237.     cornerright(ROW,RMIN,RMAX,ROW1,CORNCHAR),
  238.     scr_ch(ROW1,COL,CORNCHAR),
  239.     con_nodesright(ROW,COL,RMIN,RMAX,COL1,T).
  240.  
  241.   cornerright(RMIN,RMIN,_,RMIN,'┬') :- !.
  242.   cornerright(RMAX,_,RMAX,RMAX,'┴') :- !.
  243.   cornerright(_,RMIN,_,RMIN,'┌') :- !.
  244.   cornerright(_,_,RMAX,RMAX,'└') :- !.
  245.   cornerright(RMIDT,_,_,RMIDT,'┼') :- !.
  246.   cornerright(_,_,_,_,'├').
  247.  
  248. /************************** END DRAW RIGHT ****************************/
  249.  
  250.  
  251. /************************** DRAW LEFT *********************************/
  252.  
  253. PREDICATES
  254.   draw_left(TREE,ROW,ROW,COL,COL,COL,COL,ROW)
  255.   draw_leftlist(TREELIST,ROWLIST,ROWLIST,ROW,ROW,COL,COL,COL,COL)
  256.   connect_nodesleft(ROW,COL,INTEGER,COL,ROWLIST)
  257.   con_nodesleft(ROW,COL,ROW,ROW,COL,ROWLIST)
  258.   check_lastleft(ROW,COL,ROWLIST)
  259.   check_lastleft1(ROW,COL,ROWLIST)
  260.   cornerleft(ROW,ROW,ROW,ROW,CHAR)
  261.  
  262. CLAUSES
  263.   draw_left(_,_,_,_,_,_,_,_):-keypressed,!,readkey(KEY),treekeyact(KEY),fail.
  264.   draw_left(tree(NAME,SELECT,[]),CURROW,NEWCURROW,LASTNAMECOL,CURCOL,CURCOL,_,RESROW):-!,
  265.     incrow(CURROW,NEWCURROW,LASTNAMECOL,CURCOL),
  266.     RESROW=NEWCURROW,
  267.     str_len(NAME,NAMELEN),
  268.     COLAFTERNAME=CURCOL-NAMELEN,
  269.     writetext(RESROW,COLAFTERNAME,112,NAME,SELECT).
  270.   draw_left(tree(NAME,SELECT,TREELIST),CURROW,NEWCURROW,LASTNAMECOL,NEXTNAMECOL,CURCOL,COLSTEP,RESROW):-
  271.     str_len(NAME,NAMELEN),
  272.     CURCOL1=CURCOL-(COLSTEP+NAMELEN),
  273.     draw_leftlist(TREELIST,[],NODEROWLIST,CURROW,NEWCURROW,LASTNAMECOL,NEXTNAMECOL,CURCOL1,COLSTEP),
  274.     nodelistlen(NODEROWLIST,LEN),
  275.     listsum(NODEROWLIST,SUM),
  276.     RESROW=SUM div LEN,
  277.     COLAFTERNAME=CURCOL-NAMELEN-2,
  278.     COLAFTERNAME1=CURCOL-NAMELEN-1,
  279.     COLAFTERNAME2=CURCOL-NAMELEN,
  280.     connect_nodesleft(RESROW,COLAFTERNAME,LEN,CURCOL1,NODEROWLIST),
  281.     writetext(RESROW,COLAFTERNAME2,112,NAME,SELECT),
  282.     scr_ch(RESROW,COLAFTERNAME1,'─'),
  283.     check_lastleft(RESROW,COLAFTERNAME,NODEROWLIST).
  284.  
  285.   draw_leftlist([],NodeRowList,NodeRowList,CurRow,CurRow,NEXTNAMECOL,NEXTNAMECOL,_,_).
  286.   draw_leftlist([H|T],NodeRowList,ResNodeRowList,CurRow,CurRow2,LNCOL1,LNCOL3,CurCol,Colstep):-
  287.     draw_left(H,CurRow,Currow1,LNCOL1,LNCOL2,Curcol,Colstep,Noderow),
  288.     draw_leftlist(T,[Noderow|NodeRowList],ResNodeRowList,CurRow1,CurRow2,LNCOL2,LNCOL3,CurCol,Colstep).
  289.  
  290.   check_lastleft(ROW,COL,[_]):-!,scr_ch(ROW,COL,'─').
  291.   check_lastleft(ROW,COL,LIST):-check_lastleft1(ROW,COL,LIST).
  292.  
  293.   check_lastleft1(ROW,_,[ROW|_]):-!.
  294.   check_lastleft1(ROW,COL,[_|LIST]):-!,check_lastleft1(ROW,COL,LIST).
  295.   check_lastleft1(ROW,COL,_):-scr_ch(ROW,COL,'├').
  296.  
  297.   connect_nodesleft(ROW,COL,1,COL1,_) :-!,
  298.     treeline_hor(COL1,COL,ROW).
  299.   connect_nodesleft(ROW,COL,_,COL1,[RMAX|L]):-
  300.         lastinlist(RMIN,[RMAX|L]),
  301.         RR=RMIN+1,
  302.         treeline_ver(RR,RMAX,COL), 
  303.         con_nodesleft(ROW,COL,RMIN,RMAX,COL1,[RMAX|L]).
  304.  
  305.   con_nodesleft(_,_,_,_,_,[]).
  306.   con_nodesleft(ROW,COL,RMIN,RMAX,COL1,[ROW1|T]):-
  307.     treeline_hor(COL1,COL,ROW1),
  308.     cornerleft(ROW,RMIN,RMAX,ROW1,CORNCHAR),
  309.     scr_ch(ROW1,COL,CORNCHAR),
  310.     con_nodesleft(ROW,COL,RMIN,RMAX,COL1,T).
  311.  
  312.   cornerleft(RMIN,RMIN,_,RMIN,'┬') :- !.
  313.   cornerleft(RMAX,_,RMAX,RMAX,'┴') :- !.
  314.   cornerleft(_,RMIN,_,RMIN,'┐') :- !.
  315.   cornerleft(_,_,RMAX,RMAX,'┘') :- !.
  316.   cornerleft(RMIDT,_,_,RMIDT,'┼') :- !.
  317.   cornerleft(_,_,_,_,'┤').
  318.  
  319. /************************** END DRAW LEFT ********************************/
  320.  
  321. /****************************** DRAW DOWN ****************************/
  322.  
  323. PREDICATES
  324.   draw_down(TREE,ROW,COL,COL,COL)
  325.   draw_downlist(TREELIST,COLLIST,COLLIST,ROW,COL,COL)
  326.   connect_nodesdown(ROW,ROW,COL,ROW,COLLIST)
  327.   con_nodesdown(COL,ROW,COL,COL,ROW,COLLIST)
  328.   cornerdown(COL,COL,COL,COL,CHAR)
  329.   check_lastdown(COL,ROW,COLLIST)
  330.  
  331. CLAUSES
  332.   draw_down(_,_,_,_,_):-keypressed,!,readkey(KEY),treekeyact(KEY),fail.
  333.   draw_down(tree(NAME,SELECT,[]),CURROW,MAXCOL,NEWMAXCOL,MID):-!,
  334.     str_len(NAME,LEN),
  335.     NEWMAXCOL=MAXCOL+LEN+1,
  336.     MID=MAXCOL+(LEN-1) div 2,
  337.     writetext(CURROW,MAXCOL,112,NAME,SELECT).
  338.   draw_down(tree(NAME,SELECT,TREELIST),CURROW,MAXCOL,NEWMAXCOL,RESCOL):-
  339.     NEXTROW=CURROW+3,
  340.     draw_downlist(TREELIST,[],NODECOLLIST,NEXTROW,MAXCOL,NEWMAXCOL0),
  341.     nodelistlen(NODECOLLIST,LEN),
  342.     listsum(NODECOLLIST,SUM),
  343.     str_len(NAME,NAMELEN),
  344.     RESCOL=SUM div LEN,
  345.     JUST=RESCOL-NAMELEN div 2,
  346.     max(MAXCOL,JUST,NAMESTART),
  347.     writetext(CURROW,NAMESTART,112,NAME,SELECT),
  348.     ROW1=CURROW+1,LLEN=LEN,
  349.     connect_nodesdown(ROW1,NEXTROW,RESCOL,LLEN,NODECOLLIST),
  350.     check_lastdown(RESCOL,ROW1,NODECOLLIST),
  351.  
  352.     NEWMAXCOL1=NAMESTART+NAMELEN+1,
  353.     max(NEWMAXCOL0,NEWMAXCOL1,NEWMAXCOL).
  354.     
  355.  
  356.   draw_downlist([],NODECOLLIST,NODECOLLIST,_,MAXCOL,MAXCOL).
  357.   draw_downlist([H|T],NodeColList,ResNodeColList,CURROW,MAXCOL,MAXCOL2):-
  358.     draw_down(H,CURROW,MAXCOL,MAXCOL1,NODECOL),
  359.     draw_downlist(T,[NODECOL|NODECOLLIST],RESNODECOLLIST,CURROW,MAXCOL1,MAXCOL2).
  360.  
  361.   check_lastdown(COL,_,[COL|_]):-!.
  362.   check_lastdown(COL,ROW,[_|LIST]):-!,check_lastdown(COL,ROW,LIST).
  363.   check_lastdown(COL,ROW,_):-scr_ch(ROW,COL,'┴').
  364.  
  365.   connect_nodesdown(ROW,ROW1,COL,1,_) :-!,
  366.         treeline_ver(ROW,ROW1,COL).
  367.   connect_nodesdown(ROW,ROW1,COL,_,[CMAX|L]):-
  368.         lastinlist(CMIN,[CMAX|L]),
  369.         CC=CMIN+1,
  370.         treeline_hor(CC,CMAX,ROW),
  371.         con_nodesdown(COL,ROW,CMIN,CMAX,ROW1,[CMAX|L]).
  372.   
  373.   con_nodesdown(_,_,_,_,_,[]).
  374.   con_nodesdown(COL,ROW,CMIN,CMAX,ROW1,[COL1|T]):-
  375.     RR=ROW+1,
  376.     treeline_ver(RR,ROW1,COL1),
  377.     cornerdown(COL,CMIN,CMAX,COL1,CORNCHAR),
  378.     scr_ch(ROW,COL1,CORNCHAR),
  379.     con_nodesdown(COL,ROW,CMIN,CMAX,ROW1,T).
  380.  
  381.   cornerdown(MIN,MIN,_,MIN,'├') :- !.
  382.   cornerdown(MAX,_,MAX,MAX,'┤') :- !.
  383.   cornerdown(_,MIN,_,MIN,'┌') :- !.
  384.   cornerdown(_,_,MAX,MAX,'┐') :- !.
  385.   cornerdown(MIDT,_,_,MIDT,'┼') :- !.
  386.   cornerdown(_,_,_,_,'┬').
  387.  
  388. /************************** END DRAW DOWN ****************************/
  389.  
  390. /****************************** DRAW UP ****************************/
  391.  
  392. PREDICATES
  393.   draw_up(TREE,ROW,COL,COL,COL)
  394.   draw_uplist(TREELIST,COLLIST,COLLIST,ROW,COL,COL)
  395.   connect_nodesup(ROW,ROW,COL,ROW,COLLIST)
  396.   con_nodesup(COL,ROW,COL,COL,ROW,COLLIST)
  397.   cornerup(COL,COL,COL,COL,CHAR)
  398.   check_lastup(COL,ROW,COLLIST)
  399.  
  400. CLAUSES
  401.    
  402.   draw_up(_,_,_,_,_):-keypressed,!,readkey(KEY),treekeyact(KEY),fail.
  403.   draw_up(tree(NAME,SELECT,[]),CURROW,MAXCOL,NEWMAXCOL,MID):-!,
  404.     str_len(NAME,LEN),
  405.     NEWMAXCOL=MAXCOL+LEN+1,
  406.     MID=MAXCOL+(LEN+1) div 2,
  407.     writetext(CURROW,MAXCOL,112,NAME,SELECT).
  408.   draw_up(tree(NAME,SELECT,TREELIST),CURROW,MAXCOL,NEWMAXCOL,RESCOL):-
  409.     NEXTROW=CURROW-3,
  410.     draw_uplist(TREELIST,[],NODECOLLIST,NEXTROW,MAXCOL,NEWMAXCOL),
  411.     nodelistlen(NODECOLLIST,LEN),
  412.     listsum(NODECOLLIST,SUM),
  413.     RESCOL=SUM div LEN,
  414.     str_len(NAME,NAMELEN), JUST=RESCOL-NAMELEN div 2,
  415.     max(MAXCOL,JUST,NAMESTART),
  416.     writetext(CURROW,NAMESTART,112,NAME,SELECT),
  417.     ROW1=CURROW-1,LLEN=LEN,
  418.     ROW2=CURROW-2,
  419.     connect_nodesup(ROW1,ROW2,RESCOL,LLEN,NODECOLLIST),
  420.     check_lastup(RESCOL,ROW1,NODECOLLIST).
  421.  
  422.   draw_uplist([],NODECOLLIST,NODECOLLIST,_,MAXCOL,MAXCOL).
  423.   draw_uplist([H|T],NodeColList,ResNodeColList,CURROW,MAXCOL,MAXCOL2):-
  424.     draw_up(H,CURROW,MAXCOL,MAXCOL1,NODECOL),
  425.     draw_uplist(T,[NODECOL|NODECOLLIST],RESNODECOLLIST,CURROW,MAXCOL1,MAXCOL2).
  426.  
  427.   check_lastup(COL,_,[COL|_]):-!.
  428.   check_lastup(COL,ROW,[_|LIST]):-!,check_lastup(COL,ROW,LIST).
  429.   check_lastup(COL,ROW,_):-scr_ch(ROW,COL,'┬').
  430.  
  431.   connect_nodesup(ROW,ROW1,COL,1,_) :-!,
  432.         R2=ROW+1,
  433.         treeline_ver(ROW1,R2,COL).
  434.   connect_nodesup(ROW,ROW1,COL,_,[CMAX|L]):-
  435.         lastinlist(CMIN,[CMAX|L]),
  436.         CC=CMIN+1,
  437.         treeline_hor(CC,CMAX,ROW),
  438.         con_nodesup(COL,ROW,CMIN,CMAX,ROW1,[CMAX|L]).
  439.   
  440.   con_nodesup(_,_,_,_,_,[]).
  441.   con_nodesup(COL,ROW,CMIN,CMAX,ROW1,[COL1|T]):-
  442.     treeline_ver(ROW1,ROW,COL1),
  443.     cornerup(COL,CMIN,CMAX,COL1,CORNCHAR),
  444.     scr_ch(ROW,COL1,CORNCHAR),
  445.     con_nodesup(COL,ROW,CMIN,CMAX,ROW1,T).
  446.  
  447.   cornerup(MIN,MIN,_,MIN,'├') :- !.
  448.   cornerup(MAX,_,MAX,MAX,'┤') :- !.
  449.   cornerup(_,MIN,_,MIN,'└') :- !.
  450.   cornerup(_,_,MAX,MAX,'┘') :- !.
  451.   cornerup(MIDT,_,_,MIDT,'┼') :- !.
  452.   cornerup(_,_,_,_,'┴').
  453.  
  454. /************************** END DRAW UP ****************************/
  455.  
  456. /* treemenu construct and display a box diagram of a tree structure */
  457.  
  458.   treemenu(DIRECTION,TREE,CHOICE) :-
  459.       makewindow(81,66,23,"",0,0,24,80),  /* if this makewindow is commented out the tree will 
  460.                                              be drawn in the currently active window */
  461.      makestatus(112,"F1:Help  F10:Select  Retrn:Select  Arrows:move around  Ctrl arrows: move fast"),
  462.     newupdate(treewindow(0,0)),
  463.     repeat,
  464.     remove_treechoice,
  465.     draw(DIRECTION,TREE),
  466.     readkey(KEY),
  467.     treekeyact(KEY),!,
  468.     removestatus,
  469.     removewindow,
  470.     not(KEY=esc),
  471.     treechoice(CHOICE),!.
  472.     
  473. /* draw a tree in the selected direction */
  474.   draw(right,TREE):-draw_right(TREE,0,_,0,_,0,5,_).
  475.   draw(left,TREE) :-draw_left(TREE,0,_,0,_,75,5,_).
  476.   draw(down,TREE):-draw_down(TREE,0,0,_,_).
  477.   draw(up,TREE):-draw_up(TREE,20,0,_,_).
  478.  
  479.