#include <wx/textctrl.h>

It may be single line or multi-line.
Styles:
'\n' characters, i.e. in the Unix text format even on non-Unix platforms. This allows the user code to ignore the differences between the platforms but at a price: the indices in the control such as those returned by GetInsertionPoint() or GetSelection() can not be used as indices into the string returned by GetValue() as they're going to be slightly off for platforms using "\\r\\n" as separator (as Windows does).Instead, if you need to obtain a substring between the 2 indices obtained from the control with the help of the functions mentioned above, you should use GetRange(). And the indices themselves can only be passed to other methods, for example SetInsertionPoint() or SetSelection().
To summarize: never use the indices returned by (multiline) wxTextCtrl as indices into the string it contains, but only as arguments to be passed back to the other wxTextCtrl methods. This problem doesn't arise for single-line platforms however where the indices in the control do correspond to the positions in the value string.
wxTE_RICH style is required for style support). To use the styles you can either call SetDefaultStyle() before inserting the text or call SetStyle() later to change the style of the text already in the control (the first solution is much more efficient).In either case, if the style doesn't specify some of the attributes (for example you only want to set the text colour but without changing the font nor the text background), the values of the default style will be used for them. If there is no default style, the attributes of the text control itself are used.
So the following code correctly describes what it does: the second call to SetDefaultStyle() doesn't change the text foreground colour (which stays red) while the last one doesn't change the background colour (which stays grey):
text->SetDefaultStyle(wxTextAttr(*wxRED)); text->AppendText("Red text\n"); text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY)); text->AppendText("Red on grey text\n"); text->SetDefaultStyle(wxTextAttr(*wxBLUE); text->AppendText("Blue on grey text\n");
std::streambuf (except for some really old compilers using non-standard iostream library), allowing code such as the following:
wxTextCtrl *control = new wxTextCtrl(...); ostream stream(control) stream << 123.456 << " some text\n"; stream.flush();
Note that even if your compiler doesn't support this (the symbol wxHAS_TEXT_WINDOW_STREAM has value of 0 then) you can still use wxTextCtrl itself in a stream-like manner:
wxTextCtrl *control = new wxTextCtrl(...); *control << 123.456 << " some text\n";
However the possibility to create an ostream associated with wxTextCtrl may be useful if you need to redirect the output of a function taking an ostream as parameter to a text control.
Another commonly requested need is to redirect std::cout to the text control. This may be done in the following way:
#include <iostream> wxTextCtrl *control = new wxTextCtrl(...); std::streambuf *sbOld = std::cout.rdbuf(); std::cout.rdbuf(control); // use cout as usual, the output appears in the text control ... std::cout.rdbuf(sbOld);
But wxWidgets provides a convenient class to make it even simpler so instead you may just do
#include <iostream> wxTextCtrl *control = new wxTextCtrl(...); wxStreamToTextRedirector redirect(control); // all output to cout goes into the text control until the exit from // current scope
See wxStreamToTextRedirector for more details.
wxID_CUT, wxID_COPY, wxID_PASTE, wxID_UNDO, wxID_REDO. The associated UI update events are also processed automatically, when the control has the focus.Events:
The following event handler macros redirect the events to member function handlers 'func' with prototypes like:
Public Member Functions | |
| wxTextCtrl () | |
| wxTextCtrl (wxWindow *parent, wxWindowID id, const wxString &value="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxTextCtrlNameStr) | |
| virtual | ~wxTextCtrl () |
| void | AppendText (const wxString &text) |
| bool | AutoComplete (const wxArrayString &choices) |
| bool | AutoCompleteFileNames () |
| virtual bool | CanCopy () |
| virtual bool | CanCut () |
| virtual bool | CanPaste () |
| virtual bool | CanRedo () |
| virtual bool | CanUndo () |
| virtual void | ChangeValue (const wxString &value) |
| virtual void | Clear () |
| virtual void | Copy () |
| bool | Create (wxWindow *parent, wxWindowID id, const wxString &value="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxTextCtrlNameStr) |
| virtual void | Cut () |
| virtual void | DiscardEdits () |
| virtual bool | EmulateKeyPress (const wxKeyEvent &event) |
| const wxTextAttr | GetDefaultStyle () const |
| virtual long | GetInsertionPoint () const |
| virtual wxTextPos | GetLastPosition () const |
| virtual int | GetLineLength (long lineNo) const |
| virtual wxString | GetLineText (long lineNo) const |
| virtual int | GetNumberOfLines () const |
| virtual wxString | GetRange (long from, long to) const |
| virtual void | GetSelection (long *from, long *to) const |
| virtual wxString | GetStringSelection () |
| virtual bool | GetStyle (long position, wxTextAttr &style) |
| virtual wxString | GetValue () const |
| wxTextCtrlHitTestResult | HitTest (const wxPoint &pt, wxTextCoord col, wxTextCoord row) const |
| virtual bool | IsEditable () const |
| virtual bool | IsEmpty () const |
| virtual bool | IsModified () const |
| bool | IsMultiLine () const |
| bool | IsSingleLine () const |
| bool | LoadFile (const wxString &filename, int fileType=wxTEXT_TYPE_ANY) |
| virtual void | MarkDirty () |
| void | OnDropFiles (wxDropFilesEvent &event) |
| virtual void | Paste () |
| virtual bool | PositionToXY (long pos, long *x, long *y) const |
| virtual void | Redo () |
| virtual void | Remove (long from, long to) |
| virtual void | Replace (long from, long to, const wxString &value) |
| bool | SaveFile (const wxString &filename, int fileType=wxTEXT_TYPE_ANY) |
| virtual bool | SetDefaultStyle (const wxTextAttr &style) |
| virtual void | SetEditable (const bool editable) |
| virtual void | SetInsertionPoint (long pos) |
| virtual void | SetInsertionPointEnd () |
| virtual void | SetMaxLength (unsigned long len) |
| void | SetModified (bool modified) |
| virtual void | SetSelection (long from, long to) |
| virtual void | SelectAll () |
| virtual bool | SetStyle (long start, long end, const wxTextAttr &style) |
| virtual void | SetValue (const wxString &value) |
| virtual void | ShowPosition (long pos) |
| virtual void | Undo () |
| virtual void | WriteText (const wxString &text) |
| virtual long | XYToPosition (long x, long y) const |
| wxTextCtrl & | operator<< (const wxString &s) |
| wxTextCtrl & | operator<< (int i) |
| wxTextCtrl & | operator<< (long i) |
| wxTextCtrl & | operator<< (float f) |
| wxTextCtrl & | operator<< (double d) |
| wxTextCtrl & | operator<< (char c) |
| wxTextCtrl & | operator<< (wchar_t c) |
| wxTextCtrl::wxTextCtrl | ( | ) |
Default ctor.
| wxTextCtrl::wxTextCtrl | ( | wxWindow * | parent, | |
| wxWindowID | id, | |||
| const wxString & | value = "", |
|||
| const wxPoint & | pos = wxDefaultPosition, |
|||
| const wxSize & | size = wxDefaultSize, |
|||
| long | style = 0, |
|||
| const wxValidator & | validator = wxDefaultValidator, |
|||
| const wxString & | name = wxTextCtrlNameStr | |||
| ) |
Constructor, creating and showing a text control.
| parent | Parent window. Should not be NULL. | |
| id | Control identifier. A value of -1 denotes a default value. | |
| value | Default text value. | |
| pos | Text control position. | |
| size | Text control size. | |
| style | Window style. See wxTextCtrl. | |
| validator | Window validator. | |
| name | Window name. |
| virtual wxTextCtrl::~wxTextCtrl | ( | ) | [virtual] |
Destructor, destroying the text control.
| void wxTextCtrl::AppendText | ( | const wxString & | text | ) |
Appends the text to the end of the text control.
| text | Text to write to the text control. |
| bool wxTextCtrl::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 and wxMSW ports and does nothing under the other platforms.
| bool wxTextCtrl::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 wxGTK2 port and does nothing under the other platforms.
| virtual bool wxTextCtrl::CanCopy | ( | ) | [virtual] |
Returns true if the selection can be copied to the clipboard.
| virtual bool wxTextCtrl::CanCut | ( | ) | [virtual] |
Returns true if the selection can be cut to the clipboard.
| virtual bool wxTextCtrl::CanPaste | ( | ) | [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 wxTextCtrl::CanRedo | ( | ) | [virtual] |
Returns true if there is a redo facility available and the last operation can be redone.
| virtual bool wxTextCtrl::CanUndo | ( | ) | [virtual] |
Returns true if there is an undo facility available and the last operation can be undone.
| virtual void wxTextCtrl::ChangeValue | ( | const wxString & | value | ) | [virtual] |
Sets the text value and marks the control as not-modified (which means that IsModified() would return false immediately after the call to SetValue()).
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.
| value | The new value to set. It may contain newline characters if the text control is multi-line. |
| virtual void wxTextCtrl::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 wxTextCtrl::Copy | ( | ) | [virtual] |
Copies the selected text to the clipboard.
| bool wxTextCtrl::Create | ( | wxWindow * | parent, | |
| wxWindowID | id, | |||
| const wxString & | value = "", |
|||
| const wxPoint & | pos = wxDefaultPosition, |
|||
| const wxSize & | size = wxDefaultSize, |
|||
| long | style = 0, |
|||
| const wxValidator & | validator = wxDefaultValidator, |
|||
| const wxString & | name = wxTextCtrlNameStr | |||
| ) |
Creates the text control for two-step construction.
This method should be called if the default constructor was used for the control creation. Its parameters have the same meaning as for the non-default constructor.
| virtual void wxTextCtrl::Cut | ( | ) | [virtual] |
Copies the selected text to the clipboard and removes the selection.
| virtual void wxTextCtrl::DiscardEdits | ( | ) | [virtual] |
Resets the internal modified flag as if the current changes had been saved.
| virtual bool wxTextCtrl::EmulateKeyPress | ( | const wxKeyEvent & | event | ) | [virtual] |
This functions inserts into the control the character which would have been inserted if the given key event had occurred in the text control.
The event object should be the same as the one passed to EVT_KEY_DOWN handler previously by wxWidgets. Please note that this function doesn't currently work correctly for all keys under any platform but MSW.
| const wxTextAttr wxTextCtrl::GetDefaultStyle | ( | ) | const |
| virtual long wxTextCtrl::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()]; }
| virtual wxTextPos wxTextCtrl::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.
| virtual int wxTextCtrl::GetLineLength | ( | long | lineNo | ) | const [virtual] |
Gets the length of the specified line, not including any trailing newline character(s).
| lineNo | Line number (starting from zero). |
| virtual wxString wxTextCtrl::GetLineText | ( | long | lineNo | ) | const [virtual] |
Returns the contents of a given line in the text control, not including any trailing newline character(s).
| lineNo | The line number, starting from zero. |
| virtual int wxTextCtrl::GetNumberOfLines | ( | ) | const [virtual] |
Returns the number of lines in the text control buffer.
| virtual wxString wxTextCtrl::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 wxTextCtrl::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.
| from | The returned first position. | |
| to | The returned last position. |
| virtual wxString wxTextCtrl::GetStringSelection | ( | ) | [virtual] |
Gets the text currently selected in the control.
If there is no selection, the returned string is empty.
| virtual bool wxTextCtrl::GetStyle | ( | long | position, | |
| wxTextAttr & | style | |||
| ) | [virtual] |
Returns the style at this position in the text control.
Not all platforms support this function.
| virtual wxString wxTextCtrl::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.
| wxTextCtrlHitTestResult wxTextCtrl::HitTest | ( | const wxPoint & | pt, | |
| wxTextCoord | col, | |||
| wxTextCoord | row | |||
| ) | const |
This function finds the character at the specified position expressed in pixels.
If the return code is not wxTE_HT_UNKNOWN the row and column of the character closest to this position are returned in the col and row parameters (unless the pointers are NULL which is allowed). Please note that this function is currently only implemented in wxUniv, wxMSW and wxGTK2 ports.
| virtual bool wxTextCtrl::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 wxTextCtrl::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.
| virtual bool wxTextCtrl::IsModified | ( | ) | const [virtual] |
Returns true if the text has been modified by user.
Note that calling SetValue() doesn't make the control modified.
| bool wxTextCtrl::IsMultiLine | ( | ) | const |
| bool wxTextCtrl::IsSingleLine | ( | ) | const |
Returns true if this is a single line edit control and false otherwise.
| bool wxTextCtrl::LoadFile | ( | const wxString & | filename, | |
| int | fileType = wxTEXT_TYPE_ANY | |||
| ) |
Loads and displays the named file, if it exists.
| filename | The filename of the file to load. | |
| fileType | The type of file to load. This is currently ignored in wxTextCtrl. |
| virtual void wxTextCtrl::MarkDirty | ( | ) | [virtual] |
| void wxTextCtrl::OnDropFiles | ( | wxDropFilesEvent & | event | ) |
This event handler function implements default drag and drop behaviour, which is to load the first dropped file into the control.
| event | The drop files event. |
| virtual void wxTextCtrl::Paste | ( | ) | [virtual] |
Pastes text from the clipboard to the text item.
| virtual bool wxTextCtrl::PositionToXY | ( | long | pos, | |
| long * | x, | |||
| long * | y | |||
| ) | const [virtual] |
Converts given position to a zero-based column, line number pair.
| pos | Position. | |
| x | Receives zero based column number. | |
| y | Receives zero based line number. |
| virtual void wxTextCtrl::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 wxTextCtrl::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.
| from | The first position. | |
| to | The last position. |
| virtual void wxTextCtrl::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.
| from | The first position. | |
| to | The last position. | |
| value | The value to replace the existing text with. |
| bool wxTextCtrl::SaveFile | ( | const wxString & | filename, | |
| int | fileType = wxTEXT_TYPE_ANY | |||
| ) |
Saves the contents of the control in a text file.
| filename | The name of the file in which to save the text. | |
| fileType | The type of file to save. This is currently ignored in wxTextCtrl. |
| virtual bool wxTextCtrl::SetDefaultStyle | ( | const wxTextAttr & | style | ) | [virtual] |
Changes the default style to use for the new text which is going to be added to the control using WriteText() or AppendText().
If either of the font, foreground, or background colour is not set in style, the values of the previous default style are used for them. If the previous default style didn't set them neither, the global font or colours of the text control itself are used as fall back.
However if the style parameter is the default wxTextAttr, then the default style is just reset (instead of being combined with the new style which wouldn't change it at all).
| style | The style for the new text. |
| virtual void wxTextCtrl::SetEditable | ( | const bool | editable | ) | [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. |
| virtual void wxTextCtrl::SetInsertionPoint | ( | long | pos | ) | [virtual] |
Sets the insertion point at the given position.
| pos | Position to set. |
| virtual void wxTextCtrl::SetInsertionPointEnd | ( | ) | [virtual] |
Sets the insertion point at the end of the text control.
This is equivalent to calling wxTextCtrl::SetInsertionPoint() with wxTextCtrl::GetLastPosition() argument.
| virtual void wxTextCtrl::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.
| void wxTextCtrl::SetModified | ( | bool | modified | ) |
| virtual void wxTextCtrl::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.
| from | The first position. | |
| to | The last position. |
| virtual void wxTextCtrl::SelectAll | ( | ) | [virtual] |
| virtual bool wxTextCtrl::SetStyle | ( | long | start, | |
| long | end, | |||
| const wxTextAttr & | style | |||
| ) | [virtual] |
Changes the style of the given range.
If any attribute within style is not set, the corresponding attribute from GetDefaultStyle() is used.
| start | The start of the range to change. | |
| end | The end of the range to change. | |
| style | The new style for the range. |
| virtual void wxTextCtrl::SetValue | ( | const wxString & | value | ) | [virtual] |
Sets the text value and marks the control as not-modified (which means that IsModified() would return false immediately after the call to SetValue()).
Note that this function generates a wxEVT_COMMAND_TEXT_UPDATED 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. |
| virtual void wxTextCtrl::ShowPosition | ( | long | pos | ) | [virtual] |
Makes the line containing the given position visible.
| pos | The position that should be visible. |
| virtual void wxTextCtrl::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 wxTextCtrl::WriteText | ( | const wxString & | text | ) | [virtual] |
Writes the text into the text control at the current insertion position.
| text | Text to write to the text control. |
| virtual long wxTextCtrl::XYToPosition | ( | long | x, | |
| long | y | |||
| ) | const [virtual] |
Converts the given zero based column and line number to a position.
| x | The column number. | |
| y | The line number. |
| wxTextCtrl& wxTextCtrl::operator<< | ( | const wxString & | s | ) |
Operator definitions for appending to a text control.
These operators can be used as with the standard C++ streams, for example:
wxTextCtrl *wnd = new wxTextCtrl(my_frame); (*wnd) << "Welcome to text control number " << 1 << ".\n";
| wxTextCtrl& wxTextCtrl::operator<< | ( | int | i | ) |
Operator definitions for appending to a text control.
These operators can be used as with the standard C++ streams, for example:
wxTextCtrl *wnd = new wxTextCtrl(my_frame); (*wnd) << "Welcome to text control number " << 1 << ".\n";
| wxTextCtrl& wxTextCtrl::operator<< | ( | long | i | ) |
Operator definitions for appending to a text control.
These operators can be used as with the standard C++ streams, for example:
wxTextCtrl *wnd = new wxTextCtrl(my_frame); (*wnd) << "Welcome to text control number " << 1 << ".\n";
| wxTextCtrl& wxTextCtrl::operator<< | ( | float | f | ) |
Operator definitions for appending to a text control.
These operators can be used as with the standard C++ streams, for example:
wxTextCtrl *wnd = new wxTextCtrl(my_frame); (*wnd) << "Welcome to text control number " << 1 << ".\n";
| wxTextCtrl& wxTextCtrl::operator<< | ( | double | d | ) |
Operator definitions for appending to a text control.
These operators can be used as with the standard C++ streams, for example:
wxTextCtrl *wnd = new wxTextCtrl(my_frame); (*wnd) << "Welcome to text control number " << 1 << ".\n";
| wxTextCtrl& wxTextCtrl::operator<< | ( | char | c | ) |
Operator definitions for appending to a text control.
These operators can be used as with the standard C++ streams, for example:
wxTextCtrl *wnd = new wxTextCtrl(my_frame); (*wnd) << "Welcome to text control number " << 1 << ".\n";
| wxTextCtrl& wxTextCtrl::operator<< | ( | wchar_t | c | ) |
Operator definitions for appending to a text control.
These operators can be used as with the standard C++ streams, for example:
wxTextCtrl *wnd = new wxTextCtrl(my_frame); (*wnd) << "Welcome to text control number " << 1 << ".\n";
|
[ top ] |