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

  1.  
  2. /*! wrelocate()
  3.  *    move a window to a new location
  4.  *    the window must have been created with WSAVE2RAM.
  5.  *
  6.  *    RETURNS: 0 if successful
  7.  *        -1 if failure. Can fail because:
  8.  *            wndow was openned with WSAVE2NULL - cannot restore
  9.  *            new address out of bounds
  10.  *            not enough memory to save images of screen
  11.  *
  12.  */
  13. #include "wsys.h"
  14.  
  15.  
  16.  
  17. int wrelocate (int x, int y)
  18.     {
  19.     WHEAP *background, *contents;
  20.  
  21.     int borderwidth;        /* size of border   */
  22.     int ht, wt;        /* height and width */
  23.  
  24.     borderwidth = w0-> winbox  ?  2 : 0;
  25.  
  26.     if (    w0-> winsave == NULL
  27.        )
  28.         {
  29.         /* can't move a window without a save area
  30.          */
  31.         return (-1);
  32.         }
  33.     ht = w0->winymax  +borderwidth;
  34.     wt = w0->winxmax  +borderwidth;
  35.  
  36.     /* check that new position is inside screen bounds
  37.      */
  38.     if ( x < borderwidth )  x = borderwidth;
  39.     if ( y < borderwidth )  y = borderwidth;
  40.     if ( x+ wt  > wxabsmax )
  41.         {
  42.         x = wxabsmax - wt -1;
  43.         }
  44.     if ( y+ ht > wyabsmax )
  45.         {
  46.         y = wyabsmax - ht -1;
  47.         }
  48.  
  49.     background = w0->winsave;    /* underlying screen data */
  50.     w0->winsave = NULL;        /* prevent wsave from re-using */
  51.  
  52.     /* save current window contents
  53.      */
  54.     wsave();
  55.     contents = w0-> winsave;
  56.     if ( !contents )
  57.         {
  58.         /* not enough memory to perform move */
  59.         return (-1);
  60.         }
  61.  
  62.  
  63.     /* restore old background
  64.      */
  65.     w0->winsave = background;
  66.     wrestore ();
  67.     wheap_free (background);    /* release far memory */
  68.     w0-> winsave = NULL;
  69.  
  70.  
  71.     /* move window
  72.      */
  73.     w0->winleft =x;
  74.     w0->wintop  =y;
  75.  
  76.     /* save background in new screen area
  77.      */
  78.     wsave();
  79.     background = w0->winsave;
  80.     if ( ! background )
  81.         {
  82.         /* same amount of memeory that was freed last time
  83.          */
  84.         werror ('W', "WRELOCATE-internal");
  85.         }
  86.  
  87.     /* now put window image to screen
  88.      */
  89.     w0->winsave = contents;
  90.     wrestore ();
  91.     wheap_free (contents);
  92.  
  93.     w0->winsave = background;
  94.  
  95.     return (0);    /* wrelocate - successful */
  96.     }
  97.  
  98.  
  99.  
  100.  
  101.