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.
51 %\helpref{wxRichTextCtrl}{wxrichtextctrl}
53 \latexignore{\rtfignore{\wxheading{Members
}}}
55 \membersection{wxTextCtrl::wxTextCtrl
}\label{wxtextctrlconstr
}
57 \func{}{wxTextCtrl
}{\void}
61 \func{}{wxTextCtrl
}{\param{wxWindow*
}{parent
},
\param{const wxWindowID
}{ id
},
\rtfsp
62 \param{const wxString\&
}{value = ``"
},
\param{const wxPosition\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
63 \param{const long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
65 Constructor, creating and showing a text control.
67 \wxheading{Parameters
}
69 \docparam{parent
}{Parent window. Should not be NULL.
}
71 \docparam{id
}{Control identifier. A value of -
1 denotes a default value.
}
73 \docparam{value
}{Default text value.
}
75 \docparam{pos
}{Text control position.
}
77 \docparam{size
}{Text control size.
}
79 \docparam{style
}{Window style. See
\helpref{wxTextCtrl
}{wxtextctrl
}.
}
81 \docparam{validator
}{Window validator.
}
83 \docparam{name
}{Window name.
}
87 Under Windows, if the
{\bf wxTE
\_MULTILINE} style is used, the window is implemented
88 as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
93 \helpref{wxTextCtrl::Create
}{wxtextctrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
95 \membersection{wxTextCtrl::
\destruct{wxTextCtrl
}}
97 \func{}{\destruct{wxTextCtrl
}}{\void}
99 Destructor, destroying the text control.
101 \membersection{wxTextCtrl::Clear
}\label{wxtextctrlclear
}
103 \func{virtual void
}{Clear
}{\void}
105 Clears the text in the control.
107 \membersection{wxTextCtrl::Copy
}\label{wxtextctrlcopy
}
109 \func{virtual void
}{Copy
}{\void}
111 Copies the selected text to the clipboard under Motif and MS Windows.
113 \membersection{wxTextCtrl::Create
}\label{wxtextctrlcreate
}
115 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{const wxWindowID
}{ id
},
\rtfsp
116 \param{const wxString\&
}{value = ``"
},
\param{const wxPosition\&
}{pos
},
\param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
117 \param{const long
}{ style =
0},
\param{const wxValidator\&
}{validator
},
\param{const wxString\&
}{name = ``text"
}}
119 Creates the text control for two-step construction. Derived classes
120 should call or replace this function. See
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}\rtfsp
123 \membersection{wxTextCtrl::Cut
}\label{wxtextctrlcut
}
125 \func{virtual void
}{Cut
}{\void}
127 Copies the selected text to the clipboard and removes the selection.
129 \membersection{wxTextCtrl::DiscardEdits
}
131 \func{void
}{DiscardEdits
}{\void}
133 Resets the internal `modified' flag as if the current edits had been saved.
135 \membersection{wxTextCtrl::GetInsertionPoint
}\label{wxtextctrlgetinsertionpoint
}
137 \constfunc{virtual long
}{GetInsertionPoint
}{\void}
139 Returns the insertion point.
141 \membersection{wxTextCtrl::GetLastPosition
}\label{wxtextctrlgetlastposition
}
143 \constfunc{virtual long
}{GetLastPosition
}{\void}
145 Returns the last position in the text control.
147 \membersection{wxTextCtrl::GetLineLength
}\label{wxtextctrlgetlinelength
}
149 \constfunc{int
}{GetLineLength
}{\param{long
}{ lineNo
}}
151 Gets the length of the specified line.
153 \wxheading{Parameters
}
155 \docparam{lineNo
}{Line number (starting from zero).
}
157 \wxheading{Return value
}
159 The length of the line, or -
1 if
{\it lineNo
} was invalid.
161 \membersection{wxTextCtrl::GetLineText
}\label{wxtextctrlgetlinetext
}
163 \constfunc{wxString
}{GetLineText
}{\param{const long
}{ lineNo
}}
165 Returns the contents of a given line in the text control.
167 \wxheading{Parameters
}
169 \docparam{lineNo
}{The line number, starting from zero.
}
171 \wxheading{Return value
}
173 The contents of the line.
175 \membersection{wxTextCtrl::GetNumberOfLines
}\label{wxtextctrlgetnumberoflines
}
177 \constfunc{int
}{GetNumberOfLines
}{\void}
179 Returns the number of lines in the text control buffer.
181 \membersection{wxTextCtrl::GetValue
}\label{wxtextctrlgetvalue
}
183 \constfunc{wxString
}{GetValue
}{\void}
185 Gets the contents of the control.
187 \membersection{wxTextCtrl::IsModified
}\label{wxtextctrlismodified
}
189 \constfunc{bool
}{IsModified
}{\void}
191 Returns TRUE if the text has been modified.
193 \membersection{wxTextCtrl::LoadFile
}\label{wxtextctrlloadfile
}
195 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ filename
}}
197 Loads and displays the named file, if it exists.
199 \wxheading{Parameters
}
201 \docparam{filename
}{The filename of the file to load.
}
203 \wxheading{Return value
}
205 TRUE if successful, FALSE otherwise.
207 \membersection{wxTextCtrl::OnChar
}\label{wxtextctrlonchar
}
209 \func{void
}{OnChar
}{\param{wxKeyEvent\&
}{event
}}
211 Default handler for character input.
215 It is possible to intercept character
216 input by overriding this member. Call this function
217 to let the default behaviour take place; not calling
218 it results in the character being ignored. You can
219 replace the
{\it keyCode
} member of
{\it event
} to
220 translate keystrokes.
222 Note that Windows and Motif have different ways
223 of implementing the default behaviour. In Windows,
224 calling wxTextCtrl::OnChar immediately
225 processes the character. In Motif,
226 calling this function simply sets a flag
227 to let default processing happen. This might affect
228 the way in which you write your OnChar function
229 on different platforms.
233 \helpref{wxKeyEvent
}{wxkeyevent
}
235 \membersection{wxTextCtrl::OnDropFiles
}\label{wxtextctrlondropfiles
}
237 \func{void
}{OnDropFiles
}{\param{wxDropFilesEvent\&
}{event
}}
239 This event handler function implements default drag and drop behaviour, which
240 is to load the first dropped file into the control.
242 \wxheading{Parameters
}
244 \docparam{event
}{The drop files event.
}
248 \helpref{wxDropFilesEvent
}{wxdropfilesevent
}
250 \membersection{wxTextCtrl::Paste
}\label{wxtextctrlpaste
}
252 \func{virtual void
}{Paste
}{\void}
254 Pastes text from the clipboard to the text item.
256 \membersection{wxTextCtrl::PositionToXY
}\label{wxtextctrlpositiontoxy
}
258 \constfunc{long
}{PositionToXY
}{\param{const long
}{pos
},
\param{long *
}{x
},
\param{long *
}{y
}}
260 Converts given character and line position to a position.
262 \wxheading{Parameters
}
264 \docparam{pos
}{Position.
}
266 \docparam{x
}{Receives character position.
}
268 \docparam{y
}{Receives line position.
}
272 \helpref{wxTextCtrl::XYToPosition
}{wxtextctrlxytoposition
}
274 \membersection{wxTextCtrl::Remove
}\label{wxtextctrlremove
}
276 \func{virtual void
}{Remove
}{\param{const long
}{ from
},
\param{const long
}{ to
}}
278 Removes the text between the two positions.
280 \wxheading{Parameters
}
282 \docparam{from
}{The first position.
}
284 \docparam{to
}{The last position.
}
286 \membersection{wxTextCtrl::Replace
}\label{wxtextctrlreplace
}
288 \func{virtual void
}{Replace
}{\param{const long
}{ from
},
\param{const long
}{ to
},
\param{const wxString\&
}{value
}}
290 Replaces the text between two positions with the given text.
292 \wxheading{Parameters
}
294 \docparam{from
}{The first position.
}
296 \docparam{to
}{The last position.
}
298 \docparam{value
}{The value to replace the existing text with.
}
300 \membersection{wxTextCtrl::SaveFile
}\label{wxtextctrlsavefile
}
302 \func{bool
}{SaveFile
}{\param{const wxString\&
}{ filename
}}
304 Saves the contents of the control in a text file.
306 \wxheading{Parameters
}
308 \docparam{filename
}{The name of file in which to save the text.
}
310 \wxheading{Return value
}
312 TRUE if the operation was successful, FALSE otherwise.
314 \membersection{wxTextCtrl::SetEditable
}\label{wxtextctrlseteditable
}
316 \func{virtual void
}{SetEditable
}{\param{const bool
}{ editable
}}
318 Makes the text item editable or read-only.
320 \wxheading{Parameters
}
322 \docparam{editable
}{If TRUE, the control is editable. If FALSE, the control is read-only.
}
324 \membersection{wxTextCtrl::SetInsertionPoint
}\label{wxtextctrlsetinsertionpoint
}
326 \func{virtual void
}{SetInsertionPoint
}{\param{const long
}{ pos
}}
328 Sets the insertion point. Windows only. ??
330 \wxheading{Parameters
}
332 \docparam{pos
}{Position to set.
}
334 \membersection{wxTextCtrl::SetInsertionPointEnd
}\label{wxtextctrlsetinsertionpointend
}
336 \func{virtual void
}{SetInsertionPointEnd
}{\void}
338 Sets the insertion point at the end of the text control.
340 \membersection{wxTextCtrl::SetSelection
}\label{wxtextctrlsetselection
}
342 \func{virtual void
}{SetSelection
}{\param{const long
}{ from
},
\param{const long
}{ to
}}
344 Selects the text between the two positions.
346 \wxheading{Parameters
}
348 \docparam{from
}{The first position.
}
350 \docparam{to
}{The last position.
}
352 \membersection{wxTextCtrl::SetValue
}\label{wxtextctrlsetvalue
}
354 \func{virtual void
}{SetValue
}{\param{const wxString\&
}{ value
}}
358 \wxheading{Parameters
}
360 \docparam{value
}{The new value to set. It may contain newline characters if the text control is multi-line.
}
362 \membersection{wxTextCtrl::ShowPosition
}\label{wxtextctrlshowposition
}
364 \func{void
}{ShowPosition
}{\param{const long
}{ pos
}}
366 Makes the line containing the given position visible.
368 \wxheading{Parameters
}
370 \docparam{pos
}{The position that should be visible.
}
372 \membersection{wxTextCtrl::WriteText
}\label{wxtextctrlwritetext
}
374 \func{void
}{WriteText
}{\param{const wxString\&
}{ text
}}
376 Writes the text into the text control at the current position.
378 \wxheading{Parameters
}
380 \docparam{text
}{Text to write to the text control.
}
384 Newlines in the text string
385 are the only control characters allowed, and they will cause appropriate
386 line breaks. See
\helpref{wxTextCtrl::
\cinsert}{wxtextctrlinsert
} for more convenient ways of writing to the
389 \membersection{wxTextCtrl::XYToPosition
}\label{wxtextctrlxytoposition
}
391 \func{long
}{XYToPosition
}{\param{const long
}{ x
},
\param{const long
}{ y
}}
393 Converts the given character and line position to a position.
395 \wxheading{Parameters
}
397 \docparam{x
}{The character position.
}
399 \docparam{y
}{The line position.
}
401 \wxheading{Return value
}
405 \membersection{wxTextCtrl::operator
\cinsert}\label{wxtextctrlinsert
}
407 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{const wxString\&
}{s
}}
409 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{int
}{ i
}}
411 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{long
}{ i
}}
413 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{float
}{ f
}}
415 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{double
}{ d
}}
417 \func{wxTextCtrl\&
}{operator
\cinsert}{\param{char
}{ c
}}
419 Operator definitions for writing to a text control, for example:
422 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
424 (*wnd) << "Welcome to text control number " << 1 << ".\n";