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{Include files
}
18 \wxheading{Window styles
}
21 \begin{twocollist
}\itemsep=
0pt
22 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The callback function will
23 receive the message wxEVENT
\_TYPE\_TEXT\_ENTER\_COMMAND. Note
24 that this will break tab traversal for this panel item under
26 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
27 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
28 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
29 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created.
}
32 See also
\helpref{window styles overview
}{windowstyles
} and
33 \helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}.
37 This class multiply-inherits from
{\bf streambuf
} where compilers allow, allowing code such as the following:
41 wxTextCtrl *control = new wxTextCtrl(...);
43 ostream stream(control)
45 stream <<
123.456 << " some text
\n";
50 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
51 wxTextCtrl header file.
53 \wxheading{Event handling
}
55 To process input from a text control, use these event handler macros to direct input to member
56 functions that take a
\helpref{wxCommandEvent
}{wxcommandevent
} argument.
59 \begin{twocollist
}\itemsep=
0pt
60 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
61 generated when the text changes.
}
62 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_ENTER event,
63 generated when enter is pressed in a single-line text control.
}
68 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
70 \latexignore{\rtfignore{\wxheading{Members
}}}
72 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
74 \func{}{wxTextCtrl
}{\void}
78 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
79 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
80 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
82 Constructor, creating and showing a text control.
84 \wxheading{Parameters
}
86 \docparam{parent
}{Parent window. Should not be NULL.
}
88 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
90 \docparam{value
}{Default text value.
}
92 \docparam{pos
}{Text control position.
}
94 \docparam{size
}{Text control size.
}
96 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
98 \docparam{validator
}{Window validator.
}
100 \docparam{name
}{Window name.
}
104 The horizontal scrollbar (
{\bf wxTE
\_HSCROLL} style flag) will only be created for multi-line text controls.
105 Without a horizontal scrollbar, text lines that don't fit in the control's
106 size will be wrapped (but no newline character is inserted). Single line
107 controls don't have a horizontal scrollbar, the text is automatically scrolled
108 so that the
\helpref{insertion point
}{wxtextctrlgetinsertionpoint
} is always
111 Under Windows, if the
{\bf wxTE
\_MULTILINE} style is used, the window is implemented
112 as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
117 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
119 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
121 \func{}{\destruct{wxTextCtrl
}}{\void}
123 Destructor, destroying the text control.
125 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
127 \func{virtual void
}{Clear
}{\void}
129 Clears the text in the control.
131 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
133 \func{virtual void
}{Copy
}{\void}
135 Copies the selected text to the clipboard under Motif and MS Windows.
137 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
139 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
140 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
141 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
143 Creates the text control for two-step construction. Derived classes
144 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
147 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
149 \func{virtual void
}{Cut
}{\void}
151 Copies the selected text to the clipboard and removes the selection.
153 \membersection{wxTextCtrl::DiscardEdits
}
155 \func{void
}{DiscardEdits
}{\void}
157 Resets the internal `modified' flag as if the current edits had been saved.
159 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
161 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
163 Returns the insertion point. This is defined as the zero based index of the
164 character position to the right of the insertion point. For example, if
165 the insertion point is at the end of the text control, it is equal to
166 both
\helpref{GetValue()
}{wxtextctrlgetvalue
}.Length() and
167 \helpref{GetLastPosition()
}{wxtextctrlgetlastposition
}.
169 The following code snippet safely returns the character at the insertion
170 point or the zero character if the point is at the end of the control.
174 char GetCurrentChar(wxTextCtrl *tc)
{
175 if (tc->GetInsertionPoint() == tc->GetLastPosition())
177 return tc->GetValue
[tc->GetInsertionPoint()
];
182 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
184 \constfunc{virtual long
}{GetLastPosition
}{\void}
186 Returns the zero based index of the last position in the text control,
187 which is equal to the number of characters in the control.
189 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
191 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
193 Gets the length of the specified line, not including any trailing newline
196 \wxheading{Parameters
}
198 \docparam{lineNo
}{Line number (starting from zero).
}
200 \wxheading{Return value
}
202 The length of the line, or -
1 if
{\it lineNo
} was invalid.
204 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
206 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
208 Returns the contents of a given line in the text control, not including
209 any trailing newline character(s).
211 \wxheading{Parameters
}
213 \docparam{lineNo
}{The line number, starting from zero.
}
215 \wxheading{Return value
}
217 The contents of the line.
219 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
221 \constfunc{int
}{GetNumberOfLines
}{\void}
223 Returns the number of lines in the text control buffer.
227 Note that even empty text controls have one line (where the insertion point
228 is), so GetNumberOfLines() never returns
0.
230 For gtk
\_text (multi-line) controls, the number of lines is
231 calculated by actually counting newline characters in the buffer. You
232 may wish to avoid using functions that work with line numbers if you are
233 working with controls that contain large amounts of text.
235 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
237 \constfunc{wxString
}{GetValue
}{\void}
239 Gets the contents of the control.
241 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
243 \constfunc{bool
}{IsModified
}{\void}
245 Returns TRUE if the text has been modified.
247 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
249 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
251 Loads and displays the named file, if it exists.
253 \wxheading{Parameters
}
255 \docparam{filename
}{The filename of the file to load.
}
257 \wxheading{Return value
}
259 TRUE if successful, FALSE otherwise.
261 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
263 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
265 Default handler for character input.
269 It is possible to intercept character
270 input by overriding this member. Call this function
271 to let the default behaviour take place; not calling
272 it results in the character being ignored. You can
273 replace the
{\it keyCode
} member of
{\it event
} to
274 translate keystrokes.
276 Note that Windows and Motif have different ways
277 of implementing the default behaviour. In Windows,
278 calling wxTextCtrl::OnChar immediately
279 processes the character. In Motif,
280 calling this function simply sets a flag
281 to let default processing happen. This might affect
282 the way in which you write your OnChar function
283 on different platforms.
287 \helpref{wxKeyEvent
}{wxkeyevent
}
289 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
291 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
293 This event handler function implements default drag and drop behaviour, which
294 is to load the first dropped file into the control.
296 \wxheading{Parameters
}
298 \docparam{event
}{The drop files event.
}
302 This is not yet implemented for the GTK.
306 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
308 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
310 \func{virtual void
}{Paste
}{\void}
312 Pastes text from the clipboard to the text item.
314 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
316 \constfunc{long
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
318 Converts given position to a zero-based column, line number pair.
320 \wxheading{Parameters
}
322 \docparam{pos
}{Position.
}
324 \docparam{x
}{Receives zero based column number.
}
326 \docparam{y
}{Receives zero based line number.
}
328 \wxheading{Return value
}
330 Non-zero on success, zero on failure (most likely due to a too large position
335 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
337 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
338 y values, so (x,y) = PositionToXY() is equivalent to the call described
341 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
343 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
345 Removes the text starting at the first given position up to (but not including)
346 the character at the last position.
348 \wxheading{Parameters
}
350 \docparam{from
}{The first position.
}
352 \docparam{to
}{The last position.
}
354 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
356 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
358 Replaces the text starting at the first position up to (but not including)
359 the character at the last position with the given text.
361 \wxheading{Parameters
}
363 \docparam{from
}{The first position.
}
365 \docparam{to
}{The last position.
}
367 \docparam{value
}{The value to replace the existing text with.
}
369 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
371 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
373 Saves the contents of the control in a text file.
375 \wxheading{Parameters
}
377 \docparam{filename
}{The name of the file in which to save the text.
}
379 \wxheading{Return value
}
381 TRUE if the operation was successful, FALSE otherwise.
383 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
385 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
387 Makes the text item editable or read-only, overriding the
{\bf wxTE
\_READONLY}
390 \wxheading{Parameters
}
392 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
394 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
396 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
398 Sets the insertion point at the given position.
400 \wxheading{Parameters
}
402 \docparam{pos
}{Position to set.
}
404 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
406 \func{virtual void
}{SetInsertionPointEnd
}{\void}
408 Sets the insertion point at the end of the text control. This is equivalent
409 to
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}(
\helpref{GetLastPosition
}{wxtextctrlgetlastposition
}()).
411 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
413 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
415 Selects the text starting at the first position up to (but not including) the character at the last position.
417 \wxheading{Parameters
}
419 \docparam{from
}{The first position.
}
421 \docparam{to
}{The last position.
}
423 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
425 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
429 \wxheading{Parameters
}
431 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
433 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
435 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
437 Makes the line containing the given position visible.
439 \wxheading{Parameters
}
441 \docparam{pos
}{The position that should be visible.
}
443 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
445 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
447 Writes the text into the text control at the current insertion position.
449 \wxheading{Parameters
}
451 \docparam{text
}{Text to write to the text control.
}
455 Newlines in the text string
456 are the only control characters allowed, and they will cause appropriate
457 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} and
\helpref{wxTextCtrl::AppendText
}{wxtextctrlappendtext
} for more convenient ways of writing to the window.
459 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.
461 \membersection{wxTextCtrl::AppendText
}\label{wxtextctrlappendtext
}
463 \func{void
}{AppendText
}{\param{const wxString\&
}{ text
}}
465 Appends the text to the end of the text control.
467 \wxheading{Parameters
}
469 \docparam{text
}{Text to write to the text control.
}
473 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
474 the programmer should use
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} and
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}.
478 \helpref{wxTextCtrl::WriteText
}{wxtextctrlwritetext
}
480 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
482 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
484 Converts the given zero based column and line number to a position.
486 \wxheading{Parameters
}
488 \docparam{x
}{The column number.
}
490 \docparam{y
}{The line number.
}
492 \wxheading{Return value
}
496 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
498 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
500 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
502 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
504 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
506 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
508 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
510 Operator definitions for appending to a text control, for example:
513 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
515 (*wnd) << "Welcome to text control number " << 1 << ".\n";