README 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # $Id$
  2. ! Note: This version is not completed yet !
  3. This is SHEdit for Free Pascal, an object-oriented text editor engine with
  4. support for:
  5. - syntax highlighting
  6. - clipboard (cut, copy & paste)
  7. - undo/redo buffers
  8. - fully customizable behaviour
  9. - multiple views (editors) for a single document at a time
  10. - completely independent of any toolkit; it even can be used both in text and
  11. in graphics modes
  12. Architecture
  13. ------------
  14. There are three basic classes in SHEdit:
  15. - Document
  16. - Editor
  17. - Renderer
  18. The document class (TTextDoc) in doc_text.pp is quite simple, it just
  19. stores a text (ASCII) document as a collection of strings.
  20. What you have to know about TTextDoc is that it stores a 32-bit value for
  21. each line, which it doesn't modify on its own. The lower 8 bits of these
  22. LineFlags are reserved for syntax highlighting (SH): The first bit determines
  23. if the other SH flags are valid; and the remaining 7 bits can be used to
  24. indicate SH states which do not end at the end of the line.
  25. The editor itself is encapsulated in the class TSHTextEdit (in unit shedit.pp).
  26. It can only work in conjunction with a renderer, which is responsible for
  27. displaying the document. When you create a TSHTextEdit, the constructor expects
  28. two arguments: The document to use, and the renderer to use.
  29. The renderer itself is declared as an abstract interface class (i.e. all
  30. methods are 'virtual abstract'), this interface is called ISHRenderer.
  31. When you want to use SHEdit in your own programs, you will have to provide
  32. an implementation of the methods declared in ISHRenderer. There is a reference
  33. implementation for GTK, gtkdemo.
  34. Renderer interface
  35. ------------------
  36. This interface is quite simple; just note that SHEdit expects all corrdinates
  37. relative to the upper left corner of the document (0/0), and it uses the
  38. cell size (width and height) of the characters as base unit. For example,
  39. the coordinate X=3/Y=2 references the fourth character in the third line.
  40. procedure InvalidateLines(y1, y2: Integer);
  41. The renderer should initiate the redrawing of the lines between y1 and y2.
  42. It is recommended to use the Invalidate commands of the underlying graphics
  43. or windowing toolkit; but an implementation may choose to simply call
  44. TSHTextEdit.DrawContent.
  45. procedure ClearRect(x1, y1, x2, y2: Integer);
  46. The renderer must clear the given rectangle in the background (whitespace)
  47. color.
  48. procedure DrawTextLine(x1, x2, y: Integer; s: PChar);
  49. This is the most complex method: The renderer has to draw a complete line of
  50. text, which is given in "s". The vertical position is line "y", x1 and x2
  51. specify a horizontal clipping span.
  52. "s" has a very special format, as it contains highlighting tags:
  53. You can process "s" character by character, as usual. BUT when you encounter
  54. a special escape character (LF_Escape, defined in doc_text.pp) the renderer
  55. has to switch to the font style/color given in the following character. This
  56. character is just a index in the range ASCII #1..#255, the renderer must know
  57. himself what to do with this index. These highlighting tags are generated by
  58. a special highlighting function, see below.
  59. procedure ShowCursor(x, y: Integer);
  60. procedure HideCursor(x, y: Integer);
  61. The cursor should be drawn or be hidden, its position is given in "x" and
  62. "y". SHEdit does its own reference counting, i.e. it won't call HideCursor
  63. for an already invisible cursor, and it won't call ShowCursor for a visible
  64. cursor. If the cursor position changes, SHEdit will call HideCursor with
  65. the old position and then ShowCursor with the new position as arguments.
  66. function GetVertPos: Integer;
  67. This function shall return the vertical scrolling position of the window
  68. which is managed by the renderer.
  69. procedure SetVertPos(y: Integer);
  70. Sets the vertical scrolling position.
  71. function GetPageHeight: Integer;
  72. Gets the height of the visible part of the document.
  73. procedure SetLineCount(count: Integer);
  74. SHEdit calls this method if the number of lines in the document has changed.
  75. function GetClipboard: String;
  76. GetClipboard is called by SHEdit if the user wants to paste the contents of
  77. the clipboard into the document. GetClipboard must check if the system's
  78. clipboard contains valid text data and return it; if not, it has to return
  79. an empty string.
  80. procedure SetClipboard(Content: String);
  81. This method is used to set the content of the clipboard after a
  82. "ClipboardCut" or "ClipboardCopy" action occured.
  83. Highlighters and document type specific features
  84. ------------------------------------------------
  85. TSHTextEdit does not perform any syntax highlighting, and it always acts as a
  86. normal text editor without any fancy extra feature.
  87. This can easily be changed by deriving your own class from TSHTextEdit.
  88. Currently there are two special editor classes: TSHPasEdit (unit sh_pas.pp) and
  89. TSHXMLEdit (unit sh_xml.pp).
  90. TSHPasEdit supports syntax highlighting for Pascal sources, and it adds auto
  91. indent facilities to SHEdit (currently, when you press the Enter key, it will
  92. add as many spaces as the previous line to the new created line).
  93. TSHXMLEdit just adds syntax highlighting for XML and DTD documents.
  94. Please note that currently there is no framework for handling with different
  95. kinds of documents. It is up to the program which wants to use SHEdit to
  96. determine which editor class to use.
  97. - Sebastian Guenther, [email protected]