home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MSGD2OS2.ZIP / MENU.C < prev    next >
Text File  |  1990-09-02  |  4KB  |  212 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.                 memset(t,0,x2 - x1);             /* Patch #1 */
  99.                 p = t;                             /* Patch #1 */
  100.                 break;
  101.  
  102.             case DOWN:
  103.                 pos++;
  104.                 pos %= count;
  105.                 if ((y == y2) || (y == (count + y1 - 1)))
  106.                     scrollup(x1,y1,x2,y2,1);
  107.                 else
  108.                     y++;
  109.                 break;
  110.  
  111.             case UP:
  112.                 pos = (pos==0)?count-1:pos-1;
  113.                 if (y == y1)
  114.                     scrolldown(x1,y1,x2,min(y2,y1+count-1),1);
  115.                 else
  116.                     y--;
  117.                 break;
  118.  
  119.             case PGUP:
  120.                 i = min(count-1,y2);
  121.                 while (i--) {
  122.                     pos = (pos==0)?count-1:pos-1;
  123.                     if (y == y1) {
  124.                         scrolldown(x1,y1,x2,min(y2,y1+count-1),1);
  125.                         gotoxy(x1,y1);
  126.                         set_color(normal);
  127.                         bputs(items[pos]);
  128.                     }
  129.                     else
  130.                         y--;
  131.                     };
  132.                 break;
  133.  
  134.             case PGDN:
  135.                 i = min(count-1,y2);
  136.                 while (i--) {
  137.                     pos++;
  138.                     pos %= count;
  139.                     if ((y == y2) || (y == (count + y1 - 1))) {
  140.                         scrollup(x1,y1,x2,y2,1);
  141.                         gotoxy(x1,min(y2,y1+count-1));
  142.                         set_color(normal);
  143.                         bputs(items[pos]);
  144.                     }
  145.                     else
  146.                         y++;
  147.                 }
  148.                 break;
  149.  
  150.             case ENTER:
  151.                 set_color(normal);
  152.                 return pos;
  153.  
  154.             default:
  155.                 if ((key & 0xff) && ((p-t) < (x2-x1))) { /* Patch #1 */
  156.                     *p = (char) (key & 0xff);
  157.                     p++;
  158.                     i = count;
  159.                     while (i--) {
  160.                         if (strncmpi(t,items[pos],strlen(t)) == 0)
  161.                             break;
  162.                         pos++;
  163.                         pos %= count;
  164.                         if ((y == y2) || (y == (count + y1 - 1))) {
  165.                             scrollup(x1,y1,x2,y2,1);
  166.                             gotoxy(x1,min(y2,y1+count-1));
  167.                             set_color(normal);
  168.                             bputs(items[pos]);
  169.                         }
  170.                         else
  171.                             y++;
  172.                     }
  173.                 }
  174.  
  175.                 if ((i<0) || !(key & 0xff)) {
  176.                     memset(t,0,x2-x1);
  177.                     p = t;
  178.                 }
  179.                 break;
  180.         }
  181.  
  182.         set_color(bar);
  183.         gotoxy(x1,y);
  184.         video_update();
  185.         bputs(items[pos]);
  186.     }
  187.  
  188.     set_color(normal);
  189.     free(t);
  190.     return(-1);
  191. }
  192.  
  193. void _pascal box(int x1, int y1, int x2, int y2, int t)
  194.  
  195. {
  196.     int x, y;
  197.  
  198.     for (x = x1 + 1; x < x2; x++) {
  199.         gotoxy(x,y1); bputc(t?196:205);
  200.         gotoxy(x,y2); bputc(t?196:205);
  201.     }
  202.  
  203.     for (y = y1 + 1; y < y2; y++) {
  204.         gotoxy(x1,y); bputc(t?179:186);
  205.         gotoxy(x2,y); bputc(t?179:186);
  206.     }
  207.     gotoxy(x1,y1); bputc(t?218:201);
  208.     gotoxy(x1,y2); bputc(t?192:200);
  209.     gotoxy(x2,y1); bputc(t?191:187);
  210.     gotoxy(x2,y2); bputc(t?217:188);
  211. }
  212.