home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP12.EXE / CHP1207.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  3.4 KB  |  125 lines

  1. /*
  2.    Listing 12.7. An improved version of SaveEnv() that can assign cursor
  3.                  and color settings and save a specified region of the screen
  4.    Listing 12.8. An improved version of RestEnv() that allows for a
  5.                  region to be restored instead of the entire screen.
  6.    Author: Greg Lief / Craig Yellick
  7.    Excerpted from "Clipper 5: A Developer's Guide"
  8.    Copyright (c) 1991 M&T Books
  9.                       501 Galveston Drive
  10.                       Redwood City, CA 94063-4728
  11.                       (415) 366-3600
  12. */
  13.  
  14.  
  15. *** NOTE: Function requires SaveEnv() to be in same file to share
  16. ***       the ENVSTACK_ static variable.
  17. memvar envstack_
  18.  
  19. //  Manifest constants used by SaveEnv() and RestEnv().
  20. #define TOP      coords[1]
  21. #define LEFT     coords[2]
  22. #define BOTTOM   coords[3]
  23. #define RIGHT    coords[4]
  24. #define NTOP     envstack_[ele, SCREEN][1]
  25. #define NLEFT    envstack_[ele, SCREEN][2]
  26. #define NBOTTOM  envstack_[ele, SCREEN][3]
  27. #define NRIGHT   envstack_[ele, SCREEN][4]
  28. #define NSCREEN  envstack_[ele, SCREEN][5]
  29.  
  30. #define ROW     1
  31. #define COLUMN  2
  32. #define CURSOR  3
  33. #define COLOR   4
  34. #define SCREEN  5
  35.  
  36. function SaveEnv(scrn_save, curs_size, newcolor)
  37. /*
  38.    Save cursor row/column/size, color, and screen.
  39.  
  40.    Syntax: SaveEnv( <coords>, <cursorsize>, <color> )
  41.            All parameters are optional
  42.  
  43.    Parameters:
  44.      <coords> can be one of three things:
  45.         Nil -- do not save the screen.
  46.         Array -- four numeric expressions representing
  47.                  the screen coordinates to be saved.
  48.         Other -- save the entire screen.
  49.  
  50.      <cursorsize> is a numeric representing the new cursor
  51.        size to use.  If not passed, the cursor size will
  52.        be left unchanged. Refer to SETCURS.CH for the
  53.        appropriate definitions. Use a comma if you want
  54.        to skip this parameter.
  55.  
  56.      <color> is a character string representing the new color
  57.        setting to use. If not passed, the color will be left
  58.        unchanged.
  59.  
  60.     Examples:
  61.     ---------
  62.  
  63.     #include "setcurs.ch"
  64.  
  65.     //  Do not save screen, turn off cursor,
  66.     //  change color to W/B.
  67.     SaveEnv(, SC_NONE, 'w/b')
  68.  
  69.     //  Save full screen, don't change cursor,
  70.     //  change color to R/W.
  71.     SaveEnv(.t., , 'r/w')
  72.  
  73.     //  Save screen buffer between coordinates 10,10 and 4,69,
  74.     //  turn off cursor, leave color unchanged.
  75.     SaveEnv( { 10, 10, 14, 69 }, SC_NONE)
  76. */
  77.  
  78. local coords := ;
  79.        if(scrn_save = NIL .or. valtype(scrn_save) =="A", ;
  80.           scrn_save, { 0, 0, maxrow(), maxcol() } )
  81.  
  82. aadd(envstack_, ;
  83.       { row(), col(), ;
  84.        setcursor(curs_size), setcolor(newcolor), ;
  85.        if(valtype(coords) = "A", { TOP, LEFT, BOTTOM, RIGHT, ;
  86.            savescreen(TOP, LEFT, BOTTOM, RIGHT) }, ;
  87.          NIL) ;
  88.       })
  89.  
  90. return nil
  91.  
  92. * eof
  93.  
  94. function RestEnv()
  95. /*
  96.    Restore cursor row/column/size, color, and screen.
  97. */
  98.  
  99. local ele := len(envstack_)
  100.  
  101. //  Avoid an empty array.
  102. if ele > 0
  103.  
  104.    //  Restore row/column position.
  105.    setpos(envstack_[ele, ROW], envstack_[ele, COLUMN])
  106.  
  107.    //  Reset cursor state.
  108.    setcursor(envstack_[ele, CURSOR])
  109.  
  110.    //  Restore color.
  111.    setcolor(envstack_[ele, COLOR])
  112.  
  113.    //  Restore screen if it was saved.
  114.    if envstack_[ele, SCREEN] != NIL
  115.       restscreen(NTOP, NLEFT, NBOTTOM, NRIGHT, NSCREEN)
  116.    endif
  117.  
  118.    //  Truncate the array
  119.    asize(envstack_, len(envstack_) - 1)
  120. endif
  121.  
  122. return nil
  123.  
  124. // end of file CHP1207.PRG
  125.