1 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
3 A text control allows text to be displayed and edited. It may be
4 single line or multi-line.
6 \wxheading{Derived from
}
9 \helpref{wxControl
}{wxcontrol
}\\
10 \helpref{wxWindow
}{wxwindow
}\\
11 \helpref{wxEvtHandler
}{wxevthandler
}\\
12 \helpref{wxObject
}{wxobject
}
14 \wxheading{Window styles
}
17 \begin{twocollist
}\itemsep=
0pt
18 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The callback function will
19 receive the message wxEVENT
\_TYPE\_TEXT\_ENTER\_COMMAND. Note
20 that this will break tab traversal for this panel item under
22 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
23 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
24 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
25 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created.
}
28 See also
\helpref{window styles overview
}{windowstyles
} and
29 \helpref{wxtextctrlconstr
}.
33 This class multiply-inherits from
{\bf streambuf
} where compilers allow, allowing code such as the following:
37 wxTextCtrl *control = new wxTextCtrl(...);
39 ostream stream(control)
41 stream <<
123.456 << " some text
\n";
46 If your compiler does not support derivation from
{\bf streambuf
} and gives a compile error, define the symbol
{\bf NO
\_TEXT\_WINDOW\_STREAM} in the
47 wxTextCtrl header file.
49 \wxheading{Event handling
}
51 To process input from a text control, use these event handler macros to direct input to member
52 functions that take a
\helpref{wxCommandEvent
}{wxcommandevent
} argument.
55 \begin{twocollist
}\itemsep=
0pt
56 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
57 generated when the text changes.
}
58 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_ENTER event,
59 generated when enter is pressed in a single-line text control.
}
64 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
66 \latexignore{\rtfignore{\wxheading{Members
}}}
68 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
70 \func{}{wxTextCtrl
}{\void}
74 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
75 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
76 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
78 Constructor, creating and showing a text control.
80 \wxheading{Parameters
}
82 \docparam{parent
}{Parent window. Should not be NULL.
}
84 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
86 \docparam{value
}{Default text value.
}
88 \docparam{pos
}{Text control position.
}
90 \docparam{size
}{Text control size.
}
92 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
94 \docparam{validator
}{Window validator.
}
96 \docparam{name
}{Window name.
}
100 The horizontal scrollbar (
{\bf wxTE
\_HSCROLL} style flag) will only be created for multi-line text controls.
101 Without a horizontal scrollbar, text lines that don't fit in the control's
102 size will be wrapped (but no newline character is inserted). Single line
103 controls don't have a horizontal scrollbar, the text is automatically scrolled
104 so that the
\helpref{insertion point
}{wxtextctrlgetinsertionpoint
} is always
107 Under Windows, if the
{\bf wxTE
\_MULTILINE} style is used, the window is implemented
108 as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
111 For the GTK, the single line text control is implemented as a gtk
\_entry,
112 while the multi-line control is a gtk
\_text.
116 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
118 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
120 \func{}{\destruct{wxTextCtrl
}}{\void}
122 Destructor, destroying the text control.
124 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
126 \func{virtual void
}{Clear
}{\void}
128 Clears the text in the control.
130 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
132 \func{virtual void
}{Copy
}{\void}
134 Copies the selected text to the clipboard under Motif and MS Windows.
136 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
138 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
139 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
140 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
142 Creates the text control for two-step construction. Derived classes
143 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
146 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
148 \func{virtual void
}{Cut
}{\void}
150 Copies the selected text to the clipboard and removes the selection.
152 \membersection{wxTextCtrl::DiscardEdits
}
154 \func{void
}{DiscardEdits
}{\void}
156 Resets the internal `modified' flag as if the current edits had been saved.
158 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
160 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
162 Returns the insertion point. This is defined as the zero based index of the
163 character position to the right of the insertion point. For example, if
164 the insertion point is at the end of the text control, it is equal to
165 both
\helpref{GetValue()
}{wxtextctrlgetvalue
}.Length() and
166 \helpref{GetLastPosition()
}{wxtextctrlgetlastposition
}.
168 The following code snippet safely returns the character at the insertion
169 point or the zero character if the point is at the end of the control.
173 char GetCurrentChar(wxTextCtrl *tc)
{
174 if (tc->GetInsertionPoint() == tc->GetLastPosition())
176 return tc->GetValue
[tc->GetInsertionPoint()
];
181 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
183 \constfunc{virtual long
}{GetLastPosition
}{\void}
185 Returns the zero based index of the last position in the text control,
186 which is equal to the number of characters in the control.
188 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
190 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
192 Gets the length of the specified line, not including any trailing newline
195 \wxheading{Parameters
}
197 \docparam{lineNo
}{Line number (starting from zero).
}
199 \wxheading{Return value
}
201 The length of the line, or -
1 if
{\it lineNo
} was invalid.
203 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
205 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
207 Returns the contents of a given line in the text control, not including
208 any trailing newline character(s).
210 \wxheading{Parameters
}
212 \docparam{lineNo
}{The line number, starting from zero.
}
214 \wxheading{Return value
}
216 The contents of the line.
218 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
220 \constfunc{int
}{GetNumberOfLines
}{\void}
222 Returns the number of lines in the text control buffer.
226 Note that even empty text controls have one line (where the insertion point
227 is), so GetNumberOfLines() never returns
0.
229 For gtk
\_text (multi-line) controls, the number of lines is
230 calculated by actually counting newline characters in the buffer. You
231 may wish to avoid using functions that work with line numbers if you are
232 working with controls that contain large amounts of text.
234 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
236 \constfunc{wxString
}{GetValue
}{\void}
238 Gets the contents of the control.
240 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
242 \constfunc{bool
}{IsModified
}{\void}
244 Returns TRUE if the text has been modified.
246 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
248 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
250 Loads and displays the named file, if it exists.
252 \wxheading{Parameters
}
254 \docparam{filename
}{The filename of the file to load.
}
256 \wxheading{Return value
}
258 TRUE if successful, FALSE otherwise.
260 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
262 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
264 Default handler for character input.
268 It is possible to intercept character
269 input by overriding this member. Call this function
270 to let the default behaviour take place; not calling
271 it results in the character being ignored. You can
272 replace the
{\it keyCode
} member of
{\it event
} to
273 translate keystrokes.
275 Note that Windows and Motif have different ways
276 of implementing the default behaviour. In Windows,
277 calling wxTextCtrl::OnChar immediately
278 processes the character. In Motif,
279 calling this function simply sets a flag
280 to let default processing happen. This might affect
281 the way in which you write your OnChar function
282 on different platforms.
286 \helpref{wxKeyEvent
}{wxkeyevent
}
288 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
290 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
292 This event handler function implements default drag and drop behaviour, which
293 is to load the first dropped file into the control.
295 \wxheading{Parameters
}
297 \docparam{event
}{The drop files event.
}
301 This is not yet implemented for the GTK.
305 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
307 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
309 \func{virtual void
}{Paste
}{\void}
311 Pastes text from the clipboard to the text item.
313 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
315 \constfunc{long
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
317 Converts given position to a zero-based column, line number pair.
319 \wxheading{Parameters
}
321 \docparam{pos
}{Position.
}
323 \docparam{x
}{Receives zero based column number.
}
325 \docparam{y
}{Receives zero based line number.
}
327 \wxheading{Return value
}
329 Non-zero on success, zero on failure (most likely due to a too large position
334 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
336 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
337 y values, so (x,y) = PositionToXY() is equivalent to the call described
340 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
342 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
344 Removes the text starting at the first given position up to (but not including)
345 the character at the last position.
347 \wxheading{Parameters
}
349 \docparam{from
}{The first position.
}
351 \docparam{to
}{The last position.
}
353 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
355 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
357 Replaces the text starting at the first position up to (but not including)
358 the character at the last position with the given text.
360 \wxheading{Parameters
}
362 \docparam{from
}{The first position.
}
364 \docparam{to
}{The last position.
}
366 \docparam{value
}{The value to replace the existing text with.
}
368 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
370 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
372 Saves the contents of the control in a text file.
374 \wxheading{Parameters
}
376 \docparam{filename
}{The name of the file in which to save the text.
}
378 \wxheading{Return value
}
380 TRUE if the operation was successful, FALSE otherwise.
382 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
384 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
386 Makes the text item editable or read-only, overriding the
{\bf wxTE
\_READONLY}
389 \wxheading{Parameters
}
391 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
393 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
395 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
397 Sets the insertion point at the given position.
399 \wxheading{Parameters
}
401 \docparam{pos
}{Position to set.
}
403 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
405 \func{virtual void
}{SetInsertionPointEnd
}{\void}
407 Sets the insertion point at the end of the text control. This is equivalent
408 to
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}(
\helpref{GetLastPosition
}{wxtextctrlgetlastposition
}()).
410 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
412 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
414 Selects the text starting at the first position up to (but not including) the character at the last position.
416 \wxheading{Parameters
}
418 \docparam{from
}{The first position.
}
420 \docparam{to
}{The last position.
}
422 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
424 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
428 \wxheading{Parameters
}
430 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
432 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
434 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
436 Makes the line containing the given position visible.
438 \wxheading{Parameters
}
440 \docparam{pos
}{The position that should be visible.
}
442 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
444 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
446 Writes the text into the text control at the current insertion position.
448 \wxheading{Parameters
}
450 \docparam{text
}{Text to write to the text control.
}
454 Newlines in the text string
455 are the only control characters allowed, and they will cause appropriate
456 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} for more convenient ways of writing to the window.
458 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
\helpref{wxTextCtrl::SetInsertionPointEnd
}{wxtextctrlsetinsertionpointend
} before writing.
460 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
462 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
464 Converts the given zero based column and line number to a position.
466 \wxheading{Parameters
}
468 \docparam{x
}{The column number.
}
470 \docparam{y
}{The line number.
}
472 \wxheading{Return value
}
476 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
478 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
480 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
482 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
484 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
486 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
488 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
490 Operator definitions for writing to a text control, for example:
493 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
495 (*wnd) << "Welcome to text control number " << 1 << ".\n";