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

  1. /**
  2. *
  3. * Name        mnmouse -- Add, change, or delete a mouse menu event.
  4. *
  5. * Synopsis    presult = mnmouse(pmenu,event,ignore,action,option);
  6. *
  7. *        BMENU *presult    Pointer to menu in which mouse behavior
  8. *                was just changed, or NIL for failure.
  9. *        BMENU *pmenu    Pointer to menu in which to change mouse
  10. *                behavior.
  11. *        unsigned long event
  12. *                Bit mask designating event to handle.
  13. *                The following bits are relevant:
  14. *
  15. *                    MO_LEFT
  16. *                    MO_RIGHT
  17. *                    MO_MIDDLE
  18. *
  19. *                    MO_PRESS
  20. *                    MO_RELEASE
  21. *                    MO_CLICK
  22. *                    MO_DCLICK
  23. *                    MO_HOLD
  24. *
  25. *                    MO_RSHIFT
  26. *                    MO_LSHIFT
  27. *                    MO_CSHIFT
  28. *                    MO_ASHIFT
  29. *
  30. *                    MN_ITEMS
  31. *                    MN_OFF_ITEMS
  32. *                    MN_OUT_MENU
  33. *
  34. *        unsigned long ignore
  35. *                Bit mask indicating event bits to
  36. *                ignore.  The following bits may be
  37. *                set:
  38. *
  39. *                    MO_LEFT
  40. *                    MO_RIGHT
  41. *                    MO_MIDDLE
  42. *
  43. *                    MO_RSHIFT
  44. *                    MO_LSHIFT
  45. *                    MO_CSHIFT
  46. *                    MO_ASHIFT
  47. *
  48. *                    MN_ITEMS
  49. *                    MN_OFF_ITEMS
  50. *                    MN_OUT_MENU
  51. *
  52. *        int    action    The action(s) to take when the
  53. *                designated mouse event is detected.
  54. *                The following bits may be set:
  55. *
  56. *                   MN_TRANSMIT
  57. *                   MN_BEEP
  58. *                   MN_DISABLE
  59. *                   MN_ABORT
  60. *                   MN_KBIGNORE
  61. *                   MN_HIDE_BAR
  62. *                   MN_SHOW_BAR (overrides MN_HIDE_BAR)
  63. *                   MN_SELECT
  64. *
  65. *        int    option    How the specified action should
  66. *                be changed -- Use MN_ADD, MN_CHANGE,
  67. *                or MN_DELETE.
  68. *
  69. * Description    This function records an action to take when the mouse
  70. *        event(s) specified by "event" and "ignore" occurs during
  71. *        MNREAD or MNLREAD.
  72. *
  73. *        Some combinations of bits in "event" have the effect of
  74. *        matching several actual mouse events.  For example,
  75. *        (MO_LEFT | MO_RIGHT | MO_PRESS | MO_RELEASE) detects a
  76. *        press or release of either button.
  77. *
  78. *        An error occurs if
  79. *
  80. *            MN_ADD is specified and an action is already
  81. *              recorded for this event/ignore combination; or if
  82. *            MN_CHANGE or MN_DELETE is specified and no action is
  83. *              recorded for this event/ignore combination; or if
  84. *            the list of mouse actions is corrupted; or if
  85. *            no memory is available.
  86. *
  87. *
  88. * Returns    presult     Pointer to changed menu, or
  89. *                NIL if failure.
  90. *        b_wnerr     Possible values:
  91. *              (No change)       Success.
  92. *              MN_BAD_MENU       pmenu is invalid.
  93. *              MN_BAD_MOUSE       A member of pmenu's list
  94. *                       of mouse actions is bad.
  95. *              WN_ILL_VALUE       option is not MN_ADD,
  96. *                       MN_DELETE, or MN_CHANGE.
  97. *              MN_NO_MOU_EVENT  No matching mouse event
  98. *                       found.
  99. *              MN_MOU_CONFLICT  Cannot add an existing
  100. *                       mouse event (use MN_CHANGE
  101. *                       or MN_DELETE instead).
  102. *              WN_NO_MEMORY       Insufficient memory.
  103. *
  104. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  105. *
  106. **/
  107.  
  108. #include <stdlib.h>
  109.  
  110. #include <bmenu.h>
  111.  
  112.                       /* Internal function.          */
  113. static BMNMOUSE *cdecl mnmchmou(BMNMOUSE *,unsigned long,
  114.                 unsigned long,int *);
  115.  
  116. BMENU *mnmouse(pmenu,event,ignore,action,option)
  117. BMENU         *pmenu;
  118. unsigned long event,ignore;
  119. int          action,option;
  120. {
  121.     BMNMOUSE *pmouse;
  122.     int       error;
  123.  
  124.     mnvalidm(pmenu)        /* Validate the menu data structure.    */
  125.  
  126.     switch (option)
  127.     {
  128.     case MN_ADD:
  129.         if (pmenu->pmouse == NIL)
  130.         {
  131.         if (NIL == (pmouse = utalloc(BMNMOUSE)))
  132.         {
  133.             wnreterr(WN_NO_MEMORY);
  134.         }
  135.  
  136.         pmouse->event      = event;
  137.         pmouse->ignore      = ignore;
  138.         pmouse->action      = action;
  139.         pmouse->signature = MN_MOU_SIGN;
  140.         pmenu->pmouse      = pmouse;
  141.         }
  142.         else
  143.         {
  144.         if (NIL != mnmchmou(pmenu->pmouse,
  145.                     event,ignore,&error))
  146.         {
  147.             wnreterr(MN_MOU_CONFLICT);
  148.         }
  149.         else if (error != WN_NO_ERROR)
  150.         {
  151.             return NIL;       /* Error was recorded by          */
  152.         }              /* MNMCHMOU.              */
  153.  
  154.         if (NIL == (pmouse = utalloc(BMNMOUSE)))
  155.         {
  156.             wnreterr(WN_NO_MEMORY);
  157.         }
  158.  
  159.         pmouse->event      = event;
  160.         pmouse->ignore      = ignore;
  161.         pmouse->action      = action;
  162.         pmouse->signature = MN_MOU_SIGN;
  163.  
  164.         pmouse->pnext         = pmenu->pmouse;
  165.         pmenu->pmouse->pprev = pmouse;
  166.         pmenu->pmouse         = pmouse;
  167.         }
  168.         break;
  169.  
  170.     case MN_CHANGE:
  171.         if (NIL == (pmouse = mnmchmou(pmenu->pmouse,
  172.                       event,ignore,&error)))
  173.         {
  174.         if (error == WN_NO_ERROR)
  175.             wnerror(MN_NO_MOU_EVENT);
  176.         return NIL;
  177.         }
  178.  
  179.         pmouse->action = action;
  180.         break;
  181.  
  182.     case MN_DELETE:
  183.         if (NIL == (pmouse = mnmchmou(pmenu->pmouse,
  184.                       event,ignore,&error)))
  185.         {
  186.         if (error == WN_NO_ERROR)
  187.             wnerror(MN_NO_MOU_EVENT);
  188.         return NIL;
  189.         }
  190.  
  191.         if (NIL != pmouse->pprev)
  192.         pmouse->pprev->pnext = pmouse->pnext;
  193.         if (NIL != pmouse->pnext)
  194.         pmouse->pnext->pprev = pmouse->pprev;
  195.         if (pmenu->pmouse == pmouse)
  196.         pmenu->pmouse = pmouse->pnext;
  197.         pmouse->signature = MN_DEAD_MOUSE;
  198.         free(pmouse);
  199.         break;
  200.  
  201.     default:
  202.         wnreterr(WN_ILL_VALUE);
  203.     }
  204.     return pmenu;
  205. }
  206.  
  207. /**
  208. *
  209. * Name        mnmchmou -- Search list of mouse events.
  210. *
  211. * Synopsis    presult = mnmchmou(pmouse,event,ignore,perror);
  212. *
  213. *        BMNMOUSE *presult
  214. *                Address of the found mouse event
  215. *                record, or NIL for failure.
  216. *        BMNMOUSE *pmouse
  217. *                Address of initial mouse event
  218. *                record from which to begin search.
  219. *        unsigned long event
  220. *                Bit mask designating event to handle.
  221. *        unsigned long ignore
  222. *                Bit mask indicating event bits to
  223. *                ignore.
  224. *        int *perror    Address of variable in which to
  225. *                return resulting error.
  226. *
  227. * Description    This function searches a linked list of mouse event
  228. *        records for an entry matching a particular
  229. *        specification.    Both "event" and "ignore" must be
  230. *        matched exactly.
  231. *
  232. * Returns    presult     Pointer to mouse event record found, or
  233. *                NIL if not found or if list corrupted.
  234. *        *perror     WN_NO_ERROR if list is healthy,
  235. *                WN_BAD_MOUSE if event list corrupted,
  236. *        b_wnerr     WN_BADMOUSE if event list corrupted.
  237. *
  238. **/
  239.  
  240. #include <bmenu.h>
  241.  
  242. static BMNMOUSE *mnmchmou(pmouse,event,ignore,perror)
  243. BMNMOUSE     *pmouse;
  244. unsigned long event,ignore;
  245. int         *perror;
  246. {
  247.     for ( ;
  248.      pmouse != NIL;
  249.      pmouse = pmouse->pnext)
  250.     {
  251.     if (pmouse->signature != MN_MOU_SIGN)
  252.     {
  253.         wnreterr(MN_BAD_MOUSE);
  254.     }
  255.     if (pmouse->event == event && pmouse->ignore == ignore)
  256.     {
  257.         *perror = WN_NO_ERROR;
  258.         return pmouse;
  259.     }
  260.     }
  261.     *perror = WN_NO_ERROR;
  262.     return NIL;
  263. }
  264.