home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MSGDP206.SZH / MENU.C < prev    next >
Text File  |  1991-01-22  |  5KB  |  215 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.     if (def == -1)                                      /* WRA */
  64.         def = 0;
  65.  
  66.     p = items[pos = def];
  67.     y = y1;
  68.     do {
  69.         set_color(normal);
  70.         gotoxy(x1,y++);
  71.         bputs(items[pos++]);
  72.         pos %= count;
  73.     } while ((items[pos] != p) && (y <= y2));
  74.  
  75.     gotoxy(x1,y = y1);
  76.     pos = def;
  77.     video_update();
  78.     set_color(bar);
  79.     p = t;
  80.     bputs(items[pos]);
  81.  
  82.     while ((key = getkey()) != ABORT) {
  83.         set_color(normal);
  84.         gotoxy(x1,y);
  85.         bputs(items[pos]);
  86.  
  87.         switch (key) {
  88.             case GOBOL:
  89.                 clrwnd(x1,y1,x2,y2);
  90.                 pos = 0;
  91.                 p = items[pos];
  92.                 y = y1;
  93.                 do {
  94.                     set_color(normal);
  95.                     gotoxy(x1,y++);
  96.                     bputs(items[pos++]);
  97.                     pos %= count;
  98.                 } while ((items[pos] != p) && (y <= y2));
  99.                 y = y1;
  100.                 pos = 0;
  101.                 memset(t,0,x2 - x1);
  102.                 p = t;
  103.                 break;
  104.  
  105.             case DOWN:
  106.                 pos++;
  107.                 pos %= count;
  108.                 if ((y == y2) || (y == (count + y1 - 1)))
  109.                     scrollup(x1,y1,x2,y2,1);
  110.                 else
  111.                     y++;
  112.                 break;
  113.  
  114.             case UP:
  115.                 pos = (pos==0)?count-1:pos-1;
  116.                 if (y == y1)
  117.                     scrolldown(x1,y1,x2,min(y2,y1+count-1),1);
  118.                 else
  119.                     y--;
  120.                 break;
  121.  
  122.             case PGUP:
  123.                 i = min(count-1,y2);
  124.                 while (i--) {
  125.                     pos = (pos==0)?count-1:pos-1;
  126.                     if (y == y1) {
  127.                         scrolldown(x1,y1,x2,min(y2,y1+count-1),1);
  128.                         gotoxy(x1,y1);
  129.                         set_color(normal);
  130.                         bputs(items[pos]);
  131.                     }
  132.                     else
  133.                         y--;
  134.                     };
  135.                 break;
  136.  
  137.             case PGDN:
  138.                 i = min(count-1,y2);
  139.                 while (i--) {
  140.                     pos++;
  141.                     pos %= count;
  142.                     if ((y == y2) || (y == (count + y1 - 1))) {
  143.                         scrollup(x1,y1,x2,y2,1);
  144.                         gotoxy(x1,min(y2,y1+count-1));
  145.                         set_color(normal);
  146.                         bputs(items[pos]);
  147.                     }
  148.                     else
  149.                         y++;
  150.                 }
  151.                 break;
  152.  
  153.             case ENTER:
  154.                 set_color(normal);
  155.                 return pos;
  156.  
  157.             default:
  158.                 if ((key & 0xff) && ((p-t) < (x2-x1))) {
  159.                     *p = (char) (key & 0xff);
  160.                     p++;
  161.                     i = count;
  162.                     while (i--) {
  163.                         if (strncmpi(t,items[pos],strlen(t)) == 0)
  164.                             break;
  165.                         pos++;
  166.                         pos %= count;
  167.                         if ((y == y2) || (y == (count + y1 - 1))) {
  168.                             scrollup(x1,y1,x2,y2,1);
  169.                             gotoxy(x1,min(y2,y1+count-1));
  170.                             set_color(normal);
  171.                             bputs(items[pos]);
  172.                         }
  173.                         else
  174.                             y++;
  175.                     }
  176.                 }
  177.  
  178.                 if ((i<0) || !(key & 0xff)) {
  179.                     memset(t,0,x2-x1);
  180.                     p = t;
  181.                 }
  182.                 break;
  183.         }
  184.  
  185.         set_color(bar);
  186.         gotoxy(x1,y);
  187.         video_update();
  188.         bputs(items[pos]);
  189.     }
  190.  
  191.     set_color(normal);
  192.     free(t);
  193.     return(-1);
  194. }
  195.  
  196. void _pascal box(int x1, int y1, int x2, int y2, int t)
  197.  
  198. {
  199.     int x, y;
  200.  
  201.     for (x = x1 + 1; x < x2; x++) {
  202.         gotoxy(x,y1); bputc(t?196:205);
  203.         gotoxy(x,y2); bputc(t?196:205);
  204.     }
  205.  
  206.     for (y = y1 + 1; y < y2; y++) {
  207.         gotoxy(x1,y); bputc(t?179:186);
  208.         gotoxy(x2,y); bputc(t?179:186);
  209.     }
  210.     gotoxy(x1,y1); bputc(t?218:201);
  211.     gotoxy(x1,y2); bputc(t?192:200);
  212.     gotoxy(x2,y1); bputc(t?191:187);
  213.     gotoxy(x2,y2); bputc(t?217:188);
  214. }
  215.