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

  1. /*! wabandon.c
  2.  *
  3.  *
  4.  *        release window storage for current window,
  5.  *      unlink current window from linked list of windows,
  6.  *    make sure at least one window remains open.
  7.  *
  8.  *
  9.  */
  10.  
  11. #include  "wscreen.h"
  12. #include  "wsys.h"
  13.  
  14.  
  15.  
  16. static void rectify (int);
  17.  
  18.  
  19.  
  20. void wabandon(void) {
  21.  
  22.     WINDOW *p;
  23.  
  24.     int oldpage;
  25.  
  26.     WBUTTON *btn, *next_button;
  27.  
  28.  
  29.  
  30.  
  31.     /* free image storage area.
  32.      */
  33.     if ( w0-> winsave )
  34.         {
  35.         wheap_free (w0-> winsave);
  36.         w0->winsave = NULL;
  37.         }
  38.  
  39.  
  40.  
  41.     /* save page # of current window
  42.      *     can't reference next page if this is the last window.
  43.      */
  44.     oldpage = w0->    winpage;
  45.  
  46.  
  47.  
  48.     /* release any allocated button memory
  49.      */
  50.     for ( btn = w0-> winbutton;   btn != NULL;  btn = next_button)
  51.         {
  52.         next_button = btn->Bchain;
  53.         free (btn);
  54.         }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.     /* Now either bury the fullscreen window at the bottom of the stack
  61.      *     or close the indicated window
  62.      */
  63.     if ( w0 == wfullscreen )
  64.         {
  65.         /* this is the fullscreen window - never shut it
  66.          */
  67.         wbury  ();
  68.         }
  69.     else
  70.         {
  71.  
  72.         /* Remove old window from chain, release window memory
  73.          */
  74.          p = w0;          /*p points to the current window */
  75.         w0 = (p-> winchain);
  76.         free(p);         /* release the (old) closed window */
  77.  
  78.         /* w0 now points to previous window, old one is gone
  79.          */
  80.         rectify( oldpage );
  81.         }
  82.     return; /* wabandon */
  83.     }
  84.  
  85.  
  86.  
  87.  
  88. /* wbury ()
  89.  *    take the indicated window and place it on bottom of chain
  90.  *      screen is not changed.
  91.  *
  92.  */
  93. void wbury (void)
  94.     {
  95.     WINDOW *p;
  96.     int oldpage;
  97.  
  98.     oldpage = w0-> winpage;
  99.  
  100.     if ( (p= w0->winchain) == NULL )    /* look for next window down on list */
  101.         {
  102.         /* nothing to bury window under
  103.          */
  104.         return;
  105.         }
  106.  
  107.     while ( p->winchain )
  108.         {
  109.         p = p-> winchain;
  110.         }
  111.  
  112.     /* p now points to the bottom window in the chain
  113.      *    (the one with a NULL winchain ptr)
  114.      * set the chain ptr to the (old) open window
  115.      */
  116.     p-> winchain = w0;
  117.  
  118.     /* now use p to save the address of the window about to be promoted
  119.      */
  120.     p = w0-> winchain;
  121.     
  122.     
  123.     /* now set the chain ptr in the (old) open window to NULL
  124.      * to show it is the (oldest) window in the chain (nothing below)
  125.      */
  126.     w0-> winchain = NULL;
  127.     
  128.     /* now point w0 to the (new) top window on the chain
  129.      */
  130.     w0 = p;
  131.  
  132.     rectify ( oldpage );
  133.  
  134.     return;        /* wbury */
  135.     }
  136.  
  137.  
  138.  
  139.  
  140.  
  141. static void rectify ( int oldpage )
  142.     {
  143.     int newpage;
  144.  
  145.     newpage = w0->winpage;
  146.     if (oldpage != newpage)
  147.         {
  148.         wnextpage = newpage;
  149.         wpage_ram = wvideo_ram + wpage_size*newpage;
  150.         }
  151.  
  152.     #ifndef TEXTONLY
  153.         walign (oldpage);    /* align BGI graphics driver*/
  154.     #endif /*TEXTONLY */
  155.  
  156.     if (w0-> winflag  & WFL_CURSOR)        wcursor (ON);
  157.     else                     wcursor (OFF);
  158.  
  159.  
  160.     return;        /* rectify */
  161.     }
  162.     
  163.     /*------------------- end of WABANDON.C -----------------------*/