Text

Instances of this class are selectable user interface objects that allow the user to enter and modify text. Text controls can be either single or multi-line. When a text control is created with a border, the operating system includes a platform specific inset around the contents of the control. When created without a border, an effort is made to remove the inset such that the preferred size of the control is the same size as the contents. <p> <dl> <dt><b>Styles:</b></dt> <dd>CANCEL, CENTER, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd> <dt><b>Events:</b></dt> <dd>DefaultSelection, Modify, Verify</dd> </dl> <p> Note: Only one of the styles MULTI and SINGLE may be specified, and only one of the styles LEFT, CENTER, and RIGHT may be specified. </p><p> IMPORTANT: This class is <em>not</em> intended to be subclassed. </p>

@see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a> @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

class Text : Scrollable {
GtkTextBuffer* bufferHandle;
int tabs;
int lastEventTime;
GdkEventKey* gdkEventKey;
int fixStart;
int fixEnd;
bool doubleClick;
String message;
int INNER_BORDER;
}

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

Functions

addModifyListener
void addModifyListener(ModifyListener listener)

Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in the <code>ModifyListener</code> interface.

addSelectionListener
void addSelectionListener(SelectionListener listener)

Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the <code>SelectionListener</code> interface. <p> <code>widgetSelected</code> is not called for texts. <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text, or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>. </p>

addVerifyListener
void addVerifyListener(VerifyListener listener)

Adds the listener to the collection of listeners who will be notified when the receiver's text is verified, by sending it one of the messages defined in the <code>VerifyListener</code> interface.

append
void append(String string)

Appends a string. <p> The new text is appended to the text at the end of the widget. </p>

clearSelection
void clearSelection()

Clears the selection.

copy
void copy()

Copies the selected text. <p> The current selection is copied to the clipboard. </p>

cut
void cut()

Cuts the selected text. <p> The current selection is first copied to the clipboard and then deleted from the widget. </p>

getCaretLineNumber
int getCaretLineNumber()

Returns the line number of the caret. <p> The line number of the caret is returned. </p>

getCaretLocation
Point getCaretLocation()

Returns a point describing the receiver's location relative to its parent (or its display if its parent is null). <p> The location of the caret is returned. </p>

getCaretPosition
int getCaretPosition()

Returns the character position of the caret. <p> Indexing is zero based. </p>

getCharCount
int getCharCount()

Returns the number of characters.

getDoubleClickEnabled
bool getDoubleClickEnabled()

Returns the double click enabled flag. <p> The double click flag enables or disables the default action of the text widget when the user double clicks. </p>

getEchoChar
char getEchoChar()

Returns the echo character. <p> The echo character is the character that is displayed when the user enters text or the text is changed by the programmer. </p>

getEditable
bool getEditable()

Returns the editable state.

getLineCount
int getLineCount()

Returns the number of lines.

getLineDelimiter
String getLineDelimiter()

Returns the line delimiter.

getLineHeight
int getLineHeight()

Returns the height of a line.

getMessage
String getMessage()

Returns the widget message. When the widget is created with the style <code>SWT.SEARCH</code>, the message text is displayed as a hint for the user, indicating the purpose of the field. <p> Note: This operation is a <em>HINT</em> and is not supported on platforms that do not have this concept. </p>

getOrientation
int getOrientation()

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

getSelection
Point getSelection()

Returns a <code>Point</code> whose x coordinate is the character position representing the start of the selected text, and whose y coordinate is the character position representing the end of the selection. An "empty" selection is indicated by the x and y coordinates having the same value. <p> Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget. </p>

getSelectionCount
int getSelectionCount()

Returns the number of selected characters.

getSelectionText
String getSelectionText()

Gets the selected text, or an empty string if there is no current selection.

getTabs
int getTabs()

Returns the number of tabs. <p> Tab stop spacing is specified in terms of the space (' ') character. The width of a single tab stop is the pixel width of the spaces. </p>

getText
String getText()

Returns the widget text. <p> The text for a text widget is the characters in the widget, or an empty string if this has never been set. </p>

getText
String getText(int start, int end)

Returns a range of text. Returns an empty string if the start of the range is greater than the end. <p> Indexing is zero based. The range of a selection is from 0..N-1 where N is the number of characters in the widget. </p>

getTextLimit
int getTextLimit()

Returns the maximum number of characters that the receiver is capable of holding. <p> If this has not been changed by <code>setTextLimit()</code>, it will be the constant <code>Text.LIMIT</code>. </p>

getTopIndex
int getTopIndex()

Returns the zero-relative index of the line which is currently at the top of the receiver. <p> This index can change when lines are scrolled or new lines are added or removed. </p>

getTopPixel
int getTopPixel()

Returns the top pixel. <p> The top pixel is the pixel position of the line that is currently at the top of the widget. On some platforms, a text widget can be scrolled by pixels instead of lines so that a partial line is displayed at the top of the widget. </p><p> The top pixel changes when the widget is scrolled. The top pixel does not include the widget trimming. </p>

insert
void insert(String string)

Inserts a string. <p> The old selection is replaced with the new text. </p>

paste
void paste()

Pastes text from clipboard. <p> The selected text is deleted from the widget and new text inserted from the clipboard. </p>

removeModifyListener
void removeModifyListener(ModifyListener listener)

Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.

removeSelectionListener
void removeSelectionListener(SelectionListener listener)

Removes the listener from the collection of listeners who will be notified when the control is selected by the user.

removeVerifyListener
void removeVerifyListener(VerifyListener listener)

Removes the listener from the collection of listeners who will be notified when the control is verified.

selectAll
void selectAll()

Selects all the text in the receiver.

setDoubleClickEnabled
void setDoubleClickEnabled(bool doubleClick)

Sets the double click enabled flag. <p> The double click flag enables or disables the default action of the text widget when the user double clicks. </p><p> Note: This operation is a hint and is not supported on platforms that do not have this concept. </p>

setEchoChar
void setEchoChar(char echo)

Sets the echo character. <p> The echo character is the character that is displayed when the user enters text or the text is changed by the programmer. Setting the echo character to '\0' clears the echo character and redraws the original text. If for any reason the echo character is invalid, or if the platform does not allow modification of the echo character, the default echo character for the platform is used. </p>

setEditable
void setEditable(bool editable)

Sets the editable state.

setMessage
void setMessage(String message)

Sets the widget message. When the widget is created with the style <code>SWT.SEARCH</code>, the message text is displayed as a hint for the user, indicating the purpose of the field. <p> Note: This operation is a <em>HINT</em> and is not supported on platforms that do not have this concept. </p>

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>. <p> Note: This operation is a hint and is not supported on platforms that do not have this concept. </p>

setSelection
void setSelection(int start)

Sets the selection. <p> Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget. </p><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. This differs from other functions that address character position such as getText () that use the regular array indexing rules. </p>

setSelection
void setSelection(int start, int end)

Sets the selection to the range specified by the given start and end indices. <p> Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget. </p><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. This differs from other functions that address character position such as getText () that use the usual array indexing rules. </p>

setSelection
void setSelection(Point selection)

Sets the selection to the range specified by the given point, where the x coordinate represents the start index and the y coordinate represents the end index. <p> Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget. </p><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. This differs from other functions that address character position such as getText () that use the usual array indexing rules. </p>

setTabs
void setTabs(int tabs)

Sets the number of tabs. <p> Tab stop spacing is specified in terms of the space (' ') character. The width of a single tab stop is the pixel width of the spaces. </p>

setText
void setText(String string)

Sets the contents of the receiver to the given string. If the receiver has style SINGLE and the argument contains multiple lines of text, the result of this operation is undefined and may vary from platform to platform.

setTextLimit
void setTextLimit(int limit)

Sets the maximum number of characters that the receiver is capable of holding to be the argument. <p> Instead of trying to set the text limit to zero, consider creating a read-only text widget. </p><p> To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>. Specifying a limit value larger than <code>Text.LIMIT</code> sets the receiver's limit to <code>Text.LIMIT</code>. </p>

setTopIndex
void setTopIndex(int index)

Sets the zero-relative index of the line which is currently at the top of the receiver. This index can change when lines are scrolled or new lines are added and removed.

showSelection
void showSelection()

Shows the selection. <p> If the selection is already showing in the receiver, this method simply returns. Otherwise, lines are scrolled until the selection is visible. </p>

Static variables

DELIMITER
String DELIMITER;

The delimiter used by multi-line text widgets. When text is queried and from the widget, it will be delimited using this delimiter.

LIMIT
int LIMIT;

The maximum number of characters that can be entered into a text widget. <p> Note that this value is platform dependent, based upon the native widget implementation. </p>

Inherited Members

From Scrollable

computeTrim
Rectangle computeTrim(int x, int y, int width, int height)

Given a desired <em>client area</em> for the receiver (as described by the arguments), returns the bounding rectangle which would be required to produce that client area. <p> In other words, it returns a rectangle such that, if the receiver's bounds were set to that rectangle, the area of the receiver which is capable of displaying data (that is, not covered by the "trimmings") would be the rectangle described by the arguments (relative to the receiver's parent). </p>

getClientArea
Rectangle getClientArea()

Returns a rectangle which describes the area of the receiver which is capable of displaying data (that is, not covered by the "trimmings").

getHorizontalBar
ScrollBar getHorizontalBar()

Returns the receiver's horizontal scroll bar if it has one, and null if it does not.

getVerticalBar
ScrollBar getVerticalBar()

Returns the receiver's vertical scroll bar if it has one, and null if it does not.

Meta