home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / MOUSEINI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  7.6 KB  |  262 lines

  1. /*
  2.     mouseini.c    12/12/88
  3.  
  4.     % window manager mouse initialization functions.
  5.     by Ted.
  6.  
  7.     OWL 1.1
  8.     Copyright (c) 1988, by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.     01/19/89 TED:     Added joe's offer evcode return feature.
  14.     01/31/89 TED:     Fixed invalid lastmev->win bug.
  15.      2/08/88 ted:    added newcurrent arg features to fix mouse support.
  16.      4/04/89 ted    Added mouse de-initialization feature.
  17.      4/11/89 ted    Fixed repeating end-msg bug.
  18.      5/01/89 ted    Tweaked newcurrent features for move/size/top win transitions.
  19.      5/11/89 ted    Added mouse trap-win check.
  20.      5/19/89 jmd    removed static for silly UNIX compiler
  21.      6/14/89 ted    Fixed mouse trap-win case to msg window not border.
  22.      6/23/89 ted    Cleared wmgr_lastmoupos in InitMouse for clean startup case.
  23.      7/07/89 gam    Changed NULL to FNULL where necessary
  24.      8/16/89 ted    Added fake mouse event notification.
  25. */
  26.  
  27. #include "oakhead.h"
  28. #include "disppriv.h"
  29. #include "bordobj.h"
  30. #include "scancode.h"    /* for mouse pseudo-scancodes */
  31.  
  32. OSTATIC SMM_func (sendmousemsgs);
  33.  
  34. OSTATIC unsigned OWLPRIV domsgs(_arg2(mev_struct *mev, boolean newcurr));
  35. OSTATIC unsigned OWLPRIV sendmsgs(_arg5(mev_struct *mev, win_type win,
  36.                                 int bdmsg, int evmsg, int offermsg));
  37. OSTATIC boolean  OWLPRIV isparentequal(_arg2(win_type trapwin, win_type mevwin));
  38. /* -------------------------------------------------------------------------- */
  39.  
  40. boolean hard_InitMouse()
  41. /*
  42.     Turn on mouse support in the current display manager.
  43. */
  44. {
  45.     opbox mbox;
  46.  
  47.     if (hard_Control(HC_INITMOUSE, NULL, NULL)) {
  48.         wmgr_SetSMMptr(sendmousemsgs);
  49.  
  50.         mbox.xmin = 0; mbox.xmax = disp_GetPixWidth();
  51.         mbox.ymin = 0; mbox.ymax = disp_GetPixHeight();
  52.         hard_Control(HC_SETMOUSEBOX, &mbox, NULL);
  53.  
  54.         disp_ShowMouse();
  55.         mev_ClearEvent(wmgr_lastmoupos());
  56.  
  57.         return(TRUE);
  58.     }
  59.     return(FALSE);
  60. }
  61. /* -------------------------------------------------------------------------- */
  62.  
  63. void hard_DeinitMouse()
  64. /*
  65.     Turn off mouse support in the current display manager.
  66. */
  67. {
  68.     disp_HideMouse();
  69.     hard_Control(HC_DEINITMOUSE, NULL, NULL);
  70.  
  71.     wmgr_SetSMMptr(FNULL);
  72.     wmgr_SetNewCurrentFlag(FALSE);    /* Just to be safe */
  73.     wmgr_lastmev()->win = NULL;    /* needed to initialize mouse handling */
  74. }
  75. /* -------------------------------------------------------------------------- */
  76.  
  77. static unsigned sendmousemsgs(mouposp, newcurr)
  78.     moupos_struct *mouposp;            /* abs. mouse pos from hardware */
  79.     boolean newcurr;
  80. /*
  81.     Sends the appropriate mouse messages to the appropriate windows and borders.
  82. */
  83. {
  84.     mev_struct mouevent;
  85.     opcoord nx, ny;
  86.     win_type trapwin;
  87.  
  88.     /* Set up fresh mouse event structure */
  89.  
  90.     /* Find which window the mouse point falls in */
  91.     mouevent.win = wmgr_PointWin(mouposp->x, mouposp->y);
  92.  
  93.     /* Special case for trapping mouse events to the current window and its children */
  94.     if ((trapwin = wmgr_trapmousewin()) != NULL) {
  95.         if (!isparentequal(trapwin, mouevent.win)) {
  96.             mouevent.win = trapwin;
  97.         }
  98.     }
  99.     if (mouevent.win != NULL) {
  100.     /* Make the mouse coords relative to the window */
  101.         nx = mouposp->x - win_GetXmin(mouevent.win);
  102.         ny = mouposp->y - win_GetYmin(mouevent.win);
  103.         mouevent.x = nx;
  104.         mouevent.y = ny;
  105.         mouevent.event = mouposp->event;
  106.     }
  107.     return(domsgs(&mouevent, newcurr));
  108. }
  109. /* -------------------------------------------------------------------------- */
  110.  
  111. static unsigned OWLPRIV domsgs(mev, newcurr)
  112.     mev_struct *mev;
  113.     boolean newcurr;
  114. {
  115.     win_type cwin, pwin, mwin;
  116.     mev_struct *pmev;
  117.     unsigned evcode;
  118.     opcoord nx, ny;
  119.     opbox jbox;
  120.  
  121.     /* Return right now if we're being re-entered from one of the messages */
  122.     if (wmgr_InMouse()) {
  123.         return(MOU_IGNORE);
  124.     }
  125.     wmgr_SetInMouse(TRUE);
  126.     if (newcurr) {    /* Set flag for artificial mouse message */
  127.         wmgr_SetFakeMouse(TRUE);
  128.     }
  129.     cwin = disp_GetCurrentWin();
  130.  
  131.     /* Set up fresh mouse event flags */
  132.     mwin = mev->win;
  133.     mev->inborder = FALSE;
  134.     mev->incurrent = FALSE;
  135.     if (mwin != NULL) {
  136.         nx = mev->x;
  137.         ny = mev->y;
  138.         if (win_clippoint(mwin, &nx, &ny) != 0) {
  139.             /* Point is not in inbox, so it must be in border */
  140.             mev->inborder = TRUE;    /* Set flag if mouse is in border of win */
  141.  
  142.             /* If we've trapped the mouse and the event is outside the border, */
  143.             /*  the window should get it anyway. */
  144.  
  145.             if (wmgr_trapmousewin() != NULL) {
  146.                 bord_GetPixBox(mwin, &jbox);
  147.                 if (mev->x < jbox.xmin || mev->x >= jbox.xmax ||
  148.                     mev->y < jbox.ymin || mev->y >= jbox.ymax) {
  149.                     mev->inborder = FALSE;
  150.                 }
  151.             }
  152.         }
  153.         if (mwin == cwin) {
  154.             mev->incurrent = TRUE;    /* Set flag if mouse is in current win */
  155.         }
  156.     }
  157. /* Remember previous event structure */
  158.     pmev = wmgr_lastmev();
  159.     pwin = pmev->win;
  160.  
  161.     /* Send exit/enter messages or else a regular message */
  162.     if (mwin != pwin ||
  163.         mev->inborder != pmev->inborder || mev->incurrent != pmev->incurrent) {
  164.         /* Left window, or not in same border/win part of win, */
  165.         /* or win was current and isn't anymore */
  166.  
  167.         /* Since border message doesn't distiguish between offers & events, */
  168.         /* don't send pseudo-messages to borders for change in current-status.*/
  169.         if (newcurr && mwin == pwin && mev->inborder && pmev->inborder) {
  170.             evcode = MOU_IGNORE;
  171.         }
  172.         else {
  173.             /* Send END message to old window if needed */
  174.             sendmsgs(pmev, NULL,
  175.                         BDM_ENDMOUSE, MEV_ENDEVENT, MEV_ENDOFFER);
  176.             /* Send START message to new window if needed */
  177.             evcode = sendmsgs(mev, cwin,
  178.                         BDM_STARTMOUSE, MEV_STARTEVENT, MEV_STARTOFFER);
  179.         }
  180.     }
  181.     else {
  182.         /* We don't really care to be notified of pseudo-events that don't */
  183.         /* change the status of anything. That would open new cans of worms. */
  184.         if (newcurr) {
  185.             evcode = MOU_IGNORE;
  186.         }
  187.         /* Notify Mouse window of current event; get event code */
  188.         else evcode = sendmsgs(mev, cwin,
  189.                     BDM_MOUSE, MEV_EVENT, MEV_OFFER);
  190.     }
  191.     wmgr_SetInMouse(FALSE);
  192.     wmgr_SetFakeMouse(FALSE);
  193.     return(evcode);
  194. }
  195. /* -------------------------------------------------------------------------- */
  196.  
  197. static unsigned OWLPRIV sendmsgs(mev, cwin, bdmsg, evmsg, offermsg)
  198.     mev_struct *mev;
  199.     win_type cwin;
  200.     int bdmsg;
  201.     int evmsg;
  202.     int offermsg;
  203. {
  204.     win_type mwin;
  205.     unsigned evcode;
  206.  
  207.     mwin = mev->win;
  208.  
  209.     if (bdmsg != BDM_ENDMOUSE) {    /* Stash will be done in START case */
  210.         /* Stash current event as previous event */
  211.         memmove((VOID *)wmgr_lastmev(),
  212.                 (VOID *)mev, sizeof(mev_struct));
  213.     }
  214.     evcode = MOU_IGNORE;
  215.  
  216.     if (win_Ok(mwin)) {
  217.         if (mev->inborder) {        /* border */
  218.             /* Notify the window border of mouse event in it */
  219.             bord_Do(mwin, bdmsg, mev, NULL);
  220.         }
  221.         /* If border wants to pass offer through to window, event won't be 0 */
  222.         if (!mev_IsEventClear(mev) && win_MouseOk(mwin)) {
  223.             if (mev->incurrent) {    /* current */
  224.                 /* Notify the window of mouse event */
  225.                 evcode = win_DoMouse(mwin, evmsg, mev);
  226.             }
  227.             else {            /* not current */
  228.                 /* Ask the window if it wants the mouse event */
  229.                 evcode = win_DoMouse(mwin, offermsg, mev);
  230.                 if (!mev_IsEventClear(mev)) {
  231.                     if (cwin != NULL && win_MouseOk(cwin)) {
  232.                         evcode = win_DoMouse(cwin, MEV_REQUEST, mev);
  233.                     }
  234.                     else evcode = MOU_IGNORE;
  235.                 }
  236.             }
  237.         }
  238.     }
  239.     return(evcode);
  240. }
  241. /* -------------------------------------------------------------------------- */
  242.  
  243. static boolean OWLPRIV isparentequal(trapwin, mevwin)
  244.     win_type trapwin;
  245.     win_type mevwin;
  246. /*
  247.     Return whether trapwin is equal to mevwin or any of its parents.
  248. */
  249. {
  250.     for (;;) {
  251.         if (mevwin == NULL) {
  252.             return(FALSE);
  253.         }
  254.         if (mevwin == trapwin) {
  255.             return(TRUE);
  256.         }
  257.         mevwin = win_GetParent(mevwin);
  258.     }
  259. }
  260. /* -------------------------------------------------------------------------- */
  261.  
  262.