home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name mnmouse -- Add, change, or delete a mouse menu event.
- *
- * Synopsis presult = mnmouse(pmenu,event,ignore,action,option);
- *
- * BMENU *presult Pointer to menu in which mouse behavior
- * was just changed, or NIL for failure.
- * BMENU *pmenu Pointer to menu in which to change mouse
- * behavior.
- * unsigned long event
- * Bit mask designating event to handle.
- * The following bits are relevant:
- *
- * MO_LEFT
- * MO_RIGHT
- * MO_MIDDLE
- *
- * MO_PRESS
- * MO_RELEASE
- * MO_CLICK
- * MO_DCLICK
- * MO_HOLD
- *
- * MO_RSHIFT
- * MO_LSHIFT
- * MO_CSHIFT
- * MO_ASHIFT
- *
- * MN_ITEMS
- * MN_OFF_ITEMS
- * MN_OUT_MENU
- *
- * unsigned long ignore
- * Bit mask indicating event bits to
- * ignore. The following bits may be
- * set:
- *
- * MO_LEFT
- * MO_RIGHT
- * MO_MIDDLE
- *
- * MO_RSHIFT
- * MO_LSHIFT
- * MO_CSHIFT
- * MO_ASHIFT
- *
- * MN_ITEMS
- * MN_OFF_ITEMS
- * MN_OUT_MENU
- *
- * int action The action(s) to take when the
- * designated mouse event is detected.
- * The following bits may be set:
- *
- * MN_TRANSMIT
- * MN_BEEP
- * MN_DISABLE
- * MN_ABORT
- * MN_KBIGNORE
- * MN_HIDE_BAR
- * MN_SHOW_BAR (overrides MN_HIDE_BAR)
- * MN_SELECT
- *
- * int option How the specified action should
- * be changed -- Use MN_ADD, MN_CHANGE,
- * or MN_DELETE.
- *
- * Description This function records an action to take when the mouse
- * event(s) specified by "event" and "ignore" occurs during
- * MNREAD or MNLREAD.
- *
- * Some combinations of bits in "event" have the effect of
- * matching several actual mouse events. For example,
- * (MO_LEFT | MO_RIGHT | MO_PRESS | MO_RELEASE) detects a
- * press or release of either button.
- *
- * An error occurs if
- *
- * MN_ADD is specified and an action is already
- * recorded for this event/ignore combination; or if
- * MN_CHANGE or MN_DELETE is specified and no action is
- * recorded for this event/ignore combination; or if
- * the list of mouse actions is corrupted; or if
- * no memory is available.
- *
- *
- * Returns presult Pointer to changed menu, or
- * NIL if failure.
- * b_wnerr Possible values:
- * (No change) Success.
- * MN_BAD_MENU pmenu is invalid.
- * MN_BAD_MOUSE A member of pmenu's list
- * of mouse actions is bad.
- * WN_ILL_VALUE option is not MN_ADD,
- * MN_DELETE, or MN_CHANGE.
- * MN_NO_MOU_EVENT No matching mouse event
- * found.
- * MN_MOU_CONFLICT Cannot add an existing
- * mouse event (use MN_CHANGE
- * or MN_DELETE instead).
- * WN_NO_MEMORY Insufficient memory.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
-
- #include <stdlib.h>
-
- #include <bmenu.h>
-
- /* Internal function. */
- static BMNMOUSE *cdecl mnmchmou(BMNMOUSE *,unsigned long,
- unsigned long,int *);
-
- BMENU *mnmouse(pmenu,event,ignore,action,option)
- BMENU *pmenu;
- unsigned long event,ignore;
- int action,option;
- {
- BMNMOUSE *pmouse;
- int error;
-
- mnvalidm(pmenu) /* Validate the menu data structure. */
-
- switch (option)
- {
- case MN_ADD:
- if (pmenu->pmouse == NIL)
- {
- if (NIL == (pmouse = utalloc(BMNMOUSE)))
- {
- wnreterr(WN_NO_MEMORY);
- }
-
- pmouse->event = event;
- pmouse->ignore = ignore;
- pmouse->action = action;
- pmouse->signature = MN_MOU_SIGN;
- pmenu->pmouse = pmouse;
- }
- else
- {
- if (NIL != mnmchmou(pmenu->pmouse,
- event,ignore,&error))
- {
- wnreterr(MN_MOU_CONFLICT);
- }
- else if (error != WN_NO_ERROR)
- {
- return NIL; /* Error was recorded by */
- } /* MNMCHMOU. */
-
- if (NIL == (pmouse = utalloc(BMNMOUSE)))
- {
- wnreterr(WN_NO_MEMORY);
- }
-
- pmouse->event = event;
- pmouse->ignore = ignore;
- pmouse->action = action;
- pmouse->signature = MN_MOU_SIGN;
-
- pmouse->pnext = pmenu->pmouse;
- pmenu->pmouse->pprev = pmouse;
- pmenu->pmouse = pmouse;
- }
- break;
-
- case MN_CHANGE:
- if (NIL == (pmouse = mnmchmou(pmenu->pmouse,
- event,ignore,&error)))
- {
- if (error == WN_NO_ERROR)
- wnerror(MN_NO_MOU_EVENT);
- return NIL;
- }
-
- pmouse->action = action;
- break;
-
- case MN_DELETE:
- if (NIL == (pmouse = mnmchmou(pmenu->pmouse,
- event,ignore,&error)))
- {
- if (error == WN_NO_ERROR)
- wnerror(MN_NO_MOU_EVENT);
- return NIL;
- }
-
- if (NIL != pmouse->pprev)
- pmouse->pprev->pnext = pmouse->pnext;
- if (NIL != pmouse->pnext)
- pmouse->pnext->pprev = pmouse->pprev;
- if (pmenu->pmouse == pmouse)
- pmenu->pmouse = pmouse->pnext;
- pmouse->signature = MN_DEAD_MOUSE;
- free(pmouse);
- break;
-
- default:
- wnreterr(WN_ILL_VALUE);
- }
- return pmenu;
- }
-
- /**
- *
- * Name mnmchmou -- Search list of mouse events.
- *
- * Synopsis presult = mnmchmou(pmouse,event,ignore,perror);
- *
- * BMNMOUSE *presult
- * Address of the found mouse event
- * record, or NIL for failure.
- * BMNMOUSE *pmouse
- * Address of initial mouse event
- * record from which to begin search.
- * unsigned long event
- * Bit mask designating event to handle.
- * unsigned long ignore
- * Bit mask indicating event bits to
- * ignore.
- * int *perror Address of variable in which to
- * return resulting error.
- *
- * Description This function searches a linked list of mouse event
- * records for an entry matching a particular
- * specification. Both "event" and "ignore" must be
- * matched exactly.
- *
- * Returns presult Pointer to mouse event record found, or
- * NIL if not found or if list corrupted.
- * *perror WN_NO_ERROR if list is healthy,
- * WN_BAD_MOUSE if event list corrupted,
- * b_wnerr WN_BADMOUSE if event list corrupted.
- *
- **/
-
- #include <bmenu.h>
-
- static BMNMOUSE *mnmchmou(pmouse,event,ignore,perror)
- BMNMOUSE *pmouse;
- unsigned long event,ignore;
- int *perror;
- {
- for ( ;
- pmouse != NIL;
- pmouse = pmouse->pnext)
- {
- if (pmouse->signature != MN_MOU_SIGN)
- {
- wnreterr(MN_BAD_MOUSE);
- }
- if (pmouse->event == event && pmouse->ignore == ignore)
- {
- *perror = WN_NO_ERROR;
- return pmouse;
- }
- }
- *perror = WN_NO_ERROR;
- return NIL;
- }