home *** CD-ROM | disk | FTP | other *** search
- /* 88-05-07 Jahns kbnec() -> GETCHR() */
- /* 01-Aug-1988 Jahns plitmhilit() with ATROFS */
- /* 01-Aug-1988 Jahns pledt() select with char */
- /* 02-Aug-1988 Jahns pledt() f_end included */
- /* 16-Sep-1988 Jahns MOUSES() included */
- /* 20-Sep-1988 Jahns SET_MOUSE_WND() included */
- /* 88-10-04 Vogt N. ATROFS replaced by TASK->PTERM->ATROFS */
- /* 88-10-20 Jahns if F1 return 0x21 */
- /* 89-06-13 Jahns return all functionkey's */
- /* 89-11-23 Vogt N. GETCHR() --> GET_CHR() */
-
-
-
- /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
- /***
- * name : plist - create an instance of a pick-list object.
- *
- * synopsis: plist(h_wnd,get_fnc,ttl)
- * h_wnd - the window in which the pick-list appears
- * ttl - a string which will appear on the first line
- * of the list. this line will not be scrolled.
- * if no comment is desired, then pass a NULLPTR.
- * get_fnc - address of function which will be called to get
- * formatted elements which will appear in the
- * list.
- *
- * description: create a new object and set its attributes.
- *
- * returns: handle of newly created object.
- *
- * name : plrls - release an instance of a pick-list object.
- *
- * synopsis: plrls(h_pl)
- * h_pl handle to a pick list object.
- *
- * name : pllstkey - return key which terminated input.
- * pldsp - display a set of elements in a pick-list
- * pledt - let the user choose an element in the list.
- *
- * synopsis: pldsp(h_pl)
- * h_pl handle to pick-list to be displayed.
- *
- * pledt(h_pl, &chc, str)
- * h_pl handle to pick-list
- * chc the number of the element in the list
- * which the user chose.
- * str string buffer in which the text of the
- * chosen element will be placed.
- * if you do not wish text returned, make
- * this argument a NULLPTR.
- *
- * key = pllstkey()
- * <type,code> - the type code of the key which caused input
- * to terminate
- *
- * description: pick-lists are for allowing the user to chose from a list
- * of items which is longer than the number of lines in
- * a given screen area. the cursor keys allow the user
- * to scroll the elements of the list in and out of the
- * screen area.
- *
- * returns: pldsp() return RC_FAIL if no elements were displayed.
- * othewise SUCCEED is returned.
- * pllstkey() returns a word containing the <type,code> pair
- * of the key which caused input to terminate.
- * pledt() return
- * RC_FAIL - no elements in list.
- * RC_ESC - user pressed <ESC>
- * RC_SPECIAL - user pressed special key, e.g. function key.
- * RC_ENTER - the user pressed the <enter> key.
- *
- * (C) novum organum, inc. 1985
- *
- ***/
- #include "compiler.h"
-
- #define f_new
-
- #include "tskenv0.h"
- #include "cptpdf.h"
-
- extern struct tsk_env *TSKENV;
-
- extern char8 trtinp[256];
-
- #include "psys.h"
-
-
-
- static plitmhilit (short row, short f_hilit)
- {
- if (f_hilit) vstsetinvrs();
- _vdspa(row, 0, vidncols(), VD_CURSTAT);
- if (f_hilit) vstsetnorml();
- }
-
-
-
-
- GLOBAL HDL plist (HDL h_wnd, PFI get_fnc, char8 *ttl)
- {
- HDL h_pl;
- char8 *memgive();
-
- h_pl = (HDL) memgive(sizeof(PICKLIST));
-
- H_PL->tag = ADT_PL;
- H_PL->h_wnd = h_wnd;
- H_PL->ttl = ttl;
- H_PL->get_fnc = get_fnc;
- H_PL->fst_on_scr = 0;
- H_PL->csr_off = 0;
- return (h_pl);
-
- } /* plist */
-
-
-
- GLOBAL void SetPlmax (HDL h_pl, short max_cnt)
- {
-
- adtverify (h_pl, ADT_PL); /* verify that really a pick-list*/
- H_PL->max_cnt = max_cnt;
-
- } /* SetPlmax */
-
-
-
- GLOBAL HDL plrls(FAST HDL h_pl)
- {
- HDL h_wnd;
-
- adtverify (h_pl, ADT_PL); /* verify that this is a pick-list object.*/
- H_PL->tag = DEAD_TAG; /* zap tag. */
- h_wnd = H_PL->h_wnd;
- memtake(h_pl); /* zap pick-list. */
-
- return (h_wnd);
- }
-
-
- GLOBAL void plsetchc(FAST HDL h_pl, int fst_on_scr, int chc)
-
- {
- adtverify (h_pl, ADT_PL);
- if (chc < 0) chc = 0;
- if (fst_on_scr > chc) fst_on_scr = chc;
- else
- if (fst_on_scr < 0) fst_on_scr = 0;
- H_PL->fst_on_scr = fst_on_scr;
- H_PL->csr_off = chc - fst_on_scr;
-
- } /* plsetchc */
-
-
-
- static short fillplist( HDL h_pl,
- short row,
- short lst_row,
- char8 *buf,
- short nxt_itm )
- {
- register short n_dspd, ncols;
-
- n_dspd = 0;
- ncols = vidncols() + 1;
-
- while (row < lst_row)
- {
- /* if another string is returned, then add to window. */
- /* but if at end-of-list (RC_FAIL), then stop on this line. */
- if ((*H_PL->get_fnc)(nxt_itm, buf, ncols) == RC_FAIL)
- break;
- vdsplns(row++, 0, ncols, buf);
- nxt_itm++; /* actual number displayed in list */
- n_dspd++;
- }
- while(row < lst_row)
- vdsplns(row++, 0, ncols, "");
- return (n_dspd);
-
- } /* fillplist */
-
-
-
- static short _pldsp (HDL h_pl, short nrows, char8 *buf, short *pfst_row)
- {
- register short max_itms, n_on_scr;
-
- wndtotop(H_PL->h_wnd);
- max_itms = nrows;
-
- if (H_PL->ttl)
- {
- vdspls(0, 0, H_PL->ttl);
- max_itms--;
- *pfst_row = 1;
- }
- else
- *pfst_row = 0;
- /* fill the box with as many choices a possible, starting with FST_ON_SCR*/
-
- if (H_PL->csr_off >= max_itms)
- {
- H_PL->fst_on_scr -= (H_PL->csr_off - max_itms + 1);
- if (H_PL->fst_on_scr < 0)
- H_PL->fst_on_scr = 0;
- }
-
- FOREVER
- {
- n_on_scr = fillplist(h_pl, *pfst_row, nrows, buf, H_PL->fst_on_scr);
-
- if (H_PL->csr_off >= n_on_scr) /* make certain cursor is over */
- H_PL->csr_off = n_on_scr - 1; /* a choice in the window. */
- if (n_on_scr > 0)
- break;
- /* nothing was successfully put in the pick-list. however maybe*/
- /* we are past the end of the list. if we are not at the first*/
- /* (zero'th) element of the list, let's try from the beginning */
- /* if we are already there, then just quit. */
- H_PL->csr_off = 0;
- if (H_PL->fst_on_scr > 0)
- H_PL->fst_on_scr = 0;
- else
- break; /* already at begin. nothing in list. */
- }
-
- return (n_on_scr);
-
- } /* _pldsp */
-
-
-
- #ifdef use
-
- GLOBAL short pldsp(HDL h_pl)
- {
- register short rc, prv_attr;
- short fst_row;
- HDL prv_pl, prv_wnd, wndsetactv();
- char8 s[81];
-
- adtverify (h_pl, ADT_PL); /* verify that really a pick-list*/
- rc = RC_SUCCESS;
- prv_wnd = wndsetactv(H_PL->h_wnd);
- prv_attr = vstsetattr(VA_NORMAL);
- if (_pldsp (h_pl, vidnrows(), s, &fst_row) > 0)
- plitmhilit(fst_row + H_PL->csr_off, NO);
- else
- rc = RC_FAIL;
- vstsetattr(prv_attr);
- wndsetactv(prv_wnd);
-
- return(rc);
-
- } /* pldsp */
-
- #endif
-
-
- static char8 TEST_CH(char8 *s)
- {
- register short I;
-
- for (I = 0; I < vidncols() + 1; ++I)
- {
- if (s[I] != SP) break;
- }
- return(s[I]);
-
- } /*TEST_CH */
-
-
-
- static BOOLEAN MORE(HDL h_pl, char CH, char *s)
- {
- register short i, cnt, ncols;
-
- ncols = vidncols() + 1;
- cnt = 0;
- i = -1;
- for(;;)
- {
- if((*H_PL->get_fnc)(++i, s, ncols) == RC_FAIL) break;
- if (CH == TEST_CH(s)) ++cnt;
- if (cnt > 1) break;
- }
- return ((cnt > 1) ? TRUE : FALSE);
-
- } /* MORE */
-
-
-
- GLOBAL short pledt (HDL h_pl, short *pchc)
- {
- register short i, k, row, rc;
- short csr_off, csr_typ, chc, nrows, fst_row, max_itms;
- short ncols, fst_on_scr, n_on_scr, prv_attr, f_fill;
- HDL prv_pl, prv_wnd, wndsetactv();
- short pos, pos_sav;
- BOOLEAN cont, more, TERM;
- short CH, CHR;
- short MROW, MCOL;
- struct _WND *act_wnd;
- short min_col, min_row;
- short max_col, max_row;
- short min_c, max_c, min_r, max_r;
- short func_key;
- struct pc_kbd *PKBRD;
- char8 s[81];
- short savdev;
- short SAV_APA;
- PFI get_fnc;
-
- savdev = SET_DSP(TSKENV, TXTDSP);
-
- PKBRD = TSKENV->PKBRD;
- SAV_APA = PKBRD->f_APA;
- PKBRD->f_APA = FALSE;
-
- adtverify (h_pl, ADT_PL); /* verify that really a pick-list*/
-
- get_fnc = H_PL->get_fnc;
- prv_wnd = wndsetactv(H_PL->h_wnd);
- act_wnd = (struct _WND *) H_PL->h_wnd;
- ncols = vidncols() + 1;
- prv_attr = vstsetattr(VA_NORMAL);
- nrows = vidnrows();
- csr_typ = vidcsrtyp(CSR_HIDDEN);
-
- rc = RC_FAIL;
-
- if ((n_on_scr = _pldsp (h_pl, nrows, s, &fst_row)) > 0)
- {
- rc = RC_LOOP;
- max_itms = nrows - fst_row;
- csr_off = H_PL->csr_off;
- fst_on_scr = H_PL->fst_on_scr;
- f_fill = NO;
- }
-
- if (PKBRD->XMOUSE)
- {
- MOUSE_CLR(TSKENV);
- min_c = min_col = act_wnd->pcol;
- max_c = max_col = act_wnd->pcol + act_wnd->pncols + 1;
- min_r = min_row = act_wnd->prow;
- max_r = max_row = act_wnd->prow + act_wnd->pnrows + 1;
- SET_MOUSE_WND(TSKENV, &min_c, &max_c, &min_r, &max_r);
- }
-
- while(rc == RC_LOOP) /* fails without executing loop if list is empty.*/
- {
- plitmhilit(fst_row + csr_off, YES); /*display current choice.*/
-
-
- for (;;)
- {
- chc = fst_on_scr + csr_off;
-
- if (CHKKBD(TSKENV))
- {
- if (PKBRD->XMOUSE && PKBRD->MOUSE_ON) MOUSEOFF(TSKENV);
- CH = GET_KBD(TSKENV);
- if (CH) break;
- }
-
- if (PKBRD->XMOUSE)
- {
- MOUSE_POS(TSKENV, min_row + fst_row + csr_off, min_col + 1);
-
- TERM = TRUE;
-
- switch(MOUSE_INP(TSKENV, &MROW, &MCOL))
- {
- case 0 : TERM = FALSE;
- break;
-
- case 2 :
- CH = 0x0121;
- WRITE_BTC(TSKENV, CH);
- break;
-
- case 3 :
- CH = ESC;
- WRITE_BTC(TSKENV, CH);
- break;
-
- case 1 :
- if (MROW == min_row || MROW == max_row)
- {
- CH = (MROW == min_row) ? f_prev : f_next;
- WRITE_BTC(TSKENV, CH);
- break;
- }
- if (MCOL == max_col)
- { CH = f_end; WRITE_BTC(TSKENV, CH); break; }
- if (MCOL == min_col)
- { CH = APH; WRITE_BTC(TSKENV, CH); break; }
-
- row = MROW - min_row - 1;
-
- if (row < n_on_scr)
- {
- MOUSEOFF(TSKENV); /* mouse cursor off */
- plitmhilit(fst_row + csr_off, NO);
- csr_off = row;
- plitmhilit(fst_row + csr_off, YES);
- MOUSE_POS(TSKENV, min_row + fst_row + csr_off, min_col + 1);
- pos = fst_on_scr + csr_off;
- if (chc == pos)
- {
- CH = CR;
- WRITE_BTC(TSKENV, CH);
- break;
- }
- else
- {
- if (PKBRD->BATCHPR)
- {
- (*get_fnc)(pos, s, ncols);
- CHR = TEST_CH(s);
- WRITE_BTC(TSKENV, APH);
- k = 0;
- i = max_itms - 1;
- for(;;)
- {
- if ((pos - k) >= i)
- {
- WRITE_BTC(TSKENV, f_next);
- k += i;
- }
- else break;
- }
- if (k) ++k;
- for(i = k; i <= pos; ++i)
- {
- (*get_fnc)(i, s, ncols);
- if (TEST_CH(s) == CHR) WRITE_BTC(TSKENV, CHR);
- }
- }
- }
- } /* if (row < n_on_scr) */
- TERM = FALSE;
- break;
- }
- if (TERM) break;
- }
-
- guc();
-
- } /* for (;;) */
-
- if (PKBRD->XMOUSE && PKBRD->MOUSE_ON) MOUSEOFF(TSKENV);
-
- func_key = (CH >= f_fun) ? TRUE : FALSE;
-
- plitmhilit(fst_row + csr_off, NO);
-
- switch (CH)
- {
- case ESC :
- rc = RC_ESC;
- break;
- case CR :
- rc = RC_ENTER;
- break;
- case SP :
- case APD :
- if (csr_off < n_on_scr - 1) /* in middle of window? */
- csr_off++; /* yes, just go to next window line. */
- else /* at bottom of screen, any more elements? */
- if ((*get_fnc)(fst_on_scr + n_on_scr, s, ncols)!=RC_FAIL)
- {
- /* yes, more elements, so scroll up */
- /* add new element to bottom of window. */
- vidareascroll(fst_row, 0, max_itms, ncols, 1);
- /* put new choice on last line */
- vdsplns(fst_row + csr_off, 0, ncols, s);
- fst_on_scr++;
- }
- else
- sybeep();
- break;
- case APU :
- if (csr_off > 0) /* in middle of screen? */
- csr_off--; /* yes, just move up one line. */
- else
- if ((fst_on_scr > 0) /* are we in middle of list? */
- && /* got previous element ok? */
- ((*get_fnc)(fst_on_scr - 1, s, ncols) != RC_FAIL))
- {
- vidareascroll(fst_row, 0, max_itms, ncols, -1);
- fst_on_scr--;
- n_on_scr++;
- if (n_on_scr > max_itms)
- n_on_scr = max_itms;
- /* put new elm on first line. */
- vdsplns(fst_row, 0, ncols, s);
- }
- else
- sybeep();
- break;
- case APH :
- fst_on_scr = 0; /*move to begin of list. */
- csr_off = 0; /* then fill window. */
- f_fill = YES;
- break;
- case f_prev : /* Pg-Up */
- if (fst_on_scr > 0) /* if not at first element of list*/
- { /* then move up NLNS-1 and refill */
- i = MIN(max_itms - 1, fst_on_scr);
- fst_on_scr -= i; /* compute first now on screen, number*/
- f_fill = YES;
- }
- else /* move to first element in window. */
- if (csr_off > 0) csr_off = 0;
- else sybeep();
- break;
- case f_next : /* Pg-Dn */
- fst_on_scr += (n_on_scr - 1); /*last elm now on first line*/
- f_fill = YES;
- break;
- case f_end :
- if (H_PL->max_cnt)
- {
- pos = H_PL->max_cnt;
- (*get_fnc)(pos - 1, s, ncols);
- }
- else {
- pos = fst_on_scr + csr_off;
- while((*get_fnc)(++pos, s, ncols) != RC_FAIL);
- }
- fst_on_scr = pos - max_itms;
- if (fst_on_scr < 0) fst_on_scr = 0;
- f_fill = YES;
- break;
-
- default :
- if (func_key)
- {
- rc = CH;
- break;
- }
-
- CH = toupper(CH);
- pos = fst_on_scr + csr_off;
- pos_sav = pos;
- cont = TRUE;
- more = MORE(h_pl, CH, s);
-
- for (;;)
- {
- if((*get_fnc)(++pos, s, ncols) != RC_FAIL)
- {
- if (CH == toupper(TEST_CH(s)))
- {
- if (! PKBRD->BATCH && ! PKBRD->BATCHPR &&
- ! more && pos == pos_sav)
- rc = RC_ENTER;
- i = pos - fst_on_scr;
- if (i > 0 && i < n_on_scr)
- {
- csr_off = i;
- break;
- }
- fst_on_scr = pos;
- csr_off = 0;
- f_fill = YES;
- break;
- }
- }
- else
- {
- if (cont)
- {
- pos = -1;
- cont = FALSE;
- }
- else {
- sybeep();
- break;
- }
- }
- }
- break;
- } /* switch */
-
- if (f_fill)
- {
- n_on_scr = fillplist(h_pl, fst_row, nrows, s, fst_on_scr);
- if (csr_off >= n_on_scr)
- csr_off = n_on_scr-1;
- f_fill = NO;
- }
- } /* while(rc==RC_LOOP) */
-
- vidcsrtyp(csr_typ);
- chc = fst_on_scr + csr_off;
- H_PL->fst_on_scr = fst_on_scr; /* save the num. of first in window */
- H_PL->csr_off = csr_off; /* save offset of cursor in window. */
- *pchc = chc; /* return choice number. */
- vstsetattr(prv_attr);
- wndsetactv(prv_wnd);
-
- if (PKBRD->XMOUSE) SET_MOUSE_WND(TSKENV, &min_c, &max_c, &min_r, &max_r);
-
- PKBRD->f_APA = SAV_APA;
- SET_DSP(TSKENV, savdev);
-
- return (rc);
- }
-