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