1 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextAttr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 \section{\class{wxTextAttr
}}\label{wxtextattr
}
5 wxTextAttr represents the character and paragraph attributes, or style, for a range of text in a
\rtfsp
6 \helpref{wxTextCtrl
}{wxtextctrl
}.
8 When setting up a wxTextAttr object, pass a bitlist mask to SetFlags to indicate
9 which style elements should be changed. As a convenience, when you call a
10 setter such as SetFont, the relevant bit will be set.
12 \wxheading{Derived from
}
16 \wxheading{Include files
}
22 The following values can be passed to SetAlignment to determine
27 enum wxTextAttrAlignment
29 wxTEXT_ALIGNMENT_DEFAULT,
30 wxTEXT_ALIGNMENT_LEFT,
31 wxTEXT_ALIGNMENT_CENTRE,
32 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
33 wxTEXT_ALIGNMENT_RIGHT,
34 wxTEXT_ALIGNMENT_JUSTIFIED
39 These values are passed in a bitlist to SetFlags to determine
40 what attributes will be considered when setting the attributes
45 #define wxTEXT_ATTR_TEXT_COLOUR
0x0001
46 #define wxTEXT_ATTR_BACKGROUND_COLOUR
0x0002
47 #define wxTEXT_ATTR_FONT_FACE
0x0004
48 #define wxTEXT_ATTR_FONT_SIZE
0x0008
49 #define wxTEXT_ATTR_FONT_WEIGHT
0x0010
50 #define wxTEXT_ATTR_FONT_ITALIC
0x0020
51 #define wxTEXT_ATTR_FONT_UNDERLINE
0x0040
52 #define wxTEXT_ATTR_FONT \
53 wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT \
54 | wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE
55 #define wxTEXT_ATTR_ALIGNMENT
0x0080
56 #define wxTEXT_ATTR_LEFT_INDENT
0x0100
57 #define wxTEXT_ATTR_RIGHT_INDENT
0x0200
58 #define wxTEXT_ATTR_TABS
0x0400
62 \latexignore{\rtfignore{\wxheading{Members
}}}
64 \membersection{wxTextAttr::wxTextAttr
}\label{wxtextattrctor
}
66 \func{}{wxTextAttr
}{\void}
68 \func{}{wxTextAttr
}{\param{const wxColour\&
}{colText
},
\param{const wxColour\&
}{colBack = wxNullColour
},
69 \param{const wxFont\&
}{font = wxNullFont
},
\param{wxTextAttrAlignment
}{alignment = wxTEXT
\_ALIGNMENT\_DEFAULT}}
71 The constructors initialize one or more of the text foreground colour, background
72 colour, font, and alignment. The values not initialized in the constructor can be set
73 later, otherwise
\helpref{wxTextCtrl::SetStyle
}{wxtextctrlsetstyle
} will use
74 the default values for them.
76 \membersection{wxTextAttr::GetAlignment
}\label{wxtextattrgetalignment
}
78 \constfunc{wxTextAttrAlignment
}{GetAlignment
}{\void}
80 Returns the paragraph alignment.
82 \membersection{wxTextAttr::GetBackgroundColour
}\label{wxtextattrgetbackgroundcolour
}
84 \constfunc{const wxColour\&
}{GetBackgroundColour
}{\void}
86 Return the background colour specified by this attribute.
88 \membersection{wxTextAttr::GetFont
}\label{wxtextattrgetfont
}
90 \constfunc{const wxFont\&
}{GetFont
}{\void}
92 Return the text font specified by this attribute.
94 \membersection{wxTextAttr::GetLeftIndent
}\label{wxtextattrgetleftindent
}
96 \constfunc{int
}{GetLeftIndent
}{\void}
98 Returns the left indent in tenths of a millimetre.
100 \membersection{wxTextAttr::GetRightIndent
}\label{wxtextattrgetrightindent
}
102 \constfunc{int
}{GetRightIndent
}{\void}
104 Returns the right indent in tenths of a millimetre.
106 \membersection{wxTextAttr::GetTabs
}\label{wxtextattrgettabs
}
108 \constfunc{const wxArrayInt\&
}{GetTabs
}{\void}
110 Returns the array of integers representing the tab stops. Each
111 array element specifies the tab stop in tenths of a millimetre.
113 \membersection{wxTextAttr::GetTextColour
}\label{wxtextattrgettextcolour
}
115 \constfunc{const wxColour\&
}{GetTextColour
}{\void}
117 Return the text colour specified by this attribute.
119 \membersection{wxTextAttr::HasBackgroundColour
}\label{wxtextattrhasbackgroundcolour
}
121 \constfunc{bool
}{HasBackgroundColour
}{\void}
123 Returns
{\tt true
} if this style specifies the background colour to use.
125 \membersection{wxTextAttr::HasFont
}\label{wxtextattrhasfont
}
127 \constfunc{bool
}{HasFont
}{\void}
129 Returns
{\tt true
} if this style specifies the font to use.
131 \membersection{wxTextAttr::HasTextColour
}\label{wxtextattrhastextcolour
}
133 \constfunc{bool
}{HasTextColour
}{\void}
135 Returns
{\tt true
} if this style specifies the foreground colour to use.
137 \membersection{wxTextAttr::GetFlags
}\label{wxtextattrgetflags
}
139 \func{long
}{GetFlags
}{\void}
141 Returns a bitlist indicating which attributes will be set.
143 \membersection{wxTextAttr::IsDefault
}\label{wxtextattrisdefault
}
145 \constfunc{bool
}{IsDefault
}{\void}
147 Returns
{\tt true
} if this style specifies any non-default attributes.
149 \membersection{wxTextAttr::SetAlignment
}\label{wxtextattrsetalignment
}
151 \func{void
}{SetAlignment
}{\param{wxTextAttrAlignment
}{ alignment
}}
153 Sets the paragraph alignment.
155 \membersection{wxTextAttr::SetBackgroundColour
}\label{wxtextattrsetbackgroundcolour
}
157 \func{void
}{SetBackgroundColour
}{\param{const wxColour\&
}{colour
}}
159 Sets the background colour.
161 \membersection{wxTextAttr::SetFlags
}\label{wxtextattrsetflags
}
163 \func{void
}{SetFlags
}{\param{long
}{ flags
}}
165 Pass a bitlist indicating which attributes will be set.
167 \membersection{wxTextAttr::SetFont
}\label{wxtextattrsetfont
}
169 \func{void
}{SetFont
}{\param{const wxFont\&
}{ font
}}
173 \membersection{wxTextAttr::SetLeftIndent
}\label{wxtextattrsetleftindent
}
175 \func{void
}{SetLeftIndent
}{\param{int
}{indent
}}
177 Sets the left indent in tenths of a millimetre.
179 \membersection{wxTextAttr::SetRightIndent
}\label{wxtextattrsetrightindent
}
181 \func{void
}{SetRightIndent
}{\param{int
}{indent
}}
183 Sets the right indent in tenths of a millimetre.
185 \membersection{wxTextAttr::SetTabs
}\label{wxtextattrsettabs
}
187 \func{void
}{SetTabs
}{\param{const wxArrayInt\&
}{ tabs
}}
189 Sets the array of integers representing the tab stops. Each
190 array element specifies the tab stop in tenths of a millimetre.
192 \membersection{wxTextAttr::SetTextColour
}\label{wxtextattrsettextcolour
}
194 \func{void
}{SetTextColour
}{\param{const wxColour\&
}{colour
}}
196 Sets the text colour.
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
203 A text control allows text to be displayed and edited. It may be
204 single line or multi-line.
206 \wxheading{Derived from
}
209 \helpref{wxControl
}{wxcontrol
}\\
210 \helpref{wxWindow
}{wxwindow
}\\
211 \helpref{wxEvtHandler
}{wxevthandler
}\\
212 \helpref{wxObject
}{wxobject
}
214 \wxheading{Include files
}
218 \wxheading{Window styles
}
221 \begin{twocollist
}\itemsep=
0pt
222 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
223 the message wxEVENT
\_TYPE\_TEXT\_ENTER\_COMMAND (otherwise pressing Enter key
224 is either processed internally by the control or used for navigation between
226 \twocolitem{\windowstyle{wxTE
\_PROCESS\_TAB}}{The control will receive
227 EVT
\_CHAR messages for TAB pressed - normally, TAB is used for passing to the
228 next control in a dialog instead. For the control created with this style,
229 you can still use Ctrl-Enter to pass to the next control from the keyboard.
}
230 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
231 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
232 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
233 \twocolitem{\windowstyle{wxTE
\_RICH}}{Use rich text control under Win32, this
234 allows to have more than
64Kb of text in the control even under Win9x. This
235 style is ignored under other platforms.
}
236 \twocolitem{\windowstyle{wxTE
\_RICH2}}{Use rich text control version
2.0 or
3.0
237 under Win32, this style is ignored under other platforms
}
238 \twocolitem{\windowstyle{wxTE
\_AUTO\_URL}}{Highlight the URLs and generate the
239 wxTextUrlEvents when mouse events occur over them. This style is supported
240 under Win32 only and requires wxTE
\_RICH.
}
241 \twocolitem{\windowstyle{wxTE
\_NOHIDESEL}}{By default, the Windows text control
242 doesn't show the selection when it doesn't have focus - use this style to force
243 it to always show it. It doesn't do anything under other platforms.
}
244 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created and
245 used, so that text won't be wrapped. No effect under GTK+.
}
246 \twocolitem{\windowstyle{wxTE
\_LEFT}}{The text in the control will be left-justified (default).
}
247 \twocolitem{\windowstyle{wxTE
\_CENTRE}}{The text in the control will be centered.
}
248 \twocolitem{\windowstyle{wxTE
\_RIGHT}}{The text in the control will be right-justified.
}
249 \twocolitem{\windowstyle{wxTE
\_DONTWRAP}}{Same as
{\tt wxHSCROLL
} style.
}
250 \twocolitem{\windowstyle{wxTE
\_LINEWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv only currently).
}
251 \twocolitem{\windowstyle{wxTE
\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries only (wxUniv only currently).
}
254 See also
\helpref{window styles overview
}{windowstyles
} and
255 \helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlconstr
}.
257 \wxheading{wxTextCtrl text format
}
259 The multiline text controls always store the text as a sequence of lines
260 separated by
{\tt $
\backslash$n
} characters, i.e. in the Unix text format even
261 on non-Unix platforms. This allows the user code to ignore the differences
262 between the platforms but at a price: the indices in the control such as those
263 returned by
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} or
264 \helpref{GetSelection
}{wxtextctrlgetselection
} can
{\bf not
} be used as
265 indices into the string returned by
\helpref{GetValue
}{wxtextctrlgetvalue
} as
266 they're going to be slightly off for platforms using
267 {\tt $
\backslash$r$
\backslash$n
} as separator (as Windows does), for example.
269 Instead, if you need to obtain a substring between the $
2$ indices obtained
270 from the control with the help of the functions mentioned above, you should
271 use
\helpref{GetRange
}{wxtextctrlgetrange
}. And the indices themselves can
272 only be passed to other methods, for example
273 \helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
} or
274 \helpref{SetSelection
}{wxtextctrlsetselection
}.
276 To summarize: never use the indices returned by (multiline) wxTextCtrl as
277 indices into the string it contains, but only as arguments to be passed back
278 to the other wxTextCtrl methods.
280 \wxheading{wxTextCtrl styles
}
282 Multi-line text controls support the styles, i.e. provide a possibility to set
283 colours and font for individual characters in it (note that under Windows
{\tt
284 wxTE
\_RICH} style is required for style support). To use the styles you can
285 either call
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} before
286 inserting the text or call
\helpref{SetStyle
}{wxtextctrlsetstyle
} later to
287 change the style of the text already in the control (the first solution is
288 much more efficient).
290 In either case, if the style doesn't specify some of the attributes (for
291 example you only want to set the text colour but without changing the font nor
292 the text background), the values of the default style will be used for them.
293 If there is no default style, the attributes of the text control itself are
296 So the following code correctly describes what it does: the second call
297 to
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} doesn't change the
298 text foreground colour (which stays red) while the last one doesn't change the
299 background colour (which stays grey):
303 text->SetDefaultStyle(wxTextAttr
(*wxRED));
304 text->AppendText("Red text\n");
305 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
306 text->AppendText("Red on grey text\n");
307 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
308 text->AppendText("Blue on grey text\n");
312 \wxheading{wxTextCtrl and C++ streams}
314 This class multiply-inherits from {\bf streambuf} where compilers allow,
315 allowing code such as the following:
319 wxTextCtrl *control = new wxTextCtrl(...);
321 ostream stream(control)
323 stream << 123.456 << " some text\n";
328 If your compiler does not support derivation from {\bf streambuf} and gives a
329 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
330 wxTextCtrl header file.
332 Note that independently of this setting you can always use wxTextCtrl itself
333 in a stream-like manner:
337 wxTextCtrl *control = new wxTextCtrl(...);
339 *control << 123.456 << " some text\n";
343 always works. However the possibility to create an ostream associated with
344 wxTextCtrl may be useful if you need to redirect the output of a function
345 taking an ostream as parameter to a text control.
347 Another commonly requested need is to redirect {\bf std::cout} to the text
348 control. This could be done in the following way:
354 wxTextCtrl *control = new wxTextCtrl(...);
356 std::streambuf *sbOld = std::cout.rdbuf();
357 std::cout.rdbuf(*control);
359 // use cout as usual, the output appears in the text control
362 std::cout.rdbuf(sbOld);
366 But wxWindows provides a convenient class to make it even simpler so instead
373 wxTextCtrl *control = new wxTextCtrl(...);
375 wxStreamToTextRedirector redirect(control);
377 // all output to cout goes into the text control until the exit from current
382 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
385 \wxheading{Event handling}
387 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
388 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
389 automatically, when the control has the focus.
391 To process input from a text control, use these event handler macros to direct input to member
392 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
395 \begin{twocollist}\itemsep=0pt
396 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
397 generated when the text changes. Notice that this event will always be sent
398 when the text controls contents changes - whether this is due to user input or
399 comes from the program itself (for example, if SetValue() is called)}
400 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
401 generated when enter is pressed in a text control (which must have
402 wxTE\_PROCESS\_ENTER style for this event to be generated).}
403 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occured over an URL
404 in the text control (Win32 only)}
405 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
406 into the control than the limit set by
407 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
410 \latexignore{\rtfignore{\wxheading{Members}}}
412 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlconstr}
414 \func{}{wxTextCtrl}{\void}
418 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
419 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
420 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
422 Constructor, creating and showing a text control.
424 \wxheading{Parameters}
426 \docparam{parent}{Parent window. Should not be NULL.}
428 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
430 \docparam{value}{Default text value.}
432 \docparam{pos}{Text control position.}
434 \docparam{size}{Text control size.}
436 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
438 \docparam{validator}{Window validator.}
440 \docparam{name}{Window name.}
444 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
445 for multi-line text controls.
446 Without a horizontal scrollbar, text lines that don't fit in the control's
447 size will be wrapped (but no newline character is inserted). Single line
448 controls don't have a horizontal scrollbar, the text is automatically scrolled
449 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
452 % VZ: this is no longer true
453 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
454 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
459 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
461 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}
463 \func{}{\destruct{wxTextCtrl}}{\void}
465 Destructor, destroying the text control.
467 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
469 \func{void}{AppendText}{\param{const wxString\& }{ text}}
471 Appends the text to the end of the text control.
473 \wxheading{Parameters}
475 \docparam{text}{Text to write to the text control.}
479 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
480 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
484 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
486 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
488 \func{virtual bool}{CanCopy}{\void}
490 Returns {\tt true} if the selection can be copied to the clipboard.
492 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
494 \func{virtual bool}{CanCut}{\void}
496 Returns {\tt true} if the selection can be cut to the clipboard.
498 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
500 \func{virtual bool}{CanPaste}{\void}
502 Returns {\tt true} if the contents of the clipboard can be pasted into the
503 text control. On some platforms (Motif, GTK) this is an approximation
504 and returns {\tt true} if the control is editable, {\tt false} otherwise.
506 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
508 \func{virtual bool}{CanRedo}{\void}
510 Returns {\tt true} if there is a redo facility available and the last operation
513 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
515 \func{virtual bool}{CanUndo}{\void}
517 Returns {\tt true} if there is an undo facility available and the last operation
520 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
522 \func{virtual void}{Clear}{\void}
524 Clears the text in the control.
526 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
529 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
531 \func{virtual void}{Copy}{\void}
533 Copies the selected text to the clipboard under Motif and MS Windows.
535 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
537 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
538 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
539 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
541 Creates the text control for two-step construction. Derived classes
542 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlconstr}\rtfsp
545 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
547 \func{virtual void}{Cut}{\void}
549 Copies the selected text to the clipboard and removes the selection.
551 \membersection{wxTextCtrl::DiscardEdits}
553 \func{void}{DiscardEdits}{\void}
555 Resets the internal `modified' flag as if the current edits had been saved.
557 \membersection{wxTextCtrl::EmulateKeyPress}
559 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
561 This functions inserts into the control the character which would have been
562 inserted if the given key event had occured in the text control. The
563 {\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
564 handler previously by wxWindows.
566 Please note that this function doesn't currently work correctly for all keys
567 under any platform but MSW.
569 \wxheading{Return value}
571 {\tt true} if the event resulted in a change to the control, {\tt false}
574 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
576 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
578 Returns the style currently used for the new text.
582 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
584 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
586 \constfunc{virtual long}{GetInsertionPoint}{\void}
588 Returns the insertion point. This is defined as the zero based index of the
589 character position to the right of the insertion point. For example, if
590 the insertion point is at the end of the text control, it is equal to
591 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
592 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
594 The following code snippet safely returns the character at the insertion
595 point or the zero character if the point is at the end of the control.
599 char GetCurrentChar(wxTextCtrl *tc) {
600 if (tc->GetInsertionPoint() == tc->GetLastPosition())
602 return tc->GetValue[tc->GetInsertionPoint()];
607 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
609 \constfunc{virtual long}{GetLastPosition}{\void}
611 Returns the zero based index of the last position in the text control,
612 which is equal to the number of characters in the control.
614 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
616 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
618 Gets the length of the specified line, not including any trailing newline
621 \wxheading{Parameters}
623 \docparam{lineNo}{Line number (starting from zero).}
625 \wxheading{Return value}
627 The length of the line, or -1 if {\it lineNo} was invalid.
629 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
631 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
633 Returns the contents of a given line in the text control, not including
634 any trailing newline character(s).
636 \wxheading{Parameters}
638 \docparam{lineNo}{The line number, starting from zero.}
640 \wxheading{Return value}
642 The contents of the line.
644 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
646 \constfunc{int}{GetNumberOfLines}{\void}
648 Returns the number of lines in the text control buffer.
652 Note that even empty text controls have one line (where the insertion point
653 is), so GetNumberOfLines() never returns 0.
655 For gtk\_text (multi-line) controls, the number of lines is
656 calculated by actually counting newline characters in the buffer. You
657 may wish to avoid using functions that work with line numbers if you are
658 working with controls that contain large amounts of text.
660 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
662 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
664 Returns the string containing the text staring in the positions {\it from} and
665 up to {\it to} in the control. The positions must have been returned by another
668 Please note that the positions in a multiline wxTextCtrl do {\bf not}
669 correspond to the indices in the string returned by
670 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
671 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
672 obtain the correct results instead of extracting parts of the entire value. It
673 may also be more efficient, especially if the control contains a lot of data.
675 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
677 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
679 Gets the current selection span. If the returned values are equal, there was
682 Please note that the indices returned may be used with the other wxTextctrl
683 methods but don't necessarily represent the correct indices into the string
684 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
685 under Windows (at least,) you should use
686 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
689 \wxheading{Parameters}
691 \docparam{from}{The returned first position.}
693 \docparam{to}{The returned last position.}
695 \pythonnote{The wxPython version of this method returns a tuple
696 consisting of the from and to values.}
698 \perlnote{In wxPerl this method takes no parameter and returns a
699 2-element list {\tt ( from, to )}.}
701 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
703 \func{virtual wxString}{GetStringSelection}{\void}
705 Gets the text currently selected in the control. If there is no selection, the
706 returned string is empty.
708 \membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
710 \func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
712 Returns the style at this position in the text control. Not all platforms
713 support this function.
715 \wxheading{Return value}
717 {\tt true} on success, {\tt false} if an error occured - it may also mean that
718 the styles are not supported under this platform.
722 \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
724 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
726 \constfunc{wxString}{GetValue}{\void}
728 Gets the contents of the control. Notice that for a multiline text control,
729 the lines will be separated by (Unix-style) $\backslash$n characters, even
730 under Windows where they are separated by a $\backslash$r$\backslash$n
731 sequence in the native control.
733 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
735 \constfunc{bool}{IsEditable}{\void}
737 Returns {\tt true} if the controls contents may be edited by user (note that it
738 always can be changed by the program), i.e. if the control hasn't been put in
739 read-only mode by a previous call to
740 \helpref{SetEditable}{wxtextctrlseteditable}.
742 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
744 \constfunc{bool}{IsModified}{\void}
746 Returns {\tt true} if the text has been modified by user. Note that calling
747 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
749 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
751 \constfunc{bool}{IsMultiLine}{\void}
753 Returns {\tt true} if this is a multi line edit control and {\tt false}
758 \helpref{IsSingleLine}{wxtextctrlissingleline}
760 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
762 \constfunc{bool}{IsSingleLine}{\void}
764 Returns {\tt true} if this is a single line edit control and {\tt false}
769 \helpref{IsMultiLine}{wxtextctrlissingleline}
771 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
773 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
775 Loads and displays the named file, if it exists.
777 \wxheading{Parameters}
779 \docparam{filename}{The filename of the file to load.}
781 \wxheading{Return value}
783 {\tt true} if successful, {\tt false} otherwise.
785 % VZ: commenting this out as: (a) the docs are wrong (you can't replace
786 % anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
787 %% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
789 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
791 %% Default handler for character input.
793 %% \wxheading{Remarks}
795 %% It is possible to intercept character
796 %% input by overriding this member. Call this function
797 %% to let the default behaviour take place; not calling
798 %% it results in the character being ignored. You can
799 %% replace the {\it keyCode} member of {\it event} to
800 %% translate keystrokes.
802 %% Note that Windows and Motif have different ways
803 %% of implementing the default behaviour. In Windows,
804 %% calling wxTextCtrl::OnChar immediately
805 %% processes the character. In Motif,
806 %% calling this function simply sets a flag
807 %% to let default processing happen. This might affect
808 %% the way in which you write your OnChar function
809 %% on different platforms.
811 %% \wxheading{See also}
813 %% \helpref{wxKeyEvent}{wxkeyevent}
815 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
817 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
819 This event handler function implements default drag and drop behaviour, which
820 is to load the first dropped file into the control.
822 \wxheading{Parameters}
824 \docparam{event}{The drop files event.}
828 This is not implemented on non-Windows platforms.
832 \helpref{wxDropFilesEvent}{wxdropfilesevent}
834 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
836 \func{virtual void}{Paste}{\void}
838 Pastes text from the clipboard to the text item.
840 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
842 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
844 Converts given position to a zero-based column, line number pair.
846 \wxheading{Parameters}
848 \docparam{pos}{Position.}
850 \docparam{x}{Receives zero based column number.}
852 \docparam{y}{Receives zero based line number.}
854 \wxheading{Return value}
856 {\tt true} on success, {\tt false} on failure (most likely due to a too large position
861 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
863 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
864 y values, so (x,y) = PositionToXY() is equivalent to the call described
867 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
868 returns a 2-element list {\tt ( x, y )}.}
870 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
872 \func{virtual void}{Redo}{\void}
874 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
875 if there is no redo facility.
877 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
879 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
881 Removes the text starting at the first given position up to (but not including)
882 the character at the last position.
884 \wxheading{Parameters}
886 \docparam{from}{The first position.}
888 \docparam{to}{The last position.}
890 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
892 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
894 Replaces the text starting at the first position up to (but not including)
895 the character at the last position with the given text.
897 \wxheading{Parameters}
899 \docparam{from}{The first position.}
901 \docparam{to}{The last position.}
903 \docparam{value}{The value to replace the existing text with.}
905 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
907 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
909 Saves the contents of the control in a text file.
911 \wxheading{Parameters}
913 \docparam{filename}{The name of the file in which to save the text.}
915 \wxheading{Return value}
917 {\tt true} if the operation was successful, {\tt false} otherwise.
919 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
921 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
923 Changes the default style to use for the new text which is going to be added
924 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
925 \helpref{AppendText}{wxtextctrlappendtext}.
927 If either of the font, foreground, or background colour is not set in\rtfsp
928 {\it style}, the values of the previous default style are used for them. If
929 the previous default style didn't set them neither, the global font or colours
930 of the text control itself are used as fall back.
932 However if the {\it style} parameter is the default wxTextAttr, then the
933 default style is just reset (instead of being combined with the new style which
934 wouldn't change it at all).
936 \wxheading{Parameters}
938 \docparam{style}{The style for the new text.}
940 \wxheading{Return value}
942 {\tt true} on success, {\tt false} if an error occured - may also mean that
943 the styles are not supported under this platform.
947 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
949 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
951 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
953 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
955 \wxheading{Parameters}
957 \docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
961 \helpref{IsEditable}{wxtextctrliseditable}
963 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
965 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
967 Sets the insertion point at the given position.
969 \wxheading{Parameters}
971 \docparam{pos}{Position to set.}
973 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
975 \func{virtual void}{SetInsertionPointEnd}{\void}
977 Sets the insertion point at the end of the text control. This is equivalent
978 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
980 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
982 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
984 This function sets the maximum number of characters the user can enter into the
985 control. In other words, it allows to limit the text value length to {\it len}
986 not counting the terminating {\tt NUL} character.
988 If {\it len} is $0$, the previously set max length limit, if any, is discarded
989 and the user may enter as much text as the underlying native text control
990 widget supports (typically at least 32Kb).
992 If the user tries to enter more characters into the text control when it
993 already is filled up to the maximal length, a
994 {\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
995 (giving it the possibility to show an explanatory message, for example) and the
996 extra input is discarded.
998 Note that this function may only be used with single line text controls.
1000 \wxheading{Compatibility}
1002 Only implemented in wxMSW/wxGTK starting with wxWindows 2.3.2.
1004 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
1006 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
1008 Selects the text starting at the first position up to (but not including) the
1009 character at the last position. If both parameters are equal to $-1$ all text
1010 in the control is selected.
1012 \wxheading{Parameters}
1014 \docparam{from}{The first position.}
1016 \docparam{to}{The last position.}
1018 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
1020 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
1022 Changes the style of the given range. If any attribute within {\it style} is
1023 not set, the correspondign attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
1025 \wxheading{Parameters}
1027 \docparam{start}{The start of the range to change.}
1029 \docparam{end}{The end of the range to change.}
1031 \docparam{style}{The new style for the range.}
1033 \wxheading{Return value}
1035 {\tt true} on success, {\tt false} if an error occured - it may also mean that
1036 the styles are not supported under this platform.
1038 \wxheading{See also}
1040 \helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
1042 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
1044 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
1046 Sets the text value and marks the control as not-modified (which means that
1047 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
1048 after the call to SetValue).
1050 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
1053 \wxheading{Parameters}
1055 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
1057 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
1059 \func{void}{ShowPosition}{\param{long}{ pos}}
1061 Makes the line containing the given position visible.
1063 \wxheading{Parameters}
1065 \docparam{pos}{The position that should be visible.}
1067 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
1069 \func{virtual void}{Undo}{\void}
1071 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
1072 if there is no undo facility.
1074 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1076 \func{void}{WriteText}{\param{const wxString\& }{ text}}
1078 Writes the text into the text control at the current insertion position.
1080 \wxheading{Parameters}
1082 \docparam{text}{Text to write to the text control.}
1086 Newlines in the text string
1087 are the only control characters allowed, and they will cause appropriate
1088 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
1090 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.
1092 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1094 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
1096 Converts the given zero based column and line number to a position.
1098 \wxheading{Parameters}
1100 \docparam{x}{The column number.}
1102 \docparam{y}{The line number.}
1104 \wxheading{Return value}
1108 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1110 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1112 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1114 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1116 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1118 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1120 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1122 Operator definitions for appending to a text control, for example:
1125 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1127 (*wnd) << "Welcome to text control number " << 1 << ".\n";