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