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