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