home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / clarion / library / memoed / me_block.cla < prev    next >
Text File  |  1992-02-15  |  10KB  |  289 lines

  1.  
  2. !═════════════════════════════════════════════════════════════════════════
  3. !
  4. !  %%keyword%% '%n'
  5. !  'ME_BLOCK.CLA' - Block Operations for MEMOEDIT
  6. !
  7. !  %%keyword%% '%v'
  8. !  Revision Number: '1'
  9. !  %%keyword%% '%d'
  10. !  Revision Date  : '15-Feb-92'
  11. !
  12. !  Copyright : Bobcat Systems (c) 1992
  13. !  Author    : Robert J. Pupazzoni
  14. !           CIS:[70441,204]
  15. !
  16. !  Compiler  : Clarion Professional Developer v. 2.1, Batch 2105
  17. !
  18. !
  19. !  DESCRIPTION
  20. !
  21. !    This module contains all functions related to block operations.
  22. !
  23. !═════════════════════════════════════════════════════════════════════════
  24.  
  25. ME_Block     MEMBER()
  26.  
  27. ! ═════════════════════════════════════════════════════════════════════════
  28. !           Copy Marked Text in Edit Buffer to Hold Area
  29. ! ═════════════════════════════════════════════════════════════════════════
  30. Copy_Hold    PROCEDURE( tHold, tTable )
  31.  
  32.          ! Parameters:
  33. tHold         EXTERNAL,TABLE             ! Hold area
  34. tTable         EXTERNAL,TABLE             ! Edit buffer
  35.  
  36.          ! Locals:
  37. ilIndex         LONG                 ! Loop index
  38.  
  39.   CODE
  40.   IF NOT MED:ilMarkBegRow THEN RETURN.         ! Quit if nothing is marked
  41.  
  42.   FREE(tHold)                     ! Clear Hold area
  43.  
  44.   GET(tTable, MED:ilMarkBegRow)             ! Get first marked line
  45.   IF MED:ilMarkBegRow = MED:ilMarkEndRow     ! If only one line marked
  46.     tHold = SUB(tTable, MED:ibMarkBegCol, MED:ibMarkEndCol-MED:ibMarkBegCol+1)
  47.   ELSE                         ! Else
  48.     tHold = SUB(tTable, MED:ibMarkBegCol, 255)     !   Get mark to EOL
  49.   .                         ! Endif
  50.   ADD(tHold)                     ! Copy to Hold area
  51.  
  52.                          ! Loop thru fully marked lines
  53.   LOOP ilIndex = MED:ilMarkBegRow+1 TO MED:ilMarkEndRow-1
  54.     GET(tTable, ilIndex)             !   Get line
  55.     tHold = tTable                 !   Copy to Hold area
  56.     ADD(tHold)                     !
  57.   .                         ! End loop
  58.  
  59.   IF MED:ilMarkBegRow <> MED:ilMarkEndRow     ! If more than one line marked
  60.     GET(tTable, MED:ilMarkEndRow)         !   Get last marked line
  61.     tHold = SUB(tTable, 1, MED:ibMarkEndCol)     !   Isolate marked section
  62.     ADD(tHold)                     !   Copy to Hold area
  63.   .                         ! Endif
  64.   RETURN                     !
  65.  
  66.  
  67. ! ═════════════════════════════════════════════════════════════════════════
  68. !         Paste Hold Area into Edit Buffer at Passed Position
  69. ! ═════════════════════════════════════════════════════════════════════════
  70. Paste_Hold   PROCEDURE( tHold, tTable, ilTblNdx, ibCol )
  71.  
  72.          ! Parameters:
  73. tHold         EXTERNAL,TABLE             ! Hold area
  74. tTable         EXTERNAL,TABLE             ! Edit buffer
  75. ilTblNdx     LONG                 ! Line index to paste into
  76. ibCol         BYTE                 ! Column to paste into
  77.  
  78.          ! Locals:
  79. sTemp         STRING(255)             ! Temporary line buffer
  80. ilHoldNdx    LONG                 ! Hold index
  81.  
  82.   CODE
  83.   IF RECORDS(tHold) = 0 THEN RETURN.         ! Return if Hold is empty
  84.  
  85.   GET(tHold, 1)                     ! Get first Hold line
  86.   GET(tTable, ilTblNdx)                 ! Get line from edit buffer
  87.   sTemp     = SUB(tTable, ibCol, 255)         ! Save trailing portion
  88.   tTable = SUB(tTable, 1, ibCol-1) & tHold     ! Insert Hold at paste column
  89.   PUT(tTable)                     ! Update edit buffer
  90.  
  91.   LOOP ilHoldNdx = 2 TO RECORDS(tHold)-1     ! Loop for subsequent lines
  92.     GET(tHold, ilHoldNdx)             !   Get Hold line
  93.     ilTblNdx += 1                 !   Paste into edit buffer
  94.     tTable = tHold                 !
  95.     ADD(tTable, ilTblNdx)             !
  96.   .                         ! End loop
  97.  
  98.   IF RECORDS(tHold) = 1                 ! If only one line in Hold
  99.     GET(tTable, ilTblNdx)             !   Get displayed line
  100.     tTable = CLIP(tTable) & sTemp         !   Join line and saved sect.
  101.     PUT(tTable)                     !   Update edit buffer
  102.   ELSE                         ! Else
  103.     GET(tHold, RECORDS(tHold))             !   Get last Hold line
  104.     ilTblNdx += 1                 !   Increment table index
  105.     tTable = CLIP(tHold) & sTemp         !   Join Hold and saved sect.
  106.     ADD(tTable, ilTblNdx)             !   Add to edit buffer
  107.   .                         ! End if
  108.   RETURN                     !
  109.  
  110.  
  111. ! ═════════════════════════════════════════════════════════════════════════
  112. !             Cut Currently Marked Block
  113. ! ═════════════════════════════════════════════════════════════════════════
  114. Cut_Block    PROCEDURE( tTable )
  115.  
  116.          ! Parameters:
  117. tTable         EXTERNAL,TABLE             ! Edit buffer
  118.  
  119.          ! Parameters:
  120. sTemp         STRING(255)             ! Temporary line buffer
  121. ilIndex         LONG                 ! Loop index
  122.  
  123.   CODE
  124.   GET(tTable, MED:ilMarkEndRow)             ! Get last marked line
  125.   sTemp = SUB(tTable, MED:ibMarkEndCol+1, 255)     ! Isolate unmarked section
  126.  
  127.   GET(tTable, MED:ilMarkBegRow)             ! Get first marked line
  128.                          ! Join unmarked sections
  129.   tTable = SUB(tTable, 1, MED:ibMarkBegCol-1) & sTemp
  130.   PUT(tTable)                     ! Update edit buffer
  131.  
  132.                          ! Loop for each marked row
  133.   LOOP ilIndex = MED:ilMarkBegRow+1 TO MED:ilMarkEndRow
  134.     GET(tTable, MED:ilMarkBegRow+1)         !   Get line
  135.     IF ERRORCODE() THEN CYCLE.             !   Ignore if not found
  136.     DELETE(tTable)                 !   Delete line
  137.   .                         ! End loop
  138.   RETURN                     !
  139.  
  140.  
  141. ! ═════════════════════════════════════════════════════════════════════════
  142. !            Toggle Block Marking Mode On/Off
  143. ! ═════════════════════════════════════════════════════════════════════════
  144. Block_Mark   PROCEDURE( ilTblNdx, ibCol )
  145.  
  146.          ! Parameters:
  147. ilTblNdx     LONG                 ! Line index
  148. ibCol         BYTE                 ! Cursor column
  149.  
  150.   CODE
  151.   IF NOT MED:bbMarking                 ! If not in marking mode
  152.     MED:ilMarkBegRow = ilTblNdx             !   Set block start
  153.     MED:ibMarkBegCol = ibCol             !
  154.     MED:ilMarkEndRow = MED:ilMarkBegRow         !   Set block end
  155.     MED:ibMarkEndCol = MED:ibMarkBegCol         !
  156.     MED:bbMarking = 1                 !   Turn marking mode on
  157.   ELSE                         ! Else
  158.     MED:bbMarking = 0                 !   Turn marking mode off
  159.   .                         ! Endif
  160.   RETURN                     !
  161.  
  162.  
  163. ! ═════════════════════════════════════════════════════════════════════════
  164. !                 Unmark Marked Block
  165. ! ═════════════════════════════════════════════════════════════════════════
  166. Block_Unmark PROCEDURE( tTable, ilRowTop )
  167.  
  168.          ! Parameters:
  169. tTable         EXTERNAL,TABLE             ! Edit buffer
  170. ilRowTop     LONG                 ! Top row index
  171.  
  172.   CODE
  173.   MED:bbMarking       = 0                 ! Turn marking off
  174.   MED:ilMarkBegRow = 0                 ! Clear mark locations
  175.   MED:ibMarkBegCol = 0                 !
  176.   MED:ilMarkEndRow = 0                 !
  177.   MED:ibMarkEndCol = 0                 !
  178.   Show_Page(tTable, ilRowTop, 1, MED:ibRows)     ! Refresh screen
  179.   RETURN                     !
  180.  
  181.  
  182. ! ═════════════════════════════════════════════════════════════════════════
  183. !                  Delete Marked Block
  184. ! ═════════════════════════════════════════════════════════════════════════
  185. Block_Delete PROCEDURE( tTable, ilRowTop, ibRow, ibCol )
  186.  
  187.          ! Parameters:
  188. tTable         EXTERNAL,TABLE             ! Edit buffer
  189. ilRowTop     LONG                 ! Top row index
  190. ibRow         EXTERNAL                 ! Cursor row
  191. ibCol         EXTERNAL                 ! Cursor column
  192.  
  193.   CODE
  194.   IF NOT MED:ilMarkBegRow THEN RETURN.         ! Return if nothing marked
  195.  
  196.   MED:bbModified = 1                 ! Set modified flag
  197.   Cut_Block(tTable)                 ! Delete marked block
  198.   IF INRANGE(MED:ilMarkBegRow, ilRowTop+1, ilRowTop+MED:ibRows)
  199.     ibRow = MED:ilMarkBegRow - ilRowTop         ! Update cursor position
  200.     ibCol = MED:ibMarkBegCol             !
  201.   .                         !
  202.   Block_Unmark(tTable, ilRowTop)         ! Unmark the block
  203.   Reformat(tTable, ilRowTop+ibRow)         ! Reformat paragraph
  204.   Show_Page(tTable, ilRowTop, ibRow, MED:ibRows) ! Display rest of page
  205.   RETURN                     !
  206.  
  207.  
  208. ! ═════════════════════════════════════════════════════════════════════════
  209. !             Copy Marked Block to Cursor Location
  210. ! ═════════════════════════════════════════════════════════════════════════
  211. Block_Copy   PROCEDURE( tHold, tTable, ilRowTop, ibRow, ibCol )
  212.  
  213.          ! Parameters:
  214. tHold         EXTERNAL,TABLE             ! Hold area
  215. tTable         EXTERNAL,TABLE             ! Edit buffer
  216. ilRowTop     LONG                 ! Top row index
  217. ibRow         EXTERNAL                 ! Cursor row
  218. ibCol         EXTERNAL                 ! Cursor column
  219.  
  220.          ! Locals:
  221. ilAbsTarget  LONG                 ! Temporaries used in block
  222. ilAbsMrkBeg  LONG                 ! operations
  223. ilAbsMrkEnd  LONG                 !
  224.  
  225.   CODE
  226.   IF NOT MED:ilMarkBegRow THEN RETURN.         ! Return if nothing marked
  227.  
  228.   ilAbsTarget = 255*(ilRowTop+ibRow) + ibCol     ! Calculate absolute locations
  229.   ilAbsMrkBeg = 255*MED:ilMarkBegRow + MED:ibMarkBegCol
  230.   ilAbsMrkEnd = 255*MED:ilMarkEndRow + MED:ibMarkEndCol
  231.  
  232.   IF INRANGE(ilAbsTarget,ilAbsMrkBeg,ilAbsMrkEnd)! If target in middle of block
  233.     ! Not implemented                 !   Can't do that!
  234.     RETURN                     !   Exit
  235.   .                         ! Endif
  236.  
  237.   MED:bbModified = 1                 ! Set modified flag
  238.   Copy_Hold(tHold, tTable)             ! Copy marked block to hold
  239.   Paste_Hold(tHold, tTable, ilRowTop+ibRow, ibCol) ! Copy hold to cursor pos.
  240.   Block_Unmark(tTable, ilRowTop)         ! Unmark the block
  241.   Reformat(tTable, ilRowTop+ibRow)         ! Reformat paragraph
  242.   Show_Page(tTable, ilRowTop, ibRow, MED:ibRows) ! Display rest of page
  243.   RETURN                     !
  244.  
  245.  
  246. ! ═════════════════════════════════════════════════════════════════════════
  247. !             Move Marked Block to Cursor Location
  248. ! ═════════════════════════════════════════════════════════════════════════
  249. Block_Move   PROCEDURE( tHold, tTable, ilRowTop, ibRow, ibCol )
  250.  
  251.          ! Parameters:
  252. tHold         EXTERNAL,TABLE             ! Hold area
  253. tTable         EXTERNAL,TABLE             ! Edit buffer
  254. ilRowTop     LONG                 ! Top row index
  255. ibRow         EXTERNAL                 ! Cursor row
  256. ibCol         EXTERNAL                 ! Cursor column
  257.  
  258.          ! Locals:
  259. ilAbsTarget  LONG                 ! Temporaries used in block
  260. ilAbsMrkBeg  LONG                 ! operations
  261. ilAbsMrkEnd  LONG                 !
  262.  
  263.   CODE
  264.   IF NOT MED:ilMarkBegRow THEN RETURN.         ! Return if nothing marked
  265.  
  266.   ilAbsTarget = 255*(ilRowTop+ibRow) + ibCol     ! Calculate absolute locations
  267.   ilAbsMrkBeg = 255*MED:ilMarkBegRow + MED:ibMarkBegCol
  268.   ilAbsMrkEnd = 255*MED:ilMarkEndRow + MED:ibMarkEndCol
  269.  
  270.   IF ilAbsTarget < ilAbsMrkBeg             ! If target before block
  271.     MED:bbModified = 1                 !   Set modified flag
  272.     Copy_Hold(tHold, tTable)             !   Copy marked block to hold
  273.     Cut_Block(tTable)                 !   Delete the block
  274.                          !   Copy hold to cursor pos.
  275.     Paste_Hold(tHold, tTable, ilRowTop+ibRow, ibCol)
  276.     Block_Unmark(tTable, ilRowTop)         !   Unmark the block
  277.   ELSIF ilAbsTarget > ilAbsMrkEnd         ! Else if target after block
  278.     MED:bbModified = 1                 !   Set modified flag
  279.     Copy_Hold(tHold, tTable)             !   Copy marked block to hold
  280.                          !   Copy hold to cursor pos.
  281.     Paste_Hold(tHold, tTable, ilRowTop+ibRow, ibCol)
  282.     Cut_Block(tTable)                 !   Delete the block
  283.     Block_Unmark(tTable, ilRowTop)         !   Unmark the block
  284.   ELSE                         ! Else target is inside block
  285.     ! Not implemented                 !   Can't do that!
  286.   .                         ! Endif
  287.   RETURN                     !
  288.  
  289.