home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / MENU.C < prev    next >
Text File  |  1995-12-11  |  7KB  |  151 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   menu.c                                                                  */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*   Action bar menu items handling.                                         */
  7. /*                                                                           */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  12. /*                                                                           */
  13. /*...16->32 port.                                                            */
  14. /*...                                                                        */
  15. /*... 02/08/91  100   Philip    port to 32 bit.                              */
  16. /*... 02/08/91  112   Joe       port to 32 bit.                              */
  17. /*...                                                                        */
  18. /**Includes*******************************************************************/
  19. #include "all.h"
  20.  
  21. #define IMAX 15         /* max # of items per menu (caller must not exceed) */
  22. #define ISPACE 4        /* # of spaces between menu items                   */
  23.  
  24. extern UINT VideoCols;
  25. extern UINT MenuRow;                    /* screen row for menu bar (0..N)    */
  26. extern UINT HelpRow;                    /* screen row for menu help (0..N)   */
  27.  
  28. static  uchar optON[] = {RepCnt(0),Attrib(vaMenuCsr),0};
  29. #define optONlen optON[1]
  30. static  uchar optOFF[] = {RepCnt(0),Attrib(vaMenuBar),0};
  31. #define optOFFlen optOFF[1]
  32. static  uchar hiatt[] = { RepCnt(1), Attrib(vaMenuSel) , 0 };
  33.  
  34. /*****************************************************************************/
  35. /*  MenuBar()                                                                */
  36. /*                                                                           */
  37. /* Description:                                                              */
  38. /*   Displays a menu bar with help, allosw selection, and returns            */
  39. /*   the number (1..N) of the item selected.                                 */
  40. /*                                                                           */
  41. /*                                                                           */
  42. /* synopsis    n = MenuBar( items, helps, helpids, keys, selpos, hot, mask );*/
  43. /*                                                                           */
  44. /* Parameters:                                                               */
  45. /*                                                                           */
  46. /*   uchar *items;           (* concantenation of item strings *)            */
  47. /*   uchar *helps;           (* concantenation of help strings *)            */
  48. /*   ULONG *helpids;         (* array of help ids *)                         */
  49. /*   uchar *keys;            (* array of action keys *)                      */
  50. /*   unit  *selpos;          (* array of select key positions  *)            */
  51. /*   uint   hot;             (* item # initially selected *)                 */
  52. /*   uint   mask;            (* bit mask of disabled options *)              */
  53. /*                                                                           */
  54. /* Return:                                                                   */
  55. /*   uint   n;               (* item # selected, or zero *)                  */
  56. /*                                                                           */
  57. /* Assumptions:                                                              */
  58. /*                                                                           */
  59. /*****************************************************************************/
  60.  uint
  61. MenuBar(uchar *items,uchar *helps, ULONG *helpids,uchar *keys,
  62.         uint selpos[],uint hot,uint  mask)
  63. {
  64.     uint n, max, col, key, x, spacing;  /* was register.                  112*/
  65.     uchar *cp, *ip;                     /* was register.                  112*/
  66.     uchar icol[IMAX], ilen[IMAX];
  67.     uint helper[IMAX];
  68.  
  69.     HideCursor();
  70.     ClrScr( MenuRow, MenuRow, vaMenuBar );
  71.  
  72.     for( spacing = ISPACE+1; --spacing > 0; ){
  73.         for( max=0, col = spacing-1, ip = items, cp = helps; *ip; ++max ){
  74.             icol[max] = ( uchar )col;
  75.             ilen[max] = ( uchar )( (n = strlen(ip)) + 2 );
  76.             col += n + spacing;
  77.             ip += n+1;
  78.             helper[max] = cp - helps;
  79.             cp += strlen(cp) + 1;
  80.         }
  81.         if( col <= (VideoCols - spacing) )
  82.             break;
  83.     }
  84.  
  85.     for( n=0, ip = items; n < max; ++n){
  86.         putrc( MenuRow, icol[n] + 1, ip );
  87.         /* Put highlight attribute on appropriate character of menu item     */
  88.         putrc(MenuRow, icol[n] + selpos[n], hiatt);
  89.         ip += ilen[n] - 1;
  90.     }
  91.  
  92.  
  93.     n = hot-2;
  94.  
  95. /* goto AdvanceOption;*/
  96.  
  97.     for( ; ; ){
  98.         optONlen = optOFFlen = ilen[n];
  99.         ClrScr( HelpRow, HelpRow, vaHelp );
  100.         putrc( HelpRow, 0, helps + helper[n] );
  101.         putrc( MenuRow, icol[n], optON );
  102.         key = GetKey();
  103.         putrc( MenuRow, icol[n], optOFF );
  104.         /* Put highlight attribute on appropriate character of menu item     */
  105.         putrc(MenuRow, icol[n] + selpos[n], hiatt);
  106.         ClrScr( HelpRow, HelpRow, vaHelp );
  107.         switch( key ){
  108.             case TAB:
  109.             case RIGHT:
  110.             case SPACEBAR:
  111.             AdvanceOption:
  112.                do{ if( ++n >= max ) n = 0;
  113.                 }while( mask & (1<<n) );
  114.                 break;
  115.             case LEFT:
  116.             case S_TAB:
  117.                do{ if( --n >= max ) n = max-1;
  118.                 }while( mask & (1<<n) );
  119.                 break;
  120.             case UP:
  121.             case ESC:
  122.             case PADPLUS:
  123.             case PADENTER:
  124.                 n = -1;
  125.                 goto fini;
  126.  
  127.             case ENTER:
  128.                 goto fini;
  129.  
  130.             case F1:
  131.             {
  132.               uchar *HelpMsg;
  133.  
  134.               putrc( MenuRow, icol[n], optON );
  135.               HelpMsg = GetHelpMsg( helpids[n], NULL,0 );
  136.               CuaShowHelpBox( HelpMsg );
  137.               break;
  138.             }
  139.             default:
  140.                 if( (x = bindex(keys, max, (key & 0xFF) | 0x20)) < max  &&
  141.                     !(mask & (1<<x))  ){
  142.                     n = x;
  143.                     goto fini; }
  144.                 beep();
  145.         }
  146.     }
  147.     fini:
  148.  
  149.     return( n+1 );
  150. }
  151.