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{wxTextCtrl::wxTextCtrl
}{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
113 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
115 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
117 \func{}{\destruct{wxTextCtrl
}}{\void}
119 Destructor, destroying the text control.
121 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
123 \func{virtual void
}{Clear
}{\void}
125 Clears the text in the control.
127 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
129 \func{virtual void
}{Copy
}{\void}
131 Copies the selected text to the clipboard under Motif and MS Windows.
133 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
135 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
136 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
137 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
139 Creates the text control for two-step construction. Derived classes
140 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
143 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
145 \func{virtual void
}{Cut
}{\void}
147 Copies the selected text to the clipboard and removes the selection.
149 \membersection{wxTextCtrl::DiscardEdits
}
151 \func{void
}{DiscardEdits
}{\void}
153 Resets the internal `modified' flag as if the current edits had been saved.
155 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
157 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
159 Returns the insertion point. This is defined as the zero based index of the
160 character position to the right of the insertion point. For example, if
161 the insertion point is at the end of the text control, it is equal to
162 both
\helpref{GetValue()
}{wxtextctrlgetvalue
}.Length() and
163 \helpref{GetLastPosition()
}{wxtextctrlgetlastposition
}.
165 The following code snippet safely returns the character at the insertion
166 point or the zero character if the point is at the end of the control.
170 char GetCurrentChar(wxTextCtrl *tc)
{
171 if (tc->GetInsertionPoint() == tc->GetLastPosition())
173 return tc->GetValue
[tc->GetInsertionPoint()
];
178 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
180 \constfunc{virtual long
}{GetLastPosition
}{\void}
182 Returns the zero based index of the last position in the text control,
183 which is equal to the number of characters in the control.
185 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
187 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
189 Gets the length of the specified line, not including any trailing newline
192 \wxheading{Parameters
}
194 \docparam{lineNo
}{Line number (starting from zero).
}
196 \wxheading{Return value
}
198 The length of the line, or -
1 if
{\it lineNo
} was invalid.
200 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
202 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
204 Returns the contents of a given line in the text control, not including
205 any trailing newline character(s).
207 \wxheading{Parameters
}
209 \docparam{lineNo
}{The line number, starting from zero.
}
211 \wxheading{Return value
}
213 The contents of the line.
215 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
217 \constfunc{int
}{GetNumberOfLines
}{\void}
219 Returns the number of lines in the text control buffer.
223 Note that even empty text controls have one line (where the insertion point
224 is), so GetNumberOfLines() never returns
0.
226 For gtk
\_text (multi-line) controls, the number of lines is
227 calculated by actually counting newline characters in the buffer. You
228 may wish to avoid using functions that work with line numbers if you are
229 working with controls that contain large amounts of text.
231 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
233 \constfunc{wxString
}{GetValue
}{\void}
235 Gets the contents of the control.
237 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
239 \constfunc{bool
}{IsModified
}{\void}
241 Returns TRUE if the text has been modified.
243 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
245 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
247 Loads and displays the named file, if it exists.
249 \wxheading{Parameters
}
251 \docparam{filename
}{The filename of the file to load.
}
253 \wxheading{Return value
}
255 TRUE if successful, FALSE otherwise.
257 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
259 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
261 Default handler for character input.
265 It is possible to intercept character
266 input by overriding this member. Call this function
267 to let the default behaviour take place; not calling
268 it results in the character being ignored. You can
269 replace the
{\it keyCode
} member of
{\it event
} to
270 translate keystrokes.
272 Note that Windows and Motif have different ways
273 of implementing the default behaviour. In Windows,
274 calling wxTextCtrl::OnChar immediately
275 processes the character. In Motif,
276 calling this function simply sets a flag
277 to let default processing happen. This might affect
278 the way in which you write your OnChar function
279 on different platforms.
283 \helpref{wxKeyEvent
}{wxkeyevent
}
285 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
287 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
289 This event handler function implements default drag and drop behaviour, which
290 is to load the first dropped file into the control.
292 \wxheading{Parameters
}
294 \docparam{event
}{The drop files event.
}
298 This is not yet implemented for the GTK.
302 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
304 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
306 \func{virtual void
}{Paste
}{\void}
308 Pastes text from the clipboard to the text item.
310 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
312 \constfunc{long
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
314 Converts given position to a zero-based column, line number pair.
316 \wxheading{Parameters
}
318 \docparam{pos
}{Position.
}
320 \docparam{x
}{Receives zero based column number.
}
322 \docparam{y
}{Receives zero based line number.
}
324 \wxheading{Return value
}
326 Non-zero on success, zero on failure (most likely due to a too large position
331 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
333 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
334 y values, so (x,y) = PositionToXY() is equivalent to the call described
337 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
339 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
341 Removes the text starting at the first given position up to (but not including)
342 the character at the last position.
344 \wxheading{Parameters
}
346 \docparam{from
}{The first position.
}
348 \docparam{to
}{The last position.
}
350 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
352 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
354 Replaces the text starting at the first position up to (but not including)
355 the character at the last position with the given text.
357 \wxheading{Parameters
}
359 \docparam{from
}{The first position.
}
361 \docparam{to
}{The last position.
}
363 \docparam{value
}{The value to replace the existing text with.
}
365 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
367 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
369 Saves the contents of the control in a text file.
371 \wxheading{Parameters
}
373 \docparam{filename
}{The name of the file in which to save the text.
}
375 \wxheading{Return value
}
377 TRUE if the operation was successful, FALSE otherwise.
379 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
381 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
383 Makes the text item editable or read-only, overriding the
{\bf wxTE
\_READONLY}
386 \wxheading{Parameters
}
388 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
390 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
392 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
394 Sets the insertion point at the given position.
396 \wxheading{Parameters
}
398 \docparam{pos
}{Position to set.
}
400 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
402 \func{virtual void
}{SetInsertionPointEnd
}{\void}
404 Sets the insertion point at the end of the text control. This is equivalent
405 to
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}(
\helpref{GetLastPosition
}{wxtextctrlgetlastposition
}()).
407 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
409 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
411 Selects the text starting at the first position up to (but not including) the character at the last position.
413 \wxheading{Parameters
}
415 \docparam{from
}{The first position.
}
417 \docparam{to
}{The last position.
}
419 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
421 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
425 \wxheading{Parameters
}
427 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
429 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
431 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
433 Makes the line containing the given position visible.
435 \wxheading{Parameters
}
437 \docparam{pos
}{The position that should be visible.
}
439 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
441 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
443 Writes the text into the text control at the current insertion position.
445 \wxheading{Parameters
}
447 \docparam{text
}{Text to write to the text control.
}
451 Newlines in the text string
452 are the only control characters allowed, and they will cause appropriate
453 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} and
\helpref{wxTextCtrl::AppendText
}{wxtextctrlappendtext
} for more convenient ways of writing to the window.
455 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.
457 \membersection{wxTextCtrl::AppendText
}\label{wxtextctrlappendtext
}
459 \func{void
}{AppendText
}{\param{const wxString\&
}{ text
}}
461 Appends the text to the end of the text control.
463 \wxheading{Parameters
}
465 \docparam{text
}{Text to write to the text control.
}
469 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
470 the programmer should use
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} and
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}.
474 \helpref{wxTextCtrl::WriteText
}{wxtextctrlwritetext
}
476 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
478 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
480 Converts the given zero based column and line number to a position.
482 \wxheading{Parameters
}
484 \docparam{x
}{The column number.
}
486 \docparam{y
}{The line number.
}
488 \wxheading{Return value
}
492 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
494 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
496 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
498 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
500 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
502 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
504 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
506 Operator definitions for appending to a text control, for example:
509 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
511 (*wnd) << "Welcome to text control number " << 1 << ".\n";