1 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
3 A text control allows text to be displayed and edited. It may be
4 single line or multiline.
6 \wxheading{Derived from
}
9 \helpref{wxControl
}{wxcontrol
}\\
10 \helpref{wxWindow
}{wxwindow
}\\
11 \helpref{wxEvtHandler
}{wxevthandler
}\\
12 \helpref{wxObject
}{wxobject
}
14 \wxheading{Window styles
}
17 \begin{twocollist
}\itemsep=
0pt
18 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The callback function will
19 receive the message wxEVENT
\_TYPE\_TEXT\_ENTER\_COMMAND. Note
20 that this will break tab traversal for this panel item under
22 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
23 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
24 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
25 \twocolitem{\windowstyle{wxHSCROLL
}}{A vertical scrollbar will be present.
}
28 See also
\helpref{window styles overview
}{windowstyles
}.
32 This class multiply-inherits from
{\bf streambuf
} where compilers allow, allowing code such
37 wxTextCtrl *control = new wxTextCtrl(...);
39 ostream stream(control)
41 stream <<
123.456 << " some text
\n";
46 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
47 wxTextCtrl header file.
49 \wxheading{Event handling
}
51 To process input from a text control, use these event handler macros to direct input to member
52 functions that take a
\helpref{wxCommandEvent
}{wxcommandevent
} argument.
55 \begin{twocollist
}\itemsep=
0pt
56 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
57 generated when the text changes.
}
58 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Respond to a wxEVT
\_COMMAND\_TEXT\_ENTER event,
59 generated when enter is pressed in a single-line text control.
}
64 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
66 \latexignore{\rtfignore{\wxheading{Members
}}}
68 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
70 \func{}{wxTextCtrl
}{\void}
74 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
75 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
76 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
78 Constructor, creating and showing a text control.
80 \wxheading{Parameters
}
82 \docparam{parent
}{Parent window. Should not be NULL.
}
84 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
86 \docparam{value
}{Default text value.
}
88 \docparam{pos
}{Text control position.
}
90 \docparam{size
}{Text control size.
}
92 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
94 \docparam{validator
}{Window validator.
}
96 \docparam{name
}{Window name.
}
100 Under Windows, if the
{\bf wxTE
\_MULTILINE} style is used, the window is implemented
101 as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
106 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
108 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
110 \func{}{\destruct{wxTextCtrl
}}{\void}
112 Destructor, destroying the text control.
114 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
116 \func{virtual void
}{Clear
}{\void}
118 Clears the text in the control.
120 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
122 \func{virtual void
}{Copy
}{\void}
124 Copies the selected text to the clipboard under Motif and MS Windows.
126 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
128 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{ id
},
\rtfsp
129 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
130 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
132 Creates the text control for two-step construction. Derived classes
133 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
136 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
138 \func{virtual void
}{Cut
}{\void}
140 Copies the selected text to the clipboard and removes the selection.
142 \membersection{wxTextCtrl::DiscardEdits
}
144 \func{void
}{DiscardEdits
}{\void}
146 Resets the internal `modified' flag as if the current edits had been saved.
148 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
150 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
152 Returns the insertion point.
154 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
156 \constfunc{virtual long
}{GetLastPosition
}{\void}
158 Returns the last position in the text control.
160 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
162 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
164 Gets the length of the specified line.
166 \wxheading{Parameters
}
168 \docparam{lineNo
}{Line number (starting from zero).
}
170 \wxheading{Return value
}
172 The length of the line, or -
1 if
{\it lineNo
} was invalid.
174 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
176 \constfunc{wxString
}{GetLineText
}{\param{long
}{ lineNo
}}
178 Returns the contents of a given line in the text control.
180 \wxheading{Parameters
}
182 \docparam{lineNo
}{The line number, starting from zero.
}
184 \wxheading{Return value
}
186 The contents of the line.
188 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
190 \constfunc{int
}{GetNumberOfLines
}{\void}
192 Returns the number of lines in the text control buffer.
194 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
196 \constfunc{wxString
}{GetValue
}{\void}
198 Gets the contents of the control.
200 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
202 \constfunc{bool
}{IsModified
}{\void}
204 Returns TRUE if the text has been modified.
206 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
208 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
210 Loads and displays the named file, if it exists.
212 \wxheading{Parameters
}
214 \docparam{filename
}{The filename of the file to load.
}
216 \wxheading{Return value
}
218 TRUE if successful, FALSE otherwise.
220 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
222 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
224 Default handler for character input.
228 It is possible to intercept character
229 input by overriding this member. Call this function
230 to let the default behaviour take place; not calling
231 it results in the character being ignored. You can
232 replace the
{\it keyCode
} member of
{\it event
} to
233 translate keystrokes.
235 Note that Windows and Motif have different ways
236 of implementing the default behaviour. In Windows,
237 calling wxTextCtrl::OnChar immediately
238 processes the character. In Motif,
239 calling this function simply sets a flag
240 to let default processing happen. This might affect
241 the way in which you write your OnChar function
242 on different platforms.
246 \helpref{wxKeyEvent
}{wxkeyevent
}
248 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
250 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
252 This event handler function implements default drag and drop behaviour, which
253 is to load the first dropped file into the control.
255 \wxheading{Parameters
}
257 \docparam{event
}{The drop files event.
}
261 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
263 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
265 \func{virtual void
}{Paste
}{\void}
267 Pastes text from the clipboard to the text item.
269 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
271 \constfunc{long
}{PositionToXY
}{\param{long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
273 Converts given character and line position to a position.
275 \wxheading{Parameters
}
277 \docparam{pos
}{Position.
}
279 \docparam{x
}{Receives character position.
}
281 \docparam{y
}{Receives line position.
}
285 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
287 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
289 \func{virtual void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
291 Removes the text between the two positions.
293 \wxheading{Parameters
}
295 \docparam{from
}{The first position.
}
297 \docparam{to
}{The last position.
}
299 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
301 \func{virtual void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{value
}}
303 Replaces the text between two positions with the given text.
305 \wxheading{Parameters
}
307 \docparam{from
}{The first position.
}
309 \docparam{to
}{The last position.
}
311 \docparam{value
}{The value to replace the existing text with.
}
313 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
315 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
317 Saves the contents of the control in a text file.
319 \wxheading{Parameters
}
321 \docparam{filename
}{The name of file in which to save the text.
}
323 \wxheading{Return value
}
325 TRUE if the operation was successful, FALSE otherwise.
327 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
329 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
331 Makes the text item editable or read-only.
333 \wxheading{Parameters
}
335 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
337 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
339 \func{virtual void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
341 Sets the insertion point. Windows only. ??
343 \wxheading{Parameters
}
345 \docparam{pos
}{Position to set.
}
347 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
349 \func{virtual void
}{SetInsertionPointEnd
}{\void}
351 Sets the insertion point at the end of the text control.
353 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
355 \func{virtual void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
357 Selects the text between the two positions.
359 \wxheading{Parameters
}
361 \docparam{from
}{The first position.
}
363 \docparam{to
}{The last position.
}
365 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
367 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
371 \wxheading{Parameters
}
373 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
375 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
377 \func{void
}{ShowPosition
}{\param{long
}{ pos
}}
379 Makes the line containing the given position visible.
381 \wxheading{Parameters
}
383 \docparam{pos
}{The position that should be visible.
}
385 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
387 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
389 Writes the text into the text control at the current position.
391 \wxheading{Parameters
}
393 \docparam{text
}{Text to write to the text control.
}
397 Newlines in the text string
398 are the only control characters allowed, and they will cause appropriate
399 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} for more convenient ways of writing to the
402 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
404 \func{long
}{XYToPosition
}{\param{long
}{ x
},
\param{long
}{ y
}}
406 Converts the given character and line position to a position.
408 \wxheading{Parameters
}
410 \docparam{x
}{The character position.
}
412 \docparam{y
}{The line position.
}
414 \wxheading{Return value
}
418 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
420 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
422 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
424 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
426 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
428 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
430 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
432 Operator definitions for writing to a text control, for example:
435 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
437 (*wnd) << "Welcome to text control number " << 1 << ".\n";