## RichEdit

### Description

The RichEdit class implements the RichEdit control, which is a text input and display control with advanced formatting capabilities, including support for multiple fonts, colors, and styles. Typically, you set the 'selection' properties such as `selcolor` and `selfont` to choose a text format, and then output some text using the `seltext` property. You can then change the format and output some more text. The RichEdit control can also be used for advanced word-processing type applications.

#### RichEdit properties

The main RichEdit properties are:

`style`: The style is a set of flags:

            1 = centered
            2 = right justified
            4 = multiline
           16 = vertical scroll bar
           32 = inhibit auto horizontal scroll (ie word wrap if multiline)
           64 = horizontal scroll bar
         1024 = show selection even when control does not have focus (Windows only)
         4096 = read only
         8192 = allow Enter characters to be input (multi-line only)
        65536 = disable unnecessary scroll bars rather than removing them
    	        (Windows and MacOS only)
       131072 = allow Tab characters to be input, instead of tabbing to next control
                (Windows and MacOS only)

`text`: A character vector containing the text of the whole control. Writing to the text property replaces all the current text in the control. (Under Windows, you can also use the `rtf` property which is the same except that the text is in Rich Text Format and includes formatting information.)

`selection`: A two-element integer vector (start, length) giving the current selection start position (in index origin 0) and length. Writing to the `selection` property changes the selection on the screen, and determines where the next text will be output (i.e. the insertion point). A length of 0 means that no text is selected. A length of ¯1 selects from the given start position to the end of the text.

`seltext`: A character vector containing the text of the selected part of the control. If there is no selection, this is an empty vector. Writing to the `seltext` property deletes any current selection and inserts the text you write, in the current selection font, style and color. (Under Windows, you can also use the `selrtf` property which is the same except that the text is in Rich Text Format and includes formatting information.)

`selcolor`: The current selection color, in the same format as the `color` property.

`selfont`: The current selection font and style, in the same format as the `font` property.

`selstyle`: The current selection style, as a 5-element vector: bold, italic, underline, strikeout, and protected. Valid values for each are 1 = Set, 0 = Clear, ¯1 = Leave unchanged. Setting the 'protected' attribute means the text cannot be changed, even under program control; it must therefore be set only after you have output text to the control. (Note: The 'protected' attribute is not available under MacOS).

`selalign`: The current paragraph alignment, as a character vector keyword. One of 'left', 'right', 'center' (or 'centre')

`selbullet`: The current paragraph bullet style, as a character vector keyword or boolean scalar. One of 'none' (or 0), 'bullet' (or 1)

`selindents`: A three-element numeric vector giving the left, bullet and right indents in the current `scale` of the control

`seltabs`: A numeric vector giving the tab positions in the current `scale` of the control. (Windows only)

`linecount`: (Read-only) The number of lines of text in the control

`range`: (Read-only) A two-element integer vector. The first element is the line number of the first visible line, and the second is the count of lines visible in the control.

#### RichEdit methods

The main RichEdit methods are:

`Clear`: Delete the currently-selected text.

`Cut`: Cut the currently-selected text to the clipboard.

`Copy`: Copy the currently-selected text to the clipboard.

`Paste`: Replace the currently-selected text with the contents of the clipboard.

`Undo`: Undo the last change.

`Print`: Print the contents of the control (with formatting), to the current printer. Can optionally be called with a character-vector argument, which is the print-job name. (You can use the `Setup` and `Job` dialogs in the Printer object to allow the user to configure the printer.)

`Save`: Saves the contents of the rich-edit control to a file. You can specify the file name as the argument, or specify an empty vector in which case a dialog is displayed to allow the user to specify the file name. You can also optionally pass a second argument, to indicate whether the saved file should include formatting information. The valid values are 0 (no formatting, save as plain text), 1 (under Windows, save in Rich Text Format as a .rtf file), or 2 (under MacOS, save as Styled text).

`Load`: Loads the contents of a file into the rich-edit control. You can specify the file name as the argument, or specify an empty vector in which case a dialog is displayed to allow the user to choose a file name. Under Windows, the file can be in Rich Text Format (.rtf), in which case formatted text is loaded.

`Linetochar`: Takes a line number, and returns the position within the text of the first character of the line. Both are in index origin 0.

`Chartoline`: Takes a character position within the text, and returns the number of the line containing the character. Both are in index origin 0.

`Linelength`: Takes a line number (in index origin 0), and returns the length of the line in characters.

### Example

         ’DEMO_RichEdit;TEXT;DEMO
    [1]   © Sample function demonstrating use of the RichEdit object
    [2]   DEMO„'Œ' ŒNEW 'Window' ª DEMO.title„'RichEdit Example'
    [3]   DEMO.myRichEdit.New 'RichEdit' ª DEMO.myRichEdit.align„¯1
    [4]   DEMO.myRichEdit.scale„3 ª DEMO.myRichEdit.border„0
    [5]   DEMO.myRichEdit.selindents„20 20 20
    [6]   ©
    [7]   DEMO.myRichEdit.selection„0
    [8]   DEMO.myRichEdit.selfont„'Times New Roman' 18 1
    [9]   DEMO.myRichEdit.selcolor„220
    [10]  DEMO.myRichEdit.seltext„('Quotation',ŒR)
    [11]  ©
    [12]  DEMO.myRichEdit.selfont„'Times New Roman' 12 0
    [13]  DEMO.myRichEdit.selcolor„0
    [14]  TEXT„ŒR,'Let me not to the marriage of true minds',ŒR
    [15]  TEXT„TEXT,'Admit impediments.  Love is not love',ŒR
    [16]  TEXT„TEXT,'Which alters when it alteration finds,',ŒR
    [17]  TEXT„TEXT,'Or bends with the remover to remove.',ŒR,ŒR
    [18]  DEMO.myRichEdit.seltext„TEXT
    [19]  ©
    [20]  DEMO.myRichEdit.selfont„'Times New Roman' 10 2
    [21]  DEMO.myRichEdit.selalign„'right'
    [22]  DEMO.myRichEdit.seltext„'William Shakespeare'
    [23]  ©
    [24]  © Wait for the user to close the window
    [25]  0 0½ŒWE DEMO
         ’

### Properties

align anchors aquaadjust autodraw border canundo caption children class color data doublebuffered dragsource droptarget enabled events extent font handle limit linecount maxsize methods minsize name opened order pointer properties rtf scale selalign selbullet selcolor selection self selfont selindents selrtf selstyle seltabs seltext size sourceformats style tabstop targetformats text tie units visible where winptr

### Methods

Chartoline Clear Click Clienttoscreen Close Copy Create Cut Delete Draw Focus Hide Linelength Linetochar Load New Open Paint Paste Print Resize Save Screentoclient Send Set Show Trigger Undo

### Callbacks

onChange onClick onClose onDblClick onDestroy onDragDrop onDragEnd onDragEnter onDragLeave onDragOver onDragStart onFocus onHide onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseUp onOpen onSend onShow onUnFocus

Topic: APLX Help : System Classes : List of Classes : RichEdit

[ Previous | Next | Contents | Index ]