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