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