1 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
5 A text control allows text to be displayed and edited. It may be
6 single line or multi-line.
8 \wxheading{Derived from
}
11 \helpref{wxControl
}{wxcontrol
}\\
12 \helpref{wxWindow
}{wxwindow
}\\
13 \helpref{wxEvtHandler
}{wxevthandler
}\\
14 \helpref{wxObject
}{wxobject
}
16 \wxheading{Include files
}
20 \wxheading{Window styles
}
23 \begin{twocollist
}\itemsep=
0pt
24 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
25 the event wxEVT
\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
26 is either processed internally by the control or used for navigation between
28 \twocolitem{\windowstyle{wxTE
\_PROCESS\_TAB}}{The control will receive
29 wxEVT
\_CHAR events for TAB pressed - normally, TAB is used for passing to the
30 next control in a dialog instead. For the control created with this style,
31 you can still use Ctrl-Enter to pass to the next control from the keyboard.
}
32 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
33 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
34 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
35 \twocolitem{\windowstyle{wxTE
\_RICH}}{Use rich text control under Win32, this
36 allows to have more than
64KB of text in the control even under Win9x. This
37 style is ignored under other platforms.
}
38 \twocolitem{\windowstyle{wxTE
\_RICH2}}{Use rich text control version
2.0 or
3.0
39 under Win32, this style is ignored under other platforms
}
40 \twocolitem{\windowstyle{wxTE
\_AUTO\_URL}}{Highlight the URLs and generate the
41 wxTextUrlEvents when mouse events occur over them. This style is only supported
42 for wxTE
\_RICH Win32 and multi-line wxGTK2 text controls.
}
43 \twocolitem{\windowstyle{wxTE
\_NOHIDESEL}}{By default, the Windows text control
44 doesn't show the selection when it doesn't have focus - use this style to force
45 it to always show it. It doesn't do anything under other platforms.
}
46 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created and
47 used, so that text won't be wrapped. No effect under wxGTK1.
}
48 \twocolitem{\windowstyle{wxTE
\_NO\_VSCROLL}}{For multiline controls only:
49 vertical scrollbar will never be created. This limits the amount of text which
50 can be entered into the control to what can be displayed in it under MSW but
51 not under GTK2. Currently not implemented for the other platforms.
}
52 \twocolitem{\windowstyle{wxTE
\_LEFT}}{The text in the control will be left-justified (default).
}
53 \twocolitem{\windowstyle{wxTE
\_CENTRE}}{The text in the control will be centered (currently wxMSW and wxGTK2 only).
}
54 \twocolitem{\windowstyle{wxTE
\_RIGHT}}{The text in the control will be right-justified (currently wxMSW and wxGTK2 only).
}
55 \twocolitem{\windowstyle{wxTE
\_DONTWRAP}}{Same as
{\tt wxHSCROLL
} style: don't wrap at all, show horizontal scrollbar instead.
}
56 \twocolitem{\windowstyle{wxTE
\_CHARWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv and wxGTK2 only).
}
57 \twocolitem{\windowstyle{wxTE
\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries (wxUniv and wxGTK2 only).
}
58 \twocolitem{\windowstyle{wxTE
\_BESTWRAP}}{Wrap the lines at word boundaries or at any other character if there are words longer than the window width (this is the default).
}
59 \twocolitem{\windowstyle{wxTE
\_CAPITALIZE}}{On PocketPC and Smartphone, causes the first letter to be capitalized.
}
62 See also
\helpref{window styles overview
}{windowstyles
} and
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlctor
}.
64 Note that alignment styles (
\windowstyle{wxTE
\_LEFT},
65 \windowstyle{wxTE
\_CENTRE} and
\windowstyle{wxTE
\_RIGHT}) can be changed
66 dynamically after control creation on wxMSW and wxGTK.
67 \windowstyle{wxTE
\_READONLY},
\windowstyle{wxTE
\_PASSWORD} and wrapping styles
68 can be dynamically changed under wxGTK but not wxMSW. The other styles can be
69 only set during control creation.
72 \wxheading{wxTextCtrl text format
}
74 The multiline text controls always store the text as a sequence of lines
75 separated by
{\tt $
\backslash$n
} characters, i.e. in the Unix text format even
76 on non-Unix platforms. This allows the user code to ignore the differences
77 between the platforms but at a price: the indices in the control such as those
78 returned by
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} or
79 \helpref{GetSelection
}{wxtextctrlgetselection
} can
{\bf not
} be used as
80 indices into the string returned by
\helpref{GetValue
}{wxtextctrlgetvalue
} as
81 they're going to be slightly off for platforms using
82 {\tt $
\backslash$r$
\backslash$n
} as separator (as Windows does), for example.
84 Instead, if you need to obtain a substring between the $
2$ indices obtained
85 from the control with the help of the functions mentioned above, you should
86 use
\helpref{GetRange
}{wxtextctrlgetrange
}. And the indices themselves can
87 only be passed to other methods, for example
88 \helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
} or
89 \helpref{SetSelection
}{wxtextctrlsetselection
}.
91 To summarize: never use the indices returned by (multiline) wxTextCtrl as
92 indices into the string it contains, but only as arguments to be passed back
93 to the other wxTextCtrl methods.
95 \wxheading{wxTextCtrl styles
}
97 Multi-line text controls support the styles, i.e. provide a possibility to set
98 colours and font for individual characters in it (note that under Windows
{\tt
99 wxTE
\_RICH} style is required for style support). To use the styles you can
100 either call
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} before
101 inserting the text or call
\helpref{SetStyle
}{wxtextctrlsetstyle
} later to
102 change the style of the text already in the control (the first solution is
103 much more efficient).
105 In either case, if the style doesn't specify some of the attributes (for
106 example you only want to set the text colour but without changing the font nor
107 the text background), the values of the default style will be used for them.
108 If there is no default style, the attributes of the text control itself are
111 So the following code correctly describes what it does: the second call
112 to
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} doesn't change the
113 text foreground colour (which stays red) while the last one doesn't change the
114 background colour (which stays grey):
118 text->SetDefaultStyle(wxTextAttr
(*wxRED));
119 text->AppendText("Red text\n");
120 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
121 text->AppendText("Red on grey text\n");
122 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
123 text->AppendText("Blue on grey text\n");
127 \wxheading{wxTextCtrl and C++ streams}
129 This class multiply-inherits from {\bf streambuf} where compilers allow,
130 allowing code such as the following:
134 wxTextCtrl *control = new wxTextCtrl(...);
136 ostream stream(control)
138 stream << 123.456 << " some text\n";
143 If your compiler does not support derivation from {\bf streambuf} and gives a
144 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
145 wxTextCtrl header file.
147 Note that independently of this setting you can always use wxTextCtrl itself
148 in a stream-like manner:
152 wxTextCtrl *control = new wxTextCtrl(...);
154 *control << 123.456 << " some text\n";
158 always works. However the possibility to create an ostream associated with
159 wxTextCtrl may be useful if you need to redirect the output of a function
160 taking an ostream as parameter to a text control.
162 Another commonly requested need is to redirect {\bf std::cout} to the text
163 control. This could be done in the following way:
169 wxTextCtrl *control = new wxTextCtrl(...);
171 std::streambuf *sbOld = std::cout.rdbuf();
172 std::cout.rdbuf(*control);
174 // use cout as usual, the output appears in the text control
177 std::cout.rdbuf(sbOld);
181 But wxWidgets provides a convenient class to make it even simpler so instead
188 wxTextCtrl *control = new wxTextCtrl(...);
190 wxStreamToTextRedirector redirect(control);
192 // all output to cout goes into the text control until the exit from current
197 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
200 \wxheading{Constants}
202 The values below are the possible return codes of the
203 \helpref{HitTest}{wxtextctrlhittest} method:
207 // the point asked is ...
208 enum wxTextCtrlHitTestResult
210 wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented
211 wxTE_HT_BEFORE, // either to the left or upper
212 wxTE_HT_ON_TEXT, // directly on
213 wxTE_HT_BELOW, // below [the last line]
214 wxTE_HT_BEYOND // after [the end of line]
216 // ... the character returned
221 \wxheading{Event handling}
223 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
224 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
225 automatically, when the control has the focus.
227 To process input from a text control, use these event handler macros to direct input to member
228 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
231 \begin{twocollist}\itemsep=0pt
232 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
233 generated when the text changes. Notice that this event will be sent
234 when the text controls contents changes - whether this is due to user input or
235 comes from the program itself (for example, if SetValue() is called); see ChangeValue() for
236 a function which does not send this event.}
237 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
238 generated when enter is pressed in a text control (which must have
239 wxTE\_PROCESS\_ENTER style for this event to be generated).}
240 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occurred over an URL
241 in the text control (wxMSW and wxGTK2 only)}
242 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
243 into the control than the limit set by
244 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
247 \latexignore{\rtfignore{\wxheading{Members}}}
250 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlctor}
252 \func{}{wxTextCtrl}{\void}
256 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
257 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
258 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
260 Constructor, creating and showing a text control.
262 \wxheading{Parameters}
264 \docparam{parent}{Parent window. Should not be NULL.}
266 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
268 \docparam{value}{Default text value.}
270 \docparam{pos}{Text control position.}
272 \docparam{size}{Text control size.}
274 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
276 \docparam{validator}{Window validator.}
278 \docparam{name}{Window name.}
282 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
283 for multi-line text controls.
284 Without a horizontal scrollbar, text lines that don't fit in the control's
285 size will be wrapped (but no newline character is inserted). Single line
286 controls don't have a horizontal scrollbar, the text is automatically scrolled
287 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
290 % VZ: this is no longer true
291 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
292 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
297 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
300 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}\label{wxtextctrldtor}
302 \func{}{\destruct{wxTextCtrl}}{\void}
304 Destructor, destroying the text control.
307 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
309 \func{void}{AppendText}{\param{const wxString\& }{ text}}
311 Appends the text to the end of the text control.
313 \wxheading{Parameters}
315 \docparam{text}{Text to write to the text control.}
319 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
320 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
324 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
327 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
329 \func{virtual bool}{CanCopy}{\void}
331 Returns {\tt true} if the selection can be copied to the clipboard.
334 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
336 \func{virtual bool}{CanCut}{\void}
338 Returns {\tt true} if the selection can be cut to the clipboard.
341 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
343 \func{virtual bool}{CanPaste}{\void}
345 Returns {\tt true} if the contents of the clipboard can be pasted into the
346 text control. On some platforms (Motif, GTK) this is an approximation
347 and returns {\tt true} if the control is editable, {\tt false} otherwise.
350 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
352 \func{virtual bool}{CanRedo}{\void}
354 Returns {\tt true} if there is a redo facility available and the last operation
358 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
360 \func{virtual bool}{CanUndo}{\void}
362 Returns {\tt true} if there is an undo facility available and the last operation
366 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
368 \func{virtual void}{Clear}{\void}
370 Clears the text in the control.
372 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
376 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
378 \func{virtual void}{Copy}{\void}
380 Copies the selected text to the clipboard under Motif and MS Windows.
383 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
385 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
386 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
387 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
389 Creates the text control for two-step construction. Derived classes
390 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}\rtfsp
394 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
396 \func{virtual void}{Cut}{\void}
398 Copies the selected text to the clipboard and removes the selection.
401 \membersection{wxTextCtrl::DiscardEdits}\label{wxtextctrldiscardedits}
403 \func{void}{DiscardEdits}{\void}
405 Resets the internal `modified' flag as if the current edits had been saved.
408 \membersection{wxTextCtrl::EmulateKeyPress}\label{wxtextctrlemulatekeypress}
410 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
412 This functions inserts into the control the character which would have been
413 inserted if the given key event had occurred in the text control. The
414 {\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
415 handler previously by wxWidgets.
417 Please note that this function doesn't currently work correctly for all keys
418 under any platform but MSW.
420 \wxheading{Return value}
422 {\tt true} if the event resulted in a change to the control, {\tt false}
426 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
428 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
430 Returns the style currently used for the new text.
434 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
437 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
439 \constfunc{virtual long}{GetInsertionPoint}{\void}
441 Returns the insertion point. This is defined as the zero based index of the
442 character position to the right of the insertion point. For example, if
443 the insertion point is at the end of the text control, it is equal to
444 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
445 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
447 The following code snippet safely returns the character at the insertion
448 point or the zero character if the point is at the end of the control.
452 char GetCurrentChar(wxTextCtrl *tc) {
453 if (tc->GetInsertionPoint() == tc->GetLastPosition())
455 return tc->GetValue[tc->GetInsertionPoint()];
461 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
463 \constfunc{virtual wxTextPos}{GetLastPosition}{\void}
465 Returns the zero based index of the last position in the text control,
466 which is equal to the number of characters in the control.
469 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
471 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
473 Gets the length of the specified line, not including any trailing newline
476 \wxheading{Parameters}
478 \docparam{lineNo}{Line number (starting from zero).}
480 \wxheading{Return value}
482 The length of the line, or -1 if {\it lineNo} was invalid.
485 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
487 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
489 Returns the contents of a given line in the text control, not including
490 any trailing newline character(s).
492 \wxheading{Parameters}
494 \docparam{lineNo}{The line number, starting from zero.}
496 \wxheading{Return value}
498 The contents of the line.
501 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
503 \constfunc{int}{GetNumberOfLines}{\void}
505 Returns the number of lines in the text control buffer.
509 Note that even empty text controls have one line (where the insertion point
510 is), so GetNumberOfLines() never returns $0$.
512 For wxGTK using GTK+ 1.2.x and earlier, the number of lines in a multi-line
513 text control is calculated by actually counting newline characters in the
514 buffer, i.e. this function returns the number of logical lines and doesn't
515 depend on whether any of them are wrapped. For all the other platforms, the
516 number of physical lines in the control is returned.
518 Also note that you may wish to avoid using functions that work with line
519 numbers if you are working with controls that contain large amounts of text as
520 this function has $O(N)$ complexity for $N$ being the number of lines.
523 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
525 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
527 Returns the string containing the text starting in the positions {\it from} and
528 up to {\it to} in the control. The positions must have been returned by another
531 Please note that the positions in a multiline wxTextCtrl do {\bf not}
532 correspond to the indices in the string returned by
533 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
534 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
535 obtain the correct results instead of extracting parts of the entire value. It
536 may also be more efficient, especially if the control contains a lot of data.
539 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
541 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
543 Gets the current selection span. If the returned values are equal, there was
546 Please note that the indices returned may be used with the other wxTextctrl
547 methods but don't necessarily represent the correct indices into the string
548 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
549 under Windows (at least,) you should use
550 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
553 \wxheading{Parameters}
555 \docparam{from}{The returned first position.}
557 \docparam{to}{The returned last position.}
559 \pythonnote{The wxPython version of this method returns a tuple
560 consisting of the from and to values.}
562 \perlnote{In wxPerl this method takes no parameter and returns a
563 2-element list {\tt ( from, to )}.}
566 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
568 \func{virtual wxString}{GetStringSelection}{\void}
570 Gets the text currently selected in the control. If there is no selection, the
571 returned string is empty.
574 \membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
576 \func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
578 Returns the style at this position in the text control. Not all platforms
579 support this function.
581 \wxheading{Return value}
583 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
584 the styles are not supported under this platform.
588 \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
591 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
593 \constfunc{wxString}{GetValue}{\void}
595 Gets the contents of the control. Notice that for a multiline text control,
596 the lines will be separated by (Unix-style) $\backslash$n characters, even
597 under Windows where they are separated by a $\backslash$r$\backslash$n
598 sequence in the native control.
601 \membersection{wxTextCtrl::HitTest}\label{wxtextctrlhittest}
603 \constfunc{wxTextCtrlHitTestResult}{HitTest}{\param{const wxPoint\& }{pt}, \param{wxTextCoord }{*col}, \param{wxTextCoord }{*row}}
605 This function finds the character at the specified position expressed in
606 pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
607 of the character closest to this position are returned in the \arg{col} and
608 \arg{row} parameters (unless the pointers are {\tt NULL} which is allowed).
610 Please note that this function is currently only implemented in wxUniv,
611 wxMSW and wxGTK2 ports.
615 \helpref{PositionToXY}{wxtextctrlpositiontoxy}, \helpref{XYToPosition}{wxtextctrlxytoposition}
617 \perlnote{In wxPerl this function takes only the position argument and
618 returns a 3-element list \texttt{(result, col, row)}}.
621 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
623 \constfunc{bool}{IsEditable}{\void}
625 Returns {\tt true} if the controls contents may be edited by user (note that it
626 always can be changed by the program), i.e. if the control hasn't been put in
627 read-only mode by a previous call to
628 \helpref{SetEditable}{wxtextctrlseteditable}.
631 \membersection{wxTextCtrl::IsEmpty}\label{wxtextctrlisempty}
633 \constfunc{bool}{IsEmpty}{\void}
635 Returns \true if the control is currently empty. This is the same as
636 \texttt{GetValue().empty()} but can be much more efficient for the multiline
637 controls containing big amounts of text.
642 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
644 \constfunc{bool}{IsModified}{\void}
646 Returns {\tt true} if the text has been modified by user. Note that calling
647 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
651 \helpref{MarkDirty}{wxtextctrlmarkdirty}
654 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
656 \constfunc{bool}{IsMultiLine}{\void}
658 Returns {\tt true} if this is a multi line edit control and {\tt false}
663 \helpref{IsSingleLine}{wxtextctrlissingleline}
666 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
668 \constfunc{bool}{IsSingleLine}{\void}
670 Returns {\tt true} if this is a single line edit control and {\tt false}
675 \helpref{IsMultiLine}{wxtextctrlissingleline}
678 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
680 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}, \param{int }{fileType = wxTEXT\_TYPE\_ANY}}
682 Loads and displays the named file, if it exists.
684 \wxheading{Parameters}
686 \docparam{filename}{The filename of the file to load.}
688 \docparam{fileType}{The type of file to load. This is currently ignored in wxTextCtrl.}
690 \wxheading{Return value}
692 {\tt true} if successful, {\tt false} otherwise.
694 % VZ: commenting this out as: (a) the docs are wrong (you can't replace
695 % anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
696 %% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
698 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
700 %% Default handler for character input.
702 %% \wxheading{Remarks}
704 %% It is possible to intercept character
705 %% input by overriding this member. Call this function
706 %% to let the default behaviour take place; not calling
707 %% it results in the character being ignored. You can
708 %% replace the {\it keyCode} member of {\it event} to
709 %% translate keystrokes.
711 %% Note that Windows and Motif have different ways
712 %% of implementing the default behaviour. In Windows,
713 %% calling wxTextCtrl::OnChar immediately
714 %% processes the character. In Motif,
715 %% calling this function simply sets a flag
716 %% to let default processing happen. This might affect
717 %% the way in which you write your OnChar function
718 %% on different platforms.
720 %% \wxheading{See also}
722 %% \helpref{wxKeyEvent}{wxkeyevent}
725 \membersection{wxTextCtrl::MarkDirty}\label{wxtextctrlmarkdirty}
727 \func{void}{MarkDirty}{\void}
729 Mark text as modified (dirty).
733 \helpref{IsModified}{wxtextctrlismodified}
736 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
738 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
740 This event handler function implements default drag and drop behaviour, which
741 is to load the first dropped file into the control.
743 \wxheading{Parameters}
745 \docparam{event}{The drop files event.}
749 This is not implemented on non-Windows platforms.
753 \helpref{wxDropFilesEvent}{wxdropfilesevent}
756 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
758 \func{virtual void}{Paste}{\void}
760 Pastes text from the clipboard to the text item.
763 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
765 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
767 Converts given position to a zero-based column, line number pair.
769 \wxheading{Parameters}
771 \docparam{pos}{Position.}
773 \docparam{x}{Receives zero based column number.}
775 \docparam{y}{Receives zero based line number.}
777 \wxheading{Return value}
779 {\tt true} on success, {\tt false} on failure (most likely due to a too large position
784 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
786 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
787 y values, so (x,y) = PositionToXY() is equivalent to the call described
790 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
791 returns a 2-element list {\tt ( x, y )}.}
794 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
796 \func{virtual void}{Redo}{\void}
798 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
799 if there is no redo facility.
802 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
804 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
806 Removes the text starting at the first given position up to (but not including)
807 the character at the last position.
809 \wxheading{Parameters}
811 \docparam{from}{The first position.}
813 \docparam{to}{The last position.}
816 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
818 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
820 Replaces the text starting at the first position up to (but not including)
821 the character at the last position with the given text.
823 \wxheading{Parameters}
825 \docparam{from}{The first position.}
827 \docparam{to}{The last position.}
829 \docparam{value}{The value to replace the existing text with.}
832 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
834 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}, \param{int }{fileType = wxTEXT\_TYPE\_ANY}}
836 Saves the contents of the control in a text file.
838 \wxheading{Parameters}
840 \docparam{filename}{The name of the file in which to save the text.}
842 \docparam{fileType}{The type of file to save. This is currently ignored in wxTextCtrl.}
844 \wxheading{Return value}
846 {\tt true} if the operation was successful, {\tt false} otherwise.
849 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
851 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
853 Changes the default style to use for the new text which is going to be added
854 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
855 \helpref{AppendText}{wxtextctrlappendtext}.
857 If either of the font, foreground, or background colour is not set in\rtfsp
858 {\it style}, the values of the previous default style are used for them. If
859 the previous default style didn't set them neither, the global font or colours
860 of the text control itself are used as fall back.
862 However if the {\it style} parameter is the default wxTextAttr, then the
863 default style is just reset (instead of being combined with the new style which
864 wouldn't change it at all).
866 \wxheading{Parameters}
868 \docparam{style}{The style for the new text.}
870 \wxheading{Return value}
872 {\tt true} on success, {\tt false} if an error occurred - may also mean that
873 the styles are not supported under this platform.
877 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
880 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
882 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
884 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
886 \wxheading{Parameters}
888 \docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
892 \helpref{IsEditable}{wxtextctrliseditable}
895 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
897 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
899 Sets the insertion point at the given position.
901 \wxheading{Parameters}
903 \docparam{pos}{Position to set.}
906 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
908 \func{virtual void}{SetInsertionPointEnd}{\void}
910 Sets the insertion point at the end of the text control. This is equivalent
911 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
914 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
916 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
918 This function sets the maximum number of characters the user can enter into the
919 control. In other words, it allows to limit the text value length to {\it len}
920 not counting the terminating {\tt NUL} character.
922 If {\it len} is $0$, the previously set max length limit, if any, is discarded
923 and the user may enter as much text as the underlying native text control
924 widget supports (typically at least 32Kb).
926 If the user tries to enter more characters into the text control when it
927 already is filled up to the maximal length, a
928 {\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
929 (giving it the possibility to show an explanatory message, for example) and the
930 extra input is discarded.
932 Note that under GTK+, this function may only be used with single line text controls.
934 \wxheading{Compatibility}
936 Only implemented in wxMSW/wxGTK starting with wxWidgets 2.3.2.
939 \membersection{wxTextCtrl::SetModified}\label{wxtextctrlsetmodified}
941 \func{void}{SetModified}{\param{bool }{modified}}
943 Marks the control as being modified by the user or not.
947 \helpref{MarkDirty}{wxtextctrlmarkdirty}, \helpref{DiscardEdits}{wxtextctrldiscardedits}
950 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
952 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
954 Selects the text starting at the first position up to (but not including) the
955 character at the last position. If both parameters are equal to $-1$ all text
956 in the control is selected.
958 \wxheading{Parameters}
960 \docparam{from}{The first position.}
962 \docparam{to}{The last position.}
965 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
967 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
969 Changes the style of the given range. If any attribute within {\it style} is
970 not set, the corresponding attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
972 \wxheading{Parameters}
974 \docparam{start}{The start of the range to change.}
976 \docparam{end}{The end of the range to change.}
978 \docparam{style}{The new style for the range.}
980 \wxheading{Return value}
982 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
983 the styles are not supported under this platform.
987 \helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
990 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
992 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
994 Sets the text value and marks the control as not-modified (which means that
995 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
996 after the call to SetValue).
998 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
1001 This function is deprecated and should not be used in new code. Please use the
1002 \helpref{ChangeValue}{wxtextctrlchangevalue} function instead.
1004 \wxheading{Parameters}
1006 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
1009 \membersection{wxTextCtrl::ChangeValue}\label{wxtextctrlchangevalue}
1011 \func{virtual void}{ChangeValue}{\param{const wxString\& }{ value}}
1013 Sets the text value and marks the control as not-modified (which means that
1014 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
1015 after the call to SetValue).
1017 Note that this function will \emph{not} generate the {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
1019 This is the only difference with \helpref{SetValue}{wxtextctrlsetvalue}.
1020 See \helpref{this topic}{progevent} for more information.
1024 \wxheading{Parameters}
1026 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
1029 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
1031 \func{void}{ShowPosition}{\param{long}{ pos}}
1033 Makes the line containing the given position visible.
1035 \wxheading{Parameters}
1037 \docparam{pos}{The position that should be visible.}
1040 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
1042 \func{virtual void}{Undo}{\void}
1044 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
1045 if there is no undo facility.
1048 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1050 \func{void}{WriteText}{\param{const wxString\& }{ text}}
1052 Writes the text into the text control at the current insertion position.
1054 \wxheading{Parameters}
1056 \docparam{text}{Text to write to the text control.}
1060 Newlines in the text string
1061 are the only control characters allowed, and they will cause appropriate
1062 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
1064 After 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.
1067 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1069 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
1071 Converts the given zero based column and line number to a position.
1073 \wxheading{Parameters}
1075 \docparam{x}{The column number.}
1077 \docparam{y}{The line number.}
1079 \wxheading{Return value}
1081 The position value, or -1 if {\tt x} or {\tt y} was invalid.
1084 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1086 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1088 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1090 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1092 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1094 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1096 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1098 Operator definitions for appending to a text control, for example:
1101 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1103 (*wnd) << "Welcome to text control number " << 1 << ".\n";