home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / WINOBSC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-31  |  4.5 KB  |  160 lines

  1. /*
  2.     winobsc.c    10/14/88
  3.  
  4.     % Window routines for determining who is obscuring who.
  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.     12/09/88 ted:    Added ddisp_Cache/Flush calls for mouse.
  14.     12/11/88 ted:    Added dhard_Claim/Release calls for reentrancy.
  15.      3/31/89 ted:    Added wmgr_PointWin.
  16.      4/25/89 ted    Added wmgr_FindBelow. Added check for employed in IsObscured.
  17.      5/11/89 ted    Added win parent clip check.
  18.      8/30/89 ted    Added shadow support to IsObscured and ParentClip.
  19.  
  20.     11/06/89 ted    Added win_TopChild function used in fixing nested paint bug.
  21.      3/28/90 jmd    ansi-fied
  22. */
  23.  
  24. #include "oakhead.h"
  25. #include "disppriv.h"
  26.  
  27. /* -------------------------------------------------------------------------- */
  28.  
  29. win_type wmgr_IsObscuredPixBox(win_type topwin, win_type win, opbox *boxp, boolean doshad)
  30. /*
  31.     Determines if the given box is covered by an employed window below topwin
  32.     and above win. If win is NULL, all windows below topwin are checked.
  33.     Returns uppermost obscuring window, or NULL if box is unobscured.
  34.     If 'doshad' is TRUE, returns uppermost window whose self or shadow
  35.     obscures the box.
  36. */
  37. {
  38.     opbox tbox;
  39.  
  40.     if (topwin != NULL) {
  41.         hard_Claim();            /* Here for re-entrancy protection */
  42.  
  43.         if (win_IsEmployed(topwin)) {
  44.             for(;;) {
  45.                 topwin = win_GetBelow(topwin);
  46.                 if (topwin == NULL || topwin == win) {
  47.                     break;
  48.                 }
  49.                 if (win_IsEmployed(topwin)) {
  50.                     if (win_ParentClip(topwin, &tbox, doshad)) {
  51.                         if(opbox_clipbox(boxp, &tbox)) {
  52.                         /* windows overlap */
  53.                             hard_Release();
  54.                             return(topwin);
  55.                         }
  56.                     }
  57.                 }
  58.             }
  59.         }
  60.         hard_Release();
  61.     }
  62.     return(NULL);
  63. }
  64. /* -------------------------------------------------------------------------- */
  65.  
  66. unsigned OWLPRIV win_ParentClip(win_type win, opbox *boxp, boolean doshad)
  67. /*
  68.     Fills the passed boxp with the coordinates of the given window's outer box
  69.     (plus the window's shadow if 'doshad' is TRUE),
  70.     clipped by the inner boxes of all the window's parent windows.
  71.     Return Sutherland clip code for box clipped: 0 if box is completely
  72.     clipped out; otherwise bits saying which side(s) it was clipped on:
  73.     1, 2, 4, 8 for right, top, left, bottom; 16 for coming through at all.
  74. */
  75. {
  76.     unsigned scode, rcode;
  77.     win_type parent;
  78.     opbox winbox;
  79.  
  80.     opbox_copy(boxp, win_pixboxp(win));
  81.     if (doshad) {
  82.         boxp->xmax += win_GetShadowX(win);
  83.         boxp->ymax += win_GetShadowY(win);
  84.     }
  85.     rcode = 16;
  86.     for (;;) {
  87.         parent = win_GetParent(win);
  88.         if (parent == NULL || !win_IsParentClip(win)) {
  89.             return(rcode);
  90.         }
  91.         win_getwinbox(parent, &winbox);
  92.         if ((scode = opbox_clipbox(&winbox, boxp)) == 0) {
  93.             return(0);
  94.         }
  95.         rcode |= scode;
  96.         win = parent;
  97.     }
  98. }
  99. /* -------------------------------------------------------------------------- */
  100.  
  101. win_type wmgr_PointWin(opcoord x, opcoord y)
  102. /*
  103.     Return the first employed window lying below the given point.
  104. */
  105. {
  106.     opbox cursbox;
  107.  
  108.     /* Find which window the mouse point falls in */
  109.     cursbox.xmin = x; cursbox.xmax = cursbox.xmin + 1;
  110.     cursbox.ymin = y; cursbox.ymax = cursbox.ymin + 1;
  111.  
  112.     return(wmgr_IsObscuredPixBox(wmgr_employedhead(), NULL, &cursbox, FALSE));
  113. }
  114. /* -------------------------------------------------------------------------- */
  115.  
  116. win_type wmgr_FindBelow(win_type win)
  117. /*
  118.     Return the first employed window lying below the upper left corner of the
  119.     given window.
  120. */
  121. {
  122.     win_type bwin;
  123.  
  124.     if (win_IsEmployed(win)) {
  125.         win_setemployed(win, FALSE);
  126.         bwin = wmgr_PointWin(win_GetXmin(win), win_GetYmin(win));
  127.         win_setemployed(win, TRUE);
  128.         return(bwin);
  129.     }
  130.     else return(NULL);
  131. }
  132. /* -------------------------------------------------------------------------- */
  133.  
  134. win_type OWLPRIV win_TopChild(win_type win)
  135. /*
  136.     Returns the topmost employed child window of the given window.
  137.     If no child is found above the window, the window itself is returned.
  138.     If the window is not in the employed list itself, NULL is returned.
  139. */
  140. {
  141.     win_type currwin, parent;
  142.  
  143.     /* For all windows from top down, */
  144.     /*  starting with the top eligible window */
  145.     for (currwin = win_GetBelow(wmgr_botsyswin()); currwin != NULL;
  146.          currwin = win_GetBelow(currwin)) {
  147.  
  148.         /* For all (grand)parents of the current win, check if they are the win */
  149.         for (parent = currwin; parent != NULL;
  150.              parent = win_GetParent(parent)) {
  151.             if (parent == win) {
  152.                 return(currwin);
  153.             }
  154.         }
  155.     }    
  156.     return(NULL);
  157. }
  158. /* -------------------------------------------------------------------------- */
  159.  
  160.