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