TRichEdit / TScintilla
Rich text editing with RTF formatting, and source code editing with syntax highlighting
graph TD
TControl --> TRichEdit
TControl --> TScintilla
TRichEdit --> RTF["RTF Formatting
Bold, Italic, Colors"] TRichEdit --> OLE["OLE Objects
Embedded Pictures"] TRichEdit --> FIND["Find / Replace"] TRichEdit --> PRINT["Print / Preview / PDF"] TScintilla --> SYNTAX["Syntax Highlighting
Harbour, C, PRG"] TScintilla --> FOLD["Code Folding"] TScintilla --> MARGIN["Margins
Line Numbers, Bookmarks"] TScintilla --> AUTO["Autocomplete
Call Tips"] style TRichEdit fill:#1c2129,stroke:#58a6ff,stroke-width:2px,color:#e6edf3 style TScintilla fill:#1c2129,stroke:#58a6ff,stroke-width:2px,color:#e6edf3
Bold, Italic, Colors"] TRichEdit --> OLE["OLE Objects
Embedded Pictures"] TRichEdit --> FIND["Find / Replace"] TRichEdit --> PRINT["Print / Preview / PDF"] TScintilla --> SYNTAX["Syntax Highlighting
Harbour, C, PRG"] TScintilla --> FOLD["Code Folding"] TScintilla --> MARGIN["Margins
Line Numbers, Bookmarks"] TScintilla --> AUTO["Autocomplete
Call Tips"] style TRichEdit fill:#1c2129,stroke:#58a6ff,stroke-width:2px,color:#e6edf3 style TScintilla fill:#1c2129,stroke:#58a6ff,stroke-width:2px,color:#e6edf3
TRichEdit
Source: source/classes/trichedi.prg | Parent: TControl
TRichEdit wraps the Windows RichEdit20A control, providing a full-featured RTF editor. It supports bold/italic/underline formatting, font and color changes, paragraph alignment, bullet lists, embedded images via OLE, find/replace, zoom, undo/redo, and print/preview/PDF export.
Properties
| Property | Type | Description |
|---|---|---|
cFileName | String | Current RTF file path |
nRTFSize | Numeric | Maximum text size limit |
lURL | Logical | Enable automatic URL detection and clickable links |
lRE30 | Logical | Using RichEdit 3.0+ (supports zoom, redo, advanced typography) |
lReadOnly | Logical | Read-only mode -- editing disabled |
lHighlight | Logical | Enable syntax highlighting (for code editing) |
aKeywords1 | Array | Primary highlighted keywords |
aKeywords2 | Array | Secondary highlighted keywords |
cSeparators | String | Token separator characters for highlighting |
nClrNumber | Numeric | Color for numeric literals |
nClrString | Numeric | Color for string literals |
nClrComment | Numeric | Color for comments |
Key Methods
| Method | Description |
|---|---|
New( nTop, nLeft, bSetGet, oWnd, nWidth, nHeight, oFont, lPixel, cMsg, lHScroll, lReadOnly, bWhen, bValid, bChanged, lDesign, lHighlight, cFileName, nRTFSize, lNoURL, lNoScroll, lNoBorder ) | Constructor |
ReDefine( nId, bSetGet, oWnd, ... ) | Redefine from resource |
| Text Formatting | |
SetBold( lOnOff ) | Toggle bold on selected text |
SetItalic( lOnOff ) | Toggle italic |
SetUnderline( lOnOff ) | Toggle underline |
SetStrikeOut( lOnOff ) | Toggle strikethrough |
SetFontName( cName ) | Set font face for selection |
SetFontSize( nSize ) | Set font size for selection |
SetTextColor( nRGB ) | Set text color for selection |
SetHighLight( nColor ) | Set background highlight color for selection |
SetBkGndColor( nRGB ) | Set the entire control's background color |
SetAlign( nAlign ) | Paragraph alignment: PFA_LEFT (1), PFA_RIGHT (2), PFA_CENTER (3), PFA_JUSTIFY (4) |
SetBullet( lOnOff ) | Toggle bullet list |
SetNumbering( lOnOff ) | Toggle numbered list |
SetIndent( nLeft, nRight, nFirst ) | Set paragraph indentation |
| Clipboard & Editing | |
Copy() | Copy selection to clipboard |
Cut() | Cut selection to clipboard |
Paste() | Paste from clipboard |
Del() | Delete selection |
SelectAll() | Select all text |
UnDo() | Undo last action |
ReDo() | Redo last undone action |
CanUndo() / CanRedo() | Check if undo/redo is available |
CanCopy() / CanCut() / CanPaste() | Check clipboard operation availability |
| Find & Navigation | |
Find( cFind, lDown, lCase, lWord ) | Search for text. Returns position or -1. |
ReplaceSel( lUnDo, cText ) | Replace the current selection with new text |
GoToLine( nLine ) | Scroll to and position cursor at a specific line |
GetRow() / GetCol() | Get current cursor row and column |
GetLineCount() | Total number of lines |
GetLine( nLine ) | Get text of a specific line |
Len() | Total character count |
| File I/O | |
LoadFromRTFFile( cFileName ) | Load an RTF file into the control |
SaveToRTFFile( cFileName ) | Save content as RTF file |
LoadRTF( cRTF ) | Load RTF from a string |
SaveAsRTF() | Return content as an RTF string |
cText( cText ) | Get or set plain text content |
| OLE & Pictures | |
InsertPicture( cFile, nSizeX, nSizeY ) | Embed an image from a file |
InsertBitmap( hBitmap, nSizeX, nSizeY ) | Embed a bitmap by handle |
| Print & Export | |
Print( cName ) | Print the content |
Preview( cName ) | Show print preview |
SaveToPDF( cName, cFile, lView ) | Export to PDF |
| Zoom | |
SetZoom( nNumerator, nDenominator ) | Set zoom level (e.g. SetZoom(2, 1) = 200%) |
GetZoom() | Get current zoom as {nNumerator, nDenominator} |
Command Syntax
@ nTop, nLeft RICHEDIT [ oRTF VAR ] uVar ;
[ OF oWnd ] ;
[ SIZE nWidth, nHeight ] ;
[ FONT oFont ] ;
[ PIXEL ] ;
[ MESSAGE cMsg ] ;
[ HSCROLL ] ;
[ READONLY | NO MODIFY ] ;
[ WHEN bWhen ] ;
[ VALID bValid ] ;
[ ON CHANGE bChange ] ;
[ HIGHLIGHT ] ;
[ FILE cFileName ] ;
[ RTFSIZE nRTFSize ] ;
[ NO URL ] ;
[ NO SCROLL ] ;
[ NOBORDER ]
REDEFINE RICHEDIT [ oRTF VAR ] uVar ;
ID nId ;
[ OF oWnd ] ;
[ FONT oFont ] ;
[ READONLY ] ;
[ HIGHLIGHT ] ;
[ FILE cFileName ] ;
[ WHEN bWhen ] ;
[ VALID bValid ] ;
[ ON CHANGE bChange ]
Example: RTF Editor
#include "FiveWin.ch"
#include "RichEdit.ch"
FUNCTION RichEditDemo()
LOCAL oDlg, oRTF, cText := ""
DEFINE DIALOG oDlg TITLE "Rich Text Editor" SIZE 600, 450
@ 0.5, 0.5 RICHEDIT oRTF VAR cText OF oDlg ;
SIZE 280, 180 PIXEL
// Toolbar buttons for formatting
@ 8, 0.5 BUTTON "Bold" OF oDlg SIZE 50, 14 ;
ACTION oRTF:SetBold( .T. )
@ 8, 5 BUTTON "Italic" OF oDlg SIZE 50, 14 ;
ACTION oRTF:SetItalic( .T. )
@ 8, 9.5 BUTTON "Underline" OF oDlg SIZE 60, 14 ;
ACTION oRTF:SetUnderline( .T. )
// Load and save
@ 10, 0.5 BUTTON "Open RTF" OF oDlg SIZE 60, 14 ;
ACTION ( cFile := cGetFile( "*.rtf", "Open RTF" ), ;
If( !Empty(cFile), oRTF:LoadFromRTFFile( cFile ), ) )
@ 10, 6 BUTTON "Save RTF" OF oDlg SIZE 60, 14 ;
ACTION oRTF:SaveToRTFFile( cGetNewFile( "*.rtf", "Save RTF" ) )
@ 10, 12 BUTTON "Print" OF oDlg SIZE 50, 14 ;
ACTION oRTF:Print( "RichEdit Document" )
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL
TScintilla
Source: source/classes/scintila.prg | Parent: TControl
TScintilla wraps the Scintilla editor component, providing a professional source code editor with syntax highlighting, code folding, line numbers, bookmarks, brace matching, autocomplete, and multi-document support. It is the editor engine used in the FiveWin IDE.
Properties
| Property | Type | Description |
|---|---|---|
cFileName | String | Current file path being edited |
cLexer | String | Syntax lexer (e.g. "harbour", "cpp") |
cLang | String | Language identifier |
lMargLin | Logical | Show line number margin |
lFolding | Logical | Enable code folding |
lMarking | Logical | Enable bookmark margin |
lMessage | Logical | Show message/build margin |
nMargLines | Numeric | Width of line number margin |
nMargSymbol | Numeric | Width of symbol/bookmark margin |
nMargFold | Numeric | Width of folding margin |
nWidthTab | Numeric | Tab width in characters |
nSpacLin | Numeric | Extra line spacing |
lVirtSpace | Logical | Allow cursor in virtual space beyond line end |
cFontS | String | Editor font face name |
nHFont | Numeric | Editor font height |
lModified | Logical | Document has unsaved changes |
bModified | Block | Callback when modification state changes |
lUtf8 | Logical | Document is UTF-8 encoded |
lSaveBak | Logical | Create .bak backup on save |
aKey | Array | Custom key bindings: { { nKey, bAction }, ... } |
lAutoWords | Logical | Enable autocomplete word suggestions |
lHistClip | Logical | Clipboard history support |
Syntax Highlighting Colors
| Property | Description |
|---|---|
cCComment | Block comment color { nFore, nBack, nCase } |
cCCommentLin | Line comment color |
cCString | String literal color |
cCNumber | Numeric literal color |
cCOperator | Operator color |
cCKeyw1 .. cCKeyw5 | Keyword group colors (1-5) |
cCBraces | Matched brace color |
cCBraceBad | Unmatched brace color |
cCIdentif | Identifier color |
nColorSelection | Text selection foreground color |
nColorSelectionB | Text selection background color |
Key Methods
| Method | Description |
|---|---|
New( nRow, nCol, nWidth, nHeight, oWnd, nClrT, nClrP, cLex, cDll, bSetup, lLoad, cPathApli ) | Constructor. Creates the Scintilla editor. |
| Text Operations | |
GetText() | Get the entire document text |
AddText( cText ) | Append text at the current position |
GetLine( nLine ) | Get text of a specific line |
GetLineCount() | Total number of lines |
GetSelText() | Get the selected text |
GetCurrentPos() | Get cursor position (character offset) |
GetCurrentLineNumber() | Get current line number |
GetModify() | Check if document has unsaved changes |
| Clipboard | |
Copy() / Cut() / Paste() | Standard clipboard operations |
CopyLine() | Copy the entire current line |
CopyRange( nStart, nEnd ) | Copy a character range |
CanUndo() / CanRedo() | Check undo/redo availability |
| Navigation | |
GoLine( nLine ) | Go to a specific line (1-based) |
GoHome() / GoEol() | Go to start/end of line |
GoUp() / GoDown() | Move cursor up/down one line |
GoLeft() / GoRight() | Move cursor left/right one character |
GoAtEnd() | Go to end of document |
| Find & Replace | |
FindText( cText, lForward ) | Search for text forward or backward |
FindNext() / FindPrev() | Find next/previous occurrence of last search |
DlgFindText() | Show find dialog |
DlgReplace() | Show find/replace dialog |
DlgGoToLine() | Show go-to-line dialog |
| Code Folding | |
FoldAllContract() | Collapse all foldable regions |
FoldAllExpand() | Expand all foldable regions |
FoldAllToggle() | Toggle all folding |
| File I/O | |
AddFile( lFin, lHome ) | Load a file into the editor |
CloseF( lEnd ) | Close the current file |
| Brace Matching | |
BraceHighlight( nPos1, nPos2 ) | Highlight matching braces |
BraceBadlight( nPos1, nPos2 ) | Highlight unmatched braces |
BraceMatch( nPos ) | Find the matching brace position |
| Call Tips & Autocomplete | |
CallTipShow( nPosStart, cText ) | Show a calltip popup |
CallTipCancel() | Hide the calltip |
CallTipActive() | Check if a calltip is visible |
| Custom Keys | |
AddKey( nKey, bAction ) | Add a custom key binding |
Example: Source Code Editor
#include "FiveWin.ch"
FUNCTION CodeEditor()
LOCAL oWnd, oSci
DEFINE WINDOW oWnd TITLE "Code Editor"
// Create Scintilla editor filling the window
oSci := TScintilla():New( 0, 0, 800, 600, oWnd, ;
CLR_BLACK, CLR_WHITE, "harbour" )
// Load a source file
oSci:cFileName := "myapp.prg"
oSci:AddFile()
// Custom key bindings
oSci:AddKey( VK_F5, { || CompileAndRun() } )
oSci:AddKey( VK_F3, { || oSci:FindNext() } )
ACTIVATE WINDOW oWnd ;
ON RESIZE ( oSci:Move( 0, 0, nWidth, nHeight, .T. ) )
RETURN NIL
Example: TScintilla with Custom Colors
oSci := TScintilla():New( 0, 0, 800, 600, oWnd, ;
CLR_BLACK, RGB( 30, 30, 30 ), "harbour" )
// Dark theme colors
oSci:cCComment := { CLR_GRAY, RGB(30,30,30), SC_CASE_MIXED }
oSci:cCString := { CLR_HRED, RGB(30,30,30), SC_CASE_MIXED }
oSci:cCNumber := { CLR_RED, RGB(30,30,30), SC_CASE_MIXED }
oSci:cCKeyw1 := { CLR_CYAN, RGB(30,30,30), SC_CASE_MIXED }
oSci:cCKeyw2 := { CLR_YELLOW, RGB(30,30,30), SC_CASE_MIXED }
oSci:nColorSelection := RGB( 255, 255, 255 )
oSci:nColorSelectionB := RGB( 60, 100, 160 )
TRichEdit vs TScintilla
| Feature | TRichEdit | TScintilla |
|---|---|---|
| Primary use | Rich text / document editing | Source code editing |
| RTF formatting | Full support | No |
| Syntax highlighting | Basic (keywords only) | Full lexer-based |
| Code folding | No | Yes |
| Line numbers | Manual | Built-in margin |
| Brace matching | No | Yes |
| Autocomplete | No | Yes |
| Embedded images | OLE objects | No |
| Print / PDF | Built-in | Via report class |
| Windows dependency | Built-in RichEdit DLL | Requires SciLexer.dll |
Tips
- Use
TRichEditfor document editing, letter/memo writing, and any scenario requiring formatted text. - Use
TScintillafor source code editors, script editors, and configuration file editors. - TRichEdit supports
HIGHLIGHTmode for basic syntax highlighting of Harbour code, but TScintilla is far more capable. - TScintilla requires
SciLexer.dll(orScintilla.dll) to be available at runtime. - For TRichEdit, call
SetZoom(2, 1)for 200% zoom -- useful for high-DPI displays. - Both controls support
ON CHANGEto detect modifications in real time.
See Also
- TControl -- parent class
- TGet / TMGet -- simple text input / multiline memo
- TPrinter -- printing support