home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / CUTPASTE.PRG < prev    next >
Encoding:
Text File  |  1991-04-23  |  6.1 KB  |  186 lines

  1. /*
  2.     Function: CutNPaste()
  3.     System: GRUMPFISH LIBRARY
  4.     Author: Greg Lief
  5.     Copyright (c) 1988-90, Greg Lief
  6.     Clipper 5.x Version
  7.     Compile instructions: clipper cutpaste /n/w/a
  8.  
  9.     Allows user to cut-and-paste from underlying screen into the
  10.     Grumpfish notepad (POPNOTE)
  11.  
  12.     Syntax: CutNPaste(@<screen> [, <hicolor>, <locolor>] ;
  13.                                 [, <top>, <left>, <bottom>, <right> ;
  14.                                 [, <row>, <column>]])
  15.  
  16.     Parameters: <screen> is a character string representing the name
  17.                 of the previously saved underlying screen from which
  18.                 to cut and paste.  For performance considerations,
  19.                 you must pass this by reference (i.e., do not surround
  20.                 it with quotes and DO precede it with "@")
  21.  
  22.                 Optional parameter <hicolor> is a numeric representing
  23.                 which color to use for highlighting.  The default is
  24.                 112 (inverse, or black on white).
  25.  
  26.                 Optional parameter <locolor> is a numeric representing
  27.                 which color to use for the underlying screen.  The
  28.                 default is 7 (white on black).
  29.  
  30.                 Optional parameters <top>, <left>, <bottom>, and <right>
  31.                 are numerics which delimit the screen area that can be
  32.                 accessed.
  33.  
  34.                 Optional parameters <row> and <column> are numerics
  35.                 indicating initial placement of the cursor on the screen.
  36.                 NOTE: if these two parameters are passed, highlighting will
  37.                 begin IMMEDIATELY (rather than the user having to position
  38.                 the cursor).
  39.  
  40.     Methodology notes: this routine is used either to cut-and-paste from
  41.                        an original underlying screen, or to highlight a
  42.                        section on the current screen.  Therefore, you will
  43.                        either pass the screen variable, or the four
  44.                        coordinates, but not both!!!!  (i.e., if you pass
  45.                        the coordinates, just pass a null string as the
  46.                        screen -- example: CutNPaste('', 0, 0, 24, 79)
  47.  
  48.     Returns: A character string suitable for KEYBOARDing into a memo field
  49.  
  50.     Calls: GFATTR()     (Assembler function in GRUMPATT.ASM)
  51.  
  52. */
  53.  
  54. //───── begin preprocessor directives
  55.  
  56. #include "grump.ch"
  57. #include "inkey.ch"
  58.  
  59. //───── end preprocessor directives
  60.  
  61.  
  62. function cutnpaste(origscrn, hicolor, locolor, ntop, nleft, ;
  63.                    nbottom, nright, mrow, mcol)
  64. local oldscrn, t_anchor, l_anchor, b_anchor, r_anchor, key := 0, ;
  65.       xx, yy, shading, cutbuff, row_len, buffer
  66.  
  67. //───── establish colors if not passed as parameters
  68. default hicolor to 112
  69. default locolor to 7
  70.  
  71. //───── establish box coordinates if not passed as parameters
  72. default ntop to 0
  73. default nleft to 0
  74. default nbottom to maxrow()
  75. default nright to maxcol()
  76.  
  77. //───── establish initial screen location, anchor variables, and whether or not
  78. //───── to begin highlighting immediately
  79. if pcount() < 8
  80.    shading := .f.   // flag to indicate whether we are highlighting or not
  81.    t_anchor := b_anchor := mrow := ntop
  82.    l_anchor := r_anchor := mcol := nleft
  83. else
  84.    t_anchor := b_anchor := mrow
  85.    l_anchor := r_anchor := mcol
  86.    shading := .t.   // start highlighting immediately
  87. endif
  88. oldscrn := savescreen(ntop, nleft, nbottom, nright)
  89.  
  90. //───── if the original screen parameter was passed, user restore the original
  91. //───── underlying screen and then make it all the same color (white on black)
  92. if pcount() = 1
  93.    restscreen(0, 0, maxrow(), maxcol(), origscrn)
  94.    gfattr(0, 0, maxrow(), maxcol(), locolor)
  95. endif
  96.  
  97. cutbuff := []    && this will hold the buffer to be returned back
  98. do while .t.
  99.    if shading
  100.       gfattr(t_anchor, l_anchor, b_anchor, r_anchor, hicolor)
  101.    endif
  102.    devpos(mrow, mcol)
  103.    key := ginkey(0)
  104.    do case
  105.       case key == K_DOWN .and. mrow < nbottom
  106.          if shading
  107.             if mrow < b_anchor
  108.                gfattr(mrow, l_anchor, mrow, r_anchor, locolor)
  109.                t_anchor := ++mrow
  110.             else
  111.                b_anchor := ++mrow
  112.             endif
  113.          else
  114.             mrow++
  115.          endif
  116.  
  117.       case key == K_UP .and. mrow > ntop
  118.          if shading
  119.             if mrow > t_anchor
  120.                gfattr(mrow, l_anchor, mrow, r_anchor, locolor)
  121.                b_anchor := --mrow
  122.             else
  123.                t_anchor := --mrow
  124.             endif
  125.          else
  126.             mrow--
  127.          endif
  128.  
  129.       case key == K_RIGHT .and. mcol < nright
  130.          if shading
  131.             if mcol < r_anchor
  132.                gfattr(t_anchor, mcol, b_anchor, mcol, locolor)
  133.                l_anchor := ++mcol
  134.             else
  135.                r_anchor := ++mcol
  136.             endif
  137.          else
  138.             mcol++
  139.          endif
  140.  
  141.       case key == K_LEFT .and. mcol > nleft
  142.          if shading
  143.             if mcol > l_anchor
  144.                gfattr(t_anchor, mcol, b_anchor, mcol, locolor)
  145.                r_anchor := --mcol
  146.             else
  147.                l_anchor := --mcol
  148.             endif
  149.          else
  150.             mcol--
  151.          endif
  152.  
  153.       case key == K_ENTER
  154.          if ! shading
  155.             shading := .t.
  156.             t_anchor := b_anchor := mrow
  157.             l_anchor := r_anchor := mcol
  158.          else
  159.             exit
  160.          endif
  161.  
  162.       case key == K_ESC
  163.          exit
  164.  
  165.    endcase
  166. enddo
  167. if key == K_ENTER
  168.    //───── now to parse out all the color attributes
  169.    buffer := savescreen(t_anchor, l_anchor, b_anchor, r_anchor)
  170.    //───── determine width of one row so that we can stick in cr/lf
  171.    row_len := (r_anchor - l_anchor + 1) * 2
  172.    for xx = 1 to (b_anchor - t_anchor + 1)
  173.       for yy = 1 to row_len step 2
  174.          cutbuff += substr(buffer, (xx - 1) * row_len + yy, 1)
  175.       next
  176.       cutbuff += CRLF
  177.    next
  178. endif
  179. restscreen(ntop, nleft, nbottom, nright, oldscrn)
  180. return cutbuff
  181.  
  182. * end function CutNPaste()
  183. *--------------------------------------------------------------------*
  184.  
  185. *eof cutpaste.prg
  186.