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

  1.  
  2. !═════════════════════════════════════════════════════════════════════════
  3. !
  4. !  %%keyword%% '%n'
  5. !  'MEMOEDIT.CLA' - Clarion Memo Field Editor
  6. !
  7. !  %%keyword%% '%v'
  8. !  Revision Number: '5'
  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. !  BACKGROUND
  20. !
  21. !    In the course of developing a Clarion vertical market application, I
  22. !    had a requirement for basic word processing functions in memo fields.
  23. !
  24. !    I tried Eckenroed & Associates's MEMO3, but was disappointed by its
  25. !    large RAM requirements (30K minimum) and its inflexibility with regards
  26. !    to keystroke handling and customization.  These lmitations made it
  27. !    unacceptable for my application.
  28. !
  29. !    There were no other products that seemed to fit the bill, so I wrote
  30. !    one.  MEMOEDIT is the result.
  31. !
  32. !
  33. !  FEATURES
  34. !
  35. !    This module replaces the standard Clarion memo field editor, and adds the
  36. !    following features:
  37. !
  38. !       Dynamic word wrapping and paragraph reformatting
  39. !
  40. !       Block operations: Copy, Move, Delete
  41. !
  42. !       Written entirely in Clarion - can be overlayed.
  43. !
  44. !       All source is provided - you can selectively add/remove features
  45. !
  46. !
  47. !  REVISION HISTORY
  48. !
  49. !    1.00 - Initial release
  50. !
  51. !    1.01 - Fixed the following bugs:
  52. !          1. Delete to EOL would leave an extra space in line
  53. !          2. Filling a memo line with unbroken sequence of characters
  54. !         would cause word wrap to hang
  55. !          3. Exceeding the memo buffer line limit would result in
  56. !         a 'Subscript out of Range' error.
  57. !
  58. !    1.10 - Major overhauls:
  59. !          1. Converted most routines to procs/funcs
  60. !          2. Modifications to support Designer apps
  61. !          3. Added support for 'hard' carriage return codes
  62. !         (Codes compatible with Eckenroed's MEMO3)
  63. !
  64. !    1.15 - Fixed the following bugs:
  65. !             1. Insert/Overwrite would always Insert regardless
  66. !             2. Typing a space on last column of last line did not
  67. !                Move cursor correctly.
  68. !
  69. !═════════════════════════════════════════════════════════════════════════
  70.  
  71.          MEMBER()
  72.  
  73. !═════════════════════════════════════════════════════════════════════════
  74. !               Edit a memo field
  75. !═════════════════════════════════════════════════════════════════════════
  76. Edit_Memo    PROCEDURE( xMemo )
  77.  
  78.          ! Parameters:
  79. xMemo         EXTERNAL,DIM(1)             ! Memo field array
  80.  
  81.          ! Locals:
  82. tTable         TABLE,PRE(TAB)             ! Edit buffer
  83.            STRING(255)             !
  84.          .                     !
  85.  
  86. tHold         TABLE,PRE(HLD)             ! Hold area for block ops.
  87.            STRING(255)             !
  88.          .                     !
  89.  
  90. ilRowTop     LONG                 ! Top row table index
  91. ibRow         BYTE                 ! Cursor row
  92. ibCol         BYTE                 ! Cursor column
  93.  
  94. isKeystroke  SHORT                 ! Last keystroke typed
  95.  
  96. bbInsertMode BYTE                 ! Insert mode flag
  97.  
  98. sTemp         STRING(255)             ! Temporary line buffer
  99.  
  100. ilTblNdx     LONG                 ! Edit table index
  101. ilHoldNdx    LONG                 ! Hold table index
  102. ilMemoNdx    LONG                 ! Memo array index
  103.  
  104.   CODE
  105.   bbInsertMode = 1                 ! Set Insert mode ON
  106.   ibRow           = 1                 ! Start on first row
  107.   ibCol           = 1                 ! Start in first column
  108.  
  109.   MED:bbModified  = 0                 ! Clear modified flag
  110.   MED:bbShowCodes = 0                 ! Hide format codes
  111.  
  112.   MED:bbMarking       = 0                 ! Marking mode is OFF
  113.   MED:ilMarkBegRow = 0                 !
  114.   MED:ibMarkBegCol = 0                 !
  115.   MED:ilMarkEndRow = 0                 !
  116.   MED:ibMarkEndCol = 0                 !
  117.  
  118.   MED:ilMemoRows = MAXIMUM(xMemo[], 1)         ! Set memo size
  119.   MED:ibWrapCol     = MED:ibCols - 1         ! and word wrap column
  120.  
  121.   HELP( , eHelpID)                 ! Set help window
  122.  
  123.   DO LoadMemo                     ! Load memo into edit buffer
  124.   First_Page(tTable, ilRowTop, ibRow)         ! Display first page
  125.   DO EditLoop                     ! Edit the memo
  126.   DO SaveMemo                     ! Save edit buffer to memo
  127.  
  128.   HELP(, '')                     ! Deactivate help window
  129.   SETCURSOR                     ! Turn offf cursor
  130.   FREE(tTable)                     ! Clean up
  131.   FREE(tHold)                     !
  132.   RETURN                     !
  133.  
  134. !──────────────────────────────────────────────────────────────────────────
  135. EditLoop     ROUTINE      ! Main edit loop
  136. !──────────────────────────────────────────────────────────────────────────
  137.   LOOP                         ! Loop
  138.                          !   Set cursor position
  139.     SETCURSOR(MED:ibRowOfs+ibRow,MED:ibColOfs+ibCol)
  140.     Cursor_Size( bbInsertMode )             !   Set cursor size
  141.     ASK                         !   Wait for keystroke
  142.     isKeystroke = KEYCODE()             !   Save it
  143.  
  144.     GET(tTable, ilRowTop+ibRow)             !   Get current line
  145.  
  146.     CASE isKeystroke                 !   Process keystroke
  147.       OF Esc_Key;    BREAK             !
  148.       OF F1_Key;     HELP             !
  149.  
  150.       OF Left_Key;   Move_Left(ibCol)         !   Horizontal movement
  151.       OF Right_Key;  Move_Right(ibCol)         !
  152.       OF Ctrl_Left;  Move_WLeft(tTable, ibCol)     !
  153.       OF Ctrl_Right; Move_WRight(tTable, ibCol)     !
  154.       OF Tab_Key;    Tab_Right(ibCol)         !
  155.       OF Home_Key;   Move_BOL(ibCol)         !
  156.       OF End_Key;    Move_EOL(tTable, ibCol)     !
  157.  
  158.                          !   Vertical movement
  159.       OF Up_Key;     Move_Up(tTable, ilRowTop, ibRow)
  160.       OF Down_Key;   Move_Down(tTable, ilRowTop, ibRow)
  161.       OF PgUp_Key;   Page_Up(tTable, ilRowTop, ibRow)
  162.       OF PgDn_Key;   Page_Down(tTable, ilRowTop, ibRow)
  163.       OF Ctrl_PgUp;  First_Page(tTable, ilRowTop, ibRow)
  164.       OF Ctrl_PgDn;  Last_Page(tTable, ilRowTop, ibRow)
  165.  
  166.       OF Enter_Key;  DO Newline             !   Insertion/deletion
  167.       OF Ins_Key;    DO Toggle_Ins         !
  168.       OF Del_Key;    DO Delete_Char         !
  169.       OF BS_Key;     DO Backspace         !
  170.       OF Ctrl_End;   DO Delete_EOL         !
  171.  
  172.                          !   Block operations
  173.       OF Alt_K;         Block_Mark(ilRowTop+ibRow, ibCol)
  174.       OF Alt_D;         Block_Delete(tTable, ilRowTop, ibRow, ibCol)
  175.       OF Alt_Y;         Block_Copy(tHold, tTable, ilRowTop, ibRow, ibCol)
  176.       OF Alt_M;         Block_Move(tHold, tTable, ilRowTop, ibRow, ibCol)
  177.  
  178.       OF Alt_C;         DO Toggle_Codes         !   Special keys
  179.       OF F4_Key;     DO Today             !
  180.  
  181.     ELSE                     !   Else
  182.       IF ALERTED(isKeystroke) THEN BREAK.     !     Return on alerted key
  183.       IF INRANGE(isKeystroke, 32, 255)         !     If it's a printable char
  184.     DO Insert_Char                 !     Insert it
  185.       ELSE                     !     Else
  186.     BEEP                     !     Garbage
  187.     . .                         !   End case
  188.  
  189.     GET(tTable, ilRowTop+ibRow)             !   Get current line
  190.     ibCol = Fix_Column(tTable, ibCol)         !   Adjust cursor column
  191.  
  192.     IF MED:bbMarking                 !   If marking a block
  193.       MED:ilMarkEndRow = ilRowTop + ibRow     !     Update block end row
  194.       MED:ibMarkEndCol = ibCol             !     Update block end column
  195.       Show_Page(tTable, ilRowTop, 1, MED:ibRows) ! Update marking on screen
  196.   . .                         ! End loop
  197.  
  198.  
  199. !
  200. !             Text Insertion Routines
  201. !
  202.  
  203. !──────────────────────────────────────────────────────────────────────────
  204. Toggle_Ins   ROUTINE      ! Toggle insert/overwrite mode
  205. !──────────────────────────────────────────────────────────────────────────
  206.   bbInsertMode = BXOR(bbInsertMode, 1)         ! Toggle insert flag
  207.  
  208. !──────────────────────────────────────────────────────────────────────────
  209. Insert_Char  ROUTINE      ! Insert a character
  210. !──────────────────────────────────────────────────────────────────────────
  211.   MED:bbModified = 1                 ! Set modified flag
  212.   Insert_Text(tTable, ilRowTop, ibRow, ibCol, CHR(isKeystroke), bbInsertMode)
  213.  
  214. !──────────────────────────────────────────────────────────────────────────
  215. Today         ROUTINE      ! Insert today's date
  216. !──────────────────────────────────────────────────────────────────────────
  217.   MED:bbModified = 1                 ! Set modified flag
  218.   Insert_Text(tTable, ilRowTop, ibRow, ibCol, FORMAT(TODAY(), @D1))
  219.  
  220. !──────────────────────────────────────────────────────────────────────────
  221. NewLine         ROUTINE      ! Process the Enter key
  222. !──────────────────────────────────────────────────────────────────────────
  223.   MED:bbModified = 1                 ! Set modified flag
  224.   IF bbInsertMode                 ! If insert mode
  225.     Insert_HCR(tTable, ilRowTop, ibRow, ibCol)     !   Insert a hard CR code
  226.   .                         ! Endif
  227.   Move_BOL(ibCol)                 ! Move to BOL
  228.   Move_Down(tTable, ilRowTop, ibRow)         ! Move down
  229.  
  230.  
  231. !
  232. !             Text Deletion Routines
  233. !
  234.  
  235. !──────────────────────────────────────────────────────────────────────────
  236. Delete_Char  ROUTINE      ! Delete character under cursor
  237. !──────────────────────────────────────────────────────────────────────────
  238.   MED:bbModified = 1                 ! Set modified flag
  239.   Delete_Char(tTable, ilRowTop, ibRow, ibCol)     !
  240.  
  241. !──────────────────────────────────────────────────────────────────────────
  242. Backspace    ROUTINE      ! Delete character before cursor
  243. !──────────────────────────────────────────────────────────────────────────
  244.   IF ibCol = 1 THEN EXIT.             ! Quit if at BOL
  245.   MED:bbModified = 1                 ! Set modified flag
  246.   ibCol -= 1                     ! Move left one column
  247.   Delete_Char(tTable, ilRowTop, ibRow, ibCol)     !
  248.  
  249. !──────────────────────────────────────────────────────────────────────────
  250. Delete_EOL   ROUTINE      ! Delete to end-of-line
  251. !──────────────────────────────────────────────────────────────────────────
  252.   MED:bbModified = 1                 ! Set modified flag
  253.   Delete_EOL(tTable, ilRowTop, ibRow, ibCol)     !
  254.  
  255.  
  256. !
  257. !               Display Routines
  258. !
  259.  
  260. !──────────────────────────────────────────────────────────────────────────
  261. Toggle_Codes ROUTINE      ! Toggle display of formatting codes
  262. !──────────────────────────────────────────────────────────────────────────
  263.   MED:bbShowCodes = BXOR(MED:bbShowCodes,1)     ! Toggle flag
  264.   Show_Page(tTable, ilRowTop, 1, MED:ibRows)     ! Redisplay page
  265.  
  266.  
  267. !
  268. !            Memo Read/Write Routines
  269. !
  270.  
  271. !──────────────────────────────────────────────────────────────────────────
  272. LoadMemo     ROUTINE      ! Load memo field into edit table
  273. !──────────────────────────────────────────────────────────────────────────
  274.   FREE(tTable)                     ! Clear edit buffer
  275.   LOOP ilMemoNdx = MED:ilMemoRows TO 2 BY -1     ! Loop back thru each line
  276.     IF xMemo[ilMemoNdx] THEN BREAK.         !   Find last non-blank line
  277.   .                         ! End loop
  278.   LOOP ilTblNdx = 1 TO ilMemoNdx         ! Loop for each line
  279.     tTable = xMemo[ilTblNdx]             !   Add to edit buffer
  280.     ADD(tTable)                     !
  281.   .                         ! End loop
  282.  
  283. !──────────────────────────────────────────────────────────────────────────
  284. SaveMemo     ROUTINE      ! Save edit table back to memo field
  285. !──────────────────────────────────────────────────────────────────────────
  286.   CLEAR(xMemo[])                 ! Clear memo field
  287.   LOOP ilTblNdx = 1 TO MED:ilMemoRows         ! Loop for each line
  288.     GET(tTable, ilTblNdx)             !   Get buffer entry
  289.     IF ERRORCODE() THEN CLEAR(tTable).         !
  290.     xMemo[ilTblNdx] = tTable             !   Save to memo field
  291.   .                         ! End loop
  292.  
  293.