wxTextEntry Class Reference
[Controls]

#include <wx/textentry.h>

Inheritance diagram for wxTextEntry:
Inheritance graph
[legend]

Detailed Description

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.

Library:  wxCore
Category:  Controls
See also:
wxTextCtrl, wxComboBox

Public Member Functions

virtual void AppendText (const wxString &text)
 Appends the text to the end of the text control.
virtual 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.
virtual 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.
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 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 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.

List of all members.


Member Function Documentation

virtual void wxTextEntry::AppendText ( const wxString text  )  [virtual]

Appends the text to the end of the text control.

Parameters:
text Text to write to the text control.
Remarks:
After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired, the programmer should use GetInsertionPoint() and SetInsertionPoint().
See also:
WriteText()
virtual bool wxTextEntry::AutoComplete ( const wxArrayString choices  )  [virtual]

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 and wxMSW ports and does nothing under the other platforms.

Since:
2.9.0
Returns:
true if the auto-completion was enabled or false if the operation failed, typically because auto-completion is not supported by the current platform.
See also:
AutoCompleteFileNames()
virtual bool wxTextEntry::AutoCompleteFileNames (  )  [virtual]

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 wxGTK2 port and does nothing under the other platforms.

Since:
2.9.0
Returns:
true if the auto-completion was enabled or false if the operation failed, typically because auto-completion is not supported by the current platform.
See also:
AutoComplete()
virtual bool wxTextEntry::CanCopy (  )  const [virtual]

Returns true if the selection can be copied to the clipboard.

virtual bool wxTextEntry::CanCut (  )  const [virtual]

Returns true if the selection can be cut to the clipboard.

virtual bool wxTextEntry::CanPaste (  )  const [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.

virtual bool wxTextEntry::CanRedo (  )  const [virtual]

Returns true if there is a redo facility available and the last operation can be redone.

virtual bool wxTextEntry::CanUndo (  )  const [virtual]

Returns true if there is an undo facility available and the last operation can be undone.

virtual void wxTextEntry::ChangeValue ( const wxString value  )  [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_COMMAND_TEXT_UPDATED event but otherwise is identical to SetValue().

See User Generated Events vs Programmatically Generated Events for more information.

Since:
2.7.1
Parameters:
value The new value to set. It may contain newline characters if the text control is multi-line.
virtual void wxTextEntry::Clear (  )  [virtual]

Clears the text in the control.

Note that this function will generate a wxEVT_COMMAND_TEXT_UPDATED event, i.e. its effect is identical to calling SetValue("").

virtual void wxTextEntry::Copy (  )  [virtual]

Copies the selected text to the clipboard.

virtual wxString wxTextEntry::GetHint (  )  const [virtual]

Returns the current hint string.

See SetHint() for more information about hints.

Since:
2.9.0
virtual long wxTextEntry::GetInsertionPoint (  )  const [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 both GetLastPosition() and "GetValue().Length()" (but notice that the latter equality is not necessarily true for multiline edit controls which may use multiple new line characters).

The following code snippet safely returns the character at the insertion point or the zero character if the point is at the end of the control.

        char GetCurrentChar(wxTextCtrl *tc) {
            if (tc->GetInsertionPoint() == tc->GetLastPosition())
            return '\0';
            return tc->GetValue[tc->GetInsertionPoint()];
        }

Reimplemented in wxComboBox.

virtual wxTextPos wxTextEntry::GetLastPosition (  )  const [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.

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.

Remarks:
If given margin cannot be accurately determined, its value will be set to -1. On some platforms you cannot obtain valid margin values until you have called SetMargins().
See also:
SetMargins()
Since:
2.9.1
virtual wxString wxTextEntry::GetRange ( long  from,
long  to 
) const [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 void wxTextEntry::GetSelection ( long *  from,
long *  to 
) const [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.

Parameters:
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).

virtual wxString wxTextEntry::GetStringSelection (  )  const [virtual]

Gets the text currently selected in the control.

If there is no selection, the returned string is empty.

virtual wxString wxTextEntry::GetValue (  )  const [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.

virtual bool wxTextEntry::IsEditable (  )  const [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().

virtual bool wxTextEntry::IsEmpty (  )  const [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.

Since:
2.7.1
virtual void wxTextEntry::Paste (  )  [virtual]

Pastes text from the clipboard to the text item.

virtual void wxTextEntry::Redo (  )  [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.

virtual void wxTextEntry::Remove ( long  from,
long  to 
) [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.

Parameters:
from The first position.
to The last position.
virtual void wxTextEntry::Replace ( long  from,
long  to,
const wxString value 
) [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.

Parameters:
from The first position.
to The last position.
value The value to replace the existing text with.
virtual void wxTextEntry::SelectAll (  )  [virtual]

Selects all text in the control.

See also:
SetSelection()
virtual void wxTextEntry::SetEditable ( bool  editable  )  [virtual]

Makes the text item editable or read-only, overriding the wxTE_READONLY flag.

Parameters:
editable If true, the control is editable. If false, the control is read-only.
See also:
IsEditable()
virtual void wxTextEntry::SetHint ( const wxString hint  )  [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.

Since:
2.9.0
virtual void wxTextEntry::SetInsertionPoint ( long  pos  )  [virtual]

Sets the insertion point at the given position.

Parameters:
pos Position to set, in the range from 0 to GetLastPosition() inclusive.
virtual void wxTextEntry::SetInsertionPointEnd (  )  [virtual]

Sets the insertion point at the end of the text control.

This is equivalent to calling wxTextCtrl::SetInsertionPoint() with wxTextCtrl::GetLastPosition() argument.

bool wxTextEntry::SetMargins ( wxCoord  left,
wxCoord  top = -1 
)

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.

Returns:
true if setting of all requested margins was successful.
Since:
2.9.1
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.

Returns:
true if setting of all requested margins was successful.
Since:
2.9.1
virtual void wxTextEntry::SetMaxLength ( unsigned long  len  )  [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_COMMAND_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 void wxTextEntry::SetSelection ( long  from,
long  to 
) [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.

Parameters:
from The first position.
to The last position.
See also:
SelectAll()

Reimplemented in wxComboBox.

virtual void wxTextEntry::SetValue ( const wxString value  )  [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_COMMAND_TEXT_UPDATED event. To avoid this you can use ChangeValue() instead.

Parameters:
value The new value to set. It may contain newline characters if the text control is multi-line.

Reimplemented in wxComboBox.

virtual void wxTextEntry::Undo (  )  [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.

virtual void wxTextEntry::WriteText ( const wxString text  )  [virtual]

Writes the text into the text control at the current insertion position.

Parameters:
text Text to write to the text control.
Remarks:
Newlines in the text string are the only control characters allowed, and they will cause appropriate line breaks. See operator<<() and AppendText() for more convenient ways of writing to the window. After the write operation, the insertion point will be at the end of the inserted text, so subsequent write operations will be appended. To append text after the user may have interacted with the control, call wxTextCtrl::SetInsertionPointEnd() before writing.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines



wxWidgets logo

[ top ]