[lazarus] SHEdit
Sebastian Guenther
sguenther at gmx.de
Wed Dec 1 06:04:03 EST 1999
Curtis White wrote:
>
> I was just browsing through the fcl directory and noticed that Sebastian has
> made his SHEdit editor class generic enough that it could easily be implemented
> to work with Lazarus and checked it into CVS.
Peter added it to CVS about 2 weeks ago; sorry that you have missed this
but I thought he has announced this on one of the mailing lists...? (on
the other hand _I_ have missed that he added a lot of stuff to get the
keyboard working in the GTK demo. Sorry Peter!)
> Sebastian, can you tell us more about this? How hard would it be for us to get
> it working now with Lazarus?
It shouldn't be too hard: You only need to implement methods for drawing
a colored (highlighted) line of text, clearing rectangles on the screen
and to forward some events (redrawing, keyboard and mouse events).
I have finally started the renderer implementation for KCL yesterday, I
think this implementation can be a even better starting point for the
Lazarus version.
What makes SHEdit somewhat complicated is its flexiblity: SHEdit itself
does not deal with key definitions and style (color etc.) definitions
or. It has platform-independent syntax highlighters, which I have to
explain a little bit:
When the renderer has to display a highlighted line, it gets a string
which contains style control sequences. This sequences are indicated by
a special escape character (LF_Escape in file doc_text.pp, this is
currently ASCII #10 (why not e.g. #27 will be clear when SHEdit will be
a 'non-destructive' editor). The character (#1..#255) following
LF_Escape is a style number, and the renderer has to know for its own
what to do with this number. All highlighters must be initialized with
the style numbers for each style before usage, e.g. you must set the
member variable "shKeyword" of a Pascal highlighter to the style number
you want the highlighter to use to mark keywords in an input string. The
management of these style numbers is up to the renderer.
You will have a lot of classes in programs which use SHEdit:
+TTextDoc
+TSHTextEdit (Generic, doesn't really highlight anything)
|- TSHPasEdit (Pascal Highlighter)
|- TSHXMLEdit (XML Highlighter)
|- ...
and then you need to add some classes for each implementation:
+ TMyRenderer
+ TEditControl (Component (control/widget) class for GUI library)
|- TTextEditControl
|- TPasEditControl
|- TXMLEditControl
|- ...
you can put the rendering stuff into TEditControl, then TMyRenderer will
just forward all method calls to TEditControl (this is what KCL will
probably do). And perhaps one day FPC will support interfaces, then
IRenderer will become a _real_ interface class and you won't need
TMyRenderer anymore.
I think this isn't too complicated; the SHEdit GTK example will be more
complicated than the KCL version because the latter is based on a class
library whereas the GTK demo implements everything on its own. So I
suggest that you wait until the KCL version is basically working (it
should be ready very soon).
- Sebastian
More information about the Lazarus
mailing list