home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1991 / 04 / v_open.c < prev    next >
C/C++ Source or Header  |  1991-05-03  |  2KB  |  63 lines

  1. /*    v_open.c- Display Viewport */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <tools/viewport.h>
  7.  
  8. int v_open( viewport *v )
  9. {
  10.     /*  Open (save underlying text and clear underlying region) the viewport.
  11.      *  If clearok is enabled, area under viewport is filled with blanks
  12.      *  the first time the viewport is opened, the behavior of subsequent
  13.      *  calls depends on whether the viewport was closed or deactivated.
  14.      *  If closed and clearok is enabled, the area is filled with blanks.
  15.      *  If deactivated, the area is filled with the previous contents
  16.      *  (at deactivate time). Underlying is saved if saveok is enabled
  17.      *  and (1) this is a new or closed viewport or (2) this is a deactivated,
  18.      *  hidden viewport. The text isn't saved for deactivated, but visible
  19.      *  viewports. All the viewport-manipulation functions will open
  20.      *  the window implicitly if an explicit open hasn't been performed.
  21.      */
  22.  
  23.     if( v->magic != VMAGIC )
  24.         return 0;
  25.  
  26.     /* If the window is closed, then it doesn't exist on the screen. Save
  27.      * the underlying text and initialize if required. If it's inactive
  28.      * but not closed, then it still exists on the screen and a refresh
  29.      * is required.
  30.      */
  31.  
  32.     if( v->closed || v->inactive )
  33.     {
  34.         if( v->saveok && !v->savebuf )
  35.         {
  36.             if( !(v->savebuf = VMALLOC(v->nrows * v->ncols * sizeof(int))))
  37.                 return 0;
  38.  
  39.             _v_save_scr( v->savebuf, v->row, v->col, v->nrows, v->ncols );
  40.         }
  41.  
  42.         /* Initialize the viewport, either to the original image (before
  43.          * it was deactivated) or to blanks (if clearok is true). If neither
  44.          * condition is true, don't initialize. (I'm assuming that the
  45.          * application will then fill up the window.)
  46.          */
  47.  
  48.         if( v->inactive && v->old_image )
  49.         {
  50.             _v_restore_scr( v->old_image, v->row, v->col, v->nrows, v->ncols );
  51.             VFREE( v->old_image );
  52.             v->old_image = NULL;
  53.         }
  54.         else if( v->clearok )
  55.             v_clear( v );
  56.     }
  57.  
  58.     v->closed   = 0;
  59.     v->inactive = 0;
  60.     v_gotorc( v, v->cur_row, v->cur_col );
  61.     return 1;
  62. }
  63.