home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* XBBS SOURCE CODE copyright (c) 1990 by M. Kimes */
- /* All Rights Reserved */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the in the file LICENSE.XBS. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* XBBS LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES */
- /* AT THE ADDRESS LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO USE */
- /* THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING */
- /* AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH */
- /* M. KIMES */
- /* */
- /* */
- /* You can contact M. Kimes at the following address: */
- /* */
- /* M. Kimes 1:380/16.0@FidoNet */
- /* 542 Merrick (318)222-3455 data */
- /* Shreveport, LA 71104 */
- /* */
- /* */
- /* Please feel free to contact me at any time to share your comments about */
- /* my software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- /* akmenu.c file */
-
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include "xkeys.h"
- #include "awindow.h"
-
- #ifdef USEMOUSE
- extern int hysterisis,hcount,vcount;
- #endif
-
- extern int VSG;
- extern unsigned int baud;
-
- extern void pascal dcls(void);
- extern void pascal dputc(int x, int y, int c);
- extern int pascal dputs(int x, int y, char *s);
- extern void pascal dclrwnd(int x1, int y1, int x2, int y2);
- extern void pascal dscrollup(int x1, int y1, int x2, int y2);
- extern void pascal dscrolldn(int x1, int y1, int x2, int y2);
-
- extern void (*helpfunc)();
-
- extern unsigned int vbase;
- extern unsigned int maxx;
- extern unsigned int maxy;
- extern char current_color;
- extern unsigned int videomethod;
-
- extern char cdecl gprintf(char,char *,...);
-
-
- WINDOW * pascal open_menu(char *mnm,KMENU *mn,int hsel);
- int pascal gethmenu(KMENU *mn,WINDOW *hmenu,int hsel);
- int pascal getvmn(KMENU *mn,WINDOW *hmenu,int *hsel,int vsel);
- int pascal haccent(KMENU *mn,WINDOW *hmenu,int hsel,int vsel);
- void pascal dimension(char *sl[],int *ht,int *wd);
- void pascal light(KMENU *mn,WINDOW *hmenu,int hsel,int d);
-
- /* Display & process a menu */
- int pascal kmenu_select(char *name,KMENU *mn) {
-
- WINDOW *hmenu;
- int sx,sy;
- int hsel=1,vsel;
- #ifdef USEMOUSE
- int temph,tempv;
- #endif
-
- #ifdef USEMOUSE
- temph=hcount;
- tempv=vcount;
- hcount=hysterisis;
- vcount=hysterisis;
- #endif
- curr_cursor(&sx,&sy);
- /* cursor(0,26); */
- hmenu=open_menu(name,mn,hsel);
- while(hsel=gethmenu(mn,hmenu,hsel)) {
- vsel=1;
- while(vsel=getvmn(mn,hmenu,&hsel,vsel)) {
- if(vsel>25) {
- vsel=1;
- continue;
- }
- delete_window(hmenu);
- /* set_help("",0,0); */
- if(!baud) cursor(sx,sy);
- else gprintf(0,"\x1b[%d;%dH",sy+1,sx+1);
- #ifdef USEMOUSE
- hcount=temph;
- vcount=tempv;
- #endif
- return (mn+hsel-1)->returnkey[vsel-1];
- }
- }
- delete_window(hmenu);
- if(!baud) cursor(sx,sy);
- else gprintf(0,"\x1b[%d;%dH",sy+1,sx+1);
- /* set_help("",0,0); */
- #ifdef USEMOUSE
- hcount=temph;
- vcount=tempv;
- #endif
- return 0;
- }
-
-
- /* Open a horizontal menu */
- static WINDOW * pascal open_menu(char *mnm,KMENU *mn,int hsel) {
-
- int i=0;
- WINDOW *hmenu;
-
- /* set_help("kmenu ",30,10); */
- hmenu=establish_window(0,0,3,80);
- set_border(hmenu,2);
- set_title(hmenu,mnm);
- set_colors(hmenu,ALL,BLUE,AQUA,BRIGHT);
- set_colors(hmenu,ACCENT,WHITE,BLACK,DIM);
- display_window(hmenu);
- while((mn+i)->mname)
- wprintf(hmenu," %-9.9s ",(mn+i++)->mname);
- light(mn,hmenu,hsel,1);
- /* cursor(0,26); */
- return hmenu;
- }
-
- /* Get a horizontal selection */
- static int pascal gethmenu(KMENU *mn,WINDOW *hmenu,int hsel) {
-
- int sel;
-
- light(mn,hmenu,hsel,1);
- while(TRUE) {
- switch(sel=get_char()) {
- case FWD:
- case BS: hsel=haccent(mn,hmenu,hsel,sel);
- break;
- case ESC: return 0;
- case 0:
- case '\r': return hsel;
- case DN: return hsel;
- default: putchar (BELL);
- break;
- }
- }
- }
-
- /* Pop down a vertical menu */
- static int pascal getvmn(KMENU *mn,WINDOW *hmenu,int *hsel,int vsel) {
-
- WINDOW *vmenu;
- int ht=10,wd=20;
- int temp;
- char **mp;
-
- while (1) {
- dimension((mn+*hsel-1)->mselcs,&ht,&wd);
- if(wd+(2+(*hsel-1)*11)>78)temp=79-wd;
- else temp=2+(*hsel-1)*11;
- vmenu=establish_window(temp,2,ht,wd);
- set_colors(vmenu,ALL,BLUE,AQUA,BRIGHT);
- set_colors(vmenu,ACCENT,WHITE,BLACK,DIM);
- set_border(vmenu,4);
- display_window(vmenu);
- mp=(mn+*hsel-1)->mselcs;
- while(*mp) wprintf(vmenu,"\n%s",*mp++);
- vsel=get_selection(vmenu,vsel,"");
- delete_window(vmenu);
- if (vsel==FWD || vsel==BS) {
- *hsel=haccent(mn,hmenu,*hsel,vsel);
- vsel=1;
- }
- else
- return vsel;
- }
- }
-
- /* Manage the horizontal menu selection accent */
- static int pascal haccent(KMENU *mn,WINDOW *hmenu,int hsel,int sel) {
-
- switch (sel) {
- case FWD:
- light(mn,hmenu,hsel,0);
- if((mn+hsel)->mname)
- hsel++;
- else
- hsel=1;
- light(mn,hmenu,hsel,1);
- break;
- case BS:
- light(mn,hmenu,hsel,0);
- if(hsel==1)
- while((mn+hsel)->mname)
- hsel++;
- else
- --hsel;
- light(mn,hmenu,hsel,1);
- break;
- default:
- break;
- }
- return hsel;
- }
-
- /* Compute a menu's height & width */
- static void pascal dimension(char *sl[],int *ht,int *wd) {
-
- unsigned strlen(char *);
-
- *ht=*wd=0;
- while(sl[*ht]) {
- *wd=max(*wd,strlen(sl[*ht]));
- (*ht)++;
- }
- *ht+=2;
- *wd+=2;
- }
-
- /* Accent a horizontal menu selection */
- static void pascal light (KMENU *mn,WINDOW *hmenu,int hsel,int d) {
-
- if(d) reverse_video(hmenu);
- wcursor(hmenu,(hsel-1)*11+2,0);
- wprintf(hmenu,(mn+hsel-1)->mname);
- normal_video(hmenu);
- /* cursor(0,26); */
- }
-
-