]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/text.tex
[ 1573138 ] small docs corrections
[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,
a1665b22
VZ
221generated when the text changes. Notice that this event will always be sent
222when the text controls contents changes - whether this is due to user input or
223comes from the program itself (for example, if SetValue() is called)}
5de76427 224\twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
0f66923e
VZ
225generated when enter is pressed in a text control (which must have
226wxTE\_PROCESS\_ENTER style for this event to be generated).}
43e8916f 227\twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occurred over an URL
d69b094f 228in the text control (wxMSW and wxGTK2 only)}
f2616db5 229\twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
eef97940 230into the control than the limit set by
f2616db5 231\helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
5de76427
JS
232\end{twocollist}%
233
a660d684
KB
234\latexignore{\rtfignore{\wxheading{Members}}}
235
efe66bbc 236
15d83f72 237\membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlctor}
a660d684
KB
238
239\func{}{wxTextCtrl}{\void}
240
241Default constructor.
242
eaaa6a06 243\func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
aa8a815b
JS
244\param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
245\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
a660d684
KB
246
247Constructor, creating and showing a text control.
248
249\wxheading{Parameters}
250
251\docparam{parent}{Parent window. Should not be NULL.}
252
253\docparam{id}{Control identifier. A value of -1 denotes a default value.}
254
255\docparam{value}{Default text value.}
256
257\docparam{pos}{Text control position.}
258
259\docparam{size}{Text control size.}
260
261\docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
262
263\docparam{validator}{Window validator.}
264
265\docparam{name}{Window name.}
266
267\wxheading{Remarks}
268
74ede4eb
VZ
269The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
270for multi-line text controls.
86975656 271Without a horizontal scrollbar, text lines that don't fit in the control's
71777e2c
HH
272size will be wrapped (but no newline character is inserted). Single line
273controls don't have a horizontal scrollbar, the text is automatically scrolled
86975656 274so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
71777e2c
HH
275visible.
276
c57e3339
VZ
277% VZ: this is no longer true
278%Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
279%as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
280%apply.
a660d684
KB
281
282\wxheading{See also}
283
284\helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
285
efe66bbc 286
15d83f72 287\membersection{wxTextCtrl::\destruct{wxTextCtrl}}\label{wxtextctrldtor}
a660d684
KB
288
289\func{}{\destruct{wxTextCtrl}}{\void}
290
291Destructor, destroying the text control.
292
efe66bbc 293
ca8b28f2
JS
294\membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
295
296\func{void}{AppendText}{\param{const wxString\& }{ text}}
297
298Appends the text to the end of the text control.
299
300\wxheading{Parameters}
301
302\docparam{text}{Text to write to the text control.}
303
304\wxheading{Remarks}
305
306After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
307the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
308
309\wxheading{See also}
310
311\helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
312
efe66bbc 313
ca8b28f2
JS
314\membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
315
316\func{virtual bool}{CanCopy}{\void}
317
cc81d32f 318Returns {\tt true} if the selection can be copied to the clipboard.
ca8b28f2 319
efe66bbc 320
ca8b28f2
JS
321\membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
322
323\func{virtual bool}{CanCut}{\void}
324
cc81d32f 325Returns {\tt true} if the selection can be cut to the clipboard.
ca8b28f2 326
efe66bbc 327
ca8b28f2
JS
328\membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
329
330\func{virtual bool}{CanPaste}{\void}
331
cc81d32f 332Returns {\tt true} if the contents of the clipboard can be pasted into the
ca8b28f2 333text control. On some platforms (Motif, GTK) this is an approximation
cc81d32f 334and returns {\tt true} if the control is editable, {\tt false} otherwise.
ca8b28f2 335
efe66bbc 336
ca8b28f2
JS
337\membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
338
339\func{virtual bool}{CanRedo}{\void}
340
cc81d32f 341Returns {\tt true} if there is a redo facility available and the last operation
ca8b28f2
JS
342can be redone.
343
efe66bbc 344
ca8b28f2
JS
345\membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
346
347\func{virtual bool}{CanUndo}{\void}
348
cc81d32f 349Returns {\tt true} if there is an undo facility available and the last operation
ca8b28f2
JS
350can be undone.
351
efe66bbc 352
a660d684
KB
353\membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
354
355\func{virtual void}{Clear}{\void}
356
357Clears the text in the control.
358
674c474f
VZ
359Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
360event.
361
efe66bbc 362
a660d684
KB
363\membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
364
365\func{virtual void}{Copy}{\void}
366
367Copies the selected text to the clipboard under Motif and MS Windows.
368
efe66bbc 369
a660d684
KB
370\membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
371
eaaa6a06 372\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
aa8a815b
JS
373\param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
374\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
a660d684
KB
375
376Creates the text control for two-step construction. Derived classes
15d83f72 377should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}\rtfsp
a660d684
KB
378for further details.
379
efe66bbc 380
a660d684
KB
381\membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
382
383\func{virtual void}{Cut}{\void}
384
385Copies the selected text to the clipboard and removes the selection.
386
efe66bbc 387
15d83f72 388\membersection{wxTextCtrl::DiscardEdits}\label{wxtextctrldiscardedits}
a660d684
KB
389
390\func{void}{DiscardEdits}{\void}
391
392Resets the internal `modified' flag as if the current edits had been saved.
393
efe66bbc 394
15d83f72 395\membersection{wxTextCtrl::EmulateKeyPress}\label{wxtextctrlemulatekeypress}
94af7d45
VZ
396
397\func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
398
399This functions inserts into the control the character which would have been
43e8916f 400inserted if the given key event had occurred in the text control. The
94af7d45 401{\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
fc2171bd 402handler previously by wxWidgets.
94af7d45 403
cd916794
VZ
404Please note that this function doesn't currently work correctly for all keys
405under any platform but MSW.
406
94af7d45
VZ
407\wxheading{Return value}
408
cc81d32f 409{\tt true} if the event resulted in a change to the control, {\tt false}
94af7d45
VZ
410otherwise.
411
efe66bbc 412
02a3b391 413\membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
eda40bfc
VZ
414
415\constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
416
417Returns the style currently used for the new text.
418
419\wxheading{See also}
420
421\helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
422
efe66bbc 423
a660d684
KB
424\membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
425
426\constfunc{virtual long}{GetInsertionPoint}{\void}
427
71777e2c
HH
428Returns the insertion point. This is defined as the zero based index of the
429character position to the right of the insertion point. For example, if
430the insertion point is at the end of the text control, it is equal to
86975656
RD
431both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
432\helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
71777e2c
HH
433
434The following code snippet safely returns the character at the insertion
435point or the zero character if the point is at the end of the control.
436
437{\small%
438\begin{verbatim}
439 char GetCurrentChar(wxTextCtrl *tc) {
440 if (tc->GetInsertionPoint() == tc->GetLastPosition())
441 return '\0';
442 return tc->GetValue[tc->GetInsertionPoint()];
86975656 443 }
71777e2c
HH
444\end{verbatim}
445}%
a660d684 446
efe66bbc 447
a660d684
KB
448\membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
449
7d8268a1 450\constfunc{virtual wxTextPos}{GetLastPosition}{\void}
a660d684 451
86975656 452Returns the zero based index of the last position in the text control,
71777e2c 453which is equal to the number of characters in the control.
a660d684 454
efe66bbc 455
a660d684
KB
456\membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
457
458\constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
459
86975656 460Gets the length of the specified line, not including any trailing newline
71777e2c 461character(s).
a660d684
KB
462
463\wxheading{Parameters}
464
465\docparam{lineNo}{Line number (starting from zero).}
466
467\wxheading{Return value}
468
469The length of the line, or -1 if {\it lineNo} was invalid.
470
efe66bbc 471
a660d684
KB
472\membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
473
eaaa6a06 474\constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
a660d684 475
71777e2c
HH
476Returns the contents of a given line in the text control, not including
477any trailing newline character(s).
a660d684
KB
478
479\wxheading{Parameters}
480
481\docparam{lineNo}{The line number, starting from zero.}
482
483\wxheading{Return value}
484
485The contents of the line.
486
efe66bbc 487
a660d684
KB
488\membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
489
490\constfunc{int}{GetNumberOfLines}{\void}
491
492Returns the number of lines in the text control buffer.
493
71777e2c
HH
494\wxheading{Remarks}
495
496Note that even empty text controls have one line (where the insertion point
e894be20 497is), so GetNumberOfLines() never returns $0$.
71777e2c 498
e894be20
VZ
499For wxGTK using GTK+ 1.2.x and earlier, the number of lines in a multi-line
500text control is calculated by actually counting newline characters in the
501buffer, i.e. this function returns the number of logical lines and doesn't
502depend on whether any of them are wrapped. For all the other platforms, the
503number of physical lines in the control is returned.
504
505Also note that you may wish to avoid using functions that work with line
506numbers if you are working with controls that contain large amounts of text as
507this function has $O(N)$ complexity for $N$ being the number of lines.
71777e2c 508
efe66bbc 509
a5aa8086
VZ
510\membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
511
512\constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
513
43e8916f 514Returns the string containing the text starting in the positions {\it from} and
a5aa8086
VZ
515up to {\it to} in the control. The positions must have been returned by another
516wxTextCtrl method.
517
518Please note that the positions in a multiline wxTextCtrl do {\bf not}
7d8268a1 519correspond to the indices in the string returned by
a5aa8086
VZ
520\helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
521representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
522obtain the correct results instead of extracting parts of the entire value. It
523may also be more efficient, especially if the control contains a lot of data.
524
efe66bbc 525
ca8b28f2
JS
526\membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
527
a5aa8086 528\constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
ca8b28f2
JS
529
530Gets the current selection span. If the returned values are equal, there was
531no selection.
532
18414479
VZ
533Please note that the indices returned may be used with the other wxTextctrl
534methods but don't necessarily represent the correct indices into the string
535returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
eef97940
RD
536under Windows (at least,) you should use
537\helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
18414479
VZ
538text.
539
ca8b28f2
JS
540\wxheading{Parameters}
541
542\docparam{from}{The returned first position.}
543
544\docparam{to}{The returned last position.}
545
86975656
RD
546\pythonnote{The wxPython version of this method returns a tuple
547consisting of the from and to values.}
548
5873607e
VZ
549\perlnote{In wxPerl this method takes no parameter and returns a
5502-element list {\tt ( from, to )}.}
551
efe66bbc 552
eef97940 553\membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
18414479 554
eef97940 555\func{virtual wxString}{GetStringSelection}{\void}
18414479
VZ
556
557Gets the text currently selected in the control. If there is no selection, the
558returned string is empty.
559
efe66bbc 560
e00a5d3c
JS
561\membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
562
563\func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
564
565Returns the style at this position in the text control. Not all platforms
566support this function.
567
568\wxheading{Return value}
569
43e8916f 570{\tt true} on success, {\tt false} if an error occurred - it may also mean that
e00a5d3c
JS
571the styles are not supported under this platform.
572
573\wxheading{See also}
574
575\helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
576
efe66bbc 577
a660d684
KB
578\membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
579
580\constfunc{wxString}{GetValue}{\void}
581
9750fc42 582Gets the contents of the control. Notice that for a multiline text control,
2b5f62a0
VZ
583the lines will be separated by (Unix-style) $\backslash$n characters, even
584under Windows where they are separated by a $\backslash$r$\backslash$n
585sequence in the native control.
a660d684 586
efe66bbc
VZ
587
588\membersection{wxTextCtrl::HitTest}\label{wxtextctrlhittest}
589
590\constfunc{wxTextCtrlHitTestResult}{HitTest}{\param{const wxPoint\& }{pt}, \param{wxTextCoord }{*col}, \param{wxTextCoord }{*row}}
591
592This function finds the character at the specified position expressed in
593pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
7d8268a1 594of the character closest to this position are returned in the \arg{col} and
b325f27f 595\arg{row} parameters (unless the pointers are {\tt NULL} which is allowed).
efe66bbc 596
692c9b86
VZ
597Please note that this function is currently only implemented in wxUniv,
598wxMSW and wxGTK2 ports.
efe66bbc
VZ
599
600\wxheading{See also}
601
e119d049 602\helpref{PositionToXY}{wxtextctrlpositiontoxy}, \helpref{XYToPosition}{wxtextctrlxytoposition}
efe66bbc 603
066f177c 604\perlnote{In wxPerl this function takes only the position argument and
e119d049 605returns a 3-element list \texttt{(result, col, row)}}.
efe66bbc 606
9e3229b7
VZ
607\membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
608
609\constfunc{bool}{IsEditable}{\void}
610
cc81d32f 611Returns {\tt true} if the controls contents may be edited by user (note that it
9e3229b7 612always can be changed by the program), i.e. if the control hasn't been put in
7d8268a1 613read-only mode by a previous call to
9e3229b7
VZ
614\helpref{SetEditable}{wxtextctrlseteditable}.
615
efe66bbc 616
a660d684
KB
617\membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
618
619\constfunc{bool}{IsModified}{\void}
620
7d8268a1 621Returns {\tt true} if the text has been modified by user. Note that calling
29e1cfc2 622\helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
a660d684 623
43e8916f
MW
624\wxheading{See also}
625
626\helpref{MarkDirty}{wxtextctrlmarkdirty}
627
efe66bbc 628
aa8e9a36
VZ
629\membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
630
631\constfunc{bool}{IsMultiLine}{\void}
632
cc81d32f 633Returns {\tt true} if this is a multi line edit control and {\tt false}
aa8e9a36
VZ
634otherwise.
635
636\wxheading{See also}
637
638\helpref{IsSingleLine}{wxtextctrlissingleline}
639
efe66bbc 640
aa8e9a36
VZ
641\membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
642
643\constfunc{bool}{IsSingleLine}{\void}
644
cc81d32f 645Returns {\tt true} if this is a single line edit control and {\tt false}
aa8e9a36
VZ
646otherwise.
647
648\wxheading{See also}
649
650\helpref{IsMultiLine}{wxtextctrlissingleline}
651
efe66bbc 652
a660d684
KB
653\membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
654
3306aec1 655\func{bool}{LoadFile}{\param{const wxString\& }{ filename}, \param{int }{fileType = wxTEXT\_TYPE\_ANY}}
a660d684
KB
656
657Loads and displays the named file, if it exists.
658
659\wxheading{Parameters}
660
661\docparam{filename}{The filename of the file to load.}
662
3306aec1
JS
663\docparam{fileType}{The type of file to load. This is currently ignored in wxTextCtrl.}
664
a660d684
KB
665\wxheading{Return value}
666
cc81d32f 667{\tt true} if successful, {\tt false} otherwise.
a660d684 668
d2d50a41
VZ
669% VZ: commenting this out as: (a) the docs are wrong (you can't replace
670% anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
671%% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
7d8268a1 672%%
d2d50a41 673%% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
7d8268a1 674%%
d2d50a41 675%% Default handler for character input.
7d8268a1 676%%
d2d50a41 677%% \wxheading{Remarks}
7d8268a1 678%%
d2d50a41
VZ
679%% It is possible to intercept character
680%% input by overriding this member. Call this function
681%% to let the default behaviour take place; not calling
682%% it results in the character being ignored. You can
683%% replace the {\it keyCode} member of {\it event} to
684%% translate keystrokes.
7d8268a1 685%%
d2d50a41
VZ
686%% Note that Windows and Motif have different ways
687%% of implementing the default behaviour. In Windows,
688%% calling wxTextCtrl::OnChar immediately
689%% processes the character. In Motif,
690%% calling this function simply sets a flag
691%% to let default processing happen. This might affect
692%% the way in which you write your OnChar function
693%% on different platforms.
7d8268a1 694%%
d2d50a41 695%% \wxheading{See also}
7d8268a1 696%%
d2d50a41 697%% \helpref{wxKeyEvent}{wxkeyevent}
a660d684 698
efe66bbc 699
43e8916f
MW
700\membersection{wxTextCtrl::MarkDirty}\label{wxtextctrlmarkdirty}
701
702\func{void}{MarkDirty}{\void}
703
704Mark text as modified (dirty).
705
706\wxheading{See also}
707
708\helpref{IsModified}{wxtextctrlismodified}
709
710
a660d684
KB
711\membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
712
713\func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
714
715This event handler function implements default drag and drop behaviour, which
716is to load the first dropped file into the control.
717
718\wxheading{Parameters}
719
720\docparam{event}{The drop files event.}
721
71777e2c
HH
722\wxheading{Remarks}
723
b2cf617c 724This is not implemented on non-Windows platforms.
71777e2c 725
a660d684
KB
726\wxheading{See also}
727
728\helpref{wxDropFilesEvent}{wxdropfilesevent}
729
efe66bbc 730
a660d684
KB
731\membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
732
733\func{virtual void}{Paste}{\void}
734
735Pastes text from the clipboard to the text item.
736
efe66bbc 737
a660d684
KB
738\membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
739
0efe5ba7 740\constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
a660d684 741
71777e2c 742Converts given position to a zero-based column, line number pair.
a660d684
KB
743
744\wxheading{Parameters}
745
746\docparam{pos}{Position.}
747
71777e2c 748\docparam{x}{Receives zero based column number.}
a660d684 749
71777e2c
HH
750\docparam{y}{Receives zero based line number.}
751
752\wxheading{Return value}
753
cc81d32f 754{\tt true} on success, {\tt false} on failure (most likely due to a too large position
71777e2c 755parameter).
a660d684
KB
756
757\wxheading{See also}
758
759\helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
760
71777e2c
HH
761\pythonnote{In Python, PositionToXY() returns a tuple containing the x and
762y values, so (x,y) = PositionToXY() is equivalent to the call described
763above.}
764
5873607e
VZ
765\perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
766returns a 2-element list {\tt ( x, y )}.}
767
efe66bbc 768
ca8b28f2
JS
769\membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
770
771\func{virtual void}{Redo}{\void}
772
773If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
774if there is no redo facility.
775
efe66bbc 776
a660d684
KB
777\membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
778
eaaa6a06 779\func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
a660d684 780
71777e2c
HH
781Removes the text starting at the first given position up to (but not including)
782the character at the last position.
a660d684
KB
783
784\wxheading{Parameters}
785
786\docparam{from}{The first position.}
787
788\docparam{to}{The last position.}
789
efe66bbc 790
a660d684
KB
791\membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
792
eaaa6a06 793\func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
a660d684 794
86975656 795Replaces the text starting at the first position up to (but not including)
71777e2c 796the character at the last position with the given text.
a660d684
KB
797
798\wxheading{Parameters}
799
800\docparam{from}{The first position.}
801
802\docparam{to}{The last position.}
803
804\docparam{value}{The value to replace the existing text with.}
805
efe66bbc 806
a660d684
KB
807\membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
808
3306aec1 809\func{bool}{SaveFile}{\param{const wxString\& }{ filename}, \param{int }{fileType = wxTEXT\_TYPE\_ANY}}
a660d684
KB
810
811Saves the contents of the control in a text file.
812
813\wxheading{Parameters}
814
71777e2c 815\docparam{filename}{The name of the file in which to save the text.}
a660d684 816
3306aec1
JS
817\docparam{fileType}{The type of file to save. This is currently ignored in wxTextCtrl.}
818
a660d684
KB
819\wxheading{Return value}
820
cc81d32f 821{\tt true} if the operation was successful, {\tt false} otherwise.
a660d684 822
efe66bbc 823
eda40bfc
VZ
824\membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
825
826\func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
827
828Changes the default style to use for the new text which is going to be added
829to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
830\helpref{AppendText}{wxtextctrlappendtext}.
831
832If either of the font, foreground, or background colour is not set in\rtfsp
833{\it style}, the values of the previous default style are used for them. If
834the previous default style didn't set them neither, the global font or colours
835of the text control itself are used as fall back.
836
c598f225
VZ
837However if the {\it style} parameter is the default wxTextAttr, then the
838default style is just reset (instead of being combined with the new style which
839wouldn't change it at all).
840
eda40bfc
VZ
841\wxheading{Parameters}
842
843\docparam{style}{The style for the new text.}
844
845\wxheading{Return value}
846
43e8916f 847{\tt true} on success, {\tt false} if an error occurred - may also mean that
eda40bfc
VZ
848the styles are not supported under this platform.
849
850\wxheading{See also}
851
852\helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
853
efe66bbc 854
a660d684
KB
855\membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
856
857\func{virtual void}{SetEditable}{\param{const bool}{ editable}}
858
b2cf617c 859Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
a660d684
KB
860
861\wxheading{Parameters}
862
cc81d32f 863\docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
a660d684 864
9e3229b7
VZ
865\wxheading{See also}
866
867\helpref{IsEditable}{wxtextctrliseditable}
868
efe66bbc 869
a660d684
KB
870\membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
871
eaaa6a06 872\func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
a660d684 873
71777e2c 874Sets the insertion point at the given position.
a660d684
KB
875
876\wxheading{Parameters}
877
878\docparam{pos}{Position to set.}
879
efe66bbc 880
a660d684
KB
881\membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
882
883\func{virtual void}{SetInsertionPointEnd}{\void}
884
71777e2c
HH
885Sets the insertion point at the end of the text control. This is equivalent
886to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
a660d684 887
efe66bbc 888
d7eee191
VZ
889\membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
890
891\func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
892
893This function sets the maximum number of characters the user can enter into the
894control. In other words, it allows to limit the text value length to {\it len}
895not counting the terminating {\tt NUL} character.
896
2edb0bde 897If {\it len} is $0$, the previously set max length limit, if any, is discarded
5949fba6
VZ
898and the user may enter as much text as the underlying native text control
899widget supports (typically at least 32Kb).
900
d7eee191 901If the user tries to enter more characters into the text control when it
eef97940 902already is filled up to the maximal length, a
d7eee191
VZ
903{\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
904(giving it the possibility to show an explanatory message, for example) and the
905extra input is discarded.
906
4a82116e 907Note that under GTK+, this function may only be used with single line text controls.
d7eee191
VZ
908
909\wxheading{Compatibility}
910
fc2171bd 911Only implemented in wxMSW/wxGTK starting with wxWidgets 2.3.2.
d7eee191 912
efe66bbc 913
be0ac181
VZ
914\membersection{wxTextCtrl::SetModified}\label{wxtextctrlsetmodified}
915
916\func{void}{SetModified}{\param{bool }{modified}}
917
918Marks the control as being modified by the user or not.
919
920\wxheading{See also}
921
922\helpref{MarkDirty}{wxtextctrlmarkdirty}, \helpref{DiscardEdits}{wxtextctrldiscardedits}
923
924
a660d684
KB
925\membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
926
eaaa6a06 927\func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
a660d684 928
4d7b7fc2
VZ
929Selects the text starting at the first position up to (but not including) the
930character at the last position. If both parameters are equal to $-1$ all text
931in the control is selected.
a660d684
KB
932
933\wxheading{Parameters}
934
935\docparam{from}{The first position.}
936
937\docparam{to}{The last position.}
938
efe66bbc 939
eda40bfc
VZ
940\membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
941
942\func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
943
e00a5d3c 944Changes the style of the given range. If any attribute within {\it style} is
dbd94b75 945not set, the corresponding attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
eda40bfc
VZ
946
947\wxheading{Parameters}
948
e00a5d3c 949\docparam{start}{The start of the range to change.}
eda40bfc 950
e00a5d3c 951\docparam{end}{The end of the range to change.}
eda40bfc 952
e00a5d3c 953\docparam{style}{The new style for the range.}
eda40bfc
VZ
954
955\wxheading{Return value}
956
43e8916f 957{\tt true} on success, {\tt false} if an error occurred - it may also mean that
eda40bfc
VZ
958the styles are not supported under this platform.
959
e00a5d3c
JS
960\wxheading{See also}
961
962\helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
963
efe66bbc 964
a660d684
KB
965\membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
966
967\func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
968
7d8268a1 969Sets the text value and marks the control as not-modified (which means that
cc81d32f 970\helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
29e1cfc2 971after the call to SetValue).
a660d684 972
674c474f
VZ
973Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
974event.
975
a660d684
KB
976\wxheading{Parameters}
977
978\docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
979
efe66bbc 980
a660d684
KB
981\membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
982
eaaa6a06 983\func{void}{ShowPosition}{\param{long}{ pos}}
a660d684
KB
984
985Makes the line containing the given position visible.
986
987\wxheading{Parameters}
988
989\docparam{pos}{The position that should be visible.}
990
efe66bbc 991
ca8b28f2
JS
992\membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
993
994\func{virtual void}{Undo}{\void}
995
996If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
997if there is no undo facility.
998
efe66bbc 999
a660d684
KB
1000\membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1001
1002\func{void}{WriteText}{\param{const wxString\& }{ text}}
1003
86975656 1004Writes the text into the text control at the current insertion position.
a660d684
KB
1005
1006\wxheading{Parameters}
1007
1008\docparam{text}{Text to write to the text control.}
1009
1010\wxheading{Remarks}
1011
1012Newlines in the text string
1013are the only control characters allowed, and they will cause appropriate
abaa2936 1014line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
71777e2c
HH
1015
1016After 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 1017
efe66bbc 1018
a660d684
KB
1019\membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1020
eaaa6a06 1021\func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
a660d684 1022
71777e2c 1023Converts the given zero based column and line number to a position.
a660d684
KB
1024
1025\wxheading{Parameters}
1026
71777e2c 1027\docparam{x}{The column number.}
a660d684 1028
71777e2c 1029\docparam{y}{The line number.}
a660d684
KB
1030
1031\wxheading{Return value}
1032
21d23b88 1033The position value, or -1 if {\tt x} or {\tt y} was invalid.
a660d684 1034
efe66bbc 1035
a660d684
KB
1036\membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1037
1038\func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1039
1040\func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1041
1042\func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1043
1044\func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1045
1046\func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1047
1048\func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1049
abaa2936 1050Operator definitions for appending to a text control, for example:
a660d684
KB
1051
1052\begin{verbatim}
1053 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1054
1055 (*wnd) << "Welcome to text control number " << 1 << ".\n";
1056\end{verbatim}
1057