home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- #include "strutil.h"
- #include "scrutil.h"
- #include "wutil.h"
- #include "menutil.h"
-
-
-
- /****************************************************************************/
- /* menshow */
- /****************************************************************************/
- /*-----------------------------Description----------------------------------*/
- /* This function redisplays the described window. */
- /*-----------------------------Arguments------------------------------------*/
- /* MENU_DESC* md pointer to menu descriptor for menu. */
- /*-----------------------------Return value---------------------------------*/
- /* Returns the current selection or one of the return codes described in */
- /* menutil.h. */
- /*-----------------------------Global constants-----------------------------*/
- /*-------------------Mod-------Global variables-----------------------------*/
- /*-----------------------------Functions called-----------------------------*/
- /*-----------------------------Examples-------------------------------------*/
- /*-----------------------------Constraints/Gotchas--------------------------*/
- /*--Date--------Programmer----------Comments--------------------------------*/
- /* 1990.01.01 A. Turing initial code */
- /****************************************************************************/
- int menshow(MENU_DESC* md)
- {
- char twupd; /*temporary windowing update flag*/
- int i; /*index*/
- MENU_LIST* ml; /*local copy of menu list pointer*/
- WIND* w; /*pointer to window*/
-
- if (!md) return MEN_ERROR; /*make sure legal descriptor*/
- if (md->typ>=MEN_LAST) return MEN_ERROR; /*ditto*/
- w=md->w; /*pointer to window*/
- if (!w) return MEN_ERROR; /*bad window, oops!*/
- ml=md->menu_list; /*pointer to menu list*/
- twupd=wupd; /*copy window updating flag*/
- wupd=0; /*disable updating*/
-
- switch (md->typ) { /*differently for each type*/
- case MEN_VERTICAL: /*vertical selection list*/
- wclr(w); /*clear window*/
- if (md->cur>=md->siz) md->cur=0; /*check current*/
- wsetattr(w,md->wnd_attr); /*set window attributes*/
- for (i=0;i<md->siz;i++) { /*go through each to write out*/
- wsetcpos(w,i,0); /*go to start of row in window*/
- wputshot(w,ml[i].str,md->hot_attr,HOTKEY); /*write it out*/
- } /*to write out whole list*/
- wsetcpos(w,md->cur,0); /*current line*/
- wsetattr(w,md->sel_attr); /*invert selection colors*/
- wclreor(w); /*clear line*/
- wputshot(w,ml[md->cur].str,md->sel_attr,HOTKEY); /*write string*/
- wsetattr(w,md->wnd_attr); /*restore attributes*/
- break;
- case MEN_HORIZONTAL: /*horizontal selection list*/
- default: /*unknown type*/
- wupd=twupd; /*restore window updating flag*/
- return MEN_ERROR; /*bad descriptor*/
- } /*switch*/
- wupd=twupd; /*restore window updating flag*/
- if (wupd) wupdate(w); /*update window*/
- return md->cur; /*all ok*/
- } /*menshow*/
-
-
- /****************************************************************************/
- /* menvert */
- /****************************************************************************/
- /*-----------------------------Description----------------------------------*/
- /* This function displays a vertical menu using the information in the */
- /* menu descriptor argument. The menu descriptor tells menvert() where */
- /* to place the window, the attributes, the selection strings and the */
- /* function to call when a selection is made. */
- /*-----------------------------Arguments------------------------------------*/
- /* MENU_DESC* md see menutil.h for field definitions of MENU_DESC */
- /*-----------------------------Return value---------------------------------*/
- /* Returns the last selection made or one of the return codes described */
- /* in menutil.h. */
- /*-----------------------------Global constants-----------------------------*/
- /*-------------------Mod-------Global variables-----------------------------*/
- /*-----------------------------Functions called-----------------------------*/
- /*-----------------------------Examples-------------------------------------*/
- /*-----------------------------Constraints/Gotchas--------------------------*/
- /*--Date--------Programmer----------Comments--------------------------------*/
- /* 1990.01.01 A. Turing initial code */
- /****************************************************************************/
- int menvert(MENU_DESC* md)
- {
- int i; /*scrap*/
- int c; /*input char*/
- char* s; /*scrap*/
- char done=0; /*finished with menu*/
- char exec=0; /*execute selection flag*/
- MENU_LIST* ml; /*menu list struct pointer*/
- WIND* w; /*pointer to window*/
-
- ml=md->menu_list; /*point to menu list*/
- for (i=0;ml[i].str;i++) { /*get number of menu elements*/
- md->wid=MAX(md->wid,hotlen(ml[i].str,HOTKEY)); /*check width*/
- ml[i].hot=0; /*..reset hotkey*/
- s=strchr(ml[i].str,HOTKEY); /*..find hotkey flag*/
- while (s) { /*..check 'til no more &&'s*/
- s++; /*....point to next char*/
- if (*s!=HOTKEY) { /*....found a non-doubled hotkey*/
- ml[i].hot=toupper(*s); /*......set it*/
- break; /*......cut out on loop*/
- } /*if*/
- s++; /*....pass second &*/
- s=strchr(s,HOTKEY); /*....look for next &X*/
- } /*while seeking hotkey*/
- } /*for each menu item*/
- if (!i) return MEN_ERROR; /*no menu selections*/
- md->siz=i; /*set up size*/
- c=0;
- if (md->row==0xFFFF) md->row=getcrow();
- if (md->col==0xFFFF) md->col=getccol();
- if (!md->wnd_attr) md->wnd_attr=WND_ATTR;
- if (!md->brd_attr) md->brd_attr=BRD_ATTR;
- if (!md->sel_attr) md->sel_attr=SEL_ATTR;
- if (!md->hot_attr) md->hot_attr=HOT_ATTR;
- md->typ=MEN_VERTICAL; /*vertical selection list menu*/
- wupd=0; /*disallow window updating*/
- md->w=wopen( /*open the menu's window..*/
- md->border,md->title, /*..border type, title string*/
- md->row,md->col, /*..screen row, column*/
- md->siz,md->wid, /*..height in rows, width in columns*/
- md->wnd_attr /*..normal attribute*/
- ); /*wopen*/
- w=md->w; /*readability*/
- wupd=1; /*allow window updating*/
- if (!w) return MEN_ALLOC; /*oops! no window*/
- w->fl.wrap=0; /*no wrap*/
- w->fl.scroll=0; /*no scroll*/
- w->battr=md->brd_attr; /*border attribute*/
- w->csiz=NO_CURSOR; /*no cursor in the window*/
- wupd=0; /*reset updating*/
- for (i=0;i<md->siz;i++) { /*go through each to write out*/
- wsetcpos(w,i,0); /*go to start of row in window*/
- wputshot(w,ml[i].str,md->hot_attr,HOTKEY); /*write it out*/
- } /*to write out whole list*/
- wupdate(w); /*update screen*/
-
- while (!done) { /*go 'til done*/
- if (md->cur>=md->siz) md->cur=0; /*start at top if bad*/
- menshow(md); /*redraw window*/
- exec=0; /*reset execute selection flag*/
- do { /*only redo when need to*/
- c=wgetc(w); /*get input character*/
- if ((c>='a')&&(c<='z')) c-=0x20; /*upperize it*/
- switch (c) { /*look at value*/
- case _UPAR:
- if (md->cur==0) /*if at top*/
- md->cur=md->siz-1; /*wrap*/
- else
- md->cur--;
- break;
- case _DNAR:
- md->cur++; /*go down*/
- if (md->cur>=md->siz) md->cur=0; /*wrap*/
- break;
- case _PGUP:
- case _HOME:
- md->cur=0; /*top of list*/
- break;
- case _PGDN:
- case _END:
- md->cur=md->siz-1; /*end of list*/
- break;
- case CR:
- exec=1; /*execute selection*/
- break;
- case ESC:
- done=1; /*all done*/
- break;
- default:
- for (i=0;i<md->siz;i++) if (c==ml[i].hot) break; /*look for hotkey*/
- if (i>=md->siz) { c=0; break; } /*not found*/
- md->cur=i; /*current window*/
- menshow(md); /*redraw menu window*/
- exec=1; /*execute selection*/
- } /*switch*/
- } while (c==0); /*if nothing pressed, try again*/
-
- if (exec) { /*if we need to execute*/
- if (ml[md->cur].fun) ml[md->cur].fun(md); /*call selected function*/
- if (ml[md->cur].flags&MEN_CLOSE) done=1; /*if autoclose*/
- if (ml[md->cur].flags&MEN_NEXT) md->cur++; /*if autonext*/
- } /*if executing*/
- } /*while not done*/
- wclose(w); /*shut down window*/
- if (c==ESC) /*if ESC pressed to exit..*/
- return MEN_ESC; /*..return code*/
- else /*otherwise..*/
- return md->cur; /*..return selection*/
- } /*menvert*/
-
-
-
-