home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / NETMAIL / MSGD2SRC.ZIP / MENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-06  |  3.7 KB  |  210 lines

  1. /*
  2.  *
  3.  * menu
  4.  *
  5.  * moving bar menu code for msged
  6.  *
  7.  * implementation
  8.  *
  9.  */
  10.  
  11. #include <stdlib.h>
  12. #include <stddef.h>
  13. #include <ctype.h>
  14. #include <string.h>
  15. #include "menu.h"
  16. #include "screen.h"
  17.  
  18. #ifdef __MSC__
  19. #define strncmpi strnicmp
  20. #define strcmpi stricmp
  21. #endif
  22.  
  23. #if defined(__ZTC__)
  24. int _pascal strncmpi(char *, char *, int);
  25. #endif
  26.  
  27. /* necessary imports from screen */
  28.  
  29. extern  int maxy,             /* how many screen lines? */
  30.         maxx,             /* how many screen columns? */
  31.         videomethod;      /* DIRECT, BIOS or FOSSIL */
  32.  
  33. int _pascal menu(int x1, int y1, int x2, int y2, char **items, int bar, int normal, int def)
  34.  
  35. {
  36.     int     count = 0,
  37.         pos = 0,
  38.         y = y1,
  39.         key = 0,
  40.         i;
  41.  
  42.     char    *t = NULL,
  43.         *p = NULL,
  44.         **l = items;
  45.  
  46.     x1 = max(1,x1);
  47.     x2 = min(maxx,x2);
  48.     y1 = max(1,y1);
  49.     y2 = min(maxy,y2);
  50.  
  51.     t = malloc(x2 - x1 + 2);
  52.     memset(t,0,x2 - x1 + 2);
  53.  
  54.     set_color(normal);
  55.  
  56.     clrwnd(x1,y1,x2,y2);
  57.  
  58.     while (*l != NULL) {
  59.         count++;
  60.         l++;
  61.     }
  62.  
  63.     p = items[pos = def];
  64.     y = y1;
  65.     do {
  66.         set_color(normal);
  67.         gotoxy(x1,y++);
  68.         bputs(items[pos++]);
  69.         pos %= count;
  70.     } while ((items[pos] != p) && (y <= y2));
  71.  
  72.     gotoxy(x1,y = y1);
  73.     pos = def;
  74.     video_update();
  75.     set_color(bar);
  76.     p = t;
  77.     bputs(items[pos]);
  78.  
  79.     while ((key = getkey()) != ABORT) {
  80.         set_color(normal);
  81.         gotoxy(x1,y);
  82.         bputs(items[pos]);
  83.     
  84.         switch (key) {
  85.             case GOBOL:
  86.                 clrwnd(x1,y1,x2,y2);
  87.                 pos = 0;
  88.                 p = items[pos];
  89.                 y = y1;
  90.                 do {
  91.                     set_color(normal);
  92.                     gotoxy(x1,y++);
  93.                     bputs(items[pos++]);
  94.                     pos %= count;
  95.                 } while ((items[pos] != p) && (y <= y2));
  96.                 y = y1;
  97.                 pos = 0;
  98.                 break;
  99.  
  100.             case DOWN:
  101.                 pos++;
  102.                 pos %= count;
  103.                 if ((y == y2) || (y == (count + y1 - 1)))
  104.                     scrollup(x1,y1,x2,y2,1);
  105.                 else
  106.                     y++;
  107.                 break;
  108.                 
  109.             case UP:
  110.                 pos = (pos==0)?count-1:pos-1;
  111.                 if (y == y1)
  112.                     scrolldown(x1,y1,x2,min(y2,y1+count-1),1);
  113.                 else
  114.                     y--;
  115.                 break;
  116.  
  117.             case PGUP:
  118.                 i = min(count-1,y2);
  119.                 while (i--) {
  120.                     pos = (pos==0)?count-1:pos-1;
  121.                     if (y == y1) {
  122.                         scrolldown(x1,y1,x2,min(y2,y1+count-1),1);
  123.                         gotoxy(x1,y1);
  124.                         set_color(normal);
  125.                         bputs(items[pos]);
  126.                     }
  127.                     else
  128.                         y--;
  129.                     };
  130.                 break;
  131.  
  132.             case PGDN:
  133.                 i = min(count-1,y2);
  134.                 while (i--) {
  135.                     pos++;
  136.                     pos %= count;
  137.                     if ((y == y2) || (y == (count + y1 - 1))) {
  138.                         scrollup(x1,y1,x2,y2,1);
  139.                         gotoxy(x1,min(y2,y1+count-1));
  140.                         set_color(normal);
  141.                         bputs(items[pos]);
  142.                     }
  143.                     else
  144.                         y++;
  145.                 }
  146.                 break;
  147.  
  148.             case ENTER:
  149.                 set_color(normal);
  150.                 return pos;
  151.  
  152.             default:
  153.                 if (key & 0xff) {
  154.                     *p = (char) (key & 0xff);
  155.                     p++;
  156.                     i = count;
  157.                     while (i--) {
  158.                         if (strncmpi(t,items[pos],strlen(t)) == 0)
  159.                             break;
  160.                         pos++;
  161.                         pos %= count;
  162.                         if ((y == y2) || (y == (count + y1 - 1))) {
  163.                             scrollup(x1,y1,x2,y2,1);
  164.                             gotoxy(x1,min(y2,y1+count-1));
  165.                             set_color(normal);
  166.                             bputs(items[pos]);
  167.                         }
  168.                         else
  169.                             y++;
  170.                     }
  171.                 }
  172.  
  173.                 if ((i<0) || !(key & 0xff)) {
  174.                     memset(t,0,x2-x1);
  175.                     p = t;
  176.                 }
  177.                 break;
  178.         }
  179.     
  180.         set_color(bar);
  181.         gotoxy(x1,y);
  182.         video_update();
  183.         bputs(items[pos]);
  184.     }
  185.  
  186.     set_color(normal);
  187.     free(t);
  188.     return(-1);
  189. }
  190.  
  191. void _pascal box(int x1, int y1, int x2, int y2, int t) 
  192.  
  193. {
  194.     int x, y;
  195.  
  196.     for (x = x1 + 1; x < x2; x++) {
  197.         gotoxy(x,y1); bputc(t?196:205);
  198.         gotoxy(x,y2); bputc(t?196:205);
  199.     }
  200.  
  201.     for (y = y1 + 1; y < y2; y++) {
  202.         gotoxy(x1,y); bputc(t?179:186);
  203.         gotoxy(x2,y); bputc(t?179:186);
  204.     }
  205.     gotoxy(x1,y1); bputc(t?218:201);
  206.     gotoxy(x1,y2); bputc(t?192:200);
  207.     gotoxy(x2,y1); bputc(t?191:187);
  208.     gotoxy(x2,y2); bputc(t?217:188);
  209. }
  210.