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 control will generate
23 the message wxEVENT
\_TYPE\_TEXT\_ENTER\_COMMAND (otherwise pressing <Enter> is
24 either processed internally by the control or used for navigation between
26 \twocolitem{\windowstyle{wxTE
\_PROCESS\_TAB}}{The control will receieve
27 EVT
\_CHAR messages for TAB pressed - normally, TAB is used for passing to the
28 next control in a dialog instead. For the control created with this style,
29 you can still use Ctrl-Enter to pass to the next control from the keyboard.
}
30 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
31 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
32 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
33 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created. No effect under GTK+.
}
36 See also
\helpref{window styles overview
}{windowstyles
} and
37 \helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}.
41 This class multiply-inherits from
{\bf streambuf
} where compilers allow, allowing code such as
46 wxTextCtrl *control = new wxTextCtrl(...);
48 ostream stream(control)
50 stream <<
123.456 << " some text
\n";
55 If your compiler does not support derivation from
{\bf streambuf
} and gives a compile error, define the symbol
56 {\bf NO
\_TEXT\_WINDOW\_STREAM} in the wxTextCtrl header file.
58 Note that any use of C++ iostreams (including this one) deprecated and might get completely removed
61 \wxheading{Event handling
}
63 The following commands are processed by default event handlers in wxTextCtrl: wxID
\_CUT, wxID
\_COPY,
64 wxID
\_PASTE, wxID
\_UNDO, wxID
\_REDO. The associated UI update events are also processed
65 automatically, when the control has the focus.
67 To process input from a text control, use these event handler macros to direct input to member
68 functions that take a
\helpref{wxCommandEvent
}{wxcommandevent
} argument.
71 \begin{twocollist
}\itemsep=
0pt
72 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
73 generated when the text changes. Notice that this event will always be sent
74 when the text controls contents changes - whether this is due to user input or
75 comes from the program itself (for example, if SetValue() is called)
}
76 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_ENTER event,
77 generated when enter is pressed in a single-line text control.
}
82 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
84 \latexignore{\rtfignore{\wxheading{Members
}}}
86 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
88 \func{}{wxTextCtrl
}{\void}
92 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
93 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
94 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
96 Constructor, creating and showing a text control.
98 \wxheading{Parameters
}
100 \docparam{parent
}{Parent window. Should not be NULL.
}
102 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
104 \docparam{value
}{Default text value.
}
106 \docparam{pos
}{Text control position.
}
108 \docparam{size
}{Text control size.
}
110 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
112 \docparam{validator
}{Window validator.
}
114 \docparam{name
}{Window name.
}
118 The horizontal scrollbar (
{\bf wxTE
\_HSCROLL} style flag) will only be created for multi-line text controls.
119 Without a horizontal scrollbar, text lines that don't fit in the control's
120 size will be wrapped (but no newline character is inserted). Single line
121 controls don't have a horizontal scrollbar, the text is automatically scrolled
122 so that the
\helpref{insertion point
}{wxtextctrlgetinsertionpoint
} is always
125 Under Windows, if the
{\bf wxTE
\_MULTILINE} style is used, the window is implemented
126 as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
131 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
133 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
135 \func{}{\destruct{wxTextCtrl
}}{\void}
137 Destructor, destroying the text control.
139 \membersection{wxTextCtrl::AppendText
}\label{wxtextctrlappendtext
}
141 \func{void
}{AppendText
}{\param{const wxString\&
}{ text
}}
143 Appends the text to the end of the text control.
145 \wxheading{Parameters
}
147 \docparam{text
}{Text to write to the text control.
}
151 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
152 the programmer should use
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} and
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}.
156 \helpref{wxTextCtrl::WriteText
}{wxtextctrlwritetext
}
158 \membersection{wxTextCtrl::CanCopy
}\label{wxtextctrlcancopy
}
160 \func{virtual bool
}{CanCopy
}{\void}
162 Returns TRUE if the selection can be copied to the clipboard.
164 \membersection{wxTextCtrl::CanCut
}\label{wxtextctrlcancut
}
166 \func{virtual bool
}{CanCut
}{\void}
168 Returns TRUE if the selection can be cut to the clipboard.
170 \membersection{wxTextCtrl::CanPaste
}\label{wxtextctrlcanpaste
}
172 \func{virtual bool
}{CanPaste
}{\void}
174 Returns TRUE if the contents of the clipboard can be pasted into the
175 text control. On some platforms (Motif, GTK) this is an approximation
176 and returns TRUE if the control is editable, FALSE otherwise.
178 \membersection{wxTextCtrl::CanRedo
}\label{wxtextctrlcanredo
}
180 \func{virtual bool
}{CanRedo
}{\void}
182 Returns TRUE if there is a redo facility available and the last operation
185 \membersection{wxTextCtrl::CanUndo
}\label{wxtextctrlcanundo
}
187 \func{virtual bool
}{CanUndo
}{\void}
189 Returns TRUE if there is an undo facility available and the last operation
192 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
194 \func{virtual void
}{Clear
}{\void}
196 Clears the text in the control.
198 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
200 \func{virtual void
}{Copy
}{\void}
202 Copies the selected text to the clipboard under Motif and MS Windows.
204 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
206 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
207 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
208 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
210 Creates the text control for two-step construction. Derived classes
211 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
214 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
216 \func{virtual void
}{Cut
}{\void}
218 Copies the selected text to the clipboard and removes the selection.
220 \membersection{wxTextCtrl::DiscardEdits
}
222 \func{void
}{DiscardEdits
}{\void}
224 Resets the internal `modified' flag as if the current edits had been saved.
226 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
228 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
230 Returns the insertion point. This is defined as the zero based index of the
231 character position to the right of the insertion point. For example, if
232 the insertion point is at the end of the text control, it is equal to
233 both
\helpref{GetValue()
}{wxtextctrlgetvalue
}.Length() and
234 \helpref{GetLastPosition()
}{wxtextctrlgetlastposition
}.
236 The following code snippet safely returns the character at the insertion
237 point or the zero character if the point is at the end of the control.
241 char GetCurrentChar(wxTextCtrl *tc)
{
242 if (tc->GetInsertionPoint() == tc->GetLastPosition())
244 return tc->GetValue
[tc->GetInsertionPoint()
];
249 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
251 \constfunc{virtual long
}{GetLastPosition
}{\void}
253 Returns the zero based index of the last position in the text control,
254 which is equal to the number of characters in the control.
256 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
258 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
260 Gets the length of the specified line, not including any trailing newline
263 \wxheading{Parameters
}
265 \docparam{lineNo
}{Line number (starting from zero).
}
267 \wxheading{Return value
}
269 The length of the line, or -
1 if
{\it lineNo
} was invalid.
271 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
273 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
275 Returns the contents of a given line in the text control, not including
276 any trailing newline character(s).
278 \wxheading{Parameters
}
280 \docparam{lineNo
}{The line number, starting from zero.
}
282 \wxheading{Return value
}
284 The contents of the line.
286 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
288 \constfunc{int
}{GetNumberOfLines
}{\void}
290 Returns the number of lines in the text control buffer.
294 Note that even empty text controls have one line (where the insertion point
295 is), so GetNumberOfLines() never returns
0.
297 For gtk
\_text (multi-line) controls, the number of lines is
298 calculated by actually counting newline characters in the buffer. You
299 may wish to avoid using functions that work with line numbers if you are
300 working with controls that contain large amounts of text.
302 \membersection{wxTextCtrl::GetSelection
}\label{wxtextctrlgetselection
}
304 \func{virtual void
}{GetSelection
}{\param{long*
}{ from
},
\param{long*
}{ to
}}
306 Gets the current selection span. If the returned values are equal, there was
309 \wxheading{Parameters
}
311 \docparam{from
}{The returned first position.
}
313 \docparam{to
}{The returned last position.
}
315 \pythonnote{The wxPython version of this method returns a tuple
316 consisting of the from and to values.
}
318 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
320 \constfunc{wxString
}{GetValue
}{\void}
322 Gets the contents of the control. Notice that for a multiline text control,
323 the lines will be separated by (Unix-style) '\
\n' characters, even under
324 Windows where they are separated by "\
\r\
\n" sequence in the native control.
326 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
328 \constfunc{bool
}{IsModified
}{\void}
330 Returns TRUE if the text has been modified.
332 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
334 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
336 Loads and displays the named file, if it exists.
338 \wxheading{Parameters
}
340 \docparam{filename
}{The filename of the file to load.
}
342 \wxheading{Return value
}
344 TRUE if successful, FALSE otherwise.
346 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
348 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
350 Default handler for character input.
354 It is possible to intercept character
355 input by overriding this member. Call this function
356 to let the default behaviour take place; not calling
357 it results in the character being ignored. You can
358 replace the
{\it keyCode
} member of
{\it event
} to
359 translate keystrokes.
361 Note that Windows and Motif have different ways
362 of implementing the default behaviour. In Windows,
363 calling wxTextCtrl::OnChar immediately
364 processes the character. In Motif,
365 calling this function simply sets a flag
366 to let default processing happen. This might affect
367 the way in which you write your OnChar function
368 on different platforms.
372 \helpref{wxKeyEvent
}{wxkeyevent
}
374 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
376 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
378 This event handler function implements default drag and drop behaviour, which
379 is to load the first dropped file into the control.
381 \wxheading{Parameters
}
383 \docparam{event
}{The drop files event.
}
387 This is not yet implemented for the GTK.
391 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
393 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
395 \func{virtual void
}{Paste
}{\void}
397 Pastes text from the clipboard to the text item.
399 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
401 \constfunc{bool
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
403 Converts given position to a zero-based column, line number pair.
405 \wxheading{Parameters
}
407 \docparam{pos
}{Position.
}
409 \docparam{x
}{Receives zero based column number.
}
411 \docparam{y
}{Receives zero based line number.
}
413 \wxheading{Return value
}
415 TRUE on success, FALSE on failure (most likely due to a too large position
420 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
422 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
423 y values, so (x,y) = PositionToXY() is equivalent to the call described
426 \membersection{wxTextCtrl::Redo
}\label{wxtextctrlredo
}
428 \func{virtual void
}{Redo
}{\void}
430 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
431 if there is no redo facility.
433 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
435 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
437 Removes the text starting at the first given position up to (but not including)
438 the character at the last position.
440 \wxheading{Parameters
}
442 \docparam{from
}{The first position.
}
444 \docparam{to
}{The last position.
}
446 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
448 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
450 Replaces the text starting at the first position up to (but not including)
451 the character at the last position with the given text.
453 \wxheading{Parameters
}
455 \docparam{from
}{The first position.
}
457 \docparam{to
}{The last position.
}
459 \docparam{value
}{The value to replace the existing text with.
}
461 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
463 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
465 Saves the contents of the control in a text file.
467 \wxheading{Parameters
}
469 \docparam{filename
}{The name of the file in which to save the text.
}
471 \wxheading{Return value
}
473 TRUE if the operation was successful, FALSE otherwise.
475 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
477 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
479 Makes the text item editable or read-only, overriding the
{\bf wxTE
\_READONLY}
482 \wxheading{Parameters
}
484 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
486 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
488 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
490 Sets the insertion point at the given position.
492 \wxheading{Parameters
}
494 \docparam{pos
}{Position to set.
}
496 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
498 \func{virtual void
}{SetInsertionPointEnd
}{\void}
500 Sets the insertion point at the end of the text control. This is equivalent
501 to
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}(
\helpref{GetLastPosition
}{wxtextctrlgetlastposition
}()).
503 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
505 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
507 Selects the text starting at the first position up to (but not including) the character at the last position.
509 \wxheading{Parameters
}
511 \docparam{from
}{The first position.
}
513 \docparam{to
}{The last position.
}
515 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
517 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
521 \wxheading{Parameters
}
523 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
525 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
527 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
529 Makes the line containing the given position visible.
531 \wxheading{Parameters
}
533 \docparam{pos
}{The position that should be visible.
}
535 \membersection{wxTextCtrl::Undo
}\label{wxtextctrlundo
}
537 \func{virtual void
}{Undo
}{\void}
539 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
540 if there is no undo facility.
542 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
544 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
546 Writes the text into the text control at the current insertion position.
548 \wxheading{Parameters
}
550 \docparam{text
}{Text to write to the text control.
}
554 Newlines in the text string
555 are the only control characters allowed, and they will cause appropriate
556 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} and
\helpref{wxTextCtrl::AppendText
}{wxtextctrlappendtext
} for more convenient ways of writing to the window.
558 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.
560 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
562 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
564 Converts the given zero based column and line number to a position.
566 \wxheading{Parameters
}
568 \docparam{x
}{The column number.
}
570 \docparam{y
}{The line number.
}
572 \wxheading{Return value
}
576 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
578 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
580 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
582 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
584 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
586 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
588 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
590 Operator definitions for appending to a text control, for example:
593 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
595 (*wnd) << "Welcome to text control number " << 1 << ".\n";