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