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