home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / clarion / library / memoed / me_core.cla < prev    next >
Text File  |  1992-03-21  |  10KB  |  287 lines

  1.  
  2. !═════════════════════════════════════════════════════════════════════════
  3. !
  4. !  %%keyword%% '%n'
  5. !  'ME_CORE.CLA' - Core Editing functions for MEMOEDIT
  6. !
  7. !  %%keyword%% '%v'
  8. !  Revision Number: '2'
  9. !  %%keyword%% '%d'
  10. !  Revision Date  : '21-Mar-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 the core editing functions which change the
  22. !    contents of the edit buffer.
  23. !
  24. !═════════════════════════════════════════════════════════════════════════
  25.  
  26. ME_Core         MEMBER()
  27.  
  28. ! ═════════════════════════════════════════════════════════════════════════
  29. !                Check for Buffer Full
  30. ! ═════════════════════════════════════════════════════════════════════════
  31. Buffer_Full  FUNCTION( tTable )
  32.  
  33.          ! Parameters:
  34. tTable         EXTERNAL,TABLE             ! Edit buffer
  35.  
  36.          ! Return:
  37. bbRetVal     BYTE                 ! Return flag
  38.  
  39.          ! Screen:
  40. wBufferFull  SCREEN      WINDOW(5,33),AT(12,28),HUE(15,4)
  41.            ROW(1,1)      STRING('╔═{31}╗')
  42.            ROW(2,1)      REPEAT(3);STRING('║<0{31}>║') .
  43.            ROW(5,1)      STRING('╚═{31}╝')
  44.            ROW(3,4)      STRING('No more room in memo field!')
  45.          .
  46.  
  47.   CODE
  48.   bbRetVal = 0                     ! Assume enough room
  49.   IF RECORDS(tTable) >= MED:ilMemoRows         ! If max lines exceeded
  50.     OPEN(wBufferFull)                 !   Notify user
  51.     BEEP; ASK                     !
  52.     CLOSE(wBufferFull)                 !
  53.     bbRetVal = 1                 !   Set return flag
  54.   .                         ! Endif
  55.   RETURN( bbRetVal )                 !
  56.  
  57.  
  58. ! ═════════════════════════════════════════════════════════════════════════
  59. !                Insert Text String
  60. ! ═════════════════════════════════════════════════════════════════════════
  61. Insert_Text  PROCEDURE( tTable, ilRowTop, ibRow, ibCol, sText, bbInsert )
  62.  
  63.          ! Parameters:
  64. tTable         EXTERNAL,TABLE             ! Edit buffer
  65. ilRowTop     EXTERNAL                 ! Top row index
  66. ibRow         EXTERNAL                 ! Cursor row
  67. ibCol         EXTERNAL                 ! Cursor column
  68. sText         STRING(255)             ! Text to insert
  69. bbInsert     BYTE                 ! Insert mode flag
  70.  
  71.   CODE
  72.   GET(tTable, ilRowTop+ibRow)             ! Get current line
  73.   IF NOT OMITTED(6)                 ! If insert mode passed
  74.     IF NOT bbInsert                 !   If not in insert mode
  75.       tTable = Str_Delete(tTable, ibCol, 1)     !     Delete cursor char
  76.   . .                         ! Endif
  77.   tTable = Str_Insert(CLIP(sText), tTable, ibCol)! Insert string
  78.   ibCol += Greater_Of(1, LEN(CLIP(sText)))     ! Adjust cursor column
  79.   PUT(tTable)                     ! Update edit buffer
  80.  
  81.   IF ibCol > MED:ibWrapCol             ! If past wrap column
  82.     IF KEYCODE() = VAL(' ')             !   If keystroke was a space
  83.       ibCol = 1                     !     Go to first column
  84.     ELSE                     !   Else wordwrap
  85.       ibCol = Word_Wrap(tTable, ilRowTop+ibRow, ibCol)
  86.     .                         !   Endif
  87.     Show_Line(tTable, ilRowTop+ibRow, ibRow)     !   Redisplay line
  88.     IF RECORDS(tTable) = ilRowTop+ibRow         !   If this is the last line
  89.       CLEAR(tTable); ADD(tTable)         !     Add a blank line
  90.     .                         !   Endif
  91.     Move_Down(tTable, ilRowTop, ibRow)         !   Move down
  92.     Reformat(tTable, ilRowTop+ibRow)         !   Reformat paragraph
  93.     Show_Page(tTable, ilRowTop, ibRow, MED:ibRows)! Display rest of page
  94.   ELSIF LEN(CLIP(tTable)) > MED:ibWrapCol     ! Else if too long
  95.     Reformat(tTable, ilRowTop+ibRow)         !   Reformat paragraph
  96.     Show_Page(tTable, ilRowTop, ibRow, MED:ibRows)! Display rest of page
  97.   ELSE                         ! Else
  98.     Show_Line(tTable, ilRowTop+ibRow, ibRow)     !   Just redisplay the line
  99.   .                         ! Endif
  100.   RETURN                     !
  101.  
  102.  
  103. ! ═════════════════════════════════════════════════════════════════════════
  104. !              Insert 'Hard' Carriage Return
  105. ! ═════════════════════════════════════════════════════════════════════════
  106. Insert_HCR   PROCEDURE( tTable, ilRowTop, ibRow, ibCol )
  107.  
  108.          ! Parameters:
  109. tTable         EXTERNAL,TABLE             ! Edit buffer
  110. ilRowTop     LONG                 ! Top row index
  111. ibRow         BYTE                 ! Current row
  112. ibCol         BYTE                 ! Current column
  113.  
  114.   CODE
  115.   tTable = Str_Insert(eHCRCode, tTable, ibCol)     ! Insert format code
  116.   PUT(tTable)                     ! Update edit buffer
  117.   Split_Line(tTable, ilRowTop+ibRow, ibCol+1)     ! Split current line
  118.   Show_Line(tTable, ilRowTop+ibRow, ibRow)     ! Display line
  119.   Reformat(tTable, ilRowTop+ibRow+1)         ! Reformat paragrpah
  120.   Show_Page(tTable, ilRowTop, ibRow+1, MED:ibRows)
  121.   RETURN                     !
  122.  
  123.  
  124. ! ═════════════════════════════════════════════════════════════════════════
  125. !                Delete a Character
  126. ! ═════════════════════════════════════════════════════════════════════════
  127. Delete_Char  PROCEDURE( tTable, ilRowTop, ibRow, ibCol )
  128.  
  129.          ! Parameters:
  130. tTable         EXTERNAL,TABLE             ! Edit buffer
  131. ilRowTop     LONG                 ! Top row index
  132. ibRow         BYTE                 ! Current row
  133. ibCol         BYTE                 ! Current column
  134.  
  135.   CODE
  136.   IF ibCol > LEN(CLIP(tTable))             ! If EOL
  137.     Join_Line(tTable, ilRowTop+ibRow)         !   Join next line
  138.   ELSE                         ! Else
  139.     tTable = Str_Delete(tTable, ibCol, 1)     !   Delete cursor character
  140.     PUT(tTable)                     !   Update edit buffer
  141.   .                         ! Endif
  142.   Reformat(tTable, ilRowTop+ibRow)         ! Reformat paragrpah
  143.   Show_Page(tTable, ilRowTop, ibRow, MED:ibRows) ! Display rest of page
  144.   RETURN                     !
  145.  
  146.  
  147. ! ═════════════════════════════════════════════════════════════════════════
  148. !               Delete to End of Line
  149. ! ═════════════════════════════════════════════════════════════════════════
  150. Delete_EOL   PROCEDURE( tTable, ilRowTop, ibRow, ibCol )
  151.  
  152.          ! Parameters:
  153. tTable         EXTERNAL,TABLE             ! Edit buffer
  154. ilRowTop     LONG                 ! Top row index
  155. ibRow         BYTE                 ! Current row
  156. ibCol         BYTE                 ! Current column
  157.  
  158.          ! Locals:
  159. sTemp         STRING(255)             ! Temporary line buffer
  160.  
  161.   CODE
  162.   sTemp     = tTable                 ! Save current line
  163.   tTable = SUB(tTable, 1, ibCol-1)         ! Delete from cursor
  164.   IF INSTRING(eHCRCode, sTemp, 1)         ! If line contained hard CR
  165.     tTable = CLIP(tTable) & eHCRCode         !   Put hard CR back in
  166.   .                         ! Endif
  167.   PUT(tTable)                     ! Update edit buffer
  168.   Reformat(tTable, ilRowTop+ibRow)         ! Reformat paragrpah
  169.   Show_Page(tTable, ilRowTop, ibRow, MED:ibRows) ! Display rest of page
  170.   RETURN                     !
  171.  
  172.  
  173. ! ═════════════════════════════════════════════════════════════════════════
  174. !                Reformat Paragraph
  175. ! ═════════════════════════════════════════════════════════════════════════
  176. Reformat     PROCEDURE( tTable, ilRowStart )
  177.  
  178.          ! Parameters:
  179. tTable         EXTERNAL,TABLE             ! Edit buffer
  180. ilRowStart   LONG                 ! First row to reformat
  181.  
  182.          ! Locals:
  183. sTemp         STRING(255)             ! Temporary line buffer
  184. ibColndx     BYTE                 ! Column index
  185. ilIndex         LONG                 ! Loop index
  186.  
  187.   CODE
  188.   LOOP ilIndex = ilRowStart TO RECORDS(tTable)     ! Loop for each line
  189.     GET(tTable, ilIndex)             !  Get line from edit buffer
  190.  
  191.     IF LEN(CLIP(tTable)) <= MED:ibWrapCol     !  If line is short
  192.       IF INSTRING(eHCRCode, tTable, 1) THEN BREAK.!    Quit if hard CR found
  193.       GET(tTable, ilIndex+1)             !     Get next line
  194.       IF ERRORCODE() THEN BREAK.         !     Break if no more lines
  195.       sTemp = tTable                 !     Save it
  196.       DELETE(tTable)                 !     Delete from edit buffer
  197.       GET(tTable, ilIndex)             !     Get back original line
  198.       IF CLIP(tTable)                 !     Append next line
  199.     tTable = CLIP(tTable) & ' ' & sTemp     !
  200.       ELSE                     !
  201.     tTable = sTemp                 !
  202.       .                         !
  203.       PUT(tTable)                 !     Save back to edit buffer
  204.     .                         !   Endif
  205.  
  206.     IF LEN(CLIP(tTable)) > MED:ibWrapCol     !   If line is too long
  207.       ibColNdx = Word_Left(tTable, MED:ibWrapCol+1) !  Find breakpoint
  208.       IF ibColNdx = 1 THEN ibColNdx = MED:ibWrapCol.
  209.       Split_Line(tTable, ilIndex, ibColNdx)     !     Split line
  210.   . .                         ! End loop
  211.   RETURN                     !
  212.  
  213.  
  214. ! ═════════════════════════════════════════════════════════════════════════
  215. !               Perform Word Wrap
  216. ! ═════════════════════════════════════════════════════════════════════════
  217. Word_Wrap    FUNCTION( tTable, ilTblNdx, ibCol )
  218.  
  219.          !    Parameters:
  220. tTable         EXTERNAL,TABLE             ! Edit buffer
  221. ilTblNdx     LONG                 ! Line index
  222. ibCol         BYTE                 ! Cursor column
  223.  
  224.          ! Locals:
  225. sTemp         STRING(255)             ! Temporary line buffer
  226.  
  227.   CODE
  228.   GET(tTable, ilTblNdx)                 ! Get current line
  229.   ibCol = Word_Left(tTable, ibCol)         ! Find start of last word
  230.   IF ibCol = 1 THEN ibCol = MED:ibWrapCol.     ! Adjust for unbroken line
  231.   sTemp = SUB(tTable, ibCol, 255)         ! Get word to be wrapped
  232.   Split_Line(tTable, ilTblNdx, ibCol)         ! Split the line
  233.   RETURN( LEN(CLIP(sTemp))+1 )             ! Return new cursor position
  234.  
  235.  
  236. ! ═════════════════════════════════════════════════════════════════════════
  237. !              Split Line at Passed Position
  238. ! ═════════════════════════════════════════════════════════════════════════
  239. Split_Line   PROCEDURE( tTable, ilTblNdx, ibSplitCol )
  240.  
  241.          ! Parameters:
  242. tTable         EXTERNAL,TABLE             ! Edit buffer
  243. ilTblNdx     LONG                 ! Line index
  244. ibSplitCol   BYTE                 ! Split column
  245.  
  246.          ! Locals:
  247. sTemp         STRING(255)             ! Temporayr line buffer
  248.  
  249.   CODE
  250.   IF Buffer_Full(tTable) THEN RETURN.         ! Check for enough room
  251.  
  252.   GET(tTable, ilTblNdx)                 ! Get current line
  253.   sTemp     = SUB(tTable, ibSplitCol, 255)         ! Save text past split col
  254.   tTable = SUB(tTable, 1, ibSplitCol-1)         ! Delete portion past split
  255.   PUT(tTable)                     ! Save back to edit buffer
  256.  
  257.   tTable = LEFT(sTemp)                 ! Create new line
  258.   ADD(tTable, ilTblNdx+1)             ! with saved text
  259.  
  260.   GET(tTable, ilTblNdx)                 ! Restore current line
  261.   RETURN                     !
  262.  
  263.  
  264. ! ═════════════════════════════════════════════════════════════════════════
  265. !              Join Next Line with Current Line
  266. ! ═════════════════════════════════════════════════════════════════════════
  267. Join_Line    PROCEDURE( tTable, ilTblNdx )
  268.  
  269.          ! Parameters:
  270. tTable         EXTERNAL,TABLE             ! Edit buffer
  271. ilTblNdx     LONG                 ! Line index
  272.  
  273.          ! Locals:
  274. sTemp         STRING(255)             ! Temporary line buffer
  275.  
  276.   CODE
  277.   GET(tTable, ilTblNdx+1)             ! Get next line
  278.   IF NOT ERRORCODE()                 ! If found
  279.     sTemp = tTable                 !   Save text
  280.     DELETE(tTable)                 !   Delete from edit buffer
  281.     GET(tTable, ilTblNdx)             !   Get current line
  282.     tTable = CLIP(tTable) & ' ' & sTemp         !   Join lines
  283.     PUT(tTable)                     !   Update edit buffer
  284.   .                         ! Endif
  285.   RETURN                     !
  286.  
  287.