home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / AKMENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-18  |  7.1 KB  |  243 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   XBBS SOURCE CODE copyright (c) 1990 by M. Kimes                        */
  4. /*   All Rights Reserved                                                    */
  5. /*                                                                          */
  6. /*    For complete details of the licensing restrictions, please refer      */
  7. /*    to the License agreement, which is published in its entirety in       */
  8. /*    the in the file LICENSE.XBS.                                          */
  9. /*                                                                          */
  10. /*    USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE      */
  11. /*    XBBS LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF            */
  12. /*    THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO       */
  13. /*    NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES         */
  14. /*    AT THE ADDRESS LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO USE   */
  15. /*    THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING     */
  16. /*    AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH      */
  17. /*    M. KIMES                                                              */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /* You can contact M. Kimes at the following address:                       */
  21. /*                                                                          */
  22. /* M. Kimes                         1:380/16.0@FidoNet                      */
  23. /* 542 Merrick                      (318)222-3455 data                      */
  24. /* Shreveport, LA  71104                                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /* Please feel free to contact me at any time to share your comments about  */
  28. /* my software and/or licensing policies.                                   */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31.  
  32. /* akmenu.c file */
  33.  
  34. #include <stdio.h>
  35. #include <conio.h>
  36. #include <stdlib.h>
  37. #include "xkeys.h"
  38. #include "awindow.h"
  39.  
  40. #ifdef USEMOUSE
  41.     extern int hysterisis,hcount,vcount;
  42. #endif
  43.  
  44. extern int VSG;
  45. extern unsigned int baud;
  46.  
  47. extern void pascal dcls(void);
  48. extern void pascal dputc(int x, int y, int c);
  49. extern int  pascal dputs(int x, int y, char *s);
  50. extern void pascal dclrwnd(int x1, int y1, int x2, int y2);
  51. extern void pascal dscrollup(int x1, int y1, int x2, int y2);
  52. extern void pascal dscrolldn(int x1, int y1, int x2, int y2);
  53.  
  54. extern void (*helpfunc)();
  55.  
  56. extern unsigned int vbase;
  57. extern unsigned int maxx;
  58. extern unsigned int maxy;
  59. extern char current_color;
  60. extern unsigned int videomethod;
  61.  
  62. extern char   cdecl  gprintf(char,char *,...);
  63.  
  64.  
  65. WINDOW * pascal open_menu(char *mnm,KMENU *mn,int hsel);
  66. int pascal gethmenu(KMENU *mn,WINDOW *hmenu,int hsel);
  67. int pascal getvmn(KMENU *mn,WINDOW *hmenu,int *hsel,int vsel);
  68. int pascal haccent(KMENU *mn,WINDOW *hmenu,int hsel,int vsel);
  69. void pascal dimension(char *sl[],int *ht,int *wd);
  70. void pascal light(KMENU *mn,WINDOW *hmenu,int hsel,int d);
  71.  
  72. /* Display & process a menu */
  73. int pascal kmenu_select(char *name,KMENU *mn) {
  74.  
  75.     WINDOW *hmenu;
  76.     int sx,sy;
  77.     int hsel=1,vsel;
  78. #ifdef USEMOUSE
  79.     int temph,tempv;
  80. #endif
  81.  
  82. #ifdef USEMOUSE
  83.     temph=hcount;
  84.     tempv=vcount;
  85.     hcount=hysterisis;
  86.     vcount=hysterisis;
  87. #endif
  88.     curr_cursor(&sx,&sy);
  89. /*    cursor(0,26);     */
  90.     hmenu=open_menu(name,mn,hsel);
  91.     while(hsel=gethmenu(mn,hmenu,hsel)) {
  92.         vsel=1;
  93.         while(vsel=getvmn(mn,hmenu,&hsel,vsel)) {
  94.             if(vsel>25) {
  95.                 vsel=1;
  96.                 continue;
  97.             }
  98.             delete_window(hmenu);
  99. /*            set_help("",0,0);  */
  100.             if(!baud) cursor(sx,sy);
  101.             else gprintf(0,"\x1b[%d;%dH",sy+1,sx+1);
  102. #ifdef USEMOUSE
  103.             hcount=temph;
  104.             vcount=tempv;
  105. #endif
  106.             return (mn+hsel-1)->returnkey[vsel-1];
  107.         }
  108.     }
  109.     delete_window(hmenu);
  110.     if(!baud) cursor(sx,sy);
  111.     else gprintf(0,"\x1b[%d;%dH",sy+1,sx+1);
  112. /*    set_help("",0,0); */
  113. #ifdef USEMOUSE
  114.     hcount=temph;
  115.     vcount=tempv;
  116. #endif
  117.     return 0;
  118. }
  119.  
  120.  
  121. /* Open a horizontal menu */
  122. static WINDOW * pascal open_menu(char *mnm,KMENU *mn,int hsel) {
  123.  
  124.     int i=0;
  125.     WINDOW *hmenu;
  126.  
  127. /*    set_help("kmenu     ",30,10);     */
  128.     hmenu=establish_window(0,0,3,80);
  129.     set_border(hmenu,2);
  130.     set_title(hmenu,mnm);
  131.     set_colors(hmenu,ALL,BLUE,AQUA,BRIGHT);
  132.     set_colors(hmenu,ACCENT,WHITE,BLACK,DIM);
  133.     display_window(hmenu);
  134.     while((mn+i)->mname)
  135.         wprintf(hmenu," %-9.9s ",(mn+i++)->mname);
  136.     light(mn,hmenu,hsel,1);
  137. /*    cursor(0,26); */
  138.     return hmenu;
  139. }
  140.  
  141. /* Get a horizontal selection */
  142. static int pascal gethmenu(KMENU *mn,WINDOW *hmenu,int hsel) {
  143.  
  144.     int sel;
  145.  
  146.     light(mn,hmenu,hsel,1);
  147.     while(TRUE) {
  148.         switch(sel=get_char()) {
  149.             case FWD:
  150.             case BS:    hsel=haccent(mn,hmenu,hsel,sel);
  151.                         break;
  152.             case ESC:    return 0;
  153.             case 0:
  154.             case '\r':  return hsel;
  155.             case DN:    return hsel;
  156.             default:    putchar (BELL);
  157.                         break;
  158.         }
  159.     }
  160. }
  161.  
  162. /* Pop down a vertical menu */
  163. static int pascal getvmn(KMENU *mn,WINDOW *hmenu,int *hsel,int vsel) {
  164.  
  165.     WINDOW *vmenu;
  166.     int ht=10,wd=20;
  167.     int temp;
  168.     char **mp;
  169.  
  170.     while (1) {
  171.         dimension((mn+*hsel-1)->mselcs,&ht,&wd);
  172.         if(wd+(2+(*hsel-1)*11)>78)temp=79-wd;
  173.         else temp=2+(*hsel-1)*11;
  174.         vmenu=establish_window(temp,2,ht,wd);
  175.         set_colors(vmenu,ALL,BLUE,AQUA,BRIGHT);
  176.         set_colors(vmenu,ACCENT,WHITE,BLACK,DIM);
  177.         set_border(vmenu,4);
  178.         display_window(vmenu);
  179.         mp=(mn+*hsel-1)->mselcs;
  180.         while(*mp) wprintf(vmenu,"\n%s",*mp++);
  181.         vsel=get_selection(vmenu,vsel,"");
  182.         delete_window(vmenu);
  183.         if (vsel==FWD || vsel==BS) {
  184.             *hsel=haccent(mn,hmenu,*hsel,vsel);
  185.             vsel=1;
  186.         }
  187.         else
  188.             return vsel;
  189.     }
  190. }
  191.  
  192. /* Manage the horizontal menu selection accent */
  193. static int pascal haccent(KMENU *mn,WINDOW *hmenu,int hsel,int sel) {
  194.  
  195.     switch (sel) {
  196.         case FWD:
  197.             light(mn,hmenu,hsel,0);
  198.             if((mn+hsel)->mname)
  199.                 hsel++;
  200.             else
  201.                 hsel=1;
  202.             light(mn,hmenu,hsel,1);
  203.             break;
  204.         case BS:
  205.             light(mn,hmenu,hsel,0);
  206.             if(hsel==1)
  207.                 while((mn+hsel)->mname)
  208.                     hsel++;
  209.             else
  210.                 --hsel;
  211.             light(mn,hmenu,hsel,1);
  212.             break;
  213.         default:
  214.             break;
  215.     }
  216.     return hsel;
  217. }
  218.  
  219. /* Compute a menu's height & width */
  220. static void pascal dimension(char *sl[],int *ht,int *wd) {
  221.  
  222.     unsigned strlen(char *);
  223.  
  224.     *ht=*wd=0;
  225.     while(sl[*ht]) {
  226.         *wd=max(*wd,strlen(sl[*ht]));
  227.         (*ht)++;
  228.     }
  229.     *ht+=2;
  230.     *wd+=2;
  231. }
  232.  
  233. /* Accent a horizontal menu selection */
  234. static void pascal light (KMENU *mn,WINDOW *hmenu,int hsel,int d) {
  235.  
  236.     if(d) reverse_video(hmenu);
  237.     wcursor(hmenu,(hsel-1)*11+2,0);
  238.     wprintf(hmenu,(mn+hsel-1)->mname);
  239.     normal_video(hmenu);
  240. /*    cursor(0,26); */
  241. }
  242.  
  243.