home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / MNDEFKEY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.8 KB  |  124 lines

  1. /**
  2. *
  3. * Name        MNDEFKEY -- Add default key bindings to menu.
  4. *
  5. * Synopsis    presult = mndefkey (pmenu);
  6. *
  7. *        BMENU *presult    Pointer to just-changed BMENU
  8. *                structure, or NIL if failure.
  9. *        BMENU *pmenu    Pointer to BMENU to which to add
  10. *                key bindings.
  11. *
  12. * Description    This function adds default key bindings to a menu.
  13. *
  14. *        The default bindings are for the UP, DOWN, RIGHT,
  15. *        and LEFT keys to work as they are labeled; for the
  16. *        HOME and END keys to do logical-first and last; for
  17. *        TAB and BACKTAB to do logical-next and previous;
  18. *        for ENTER to transmit the selection; and for ESC to
  19. *        abort the selection.
  20. *
  21. *        To change the default key bindings, make B_MNKEYMAP
  22. *        point to some key table other than B_MNDEFKEY.
  23. *
  24. * Returns    presult       Pointer to newly-changed BMENU
  25. *                  structure, or NIL if failure.
  26. *        b_wnerr       Possible values:
  27. *                  (No change)    Success.
  28. *                  MN_BAD_MENU    Invalid menu.
  29. *                  WN_NO_MEMORY    Insufficient memory.
  30. *
  31. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  32. *
  33. **/
  34.  
  35. #include <bmenu.h>
  36. #include <bkeys.h>
  37.  
  38. #define FALSE 0
  39.  
  40. BMENU *mndefkey (pmenu)
  41. BMENU *pmenu;
  42. {
  43.     BKEYTAB *pktab;
  44.  
  45.         /* For each entry in the key map (char code, scan   */
  46.         /* code, action) insert in menu's key list.         */
  47.     for (pktab = b_mnkeytab;
  48.      pktab->action != MN_INVALID_ACTION;
  49.      pktab++)
  50.         /* Add the key to the keylist if not done.        */
  51.     if (mnkey (pmenu, -1, -1, pktab->ch, pktab->scan,
  52.            pktab->action, MN_ADD) == NIL)
  53.         return (NIL);
  54.  
  55.     return (pmenu);
  56. }
  57.  
  58.  
  59.  
  60. /**
  61. *
  62. * Name        b_mndefkey -- Table which contains default
  63. *                  key map used by MNDEFKEY.
  64. *
  65. * Description    This table contains the default menu key map.  When
  66. *        MNCREATE is called, MNCREATE calls MNDEFKEY to set
  67. *        up the key map with which the menu is "born".
  68. *
  69. *        The global variable B_MNKEYTAB points to the current
  70. *        default key map, and is "born" pointing to the
  71. *        key map found below.
  72. *
  73. **/
  74.  
  75. BKEYTAB b_mndefkey [] =
  76.    {
  77.        {KB_C_N_UP,    KB_S_N_UP,     MN_UP          },
  78.        {KB_C_N_DOWN,  KB_S_N_DOWN,   MN_DOWN          },
  79.        {KB_C_N_RIGHT, KB_S_N_RIGHT,  MN_RIGHT          },
  80.        {KB_C_N_LEFT,  KB_S_N_LEFT,   MN_LEFT          },
  81.        {KB_C_N_HOME,  KB_S_N_HOME,   MN_FIRST          },
  82.        {KB_C_N_END,   KB_S_N_END,    MN_LAST          },
  83.        {KB_C_N_TAB,   KB_S_N_TAB,    MN_NEXT          },
  84.        {KB_C_S_TAB,   KB_S_S_TAB,    MN_PREVIOUS      },
  85.        {KB_C_N_ENTER, KB_S_N_ENTER,  MN_TRANSMIT      },
  86.        {KB_C_N_ESC,   KB_S_N_ESC,    MN_ABORT          },
  87.  
  88.        {KB_C_N_NEW_UP,      KB_S_N_NEW_UP,    MN_UP     },
  89.        {KB_C_N_NEW_DOWN,  KB_S_N_NEW_DOWN,  MN_DOWN   },
  90.        {KB_C_N_NEW_RIGHT, KB_S_N_NEW_RIGHT, MN_RIGHT  },
  91.        {KB_C_N_NEW_LEFT,  KB_S_N_NEW_LEFT,  MN_LEFT   },
  92.        {KB_C_N_NEW_HOME,  KB_S_N_NEW_HOME,  MN_FIRST  },
  93.        {KB_C_N_NEW_END,   KB_S_N_NEW_END,   MN_LAST   },
  94.        {KB_C_N_PADENTER,  KB_S_N_PADENTER,  MN_TRANSMIT},
  95.  
  96.        {KB_C_N_PGUP,      KB_S_N_PGUP,        MN_PGUP   },
  97.        {KB_C_N_PGDN,      KB_S_N_PGDN,        MN_PGDN   },
  98.        {KB_C_N_NEW_PGUP,  KB_S_N_NEW_PGUP,  MN_PGUP   },
  99.        {KB_C_N_NEW_PGDN,  KB_S_N_NEW_PGDN,  MN_PGDN   },
  100.  
  101.        {KB_C_C_RIGHT,      KB_S_C_RIGHT,     MN_PGRIGHT},
  102.        {KB_C_C_LEFT,      KB_S_C_LEFT,        MN_PGLEFT },
  103.        {KB_C_C_NEW_RIGHT, KB_S_C_NEW_RIGHT, MN_PGRIGHT},
  104.        {KB_C_C_NEW_LEFT,  KB_S_C_NEW_LEFT,  MN_PGLEFT },
  105.  
  106.        {KBNDEF,       KBNDEF,         MN_INVALID_ACTION}
  107.    };
  108.  
  109.  
  110.  
  111. /**
  112. *
  113. * Name        b_mnkeytab -- Variable which points to current
  114. *                  default key table used by MNDEFKEY.
  115. *
  116. * Description    This variable points to the default key map which
  117. *        MNCREATE attaches to each newborn menu.  The
  118. *        default for B_MNKEYTAB is to point at the B_MNDEFKEY
  119. *        table.
  120. *
  121. **/
  122.  
  123. BKEYTAB *b_mnkeytab = b_mndefkey;
  124.