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