home *** CD-ROM | disk | FTP | other *** search
- /*
- mouseini.c 12/12/88
-
- % window manager mouse initialization functions.
- by Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 01/19/89 TED: Added joe's offer evcode return feature.
- 01/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.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "bordobj.h"
- #include "scancode.h" /* for mouse pseudo-scancodes */
-
- OSTATIC SMM_func (sendmousemsgs);
-
- OSTATIC unsigned OWLPRIV domsgs(_arg2(mev_struct *mev, boolean newcurr));
- OSTATIC unsigned OWLPRIV sendmsgs(_arg5(mev_struct *mev, win_type win,
- int bdmsg, int evmsg, int offermsg));
- OSTATIC boolean OWLPRIV isparentequal(_arg2(win_type trapwin, win_type mevwin));
- /* -------------------------------------------------------------------------- */
-
- boolean hard_InitMouse()
- /*
- 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()
- /*
- 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_lastmev()->win = NULL; /* needed to initialize mouse handling */
- }
- /* -------------------------------------------------------------------------- */
-
- static unsigned sendmousemsgs(mouposp, newcurr)
- moupos_struct *mouposp; /* abs. mouse pos from hardware */
- boolean newcurr;
- /*
- Sends the appropriate mouse messages to the appropriate windows and borders.
- */
- {
- mev_struct mouevent;
- opcoord nx, ny;
- win_type trapwin;
-
- /* Set up fresh mouse event structure */
-
- /* Find which window the mouse point falls in */
- mouevent.win = wmgr_PointWin(mouposp->x, mouposp->y);
-
- /* Special case for trapping mouse events to the current window and its children */
- if ((trapwin = wmgr_trapmousewin()) != NULL) {
- if (!isparentequal(trapwin, mouevent.win)) {
- mouevent.win = trapwin;
- }
- }
- if (mouevent.win != NULL) {
- /* Make the mouse coords relative to the window */
- nx = mouposp->x - win_GetXmin(mouevent.win);
- ny = mouposp->y - win_GetYmin(mouevent.win);
- mouevent.x = nx;
- mouevent.y = ny;
- mouevent.event = mouposp->event;
- }
- return(domsgs(&mouevent, newcurr));
- }
- /* -------------------------------------------------------------------------- */
-
- static unsigned OWLPRIV domsgs(mev, newcurr)
- mev_struct *mev;
- boolean newcurr;
- {
- win_type cwin, pwin, mwin;
- mev_struct *pmev;
- unsigned evcode;
- opcoord nx, ny;
- opbox jbox;
-
- /* Return right now if we're being re-entered from one of the messages */
- if (wmgr_InMouse()) {
- return(MOU_IGNORE);
- }
- wmgr_SetInMouse(TRUE);
- if (newcurr) { /* Set flag for artificial mouse message */
- wmgr_SetFakeMouse(TRUE);
- }
- cwin = disp_GetCurrentWin();
-
- /* Set up fresh mouse event flags */
- mwin = mev->win;
- mev->inborder = FALSE;
- mev->incurrent = FALSE;
- if (mwin != NULL) {
- nx = mev->x;
- ny = mev->y;
- if (win_clippoint(mwin, &nx, &ny) != 0) {
- /* Point is not in inbox, so it must be in border */
- mev->inborder = TRUE; /* Set flag if mouse is in border of win */
-
- /* If we've trapped the mouse and the event is outside the border, */
- /* the window should get it anyway. */
-
- if (wmgr_trapmousewin() != NULL) {
- bord_GetPixBox(mwin, &jbox);
- if (mev->x < jbox.xmin || mev->x >= jbox.xmax ||
- mev->y < jbox.ymin || mev->y >= jbox.ymax) {
- mev->inborder = FALSE;
- }
- }
- }
- if (mwin == cwin) {
- mev->incurrent = TRUE; /* Set flag if mouse is in current win */
- }
- }
- /* Remember previous event structure */
- pmev = wmgr_lastmev();
- pwin = pmev->win;
-
- /* Send exit/enter messages or else a regular message */
- if (mwin != pwin ||
- mev->inborder != pmev->inborder || mev->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 distiguish between offers & events, */
- /* don't send pseudo-messages to borders for change in current-status.*/
- if (newcurr && mwin == pwin && mev->inborder && pmev->inborder) {
- evcode = MOU_IGNORE;
- }
- else {
- /* Send END message to old window if needed */
- sendmsgs(pmev, NULL,
- BDM_ENDMOUSE, MEV_ENDEVENT, MEV_ENDOFFER);
- /* Send START message to new window if needed */
- evcode = sendmsgs(mev, cwin,
- BDM_STARTMOUSE, MEV_STARTEVENT, MEV_STARTOFFER);
- }
- }
- 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(mev, cwin,
- BDM_MOUSE, MEV_EVENT, MEV_OFFER);
- }
- wmgr_SetInMouse(FALSE);
- wmgr_SetFakeMouse(FALSE);
- return(evcode);
- }
- /* -------------------------------------------------------------------------- */
-
- static unsigned OWLPRIV sendmsgs(mev, cwin, bdmsg, evmsg, offermsg)
- mev_struct *mev;
- win_type cwin;
- int bdmsg;
- int evmsg;
- int offermsg;
- {
- win_type mwin;
- unsigned evcode;
-
- mwin = mev->win;
-
- if (bdmsg != BDM_ENDMOUSE) { /* Stash will be done in START case */
- /* Stash current event as previous event */
- memmove((VOID *)wmgr_lastmev(),
- (VOID *)mev, sizeof(mev_struct));
- }
- evcode = MOU_IGNORE;
-
- if (win_Ok(mwin)) {
- if (mev->inborder) { /* border */
- /* Notify the window border of mouse event in it */
- bord_Do(mwin, bdmsg, mev, NULL);
- }
- /* 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 */
- /* Ask the window if it wants the mouse event */
- 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;
- }
- }
- }
- }
- return(evcode);
- }
- /* -------------------------------------------------------------------------- */
-
- static boolean OWLPRIV isparentequal(trapwin, mevwin)
- 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);
- }
- }
- /* -------------------------------------------------------------------------- */
-
-