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