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{wxTE
\_RICH}}{Use rich text control under Win32, this
34 allows to have more than
64Kb of text in the control even under Win9x. This
35 style is ignored under other platforms.
}
36 \twocolitem{\windowstyle{wxTE
\_AUTO\_URL}}{Highlight the URLs and generate the
37 wxTextUrlEvents when mouse events occur over them. This style is supported
38 under Win32 only and requires wxTE
\_RICH.
}
39 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created. No effect under GTK+.
}
42 See also
\helpref{window styles overview
}{windowstyles
} and
43 \helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}.
47 This class multiply-inherits from
{\bf streambuf
} where compilers allow, allowing code such as
52 wxTextCtrl *control = new wxTextCtrl(...);
54 ostream stream(control)
56 stream <<
123.456 << " some text
\n";
61 If your compiler does not support derivation from
{\bf streambuf
} and gives a compile error, define the symbol
62 {\bf NO
\_TEXT\_WINDOW\_STREAM} in the wxTextCtrl header file.
64 % VZ: it is wrong to say that C++ iostreams are deprecated, we need a better
65 % wording here - disabling this for now
66 %Note that any use of C++ iostreams (including this one) is deprecated and might
67 %get completely removed in the future.
69 \wxheading{Event handling
}
71 The following commands are processed by default event handlers in wxTextCtrl: wxID
\_CUT, wxID
\_COPY,
72 wxID
\_PASTE, wxID
\_UNDO, wxID
\_REDO. The associated UI update events are also processed
73 automatically, when the control has the focus.
75 To process input from a text control, use these event handler macros to direct input to member
76 functions that take a
\helpref{wxCommandEvent
}{wxcommandevent
} argument.
79 \begin{twocollist
}\itemsep=
0pt
80 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
81 generated when the text changes. Notice that this event will always be sent
82 when the text controls contents changes - whether this is due to user input or
83 comes from the program itself (for example, if SetValue() is called)
}
84 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_ENTER event,
85 generated when enter is pressed in a single-line text control.
}
86 \twocolitem{{\bf EVT
\_TEXT\_URL(id, func)
}}{A mouse event occured over an URL
87 in the text control (Win32 only)
}
88 \twocolitem{{\bf EVT
\_TEXT\_MAXLEN(id, func)
}}{User tried to enter more text
89 into the control than the limit set by
90 \helpref{SetMaxLength
}{wxtextctrlsetmaxlength
}.
}
95 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
97 \latexignore{\rtfignore{\wxheading{Members
}}}
99 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
101 \func{}{wxTextCtrl
}{\void}
105 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
106 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
107 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
109 Constructor, creating and showing a text control.
111 \wxheading{Parameters
}
113 \docparam{parent
}{Parent window. Should not be NULL.
}
115 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
117 \docparam{value
}{Default text value.
}
119 \docparam{pos
}{Text control position.
}
121 \docparam{size
}{Text control size.
}
123 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
125 \docparam{validator
}{Window validator.
}
127 \docparam{name
}{Window name.
}
131 The horizontal scrollbar (
{\bf wxTE
\_HSCROLL} style flag) will only be created for multi-line text controls.
132 Without a horizontal scrollbar, text lines that don't fit in the control's
133 size will be wrapped (but no newline character is inserted). Single line
134 controls don't have a horizontal scrollbar, the text is automatically scrolled
135 so that the
\helpref{insertion point
}{wxtextctrlgetinsertionpoint
} is always
138 % VZ: this is no longer true
139 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
140 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
145 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
147 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
149 \func{}{\destruct{wxTextCtrl
}}{\void}
151 Destructor, destroying the text control.
153 \membersection{wxTextCtrl::AppendText
}\label{wxtextctrlappendtext
}
155 \func{void
}{AppendText
}{\param{const wxString\&
}{ text
}}
157 Appends the text to the end of the text control.
159 \wxheading{Parameters
}
161 \docparam{text
}{Text to write to the text control.
}
165 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
166 the programmer should use
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} and
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}.
170 \helpref{wxTextCtrl::WriteText
}{wxtextctrlwritetext
}
172 \membersection{wxTextCtrl::CanCopy
}\label{wxtextctrlcancopy
}
174 \func{virtual bool
}{CanCopy
}{\void}
176 Returns TRUE if the selection can be copied to the clipboard.
178 \membersection{wxTextCtrl::CanCut
}\label{wxtextctrlcancut
}
180 \func{virtual bool
}{CanCut
}{\void}
182 Returns TRUE if the selection can be cut to the clipboard.
184 \membersection{wxTextCtrl::CanPaste
}\label{wxtextctrlcanpaste
}
186 \func{virtual bool
}{CanPaste
}{\void}
188 Returns TRUE if the contents of the clipboard can be pasted into the
189 text control. On some platforms (Motif, GTK) this is an approximation
190 and returns TRUE if the control is editable, FALSE otherwise.
192 \membersection{wxTextCtrl::CanRedo
}\label{wxtextctrlcanredo
}
194 \func{virtual bool
}{CanRedo
}{\void}
196 Returns TRUE if there is a redo facility available and the last operation
199 \membersection{wxTextCtrl::CanUndo
}\label{wxtextctrlcanundo
}
201 \func{virtual bool
}{CanUndo
}{\void}
203 Returns TRUE if there is an undo facility available and the last operation
206 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
208 \func{virtual void
}{Clear
}{\void}
210 Clears the text in the control.
212 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
214 \func{virtual void
}{Copy
}{\void}
216 Copies the selected text to the clipboard under Motif and MS Windows.
218 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
220 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
221 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
222 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
224 Creates the text control for two-step construction. Derived classes
225 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
228 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
230 \func{virtual void
}{Cut
}{\void}
232 Copies the selected text to the clipboard and removes the selection.
234 \membersection{wxTextCtrl::DiscardEdits
}
236 \func{void
}{DiscardEdits
}{\void}
238 Resets the internal `modified' flag as if the current edits had been saved.
240 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
242 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
244 Returns the insertion point. This is defined as the zero based index of the
245 character position to the right of the insertion point. For example, if
246 the insertion point is at the end of the text control, it is equal to
247 both
\helpref{GetValue()
}{wxtextctrlgetvalue
}.Length() and
248 \helpref{GetLastPosition()
}{wxtextctrlgetlastposition
}.
250 The following code snippet safely returns the character at the insertion
251 point or the zero character if the point is at the end of the control.
255 char GetCurrentChar(wxTextCtrl *tc)
{
256 if (tc->GetInsertionPoint() == tc->GetLastPosition())
258 return tc->GetValue
[tc->GetInsertionPoint()
];
263 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
265 \constfunc{virtual long
}{GetLastPosition
}{\void}
267 Returns the zero based index of the last position in the text control,
268 which is equal to the number of characters in the control.
270 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
272 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
274 Gets the length of the specified line, not including any trailing newline
277 \wxheading{Parameters
}
279 \docparam{lineNo
}{Line number (starting from zero).
}
281 \wxheading{Return value
}
283 The length of the line, or -
1 if
{\it lineNo
} was invalid.
285 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
287 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
289 Returns the contents of a given line in the text control, not including
290 any trailing newline character(s).
292 \wxheading{Parameters
}
294 \docparam{lineNo
}{The line number, starting from zero.
}
296 \wxheading{Return value
}
298 The contents of the line.
300 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
302 \constfunc{int
}{GetNumberOfLines
}{\void}
304 Returns the number of lines in the text control buffer.
308 Note that even empty text controls have one line (where the insertion point
309 is), so GetNumberOfLines() never returns
0.
311 For gtk
\_text (multi-line) controls, the number of lines is
312 calculated by actually counting newline characters in the buffer. You
313 may wish to avoid using functions that work with line numbers if you are
314 working with controls that contain large amounts of text.
316 \membersection{wxTextCtrl::GetSelection
}\label{wxtextctrlgetselection
}
318 \func{virtual void
}{GetSelection
}{\param{long*
}{ from
},
\param{long*
}{ to
}}
320 Gets the current selection span. If the returned values are equal, there was
323 \wxheading{Parameters
}
325 \docparam{from
}{The returned first position.
}
327 \docparam{to
}{The returned last position.
}
329 \pythonnote{The wxPython version of this method returns a tuple
330 consisting of the from and to values.
}
332 \perlnote{In wxPerl this method takes no parameter and returns a
333 2-element list
{\tt ( from, to )
}.
}
335 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
337 \constfunc{wxString
}{GetValue
}{\void}
339 Gets the contents of the control. Notice that for a multiline text control,
340 the lines will be separated by (Unix-style) $
\backslash$n characters, even under
341 Windows where they are separated by a $
\backslash$r$
\backslash$n sequence in the native control.
343 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
345 \constfunc{bool
}{IsModified
}{\void}
347 Returns TRUE if the text has been modified.
349 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
351 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
353 Loads and displays the named file, if it exists.
355 \wxheading{Parameters
}
357 \docparam{filename
}{The filename of the file to load.
}
359 \wxheading{Return value
}
361 TRUE if successful, FALSE otherwise.
363 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
365 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
367 Default handler for character input.
371 It is possible to intercept character
372 input by overriding this member. Call this function
373 to let the default behaviour take place; not calling
374 it results in the character being ignored. You can
375 replace the
{\it keyCode
} member of
{\it event
} to
376 translate keystrokes.
378 Note that Windows and Motif have different ways
379 of implementing the default behaviour. In Windows,
380 calling wxTextCtrl::OnChar immediately
381 processes the character. In Motif,
382 calling this function simply sets a flag
383 to let default processing happen. This might affect
384 the way in which you write your OnChar function
385 on different platforms.
389 \helpref{wxKeyEvent
}{wxkeyevent
}
391 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
393 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
395 This event handler function implements default drag and drop behaviour, which
396 is to load the first dropped file into the control.
398 \wxheading{Parameters
}
400 \docparam{event
}{The drop files event.
}
404 This is not implemented on non-Windows platforms.
408 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
410 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
412 \func{virtual void
}{Paste
}{\void}
414 Pastes text from the clipboard to the text item.
416 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
418 \constfunc{bool
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
420 Converts given position to a zero-based column, line number pair.
422 \wxheading{Parameters
}
424 \docparam{pos
}{Position.
}
426 \docparam{x
}{Receives zero based column number.
}
428 \docparam{y
}{Receives zero based line number.
}
430 \wxheading{Return value
}
432 TRUE on success, FALSE on failure (most likely due to a too large position
437 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
439 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
440 y values, so (x,y) = PositionToXY() is equivalent to the call described
443 \perlnote{In wxPerl this method only takes the
{\tt pos
} parameter, and
444 returns a
2-element list
{\tt ( x, y )
}.
}
446 \membersection{wxTextCtrl::Redo
}\label{wxtextctrlredo
}
448 \func{virtual void
}{Redo
}{\void}
450 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
451 if there is no redo facility.
453 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
455 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
457 Removes the text starting at the first given position up to (but not including)
458 the character at the last position.
460 \wxheading{Parameters
}
462 \docparam{from
}{The first position.
}
464 \docparam{to
}{The last position.
}
466 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
468 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
470 Replaces the text starting at the first position up to (but not including)
471 the character at the last position with the given text.
473 \wxheading{Parameters
}
475 \docparam{from
}{The first position.
}
477 \docparam{to
}{The last position.
}
479 \docparam{value
}{The value to replace the existing text with.
}
481 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
483 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
485 Saves the contents of the control in a text file.
487 \wxheading{Parameters
}
489 \docparam{filename
}{The name of the file in which to save the text.
}
491 \wxheading{Return value
}
493 TRUE if the operation was successful, FALSE otherwise.
495 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
497 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
499 Makes the text item editable or read-only, overriding the
{\bf wxTE
\_READONLY} flag.
501 \wxheading{Parameters
}
503 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
505 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
507 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
509 Sets the insertion point at the given position.
511 \wxheading{Parameters
}
513 \docparam{pos
}{Position to set.
}
515 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
517 \func{virtual void
}{SetInsertionPointEnd
}{\void}
519 Sets the insertion point at the end of the text control. This is equivalent
520 to
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}(
\helpref{GetLastPosition
}{wxtextctrlgetlastposition
}()).
522 \membersection{wxTextCtrl::SetMaxLength
}\label{wxtextctrlsetmaxlength
}
524 \func{virtual void
}{SetMaxLength
}{\param{unsigned long
}{len
}}
526 This function sets the maximum number of characters the user can enter into the
527 control. In other words, it allows to limit the text value length to
{\it len
}
528 not counting the terminating
{\tt NUL
} character.
530 If
{\it len
} is $
0$, the previously set max length limi, if any, is discarded
531 and the user may enter as much text as the underlying native text control
532 widget supports (typically at least
32Kb).
534 If the user tries to enter more characters into the text control when it
535 already is filled up to the maximal length, a
536 {\tt wxEVT
\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
537 (giving it the possibility to show an explanatory message, for example) and the
538 extra input is discarded.
540 Note that this function may only be used with single line text controls.
542 \wxheading{Compatibility
}
544 Only implemented in wxMSW/wxGTK starting with wxWindows
2.3.2.
546 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
548 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
550 Selects the text starting at the first position up to (but not including) the character at the last position.
552 \wxheading{Parameters
}
554 \docparam{from
}{The first position.
}
556 \docparam{to
}{The last position.
}
558 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
560 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
562 Sets the text value and marks the control as not-modified.
564 \wxheading{Parameters
}
566 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
568 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
570 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
572 Makes the line containing the given position visible.
574 \wxheading{Parameters
}
576 \docparam{pos
}{The position that should be visible.
}
578 \membersection{wxTextCtrl::Undo
}\label{wxtextctrlundo
}
580 \func{virtual void
}{Undo
}{\void}
582 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
583 if there is no undo facility.
585 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
587 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
589 Writes the text into the text control at the current insertion position.
591 \wxheading{Parameters
}
593 \docparam{text
}{Text to write to the text control.
}
597 Newlines in the text string
598 are the only control characters allowed, and they will cause appropriate
599 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} and
\helpref{wxTextCtrl::AppendText
}{wxtextctrlappendtext
} for more convenient ways of writing to the window.
601 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.
603 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
605 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
607 Converts the given zero based column and line number to a position.
609 \wxheading{Parameters
}
611 \docparam{x
}{The column number.
}
613 \docparam{y
}{The line number.
}
615 \wxheading{Return value
}
619 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
621 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
623 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
625 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
627 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
629 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
631 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
633 Operator definitions for appending to a text control, for example:
636 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
638 (*wnd) << "Welcome to text control number " << 1 << ".\n";