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