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.
}
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 the following:
45 wxTextCtrl *control = new wxTextCtrl(...);
47 ostream stream(control)
49 stream <<
123.456 << " some text
\n";
54 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
55 wxTextCtrl header file.
57 \wxheading{Event handling
}
59 The following commands are processed by default event handlers in wxTextCtrl: wxID
\_CUT, wxID
\_COPY,
60 wxID
\_PASTE, wxID
\_UNDO, wxID
\_REDO. The associated UI update events are also processed
61 automatically, when the control has the focus.
63 To process input from a text control, use these event handler macros to direct input to member
64 functions that take a
\helpref{wxCommandEvent
}{wxcommandevent
} argument.
67 \begin{twocollist
}\itemsep=
0pt
68 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
69 generated when the text changes.
}
70 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_ENTER event,
71 generated when enter is pressed in a single-line text control.
}
76 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
78 \latexignore{\rtfignore{\wxheading{Members
}}}
80 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
82 \func{}{wxTextCtrl
}{\void}
86 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
87 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
88 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
90 Constructor, creating and showing a text control.
92 \wxheading{Parameters
}
94 \docparam{parent
}{Parent window. Should not be NULL.
}
96 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
98 \docparam{value
}{Default text value.
}
100 \docparam{pos
}{Text control position.
}
102 \docparam{size
}{Text control size.
}
104 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
106 \docparam{validator
}{Window validator.
}
108 \docparam{name
}{Window name.
}
112 The horizontal scrollbar (
{\bf wxTE
\_HSCROLL} style flag) will only be created for multi-line text controls.
113 Without a horizontal scrollbar, text lines that don't fit in the control's
114 size will be wrapped (but no newline character is inserted). Single line
115 controls don't have a horizontal scrollbar, the text is automatically scrolled
116 so that the
\helpref{insertion point
}{wxtextctrlgetinsertionpoint
} is always
119 Under Windows, if the
{\bf wxTE
\_MULTILINE} style is used, the window is implemented
120 as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
125 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
127 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
129 \func{}{\destruct{wxTextCtrl
}}{\void}
131 Destructor, destroying the text control.
133 \membersection{wxTextCtrl::AppendText
}\label{wxtextctrlappendtext
}
135 \func{void
}{AppendText
}{\param{const wxString\&
}{ text
}}
137 Appends the text to the end of the text control.
139 \wxheading{Parameters
}
141 \docparam{text
}{Text to write to the text control.
}
145 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
146 the programmer should use
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} and
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}.
150 \helpref{wxTextCtrl::WriteText
}{wxtextctrlwritetext
}
152 \membersection{wxTextCtrl::CanCopy
}\label{wxtextctrlcancopy
}
154 \func{virtual bool
}{CanCopy
}{\void}
156 Returns TRUE if the selection can be copied to the clipboard.
158 \membersection{wxTextCtrl::CanCut
}\label{wxtextctrlcancut
}
160 \func{virtual bool
}{CanCut
}{\void}
162 Returns TRUE if the selection can be cut to the clipboard.
164 \membersection{wxTextCtrl::CanPaste
}\label{wxtextctrlcanpaste
}
166 \func{virtual bool
}{CanPaste
}{\void}
168 Returns TRUE if the contents of the clipboard can be pasted into the
169 text control. On some platforms (Motif, GTK) this is an approximation
170 and returns TRUE if the control is editable, FALSE otherwise.
172 \membersection{wxTextCtrl::CanRedo
}\label{wxtextctrlcanredo
}
174 \func{virtual bool
}{CanRedo
}{\void}
176 Returns TRUE if there is a redo facility available and the last operation
179 \membersection{wxTextCtrl::CanUndo
}\label{wxtextctrlcanundo
}
181 \func{virtual bool
}{CanUndo
}{\void}
183 Returns TRUE if there is an undo facility available and the last operation
186 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
188 \func{virtual void
}{Clear
}{\void}
190 Clears the text in the control.
192 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
194 \func{virtual void
}{Copy
}{\void}
196 Copies the selected text to the clipboard under Motif and MS Windows.
198 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
200 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
201 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
202 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
204 Creates the text control for two-step construction. Derived classes
205 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
208 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
210 \func{virtual void
}{Cut
}{\void}
212 Copies the selected text to the clipboard and removes the selection.
214 \membersection{wxTextCtrl::DiscardEdits
}
216 \func{void
}{DiscardEdits
}{\void}
218 Resets the internal `modified' flag as if the current edits had been saved.
220 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
222 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
224 Returns the insertion point. This is defined as the zero based index of the
225 character position to the right of the insertion point. For example, if
226 the insertion point is at the end of the text control, it is equal to
227 both
\helpref{GetValue()
}{wxtextctrlgetvalue
}.Length() and
228 \helpref{GetLastPosition()
}{wxtextctrlgetlastposition
}.
230 The following code snippet safely returns the character at the insertion
231 point or the zero character if the point is at the end of the control.
235 char GetCurrentChar(wxTextCtrl *tc)
{
236 if (tc->GetInsertionPoint() == tc->GetLastPosition())
238 return tc->GetValue
[tc->GetInsertionPoint()
];
243 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
245 \constfunc{virtual long
}{GetLastPosition
}{\void}
247 Returns the zero based index of the last position in the text control,
248 which is equal to the number of characters in the control.
250 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
252 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
254 Gets the length of the specified line, not including any trailing newline
257 \wxheading{Parameters
}
259 \docparam{lineNo
}{Line number (starting from zero).
}
261 \wxheading{Return value
}
263 The length of the line, or -
1 if
{\it lineNo
} was invalid.
265 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
267 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
269 Returns the contents of a given line in the text control, not including
270 any trailing newline character(s).
272 \wxheading{Parameters
}
274 \docparam{lineNo
}{The line number, starting from zero.
}
276 \wxheading{Return value
}
278 The contents of the line.
280 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
282 \constfunc{int
}{GetNumberOfLines
}{\void}
284 Returns the number of lines in the text control buffer.
288 Note that even empty text controls have one line (where the insertion point
289 is), so GetNumberOfLines() never returns
0.
291 For gtk
\_text (multi-line) controls, the number of lines is
292 calculated by actually counting newline characters in the buffer. You
293 may wish to avoid using functions that work with line numbers if you are
294 working with controls that contain large amounts of text.
296 \membersection{wxTextCtrl::GetSelection
}\label{wxtextctrlgetselection
}
298 \func{virtual void
}{GetSelection
}{\param{long*
}{ from
},
\param{long*
}{ to
}}
300 Gets the current selection span. If the returned values are equal, there was
303 \wxheading{Parameters
}
305 \docparam{from
}{The returned first position.
}
307 \docparam{to
}{The returned last position.
}
309 \pythonnote{The wxPython version of this method returns a tuple
310 consisting of the from and to values.
}
312 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
314 \constfunc{wxString
}{GetValue
}{\void}
316 Gets the contents of the control.
318 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
320 \constfunc{bool
}{IsModified
}{\void}
322 Returns TRUE if the text has been modified.
324 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
326 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
328 Loads and displays the named file, if it exists.
330 \wxheading{Parameters
}
332 \docparam{filename
}{The filename of the file to load.
}
334 \wxheading{Return value
}
336 TRUE if successful, FALSE otherwise.
338 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
340 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
342 Default handler for character input.
346 It is possible to intercept character
347 input by overriding this member. Call this function
348 to let the default behaviour take place; not calling
349 it results in the character being ignored. You can
350 replace the
{\it keyCode
} member of
{\it event
} to
351 translate keystrokes.
353 Note that Windows and Motif have different ways
354 of implementing the default behaviour. In Windows,
355 calling wxTextCtrl::OnChar immediately
356 processes the character. In Motif,
357 calling this function simply sets a flag
358 to let default processing happen. This might affect
359 the way in which you write your OnChar function
360 on different platforms.
364 \helpref{wxKeyEvent
}{wxkeyevent
}
366 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
368 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
370 This event handler function implements default drag and drop behaviour, which
371 is to load the first dropped file into the control.
373 \wxheading{Parameters
}
375 \docparam{event
}{The drop files event.
}
379 This is not yet implemented for the GTK.
383 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
385 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
387 \func{virtual void
}{Paste
}{\void}
389 Pastes text from the clipboard to the text item.
391 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
393 \constfunc{long
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
395 Converts given position to a zero-based column, line number pair.
397 \wxheading{Parameters
}
399 \docparam{pos
}{Position.
}
401 \docparam{x
}{Receives zero based column number.
}
403 \docparam{y
}{Receives zero based line number.
}
405 \wxheading{Return value
}
407 Non-zero on success, zero on failure (most likely due to a too large position
412 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
414 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
415 y values, so (x,y) = PositionToXY() is equivalent to the call described
418 \membersection{wxTextCtrl::Redo
}\label{wxtextctrlredo
}
420 \func{virtual void
}{Redo
}{\void}
422 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
423 if there is no redo facility.
425 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
427 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
429 Removes the text starting at the first given position up to (but not including)
430 the character at the last position.
432 \wxheading{Parameters
}
434 \docparam{from
}{The first position.
}
436 \docparam{to
}{The last position.
}
438 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
440 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
442 Replaces the text starting at the first position up to (but not including)
443 the character at the last position with the given text.
445 \wxheading{Parameters
}
447 \docparam{from
}{The first position.
}
449 \docparam{to
}{The last position.
}
451 \docparam{value
}{The value to replace the existing text with.
}
453 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
455 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
457 Saves the contents of the control in a text file.
459 \wxheading{Parameters
}
461 \docparam{filename
}{The name of the file in which to save the text.
}
463 \wxheading{Return value
}
465 TRUE if the operation was successful, FALSE otherwise.
467 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
469 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
471 Makes the text item editable or read-only, overriding the
{\bf wxTE
\_READONLY}
474 \wxheading{Parameters
}
476 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
478 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
480 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
482 Sets the insertion point at the given position.
484 \wxheading{Parameters
}
486 \docparam{pos
}{Position to set.
}
488 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
490 \func{virtual void
}{SetInsertionPointEnd
}{\void}
492 Sets the insertion point at the end of the text control. This is equivalent
493 to
\helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
}(
\helpref{GetLastPosition
}{wxtextctrlgetlastposition
}()).
495 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
497 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
499 Selects the text starting at the first position up to (but not including) the character at the last position.
501 \wxheading{Parameters
}
503 \docparam{from
}{The first position.
}
505 \docparam{to
}{The last position.
}
507 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
509 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
513 \wxheading{Parameters
}
515 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
517 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
519 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
521 Makes the line containing the given position visible.
523 \wxheading{Parameters
}
525 \docparam{pos
}{The position that should be visible.
}
527 \membersection{wxTextCtrl::Undo
}\label{wxtextctrlundo
}
529 \func{virtual void
}{Undo
}{\void}
531 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
532 if there is no undo facility.
534 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
536 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
538 Writes the text into the text control at the current insertion position.
540 \wxheading{Parameters
}
542 \docparam{text
}{Text to write to the text control.
}
546 Newlines in the text string
547 are the only control characters allowed, and they will cause appropriate
548 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} and
\helpref{wxTextCtrl::AppendText
}{wxtextctrlappendtext
} for more convenient ways of writing to the window.
550 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.
552 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
554 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
556 Converts the given zero based column and line number to a position.
558 \wxheading{Parameters
}
560 \docparam{x
}{The column number.
}
562 \docparam{y
}{The line number.
}
564 \wxheading{Return value
}
568 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
570 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
572 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
574 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
576 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
578 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
580 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
582 Operator definitions for appending to a text control, for example:
585 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
587 (*wnd) << "Welcome to text control number " << 1 << ".\n";