home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / prog2 / boss_sup.lzh / WN_POPUP.C < prev    next >
C/C++ Source or Header  |  1990-03-08  |  6KB  |  137 lines

  1. /*
  2. ** WN_POPUP - Popup Menu/Window Driver
  3. **
  4. ** Copyright (c) 1985-1990 Philip A. Mongelluzzo
  5. ** All rights reserved.
  6. */
  7.  
  8. #include "windows.h"                    /* window header */
  9.  
  10. /*
  11. ************
  12. * wn_popup *
  13. ************
  14. */
  15.  
  16. /*
  17. ** wn_popup(page,row,col,width,height,atrib,batrib,mx,cflag)
  18. **
  19. **  int page -  video page (Usually 0)
  20. **  int row  -  row of origin (0 to WN_MAXROWS)
  21. **  int col  -  col of origin (0 to WN_MAXCOLS)
  22. **  int width - width (inside dimension)
  23. **  int height - height (inside dimension)
  24. **  unsigned atrib - window attribute
  25. **  unsigned batrib - border attribute
  26. **  struct pmenu *mx - pointer to menu structure
  27. **  int cflag - close on exit flag (TRUE to leave open)
  28. */
  29.  
  30. wn_popup(page,row,col,width,height,atrib,batrib,mx,cflag)
  31. int page;                               /* video page */
  32. int row, col;                           /* window - upper row/col */
  33. int width, height;                      /* window - height & width */
  34. struct pmenu *mx;                       /* pointer to popup menu struct */
  35. int cflag;                              /* close on return strike flag */
  36. int atrib, batrib;                      /* attributes - window & border */
  37. {
  38. int i;                                  /* scratch integer */
  39. WINDOWPTR w;                            /* window pointer */
  40. unsigned int c;                         /* key scan code,,char */
  41. int j;                                  /* 1st char scan index */
  42. char ch;                                /* CHARACTER (!scan code) Entered */
  43.  
  44.   if(mx->winopn) {                      /* window is still open */
  45.     goto d0;                            /* enter processing loop */
  46.   }
  47.   mx->lndx = -1;                        /* set index out of range */
  48.   w = wn_open(page, row, col, width, height, atrib, batrib);
  49.   wn_sync(w,FALSE);                     /* sync cursor */
  50.   mx->wpsave = w;                       /* save pointer */
  51.   if (w == NULL) return(99);            /* out of mem or just fubar */
  52.   mx->winopn = TRUE;                    /* say window is open */
  53.  
  54.   i = 0;                                /* init index */
  55.  
  56.   while(mx->scrn[i].r != 99) {          /* for as long as we have data */
  57.     wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, atrib);
  58.     i++;
  59.   }
  60.  
  61. d0:
  62.   w = mx->wpsave;                       /* restore pointer */
  63.   i = mx->lndx;                         /* BLINDLY assume that we're back */
  64.   if(i < mx->fm) i = mx->fm;            /* and reset if "i" is now out of */
  65.   if(i > mx->lm) i = mx->fm;            /* range - (dumb, but it works) */
  66.   while(TRUE) {                         /* till we exit */
  67.     wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, v_setrev(atrib));
  68.     c = v_getch();                      /* Fetch keyboard character */
  69.     ch = c & 0xFF;                      /* character */
  70.     if(c == ESCAPE) break;              /* ESC (user wants out) */
  71.     if(c == RET) {                      /* so RETURN */
  72.       if(cflag) {                       /* close window on return strike ? */
  73.         wn_close(w);                    /* close the window */
  74.         mx->winopn = FALSE;             /* say window is closed */
  75.       }
  76.       mx->lndx = i;                     /* remember last indx */
  77.       return(mx->scrn[i].rv);           /* return with rv */
  78.     }
  79.     if(c == DARROW) c = SPACE;          /* Down arrow acts like Space */
  80.     if(c == RARROW) c = SPACE;          /* Right arrow does too */
  81.     if(c == LARROW) c = BS;             /* Left arrow acts like Back Space */
  82.     if(c == UARROW) c = BS;             /* Up arrow does too */
  83.     if(c == SPACE || c == DEL || c == BS) {
  84.       wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, atrib);
  85.       if(c == SPACE)                    /* foreward ?? */
  86.         i++;                            /* bump index */
  87.       else
  88.         i--;                            /* decrement */
  89.       if(i < mx->fm) i = mx->lm;        /* wrap on either */
  90.       if(i > mx->lm) i = mx->fm;        /* end */
  91.     }                                   /* endif */
  92.     ch = toupper(ch);                   /* lets see if we can use 1st char */
  93.     for (j=mx->fm; j<=mx->lm; j++) {
  94.       if (ch == *mx->scrn[j].t) {  
  95.         wn_putsa(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t, atrib);
  96.         i=j;                           
  97.         break;
  98.       }
  99.     }                                   /* end 1st char scan */
  100.   }                                     /* end while */
  101.   wn_close(w);                          /* bye bye */
  102.   mx->winopn = FALSE;                   /* say window is closed */
  103.   return(99);                           /* nothing selected */
  104. }
  105.  
  106. #ifdef COMMENTS
  107. /*
  108. *************                           /* quick popup... */
  109. * wn_qpopup *                           /* this is a hack of popup */
  110. *************                           /* but the code fragment */
  111. */                                      /* could be of value */
  112.                                         /* ONE TIME DISPLAY ONLY POPUP */
  113.                                         /* CLOSED BY CALLER */
  114. #endif
  115.  
  116. WINDOWPTR wn_qpopup(page,row,col,width,height,atrib,batrib,mx)
  117. int page;                               /* video page */
  118. int row, col;                           /* window - upper row/col */
  119. int width, height;                      /* window - height & width */
  120. int atrib, batrib;                      /* atributes - window & border */
  121. struct pmenu *mx;                       /* pointer to text struct */
  122. {
  123. int i;                                  /* scratch integer */
  124. WINDOWPTR w;                            /* window pointer */
  125.  
  126.   w = wn_open(page, row, col, width, height, atrib, batrib);
  127.  
  128.   i = 0;                                /* init index */
  129.   while(mx->scrn[i].r != 99) {          /* for as long as we have data */
  130.     wn_puts(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t);
  131.     i++;
  132.   }
  133.   return(w);
  134. }
  135.  
  136. /* End */
  137.