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{wxTE
\_NOHIDESEL}}{By default, the Windows text control
40 doesn't show the selection when it doesn't have focus - use this style to force
41 it to always show it. It doesn't do anything under other platforms.
}
42 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created. No effect under GTK+.
}
45 See also
\helpref{window styles overview
}{windowstyles
} and
46 \helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}.
50 This class multiply-inherits from
{\bf streambuf
} where compilers allow, allowing code such as
55 wxTextCtrl *control = new wxTextCtrl(...);
57 ostream stream(control)
59 stream <<
123.456 << " some text
\n";
64 If your compiler does not support derivation from
{\bf streambuf
} and gives a compile error, define the symbol
65 {\bf NO
\_TEXT\_WINDOW\_STREAM} in the wxTextCtrl header file.
67 % VZ: it is wrong to say that C++ iostreams are deprecated, we need a better
68 % wording here - disabling this for now
69 %Note that any use of C++ iostreams (including this one) is deprecated and might
70 %get completely removed in the future.
72 \wxheading{Event handling
}
74 The following commands are processed by default event handlers in wxTextCtrl: wxID
\_CUT, wxID
\_COPY,
75 wxID
\_PASTE, wxID
\_UNDO, wxID
\_REDO. The associated UI update events are also processed
76 automatically, when the control has the focus.
78 To process input from a text control, use these event handler macros to direct input to member
79 functions that take a
\helpref{wxCommandEvent
}{wxcommandevent
} argument.
82 \begin{twocollist
}\itemsep=
0pt
83 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
84 generated when the text changes. Notice that this event will always be sent
85 when the text controls contents changes - whether this is due to user input or
86 comes from the program itself (for example, if SetValue() is called)
}
87 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_ENTER event,
88 generated when enter is pressed in a single-line text control.
}
89 \twocolitem{{\bf EVT
\_TEXT\_URL(id, func)
}}{A mouse event occured over an URL
90 in the text control (Win32 only)
}
91 \twocolitem{{\bf EVT
\_TEXT\_MAXLEN(id, func)
}}{User tried to enter more text
92 into the control than the limit set by
93 \helpref{SetMaxLength
}{wxtextctrlsetmaxlength
}.
}
98 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
100 \latexignore{\rtfignore{\wxheading{Members
}}}
102 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
104 \func{}{wxTextCtrl
}{\void}
108 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
109 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
110 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
112 Constructor, creating and showing a text control.
114 \wxheading{Parameters
}
116 \docparam{parent
}{Parent window. Should not be NULL.
}
118 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
120 \docparam{value
}{Default text value.
}
122 \docparam{pos
}{Text control position.
}
124 \docparam{size
}{Text control size.
}
126 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
128 \docparam{validator
}{Window validator.
}
130 \docparam{name
}{Window name.
}
134 The horizontal scrollbar (
{\bf wxTE
\_HSCROLL} style flag) will only be created for multi-line text controls.
135 Without a horizontal scrollbar, text lines that don't fit in the control's
136 size will be wrapped (but no newline character is inserted). Single line
137 controls don't have a horizontal scrollbar, the text is automatically scrolled
138 so that the
\helpref{insertion point
}{wxtextctrlgetinsertionpoint
} is always
141 % VZ: this is no longer true
142 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
143 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
148 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
150 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
152 \func{}{\destruct{wxTextCtrl
}}{\void}
154 Destructor, destroying the text control.
156 \membersection{wxTextCtrl::AppendText
}\label{wxtextctrlappendtext
}
158 \func{void
}{AppendText
}{\param{const wxString\&
}{ text
}}
160 Appends the text to the end of the text control.
162 \wxheading{Parameters
}
164 \docparam{text
}{Text to write to the text control.
}
168 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
169 the programmer should use
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} and
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}.
173 \helpref{wxTextCtrl::WriteText
}{wxtextctrlwritetext
}
175 \membersection{wxTextCtrl::CanCopy
}\label{wxtextctrlcancopy
}
177 \func{virtual bool
}{CanCopy
}{\void}
179 Returns TRUE if the selection can be copied to the clipboard.
181 \membersection{wxTextCtrl::CanCut
}\label{wxtextctrlcancut
}
183 \func{virtual bool
}{CanCut
}{\void}
185 Returns TRUE if the selection can be cut to the clipboard.
187 \membersection{wxTextCtrl::CanPaste
}\label{wxtextctrlcanpaste
}
189 \func{virtual bool
}{CanPaste
}{\void}
191 Returns TRUE if the contents of the clipboard can be pasted into the
192 text control. On some platforms (Motif, GTK) this is an approximation
193 and returns TRUE if the control is editable, FALSE otherwise.
195 \membersection{wxTextCtrl::CanRedo
}\label{wxtextctrlcanredo
}
197 \func{virtual bool
}{CanRedo
}{\void}
199 Returns TRUE if there is a redo facility available and the last operation
202 \membersection{wxTextCtrl::CanUndo
}\label{wxtextctrlcanundo
}
204 \func{virtual bool
}{CanUndo
}{\void}
206 Returns TRUE if there is an undo facility available and the last operation
209 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
211 \func{virtual void
}{Clear
}{\void}
213 Clears the text in the control.
215 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
217 \func{virtual void
}{Copy
}{\void}
219 Copies the selected text to the clipboard under Motif and MS Windows.
221 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
223 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
224 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
225 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
227 Creates the text control for two-step construction. Derived classes
228 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
231 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
233 \func{virtual void
}{Cut
}{\void}
235 Copies the selected text to the clipboard and removes the selection.
237 \membersection{wxTextCtrl::DiscardEdits
}
239 \func{void
}{DiscardEdits
}{\void}
241 Resets the internal `modified' flag as if the current edits had been saved.
243 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
245 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
247 Returns the insertion point. This is defined as the zero based index of the
248 character position to the right of the insertion point. For example, if
249 the insertion point is at the end of the text control, it is equal to
250 both
\helpref{GetValue()
}{wxtextctrlgetvalue
}.Length() and
251 \helpref{GetLastPosition()
}{wxtextctrlgetlastposition
}.
253 The following code snippet safely returns the character at the insertion
254 point or the zero character if the point is at the end of the control.
258 char GetCurrentChar(wxTextCtrl *tc)
{
259 if (tc->GetInsertionPoint() == tc->GetLastPosition())
261 return tc->GetValue
[tc->GetInsertionPoint()
];
266 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
268 \constfunc{virtual long
}{GetLastPosition
}{\void}
270 Returns the zero based index of the last position in the text control,
271 which is equal to the number of characters in the control.
273 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
275 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
277 Gets the length of the specified line, not including any trailing newline
280 \wxheading{Parameters
}
282 \docparam{lineNo
}{Line number (starting from zero).
}
284 \wxheading{Return value
}
286 The length of the line, or -
1 if
{\it lineNo
} was invalid.
288 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
290 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
292 Returns the contents of a given line in the text control, not including
293 any trailing newline character(s).
295 \wxheading{Parameters
}
297 \docparam{lineNo
}{The line number, starting from zero.
}
299 \wxheading{Return value
}
301 The contents of the line.
303 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
305 \constfunc{int
}{GetNumberOfLines
}{\void}
307 Returns the number of lines in the text control buffer.
311 Note that even empty text controls have one line (where the insertion point
312 is), so GetNumberOfLines() never returns
0.
314 For gtk
\_text (multi-line) controls, the number of lines is
315 calculated by actually counting newline characters in the buffer. You
316 may wish to avoid using functions that work with line numbers if you are
317 working with controls that contain large amounts of text.
319 \membersection{wxTextCtrl::GetSelection
}\label{wxtextctrlgetselection
}
321 \func{virtual void
}{GetSelection
}{\param{long*
}{ from
},
\param{long*
}{ to
}}
323 Gets the current selection span. If the returned values are equal, there was
326 \wxheading{Parameters
}
328 \docparam{from
}{The returned first position.
}
330 \docparam{to
}{The returned last position.
}
332 \pythonnote{The wxPython version of this method returns a tuple
333 consisting of the from and to values.
}
335 \perlnote{In wxPerl this method takes no parameter and returns a
336 2-element list
{\tt ( from, to )
}.
}
338 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
340 \constfunc{wxString
}{GetValue
}{\void}
342 Gets the contents of the control. Notice that for a multiline text control,
343 the lines will be separated by (Unix-style) $
\backslash$n characters, even under
344 Windows where they are separated by a $
\backslash$r$
\backslash$n sequence in the native control.
346 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
348 \constfunc{bool
}{IsModified
}{\void}
350 Returns TRUE if the text has been modified.
352 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
354 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
356 Loads and displays the named file, if it exists.
358 \wxheading{Parameters
}
360 \docparam{filename
}{The filename of the file to load.
}
362 \wxheading{Return value
}
364 TRUE if successful, FALSE otherwise.
366 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
368 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
370 Default handler for character input.
374 It is possible to intercept character
375 input by overriding this member. Call this function
376 to let the default behaviour take place; not calling
377 it results in the character being ignored. You can
378 replace the
{\it keyCode
} member of
{\it event
} to
379 translate keystrokes.
381 Note that Windows and Motif have different ways
382 of implementing the default behaviour. In Windows,
383 calling wxTextCtrl::OnChar immediately
384 processes the character. In Motif,
385 calling this function simply sets a flag
386 to let default processing happen. This might affect
387 the way in which you write your OnChar function
388 on different platforms.
392 \helpref{wxKeyEvent
}{wxkeyevent
}
394 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
396 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
398 This event handler function implements default drag and drop behaviour, which
399 is to load the first dropped file into the control.
401 \wxheading{Parameters
}
403 \docparam{event
}{The drop files event.
}
407 This is not implemented on non-Windows platforms.
411 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
413 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
415 \func{virtual void
}{Paste
}{\void}
417 Pastes text from the clipboard to the text item.
419 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
421 \constfunc{bool
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
423 Converts given position to a zero-based column, line number pair.
425 \wxheading{Parameters
}
427 \docparam{pos
}{Position.
}
429 \docparam{x
}{Receives zero based column number.
}
431 \docparam{y
}{Receives zero based line number.
}
433 \wxheading{Return value
}
435 TRUE on success, FALSE on failure (most likely due to a too large position
440 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
442 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
443 y values, so (x,y) = PositionToXY() is equivalent to the call described
446 \perlnote{In wxPerl this method only takes the
{\tt pos
} parameter, and
447 returns a
2-element list
{\tt ( x, y )
}.
}
449 \membersection{wxTextCtrl::Redo
}\label{wxtextctrlredo
}
451 \func{virtual void
}{Redo
}{\void}
453 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
454 if there is no redo facility.
456 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
458 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
460 Removes the text starting at the first given position up to (but not including)
461 the character at the last position.
463 \wxheading{Parameters
}
465 \docparam{from
}{The first position.
}
467 \docparam{to
}{The last position.
}
469 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
471 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
473 Replaces the text starting at the first position up to (but not including)
474 the character at the last position with the given text.
476 \wxheading{Parameters
}
478 \docparam{from
}{The first position.
}
480 \docparam{to
}{The last position.
}
482 \docparam{value
}{The value to replace the existing text with.
}
484 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
486 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
488 Saves the contents of the control in a text file.
490 \wxheading{Parameters
}
492 \docparam{filename
}{The name of the file in which to save the text.
}
494 \wxheading{Return value
}
496 TRUE if the operation was successful, FALSE otherwise.
498 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
500 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
502 Makes the text item editable or read-only, overriding the
{\bf wxTE
\_READONLY} flag.
504 \wxheading{Parameters
}
506 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
508 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
510 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
512 Sets the insertion point at the given position.
514 \wxheading{Parameters
}
516 \docparam{pos
}{Position to set.
}
518 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
520 \func{virtual void
}{SetInsertionPointEnd
}{\void}
522 Sets the insertion point at the end of the text control. This is equivalent
523 to
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}(
\helpref{GetLastPosition
}{wxtextctrlgetlastposition
}()).
525 \membersection{wxTextCtrl::SetMaxLength
}\label{wxtextctrlsetmaxlength
}
527 \func{virtual void
}{SetMaxLength
}{\param{unsigned long
}{len
}}
529 This function sets the maximum number of characters the user can enter into the
530 control. In other words, it allows to limit the text value length to
{\it len
}
531 not counting the terminating
{\tt NUL
} character.
533 If
{\it len
} is $
0$, the previously set max length limi, if any, is discarded
534 and the user may enter as much text as the underlying native text control
535 widget supports (typically at least
32Kb).
537 If the user tries to enter more characters into the text control when it
538 already is filled up to the maximal length, a
539 {\tt wxEVT
\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
540 (giving it the possibility to show an explanatory message, for example) and the
541 extra input is discarded.
543 Note that this function may only be used with single line text controls.
545 \wxheading{Compatibility
}
547 Only implemented in wxMSW/wxGTK starting with wxWindows
2.3.2.
549 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
551 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
553 Selects the text starting at the first position up to (but not including) the character at the last position.
555 \wxheading{Parameters
}
557 \docparam{from
}{The first position.
}
559 \docparam{to
}{The last position.
}
561 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
563 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
565 Sets the text value and marks the control as not-modified.
567 \wxheading{Parameters
}
569 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
571 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
573 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
575 Makes the line containing the given position visible.
577 \wxheading{Parameters
}
579 \docparam{pos
}{The position that should be visible.
}
581 \membersection{wxTextCtrl::Undo
}\label{wxtextctrlundo
}
583 \func{virtual void
}{Undo
}{\void}
585 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
586 if there is no undo facility.
588 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
590 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
592 Writes the text into the text control at the current insertion position.
594 \wxheading{Parameters
}
596 \docparam{text
}{Text to write to the text control.
}
600 Newlines in the text string
601 are the only control characters allowed, and they will cause appropriate
602 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} and
\helpref{wxTextCtrl::AppendText
}{wxtextctrlappendtext
} for more convenient ways of writing to the window.
604 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.
606 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
608 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
610 Converts the given zero based column and line number to a position.
612 \wxheading{Parameters
}
614 \docparam{x
}{The column number.
}
616 \docparam{y
}{The line number.
}
618 \wxheading{Return value
}
622 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
624 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
626 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
628 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
630 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
632 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
634 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
636 Operator definitions for appending to a text control, for example:
639 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
641 (*wnd) << "Welcome to text control number " << 1 << ".\n";