home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / MOUSEINI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-24  |  8.3 KB  |  270 lines

  1. /*
  2.     mouseini.c    12/12/88
  3.  
  4.     % window manager mouse initialization functions.
  5.     by Ted.
  6.  
  7.     OWL 1.2
  8.     Copyright (c) 1988, by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.      1/19/89 ted    Added joe's offer evcode return feature.
  14.      1/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.     11/27/89 ted    Renamed wmgr_trapmousewin() macro to disp_GetMouseTrap().
  27.     12/10/89 ted    Added possibility for endevent to return evcode.
  28.      3/28/90 jmd    ansi-fied
  29.      5/12/90 jmd     changed scancodes to ints
  30.      6/22/90 ted    added "void"s to no-parameter functions per ansii.
  31.      8/02/90 jmd    corrected spelling in comment
  32.      8/03/90 jmd    borders can now return events via kb_Read
  33.      8/27/90 ted    Added code to clear nextchild before offer/request msgs.
  34.      9/23/90 ted    added support for new 'outside' flag and 'currmev' struct;
  35.                      moved lastmev update to end of sendmsgs function.
  36.      9/23/90 ted    Made offer/event transitions go thru border if mousethru is on.
  37. */
  38.  
  39. #include "oakhead.h"
  40. #include "disppriv.h"
  41. #include "bordobj.h"
  42. #include "scancode.h"    /* for mouse pseudo-scancodes */
  43.  
  44. OSTATIC SMM_func (sendmousemsgs);
  45. OSTATIC int         OWLPRIV sendmsgs(mev_struct *mev, win_type cwin, int bdmsg, int evmsg, int offermsg);
  46. OSTATIC boolean    OWLPRIV isparentequal(win_type trapwin, win_type mevwin);
  47.  
  48. #define cmev    wmgr_currmev()
  49. #define pmev    wmgr_lastmev()
  50. /* -------------------------------------------------------------------------- */
  51.  
  52. boolean hard_InitMouse(void)
  53. /*
  54.     Turn on mouse support in the current display manager.
  55. */
  56. {
  57.     opbox mbox;
  58.  
  59.     if (hard_Control(HC_INITMOUSE, NULL, NULL)) {
  60.         wmgr_SetSMMptr(sendmousemsgs);
  61.  
  62.         mbox.xmin = 0; mbox.xmax = disp_GetPixWidth();
  63.         mbox.ymin = 0; mbox.ymax = disp_GetPixHeight();
  64.         hard_Control(HC_SETMOUSEBOX, &mbox, NULL);
  65.  
  66.         disp_ShowMouse();
  67.         mev_ClearEvent(wmgr_lastmoupos());
  68.  
  69.         return(TRUE);
  70.     }
  71.     return(FALSE);
  72. }
  73. /* -------------------------------------------------------------------------- */
  74.  
  75. void hard_DeinitMouse(void)
  76. /*
  77.     Turn off mouse support in the current display manager.
  78. */
  79. {
  80.     disp_HideMouse();
  81.     hard_Control(HC_DEINITMOUSE, NULL, NULL);
  82.  
  83.     wmgr_SetSMMptr(FNULL);
  84.     wmgr_SetNewCurrentFlag(FALSE);    /* Just to be safe */
  85.     wmgr_currmev()->win = NULL;    /* needed to initialize mouse handling */
  86.     wmgr_lastmev()->win = NULL;
  87. }
  88. /* -------------------------------------------------------------------------- */
  89.  
  90. static int sendmousemsgs(moupos_struct *mouposp, boolean newcurr)
  91. /*
  92.     Sends the appropriate mouse messages to the appropriate windows and borders.
  93.     Returns a scancode which is returned through kb_Read to the current window.
  94. */
  95. {
  96.     win_type trapwin;
  97.     win_type cwin, pwin, mwin;
  98.     int evcode, tevcode;
  99.     boolean pincurr;
  100.     opcoord tx, ty;
  101.  
  102.  
  103.     /* Return right now if we're being re-entered from one of the messages */
  104.     if (wmgr_InMouse()) {
  105.         return(MOU_IGNORE);
  106.     }
  107.  
  108.     /* Set up fresh mouse event structure */
  109.  
  110.     /* Find which window the mouse point falls in */
  111.     cmev->win = wmgr_PointWin(mouposp->x, mouposp->y);
  112.  
  113.     /* Special case for trapping mouse events to the current window and its children */
  114.     cmev->outside = FALSE;
  115.     if ((trapwin = disp_GetMouseTrap()) != NULL) {
  116.         if (!isparentequal(trapwin, cmev->win)) {
  117.             cmev->win = trapwin;
  118.             cmev->outside = TRUE;
  119.         }
  120.     }
  121.     /* Make the mouse coords relative to the window */
  122.     if (cmev->win != NULL) {
  123.         cmev->x = mouposp->x - win_GetXmin(cmev->win);
  124.         cmev->y = mouposp->y - win_GetYmin(cmev->win);
  125.         cmev->event = mouposp->event;
  126.     }
  127.  
  128.     wmgr_SetInMouse(TRUE);
  129.     if (newcurr) {    /* Set flag for artificial mouse message */
  130.         wmgr_SetFakeMouse(TRUE);
  131.     }
  132.     cwin = disp_GetCurrentWin();
  133.  
  134.     /* Set up fresh mouse event flags */
  135.     mwin = cmev->win;
  136.     cmev->inborder = FALSE;
  137.     cmev->incurrent = FALSE;
  138.     if (mwin != NULL) {
  139.         tx = cmev->x;
  140.         ty = cmev->y;
  141.         if (!cmev->outside) {
  142.             if (win_clippoint(mwin, &tx, &ty) != 0) {
  143.                 /* Point is not in inbox, so it must be in border */
  144.                 cmev->inborder = TRUE;    /* Set flag if mouse is in border of win */
  145.             }
  146.         }
  147.         if (mwin == cwin) {
  148.             cmev->incurrent = TRUE;    /* Set flag if mouse is in current win */
  149.         }
  150.     }
  151. /* Remember previous event structure */
  152.     pwin = pmev->win;
  153.  
  154.     /* Send exit/enter messages or else a regular message */
  155.     if (mwin != pwin ||
  156.         cmev->inborder != pmev->inborder || cmev->incurrent != pmev->incurrent) {
  157.         /* Left window, or not in same border/win part of win, */
  158.         /* or win was current and isn't anymore */
  159.  
  160.         /* Since border message doesn't distinguish between offers & events, */
  161.         /* don't send pseudo-messages to borders for change in current-status.*/
  162.         if (newcurr && mwin == pwin && cmev->inborder && pmev->inborder &&
  163.             !(bord_GetFeature(mwin) & BD_MOUSETHRU)) {
  164.             evcode = MOU_IGNORE;
  165.         }
  166.         else {
  167.             /* Send END message to old window if needed */
  168.             tevcode = sendmsgs(pmev, NULL, BDM_ENDMOUSE, MEV_ENDEVENT, MEV_ENDOFFER);
  169.  
  170.             pincurr = pmev->incurrent;    /* Start msg is going to wipe pmev */
  171.  
  172.             /* Send START message to new window if needed */
  173.             evcode  = sendmsgs(cmev, cwin, BDM_STARTMOUSE, MEV_STARTEVENT, MEV_STARTOFFER);
  174.  
  175.             /* If startoffer msg had nothing to say and offer was refused,
  176.                 return evcode from endevent msg.
  177.             */
  178.             if (evcode == MOU_IGNORE && mev_IsEventClear(cmev) &&
  179.                 pincurr && !cmev->incurrent) {
  180.                 evcode = tevcode;
  181.             }
  182.         }
  183.     }
  184.     else {
  185.         /* We don't really care to be notified of pseudo-events that don't */
  186.         /* change the status of anything. That would open new cans of worms. */
  187.         if (newcurr) {
  188.             evcode = MOU_IGNORE;
  189.         }
  190.         /* Notify Mouse window of current event; get event code */
  191.         else {
  192.             evcode = sendmsgs(cmev, cwin, BDM_MOUSE, MEV_EVENT, MEV_OFFER);
  193.         }
  194.     }
  195.     wmgr_SetInMouse(FALSE);
  196.     wmgr_SetFakeMouse(FALSE);
  197.  
  198.     return(evcode);
  199. }
  200. /* -------------------------------------------------------------------------- */
  201.  
  202. static int OWLPRIV sendmsgs(mev_struct *mev, win_type cwin, int bdmsg, int evmsg, int offermsg)
  203. {
  204.     win_type mwin;
  205.     int evcode, ret;
  206.  
  207.     mwin = mev->win;
  208.     evcode = MOU_IGNORE;
  209.  
  210.     if (win_Ok(mwin)) {
  211.         if (mev->inborder) {        /* border */
  212.             /* Notify the window border of mouse event in it */
  213.             ret = bord_Do(mwin, bdmsg, mev, NULL);
  214.             if (ret != 0 && ret != 1) {
  215.                 evcode = ret;
  216.             }
  217.         }
  218.         /* If border wants to pass offer through to window, event won't be 0 */
  219.         if (!mev_IsEventClear(mev) && win_MouseOk(mwin)) {
  220.             if (mev->incurrent) {    /* current */
  221.                 /* Notify the window of mouse event */
  222.                 evcode = win_DoMouse(mwin, evmsg, mev);
  223.             }
  224.             else {            /* not current */
  225.                 /* Clear nextchild out now in case offer doesn't set it */
  226.                 win_SetNextChild(mwin, -1);
  227.  
  228.                 /* Ask the window if it wants the mouse event */
  229.                 /* Allow offer msg to return evcode if mwin doesn't accept offer */
  230.                 evcode = win_DoMouse(mwin, offermsg, mev);
  231.                 if (!mev_IsEventClear(mev)) {
  232.                     if (cwin != NULL && win_MouseOk(cwin)) {
  233.                         evcode = win_DoMouse(cwin, MEV_REQUEST, mev);
  234.                     }
  235.                     else {
  236.                         evcode = MOU_IGNORE;
  237.                     }
  238.                 }
  239.             }
  240.         }
  241.         else {
  242.             mev_ClearEvent(mev);    /* for the benefit of passing endevent msg thru */
  243.         }
  244.     }
  245.     if (bdmsg != BDM_ENDMOUSE) {    /* Stash will be done in START case */
  246.         /* Stash current event as previous event */
  247.         memmove((VOID *) wmgr_lastmev(), (VOID *) wmgr_currmev(), sizeof(mev_struct));
  248.     }
  249.     return(evcode);
  250. }
  251. /* -------------------------------------------------------------------------- */
  252.  
  253. static boolean OWLPRIV isparentequal(win_type trapwin, win_type mevwin)
  254. /*
  255.     Return whether trapwin is equal to mevwin or any of its parents.
  256. */
  257. {
  258.     for (;;) {
  259.         if (mevwin == NULL) {
  260.             return(FALSE);
  261.         }
  262.         if (mevwin == trapwin) {
  263.             return(TRUE);
  264.         }
  265.         mevwin = win_GetParent(mevwin);
  266.     }
  267. }
  268. /* -------------------------------------------------------------------------- */
  269.  
  270.