home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume2 / window / part3 / wlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  3.5 KB  |  172 lines

  1. /*
  2.  *************
  3.  * DISTRIBUTION NOTICE  July 30 1985
  4.  * A Revised Edition of WM, by Matt Lennon and Tom Truscott,
  5.  *        Research Triangle Institute, (919) 541-7005.
  6.  * Based on the original by Robert Jacob (decvax!nrl-css!jacob),
  7.  *        Naval Research Laboratory, (202) 767-3365.
  8.  * No claims or warranties of any sort are made for this distribution.
  9.  * General permission is granted to copy, but not for profit,
  10.  * any of this distribution, provided that this notice
  11.  * is always included in the copies.
  12.  *************
  13.  */
  14. /*
  15.  * Code for rearranging window display order
  16.  */
  17.  
  18. #include "wm.h"
  19.  
  20.  
  21. /*
  22.  * Make window 'w' the new top window.
  23.  * Insert 'w' into window list (keeps track
  24.  * of redraw order).
  25.  * 'topw' (pointer to the top window) is set to 'w'.
  26.  * Recompute obscured window status.
  27.  */
  28. WListAdd(w)
  29.  
  30. register int w;
  31. {
  32.     register int wt;    /* temporary window pointer */
  33.  
  34.      /* Add w to empty list.
  35.       */
  36.     if (botw < 0)
  37.     botw=w;
  38.  
  39.      /* Add w to top of nonempty list.
  40.       */
  41.     else
  42.     {
  43.     for (wt=botw; win[wt].next>=0; wt=win[wt].next)
  44.         ;
  45.     win[wt].next=w;
  46.     }
  47.  
  48.  
  49.     win[w].next = -1;
  50.     topw = w;
  51.  
  52.     /* Recompute obscured window status */
  53.     WObscure();
  54. }
  55.  
  56. /*
  57.  * Delete window 'w'.
  58.  * Remove it from window list.
  59.  * Recompute obscured windows.
  60.  */
  61. WListDelete(w)
  62.  
  63. register int w;
  64. {
  65.     register int wt;    /* temporary window pointer */
  66.  
  67.     if ( ! iswindow(w))
  68.     return;
  69.  
  70.      /* Don't read from this window any more.
  71.       */
  72.     DisablePty(w);
  73.  
  74.      /* Delete w from list.
  75.       */
  76.     if (botw==w)
  77.     botw=win[botw].next;
  78.     else
  79.     {
  80.     for (wt=botw; wt>=0; wt=win[wt].next)
  81.         if (win[wt].next==w) break;
  82.     if (wt>=0)
  83.         win[wt].next=win[win[wt].next].next;
  84.     }
  85.  
  86.      /* Find new topw.
  87.       */
  88.     wt=botw;
  89.     while (wt>=0 && win[wt].next>=0)
  90.     wt=win[wt].next;
  91.     topw=wt;
  92.  
  93.     /* Recompute obscured window info */
  94.     WObscure();
  95. }
  96.  
  97. /*
  98.  * Recompute obscured ('blocked') and 'covers' information
  99.  * Enable/Disable ptys appropriately.
  100.  */
  101. WObscure()
  102. {
  103.     register int w, wt, i;
  104.  
  105.     for (w = botw; w >= 0; w = win[w].next) {
  106.     EnablePty(w);
  107.     win[w].flags &= ~BLOCKED;
  108.     for (i = 0; i < MAXWINDOWS; i++)
  109.         win[w].covers[i] = FALSE;
  110.     for (wt = botw; wt != w; wt = win[wt].next) {
  111.         if (!overlap(w, wt))
  112.         continue;
  113.         win[w].covers[wt] = TRUE;
  114.         win[wt].flags |= BLOCKED;
  115.         /* We could disable the obscured window's pty at this point,
  116.          * but we'll wait and do it in 'readptys()'.
  117.          */
  118.         /* (we should probably disable it now if it was previously) */
  119.     }
  120.     }
  121. }
  122.  
  123. /* Note: the arithmetic 'bottom' is actual the visual 'top'!
  124.  * Also, RIGHT and TOP are the index of the column (row) just past
  125.  * the index of the window's actual right (top).
  126.  */
  127. #define BOTTOM(wp)    (wbegy(wp))
  128. #define    TOP(wp)        (BOTTOM(wp)+wlines(wp))
  129. #define LEFT(wp)    (wbegx(wp))
  130. #define    RIGHT(wp)    (LEFT(wp)+wcols(wp))
  131.  
  132. /*
  133.  * Determine if two windows overlap.
  134.  * Windows must have at least a row (column) separating them
  135.  * to permit the border lines to be drawn.
  136.  */
  137. overlap(w1, w2)
  138.  
  139. int w1, w2;
  140. {
  141.     register WINDOW *wp1, *wp2;
  142.  
  143.     wp1 = win[w1].wptr;
  144.     wp2 = win[w2].wptr;
  145.     return(LEFT(wp1)   <= RIGHT(wp2)
  146.     && LEFT(wp2)   <= RIGHT(wp1)
  147.     && BOTTOM(wp1) <= TOP(wp2)
  148.     && BOTTOM(wp2) <= TOP(wp1));
  149. }
  150.  
  151. /*
  152.  * Returns 1 if a window (or its border) above w cover point (y,x),
  153.  * otherwise returns 0.
  154.  */
  155. covers(w, y, x)
  156. int w;
  157. register int y, x;
  158. {
  159.     register int wt;
  160.     register WINDOW *wp;
  161.  
  162.     for (wt = w; (wt = win[wt].next) >= 0;) {
  163.     wp = win[wt].wptr;
  164.     if (LEFT(wp)    <= x+1
  165.      && x        <= RIGHT(wp)
  166.      && BOTTOM(wp)    <= y+1
  167.      && y        <= TOP(wp))
  168.         return(1);
  169.     }
  170.     return(0);
  171. }
  172.