home *** CD-ROM | disk | FTP | other *** search
- /*
- mouseini.c 12/12/88
-
- % window manager mouse initialization functions.
- by Ted.
-
- OWL 1.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 1/19/89 ted Added joe's offer evcode return feature.
- 1/31/89 ted Fixed invalid lastmev->win bug.
- 2/08/88 ted added newcurrent arg features to fix mouse support.
- 4/04/89 ted Added mouse de-initialization feature.
- 4/11/89 ted Fixed repeating end-msg bug.
- 5/01/89 ted Tweaked newcurrent features for move/size/top win transitions.
- 5/11/89 ted Added mouse trap-win check.
- 5/19/89 jmd removed static for silly UNIX compiler
- 6/14/89 ted Fixed mouse trap-win case to msg window not border.
- 6/23/89 ted Cleared wmgr_lastmoupos in InitMouse for clean startup case.
- 7/07/89 gam Changed NULL to FNULL where necessary
- 8/16/89 ted Added fake mouse event notification.
-
- 11/27/89 ted Renamed wmgr_trapmousewin() macro to disp_GetMouseTrap().
- 12/10/89 ted Added possibility for endevent to return evcode.
- 3/28/90 jmd ansi-fied
- 5/12/90 jmd changed scancodes to ints
- 6/22/90 ted added "void"s to no-parameter functions per ansii.
- 8/02/90 jmd corrected spelling in comment
- 8/03/90 jmd borders can now return events via kb_Read
- 8/27/90 ted Added code to clear nextchild before offer/request msgs.
- 9/23/90 ted added support for new 'outside' flag and 'currmev' struct;
- moved lastmev update to end of sendmsgs function.
- 9/23/90 ted Made offer/event transitions go thru border if mousethru is on.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "bordobj.h"
- #include "scancode.h" /* for mouse pseudo-scancodes */
-
- OSTATIC SMM_func (sendmousemsgs);
- OSTATIC int OWLPRIV sendmsgs(mev_struct *mev, win_type cwin, int bdmsg, int evmsg, int offermsg);
- OSTATIC boolean OWLPRIV isparentequal(win_type trapwin, win_type mevwin);
-
- #define cmev wmgr_currmev()
- #define pmev wmgr_lastmev()
- /* -------------------------------------------------------------------------- */
-
- boolean hard_InitMouse(void)
- /*
- Turn on mouse support in the current display manager.
- */
- {
- opbox mbox;
-
- if (hard_Control(HC_INITMOUSE, NULL, NULL)) {
- wmgr_SetSMMptr(sendmousemsgs);
-
- mbox.xmin = 0; mbox.xmax = disp_GetPixWidth();
- mbox.ymin = 0; mbox.ymax = disp_GetPixHeight();
- hard_Control(HC_SETMOUSEBOX, &mbox, NULL);
-
- disp_ShowMouse();
- mev_ClearEvent(wmgr_lastmoupos());
-
- return(TRUE);
- }
- return(FALSE);
- }
- /* -------------------------------------------------------------------------- */
-
- void hard_DeinitMouse(void)
- /*
- Turn off mouse support in the current display manager.
- */
- {
- disp_HideMouse();
- hard_Control(HC_DEINITMOUSE, NULL, NULL);
-
- wmgr_SetSMMptr(FNULL);
- wmgr_SetNewCurrentFlag(FALSE); /* Just to be safe */
- wmgr_currmev()->win = NULL; /* needed to initialize mouse handling */
- wmgr_lastmev()->win = NULL;
- }
- /* -------------------------------------------------------------------------- */
-
- static int sendmousemsgs(moupos_struct *mouposp, boolean newcurr)
- /*
- Sends the appropriate mouse messages to the appropriate windows and borders.
- Returns a scancode which is returned through kb_Read to the current window.
- */
- {
- win_type trapwin;
- win_type cwin, pwin, mwin;
- int evcode, tevcode;
- boolean pincurr;
- opcoord tx, ty;
-
-
- /* Return right now if we're being re-entered from one of the messages */
- if (wmgr_InMouse()) {
- return(MOU_IGNORE);
- }
-
- /* Set up fresh mouse event structure */
-
- /* Find which window the mouse point falls in */
- cmev->win = wmgr_PointWin(mouposp->x, mouposp->y);
-
- /* Special case for trapping mouse events to the current window and its children */
- cmev->outside = FALSE;
- if ((trapwin = disp_GetMouseTrap()) != NULL) {
- if (!isparentequal(trapwin, cmev->win)) {
- cmev->win = trapwin;
- cmev->outside = TRUE;
- }
- }
- /* Make the mouse coords relative to the window */
- if (cmev->win != NULL) {
- cmev->x = mouposp->x - win_GetXmin(cmev->win);
- cmev->y = mouposp->y - win_GetYmin(cmev->win);
- cmev->event = mouposp->event;
- }
-
- wmgr_SetInMouse(TRUE);
- if (newcurr) { /* Set flag for artificial mouse message */
- wmgr_SetFakeMouse(TRUE);
- }
- cwin = disp_GetCurrentWin();
-
- /* Set up fresh mouse event flags */
- mwin = cmev->win;
- cmev->inborder = FALSE;
- cmev->incurrent = FALSE;
- if (mwin != NULL) {
- tx = cmev->x;
- ty = cmev->y;
- if (!cmev->outside) {
- if (win_clippoint(mwin, &tx, &ty) != 0) {
- /* Point is not in inbox, so it must be in border */
- cmev->inborder = TRUE; /* Set flag if mouse is in border of win */
- }
- }
- if (mwin == cwin) {
- cmev->incurrent = TRUE; /* Set flag if mouse is in current win */
- }
- }
- /* Remember previous event structure */
- pwin = pmev->win;
-
- /* Send exit/enter messages or else a regular message */
- if (mwin != pwin ||
- cmev->inborder != pmev->inborder || cmev->incurrent != pmev->incurrent) {
- /* Left window, or not in same border/win part of win, */
- /* or win was current and isn't anymore */
-
- /* Since border message doesn't distinguish between offers & events, */
- /* don't send pseudo-messages to borders for change in current-status.*/
- if (newcurr && mwin == pwin && cmev->inborder && pmev->inborder &&
- !(bord_GetFeature(mwin) & BD_MOUSETHRU)) {
- evcode = MOU_IGNORE;
- }
- else {
- /* Send END message to old window if needed */
- tevcode = sendmsgs(pmev, NULL, BDM_ENDMOUSE, MEV_ENDEVENT, MEV_ENDOFFER);
-
- pincurr = pmev->incurrent; /* Start msg is going to wipe pmev */
-
- /* Send START message to new window if needed */
- evcode = sendmsgs(cmev, cwin, BDM_STARTMOUSE, MEV_STARTEVENT, MEV_STARTOFFER);
-
- /* If startoffer msg had nothing to say and offer was refused,
- return evcode from endevent msg.
- */
- if (evcode == MOU_IGNORE && mev_IsEventClear(cmev) &&
- pincurr && !cmev->incurrent) {
- evcode = tevcode;
- }
- }
- }
- else {
- /* We don't really care to be notified of pseudo-events that don't */
- /* change the status of anything. That would open new cans of worms. */
- if (newcurr) {
- evcode = MOU_IGNORE;
- }
- /* Notify Mouse window of current event; get event code */
- else {
- evcode = sendmsgs(cmev, cwin, BDM_MOUSE, MEV_EVENT, MEV_OFFER);
- }
- }
- wmgr_SetInMouse(FALSE);
- wmgr_SetFakeMouse(FALSE);
-
- return(evcode);
- }
- /* -------------------------------------------------------------------------- */
-
- static int OWLPRIV sendmsgs(mev_struct *mev, win_type cwin, int bdmsg, int evmsg, int offermsg)
- {
- win_type mwin;
- int evcode, ret;
-
- mwin = mev->win;
- evcode = MOU_IGNORE;
-
- if (win_Ok(mwin)) {
- if (mev->inborder) { /* border */
- /* Notify the window border of mouse event in it */
- ret = bord_Do(mwin, bdmsg, mev, NULL);
- if (ret != 0 && ret != 1) {
- evcode = ret;
- }
- }
- /* If border wants to pass offer through to window, event won't be 0 */
- if (!mev_IsEventClear(mev) && win_MouseOk(mwin)) {
- if (mev->incurrent) { /* current */
- /* Notify the window of mouse event */
- evcode = win_DoMouse(mwin, evmsg, mev);
- }
- else { /* not current */
- /* Clear nextchild out now in case offer doesn't set it */
- win_SetNextChild(mwin, -1);
-
- /* Ask the window if it wants the mouse event */
- /* Allow offer msg to return evcode if mwin doesn't accept offer */
- evcode = win_DoMouse(mwin, offermsg, mev);
- if (!mev_IsEventClear(mev)) {
- if (cwin != NULL && win_MouseOk(cwin)) {
- evcode = win_DoMouse(cwin, MEV_REQUEST, mev);
- }
- else {
- evcode = MOU_IGNORE;
- }
- }
- }
- }
- else {
- mev_ClearEvent(mev); /* for the benefit of passing endevent msg thru */
- }
- }
- if (bdmsg != BDM_ENDMOUSE) { /* Stash will be done in START case */
- /* Stash current event as previous event */
- memmove((VOID *) wmgr_lastmev(), (VOID *) wmgr_currmev(), sizeof(mev_struct));
- }
- return(evcode);
- }
- /* -------------------------------------------------------------------------- */
-
- static boolean OWLPRIV isparentequal(win_type trapwin, win_type mevwin)
- /*
- Return whether trapwin is equal to mevwin or any of its parents.
- */
- {
- for (;;) {
- if (mevwin == NULL) {
- return(FALSE);
- }
- if (mevwin == trapwin) {
- return(TRUE);
- }
- mevwin = win_GetParent(mevwin);
- }
- }
- /* -------------------------------------------------------------------------- */
-