]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/text.tex
typo (patch 1528925)
[wxWidgets.git] / docs / latex / wx / text.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 \section{\class{wxTextCtrl}}\label{wxtextctrl}
4
5 A text control allows text to be displayed and edited. It may be
6 single line or multi-line.
7
8 \wxheading{Derived from}
9
10 streambuf\\
11 \helpref{wxControl}{wxcontrol}\\
12 \helpref{wxWindow}{wxwindow}\\
13 \helpref{wxEvtHandler}{wxevthandler}\\
14 \helpref{wxObject}{wxobject}
15
16 \wxheading{Include files}
17
18 <wx/textctrl.h>
19
20 \wxheading{Window styles}
21
22 \twocolwidtha{5cm}
23 \begin{twocollist}\itemsep=0pt
24 \twocolitem{\windowstyle{wxTE\_PROCESS\_ENTER}}{The control will generate
25 the event wxEVT\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
26 is either processed internally by the control or used for navigation between
27 dialog controls).}
28 \twocolitem{\windowstyle{wxTE\_PROCESS\_TAB}}{The control will receive
29 wxEVT\_CHAR events for TAB pressed - normally, TAB is used for passing to the
30 next control in a dialog instead. For the control created with this style,
31 you can still use Ctrl-Enter to pass to the next control from the keyboard.}
32 \twocolitem{\windowstyle{wxTE\_MULTILINE}}{The text control allows multiple lines.}
33 \twocolitem{\windowstyle{wxTE\_PASSWORD}}{The text will be echoed as asterisks.}
34 \twocolitem{\windowstyle{wxTE\_READONLY}}{The text will not be user-editable.}
35 \twocolitem{\windowstyle{wxTE\_RICH}}{Use rich text control under Win32, this
36 allows to have more than 64KB of text in the control even under Win9x. This
37 style is ignored under other platforms.}
38 \twocolitem{\windowstyle{wxTE\_RICH2}}{Use rich text control version 2.0 or 3.0
39 under Win32, this style is ignored under other platforms}
40 \twocolitem{\windowstyle{wxTE\_AUTO\_URL}}{Highlight the URLs and generate the
41 wxTextUrlEvents when mouse events occur over them. This style is only supported
42 for wxTE\_RICH Win32 and multi-line wxGTK2 text controls.}
43 \twocolitem{\windowstyle{wxTE\_NOHIDESEL}}{By default, the Windows text control
44 doesn't show the selection when it doesn't have focus - use this style to force
45 it to always show it. It doesn't do anything under other platforms.}
46 \twocolitem{\windowstyle{wxHSCROLL}}{A horizontal scrollbar will be created and
47 used, so that text won't be wrapped. No effect under wxGTK1.}
48 \twocolitem{\windowstyle{wxTE\_LEFT}}{The text in the control will be left-justified (default).}
49 \twocolitem{\windowstyle{wxTE\_CENTRE}}{The text in the control will be centered (currently wxMSW and wxGTK2 only).}
50 \twocolitem{\windowstyle{wxTE\_RIGHT}}{The text in the control will be right-justified (currently wxMSW and wxGTK2 only).}
51 \twocolitem{\windowstyle{wxTE\_DONTWRAP}}{Same as {\tt wxHSCROLL} style: don't wrap at all, show horizontal scrollbar instead.}
52 \twocolitem{\windowstyle{wxTE\_CHARWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv and wxGTK2 only).}
53 \twocolitem{\windowstyle{wxTE\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries (wxUniv and wxGTK2 only).}
54 \twocolitem{\windowstyle{wxTE\_BESTWRAP}}{Wrap the lines at word boundaries or at any other character if there are words longer than the window width (this is the default).}
55 \twocolitem{\windowstyle{wxTE\_CAPITALIZE}}{On PocketPC and Smartphone, causes the first letter to be capitalized.}
56 \twocolitem{\windowstyle{wxTE\_FILENAME}}{Should be used for the text controls
57 containing file names. This currently just enables file names auto-completion
58 (and only under Windows for now) but can have other effects in the future.}
59 \end{twocollist}
60
61 See also \helpref{window styles overview}{windowstyles} and \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}.
62
63 \wxheading{wxTextCtrl text format}
64
65 The multiline text controls always store the text as a sequence of lines
66 separated by {\tt $\backslash$n} characters, i.e. in the Unix text format even
67 on non-Unix platforms. This allows the user code to ignore the differences
68 between the platforms but at a price: the indices in the control such as those
69 returned by \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} or
70 \helpref{GetSelection}{wxtextctrlgetselection} can {\bf not} be used as
71 indices into the string returned by \helpref{GetValue}{wxtextctrlgetvalue} as
72 they're going to be slightly off for platforms using
73 {\tt $\backslash$r$\backslash$n} as separator (as Windows does), for example.
74
75 Instead, if you need to obtain a substring between the $2$ indices obtained
76 from the control with the help of the functions mentioned above, you should
77 use \helpref{GetRange}{wxtextctrlgetrange}. And the indices themselves can
78 only be passed to other methods, for example
79 \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint} or
80 \helpref{SetSelection}{wxtextctrlsetselection}.
81
82 To summarize: never use the indices returned by (multiline) wxTextCtrl as
83 indices into the string it contains, but only as arguments to be passed back
84 to the other wxTextCtrl methods.
85
86 \wxheading{wxTextCtrl styles}
87
88 Multi-line text controls support the styles, i.e. provide a possibility to set
89 colours and font for individual characters in it (note that under Windows {\tt
90 wxTE\_RICH} style is required for style support). To use the styles you can
91 either call \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} before
92 inserting the text or call \helpref{SetStyle}{wxtextctrlsetstyle} later to
93 change the style of the text already in the control (the first solution is
94 much more efficient).
95
96 In either case, if the style doesn't specify some of the attributes (for
97 example you only want to set the text colour but without changing the font nor
98 the text background), the values of the default style will be used for them.
99 If there is no default style, the attributes of the text control itself are
100 used.
101
102 So the following code correctly describes what it does: the second call
103 to \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} doesn't change the
104 text foreground colour (which stays red) while the last one doesn't change the
105 background colour (which stays grey):
106
107 {\small%
108 \begin{verbatim}
109 text->SetDefaultStyle(wxTextAttr(*wxRED));
110 text->AppendText("Red text\n");
111 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
112 text->AppendText("Red on grey text\n");
113 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
114 text->AppendText("Blue on grey text\n");
115 \end{verbatim}
116 }%
117
118 \wxheading{wxTextCtrl and C++ streams}
119
120 This class multiply-inherits from {\bf streambuf} where compilers allow,
121 allowing code such as the following:
122
123 {\small%
124 \begin{verbatim}
125 wxTextCtrl *control = new wxTextCtrl(...);
126
127 ostream stream(control)
128
129 stream << 123.456 << " some text\n";
130 stream.flush();
131 \end{verbatim}
132 }%
133
134 If your compiler does not support derivation from {\bf streambuf} and gives a
135 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
136 wxTextCtrl header file.
137
138 Note that independently of this setting you can always use wxTextCtrl itself
139 in a stream-like manner:
140
141 {\small%
142 \begin{verbatim}
143 wxTextCtrl *control = new wxTextCtrl(...);
144
145 *control << 123.456 << " some text\n";
146 \end{verbatim}
147 }%
148
149 always works. However the possibility to create an ostream associated with
150 wxTextCtrl may be useful if you need to redirect the output of a function
151 taking an ostream as parameter to a text control.
152
153 Another commonly requested need is to redirect {\bf std::cout} to the text
154 control. This could be done in the following way:
155
156 {\small%
157 \begin{verbatim}
158 #include <iostream>
159
160 wxTextCtrl *control = new wxTextCtrl(...);
161
162 std::streambuf *sbOld = std::cout.rdbuf();
163 std::cout.rdbuf(*control);
164
165 // use cout as usual, the output appears in the text control
166 ...
167
168 std::cout.rdbuf(sbOld);
169 \end{verbatim}
170 }%
171
172 But wxWidgets provides a convenient class to make it even simpler so instead
173 you may just do
174
175 {\small%
176 \begin{verbatim}
177 #include <iostream>
178
179 wxTextCtrl *control = new wxTextCtrl(...);
180
181 wxStreamToTextRedirector redirect(control);
182
183 // all output to cout goes into the text control until the exit from current
184 // scope
185 \end{verbatim}
186 }%
187
188 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
189 details.
190
191 \wxheading{Constants}
192
193 The values below are the possible return codes of the
194 \helpref{HitTest}{wxtextctrlhittest} method:
195
196 {\small
197 \begin{verbatim}
198 // the point asked is ...
199 enum wxTextCtrlHitTestResult
200 {
201 wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented
202 wxTE_HT_BEFORE, // either to the left or upper
203 wxTE_HT_ON_TEXT, // directly on
204 wxTE_HT_BELOW, // below [the last line]
205 wxTE_HT_BEYOND // after [the end of line]
206 };
207 // ... the character returned
208 \end{verbatim}
209 }
210
211
212 \wxheading{Event handling}
213
214 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
215 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
216 automatically, when the control has the focus.
217
218 To process input from a text control, use these event handler macros to direct input to member
219 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
220
221 \twocolwidtha{7cm}%
222 \begin{twocollist}\itemsep=0pt
223 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
224 generated when the text changes. Notice that this event will always be sent
225 when the text controls contents changes - whether this is due to user input or
226 comes from the program itself (for example, if SetValue() is called)}
227 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
228 generated when enter is pressed in a text control (which must have
229 wxTE\_PROCESS\_ENTER style for this event to be generated).}
230 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occurred over an URL
231 in the text control (wxMSW and wxGTK2 only)}
232 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
233 into the control than the limit set by
234 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
235 \end{twocollist}%
236
237 \latexignore{\rtfignore{\wxheading{Members}}}
238
239
240 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlctor}
241
242 \func{}{wxTextCtrl}{\void}
243
244 Default constructor.
245
246 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
247 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
248 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
249
250 Constructor, creating and showing a text control.
251
252 \wxheading{Parameters}
253
254 \docparam{parent}{Parent window. Should not be NULL.}
255
256 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
257
258 \docparam{value}{Default text value.}
259
260 \docparam{pos}{Text control position.}
261
262 \docparam{size}{Text control size.}
263
264 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
265
266 \docparam{validator}{Window validator.}
267
268 \docparam{name}{Window name.}
269
270 \wxheading{Remarks}
271
272 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
273 for multi-line text controls.
274 Without a horizontal scrollbar, text lines that don't fit in the control's
275 size will be wrapped (but no newline character is inserted). Single line
276 controls don't have a horizontal scrollbar, the text is automatically scrolled
277 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
278 visible.
279
280 % VZ: this is no longer true
281 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
282 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
283 %apply.
284
285 \wxheading{See also}
286
287 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
288
289
290 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}\label{wxtextctrldtor}
291
292 \func{}{\destruct{wxTextCtrl}}{\void}
293
294 Destructor, destroying the text control.
295
296
297 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
298
299 \func{void}{AppendText}{\param{const wxString\& }{ text}}
300
301 Appends the text to the end of the text control.
302
303 \wxheading{Parameters}
304
305 \docparam{text}{Text to write to the text control.}
306
307 \wxheading{Remarks}
308
309 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
310 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
311
312 \wxheading{See also}
313
314 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
315
316
317 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
318
319 \func{virtual bool}{CanCopy}{\void}
320
321 Returns {\tt true} if the selection can be copied to the clipboard.
322
323
324 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
325
326 \func{virtual bool}{CanCut}{\void}
327
328 Returns {\tt true} if the selection can be cut to the clipboard.
329
330
331 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
332
333 \func{virtual bool}{CanPaste}{\void}
334
335 Returns {\tt true} if the contents of the clipboard can be pasted into the
336 text control. On some platforms (Motif, GTK) this is an approximation
337 and returns {\tt true} if the control is editable, {\tt false} otherwise.
338
339
340 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
341
342 \func{virtual bool}{CanRedo}{\void}
343
344 Returns {\tt true} if there is a redo facility available and the last operation
345 can be redone.
346
347
348 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
349
350 \func{virtual bool}{CanUndo}{\void}
351
352 Returns {\tt true} if there is an undo facility available and the last operation
353 can be undone.
354
355
356 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
357
358 \func{virtual void}{Clear}{\void}
359
360 Clears the text in the control.
361
362 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
363 event.
364
365
366 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
367
368 \func{virtual void}{Copy}{\void}
369
370 Copies the selected text to the clipboard under Motif and MS Windows.
371
372
373 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
374
375 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
376 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
377 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
378
379 Creates the text control for two-step construction. Derived classes
380 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}\rtfsp
381 for further details.
382
383
384 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
385
386 \func{virtual void}{Cut}{\void}
387
388 Copies the selected text to the clipboard and removes the selection.
389
390
391 \membersection{wxTextCtrl::DiscardEdits}\label{wxtextctrldiscardedits}
392
393 \func{void}{DiscardEdits}{\void}
394
395 Resets the internal `modified' flag as if the current edits had been saved.
396
397
398 \membersection{wxTextCtrl::EmulateKeyPress}\label{wxtextctrlemulatekeypress}
399
400 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
401
402 This functions inserts into the control the character which would have been
403 inserted if the given key event had occurred in the text control. The
404 {\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
405 handler previously by wxWidgets.
406
407 Please note that this function doesn't currently work correctly for all keys
408 under any platform but MSW.
409
410 \wxheading{Return value}
411
412 {\tt true} if the event resulted in a change to the control, {\tt false}
413 otherwise.
414
415
416 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
417
418 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
419
420 Returns the style currently used for the new text.
421
422 \wxheading{See also}
423
424 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
425
426
427 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
428
429 \constfunc{virtual long}{GetInsertionPoint}{\void}
430
431 Returns the insertion point. This is defined as the zero based index of the
432 character position to the right of the insertion point. For example, if
433 the insertion point is at the end of the text control, it is equal to
434 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
435 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
436
437 The following code snippet safely returns the character at the insertion
438 point or the zero character if the point is at the end of the control.
439
440 {\small%
441 \begin{verbatim}
442 char GetCurrentChar(wxTextCtrl *tc) {
443 if (tc->GetInsertionPoint() == tc->GetLastPosition())
444 return '\0';
445 return tc->GetValue[tc->GetInsertionPoint()];
446 }
447 \end{verbatim}
448 }%
449
450
451 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
452
453 \constfunc{virtual wxTextPos}{GetLastPosition}{\void}
454
455 Returns the zero based index of the last position in the text control,
456 which is equal to the number of characters in the control.
457
458
459 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
460
461 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
462
463 Gets the length of the specified line, not including any trailing newline
464 character(s).
465
466 \wxheading{Parameters}
467
468 \docparam{lineNo}{Line number (starting from zero).}
469
470 \wxheading{Return value}
471
472 The length of the line, or -1 if {\it lineNo} was invalid.
473
474
475 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
476
477 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
478
479 Returns the contents of a given line in the text control, not including
480 any trailing newline character(s).
481
482 \wxheading{Parameters}
483
484 \docparam{lineNo}{The line number, starting from zero.}
485
486 \wxheading{Return value}
487
488 The contents of the line.
489
490
491 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
492
493 \constfunc{int}{GetNumberOfLines}{\void}
494
495 Returns the number of lines in the text control buffer.
496
497 \wxheading{Remarks}
498
499 Note that even empty text controls have one line (where the insertion point
500 is), so GetNumberOfLines() never returns $0$.
501
502 For wxGTK using GTK+ 1.2.x and earlier, the number of lines in a multi-line
503 text control is calculated by actually counting newline characters in the
504 buffer, i.e. this function returns the number of logical lines and doesn't
505 depend on whether any of them are wrapped. For all the other platforms, the
506 number of physical lines in the control is returned.
507
508 Also note that you may wish to avoid using functions that work with line
509 numbers if you are working with controls that contain large amounts of text as
510 this function has $O(N)$ complexity for $N$ being the number of lines.
511
512
513 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
514
515 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
516
517 Returns the string containing the text starting in the positions {\it from} and
518 up to {\it to} in the control. The positions must have been returned by another
519 wxTextCtrl method.
520
521 Please note that the positions in a multiline wxTextCtrl do {\bf not}
522 correspond to the indices in the string returned by
523 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
524 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
525 obtain the correct results instead of extracting parts of the entire value. It
526 may also be more efficient, especially if the control contains a lot of data.
527
528
529 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
530
531 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
532
533 Gets the current selection span. If the returned values are equal, there was
534 no selection.
535
536 Please note that the indices returned may be used with the other wxTextctrl
537 methods but don't necessarily represent the correct indices into the string
538 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
539 under Windows (at least,) you should use
540 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
541 text.
542
543 \wxheading{Parameters}
544
545 \docparam{from}{The returned first position.}
546
547 \docparam{to}{The returned last position.}
548
549 \pythonnote{The wxPython version of this method returns a tuple
550 consisting of the from and to values.}
551
552 \perlnote{In wxPerl this method takes no parameter and returns a
553 2-element list {\tt ( from, to )}.}
554
555
556 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
557
558 \func{virtual wxString}{GetStringSelection}{\void}
559
560 Gets the text currently selected in the control. If there is no selection, the
561 returned string is empty.
562
563
564 \membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
565
566 \func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
567
568 Returns the style at this position in the text control. Not all platforms
569 support this function.
570
571 \wxheading{Return value}
572
573 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
574 the styles are not supported under this platform.
575
576 \wxheading{See also}
577
578 \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
579
580
581 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
582
583 \constfunc{wxString}{GetValue}{\void}
584
585 Gets the contents of the control. Notice that for a multiline text control,
586 the lines will be separated by (Unix-style) $\backslash$n characters, even
587 under Windows where they are separated by a $\backslash$r$\backslash$n
588 sequence in the native control.
589
590
591 \membersection{wxTextCtrl::HitTest}\label{wxtextctrlhittest}
592
593 \constfunc{wxTextCtrlHitTestResult}{HitTest}{\param{const wxPoint\& }{pt}, \param{wxTextCoord }{*col}, \param{wxTextCoord }{*row}}
594
595 This function finds the character at the specified position expressed in
596 pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
597 of the character closest to this position are returned in the \arg{col} and
598 \arg{row} parameters (unless the pointers are {\tt NULL} which is allowed).
599
600 Please note that this function is currently only implemented in wxUniv,
601 wxMSW and wxGTK2 ports.
602
603 \wxheading{See also}
604
605 \helpref{PositionToXY}{wxtextctrlpositiontoxy}, \helpref{XYToPosition}{wxtextctrlxytoposition}
606
607 \perlnote{In wxPerl this function takes only the position argument and
608 returns a 3-element list \texttt{(result, col, row)}}.
609
610 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
611
612 \constfunc{bool}{IsEditable}{\void}
613
614 Returns {\tt true} if the controls contents may be edited by user (note that it
615 always can be changed by the program), i.e. if the control hasn't been put in
616 read-only mode by a previous call to
617 \helpref{SetEditable}{wxtextctrlseteditable}.
618
619
620 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
621
622 \constfunc{bool}{IsModified}{\void}
623
624 Returns {\tt true} if the text has been modified by user. Note that calling
625 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
626
627 \wxheading{See also}
628
629 \helpref{MarkDirty}{wxtextctrlmarkdirty}
630
631
632 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
633
634 \constfunc{bool}{IsMultiLine}{\void}
635
636 Returns {\tt true} if this is a multi line edit control and {\tt false}
637 otherwise.
638
639 \wxheading{See also}
640
641 \helpref{IsSingleLine}{wxtextctrlissingleline}
642
643
644 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
645
646 \constfunc{bool}{IsSingleLine}{\void}
647
648 Returns {\tt true} if this is a single line edit control and {\tt false}
649 otherwise.
650
651 \wxheading{See also}
652
653 \helpref{IsMultiLine}{wxtextctrlissingleline}
654
655
656 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
657
658 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
659
660 Loads and displays the named file, if it exists.
661
662 \wxheading{Parameters}
663
664 \docparam{filename}{The filename of the file to load.}
665
666 \wxheading{Return value}
667
668 {\tt true} if successful, {\tt false} otherwise.
669
670 % VZ: commenting this out as: (a) the docs are wrong (you can't replace
671 % anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
672 %% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
673 %%
674 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
675 %%
676 %% Default handler for character input.
677 %%
678 %% \wxheading{Remarks}
679 %%
680 %% It is possible to intercept character
681 %% input by overriding this member. Call this function
682 %% to let the default behaviour take place; not calling
683 %% it results in the character being ignored. You can
684 %% replace the {\it keyCode} member of {\it event} to
685 %% translate keystrokes.
686 %%
687 %% Note that Windows and Motif have different ways
688 %% of implementing the default behaviour. In Windows,
689 %% calling wxTextCtrl::OnChar immediately
690 %% processes the character. In Motif,
691 %% calling this function simply sets a flag
692 %% to let default processing happen. This might affect
693 %% the way in which you write your OnChar function
694 %% on different platforms.
695 %%
696 %% \wxheading{See also}
697 %%
698 %% \helpref{wxKeyEvent}{wxkeyevent}
699
700
701 \membersection{wxTextCtrl::MarkDirty}\label{wxtextctrlmarkdirty}
702
703 \func{void}{MarkDirty}{\void}
704
705 Mark text as modified (dirty).
706
707 \wxheading{See also}
708
709 \helpref{IsModified}{wxtextctrlismodified}
710
711
712 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
713
714 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
715
716 This event handler function implements default drag and drop behaviour, which
717 is to load the first dropped file into the control.
718
719 \wxheading{Parameters}
720
721 \docparam{event}{The drop files event.}
722
723 \wxheading{Remarks}
724
725 This is not implemented on non-Windows platforms.
726
727 \wxheading{See also}
728
729 \helpref{wxDropFilesEvent}{wxdropfilesevent}
730
731
732 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
733
734 \func{virtual void}{Paste}{\void}
735
736 Pastes text from the clipboard to the text item.
737
738
739 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
740
741 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
742
743 Converts given position to a zero-based column, line number pair.
744
745 \wxheading{Parameters}
746
747 \docparam{pos}{Position.}
748
749 \docparam{x}{Receives zero based column number.}
750
751 \docparam{y}{Receives zero based line number.}
752
753 \wxheading{Return value}
754
755 {\tt true} on success, {\tt false} on failure (most likely due to a too large position
756 parameter).
757
758 \wxheading{See also}
759
760 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
761
762 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
763 y values, so (x,y) = PositionToXY() is equivalent to the call described
764 above.}
765
766 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
767 returns a 2-element list {\tt ( x, y )}.}
768
769
770 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
771
772 \func{virtual void}{Redo}{\void}
773
774 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
775 if there is no redo facility.
776
777
778 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
779
780 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
781
782 Removes the text starting at the first given position up to (but not including)
783 the character at the last position.
784
785 \wxheading{Parameters}
786
787 \docparam{from}{The first position.}
788
789 \docparam{to}{The last position.}
790
791
792 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
793
794 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
795
796 Replaces the text starting at the first position up to (but not including)
797 the character at the last position with the given text.
798
799 \wxheading{Parameters}
800
801 \docparam{from}{The first position.}
802
803 \docparam{to}{The last position.}
804
805 \docparam{value}{The value to replace the existing text with.}
806
807
808 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
809
810 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
811
812 Saves the contents of the control in a text file.
813
814 \wxheading{Parameters}
815
816 \docparam{filename}{The name of the file in which to save the text.}
817
818 \wxheading{Return value}
819
820 {\tt true} if the operation was successful, {\tt false} otherwise.
821
822
823 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
824
825 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
826
827 Changes the default style to use for the new text which is going to be added
828 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
829 \helpref{AppendText}{wxtextctrlappendtext}.
830
831 If either of the font, foreground, or background colour is not set in\rtfsp
832 {\it style}, the values of the previous default style are used for them. If
833 the previous default style didn't set them neither, the global font or colours
834 of the text control itself are used as fall back.
835
836 However if the {\it style} parameter is the default wxTextAttr, then the
837 default style is just reset (instead of being combined with the new style which
838 wouldn't change it at all).
839
840 \wxheading{Parameters}
841
842 \docparam{style}{The style for the new text.}
843
844 \wxheading{Return value}
845
846 {\tt true} on success, {\tt false} if an error occurred - may also mean that
847 the styles are not supported under this platform.
848
849 \wxheading{See also}
850
851 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
852
853
854 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
855
856 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
857
858 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
859
860 \wxheading{Parameters}
861
862 \docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
863
864 \wxheading{See also}
865
866 \helpref{IsEditable}{wxtextctrliseditable}
867
868
869 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
870
871 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
872
873 Sets the insertion point at the given position.
874
875 \wxheading{Parameters}
876
877 \docparam{pos}{Position to set.}
878
879
880 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
881
882 \func{virtual void}{SetInsertionPointEnd}{\void}
883
884 Sets the insertion point at the end of the text control. This is equivalent
885 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
886
887
888 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
889
890 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
891
892 This function sets the maximum number of characters the user can enter into the
893 control. In other words, it allows to limit the text value length to {\it len}
894 not counting the terminating {\tt NUL} character.
895
896 If {\it len} is $0$, the previously set max length limit, if any, is discarded
897 and the user may enter as much text as the underlying native text control
898 widget supports (typically at least 32Kb).
899
900 If the user tries to enter more characters into the text control when it
901 already is filled up to the maximal length, a
902 {\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
903 (giving it the possibility to show an explanatory message, for example) and the
904 extra input is discarded.
905
906 Note that under GTK+, this function may only be used with single line text controls.
907
908 \wxheading{Compatibility}
909
910 Only implemented in wxMSW/wxGTK starting with wxWidgets 2.3.2.
911
912
913 \membersection{wxTextCtrl::SetModified}\label{wxtextctrlsetmodified}
914
915 \func{void}{SetModified}{\param{bool }{modified}}
916
917 Marks the control as being modified by the user or not.
918
919 \wxheading{See also}
920
921 \helpref{MarkDirty}{wxtextctrlmarkdirty}, \helpref{DiscardEdits}{wxtextctrldiscardedits}
922
923
924 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
925
926 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
927
928 Selects the text starting at the first position up to (but not including) the
929 character at the last position. If both parameters are equal to $-1$ all text
930 in the control is selected.
931
932 \wxheading{Parameters}
933
934 \docparam{from}{The first position.}
935
936 \docparam{to}{The last position.}
937
938
939 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
940
941 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
942
943 Changes the style of the given range. If any attribute within {\it style} is
944 not set, the corresponding attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
945
946 \wxheading{Parameters}
947
948 \docparam{start}{The start of the range to change.}
949
950 \docparam{end}{The end of the range to change.}
951
952 \docparam{style}{The new style for the range.}
953
954 \wxheading{Return value}
955
956 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
957 the styles are not supported under this platform.
958
959 \wxheading{See also}
960
961 \helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
962
963
964 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
965
966 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
967
968 Sets the text value and marks the control as not-modified (which means that
969 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
970 after the call to SetValue).
971
972 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
973 event.
974
975 \wxheading{Parameters}
976
977 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
978
979
980 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
981
982 \func{void}{ShowPosition}{\param{long}{ pos}}
983
984 Makes the line containing the given position visible.
985
986 \wxheading{Parameters}
987
988 \docparam{pos}{The position that should be visible.}
989
990
991 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
992
993 \func{virtual void}{Undo}{\void}
994
995 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
996 if there is no undo facility.
997
998
999 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1000
1001 \func{void}{WriteText}{\param{const wxString\& }{ text}}
1002
1003 Writes the text into the text control at the current insertion position.
1004
1005 \wxheading{Parameters}
1006
1007 \docparam{text}{Text to write to the text control.}
1008
1009 \wxheading{Remarks}
1010
1011 Newlines in the text string
1012 are the only control characters allowed, and they will cause appropriate
1013 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
1014
1015 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.
1016
1017
1018 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1019
1020 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
1021
1022 Converts the given zero based column and line number to a position.
1023
1024 \wxheading{Parameters}
1025
1026 \docparam{x}{The column number.}
1027
1028 \docparam{y}{The line number.}
1029
1030 \wxheading{Return value}
1031
1032 The position value, or -1 if {\tt x} or {\tt y} was invalid.
1033
1034
1035 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1036
1037 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1038
1039 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1040
1041 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1042
1043 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1044
1045 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1046
1047 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1048
1049 Operator definitions for appending to a text control, for example:
1050
1051 \begin{verbatim}
1052 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1053
1054 (*wnd) << "Welcome to text control number " << 1 << ".\n";
1055 \end{verbatim}
1056