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