1 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextAttr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 \section{\class{wxTextAttr
}}\label{wxtextattr
}
5 wxTextAttr represents the attributes, or style, for a range of text in a
\rtfsp
6 \helpref{wxTextCtrl
}{wxtextctrl
}.
8 \wxheading{Derived from
}
12 \wxheading{Include files
}
16 \latexignore{\rtfignore{\wxheading{Members
}}}
18 \membersection{wxTextAttr::wxTextAttr
}\label{wxtextattrctor
}
20 \func{}{wxTextAttr
}{\void}
22 \func{}{wxTextAttr
}{\param{const wxColour\&
}{colText
},
\param{const wxColour\&
}{colBack = wxNullColour
},
\param{const wxFont\&
}{font = wxNullFont
}}
24 The constructors initialize one or more of the text foreground and background
25 colours and font. The values not initialized in the constructor can be set
26 later, otherwise
\helpref{wxTextCtrl::SetStyle
}{wxtextctrlsetstyle
} will use
27 the default values for them.
29 \membersection{wxTextAttr::GetBackgroundColour
}
31 \constfunc{const wxColour\&
}{GetBackgroundColour
}{\void}
33 Return the background colour specified by this attribute.
35 \membersection{wxTextAttr::GetFont
}
37 \constfunc{const wxFont\&
}{GetFont
}{\void}
39 Return the text font specified by this attribute.
41 \membersection{wxTextAttr::GetTextColour
}
43 \constfunc{const wxColour\&
}{GetTextColour
}{\void}
45 Return the text colour specified by this attribute.
47 \membersection{wxTextAttr::HasBackgroundColour
}
49 \constfunc{bool
}{HasBackgroundColour
}{\void}
51 Returns
{\tt TRUE
} if this style specifies the background colour to use.
53 \membersection{wxTextAttr::HasFont
}
55 \constfunc{bool
}{HasFont
}{\void}
57 Returns
{\tt TRUE
} if this style specifies the font to use.
59 \membersection{wxTextAttr::HasTextColour
}
61 \constfunc{bool
}{HasTextColour
}{\void}
63 Returns
{\tt TRUE
} if this style specifies the foreground colour to use.
65 \membersection{wxTextAttr::IsDefault
}
67 \constfunc{bool
}{IsDefault
}{\void}
69 Returns
{\tt TRUE
} if this style specifies any non-default attributes.
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
75 A text control allows text to be displayed and edited. It may be
76 single line or multi-line.
78 \wxheading{Derived from
}
81 \helpref{wxControl
}{wxcontrol
}\\
82 \helpref{wxWindow
}{wxwindow
}\\
83 \helpref{wxEvtHandler
}{wxevthandler
}\\
84 \helpref{wxObject
}{wxobject
}
86 \wxheading{Include files
}
90 \wxheading{Window styles
}
93 \begin{twocollist
}\itemsep=
0pt
94 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
95 the message wxEVENT
\_TYPE\_TEXT\_ENTER\_COMMAND (otherwise pressing Enter key
96 is either processed internally by the control or used for navigation between
98 \twocolitem{\windowstyle{wxTE
\_PROCESS\_TAB}}{The control will receive
99 EVT
\_CHAR messages for TAB pressed - normally, TAB is used for passing to the
100 next control in a dialog instead. For the control created with this style,
101 you can still use Ctrl-Enter to pass to the next control from the keyboard.
}
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.
}
105 \twocolitem{\windowstyle{wxTE
\_RICH}}{Use rich text control under Win32, this
106 allows to have more than
64Kb of text in the control even under Win9x. This
107 style is ignored under other platforms.
}
108 \twocolitem{\windowstyle{wxTE
\_RICH2}}{Use rich text control version
2.0 or
3.0
109 under Win32, this style is ignored under other platforms
}
110 \twocolitem{\windowstyle{wxTE
\_AUTO\_URL}}{Highlight the URLs and generate the
111 wxTextUrlEvents when mouse events occur over them. This style is supported
112 under Win32 only and requires wxTE
\_RICH.
}
113 \twocolitem{\windowstyle{wxTE
\_NOHIDESEL}}{By default, the Windows text control
114 doesn't show the selection when it doesn't have focus - use this style to force
115 it to always show it. It doesn't do anything under other platforms.
}
116 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created. No effect under GTK+.
}
117 \twocolitem{\windowstyle{wxTE
\_LEFT}}{The text control will be left-justified (default).
}
118 \twocolitem{\windowstyle{wxTE
\_CENTRE}}{The text control will be centre-justified.
}
119 \twocolitem{\windowstyle{wxTE
\_RIGHT}}{The text control will be right-justified.
}
120 \twocolitem{\windowstyle{wxTE
\_DONTWRAP}}{Same as
{\tt wxHSCROLL
} style.
}
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).
}
125 See also
\helpref{window styles overview
}{windowstyles
} and
126 \helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}.
128 \wxheading{wxTextCtrl text format
}
130 The multiline text controls always store the text as a sequence of lines
131 separated by
{\tt $
\backslash$n
} characters, i.e. in the Unix text format even
132 on non-Unix platforms. This allows the user code to ignore the differences
133 between the platforms but at a price: the indices in the control such as those
134 returned by
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} or
135 \helpref{GetSelection
}{wxtextctrlgetselection
} can
{\bf not
} be used as
136 indices into the string returned by
\helpref{GetValue
}{wxtextctrlgetvalue
} as
137 they're going to be slightly off for platforms using
138 {\tt $
\backslash$r$
\backslash$n
} as separator (as Windows does), for example.
140 Instead, if you need to obtain a substring between the $
2$ indices obtained
141 from the control with the help of the functions mentioned above, you should
142 use
\helpref{GetRange
}{wxtextctrlgetrange
}. And the indices themselves can
143 only be passed to other methods, for example
144 \helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
} or
145 \helpref{SetSelection
}{wxtextctrlsetselection
}.
147 To summarize: never use the indices returned by (multiline) wxTextCtrl as
148 indices into the string it contains, but only as arguments to be passed back
149 to the other wxTextCtrl methods.
151 \wxheading{wxTextCtrl styles
}
153 Multi-line text controls support the styles, i.e. provide a possibility to set
154 colours and font for individual characters in it (note that under Windows
{\tt
155 wxTE
\_RICH} style is required for style support). To use the styles you can
156 either call
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} before
157 inserting the text or call
\helpref{SetStyle
}{wxtextctrlsetstyle
} later to
158 change the style of the text already in the control (the first solution is
159 much more efficient).
161 In either case, if the style doesn't specify some of the attributes (for
162 example you only want to set the text colour but without changing the font nor
163 the text background), the values of the default style will be used for them.
164 If there is no default style, the attributes of the text control itself are
167 So the following code correctly describes what it does: the second call
168 to
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} doesn't change the
169 text foreground colour (which stays red) while the last one doesn't change the
170 background colour (which stays grey):
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");
183 \wxheading{wxTextCtrl and C++ streams}
185 This class multiply-inherits from {\bf streambuf} where compilers allow,
186 allowing code such as the following:
190 wxTextCtrl *control = new wxTextCtrl(...);
192 ostream stream(control)
194 stream << 123.456 << " some text\n";
199 If your compiler does not support derivation from {\bf streambuf} and gives a
200 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
201 wxTextCtrl header file.
203 Note that independently of this setting you can always use wxTextCtrl itself
204 in a stream-like manner:
208 wxTextCtrl *control = new wxTextCtrl(...);
210 *control << 123.456 << " some text\n";
214 always works. However the possibility to create an ostream associated with
215 wxTextCtrl may be useful if you need to redirect the output of a function
216 taking an ostream as parameter to a text control.
218 Another commonly requested need is to redirect {\bf std::cout} to the text
219 control. This could be done in the following way:
225 wxTextCtrl *control = new wxTextCtrl(...);
227 std::streambuf *sbOld = std::cout.rdbuf();
228 std::cout.rdbuf(*control);
230 // use cout as usual, the output appears in the text control
233 std::cout.rdbuf(sbOld);
237 But wxWindows provides a convenient class to make it even simpler so instead
244 wxTextCtrl *control = new wxTextCtrl(...);
246 wxStreamToTextRedirector redirect(control);
248 // all output to cout goes into the text control until the exit from current
253 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
256 \wxheading{Event handling}
258 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
259 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
260 automatically, when the control has the focus.
262 To process input from a text control, use these event handler macros to direct input to member
263 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
266 \begin{twocollist}\itemsep=0pt
267 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
268 generated when the text changes. Notice that this event will always be sent
269 when the text controls contents changes - whether this is due to user input or
270 comes from the program itself (for example, if SetValue() is called)}
271 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
272 generated when enter is pressed in a text control (which must have
273 wxTE\_PROCESS\_ENTER style for this event to be generated).}
274 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occured over an URL
275 in the text control (Win32 only)}
276 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
277 into the control than the limit set by
278 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
281 \latexignore{\rtfignore{\wxheading{Members}}}
283 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlconstr}
285 \func{}{wxTextCtrl}{\void}
289 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
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}}
293 Constructor, creating and showing a text control.
295 \wxheading{Parameters}
297 \docparam{parent}{Parent window. Should not be NULL.}
299 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
301 \docparam{value}{Default text value.}
303 \docparam{pos}{Text control position.}
305 \docparam{size}{Text control size.}
307 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
309 \docparam{validator}{Window validator.}
311 \docparam{name}{Window name.}
315 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
316 for multi-line text controls.
317 Without a horizontal scrollbar, text lines that don't fit in the control's
318 size will be wrapped (but no newline character is inserted). Single line
319 controls don't have a horizontal scrollbar, the text is automatically scrolled
320 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
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
330 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
332 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}
334 \func{}{\destruct{wxTextCtrl}}{\void}
336 Destructor, destroying the text control.
338 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
340 \func{void}{AppendText}{\param{const wxString\& }{ text}}
342 Appends the text to the end of the text control.
344 \wxheading{Parameters}
346 \docparam{text}{Text to write to the text control.}
350 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
351 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
355 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
357 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
359 \func{virtual bool}{CanCopy}{\void}
361 Returns {\tt TRUE} if the selection can be copied to the clipboard.
363 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
365 \func{virtual bool}{CanCut}{\void}
367 Returns {\tt TRUE} if the selection can be cut to the clipboard.
369 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
371 \func{virtual bool}{CanPaste}{\void}
373 Returns {\tt TRUE} if the contents of the clipboard can be pasted into the
374 text control. On some platforms (Motif, GTK) this is an approximation
375 and returns {\tt TRUE} if the control is editable, {\tt FALSE} otherwise.
377 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
379 \func{virtual bool}{CanRedo}{\void}
381 Returns {\tt TRUE} if there is a redo facility available and the last operation
384 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
386 \func{virtual bool}{CanUndo}{\void}
388 Returns {\tt TRUE} if there is an undo facility available and the last operation
391 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
393 \func{virtual void}{Clear}{\void}
395 Clears the text in the control.
397 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
400 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
402 \func{virtual void}{Copy}{\void}
404 Copies the selected text to the clipboard under Motif and MS Windows.
406 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
408 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
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}}
412 Creates the text control for two-step construction. Derived classes
413 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlconstr}\rtfsp
416 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
418 \func{virtual void}{Cut}{\void}
420 Copies the selected text to the clipboard and removes the selection.
422 \membersection{wxTextCtrl::DiscardEdits}
424 \func{void}{DiscardEdits}{\void}
426 Resets the internal `modified' flag as if the current edits had been saved.
428 \membersection{wxTextCtrl::EmulateKeyPress}
430 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
432 This functions inserts into the control the character which would have been
433 inserted 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}
435 handler previously by wxWindows.
437 Please note that this function doesn't currently work correctly for all keys
438 under any platform but MSW.
440 \wxheading{Return value}
442 {\tt TRUE} if the event resulted in a change to the control, {\tt FALSE}
445 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
447 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
449 Returns the style currently used for the new text.
453 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
455 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
457 \constfunc{virtual long}{GetInsertionPoint}{\void}
459 Returns the insertion point. This is defined as the zero based index of the
460 character position to the right of the insertion point. For example, if
461 the insertion point is at the end of the text control, it is equal to
462 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
463 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
465 The following code snippet safely returns the character at the insertion
466 point or the zero character if the point is at the end of the control.
470 char GetCurrentChar(wxTextCtrl *tc) {
471 if (tc->GetInsertionPoint() == tc->GetLastPosition())
473 return tc->GetValue[tc->GetInsertionPoint()];
478 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
480 \constfunc{virtual long}{GetLastPosition}{\void}
482 Returns the zero based index of the last position in the text control,
483 which is equal to the number of characters in the control.
485 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
487 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
489 Gets the length of the specified line, not including any trailing newline
492 \wxheading{Parameters}
494 \docparam{lineNo}{Line number (starting from zero).}
496 \wxheading{Return value}
498 The length of the line, or -1 if {\it lineNo} was invalid.
500 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
502 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
504 Returns the contents of a given line in the text control, not including
505 any trailing newline character(s).
507 \wxheading{Parameters}
509 \docparam{lineNo}{The line number, starting from zero.}
511 \wxheading{Return value}
513 The contents of the line.
515 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
517 \constfunc{int}{GetNumberOfLines}{\void}
519 Returns the number of lines in the text control buffer.
523 Note that even empty text controls have one line (where the insertion point
524 is), so GetNumberOfLines() never returns 0.
526 For gtk\_text (multi-line) controls, the number of lines is
527 calculated by actually counting newline characters in the buffer. You
528 may wish to avoid using functions that work with line numbers if you are
529 working with controls that contain large amounts of text.
531 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
533 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
535 Returns the string containing the text staring in the positions {\it from} and
536 up to {\it to} in the control. The positions must have been returned by another
539 Please note that the positions in a multiline wxTextCtrl do {\bf not}
540 correspond to the indices in the string returned by
541 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
542 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
543 obtain the correct results instead of extracting parts of the entire value. It
544 may also be more efficient, especially if the control contains a lot of data.
546 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
548 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
550 Gets the current selection span. If the returned values are equal, there was
553 Please note that the indices returned may be used with the other wxTextctrl
554 methods but don't necessarily represent the correct indices into the string
555 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
556 under Windows (at least,) you should use
557 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
560 \wxheading{Parameters}
562 \docparam{from}{The returned first position.}
564 \docparam{to}{The returned last position.}
566 \pythonnote{The wxPython version of this method returns a tuple
567 consisting of the from and to values.}
569 \perlnote{In wxPerl this method takes no parameter and returns a
570 2-element list {\tt ( from, to )}.}
572 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
574 \func{virtual wxString}{GetStringSelection}{\void}
576 Gets the text currently selected in the control. If there is no selection, the
577 returned string is empty.
579 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
581 \constfunc{wxString}{GetValue}{\void}
583 Gets the contents of the control. Notice that for a multiline text control,
584 the lines will be separated by (Unix-style) $\backslash$n characters, even
585 under Windows where they are separated by a $\backslash$r$\backslash$n
586 sequence in the native control.
588 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
590 \constfunc{bool}{IsEditable}{\void}
592 Returns {\tt TRUE} if the controls contents may be edited by user (note that it
593 always can be changed by the program), i.e. if the control hasn't been put in
594 read-only mode by a previous call to
595 \helpref{SetEditable}{wxtextctrlseteditable}.
597 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
599 \constfunc{bool}{IsModified}{\void}
601 Returns {\tt TRUE} if the text has been modified by user. Note that calling
602 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
604 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
606 \constfunc{bool}{IsMultiLine}{\void}
608 Returns {\tt TRUE} if this is a multi line edit control and {\tt FALSE}
613 \helpref{IsSingleLine}{wxtextctrlissingleline}
615 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
617 \constfunc{bool}{IsSingleLine}{\void}
619 Returns {\tt TRUE} if this is a single line edit control and {\tt FALSE}
624 \helpref{IsMultiLine}{wxtextctrlissingleline}
626 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
628 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
630 Loads and displays the named file, if it exists.
632 \wxheading{Parameters}
634 \docparam{filename}{The filename of the file to load.}
636 \wxheading{Return value}
638 {\tt TRUE} if successful, {\tt FALSE} otherwise.
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}
644 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
646 %% Default handler for character input.
648 %% \wxheading{Remarks}
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.
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.
666 %% \wxheading{See also}
668 %% \helpref{wxKeyEvent}{wxkeyevent}
670 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
672 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
674 This event handler function implements default drag and drop behaviour, which
675 is to load the first dropped file into the control.
677 \wxheading{Parameters}
679 \docparam{event}{The drop files event.}
683 This is not implemented on non-Windows platforms.
687 \helpref{wxDropFilesEvent}{wxdropfilesevent}
689 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
691 \func{virtual void}{Paste}{\void}
693 Pastes text from the clipboard to the text item.
695 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
697 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
699 Converts given position to a zero-based column, line number pair.
701 \wxheading{Parameters}
703 \docparam{pos}{Position.}
705 \docparam{x}{Receives zero based column number.}
707 \docparam{y}{Receives zero based line number.}
709 \wxheading{Return value}
711 {\tt TRUE} on success, {\tt FALSE} on failure (most likely due to a too large position
716 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
718 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
719 y values, so (x,y) = PositionToXY() is equivalent to the call described
722 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
723 returns a 2-element list {\tt ( x, y )}.}
725 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
727 \func{virtual void}{Redo}{\void}
729 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
730 if there is no redo facility.
732 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
734 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
736 Removes the text starting at the first given position up to (but not including)
737 the character at the last position.
739 \wxheading{Parameters}
741 \docparam{from}{The first position.}
743 \docparam{to}{The last position.}
745 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
747 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
749 Replaces the text starting at the first position up to (but not including)
750 the character at the last position with the given text.
752 \wxheading{Parameters}
754 \docparam{from}{The first position.}
756 \docparam{to}{The last position.}
758 \docparam{value}{The value to replace the existing text with.}
760 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
762 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
764 Saves the contents of the control in a text file.
766 \wxheading{Parameters}
768 \docparam{filename}{The name of the file in which to save the text.}
770 \wxheading{Return value}
772 {\tt TRUE} if the operation was successful, {\tt FALSE} otherwise.
774 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
776 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
778 Changes the default style to use for the new text which is going to be added
779 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
780 \helpref{AppendText}{wxtextctrlappendtext}.
782 If 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
784 the previous default style didn't set them neither, the global font or colours
785 of the text control itself are used as fall back.
787 However if the {\it style} parameter is the default wxTextAttr, then the
788 default style is just reset (instead of being combined with the new style which
789 wouldn't change it at all).
791 \wxheading{Parameters}
793 \docparam{style}{The style for the new text.}
795 \wxheading{Return value}
797 {\tt TRUE} on success, {\tt FALSE} if an error occured - may also mean that
798 the styles are not supported under this platform.
802 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
804 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
806 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
808 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
810 \wxheading{Parameters}
812 \docparam{editable}{If {\tt TRUE}, the control is editable. If {\tt FALSE}, the control is read-only.}
816 \helpref{IsEditable}{wxtextctrliseditable}
818 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
820 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
822 Sets the insertion point at the given position.
824 \wxheading{Parameters}
826 \docparam{pos}{Position to set.}
828 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
830 \func{virtual void}{SetInsertionPointEnd}{\void}
832 Sets the insertion point at the end of the text control. This is equivalent
833 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
835 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
837 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
839 This function sets the maximum number of characters the user can enter into the
840 control. In other words, it allows to limit the text value length to {\it len}
841 not counting the terminating {\tt NUL} character.
843 If {\it len} is $0$, the previously set max length limit, if any, is discarded
844 and the user may enter as much text as the underlying native text control
845 widget supports (typically at least 32Kb).
847 If the user tries to enter more characters into the text control when it
848 already is filled up to the maximal length, a
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
851 extra input is discarded.
853 Note that this function may only be used with single line text controls.
855 \wxheading{Compatibility}
857 Only implemented in wxMSW/wxGTK starting with wxWindows 2.3.2.
859 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
861 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
863 Selects the text starting at the first position up to (but not including) the
864 character at the last position. If both parameters are equal to $-1$ all text
865 in the control is selected.
867 \wxheading{Parameters}
869 \docparam{from}{The first position.}
871 \docparam{to}{The last position.}
873 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
875 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
877 Changes the style of the selection. If either of the font, foreground, or
878 background colour is not set in {\it style}, the values of\rtfsp
879 \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} are used.
881 \wxheading{Parameters}
883 \docparam{start}{The start of selection to change.}
885 \docparam{end}{The end of selection to change.}
887 \docparam{style}{The new style for the selection.}
889 \wxheading{Return value}
891 {\tt TRUE} on success, {\tt FALSE} if an error occured - may also mean that
892 the styles are not supported under this platform.
894 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
896 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
898 Sets the text value and marks the control as not-modified (which means that
899 \helpref{IsModified}{wxtextctrlismodified} would return {\tt FALSE} immediately
900 after the call to SetValue).
902 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
905 \wxheading{Parameters}
907 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
909 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
911 \func{void}{ShowPosition}{\param{long}{ pos}}
913 Makes the line containing the given position visible.
915 \wxheading{Parameters}
917 \docparam{pos}{The position that should be visible.}
919 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
921 \func{virtual void}{Undo}{\void}
923 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
924 if there is no undo facility.
926 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
928 \func{void}{WriteText}{\param{const wxString\& }{ text}}
930 Writes the text into the text control at the current insertion position.
932 \wxheading{Parameters}
934 \docparam{text}{Text to write to the text control.}
938 Newlines in the text string
939 are the only control characters allowed, and they will cause appropriate
940 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
942 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.
944 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
946 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
948 Converts the given zero based column and line number to a position.
950 \wxheading{Parameters}
952 \docparam{x}{The column number.}
954 \docparam{y}{The line number.}
956 \wxheading{Return value}
960 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
962 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
964 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
966 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
968 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
970 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
972 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
974 Operator definitions for appending to a text control, for example:
977 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
979 (*wnd) << "Welcome to text control number " << 1 << ".\n";