]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/text.tex
Doc updates.
[wxWidgets.git] / docs / latex / wx / text.tex
CommitLineData
a660d684
KB
1\section{\class{wxTextCtrl}}\label{wxtextctrl}
2
3A text control allows text to be displayed and edited. It may be
71777e2c 4single line or multi-line.
a660d684
KB
5
6\wxheading{Derived from}
7
8streambuf\\
9\helpref{wxControl}{wxcontrol}\\
10\helpref{wxWindow}{wxwindow}\\
11\helpref{wxEvtHandler}{wxevthandler}\\
12\helpref{wxObject}{wxobject}
13
954b8ae6
JS
14\wxheading{Include files}
15
16<wx/textctrl.h>
17
a660d684
KB
18\wxheading{Window styles}
19
20\twocolwidtha{5cm}
21\begin{twocollist}\itemsep=0pt
22\twocolitem{\windowstyle{wxTE\_PROCESS\_ENTER}}{The callback function will
23receive the message wxEVENT\_TYPE\_TEXT\_ENTER\_COMMAND. Note
24that this will break tab traversal for this panel item under
25Windows.}
26\twocolitem{\windowstyle{wxTE\_MULTILINE}}{The text control allows multiple lines.}
27\twocolitem{\windowstyle{wxTE\_PASSWORD}}{The text will be echoed as asterisks.}
28\twocolitem{\windowstyle{wxTE\_READONLY}}{The text will not be user-editable.}
71777e2c 29\twocolitem{\windowstyle{wxHSCROLL}}{A horizontal scrollbar will be created.}
a660d684
KB
30\end{twocollist}
31
86975656 32See also \helpref{window styles overview}{windowstyles} and
f66205b6 33\helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlconstr}.
a660d684
KB
34
35\wxheading{Remarks}
36
71777e2c 37This class multiply-inherits from {\bf streambuf} where compilers allow, allowing code such as the following:
a660d684
KB
38
39{\small%
40\begin{verbatim}
41 wxTextCtrl *control = new wxTextCtrl(...);
42
43 ostream stream(control)
44
45 stream << 123.456 << " some text\n";
46 stream.flush();
47\end{verbatim}
48}%
49
50If your compiler does not support derivation from {\bf streambuf} and gives a compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
51wxTextCtrl header file.
52
5de76427
JS
53\wxheading{Event handling}
54
e702ff0f
JS
55The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
56wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
57automatically, when the control has the focus.
58
5de76427
JS
59To process input from a text control, use these event handler macros to direct input to member
60functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
61
62\twocolwidtha{7cm}%
63\begin{twocollist}\itemsep=0pt
64\twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
65generated when the text changes.}
66\twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
67generated when enter is pressed in a single-line text control.}
68\end{twocollist}%
69
a660d684
KB
70%\wxheading{See also}
71%
72%\helpref{wxRichTextCtrl}{wxrichtextctrl}
73%
74\latexignore{\rtfignore{\wxheading{Members}}}
75
76\membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlconstr}
77
78\func{}{wxTextCtrl}{\void}
79
80Default constructor.
81
eaaa6a06 82\func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
36b3b54a 83\param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 84\param{long}{ style = 0}, \param{const wxValidator\& }{validator}, \param{const wxString\& }{name = ``text"}}
a660d684
KB
85
86Constructor, creating and showing a text control.
87
88\wxheading{Parameters}
89
90\docparam{parent}{Parent window. Should not be NULL.}
91
92\docparam{id}{Control identifier. A value of -1 denotes a default value.}
93
94\docparam{value}{Default text value.}
95
96\docparam{pos}{Text control position.}
97
98\docparam{size}{Text control size.}
99
100\docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
101
102\docparam{validator}{Window validator.}
103
104\docparam{name}{Window name.}
105
106\wxheading{Remarks}
107
86975656
RD
108The horizontal scrollbar ({\bf wxTE\_HSCROLL} style flag) will only be created for multi-line text controls.
109Without a horizontal scrollbar, text lines that don't fit in the control's
71777e2c
HH
110size will be wrapped (but no newline character is inserted). Single line
111controls don't have a horizontal scrollbar, the text is automatically scrolled
86975656 112so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
71777e2c
HH
113visible.
114
a660d684
KB
115Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
116as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
117apply.
118
119\wxheading{See also}
120
121\helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
122
123\membersection{wxTextCtrl::\destruct{wxTextCtrl}}
124
125\func{}{\destruct{wxTextCtrl}}{\void}
126
127Destructor, destroying the text control.
128
ca8b28f2
JS
129\membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
130
131\func{void}{AppendText}{\param{const wxString\& }{ text}}
132
133Appends the text to the end of the text control.
134
135\wxheading{Parameters}
136
137\docparam{text}{Text to write to the text control.}
138
139\wxheading{Remarks}
140
141After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
142the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
143
144\wxheading{See also}
145
146\helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
147
148\membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
149
150\func{virtual bool}{CanCopy}{\void}
151
152Returns TRUE if the selection can be copied to the clipboard.
153
154\membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
155
156\func{virtual bool}{CanCut}{\void}
157
158Returns TRUE if the selection can be cut to the clipboard.
159
160\membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
161
162\func{virtual bool}{CanPaste}{\void}
163
164Returns TRUE if the contents of the clipboard can be pasted into the
165text control. On some platforms (Motif, GTK) this is an approximation
166and returns TRUE if the control is editable, FALSE otherwise.
167
168\membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
169
170\func{virtual bool}{CanRedo}{\void}
171
172Returns TRUE if there is a redo facility available and the last operation
173can be redone.
174
175\membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
176
177\func{virtual bool}{CanUndo}{\void}
178
179Returns TRUE if there is an undo facility available and the last operation
180can be undone.
181
a660d684
KB
182\membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
183
184\func{virtual void}{Clear}{\void}
185
186Clears the text in the control.
187
188\membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
189
190\func{virtual void}{Copy}{\void}
191
192Copies the selected text to the clipboard under Motif and MS Windows.
193
194\membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
195
eaaa6a06 196\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
36b3b54a 197\param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 198\param{long}{ style = 0}, \param{const wxValidator\& }{validator}, \param{const wxString\& }{name = ``text"}}
a660d684
KB
199
200Creates the text control for two-step construction. Derived classes
201should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlconstr}\rtfsp
202for further details.
203
204\membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
205
206\func{virtual void}{Cut}{\void}
207
208Copies the selected text to the clipboard and removes the selection.
209
210\membersection{wxTextCtrl::DiscardEdits}
211
212\func{void}{DiscardEdits}{\void}
213
214Resets the internal `modified' flag as if the current edits had been saved.
215
216\membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
217
218\constfunc{virtual long}{GetInsertionPoint}{\void}
219
71777e2c
HH
220Returns the insertion point. This is defined as the zero based index of the
221character position to the right of the insertion point. For example, if
222the insertion point is at the end of the text control, it is equal to
86975656
RD
223both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
224\helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
71777e2c
HH
225
226The following code snippet safely returns the character at the insertion
227point or the zero character if the point is at the end of the control.
228
229{\small%
230\begin{verbatim}
231 char GetCurrentChar(wxTextCtrl *tc) {
232 if (tc->GetInsertionPoint() == tc->GetLastPosition())
233 return '\0';
234 return tc->GetValue[tc->GetInsertionPoint()];
86975656 235 }
71777e2c
HH
236\end{verbatim}
237}%
a660d684
KB
238
239\membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
240
241\constfunc{virtual long}{GetLastPosition}{\void}
242
86975656 243Returns the zero based index of the last position in the text control,
71777e2c 244which is equal to the number of characters in the control.
a660d684
KB
245
246\membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
247
248\constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
249
86975656 250Gets the length of the specified line, not including any trailing newline
71777e2c 251character(s).
a660d684
KB
252
253\wxheading{Parameters}
254
255\docparam{lineNo}{Line number (starting from zero).}
256
257\wxheading{Return value}
258
259The length of the line, or -1 if {\it lineNo} was invalid.
260
261\membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
262
eaaa6a06 263\constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
a660d684 264
71777e2c
HH
265Returns the contents of a given line in the text control, not including
266any trailing newline character(s).
a660d684
KB
267
268\wxheading{Parameters}
269
270\docparam{lineNo}{The line number, starting from zero.}
271
272\wxheading{Return value}
273
274The contents of the line.
275
276\membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
277
278\constfunc{int}{GetNumberOfLines}{\void}
279
280Returns the number of lines in the text control buffer.
281
71777e2c
HH
282\wxheading{Remarks}
283
284Note that even empty text controls have one line (where the insertion point
285is), so GetNumberOfLines() never returns 0.
286
287For gtk\_text (multi-line) controls, the number of lines is
288calculated by actually counting newline characters in the buffer. You
289may wish to avoid using functions that work with line numbers if you are
290working with controls that contain large amounts of text.
291
ca8b28f2
JS
292\membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
293
294\func{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
295
296Gets the current selection span. If the returned values are equal, there was
297no selection.
298
299\wxheading{Parameters}
300
301\docparam{from}{The returned first position.}
302
303\docparam{to}{The returned last position.}
304
86975656
RD
305\pythonnote{The wxPython version of this method returns a tuple
306consisting of the from and to values.}
307
a660d684
KB
308\membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
309
310\constfunc{wxString}{GetValue}{\void}
311
312Gets the contents of the control.
313
314\membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
315
316\constfunc{bool}{IsModified}{\void}
317
318Returns TRUE if the text has been modified.
319
320\membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
321
322\func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
323
324Loads and displays the named file, if it exists.
325
326\wxheading{Parameters}
327
328\docparam{filename}{The filename of the file to load.}
329
330\wxheading{Return value}
331
332TRUE if successful, FALSE otherwise.
333
334\membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
335
336\func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
337
338Default handler for character input.
339
340\wxheading{Remarks}
341
342It is possible to intercept character
343input by overriding this member. Call this function
344to let the default behaviour take place; not calling
345it results in the character being ignored. You can
346replace the {\it keyCode} member of {\it event} to
347translate keystrokes.
348
349Note that Windows and Motif have different ways
350of implementing the default behaviour. In Windows,
351calling wxTextCtrl::OnChar immediately
352processes the character. In Motif,
353calling this function simply sets a flag
354to let default processing happen. This might affect
355the way in which you write your OnChar function
356on different platforms.
357
358\wxheading{See also}
359
360\helpref{wxKeyEvent}{wxkeyevent}
361
362\membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
363
364\func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
365
366This event handler function implements default drag and drop behaviour, which
367is to load the first dropped file into the control.
368
369\wxheading{Parameters}
370
371\docparam{event}{The drop files event.}
372
71777e2c
HH
373\wxheading{Remarks}
374
375This is not yet implemented for the GTK.
376
a660d684
KB
377\wxheading{See also}
378
379\helpref{wxDropFilesEvent}{wxdropfilesevent}
380
381\membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
382
383\func{virtual void}{Paste}{\void}
384
385Pastes text from the clipboard to the text item.
386
387\membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
388
eaaa6a06 389\constfunc{long}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
a660d684 390
71777e2c 391Converts given position to a zero-based column, line number pair.
a660d684
KB
392
393\wxheading{Parameters}
394
395\docparam{pos}{Position.}
396
71777e2c 397\docparam{x}{Receives zero based column number.}
a660d684 398
71777e2c
HH
399\docparam{y}{Receives zero based line number.}
400
401\wxheading{Return value}
402
403Non-zero on success, zero on failure (most likely due to a too large position
404parameter).
a660d684
KB
405
406\wxheading{See also}
407
408\helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
409
71777e2c
HH
410\pythonnote{In Python, PositionToXY() returns a tuple containing the x and
411y values, so (x,y) = PositionToXY() is equivalent to the call described
412above.}
413
ca8b28f2
JS
414\membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
415
416\func{virtual void}{Redo}{\void}
417
418If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
419if there is no redo facility.
420
a660d684
KB
421\membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
422
eaaa6a06 423\func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
a660d684 424
71777e2c
HH
425Removes the text starting at the first given position up to (but not including)
426the character at the last position.
a660d684
KB
427
428\wxheading{Parameters}
429
430\docparam{from}{The first position.}
431
432\docparam{to}{The last position.}
433
434\membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
435
eaaa6a06 436\func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
a660d684 437
86975656 438Replaces the text starting at the first position up to (but not including)
71777e2c 439the character at the last position with the given text.
a660d684
KB
440
441\wxheading{Parameters}
442
443\docparam{from}{The first position.}
444
445\docparam{to}{The last position.}
446
447\docparam{value}{The value to replace the existing text with.}
448
449\membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
450
451\func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
452
453Saves the contents of the control in a text file.
454
455\wxheading{Parameters}
456
71777e2c 457\docparam{filename}{The name of the file in which to save the text.}
a660d684
KB
458
459\wxheading{Return value}
460
461TRUE if the operation was successful, FALSE otherwise.
462
463\membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
464
465\func{virtual void}{SetEditable}{\param{const bool}{ editable}}
466
71777e2c
HH
467Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY}
468flag.
a660d684
KB
469
470\wxheading{Parameters}
471
472\docparam{editable}{If TRUE, the control is editable. If FALSE, the control is read-only.}
473
474\membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
475
eaaa6a06 476\func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
a660d684 477
71777e2c 478Sets the insertion point at the given position.
a660d684
KB
479
480\wxheading{Parameters}
481
482\docparam{pos}{Position to set.}
483
484\membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
485
486\func{virtual void}{SetInsertionPointEnd}{\void}
487
71777e2c
HH
488Sets the insertion point at the end of the text control. This is equivalent
489to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
a660d684
KB
490
491\membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
492
eaaa6a06 493\func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
a660d684 494
71777e2c 495Selects the text starting at the first position up to (but not including) the character at the last position.
a660d684
KB
496
497\wxheading{Parameters}
498
499\docparam{from}{The first position.}
500
501\docparam{to}{The last position.}
502
503\membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
504
505\func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
506
507Sets the text value.
508
509\wxheading{Parameters}
510
511\docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
512
513\membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
514
eaaa6a06 515\func{void}{ShowPosition}{\param{long}{ pos}}
a660d684
KB
516
517Makes the line containing the given position visible.
518
519\wxheading{Parameters}
520
521\docparam{pos}{The position that should be visible.}
522
ca8b28f2
JS
523\membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
524
525\func{virtual void}{Undo}{\void}
526
527If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
528if there is no undo facility.
529
a660d684
KB
530\membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
531
532\func{void}{WriteText}{\param{const wxString\& }{ text}}
533
86975656 534Writes the text into the text control at the current insertion position.
a660d684
KB
535
536\wxheading{Parameters}
537
538\docparam{text}{Text to write to the text control.}
539
540\wxheading{Remarks}
541
542Newlines in the text string
543are the only control characters allowed, and they will cause appropriate
abaa2936 544line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
71777e2c
HH
545
546After 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.
a660d684
KB
547
548\membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
549
eaaa6a06 550\func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
a660d684 551
71777e2c 552Converts the given zero based column and line number to a position.
a660d684
KB
553
554\wxheading{Parameters}
555
71777e2c 556\docparam{x}{The column number.}
a660d684 557
71777e2c 558\docparam{y}{The line number.}
a660d684
KB
559
560\wxheading{Return value}
561
562The position value.
563
564\membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
565
566\func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
567
568\func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
569
570\func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
571
572\func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
573
574\func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
575
576\func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
577
abaa2936 578Operator definitions for appending to a text control, for example:
a660d684
KB
579
580\begin{verbatim}
581 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
582
583 (*wnd) << "Welcome to text control number " << 1 << ".\n";
584\end{verbatim}
585