StyledText

A StyledText is an editable user interface object that displays lines of text. The following style attributes can be defined for the text: <ul> <li>foreground color <li>background color <li>font style (bold, italic, bold-italic, regular) <li>underline <li>strikeout </ul> <p> In addition to text style attributes, the background color of a line may be specified. </p><p> There are two ways to use this widget when specifying text style information. You may use the API that is defined for StyledText or you may define your own LineStyleListener. If you define your own listener, you will be responsible for maintaining the text style information for the widget. IMPORTANT: You may not define your own listener and use the StyledText API. The following StyledText API is not supported if you have defined a LineStyleListener: <ul> <li>getStyleRangeAtOffset(int) <li>getStyleRanges() <li>replaceStyleRanges(int,int,StyleRange[]) <li>setStyleRange(StyleRange) <li>setStyleRanges(StyleRange[]) </ul> </p><p> There are two ways to use this widget when specifying line background colors. You may use the API that is defined for StyledText or you may define your own LineBackgroundListener. If you define your own listener, you will be responsible for maintaining the line background color information for the widget. IMPORTANT: You may not define your own listener and use the StyledText API. The following StyledText API is not supported if you have defined a LineBackgroundListener: <ul> <li>getLineBackground(int) <li>setLineBackground(int,int,Color) </ul> </p><p> The content implementation for this widget may also be user-defined. To do so, you must implement the StyledTextContent interface and use the StyledText API setContent(StyledTextContent) to initialize the widget. </p><p> <dl> <dt><b>Styles:</b><dd>FULL_SELECTION, MULTI, READ_ONLY, SINGLE, WRAP <dt><b>Events:</b><dd>ExtendedModify, LineGetBackground, LineGetSegments, LineGetStyle, Modify, Selection, Verify, VerifyKey </dl> </p><p> IMPORTANT: This class is <em>not</em> intended to be subclassed. </p>

@see <a href="http://www.eclipse.org/swt/snippets/#styledtext">StyledText snippets</a> @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: CustomControlExample, TextEditor</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

class StyledText : Canvas {
char TAB;
String PlatformLineDelimiter;
String PlatformLineDelimiter;
int BIDI_CARET_WIDTH;
int DEFAULT_WIDTH;
int DEFAULT_HEIGHT;
int V_SCROLL_RATE;
int H_SCROLL_RATE;
int ExtendedModify;
int LineGetBackground;
int LineGetStyle;
int TextChanging;
int TextSet;
int VerifyKey;
int TextChanged;
int LineGetSegments;
int PaintObject;
int WordNext;
int WordPrevious;
int PREVIOUS_OFFSET_TRAILING;
int OFFSET_LEADING;
Color selectionBackground;
Color selectionForeground;
StyledTextContent content;
StyledTextRenderer renderer;
Listener listener;
TextChangeListener textChangeListener;
int verticalScrollOffset;
int horizontalScrollOffset;
int topIndex;
int topIndexY;
int clientAreaHeight;
int clientAreaWidth;
int tabLength;
int leftMargin;
int topMargin;
int rightMargin;
int bottomMargin;
int columnX;
int caretOffset;
int caretAlignment;
Point selection;
Point clipboardSelection;
bool selectedTextValid;
int selectionAnchor;
Point doubleClickSelection;
bool editable;
bool wordWrap;
bool doubleClickEnabled;
bool overwrite;
int textLimit;
int[int] keyActionMap;
Color background;
Color foreground;
Clipboard clipboard;
int clickCount;
int autoScrollDirection;
int autoScrollDistance;
int lastTextChangeStart;
int lastTextChangeNewLineCount;
int lastTextChangeNewCharCount;
int lastTextChangeReplaceLineCount;
int lastTextChangeReplaceCharCount;
int lastLineBottom;
bool isMirrored_;
bool bidiColoring;
Image leftCaretBitmap;
Image rightCaretBitmap;
int caretDirection;
int caretWidth;
Caret defaultCaret;
bool updateCaretDirection;
bool fixedLineHeight;
bool dragDetect_;
IME ime;
int alignment;
bool justify;
int indent;
int lineSpacing;
bool IS_CARBON;
bool IS_GTK;
bool IS_MOTIF;
}

Constructors

this
this(Composite parent, int style)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. <p> The style value is either one of the style constants defined in class <code>SWT</code> which is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses. </p>

Members

Classes

Printing
class Printing

The Printing class : printing of a range of text. An instance of <code>Printing</code> is returned in the StyledText#print(Printer) API. The run() method may be invoked from any thread.

RTFWriter
class RTFWriter

The <code>RTFWriter</code> class is used to write widget content as rich text. The implementation complies with the RTF specification version 1.5. <p> toString() is guaranteed to return a valid RTF string only after close() has been called. </p><p> Whole and partial lines and line breaks can be written. Lines will be formatted using the styles queried from the LineStyleListener, if set, or those set directly in the widget. All styles are applied to the RTF stream like they are rendered by the widget. In addition, the widget font name and size is used for the whole text. </p>

TextWriter
class TextWriter

The <code>TextWriter</code> class is used to write widget content to a string. Whole and partial lines and line breaks can be written. To write partial lines, specify the start and length of the desired segment during object creation. <p> </b>NOTE:</b> <code>toString()</code> is guaranteed to return a valid string only after close() has been called. </p>

Functions

addBidiSegmentListener
void addBidiSegmentListener(BidiSegmentListener listener)

Adds a bidirectional segment listener. <p> A BidiSegmentEvent is sent whenever a line of text is measured or rendered. The user can specify text ranges in the line that should be treated as if they had a different direction than the surrounding text. This may be used when adjacent segments of right-to-left text should not be reordered relative to each other. E.g., Multiple Java string literals in a right-to-left language should generally remain in logical order to each other, that is, the way they are stored. </p>

addExtendedModifyListener
void addExtendedModifyListener(ExtendedModifyListener extendedModifyListener)

Adds an extended modify listener. An ExtendedModify event is sent by the widget when the widget text has changed.

addLineBackgroundListener
void addLineBackgroundListener(LineBackgroundListener listener)

Adds a line background listener. A LineGetBackground event is sent by the widget to determine the background color for a line.

addLineStyleListener
void addLineStyleListener(LineStyleListener listener)

Adds a line style listener. A LineGetStyle event is sent by the widget to determine the styles for a line.

addModifyListener
void addModifyListener(ModifyListener modifyListener)

Adds a modify listener. A Modify event is sent by the widget when the widget text has changed.

addPaintObjectListener
void addPaintObjectListener(PaintObjectListener listener)

Adds a paint object listener. A paint object event is sent by the widget when an object needs to be drawn.

addSelectionListener
void addSelectionListener(SelectionListener listener)

Adds a selection listener. A Selection event is sent by the widget when the user changes the selection. <p> When <code>widgetSelected</code> is called, the event x and y fields contain the start and end caret indices of the selection. <code>widgetDefaultSelected</code> is not called for StyledTexts. </p>

addVerifyKeyListener
void addVerifyKeyListener(VerifyKeyListener listener)

Adds a verify key listener. A VerifyKey event is sent by the widget when a key is pressed. The widget ignores the key press if the listener sets the doit field of the event to false.

addVerifyListener
void addVerifyListener(VerifyListener verifyListener)

Adds a verify listener. A Verify event is sent by the widget when the widget text is about to change. The listener can set the event text and the doit field to change the text that is set in the widget or to force the widget to ignore the text change.

addWordMovementListener
void addWordMovementListener(MovementListener movementListener)

Adds a word movement listener. A movement event is sent when the boundary of a word is needed. For example, this occurs during word next and word previous actions.

append
void append(String string)

Appends a string to the text at the end of the widget.

calculateScrollBars
void calculateScrollBars()

Calculates the scroll bars

calculateTopIndex
void calculateTopIndex(int delta)

Calculates the top index based on the current vertical scroll offset. The top index is the index of the topmost fully visible line or the topmost partially visible line if no line is fully visible. The top index starts at 0.

claimBottomFreeSpace
void claimBottomFreeSpace()

Scrolls down the text to use new space made available by a resize or by deleted lines.

claimRightFreeSpace
void claimRightFreeSpace()

Scrolls text to the right to use new space made available by a resize.

clearSelection
void clearSelection(bool sendEvent)

Removes the widget selection.

copy
void copy()

Copies the selected text to the <code>DND.CLIPBOARD</code> clipboard. <p> The text will be put on the clipboard in plain text format and RTF format. The <code>DND.CLIPBOARD</code> clipboard is used for data that is transferred by keyboard accelerator (such as Ctrl+C/Ctrl+V) or by menu action. </p>

copy
void copy(int clipboardType)

Copies the selected text to the specified clipboard. The text will be put in the clipboard in plain text format and RTF format. <p> The clipboardType is one of the clipboard constants defined in class <code>DND</code>. The <code>DND.CLIPBOARD</code> clipboard is used for data that is transferred by keyboard accelerator (such as Ctrl+C/Ctrl+V) or by menu action. The <code>DND.SELECTION_CLIPBOARD</code> clipboard is used for data that is transferred by selecting text and pasting with the middle mouse button. </p>

createCaretBitmaps
void createCaretBitmaps()

Create the bitmaps to use for the caret in bidi mode. This method only needs to be called upon widget creation and when the font changes (the caret bitmap height needs to match font height).

createKeyBindings
void createKeyBindings()

Creates default key bindings.

cut
void cut()

Moves the selected text to the clipboard. The text will be put in the clipboard in plain text format and RTF format.

doAutoScroll
void doAutoScroll(Event event)

A mouse move event has occurred. See if we should start autoscrolling. If the move position is outside of the client area, initiate autoscrolling. Otherwise, we've moved back into the widget so end autoscrolling.

doAutoScroll
void doAutoScroll(int direction, int distance)

Initiates autoscrolling.

doBackspace
void doBackspace()

Deletes the previous character. Delete the selected text if any. Move the caret in front of the deleted text.

doContent
void doContent(dchar key)

Replaces the selection with the character or insert the character at the current caret position if no selection exists. <p> If a carriage return was typed replace it with the line break character used by the widget on this platform. </p>

doContentEnd
void doContentEnd()

Moves the caret after the last character of the widget content.

doContentStart
void doContentStart()

Moves the caret in front of the first character of the widget content.

doCursorNext
void doCursorNext()

Moves the caret to the end of the selection if a selection exists. Otherwise, if no selection exists move the cursor according to the cursor selection rules.

doCursorPrevious
void doCursorPrevious()

Moves the caret to the start of the selection if a selection exists. Otherwise, if no selection exists move the cursor according to the cursor selection rules.

doDelete
void doDelete()

Deletes the next character. Delete the selected text if any.

doDeleteWordNext
void doDeleteWordNext()

Deletes the next word.

doDeleteWordPrevious
void doDeleteWordPrevious()

Deletes the previous word.

doLineDown
void doLineDown(bool select)

Moves the caret one line down and to the same character offset relative to the beginning of the line. Move the caret to the end of the new line if the new line is shorter than the character offset.

doLineEnd
void doLineEnd()

Moves the caret to the end of the line.

doLineStart
void doLineStart()

Moves the caret to the beginning of the line.

doLineUp
void doLineUp(bool select)

Moves the caret one line up and to the same character offset relative to the beginning of the line. Move the caret to the end of the new line if the new line is shorter than the character offset.

doMouseLocationChange
void doMouseLocationChange(int x, int y, bool select)

Moves the caret to the specified location.

doMouseSelection
void doMouseSelection()

Updates the selection based on the caret position

doMouseWordSelect
int doMouseWordSelect(int x, int newCaretOffset, int line)

Returns the offset of the word at the specified offset. If the current selection extends from high index to low index (i.e., right to left, or caret is at left border of selection on non-bidi platforms) the start offset of the word preceding the selection is returned. If the current selection extends from low index to high index the end offset of the word following the selection is returned.

doPageDown
void doPageDown(bool select, int height)

Scrolls one page down so that the last line (truncated or whole) of the current page becomes the fully visible top line. <p> The caret is scrolled the same number of lines so that its location relative to the top line remains the same. The exception is the end of the text where a full page scroll is not possible. In this case the caret is moved after the last character. </p>

doPageEnd
void doPageEnd()

Moves the cursor to the end of the last fully visible line.

doPageStart
void doPageStart()

Moves the cursor to the beginning of the first fully visible line.

doPageUp
void doPageUp(bool select, int height)

Scrolls one page up so that the first line (truncated or whole) of the current page becomes the fully visible last line. The caret is scrolled the same number of lines so that its location relative to the top line remains the same. The exception is the beginning of the text where a full page scroll is not possible. In this case the caret is moved in front of the first character.

doSelection
void doSelection(int direction)

Updates the selection to extend to the current caret position.

doSelectionCursorNext
void doSelectionCursorNext()

Moves the caret to the next character or to the beginning of the next line if the cursor is at the end of a line.

doSelectionCursorPrevious
void doSelectionCursorPrevious()

Moves the caret to the previous character or to the end of the previous line if the cursor is at the beginning of a line.

doSelectionLineDown
void doSelectionLineDown()

Moves the caret one line down and to the same character offset relative to the beginning of the line. Moves the caret to the end of the new line if the new line is shorter than the character offset. Moves the caret to the end of the text if the caret already is on the last line. Adjusts the selection according to the caret change. This can either add to or subtract from the old selection, depending on the previous selection direction.

doSelectionLineUp
void doSelectionLineUp()

Moves the caret one line up and to the same character offset relative to the beginning of the line. Moves the caret to the end of the new line if the new line is shorter than the character offset. Moves the caret to the beginning of the document if it is already on the first line. Adjusts the selection according to the caret change. This can either add to or subtract from the old selection, depending on the previous selection direction.

doSelectionPageDown
void doSelectionPageDown(int pixels)

Scrolls one page down so that the last line (truncated or whole) of the current page becomes the fully visible top line. <p> The caret is scrolled the same number of lines so that its location relative to the top line remains the same. The exception is the end of the text where a full page scroll is not possible. In this case the caret is moved after the last character. <p></p> Adjusts the selection according to the caret change. This can either add to or subtract from the old selection, depending on the previous selection direction. </p>

doSelectionPageUp
void doSelectionPageUp(int pixels)

Scrolls one page up so that the first line (truncated or whole) of the current page becomes the fully visible last line. <p> The caret is scrolled the same number of lines so that its location relative to the top line remains the same. The exception is the beginning of the text where a full page scroll is not possible. In this case the caret is moved in front of the first character. </p><p> Adjusts the selection according to the caret change. This can either add to or subtract from the old selection, depending on the previous selection direction. </p>

doSelectionWordNext
void doSelectionWordNext()

Moves the caret to the end of the next word .

doSelectionWordPrevious
void doSelectionWordPrevious()

Moves the caret to the start of the previous word.

doVisualNext
void doVisualNext()

Moves the caret one character to the right. Do not go to the next line. When in a bidi locale and at a R2L character the caret is moved to the end of the R2L segment (visually left) and then one character to the right (visually right because it's now in a L2R segment).

doVisualPrevious
void doVisualPrevious()

Moves the caret one character to the left. Do not go to the previous line. When in a bidi locale and at a R2L character the caret is moved to the beginning of the R2L segment (visually right) and then one character to the left (visually left because it's now in a L2R segment).

doWordNext
void doWordNext()

Moves the caret to the end of the next word. If a selection exists, move the caret to the end of the selection and remove the selection.

doWordPrevious
void doWordPrevious()

Moves the caret to the start of the previous word. If a selection exists, move the caret to the start of the selection and remove the selection.

endAutoScroll
void endAutoScroll()

Ends the autoscroll process.

getAlignment
int getAlignment()

Returns the alignment of the widget.

getBaseline
int getBaseline()

Returns the baseline, in pixels.

getBaseline
int getBaseline(int offset)

Returns the baseline at the given offset, in pixels.

getBidiColoring
bool getBidiColoring()

Gets the BIDI coloring mode. When true the BIDI text display algorithm is applied to segments of text that are the same color.

getBidiSegments
int[] getBidiSegments(int lineOffset, String line)

Returns the text segments that should be treated as if they had a different direction than the surrounding text.

getBidiSegmentsCompatibility
int[] getBidiSegmentsCompatibility(String line, int lineOffset)

@see #getBidiSegments Supports deprecated setBidiColoring API. Remove when API is removed.

getBottomIndex
int getBottomIndex()

Returns the index of the last fully visible line.

getCaretOffset
int getCaretOffset()

Returns the caret position relative to the start of the text.

getCaretWidth
int getCaretWidth()

Returns the caret width.

getCharCount
int getCharCount()

Gets the number of characters.

getContent
StyledTextContent getContent()

Returns the content implementation that is used for text storage.

getDoubleClickEnabled
bool getDoubleClickEnabled()

Returns whether the widget implements double click mouse behavior.

getEditable
bool getEditable()

Returns whether the widget content can be edited.

getHorizontalIncrement
int getHorizontalIncrement()

Returns the horizontal scroll increment.

getHorizontalIndex
int getHorizontalIndex()

Returns the horizontal scroll offset relative to the start of the line.

getHorizontalPixel
int getHorizontalPixel()

Returns the horizontal scroll offset relative to the start of the line.

getIndent
int getIndent()

Returns the line indentation of the widget.

getJustify
bool getJustify()

Returns whether the widget justifies lines.

getKeyBinding
int getKeyBinding(int key)

Returns the action assigned to the key. Returns SWT.NULL if there is no action associated with the key.

getLine
String getLine(int lineIndex)

Returns the line at the given line index without delimiters. Index 0 is the first line of the content. When there are not any lines, getLine(0) is a valid call that answers an empty string. <p>

getLineAlignment
int getLineAlignment(int index)

Returns the alignment of the line at the given index.

getLineAtOffset
int getLineAtOffset(int offset)

Returns the line at the specified offset in the text where 0 &lt; offset &lt; getCharCount() so that getLineAtOffset(getCharCount()) returns the line of the insert location.

getLineBackground
Color getLineBackground(int index)

Returns the background color of the line at the given index. Returns null if a LineBackgroundListener has been set or if no background color has been specified for the line. Should not be called if a LineBackgroundListener has been set since the listener maintains the line background colors.

getLineBackgroundData
StyledTextEvent getLineBackgroundData(int lineOffset, String line)

Returns the line background data for the given line or null if there is none.

getLineBullet
Bullet getLineBullet(int index)

Returns the bullet of the line at the given index.

getLineCount
int getLineCount()

Gets the number of text lines.

getLineCountWhole
int getLineCountWhole()

Returns the number of lines that can be completely displayed in the widget client area.

getLineDelimiter
String getLineDelimiter()

Returns the line delimiter used for entering new lines by key down or paste operation.

getLineHeight
int getLineHeight()

Returns the line height. <p> Note: this API should not be used if a StyleRange attribute causes lines to have different heights (i.e. different fonts, rise, etc). </p>

getLineHeight
int getLineHeight(int offset)

Returns the line height at the given offset.

getLineIndent
int getLineIndent(int index)

Returns the indentation of the line at the given index.

getLineIndex
int getLineIndex(int y)

Returns the line index for a y, relative to the client area. The line index returned is always in the range 0..lineCount - 1.

getLineJustify
bool getLineJustify(int index)

Returns whether the line at the given index is justified.

getLinePixel
int getLinePixel(int lineIndex)

Returns the top pixel, relative to the client area, of a given line. Clamps out of ranges index.

getLineSpacing
int getLineSpacing()

Returns the line spacing of the widget.

getLineStyleData
StyledTextEvent getLineStyleData(int lineOffset, String line)

Returns the line style data for the given line or null if there is none. <p> If there is a LineStyleListener but it does not set any styles, the StyledTextEvent.styles field will be initialized to an empty array. </p>

getLocationAtOffset
Point getLocationAtOffset(int offset)

Returns the x, y location of the upper left corner of the character bounding box at the specified offset in the text. The point is relative to the upper left corner of the widget client area.

getModelDelimitedText
String getModelDelimitedText(String text)

Returns a string that uses only the line delimiter specified by the StyledTextContent implementation. <p> Returns only the first line if the widget has the SWT.SINGLE style. </p>

getOffsetAtLine
int getOffsetAtLine(int lineIndex)

Returns the character offset of the first character of the given line.

getOffsetAtLocation
int getOffsetAtLocation(Point point)

Returns the offset of the character at the given location relative to the first character in the document. <p> The return value reflects the character offset that the caret will be placed at if a mouse click occurred at the specified location. If the x coordinate of the location is beyond the center of a character the returned offset will be behind the character. </p>

getOffsetAtPoint
int getOffsetAtPoint(int x, int y, int lineIndex)

Returns the offset at the specified x location in the specified line.

getOrientation
int getOrientation()

Returns the orientation of the receiver.

getPartialBottomIndex
int getPartialBottomIndex()

Returns the index of the last partially visible line.

getPartialTopIndex
int getPartialTopIndex()

Returns the index of the first partially visible line.

getPlatformDelimitedText
String getPlatformDelimitedText(TextWriter writer)

Returns the content in the specified range using the platform line delimiter to separate lines.

getPointAtOffset
Point getPointAtOffset(int offset)

Returns the location of the given offset. <p> <b>NOTE:</b> Does not return correct values for true italic fonts (vs. slanted fonts). </p>

getRanges
int[] getRanges()

Returns all the ranges of text that have an associated StyleRange. Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles. <p> The ranges array contains start and length pairs. Each pair refers to the corresponding style in the styles array. For example, the pair that starts at rangesn with length ranges[n+1] uses the style at styles[n/2] returned by <code>getStyleRanges(int, int, bool)</code>. </p>

getRanges
int[] getRanges(int start, int length)

Returns the ranges of text that have an associated StyleRange. Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles. <p> The ranges array contains start and length pairs. Each pair refers to the corresponding style in the styles array. For example, the pair that starts at rangesn with length ranges[n+1] uses the style at styles[n/2] returned by <code>getStyleRanges(int, int, bool)</code>. </p>

getSelection
Point getSelection()

Returns the selection. <p> Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N </p>

getSelectionBackground
Color getSelectionBackground()

Returns the receiver's selection background color.

getSelectionCount
int getSelectionCount()

Gets the number of selected characters.

getSelectionForeground
Color getSelectionForeground()

Returns the receiver's selection foreground color.

getSelectionRange
Point getSelectionRange()

Returns the selection.

getSelectionText
String getSelectionText()

Returns the selected text.

getStyleRangeAtOffset
StyleRange getStyleRangeAtOffset(int offset)

Returns the style range at the given offset. <p> Returns null if a LineStyleListener has been set or if a style is not set for the offset. Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p>

getStyleRanges
StyleRange[] getStyleRanges()

Returns the styles. <p> Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles. <p></p> Note: Because a StyleRange includes the start and length, the same instance cannot occur multiple times in the array of styles. If the same style attributes, such as font and color, occur in multiple StyleRanges, <code>getStyleRanges(bool)</code> can be used to get the styles without the ranges. </p>

getStyleRanges
StyleRange[] getStyleRanges(bool includeRanges)

Returns the styles. <p> Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p><p> Note: When <code>includeRanges</code> is true, the start and length fields of each StyleRange will be valid, however the StyleRange objects may need to be cloned. When <code>includeRanges</code> is false, <code>getRanges(int, int)</code> can be used to get the associated ranges. </p>

getStyleRanges
StyleRange[] getStyleRanges(int start, int length)

Returns the styles for the given text range. <p> Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p><p> Note: Because the StyleRange includes the start and length, the same instance cannot occur multiple times in the array of styles. If the same style attributes, such as font and color, occur in multiple StyleRanges, <code>getStyleRanges(int, int, bool)</code> can be used to get the styles without the ranges. </p> @param start the start offset of the style ranges to return @param length the number of style ranges to return

getStyleRanges
StyleRange[] getStyleRanges(int start, int length, bool includeRanges)

Returns the styles for the given text range. <p> Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p><p> Note: When <code>includeRanges</code> is true, the start and length fields of each StyleRange will be valid, however the StyleRange objects may need to be cloned. When <code>includeRanges</code> is false, <code>getRanges(int, int)</code> can be used to get the associated ranges. </p>

getTabs
int getTabs()

Returns the tab width measured in characters.

getText
String getText()

Returns a copy of the widget content.

getText
String getText(int start, int end)

Returns the widget content between the two offsets.

getTextBounds
Rectangle getTextBounds(int start, int end)

Returns the smallest bounding rectangle that includes the characters between two offsets.

getTextLimit
int getTextLimit()

Returns the maximum number of characters that the receiver is capable of holding.

getTextRange
String getTextRange(int start, int length)

Returns the widget content starting at start for length characters.

getTopIndex
int getTopIndex()

Gets the top index. <p> The top index is the index of the fully visible line that is currently at the top of the widget or the topmost partially visible line if no line is fully visible. The top index changes when the widget is scrolled. Indexing is zero based. </p>

getTopPixel
int getTopPixel()

Gets the top pixel. <p> The top pixel is the pixel position of the line that is currently at the top of the widget. The text widget can be scrolled by pixels by dragging the scroll thumb so that a partial line may be displayed at the top the widget. The top pixel changes when the widget is scrolled. The top pixel does not include the widget trimming. </p>

getVerticalIncrement
int getVerticalIncrement()

Returns the vertical scroll increment.

getWordWrap
bool getWordWrap()

Returns whether the widget wraps lines.

handleDispose
void handleDispose(Event event)

Frees resources.

handleHorizontalScroll
void handleHorizontalScroll(Event event)

Scrolls the widget horizontally.

handleKey
void handleKey(Event event)

If an action has been registered for the key stroke execute the action. Otherwise, if a character has been entered treat it as new content.

handleKeyDown
void handleKeyDown(Event event)

If a VerifyKey listener exists, verify that the key that was entered should be processed.

handleKeyUp
void handleKeyUp(Event event)

Update the Selection Clipboard.

handleMouseDown
void handleMouseDown(Event event)

Updates the caret location and selection if mouse button 1 has been pressed.

handleMouseMove
void handleMouseMove(Event event)

Updates the caret location and selection if mouse button 1 is pressed during the mouse move.

handleMouseUp
void handleMouseUp(Event event)

Autoscrolling ends when the mouse button is released.

handlePaint
void handlePaint(Event event)

Renders the invalidated area specified in the paint event.

handleResize
void handleResize(Event event)

Recalculates the scroll bars. Rewraps all lines when in word wrap mode.

handleTextChanged
void handleTextChanged(TextChangedEvent event)

Updates the caret position and selection and the scroll bars to reflect the content change.

handleTextChanging
void handleTextChanging(TextChangingEvent event)

Updates the screen to reflect a pending content change.

handleTextSet
void handleTextSet(TextChangedEvent event)

Called when the widget content is set programmatically, overwriting the old content. Resets the caret position, selection and scroll offsets. Recalculates the content width and scroll bars. Redraws the widget.

handleTraverse
void handleTraverse(Event event)

Called when a traversal key is pressed. Allow tab next traversal to occur when the widget is in single line mode or in multi line and non-editable mode . When in editable multi line mode we want to prevent the tab traversal and receive the tab key event instead.

handleVerticalScroll
void handleVerticalScroll(Event event)

Scrolls the widget vertically.

initializeAccessible
void initializeAccessible()

Add accessibility support for the widget.

insert
void insert(String string)

Inserts a string. The old selection is replaced with the new text.

installDefaultContent
void installDefaultContent()

Creates content change listeners and set the default content model.

installListeners
void installListeners()

Adds event listeners

invokeAction
void invokeAction(int action)

Executes the action.

isBidi
bool isBidi()

Temporary until SWT provides this

isLineDelimiter
bool isLineDelimiter(int offset)

Returns whether the given offset is inside a multi byte line delimiter.

isMirrored
bool isMirrored()

Returns whether the widget is mirrored (right oriented/right to left writing order).

isSingleLine
bool isSingleLine()

Returns whether the widget can have only one line.

modifyContent
void modifyContent(Event event, bool updateCaret)

Sends the specified verify event, replace/insert text as defined by the event and send a modify event.

paste
void paste()

Replaces the selection with the text on the <code>DND.CLIPBOARD</code> clipboard or, if there is no selection, inserts the text at the current caret offset. If the widget has the SWT.SINGLE style and the clipboard text contains more than one line, only the first line without line delimiters is inserted in the widget.

print
void print()

Prints the widget's text to the default printer.

print
Runnable print(Printer printer)

Returns a runnable that will print the widget's text to the specified printer. <p> The runnable may be run in a non-UI thread. </p>

print
Runnable print(Printer printer, StyledTextPrintOptions options)

Returns a runnable that will print the widget's text to the specified printer. <p> The runnable may be run in a non-UI thread. </p>

redraw
void redraw()

Causes the entire bounds of the receiver to be marked as needing to be redrawn. The next time a paint request is processed, the control will be completely painted. <p> Recalculates the content width for all lines in the bounds. When a <code>LineStyleListener</code> is used a redraw call is the only notification to the widget that styles have changed and that the content width may have changed. </p>

redraw
void redraw(int x, int y, int width, int height, bool all)

Causes the rectangular area of the receiver specified by the arguments to be marked as needing to be redrawn. The next time a paint request is processed, that area of the receiver will be painted. If the <code>all</code> flag is <code>true</code>, any children of the receiver which intersect with the specified area will also paint their intersecting areas. If the <code>all</code> flag is <code>false</code>, the children will not be painted. <p> Marks the content width of all lines in the specified rectangle as unknown. Recalculates the content width of all visible lines. When a <code>LineStyleListener</code> is used a redraw call is the only notification to the widget that styles have changed and that the content width may have changed. </p>

redrawRange
void redrawRange(int start, int length, bool clearBackground)

Redraws the specified text range.

removeBidiSegmentListener
void removeBidiSegmentListener(BidiSegmentListener listener)

Removes the specified bidirectional segment listener.

removeExtendedModifyListener
void removeExtendedModifyListener(ExtendedModifyListener extendedModifyListener)

Removes the specified extended modify listener.

removeLineBackgroundListener
void removeLineBackgroundListener(LineBackgroundListener listener)

Removes the specified line background listener.

removeLineStyleListener
void removeLineStyleListener(LineStyleListener listener)

Removes the specified line style listener.

removeModifyListener
void removeModifyListener(ModifyListener modifyListener)

Removes the specified modify listener.

removePaintObjectListener
void removePaintObjectListener(PaintObjectListener listener)

Removes the specified listener.

removeSelectionListener
void removeSelectionListener(SelectionListener listener)

Removes the listener from the collection of listeners who will be notified when the user changes the receiver's selection.

removeVerifyKeyListener
void removeVerifyKeyListener(VerifyKeyListener listener)

Removes the specified key verify listener.

removeVerifyListener
void removeVerifyListener(VerifyListener verifyListener)

Removes the specified verify listener.

removeWordMovementListener
void removeWordMovementListener(MovementListener listener)

Removes the specified word movement listener.

replaceStyleRanges
void replaceStyleRanges(int start, int length, StyleRange[] ranges)

Replaces the styles in the given range with new styles. This method effectively deletes the styles in the given range and then adds the the new styles. <p> Note: Because a StyleRange includes the start and length, the same instance cannot occur multiple times in the array of styles. If the same style attributes, such as font and color, occur in multiple StyleRanges, <code>setStyleRanges(int, int, int[], StyleRange[])</code> can be used to share styles and reduce memory usage. </p><p> Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p>

replaceTextRange
void replaceTextRange(int start, int length, String text)

Replaces the given text range with new text. If the widget has the SWT.SINGLE style and "text" contains more than one line, only the first line is rendered but the text is stored unchanged. A subsequent call to getText will return the same text that was set. Note that only a single line of text should be set when the SWT.SINGLE style is used. <p> <b>NOTE:</b> During the replace operation the current selection is changed as follows: <ul> <li>selection before replaced text: selection unchanged <li>selection after replaced text: adjust the selection so that same text remains selected <li>selection intersects replaced text: selection is cleared and caret is placed after inserted text </ul> </p>

reset
void reset()

Resets the caret position, selection and scroll offsets. Recalculate the content width and scroll bars. Redraw the widget.

resetSelection
void resetSelection()

Resets the selection.

scrollHorizontal
bool scrollHorizontal(int pixels, bool adjustScrollBar)

Scrolls the widget horizontally.

scrollVertical
bool scrollVertical(int pixels, bool adjustScrollBar)

Scrolls the widget vertically.

selectAll
void selectAll()

Selects all the text.

sendKeyEvent
void sendKeyEvent(Event event)

Replaces/inserts text as defined by the event.

sendLineEvent
StyledTextEvent sendLineEvent(int eventType, int lineOffset, String line)

Returns a StyledTextEvent that can be used to request data such as styles and background color for a line. <p> The specified line may be a visual (wrapped) line if in word wrap mode. The returned object will always be for a logical (unwrapped) line. </p>

sendSelectionEvent
void sendSelectionEvent()

Sends the specified selection event.

setAlignment
void setAlignment(int alignment)

Sets the alignment of the widget. The argument should be one of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or <code>SWT.RIGHT</code>. The alignment applies for all lines. </p><p> Note that if <code>SWT.MULTI</code> is set, then <code>SWT.WRAP</code> must also be set in order to stabilize the right edge before setting alignment. </p>

setBackground
void setBackground(Color color)

@see Control#setBackground(Color)

setBidiColoring
void setBidiColoring(bool mode)

Sets the BIDI coloring mode. When true the BIDI text display algorithm is applied to segments of text that are the same color.

setCaret
void setCaret(Caret caret)

Sets the receiver's caret. Set the caret's height and location.

setCaretLocation
void setCaretLocation()

Moves the Caret to the current caret offset.

setCaretOffset
void setCaretOffset(int offset)

Sets the caret offset.

setClipboardContent
void setClipboardContent(int start, int length, int clipboardType)

Copies the specified text range to the clipboard. The text will be placed in the clipboard in plain text format and RTF format.

setContent
void setContent(StyledTextContent newContent)

Sets the content implementation to use for text storage.

setCursor
void setCursor(Cursor cursor)

Sets the receiver's cursor to the cursor specified by the argument. Overridden to handle the null case since the StyledText widget uses an ibeam as its default cursor.

setDoubleClickEnabled
void setDoubleClickEnabled(bool enable)

Sets whether the widget : double click mouse behavior. </p>

setEditable
void setEditable(bool editable)

Sets whether the widget content can be edited. </p>

setFont
void setFont(Font font)

Sets a new font to render text with. <p> <b>NOTE:</b> Italic fonts are not supported unless they have no overhang and the same baseline as regular fonts. </p>

setHorizontalIndex
void setHorizontalIndex(int offset)

Sets the horizontal scroll offset relative to the start of the line. Do nothing if there is no text set. <p> <b>NOTE:</b> The horizontal index is reset to 0 when new text is set in the widget. </p>

setHorizontalPixel
void setHorizontalPixel(int pixel)

Sets the horizontal pixel offset relative to the start of the line. Do nothing if there is no text set. <p> <b>NOTE:</b> The horizontal pixel offset is reset to 0 when new text is set in the widget. </p>

setIndent
void setIndent(int indent)

Sets the line indentation of the widget. <p> It is the amount of blank space, in pixels, at the beginning of each line. When a line wraps in several lines only the first one is indented. </p>

setJustify
void setJustify(bool justify)

Sets whether the widget should justify lines.

setKeyBinding
void setKeyBinding(int key, int action)

Maps a key to an action. <p> One action can be associated with N keys. However, each key can only have one action (key:action is N:1 relation). </p>

setLineAlignment
void setLineAlignment(int startLine, int lineCount, int alignment)

Sets the alignment of the specified lines. The argument should be one of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or <code>SWT.RIGHT</code>. <p><p> Note that if <code>SWT.MULTI</code> is set, then <code>SWT.WRAP</code> must also be set in order to stabilize the right edge before setting alignment. </p> Should not be called if a LineStyleListener has been set since the listener maintains the line attributes. </p><p> All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter. </p><p> When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged.

setLineBackground
void setLineBackground(int startLine, int lineCount, Color background)

Sets the background color of the specified lines. <p> The background color is drawn for the width of the widget. All line background colors are discarded when setText is called. The text background color if defined in a StyleRange overlays the line background color. </p><p> Should not be called if a LineBackgroundListener has been set since the listener maintains the line backgrounds. </p><p> All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter. </p><p> When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged. </p>

setLineBullet
void setLineBullet(int startLine, int lineCount, Bullet bullet)

Sets the bullet of the specified lines. <p> Should not be called if a LineStyleListener has been set since the listener maintains the line attributes. </p><p> All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter. </p><p> When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged. </p>

setLineIndent
void setLineIndent(int startLine, int lineCount, int indent)

Sets the indent of the specified lines. <p> Should not be called if a LineStyleListener has been set since the listener maintains the line attributes. </p><p> All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter. </p><p> When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged. </p>

setLineJustify
void setLineJustify(int startLine, int lineCount, bool justify)

Sets the justify of the specified lines. <p> Should not be called if a LineStyleListener has been set since the listener maintains the line attributes. </p><p> All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter. </p><p> When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged. </p>

setLineSpacing
void setLineSpacing(int lineSpacing)

Sets the line spacing of the widget. The line spacing applies for all lines.

setMouseWordSelectionAnchor
void setMouseWordSelectionAnchor()

Flips selection anchor based on word selection direction.

setOrientation
void setOrientation(int orientation)

Sets the orientation of the receiver, which must be one of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.

setScrollBars
void setScrollBars(bool vertical)

Adjusts the maximum and the page size of the scroll bars to reflect content width/length changes.

setSelection
void setSelection(int start)

Sets the selection to the given position and scrolls it into view. Equivalent to setSelection(start,start).

setSelection
void setSelection(Point point)

Sets the selection and scrolls it into view. <p> Indexing is zero based. Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N </p>

setSelection
void setSelection(int start, int end)

Sets the selection and scrolls it into view. <p> Indexing is zero based. Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N </p>

setSelection
void setSelection(int start, int length, bool sendEvent)

Sets the selection. <p> The new selection may not be visible. Call showSelection to scroll the selection into view. </p>

setSelectionBackground
void setSelectionBackground(Color color)

Sets the receiver's selection background color to the color specified by the argument, or to the default system color for the control if the argument is null.

setSelectionForeground
void setSelectionForeground(Color color)

Sets the receiver's selection foreground color to the color specified by the argument, or to the default system color for the control if the argument is null. <p> Note that this is a <em>HINT</em>. Some platforms do not allow the application to change the selection foreground color. </p> @param color the new color (or null)

setSelectionRange
void setSelectionRange(int start, int length)

Sets the selection. <p> The new selection may not be visible. Call showSelection to scroll the selection into view. A negative length places the caret at the visual start of the selection. </p>

setStyleRange
void setStyleRange(StyleRange range)

Adds the specified style. <p> The new style overwrites existing styles for the specified range. Existing style ranges are adjusted if they partially overlap with the new style. To clear an individual style, call setStyleRange with a StyleRange that has null attributes. </p><p> Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p>

setStyleRanges
void setStyleRanges(int start, int length, int[] ranges, StyleRange[] styles)

Clears the styles in the range specified by <code>start</code> and <code>length</code> and adds the new styles. <p> The ranges array contains start and length pairs. Each pair refers to the corresponding style in the styles array. For example, the pair that starts at rangesn with length ranges[n+1] uses the style at styles[n/2]. The range fields within each StyleRange are ignored. If ranges or styles is null, the specified range is cleared. </p><p> Note: It is expected that the same instance of a StyleRange will occur multiple times within the styles array, reducing memory usage. </p><p> Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p>

setStyleRanges
void setStyleRanges(int[] ranges, StyleRange[] styles)

Sets styles to be used for rendering the widget content. <p> All styles in the widget will be replaced with the given set of ranges and styles. The ranges array contains start and length pairs. Each pair refers to the corresponding style in the styles array. For example, the pair that starts at rangesn with length ranges[n+1] uses the style at styles[n/2]. The range fields within each StyleRange are ignored. If either argument is null, the styles are cleared. </p><p> Note: It is expected that the same instance of a StyleRange will occur multiple times within the styles array, reducing memory usage. </p><p> Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p>

setStyleRanges
void setStyleRanges(StyleRange[] ranges)

Sets styles to be used for rendering the widget content. All styles in the widget will be replaced with the given set of styles. <p> Note: Because a StyleRange includes the start and length, the same instance cannot occur multiple times in the array of styles. If the same style attributes, such as font and color, occur in multiple StyleRanges, <code>setStyleRanges(int[], StyleRange[])</code> can be used to share styles and reduce memory usage. </p><p> Should not be called if a LineStyleListener has been set since the listener maintains the styles. </p>

setTabs
void setTabs(int tabs)

Sets the tab width.

setText
void setText(String text)

Sets the widget content. If the widget has the SWT.SINGLE style and "text" contains more than one line, only the first line is rendered but the text is stored unchanged. A subsequent call to getText will return the same text that was set. <p> <b>Note:</b> Only a single line of text should be set when the SWT.SINGLE style is used. </p>

setTextLimit
void setTextLimit(int limit)

Sets the text limit to the specified number of characters. <p> The text limit specifies the amount of text that the user can type into the widget. </p>

setTopIndex
void setTopIndex(int topIndex)

Sets the top index. Do nothing if there is no text set. <p> The top index is the index of the line that is currently at the top of the widget. The top index changes when the widget is scrolled. Indexing starts from zero. Note: The top index is reset to 0 when new text is set in the widget. </p>

setTopPixel
void setTopPixel(int pixel)

Sets the top pixel offset. Do nothing if there is no text set. <p> The top pixel offset is the vertical pixel offset of the widget. The widget is scrolled so that the given pixel position is at the top. The top index is adjusted to the corresponding top line. Note: The top pixel is reset to 0 when new text is set in the widget. </p>

setWordWrap
void setWordWrap(bool wrap)

Sets whether the widget wraps lines. <p> This overrides the creation style bit SWT.WRAP. </p>

showCaret
void showCaret()

Sets the caret location and scrolls the caret offset into view.

showSelection
void showSelection()

Scrolls the selection into view. <p> The end of the selection will be scrolled into view. Note that if a right-to-left selection exists, the end of the selection is the visual beginning of the selection (i.e., where the caret is located). </p>

updateSelection
void updateSelection(int startOffset, int replacedLength, int newLength)

Updates the selection and caret position depending on the text change. <p> If the selection intersects with the replaced text, the selection is reset and the caret moved to the end of the new text. If the selection is behind the replaced text it is moved so that the same text remains selected. If the selection is before the replaced text it is left unchanged. </p>

Static functions

checkStyle
int checkStyle(int style)

Hides the scroll bars if widget is created in single line mode.

Inherited Members

From Canvas

drawBackground
void drawBackground(GC gc, int x, int y, int width, int height)

Fills the interior of the rectangle specified by the arguments, with the receiver's background.

getCaret
Caret getCaret()

Returns the caret. <p> The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time. </p>

getIME
IME getIME()

Returns the IME.

scroll
void scroll(int destX, int destY, int x, int y, int width, int height, bool all)

Scrolls a rectangular area of the receiver by first copying the source area to the destination and then causing the area of the source which is not covered by the destination to be repainted. Children that intersect the rectangle are optionally moved during the operation. In addition, outstanding paint events are flushed before the source area is copied to ensure that the contents of the canvas are drawn correctly.

setCaret
void setCaret(Caret caret)

Sets the receiver's caret. <p> The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time. </p> @param caret the new caret for the receiver, may be null

setIME
void setIME(IME ime)

Sets the receiver's IME.

Meta