#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. More... | |
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. More... | |
bool | AutoComplete (wxTextCompleter *completer) |
Enable auto-completion using the provided completer object. More... | |
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. More... | |
bool | AutoCompleteDirectories () |
Call this function to enable auto-completion of the text using the file system directories. More... | |
virtual bool | CanCopy () const |
Returns true if the selection can be copied to the clipboard. More... | |
virtual bool | CanCut () const |
Returns true if the selection can be cut to the clipboard. More... | |
virtual bool | CanPaste () const |
Returns true if the contents of the clipboard can be pasted into the text control. More... | |
virtual bool | CanRedo () const |
Returns true if there is a redo facility available and the last operation can be redone. More... | |
virtual bool | CanUndo () const |
Returns true if there is an undo facility available and the last operation can be undone. More... | |
virtual void | ChangeValue (const wxString &value) |
Sets the new text control value. More... | |
virtual void | Clear () |
Clears the text in the control. More... | |
virtual void | Copy () |
Copies the selected text to the clipboard. More... | |
virtual void | Cut () |
Copies the selected text to the clipboard and removes it from the control. More... | |
void | ForceUpper () |
Convert all text entered into the control to upper case. More... | |
virtual long | GetInsertionPoint () const |
Returns the insertion point, or cursor, position. More... | |
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. More... | |
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. More... | |
virtual void | GetSelection (long *from, long *to) const |
Gets the current selection span. More... | |
virtual wxString | GetStringSelection () const |
Gets the text currently selected in the control. More... | |
virtual wxString | GetValue () const |
Gets the contents of the control. More... | |
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). More... | |
virtual bool | IsEmpty () const |
Returns true if the control is currently empty. More... | |
virtual void | Paste () |
Pastes text from the clipboard to the text item. More... | |
virtual void | Redo () |
If there is a redo facility and the last operation can be redone, redoes the last operation. More... | |
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. More... | |
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. More... | |
virtual void | SetEditable (bool editable) |
Makes the text item editable or read-only, overriding the wxTE_READONLY flag. More... | |
virtual void | SetInsertionPoint (long pos) |
Sets the insertion point at the given position. More... | |
virtual void | SetInsertionPointEnd () |
Sets the insertion point at the end of the text control. More... | |
virtual void | SetMaxLength (unsigned long len) |
This function sets the maximum number of characters the user can enter into the control. More... | |
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. More... | |
virtual void | SelectAll () |
Selects all text in the control. More... | |
virtual void | SelectNone () |
Deselects selected text in the control. More... | |
virtual bool | SetHint (const wxString &hint) |
Sets a hint shown in an empty unfocused text control. More... | |
virtual wxString | GetHint () const |
Returns the current hint string. More... | |
wxPoint | GetMargins () const |
Returns the margins used by the control. More... | |
virtual void | SetValue (const wxString &value) |
Sets the new text control value. More... | |
virtual void | Undo () |
If there is an undo facility and the last operation can be undone, undoes the last operation. More... | |
virtual void | WriteText (const wxString &text) |
Writes the text into the text control at the current insertion position. More... | |
bool | SetMargins (const wxPoint &pt) |
Attempts to set the control margins. More... | |
bool | SetMargins (wxCoord left, wxCoord top=-1) |
Attempts to set the control margins. More... | |
|
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.
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 returning 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.
completer | The object to be used for generating completions if non-null. If it is nullptr, 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 (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.
void wxTextEntry::ForceUpper | ( | ) |
Convert all text entered into the control to upper case.
Call this method to ensure that all text entered into the control is converted on the fly to upper case. If the control is not empty, its existing contents is also converted to upper case.
|
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, wxComboBox, and wxComboCtrl.
|
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 wxOwnerDrawnComboBox, and 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 macOS.
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.
Another limitation is that hints are ignored for the controls with wxTE_PASSWORD
style.
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 limiting 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.
|
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, wxComboBox, and wxComboCtrl.
|
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 unless the control value doesn't change at all, in which case the insertion point is left at its original position.
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.