A richedit control is an edit control that displays RTF (rich text format) data.
RTF is a text description language that uses only standard ASCII characters, so that you can create and view RTF data as ordinary text. For a summary of the language, see file: system\examples\data\rtf.txt.
You can also create RTF data from most Windows editors, for example, WordPad, by saving your text in RTF format. Thus you could create and format some text in WordPad, save it in RTF format, then read in the RTF file and display it in J using a richedit control.
You can also copy and paste between a richedit control and any application, such as WordPad, that supports RTF.
Events and event data for richedit controls are the same as for edit controls. The event data is the simple text from the control, not the rtf data. To read the text in rtf format, use command qrtf
.
Here is a summary of commands applicable to richedit controls:
set
set rtfdata into a richedit control. For example:
wd 'set rid *',rtfdata |
setreplace
replace selected rtfdata in a richedit control For example:
wd 'setreplace rid *',rtfdata |
setbkgnd
set background color. For example:
wd 'setbkgnd rid 255 0 0' |
setreadonly
prevent the user from making changes. For example:
wd 'setreadonly rid' |
qrtf
reads the RTF data from the control. For example:
rtfdata=. wd 'qrtf rid' |
The \
character starts an RTF command and curly braces {}
group data.
Some RTF commands:
\b | bold |
\cfn | color from color table |
\fn | font from font table |
\fsn | font size |
\i | italic |
\par | paragraph (new line) |
\ul | underline |
\b
can be followed by a 0 or 1 to turn the attribute off or on.
The font table definition is enclosed in {}
and each font definition is also enclosed in {}
. For example:
{\fonttbl{\f0\fcourier Courier New;}}
The \fn
command indicates which font to use. For example:
\f0 test
The \fsn
command indicates font size. For example:
\fs90 test
To replace the current selection with "test" in Courier New size 90:
wd 'setreplace rid *{{\fonttbl{\f0\fcourier Courier New;}}\f0\ fs90 test}'
Colors are managed in a manner similar to fonts. Define a color table and then select colors from that table. The following table defines colors black and red:
{\colortbl\red0\green0\blue0;\red255\green0\blue0;}
To replace the current selection with 'test'
in red:
wd 'setreplace rid *{{\colortbl\red0\green0\blue0;\red255\ green0\blue0;}\cf1 test}'
The /
character is an escape character that treats the following character as text. For example to enter a }
as part of text, rather than treat it as a grouping character:
wd 'setreplace red *{the character /{ appears}'
The following example (in script examples\demo\rtf.ijs) creates some RTF data, then displays it in a form with a richeditm control:
rtfdata=: 0 : 0 { {\fonttbl{\f0\fcourier Courier New;}} {\colortbl\red0\green0\blue0;\red255\green0\blue0;} \f0 black \par \b \cf1 bold red \par \i \fs60 big bold italic red } ) wd 0 : 0 pc abc closeok; xywh 148 8 34 12;cc ok button;cn "OK"; xywh 148 23 34 12;cc cancel button;cn "Cancel"; xywh 9 7 128 69;cc rid richeditm es_autovscroll es_sunken; pas 6 6;pcenter; rem form end; ) wd 'set rid *',rtfdata wd 'pshow'