home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wlink.c < prev    next >
C/C++ Source or Header  |  1991-03-17  |  3KB  |  156 lines

  1. /* wunlink(), wlink()
  2.  *    unlink the current window from the chain of windows.
  3.  *        the image of the window is saved (pointer winsave).
  4.  *        the screen is not changed.
  5.  *      this function is used just before changing modes
  6.  *               or just before wcloseall
  7.  *    allows subsequent wlink to re-establish this window
  8.  *          when you come back to the window's mode.
  9.  *
  10.  *        RETURNS: pointer to the window if successful, NULL if error
  11.  *
  12.  *
  13.  *    wlink opens the specified window, restores its image to the screen
  14.  *        parameter = window pointer obtained by wunlink ()
  15.  *        RETURNS: 0 if successful, -1 on error .
  16.  *
  17.  *    do NOT place a text-mode window on a graphics mode screen
  18.  *        or vice-versa.
  19.  *
  20.  *    example:     winit ('T');
  21.  *                      wopen (... );
  22.  *            wputs ("A bunch of stuff...);
  23.  *            my_textw0indow = wunlink ();
  24.  *            init ('G');
  25.  *                do graphics things...
  26.  *            winit ('T');
  27.  *            wlink ( my_textw0indow );
  28.  *
  29.  *
  30.  */
  31. #include "wsys.h"
  32.  
  33.  
  34.  
  35. /* local function to define a blank window that sits on top of
  36.  * affected area of screen
  37.  */
  38. static void overlay ( void );
  39.  
  40.  
  41. WINDOW     *wunlink (void)
  42.  
  43.     {
  44.  
  45.     WINDOW *oldw;
  46.     WHEAP  *olds;
  47.  
  48.  
  49.  
  50.  
  51.     /* cannot unlink the only window or the fullscreen window
  52.      */
  53.     if ( w0-> winchain == NULL || w0 == wfullscreen )
  54.         {
  55.         return (NULL);
  56.         }
  57.  
  58.  
  59.     oldw = w0;
  60.     olds = w0->winsave;
  61.  
  62.  
  63.     /* place a new window on top of the current window
  64.      * the save area of the new window will have the contents of
  65.      * the current values of the current window
  66.      */
  67.     overlay ();
  68.  
  69.  
  70.     /* swap the save area pointers
  71.      * and close the old window ( will restore screen if needed )
  72.      */
  73.  
  74.     oldw->winsave = w0 -> winsave;    /* contents of window to unlink */
  75.     w0  ->winsave = olds;        /* screen prior to window */
  76.  
  77.     wclose();
  78.  
  79.     w0 = w0-> winchain;         /* unlink */
  80.  
  81.     return (oldw);
  82.  
  83.     }
  84.  
  85.  
  86.  
  87.  
  88. void    wlink (WINDOW  *neww)
  89.  
  90.     {
  91.     WHEAP *news;
  92.  
  93.  
  94.     /* always place new window in current page */
  95.     neww-> winpage = w0->winpage;
  96.  
  97.     news = neww-> winsave;
  98.  
  99.  
  100.  
  101.     neww-> winchain = w0;    /* link into chain */
  102.     w0 = neww;
  103.  
  104.  
  105.  
  106.     overlay ();
  107.  
  108.     /* swap save area pointers and restore
  109.      * screen to show new window contents
  110.      */
  111.     neww-> winsave = w0-> winsave;
  112.     w0->winsave = news;
  113.  
  114.  
  115.  
  116.     wclose();
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.     return;        /* wlink -- successful */
  124.     }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. /* overlay()
  133.  * static fucntion to create a dummy window
  134.  * in the screen area of the window of interest.
  135.  */
  136. static void overlay (void)
  137.     {
  138.     int r, l, t, b, extra, extra2;
  139.  
  140.  
  141.     extra  =  ( w0->winbox ) ? 1: 0;
  142.     extra2 = 2*extra;
  143.  
  144.     l = w0-> winleft    - extra;
  145.     t = w0-> wintop     - extra;
  146.     r = w0->winxmax + extra2;
  147.     b = w0->winymax + extra2;
  148.  
  149.     wopen ( l, t, r, b, 0x07, NO_BORDER, 0x07, WSAVE2RAM );
  150.  
  151.     return;    /* overlay */
  152.     }
  153.  
  154.  
  155.  
  156. /*------------------ WLINK.C -------------------------*/