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