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

  1.  
  2. /*! wlocate ()
  3.  *
  4.  *      assistance in locating a new window.
  5.  *    can locate window at a specified x,y offset from a specified point.
  6.  *
  7.  *    specification is made in the global variable struct wlocation
  8.  *    can specify offsets from any on of:
  9.  *             center of screen (default)    WLOC_CENTER
  10.  *             top left of screen            WLOC_ATXY
  11.  *               top left of current window    WLOC_ATWIN
  12.  *              current cursor position       WLOC_ATCUR
  13.  *    can specify x,y offsets which may be positive or negative.
  14.  *    if location places any edge of window out of screen,
  15.  *          location is adjusted as needed.
  16.  *      After each call, the wlocation structure is reset to CENTER fo screen.
  17.  *
  18.  *    PARAMETERS:
  19.  *        aleft, atop = pointers to unsinged char
  20.  *                which will contain the new location
  21.  *        xmax, ymax  = size of desired window.
  22.  */
  23. #include "wsys.h"
  24.  
  25.  
  26.  
  27. void wlocate ( int *aleft, int *atop, int xmax, int ymax )
  28.     {
  29.     int x, y;
  30.     register int leftmost, topmost;
  31.  
  32.     switch ( wlocation.wloc_type )
  33.         {
  34.     case ( WLOC_ATXY ):
  35.         x = y = 0;
  36.         break;
  37.     case ( WLOC_ATWIN ):
  38.         x = w0-> winleft;
  39.         y = w0-> wintop;
  40.         break;
  41.     case ( WLOC_ATCUR ):
  42.         x = w0-> winleft + w0->winx;
  43.         y = w0-> wintop +  w0->winy;
  44.         break;
  45.     default:
  46.         /* the default is WLOC_CENTER = center of screen */
  47.         x = ( wxabsmax - xmax )/2;
  48.         y = ( wyabsmax - ymax )/2;
  49.         break;
  50.  
  51.         }    /* end swtich */
  52.  
  53.     x += wlocation.wloc_x +1;
  54.     y += wlocation.wloc_y +1;
  55.  
  56.  
  57.     /* check window to make sure it fits in screen
  58.      * allow room for borders
  59.      */
  60.     if ( x<1 ) x =1;
  61.     if ( y<1 ) y =1;
  62.  
  63.     leftmost = wxabsmax - xmax -3;
  64.     x = min (x,leftmost);
  65.  
  66.     topmost = wyabsmax - ymax -3;
  67.     y = min (y, topmost);
  68.  
  69.     *aleft = x;
  70.     *atop  = y;
  71.  
  72.  
  73.     /* reset wlocation so next call defaults to CENTER */
  74.     wlocation.wloc_type = wlocation.wloc_x = wlocation.wloc_y =0;
  75.  
  76.  
  77.     return;    /* wlocate */
  78.     }
  79.