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