#include <wx/textentry.h>
Common base class for single line text entry fields.
This class is not a control itself, as it doesn't derive from wxWindow. Instead it is used as a base class by other controls, notably wxTextCtrl and wxComboBox and gathers the methods common to both of them.
Public Member Functions | |
virtual void | AppendText (const wxString &text) |
Appends the text to the end of the text control. | |
bool | AutoComplete (const wxArrayString &choices) |
Call this function to enable auto-completion of the text typed in a single-line text control using the given choices. | |
bool | AutoComplete (wxTextCompleter *completer) |
Enable auto-completion using the provided completer object. | |
bool | AutoCompleteFileNames () |
Call this function to enable auto-completion of the text typed in a single-line text control using all valid file system paths. | |
bool | AutoCompleteDirectories () |
Call this function to enable auto-completion of the text using the file system directories. | |
virtual bool | CanCopy () const |
Returns true if the selection can be copied to the clipboard. | |
virtual bool | CanCut () const |
Returns true if the selection can be cut to the clipboard. | |
virtual bool | CanPaste () const |
Returns true if the contents of the clipboard can be pasted into the text control. | |
virtual bool | CanRedo () const |
Returns true if there is a redo facility available and the last operation can be redone. | |
virtual bool | CanUndo () const |
Returns true if there is an undo facility available and the last operation can be undone. | |
virtual void | ChangeValue (const wxString &value) |
Sets the new text control value. | |
virtual void | Clear () |
Clears the text in the control. | |
virtual void | Copy () |
Copies the selected text to the clipboard. | |
virtual void | Cut () |
Copies the selected text to the clipboard and removes it from the control. | |
virtual long | GetInsertionPoint () const |
Returns the insertion point, or cursor, position. | |
virtual wxTextPos | GetLastPosition () const |
Returns the zero based index of the last position in the text control, which is equal to the number of characters in the control. | |
virtual wxString | GetRange (long from, long to) const |
Returns the string containing the text starting in the positions from and up to to in the control. | |
virtual void | GetSelection (long *from, long *to) const |
Gets the current selection span. | |
virtual wxString | GetStringSelection () const |
Gets the text currently selected in the control. | |
virtual wxString | GetValue () const |
Gets the contents of the control. | |
virtual bool | IsEditable () const |
Returns true if the controls contents may be edited by user (note that it always can be changed by the program). | |
virtual bool | IsEmpty () const |
Returns true if the control is currently empty. | |
virtual void | Paste () |
Pastes text from the clipboard to the text item. | |
virtual void | Redo () |
If there is a redo facility and the last operation can be redone, redoes the last operation. | |
virtual void | Remove (long from, long to) |
Removes the text starting at the first given position up to (but not including) the character at the last position. | |
virtual void | Replace (long from, long to, const wxString &value) |
Replaces the text starting at the first position up to (but not including) the character at the last position with the given text. | |
virtual void | SetEditable (bool editable) |
Makes the text item editable or read-only, overriding the wxTE_READONLY flag. | |
virtual void | SetInsertionPoint (long pos) |
Sets the insertion point at the given position. | |
virtual void | SetInsertionPointEnd () |
Sets the insertion point at the end of the text control. | |
virtual void | SetMaxLength (unsigned long len) |
This function sets the maximum number of characters the user can enter into the control. | |
virtual void | SetSelection (long from, long to) |
Selects the text starting at the first position up to (but not including) the character at the last position. | |
virtual void | SelectAll () |
Selects all text in the control. | |
virtual void | SelectNone () |
Deselects selected text in the control. | |
virtual bool | SetHint (const wxString &hint) |
Sets a hint shown in an empty unfocused text control. | |
virtual wxString | GetHint () const |
Returns the current hint string. | |
wxPoint | GetMargins () const |
Returns the margins used by the control. | |
virtual void | SetValue (const wxString &value) |
Sets the new text control value. | |
virtual void | Undo () |
If there is an undo facility and the last operation can be undone, undoes the last operation. | |
virtual void | WriteText (const wxString &text) |
Writes the text into the text control at the current insertion position. | |
bool | SetMargins (const wxPoint &pt) |
Attempts to set the control margins. | |
bool | SetMargins (wxCoord left, wxCoord top=-1) |
Attempts to set the control margins. | |
|
virtual |
Appends the text to the end of the text control.
text | Text to write to the text control. |
Reimplemented in wxStyledTextCtrl.
bool wxTextEntry::AutoComplete | ( | const wxArrayString & | choices | ) |
Call this function to enable auto-completion of the text typed in a single-line text control using the given choices.
Notice that currently this function is only implemented in wxGTK2, wxMSW and wxOSX/Cocoa (for wxTextCtrl only, but not for wxComboBox) ports and does nothing under the other platforms.
bool wxTextEntry::AutoComplete | ( | wxTextCompleter * | completer | ) |
Enable auto-completion using the provided completer object.
This method should be used instead of AutoComplete() overload taking the array of possible completions if the total number of strings is too big as it allows to return the completions dynamically, depending on the text already entered by user and so is more efficient.
The specified completer object will be used to retrieve the list of possible completions for the already entered text and will be deleted by wxTextEntry itself when it's not needed any longer.
Notice that you need to include wx/textcompleter.h
in order to define your class inheriting from wxTextCompleter.
Currently this method is only implemented in wxMSW and wxOSX/Cocoa (for wxTextCtrl only, but not for wxComboBox).
completer | The object to be used for generating completions if non-NULL. If it is NULL, auto-completion is disabled. The wxTextEntry object takes ownership of this pointer and will delete it in any case (i.e. even if this method returns false). |
bool wxTextEntry::AutoCompleteDirectories | ( | ) |
Call this function to enable auto-completion of the text using the file system directories.
Unlike AutoCompleteFileNames() which completes both file names and directories, this function only completes the directory names.
Notice that currently this function is only implemented in wxMSW port and does nothing under the other platforms.
bool wxTextEntry::AutoCompleteFileNames | ( | ) |
Call this function to enable auto-completion of the text typed in a single-line text control using all valid file system paths.
Notice that currently this function is only implemented in wxMSW port and does nothing under the other platforms.
|
virtual |
Returns true if the selection can be copied to the clipboard.
|
virtual |
Returns true if the selection can be cut to the clipboard.
|
virtual |
Returns true if the contents of the clipboard can be pasted into the text control.
On some platforms (Motif, GTK) this is an approximation and returns true if the control is editable, false otherwise.
Reimplemented in wxStyledTextCtrl.
|
virtual |
Returns true if there is a redo facility available and the last operation can be redone.
Reimplemented in wxStyledTextCtrl.
|
virtual |
Returns true if there is an undo facility available and the last operation can be undone.
Reimplemented in wxStyledTextCtrl.
|
virtual |
Sets the new text control value.
It also marks the control as not-modified which means that IsModified() would return false immediately after the call to ChangeValue().
The insertion point is set to the start of the control (i.e. position 0) by this function.
This functions does not generate the wxEVT_TEXT
event but otherwise is identical to SetValue().
See User Generated Events vs Programmatically Generated Events for more information.
value | The new value to set. It may contain newline characters if the text control is multi-line. |
|
virtual |
Clears the text in the control.
Note that this function will generate a wxEVT_TEXT
event, i.e. its effect is identical to calling SetValue
("").
Reimplemented in wxStyledTextCtrl.
|
virtual |
Copies the selected text to the clipboard.
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
|
virtual |
Copies the selected text to the clipboard and removes it from the control.
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
|
virtual |
Returns the current hint string.
See SetHint() for more information about hints.
Reimplemented in wxComboCtrl.
|
virtual |
Returns the insertion point, or cursor, position.
This is defined as the zero based index of the character position to the right of the insertion point. For example, if the insertion point is at the end of the single-line text control, it is equal to GetLastPosition().
Notice that insertion position is, in general, different from the index of the character the cursor position at in the string returned by GetValue(). While this is always the case for the single line controls, multi-line controls can use two characters "\\r\\n"
as line separator (this is notably the case under MSW) meaning that indices in the control and its string value are offset by 1 for every line.
Hence to correctly get the character at the current cursor position, taking into account that there can be none if the cursor is at the end of the string, you could do the following:
Reimplemented in wxStyledTextCtrl, wxComboCtrl, and wxComboBox.
|
virtual |
Returns the zero based index of the last position in the text control, which is equal to the number of characters in the control.
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
wxPoint wxTextEntry::GetMargins | ( | ) | const |
Returns the margins used by the control.
The x
field of the returned point is the horizontal margin and the y
field is the vertical one.
|
virtual |
Returns the string containing the text starting in the positions from and up to to in the control.
The positions must have been returned by another wxTextCtrl method. Please note that the positions in a multiline wxTextCtrl do not correspond to the indices in the string returned by GetValue() because of the different new line representations (CR
or CR
LF) and so this method should be used to obtain the correct results instead of extracting parts of the entire value. It may also be more efficient, especially if the control contains a lot of data.
|
virtual |
Gets the current selection span.
If the returned values are equal, there was no selection. Please note that the indices returned may be used with the other wxTextCtrl methods but don't necessarily represent the correct indices into the string returned by GetValue() for multiline controls under Windows (at least,) you should use GetStringSelection() to get the selected text.
from | The returned first position. |
to | The returned last position. |
wxPerl Note: In wxPerl this method takes no parameters and returns a 2-element list (from, to).
Reimplemented in wxStyledTextCtrl, and wxComboBox.
|
virtual |
Gets the text currently selected in the control.
If there is no selection, the returned string is empty.
Reimplemented in wxComboBox.
|
virtual |
Gets the contents of the control.
Notice that for a multiline text control, the lines will be separated by (Unix-style) \n
characters, even under Windows where they are separated by a \r\n
sequence in the native control.
Reimplemented in wxComboCtrl.
|
virtual |
Returns true if the controls contents may be edited by user (note that it always can be changed by the program).
In other words, this functions returns true if the control hasn't been put in read-only mode by a previous call to SetEditable().
Reimplemented in wxStyledTextCtrl.
|
virtual |
Returns true if the control is currently empty.
This is the same as GetValue()
.empty() but can be much more efficient for the multiline controls containing big amounts of text.
Reimplemented in wxComboBox.
|
virtual |
Pastes text from the clipboard to the text item.
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
|
virtual |
If there is a redo facility and the last operation can be redone, redoes the last operation.
Does nothing if there is no redo facility.
Reimplemented in wxStyledTextCtrl.
|
virtual |
Removes the text starting at the first given position up to (but not including) the character at the last position.
This function puts the current insertion point position at to as a side effect.
from | The first position. |
to | The last position. |
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
|
virtual |
Replaces the text starting at the first position up to (but not including) the character at the last position with the given text.
This function puts the current insertion point position at to as a side effect.
from | The first position. |
to | The last position. |
value | The value to replace the existing text with. |
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
|
virtual |
|
virtual |
|
virtual |
Makes the text item editable or read-only, overriding the wxTE_READONLY flag.
editable | If true, the control is editable. If false, the control is read-only. |
Reimplemented in wxStyledTextCtrl.
|
virtual |
Sets a hint shown in an empty unfocused text control.
The hints are usually used to indicate to the user what is supposed to be entered into the given entry field, e.g. a common use of them is to show an explanation of what can be entered in a wxSearchCtrl.
The hint is shown (usually greyed out) for an empty control until it gets focus and is shown again if the control loses it and remains empty. It won't be shown once the control has a non-empty value, although it will be shown again if the control contents is cleared. Because of this, it generally only makes sense to use hints with the controls which are initially empty.
Notice that hints are known as cue banners under MSW or placeholder strings under OS X.
For the platforms without native hints support, the implementation has several known limitations. Notably, the hint display will not be properly updated if you change wxTextEntry contents programmatically when the hint is displayed using methods other than SetValue() or ChangeValue() or others which use them internally (e.g. Clear()). In other words, currently you should avoid calling methods such as WriteText() or Replace() when using hints and the text control is empty. If you bind to the control's focus and wxEVT_TEXT events, you must call wxEvent::Skip() on them so that the generic implementation works correctly.
Reimplemented in wxComboCtrl.
|
virtual |
Sets the insertion point at the given position.
pos | Position to set, in the range from 0 to GetLastPosition() inclusive. |
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
|
virtual |
Sets the insertion point at the end of the text control.
This is equivalent to calling wxTextCtrl::SetInsertionPoint() with wxTextCtrl::GetLastPosition() argument.
Reimplemented in wxComboCtrl.
bool wxTextEntry::SetMargins | ( | const wxPoint & | pt | ) |
Attempts to set the control margins.
When margins are given as wxPoint, x indicates the left and y the top margin. Use -1 to indicate that an existing value should be used.
Attempts to set the control margins.
When margins are given as wxPoint, x indicates the left and y the top margin. Use -1 to indicate that an existing value should be used.
|
virtual |
This function sets the maximum number of characters the user can enter into the control.
In other words, it allows to limit the text value length to len not counting the terminating NUL
character.
If len is 0, the previously set max length limit, if any, is discarded and the user may enter as much text as the underlying native text control widget supports (typically at least 32Kb). If the user tries to enter more characters into the text control when it already is filled up to the maximal length, a wxEVT_TEXT_MAXLEN
event is sent to notify the program about it (giving it the possibility to show an explanatory message, for example) and the extra input is discarded.
Note that in wxGTK this function may only be used with single line text controls.
|
virtual |
Selects the text starting at the first position up to (but not including) the character at the last position.
If both parameters are equal to -1 all text in the control is selected.
Notice that the insertion point will be moved to from by this function.
from | The first position. |
to | The last position. |
Reimplemented in wxStyledTextCtrl, wxComboCtrl, and wxComboBox.
|
virtual |
Sets the new text control value.
It also marks the control as not-modified which means that IsModified() would return false immediately after the call to SetValue().
The insertion point is set to the start of the control (i.e. position 0) by this function.
Note that, unlike most other functions changing the controls values, this function generates a wxEVT_TEXT
event. To avoid this you can use ChangeValue() instead.
value | The new value to set. It may contain newline characters if the text control is multi-line. |
Reimplemented in wxComboCtrl, and wxComboBox.
|
virtual |
If there is an undo facility and the last operation can be undone, undoes the last operation.
Does nothing if there is no undo facility.
Reimplemented in wxStyledTextCtrl, and wxComboCtrl.
|
virtual |
Writes the text into the text control at the current insertion position.
text | Text to write to the text control. |
Reimplemented in wxStyledTextCtrl.