wxTextCtrl(3)
β¨ NAME β¨
okay so this is the manual page for wxTextCtrl(3) β a text control that lets text be, like, displayed and edited. that's it, that's the whole vibe. π
πΈ DESCRIPTION πΈ
so a text control can be single line or multi-line, your choice. one thing to clock tho: a lot of the methods you'd expect to live here actually live in the base class wxTextEntry (which is not implemented in wx, so don't come looking for it), and that class is the shared base for wxTextCtrl and all the other controls that use a single line text entry field (hi wxComboBox π).
π Styles π
this class supports the following styles, bestie, memorize them:
wxTE_PROCESS_ENTERβ the control will generate the eventwxEVT_TEXT_ENTERthat the program can handle. otherwise β meaning either you didn't specify this style at all, or you did but there's no event handler for this event, or the event handler calledwxEvent:skip/2to avoid overriding the default handling β pressing the Enter key is either processed internally by the control or used to activate the default button of the dialog, if there is one.wxTE_PROCESS_TABβ normally TAB is the keyboard-navigation key, and pressing it in a control moves focus to the next one. with this style that doesn't happen, and if the TAB isn't otherwise processed (e.g. by awxEVT_CHARevent handler), a literal TAB character gets inserted into the control. note that this style has no effect for single-line text controls when usingwxGTK.wxTE_MULTILINEβ the text control allows multiple lines. if you don't specify this style, line break characters should not be used in the control's value. π«wxTE_PASSWORDβ the text will be echoed as asterisks. secret girl stuff πwxTE_READONLYβ the text will not be user-editable.wxTE_RICHβ use a rich text control under MSW; this allows having more than 64KB of text in the control. this style is ignored under other platforms.wxTE_RICH2β use rich text control version 2.0 or higher under MSW; this style is ignored under other platforms.wxTE_AUTO_URLβ highlight the URLs and generate thewxTextUrlEventswhen mouse events occur over them.wxTE_NOHIDESELβ by default, the Windows text control doesn't show the selection when it doesn't have focus. use this style to force it to always show it. it doesn't do anything under other platforms.wxHSCROLLβ a horizontal scrollbar will be created and used, so that text won't be wrapped. no effect underwxGTK1.wxTE_NO_VSCROLLβ for multiline controls only: the vertical scrollbar will never be created. this limits the amount of text which can be entered into the control to what can be displayed in it underwxMSW, but not underwxGTKorwxOSX. currently not implemented for the other platforms.wxTE_LEFTβ the text in the control will be left-justified (this is the default).wxTE_CENTREβ the text in the control will be centered (wxMSW,wxGTK,wxOSX).wxTE_RIGHTβ the text in the control will be right-justified (wxMSW,wxGTK,wxOSX).wxTE_DONTWRAPβ same aswxHSCROLLstyle: don't wrap at all, show a horizontal scrollbar instead.wxTE_CHARWRAPβ for multiline controls only: wrap the lines too long to be shown entirely at any position (wxUniv,wxGTK,wxOSX).wxTE_WORDWRAPβ for multiline controls only: wrap the lines too long to be shown entirely at word boundaries (wxUniv,wxMSW,wxGTK,wxOSX).wxTE_BESTWRAPβ for multiline controls only: wrap the lines at word boundaries or at any other character if there are words longer than the window width (this is the default).wxTE_CAPITALIZEβ on PocketPC and Smartphone, causes the first letter to be capitalized. π
heads up: alignment styles (wxTE_LEFT,wxTE_CENTREandwxTE_RIGHT) can be changed dynamically after control creation onwxMSW,wxGTKandwxOSX.wxTE_READONLY,wxTE_PASSWORDand wrapping styles can be dynamically changed underwxGTKbut notwxMSW. every other style can only be set during control creation, periodt.
π¦ wxTextCtrl Text Format π¦
multiline text controls always store the text as a sequence of lines separated by '\n' characters β i.e. in the Unix text format even on non-Unix platforms. this is a whole gift because it lets your user code ignore the differences between platformsβ¦ but at a price π: the indices in the control, like the ones returned by getInsertionPoint/1 or getSelection/1, can not be used as indices into the string returned by getValue/1, because they're going to be slightly off for platforms using "\\r\\n" as separator (the way Windows does).
so instead: if you need a substring between the 2 indices you got from the control via those functions mentioned above, you should use getRange/3. and the indices themselves can only be passed to other methods, for example setInsertionPoint/2 or setSelection/3.
to summarize, and this is the important bit: never use the indices returned by a (multiline) wxTextCtrl as indices into the string it contains β only as arguments to be passed back to the other wxTextCtrl methods. no cap. this problem doesn't arise for single-line platforms tho, where the indices in the control do correspond to the positions in the value string. π
π wxTextCtrl Positions and Coordinates π
you can work with either linear positions β i.e. roughly (but not always exactly, as explained up there ^^^) the index of the character in the text contained in the control β or X-Y coordinates, i.e. column and line of the character. this class provides positionToXY/2 and xYToPosition/3 to convert between the two.
also, a position in the control can be converted to its coordinates in pixels using PositionToCoords() (not implemented in wx), which is useful for stuff like showing a popup menu near a given character. and going the other way, HitTest() (not implemented in wx) can be used to find the character under, or near, the given pixel coordinates.
to be more precise: positions actually refer to the gaps between characters, not the characters themselves. so position 0 is the one before the very first character in the control, which means it's a valid position even when the control is empty β¨. and if the control contains a single character, it has two valid positions: 0 before that character and 1 after it. which means that when the docs of various functions mention "invalid position", they do not consider the position just after the last character of the line invalid β only the positions beyond that one (e.g. 2 and greater in the single character example) are actually invalid.
π wxTextCtrl Styles. π
multi-line text controls support styling, i.e. they let you set colours and font for individual characters in them (note: under Windows the wxTE_RICH style is required for style support). to use the styles you can either call setDefaultStyle/2 before inserting the text, or call setStyle/4 later to change the style of the text already in the control β and the first solution is much more efficient, so do that one. π₯
either way, if the style doesn't specify some of the attributes (like, say you only want to set the text colour but without changing the font or the text background), the values of the default style will be used for them. and if there's 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/2 doesn't change the text foreground colour (which stays red) while the last one doesn't change the background colour (which stays grey):
π§ wxTextCtrl and C++ Streams π§
this class multiply-inherits from std::streambuf (except for some really old compilers using a non-standard iostream library), allowing code such as the following:
note that even if your build of wxWidgets 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:
however, the possibility to create a std::ostream associated with wxTextCtrl may be useful if you need to redirect the output of a function taking a std::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:
but wxWidgets provides a convenient class to make it even simpler, so instead you may just do
see wxStreamToTextRedirector (not implemented in wx) for more details.
β Event Handling. β
the following commands are processed by default event handlers in wxTextCtrl: 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.
see: create/4
this class is derived, and can use functions, from:
wxControlwxWindowwxEvtHandler
wxWidgets docs: wxTextCtrl
π« Events π«
event types emitted from this class:
command_text_updatedcommand_text_entertext_maxlen
π DATA TYPES π
wxTextCtrl() :: wx:wx_object().
π FUNCTIONS π
appendText(This, Text) -> ok
when
This :: wxTextCtrl(), Text :: unicode:chardata().
appends the text to the end of the text control.
Remark: after the text is appended, the insertion point will be at the end of the text control. if that behaviour is not desired, the programmer should use getInsertionPoint/1 and setInsertionPoint/2.
see: writeText/2
canCopy(This) -> boolean() when This :: wxTextCtrl().
returns true if the selection can be copied to the clipboard. π
canCut(This) -> boolean() when This :: wxTextCtrl().
returns true if the selection can be cut to the clipboard. βοΈ
canPaste(This) -> boolean() when This :: wxTextCtrl().
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.
canRedo(This) -> boolean() when This :: wxTextCtrl().
returns true if there is a redo facility available and the last operation can be redone.
canUndo(This) -> boolean() when This :: wxTextCtrl().
returns true if there is an undo facility available and the last operation can be undone. β©οΈ
changeValue(This, Value) -> ok
when
This :: wxTextCtrl(),
Value :: unicode:chardata().
sets the new text control value.
it also marks the control as not-modified, which means IsModified() would return false immediately after the call to changeValue/2.
the insertion point is set to the start of the control (i.e. position 0) by this function.
This one does not generate the wxEVT_TEXT event, but otherwise it's literally identical to setValue/2. π
Peep overview_events_prog for more info. π
Since: 2.7.1
π§Ό clear(This) -> ok when This :: wxTextCtrl().
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(""). No cap.
π copy(This) -> ok when This :: wxTextCtrl().
Copies the selected text to the clipboard. π
π create(This, Parent, Id, [Option]) -> boolean()
create(This, Parent, Id, [Option]) -> boolean()
when
This :: wxTextCtrl(),
Parent :: wxWindow:wxWindow(),
Id :: integer(),
Option ::
{value, unicode:chardata()} |
{pos, {X :: integer(), Y :: integer()}} |
{size, {W :: integer(), H :: integer()}} |
{style, integer()} |
{validator, wx:wx_object()}.
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. π
βοΈ cut(This) -> ok when This :: wxTextCtrl().
Copies the selected text to the clipboard and removes it from the control. π«Ά
π destroy(This :: wxTextCtrl()) -> ok.
Destroys the object. π
π§½ discardEdits(This) -> ok when This :: wxTextCtrl().
Resets the internal modified flag as if the current changes had been saved. β¨
β¨οΈ emulateKeyPress(This, Event) -> boolean()
emulateKeyPress(This, Event) -> boolean()
when
This :: wxTextCtrl(),
Event :: wxKeyEvent:wxKeyEvent().
This function 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. π
Return: true if the event resulted in a change to the control, false otherwise.
π¨ getDefaultStyle(This) -> wxTextAttr:wxTextAttr()
getDefaultStyle(This) -> wxTextAttr:wxTextAttr()
when This :: wxTextCtrl().
Returns the style currently used for the new text. β¨
See: setDefaultStyle/2
π getInsertionPoint(This) -> integer()
getInsertionPoint(This) -> integer() when This :: wxTextCtrl().
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/1. π¦
Notice that insertion position is, in general, different from the index of the character the cursor position at in the string returned by getValue/1. 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:
π getLastPosition(This) -> integer()
getLastPosition(This) -> integer() when This :: wxTextCtrl().
Returns the zero based index of the last position in the text control, which is equal to the number of characters in the control. π
π getLineLength(This, LineNo) -> integer()
getLineLength(This, LineNo) -> integer()
when This :: wxTextCtrl(), LineNo :: integer().
Gets the length of the specified line, not including any trailing newline character(s). πΈ
Return: The length of the line, or -1 if lineNo was invalid.
π getLineText(This, LineNo) -> unicode:charlist()
getLineText(This, LineNo) -> unicode:charlist()
when This :: wxTextCtrl(), LineNo :: integer().
Returns the contents of a given line in the text control, not including any trailing newline character(s). π
Return: The contents of the line.
π’ getNumberOfLines(This) -> integer()
getNumberOfLines(This) -> integer() when This :: wxTextCtrl().
Returns the number of lines in the text control buffer. π¦
The returned number is the number of logical lines, i.e. just the count of the number of newline characters in the control + 1, for wxGTK and wxOSX/Cocoa ports while it is the number of physical lines, i.e. the count of lines actually shown in the control, in wxMSW. Because of this discrepancy, it is not recommended to use this function. π
Remark: Note that even empty text controls have one line (where the insertion point is), so getNumberOfLines/1 never returns 0. β¨
βοΈ getRange(This, From, To) -> unicode:charlist()
getRange(This, From, To) -> unicode:charlist()
when
This :: wxTextCtrl(),
From :: integer(),
To :: integer().
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/1 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. π₯
π― getSelection(This) -> {From :: integer(), To :: integer()}
getSelection(This) -> {From :: integer(), To :: integer()}
when This :: wxTextCtrl().
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/1 for multiline controls under Windows (at least,) you should use getStringSelection/1 to get the selected text. π
π getStringSelection(This) -> unicode:charlist()
getStringSelection(This) -> unicode:charlist()
when This :: wxTextCtrl().
Gets the text currently selected in the control. πΈ
If there is no selection, the returned string is empty. π«Ά
π¨ getStyle(This, Position, Style) -> boolean()
getStyle(This, Position, Style) -> boolean()
when
This :: wxTextCtrl(),
Position :: integer(),
Style :: wxTextAttr:wxTextAttr().
Returns the style at this position in the text control. π
Not all platforms support this function. π
Return: true on success, false if an error occurred (this may also mean that the styles are not supported under this platform).
See:
setStyle/4wxTextAttr
π getValue(This) -> unicode:charlist()
getValue(This) -> unicode:charlist() when This :: wxTextCtrl().
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. π
βοΈ isEditable(This) -> boolean()
isEditable(This) -> boolean() when This :: wxTextCtrl().
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/2. π¦
π
isModified(This) -> boolean()
isModified(This) -> boolean() when This :: wxTextCtrl().
Returns true if the text has been modified by user. π
Note that calling setValue/2 doesn't make the control modified. π
See: markDirty/1
π isMultiLine(This) -> boolean()
isMultiLine(This) -> boolean() when This :: wxTextCtrl().
Returns true if this is a multi line edit control and false otherwise. π
See: isSingleLine/1
πΈ isSingleLine(This) -> boolean()
isSingleLine(This) -> boolean() when This :: wxTextCtrl().
Returns true if this is a single line edit control and false otherwise. β¨
See:
isSingleLine/1isMultiLine/1
π loadFile(This, Filename, [Option]) -> boolean()
loadFile(This, Filename, [Option]) -> boolean()
when
This :: wxTextCtrl(),
Filename :: unicode:chardata(),
Option :: {fileType, integer()}.
Loads and displays the named file, if it exists. π
Return: true if successful, false otherwise.
π· markDirty(This) -> ok when This :: wxTextCtrl().
Mark text as modified (dirty). π
See: isModified/1
π new() -> wxTextCtrl().
Default ctor. β¨
π new(Parent, Id, [Option]) -> wxTextCtrl()
new(Parent, Id, [Option]) -> wxTextCtrl()
when
Parent :: wxWindow:wxWindow(),
Id :: integer(),
Option ::
{value, unicode:chardata()} |
{pos, {X :: integer(), Y :: integer()}} |
{size, {W :: integer(), H :: integer()}} |
{style, integer()} |
{validator, wx:wx_object()}.
Constructor, creating and showing a text control. π
Remark: The horizontal scrollbar (wxHSCROLL style flag) will only be created for multi-line text controls. Without a horizontal scrollbar, text lines that don't fit in the control's size will be wrapped (but no newline character is inserted). Single line controls don't have a horizontal scrollbar, the text is automatically scrolled so that the insertion point is always visible. π
See: create/4
π paste(This) -> ok when This :: wxTextCtrl().
Pastes text from the clipboard to the text item. π«Ά
π positionToXY(This, Pos) -> Result
positionToXY(This, Pos) -> Result
when
Result ::
{Res :: boolean(),
X :: integer(),
Y :: integer()},
This :: wxTextCtrl(),
Pos :: integer().
Converts given position to a zero-based column, line number pair. π
Return: true on success, false on failure (most likely due to a too large position parameter). π
See: xYToPosition/3
π redo(This) -> ok when This :: wxTextCtrl().
If there is a redo facility and the last operation can be redone, redoes the last operation. β¨
And redo/1? It does nothing if there is no redo facility. Thatβs the tea. β
remove/3 π§Ή
remove(This, From, To) -> ok
when
This :: wxTextCtrl(),
From :: integer(),
To :: integer().
Removes the text starting at the first given position up to (but not including) the character at the last position. And it puts the current insertion point position at To as a side effect. Slay. π
replace/4 β¨
replace(This, From, To, Value) -> ok
when
This :: wxTextCtrl(),
From :: integer(),
To :: integer(),
Value :: unicode:chardata().
Replaces the text starting at the first position up to (but not including) the character at the last position with the given text. Also sets the current insertion point position at To as a side effect. Iconic. π
saveFile/2 πΎ
saveFile(This, [Option]) -> boolean()
when
This :: wxTextCtrl(),
Option ::
{file, unicode:chardata()} |
{fileType, integer()}.
Saves the contents of the control in a text file. Returns true if the operation was successful, false otherwise. No cap. π«Ά
setDefaultStyle/2 π¨
setDefaultStyle(This, Style) -> boolean()
when
This :: wxTextCtrl(),
Style :: wxTextAttr:wxTextAttr().
Changes the default style to use for the new text which is going to be added to the control. This applies both to the text added programmatically using writeText/2 or appendText/2 and to the text entered by the user interactively. 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). Return: true on success, false if an error occurred (this may also mean that the styles are not supported under this platform). See: getDefaultStyle/1. π
setEditable/2 π
setEditable(This, Editable) -> ok
when This :: wxTextCtrl(), Editable :: boolean().
Makes the text item editable or read-only, overriding the wxTE\_READONLY flag. See: isEditable/1. Periodt. β¨
setInsertionPoint/2 π
setInsertionPoint(This, Pos) -> ok
when This :: wxTextCtrl(), Pos :: integer().
Sets the insertion point at the given position. Simple as that. πΈ
setInsertionPointEnd/1 π
setInsertionPointEnd(This) -> ok when This :: wxTextCtrl().
Sets the insertion point at the end of the text control. This is equivalent to calling setInsertionPoint/2 with getLastPosition/1 argument. Cute. π
setMaxLength/2 π
setMaxLength(This, Len) -> ok
when This :: wxTextCtrl(), Len :: integer().
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. Note that in wxGTK this function may only be used with single line text controls. π
setSelection/3 ποΈ
setSelection(This, From, To) -> ok
when
This :: wxTextCtrl(),
From :: integer(),
To :: integer().
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. Obsessed. π
setStyle/4 π
setStyle(This, Start, End, Style) -> boolean()
when
This :: wxTextCtrl(),
Start :: integer(),
End :: integer(),
Style :: wxTextAttr:wxTextAttr().
Changes the style of the given range. If any attribute within style is not set, the corresponding attribute from getDefaultStyle/1 is used. Return: true on success, false if an error occurred (this may also mean that the styles are not supported under this platform).
See:
getStyle/3wxTextAttr
setValue/2 π
setValue(This, Value) -> ok
when This :: wxTextCtrl(), Value ::
unicode:chardata().
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/2. 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/2 instead. Iykyk. π
showPosition/2 π
showPosition(This, Pos) -> ok
when This :: wxTextCtrl(), Pos :: integer().
Makes the line containing the given position visible. Thatβs it. π¦
undo/1 β©οΈ
undo(This) -> ok when This :: wxTextCtrl().
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. π
writeText/2 βοΈ
writeText(This, Text) -> ok
when This :: wxTextCtrl(), Text ::
unicode:chardata().
Writes the text into the text control at the current insertion position. Remark: Newlines in the text string are the only control characters allowed, and they will cause appropriate line breaks. See operator<<() and appendText/2 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 setInsertionPointEnd/1 before writing. Lowkey useful. π₯
xYToPosition/3 π§
xYToPosition(This, X, Y) -> integer()
when
This :: wxTextCtrl(),
X :: integer(),
Y :: integer().
Converts the given zero based column and line number to a position. Return: The position value, or -1 if x or y was invalid. Main character energy. π
And thatβs a wrap, besties! π This manpage was brought to you by Ericsson AB, version wx 2.6, and the page itself is wxTextCtrl(3). Stay iconic, stay slaying. πβ¨
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms