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

  1. /*! wdefine
  2.  *
  3.  *
  4.  *  open a window, save previous contents, draw borders
  5.  *
  6.  *
  7.  *
  8.  */
  9. #include  "wscreen.h"
  10. #include  "wsys.h"
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. WINDOW *wdefine (int x, int y,  int xmax,  int ymax,
  18.         unsigned char color, int boxtype, unsigned char box_color )
  19.     {
  20.     WINDOW     *Wnew;
  21.     int     extra;                /* extra lines for borders */
  22.     int     priorpage, priorcursor;        /*last winodw's state */
  23.  
  24.     int     xend, yend;
  25.  
  26.  
  27.     extra = boxtype ? 1 : 0;
  28.  
  29.  
  30.  
  31.  
  32.     /* note coords start counting at 0
  33.      * so adding number of columns would be off by 1
  34.      * ie, winxmax=9 for a 10 column wide window
  35.      */
  36.     --xmax;
  37.     --ymax;
  38.  
  39.  
  40.     xend =  x + xmax;            /* right, bottom */
  41.     yend =  y + ymax;
  42.  
  43.  
  44.  
  45.  
  46.     /* validate input paramters */
  47.     if   ( (x           < extra)
  48.         || (y           < extra)
  49.         || (xend +extra > wxabsmax)
  50.         || (yend +extra > wyabsmax)
  51.          )
  52.         {
  53.         werror ('W', "window out of bounds");
  54.         }
  55.  
  56.  
  57.  
  58.  
  59.     /* save page number of current (=old) window
  60.      * and, if graphics mode, save BGI info about graphics position.
  61.      */
  62.  
  63.     if ( w0 != NULL )
  64.         {
  65.         priorpage = w0->winpage;
  66.         priorcursor = w0->winflag & WFL_CURSOR;
  67.  
  68.         #ifndef TEXTONLY
  69.                         /* get the graphics driver current position
  70.                          * in the old window.
  71.                          */
  72.             wherepxpy();
  73.  
  74.         #endif /* ! TEXTONLY */
  75.  
  76.         }
  77.     else    {
  78.         /* first call - no old window exists */
  79.         priorpage  = 0;
  80.         priorcursor= 1;
  81.         }
  82.  
  83.     /* construct linked list of window save areas
  84.      *
  85.      */
  86.     Wnew = (WINDOW *) wmalloc (sizeof( WINDOW ), "wopen");
  87.  
  88.  
  89.     /* make the new area the active window
  90.      */
  91.     Wnew-> winchain = w0;
  92.     w0 = Wnew;
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.     /* initialize new window data
  101.      */
  102.     w0-> winsave = NULL;
  103.     w0-> winbutton = NULL;
  104.  
  105.     w0-> winleft        = x;
  106.     w0-> winxmax         = xmax;
  107.     w0-> wintop         = y;
  108.     w0-> winymax         = ymax;
  109.  
  110.     w0-> winx = w0-> winy    = 0;
  111.  
  112.     w0-> winbox      = boxtype;
  113.     w0-> winboxcolor = box_color;
  114.     w0-> winattr     = color;
  115.  
  116.     /* set default putstyle for new window
  117.      * ie, turn on everything except cursor
  118.      */
  119.     w0->winflag     = 0;        /* cursor */
  120.     w0->winputstyle = 0xff;
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.     /* setup new page # if requested
  128.      */
  129.  
  130.  
  131.     if ( priorpage != wnextpage )
  132.         {
  133.         /* validate the page #, compute new display RAM addr,
  134.          * interface with graphics package.
  135.          *
  136.          */
  137.         if ( wnextpage <0 )
  138.             {
  139.             /* too low, use page 0 */
  140.             wnextpage = 0;
  141.             }
  142.         else
  143.         if ( wnextpage > wlastpage )
  144.             {
  145.             /* too high, use highest valid number */
  146.             wnextpage = wlastpage;
  147.             }
  148.  
  149.         wpage_ram = wvideo_ram + wpage_size*wnextpage;
  150.  
  151.  
  152.         }    /* end of changing displayed page */
  153.  
  154.     w0->winpage = wnextpage;
  155.  
  156.  
  157.  
  158.     #ifdef TEXTONLY
  159.         if (priorcursor)
  160.             {
  161.             wcursor (OFF);
  162.             }
  163.     #else
  164.         /* Set the graphics driver viewport to match the open window
  165.          */
  166.                 if (wmode == 'G' )
  167.                           {
  168.                   walign (priorpage);
  169.               }
  170.         else      {
  171.               /* mode = T */
  172.               if (priorcursor)
  173.                 {
  174.                 wcursor (OFF);
  175.                 }
  176.                           }
  177.     #endif    /* ! TEXTONLY */
  178.  
  179.     return (w0);        /* wdefine */
  180.     }
  181.  
  182.