home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / WINMOUGT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-13  |  3.6 KB  |  127 lines

  1. /*
  2.     winmougt.c  12/05/90
  3.  
  4.     % winmou_GreedyTrack
  5.     by Ted.
  6.  
  7.     The generic window greedy mouse handler.
  8.     When a mouse button is clicked over the window, the stuffcode
  9.     is set to MOU_CLICK.
  10.  
  11.     OWL 3.2
  12.     Copyright (c) 1990 by Oakland Group, Inc.
  13.     ALL RIGHTS RESERVED.
  14.  
  15.     Revision History:
  16.     -----------------
  17.     12/12/90 jmd    added missing variable, bordobj.h
  18. */
  19.  
  20. #include "oakhead.h"
  21. #include "odisp.h"
  22. #include "scancode.h"        /* for MOU codes */
  23. #include "bordobj.h"        /* for bord_GetPixBox */
  24.  
  25. OSTATIC int winmev_greedyclip(win_type win, mev_struct *mev);
  26. /* -------------------------------------------------------------------------- */
  27.  
  28. int winmou_GreedyTrack(win_type win, int msg, mev_struct *mev)
  29. /*
  30.     Messages a mouse handler receives when its window is current
  31.     MEV_REQUEST            someone else wants to be it
  32.     MEV_STARTEVENT        current, mouse entered
  33.     MEV_EVENT            current, event in win
  34.     MEV_ENDEVENT        current, mouse left
  35.     Messages a mouse handler receives when its window is not current
  36.     MEV_STARTOFFER        not current, mouse entered
  37.     MEV_OFFER            not current, event in win
  38.     MEV_ENDOFFER        not current, mouse left
  39. */
  40. {
  41.     int ret;
  42.  
  43.     switch (msg) {
  44.     case MEV_STARTCUR:
  45.         /* Trap all mouse events while we're current */
  46.         disp_TrapMouse(win);
  47.         break;
  48.  
  49.     case MEV_STOPCUR:
  50.         break;
  51.  
  52.     case MEV_STARTOFFER:
  53.     case MEV_OFFER:
  54.     case MEV_ENDOFFER:
  55.         /* Only respond to offers if trapping is on */
  56.         if (disp_IsTrappedMouse()) {
  57.             /* If the event is inside our window or border do the normal thing;
  58.                 otherwise bail out of the window */
  59.             if ((ret = winmev_greedyclip(win, mev)) == MOU_HERE) {
  60.                 return(winmou_Track(win, msg, mev));
  61.             }
  62.             else {
  63.                 /* Event is not in our win, but trapping is on, so one of our
  64.                     children must be current; the standard response for a click
  65.                     outside is to exit the child and ourselves */
  66.                 /* Mouse was outside the window; don't accept the offer, but
  67.                     if the mouse was clicked return MOU_THERE so that
  68.                     the popup will be removed */
  69.                 mev_ClearEvent(mev);
  70.                 return(ret);
  71.             }
  72.         }
  73.         mev_ClearEvent(mev);
  74.         break;
  75.         
  76.     case MEV_REQUEST:    /* we're the current window so trapping must be on */
  77.         return(winmou_Track(win, msg, mev));
  78.  
  79.     case MEV_STARTEVENT:
  80.         win_SetDebounced(win, mev_IsButtonDown(mev));
  81.         /* no break, fall through */
  82.     case MEV_EVENT:        /* we're the current window so trapping must be on */
  83.     case MEV_ENDEVENT:
  84.  
  85.         /* If the event is inside our window or border do the normal thing;
  86.             otherwise bail out of the window */
  87.         if ((ret = winmev_greedyclip(win, mev)) == MOU_HERE) {
  88.             return(winmou_Track(win, msg, mev));
  89.         }
  90.         else {     /* Otherwise exit if button is clicked */
  91.             return(ret);
  92.         }
  93.     }
  94.     return(MOU_IGNORE);        /* Ignore this mouse event */
  95. }
  96. /* -------------------------------------------------------------------------- */
  97.  
  98. static int winmev_greedyclip(win_type win, mev_struct *mev)
  99. {
  100.     opbox bbox;
  101.  
  102.     /* If the event is inside our window or border, return MOU_HERE. */
  103.     bord_GetPixBox(win, &bbox);
  104.     if (mev_GetX(mev) >= bbox.xmin && mev_GetY(mev) >= bbox.ymin &&
  105.         mev_GetX(mev) <  bbox.xmax && mev_GetY(mev) <  bbox.ymax) {
  106.  
  107.         return(MOU_HERE);
  108.     }
  109.     else {     /* Otherwise exit if button is clicked */
  110.         if (!mev_IsButtonDown(mev)) {
  111.             win_SetDebounced(win, FALSE);
  112.         }
  113.         else {
  114.             if (!win_GetDebounced(win)) {
  115.                 win_SetDebounced(win, TRUE);
  116.  
  117.                 /* Mouse has been clicked outside the window; return
  118.                    MOU_THERE so that the popup can be removed */
  119.                 return(MOU_THERE);
  120.             }
  121.         }
  122.     }
  123.     return(MOU_IGNORE);
  124. }
  125. /* -------------------------------------------------------------------------- */
  126.  
  127.