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 \texttt{wxTextPos
} is the type containing the index of a position in a text
23 control.
\texttt{wxTextCoord
} contains the index of a column or a row in the
26 Note that although both of these types should probably have been unsigned, due
27 to backwards compatibility reasons, are defined as
\texttt{long
} currently.
28 Their use (instead of plain
\texttt{long
}) is still encouraged as it makes the
33 The following values can be passed to SetAlignment to determine
38 enum wxTextAttrAlignment
40 wxTEXT_ALIGNMENT_DEFAULT,
41 wxTEXT_ALIGNMENT_LEFT,
42 wxTEXT_ALIGNMENT_CENTRE,
43 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
44 wxTEXT_ALIGNMENT_RIGHT,
45 wxTEXT_ALIGNMENT_JUSTIFIED
50 These values are passed in a bitlist to SetFlags to determine
51 what attributes will be considered when setting the attributes
56 #define wxTEXT_ATTR_TEXT_COLOUR
0x0001
57 #define wxTEXT_ATTR_BACKGROUND_COLOUR
0x0002
58 #define wxTEXT_ATTR_FONT_FACE
0x0004
59 #define wxTEXT_ATTR_FONT_SIZE
0x0008
60 #define wxTEXT_ATTR_FONT_WEIGHT
0x0010
61 #define wxTEXT_ATTR_FONT_ITALIC
0x0020
62 #define wxTEXT_ATTR_FONT_UNDERLINE
0x0040
63 #define wxTEXT_ATTR_FONT \
64 wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT \
65 | wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE
66 #define wxTEXT_ATTR_ALIGNMENT
0x0080
67 #define wxTEXT_ATTR_LEFT_INDENT
0x0100
68 #define wxTEXT_ATTR_RIGHT_INDENT
0x0200
69 #define wxTEXT_ATTR_TABS
0x0400
73 The values below are the possible return codes of the
74 \helpref{HitTest
}{wxtextctrlhittest
} method:
77 // the point asked is ...
78 enum wxTextCtrlHitTestResult
80 wxTE_HT_UNKNOWN = -
2, // this means HitTest() is simply not implemented
81 wxTE_HT_BEFORE, // either to the left or upper
82 wxTE_HT_ON_TEXT, // directly on
83 wxTE_HT_BELOW, // below
[the last line
]
84 wxTE_HT_BEYOND // after
[the end of line
]
86 // ... the character returned
91 \latexignore{\rtfignore{\wxheading{Members
}}}
94 \membersection{wxTextAttr::wxTextAttr
}\label{wxtextattrctor
}
96 \func{}{wxTextAttr
}{\void}
98 \func{}{wxTextAttr
}{\param{const wxColour\&
}{colText
},
\param{const wxColour\&
}{colBack = wxNullColour
},
99 \param{const wxFont\&
}{font = wxNullFont
},
\param{wxTextAttrAlignment
}{alignment = wxTEXT
\_ALIGNMENT\_DEFAULT}}
101 The constructors initialize one or more of the text foreground colour, background
102 colour, font, and alignment. The values not initialized in the constructor can be set
103 later, otherwise
\helpref{wxTextCtrl::SetStyle
}{wxtextctrlsetstyle
} will use
104 the default values for them.
107 \membersection{wxTextAttr::GetAlignment
}\label{wxtextattrgetalignment
}
109 \constfunc{wxTextAttrAlignment
}{GetAlignment
}{\void}
111 Returns the paragraph alignment.
114 \membersection{wxTextAttr::GetBackgroundColour
}\label{wxtextattrgetbackgroundcolour
}
116 \constfunc{const wxColour\&
}{GetBackgroundColour
}{\void}
118 Return the background colour specified by this attribute.
121 \membersection{wxTextAttr::GetFont
}\label{wxtextattrgetfont
}
123 \constfunc{const wxFont\&
}{GetFont
}{\void}
125 Return the text font specified by this attribute.
128 \membersection{wxTextAttr::GetLeftIndent
}\label{wxtextattrgetleftindent
}
130 \constfunc{int
}{GetLeftIndent
}{\void}
132 Returns the left indent in tenths of a millimetre.
135 \membersection{wxTextAttr::GetLeftSubIndent
}\label{wxtextattrgetleftsubindent
}
137 \constfunc{int
}{GetLeftSubIndent
}{\void}
139 Returns the left sub indent for all lines but the first line in a paragraph in
140 tenths of a millimetre.
143 \membersection{wxTextAttr::GetRightIndent
}\label{wxtextattrgetrightindent
}
145 \constfunc{int
}{GetRightIndent
}{\void}
147 Returns the right indent in tenths of a millimetre.
150 \membersection{wxTextAttr::GetTabs
}\label{wxtextattrgettabs
}
152 \constfunc{const wxArrayInt\&
}{GetTabs
}{\void}
154 Returns the array of integers representing the tab stops. Each
155 array element specifies the tab stop in tenths of a millimetre.
158 \membersection{wxTextAttr::GetTextColour
}\label{wxtextattrgettextcolour
}
160 \constfunc{const wxColour\&
}{GetTextColour
}{\void}
162 Return the text colour specified by this attribute.
165 \membersection{wxTextAttr::HasBackgroundColour
}\label{wxtextattrhasbackgroundcolour
}
167 \constfunc{bool
}{HasBackgroundColour
}{\void}
169 Returns
{\tt true
} if this style specifies the background colour to use.
172 \membersection{wxTextAttr::HasFont
}\label{wxtextattrhasfont
}
174 \constfunc{bool
}{HasFont
}{\void}
176 Returns
{\tt true
} if this style specifies the font to use.
179 \membersection{wxTextAttr::HasTextColour
}\label{wxtextattrhastextcolour
}
181 \constfunc{bool
}{HasTextColour
}{\void}
183 Returns
{\tt true
} if this style specifies the foreground colour to use.
186 \membersection{wxTextAttr::GetFlags
}\label{wxtextattrgetflags
}
188 \func{long
}{GetFlags
}{\void}
190 Returns a bitlist indicating which attributes will be set.
193 \membersection{wxTextAttr::IsDefault
}\label{wxtextattrisdefault
}
195 \constfunc{bool
}{IsDefault
}{\void}
197 Returns
{\tt true
} if this style specifies any non-default attributes.
200 \membersection{wxTextAttr::SetAlignment
}\label{wxtextattrsetalignment
}
202 \func{void
}{SetAlignment
}{\param{wxTextAttrAlignment
}{ alignment
}}
204 Sets the paragraph alignment.
207 \membersection{wxTextAttr::SetBackgroundColour
}\label{wxtextattrsetbackgroundcolour
}
209 \func{void
}{SetBackgroundColour
}{\param{const wxColour\&
}{colour
}}
211 Sets the background colour.
214 \membersection{wxTextAttr::SetFlags
}\label{wxtextattrsetflags
}
216 \func{void
}{SetFlags
}{\param{long
}{ flags
}}
218 Pass a bitlist indicating which attributes will be set.
221 \membersection{wxTextAttr::SetFont
}\label{wxtextattrsetfont
}
223 \func{void
}{SetFont
}{\param{const wxFont\&
}{ font
}}
228 \membersection{wxTextAttr::SetLeftIndent
}\label{wxtextattrsetleftindent
}
230 \func{void
}{SetLeftIndent
}{\param{int
}{indent
},
\param{int
}{subIndent =
0}}
232 Sets the left indent in tenths of a millimetre.
233 subIndent sets the indent for all lines but the first line in a paragraph
234 relative to the first line.
237 \membersection{wxTextAttr::SetRightIndent
}\label{wxtextattrsetrightindent
}
239 \func{void
}{SetRightIndent
}{\param{int
}{indent
}}
241 Sets the right indent in tenths of a millimetre.
244 \membersection{wxTextAttr::SetTabs
}\label{wxtextattrsettabs
}
246 \func{void
}{SetTabs
}{\param{const wxArrayInt\&
}{ tabs
}}
248 Sets the array of integers representing the tab stops. Each
249 array element specifies the tab stop in tenths of a millimetre.
252 \membersection{wxTextAttr::SetTextColour
}\label{wxtextattrsettextcolour
}
254 \func{void
}{SetTextColour
}{\param{const wxColour\&
}{colour
}}
256 Sets the text colour.
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
263 A text control allows text to be displayed and edited. It may be
264 single line or multi-line.
266 \wxheading{Derived from
}
269 \helpref{wxControl
}{wxcontrol
}\\
270 \helpref{wxWindow
}{wxwindow
}\\
271 \helpref{wxEvtHandler
}{wxevthandler
}\\
272 \helpref{wxObject
}{wxobject
}
274 \wxheading{Include files
}
278 \wxheading{Window styles
}
281 \begin{twocollist
}\itemsep=
0pt
282 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
283 the event wxEVT
\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
284 is either processed internally by the control or used for navigation between
286 \twocolitem{\windowstyle{wxTE
\_PROCESS\_TAB}}{The control will receive
287 wxEVT
\_CHAR events for TAB pressed - normally, TAB is used for passing to the
288 next control in a dialog instead. For the control created with this style,
289 you can still use Ctrl-Enter to pass to the next control from the keyboard.
}
290 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
291 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
292 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
293 \twocolitem{\windowstyle{wxTE
\_RICH}}{Use rich text control under Win32, this
294 allows to have more than
64KB of text in the control even under Win9x. This
295 style is ignored under other platforms.
}
296 \twocolitem{\windowstyle{wxTE
\_RICH2}}{Use rich text control version
2.0 or
3.0
297 under Win32, this style is ignored under other platforms
}
298 \twocolitem{\windowstyle{wxTE
\_AUTO\_URL}}{Highlight the URLs and generate the
299 wxTextUrlEvents when mouse events occur over them. This style is supported
300 under Win32 only and requires wxTE
\_RICH.
}
301 \twocolitem{\windowstyle{wxTE
\_NOHIDESEL}}{By default, the Windows text control
302 doesn't show the selection when it doesn't have focus - use this style to force
303 it to always show it. It doesn't do anything under other platforms.
}
304 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created and
305 used, so that text won't be wrapped. No effect under wxGTK1.
}
306 \twocolitem{\windowstyle{wxTE
\_LEFT}}{The text in the control will be left-justified (default).
}
307 \twocolitem{\windowstyle{wxTE
\_CENTRE}}{The text in the control will be centered (currently wxMSW and wxGTK2 only).
}
308 \twocolitem{\windowstyle{wxTE
\_RIGHT}}{The text in the control will be right-justified (currently wxMSW and wxGTK2 only).
}
309 \twocolitem{\windowstyle{wxTE
\_DONTWRAP}}{Same as
{\tt wxHSCROLL
} style.
}
310 \twocolitem{\windowstyle{wxTE
\_LINEWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv only currently).
}
311 \twocolitem{\windowstyle{wxTE
\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries only (wxUniv only currently).
}
314 See also
\helpref{window styles overview
}{windowstyles
} and
315 \helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlctor
}.
317 \wxheading{wxTextCtrl text format
}
319 The multiline text controls always store the text as a sequence of lines
320 separated by
{\tt $
\backslash$n
} characters, i.e. in the Unix text format even
321 on non-Unix platforms. This allows the user code to ignore the differences
322 between the platforms but at a price: the indices in the control such as those
323 returned by
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} or
324 \helpref{GetSelection
}{wxtextctrlgetselection
} can
{\bf not
} be used as
325 indices into the string returned by
\helpref{GetValue
}{wxtextctrlgetvalue
} as
326 they're going to be slightly off for platforms using
327 {\tt $
\backslash$r$
\backslash$n
} as separator (as Windows does), for example.
329 Instead, if you need to obtain a substring between the $
2$ indices obtained
330 from the control with the help of the functions mentioned above, you should
331 use
\helpref{GetRange
}{wxtextctrlgetrange
}. And the indices themselves can
332 only be passed to other methods, for example
333 \helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
} or
334 \helpref{SetSelection
}{wxtextctrlsetselection
}.
336 To summarize: never use the indices returned by (multiline) wxTextCtrl as
337 indices into the string it contains, but only as arguments to be passed back
338 to the other wxTextCtrl methods.
340 \wxheading{wxTextCtrl styles
}
342 Multi-line text controls support the styles, i.e. provide a possibility to set
343 colours and font for individual characters in it (note that under Windows
{\tt
344 wxTE
\_RICH} style is required for style support). To use the styles you can
345 either call
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} before
346 inserting the text or call
\helpref{SetStyle
}{wxtextctrlsetstyle
} later to
347 change the style of the text already in the control (the first solution is
348 much more efficient).
350 In either case, if the style doesn't specify some of the attributes (for
351 example you only want to set the text colour but without changing the font nor
352 the text background), the values of the default style will be used for them.
353 If there is no default style, the attributes of the text control itself are
356 So the following code correctly describes what it does: the second call
357 to
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} doesn't change the
358 text foreground colour (which stays red) while the last one doesn't change the
359 background colour (which stays grey):
363 text->SetDefaultStyle(wxTextAttr
(*wxRED));
364 text->AppendText("Red text\n");
365 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
366 text->AppendText("Red on grey text\n");
367 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
368 text->AppendText("Blue on grey text\n");
372 \wxheading{wxTextCtrl and C++ streams}
374 This class multiply-inherits from {\bf streambuf} where compilers allow,
375 allowing code such as the following:
379 wxTextCtrl *control = new wxTextCtrl(...);
381 ostream stream(control)
383 stream << 123.456 << " some text\n";
388 If your compiler does not support derivation from {\bf streambuf} and gives a
389 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
390 wxTextCtrl header file.
392 Note that independently of this setting you can always use wxTextCtrl itself
393 in a stream-like manner:
397 wxTextCtrl *control = new wxTextCtrl(...);
399 *control << 123.456 << " some text\n";
403 always works. However the possibility to create an ostream associated with
404 wxTextCtrl may be useful if you need to redirect the output of a function
405 taking an ostream as parameter to a text control.
407 Another commonly requested need is to redirect {\bf std::cout} to the text
408 control. This could be done in the following way:
414 wxTextCtrl *control = new wxTextCtrl(...);
416 std::streambuf *sbOld = std::cout.rdbuf();
417 std::cout.rdbuf(*control);
419 // use cout as usual, the output appears in the text control
422 std::cout.rdbuf(sbOld);
426 But wxWidgets provides a convenient class to make it even simpler so instead
433 wxTextCtrl *control = new wxTextCtrl(...);
435 wxStreamToTextRedirector redirect(control);
437 // all output to cout goes into the text control until the exit from current
442 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
445 \wxheading{Event handling}
447 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
448 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
449 automatically, when the control has the focus.
451 To process input from a text control, use these event handler macros to direct input to member
452 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
455 \begin{twocollist}\itemsep=0pt
456 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
457 generated when the text changes. Notice that this event will always be sent
458 when the text controls contents changes - whether this is due to user input or
459 comes from the program itself (for example, if SetValue() is called)}
460 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
461 generated when enter is pressed in a text control (which must have
462 wxTE\_PROCESS\_ENTER style for this event to be generated).}
463 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occured over an URL
464 in the text control (Win32 only)}
465 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
466 into the control than the limit set by
467 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
470 \latexignore{\rtfignore{\wxheading{Members}}}
473 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlctor}
475 \func{}{wxTextCtrl}{\void}
479 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
480 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
481 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
483 Constructor, creating and showing a text control.
485 \wxheading{Parameters}
487 \docparam{parent}{Parent window. Should not be NULL.}
489 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
491 \docparam{value}{Default text value.}
493 \docparam{pos}{Text control position.}
495 \docparam{size}{Text control size.}
497 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
499 \docparam{validator}{Window validator.}
501 \docparam{name}{Window name.}
505 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
506 for multi-line text controls.
507 Without a horizontal scrollbar, text lines that don't fit in the control's
508 size will be wrapped (but no newline character is inserted). Single line
509 controls don't have a horizontal scrollbar, the text is automatically scrolled
510 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
513 % VZ: this is no longer true
514 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
515 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
520 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
523 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}\label{wxtextctrldtor}
525 \func{}{\destruct{wxTextCtrl}}{\void}
527 Destructor, destroying the text control.
530 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
532 \func{void}{AppendText}{\param{const wxString\& }{ text}}
534 Appends the text to the end of the text control.
536 \wxheading{Parameters}
538 \docparam{text}{Text to write to the text control.}
542 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
543 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
547 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
550 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
552 \func{virtual bool}{CanCopy}{\void}
554 Returns {\tt true} if the selection can be copied to the clipboard.
557 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
559 \func{virtual bool}{CanCut}{\void}
561 Returns {\tt true} if the selection can be cut to the clipboard.
564 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
566 \func{virtual bool}{CanPaste}{\void}
568 Returns {\tt true} if the contents of the clipboard can be pasted into the
569 text control. On some platforms (Motif, GTK) this is an approximation
570 and returns {\tt true} if the control is editable, {\tt false} otherwise.
573 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
575 \func{virtual bool}{CanRedo}{\void}
577 Returns {\tt true} if there is a redo facility available and the last operation
581 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
583 \func{virtual bool}{CanUndo}{\void}
585 Returns {\tt true} if there is an undo facility available and the last operation
589 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
591 \func{virtual void}{Clear}{\void}
593 Clears the text in the control.
595 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
599 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
601 \func{virtual void}{Copy}{\void}
603 Copies the selected text to the clipboard under Motif and MS Windows.
606 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
608 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
609 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
610 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
612 Creates the text control for two-step construction. Derived classes
613 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}\rtfsp
617 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
619 \func{virtual void}{Cut}{\void}
621 Copies the selected text to the clipboard and removes the selection.
624 \membersection{wxTextCtrl::DiscardEdits}\label{wxtextctrldiscardedits}
626 \func{void}{DiscardEdits}{\void}
628 Resets the internal `modified' flag as if the current edits had been saved.
631 \membersection{wxTextCtrl::EmulateKeyPress}\label{wxtextctrlemulatekeypress}
633 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
635 This functions inserts into the control the character which would have been
636 inserted if the given key event had occured in the text control. The
637 {\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
638 handler previously by wxWidgets.
640 Please note that this function doesn't currently work correctly for all keys
641 under any platform but MSW.
643 \wxheading{Return value}
645 {\tt true} if the event resulted in a change to the control, {\tt false}
649 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
651 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
653 Returns the style currently used for the new text.
657 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
660 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
662 \constfunc{virtual long}{GetInsertionPoint}{\void}
664 Returns the insertion point. This is defined as the zero based index of the
665 character position to the right of the insertion point. For example, if
666 the insertion point is at the end of the text control, it is equal to
667 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
668 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
670 The following code snippet safely returns the character at the insertion
671 point or the zero character if the point is at the end of the control.
675 char GetCurrentChar(wxTextCtrl *tc) {
676 if (tc->GetInsertionPoint() == tc->GetLastPosition())
678 return tc->GetValue[tc->GetInsertionPoint()];
684 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
686 \constfunc{virtual wxTextPos}{GetLastPosition}{\void}
688 Returns the zero based index of the last position in the text control,
689 which is equal to the number of characters in the control.
692 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
694 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
696 Gets the length of the specified line, not including any trailing newline
699 \wxheading{Parameters}
701 \docparam{lineNo}{Line number (starting from zero).}
703 \wxheading{Return value}
705 The length of the line, or -1 if {\it lineNo} was invalid.
708 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
710 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
712 Returns the contents of a given line in the text control, not including
713 any trailing newline character(s).
715 \wxheading{Parameters}
717 \docparam{lineNo}{The line number, starting from zero.}
719 \wxheading{Return value}
721 The contents of the line.
724 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
726 \constfunc{int}{GetNumberOfLines}{\void}
728 Returns the number of lines in the text control buffer.
732 Note that even empty text controls have one line (where the insertion point
733 is), so GetNumberOfLines() never returns 0.
735 For gtk\_text (multi-line) controls, the number of lines is
736 calculated by actually counting newline characters in the buffer. You
737 may wish to avoid using functions that work with line numbers if you are
738 working with controls that contain large amounts of text.
741 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
743 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
745 Returns the string containing the text staring in the positions {\it from} and
746 up to {\it to} in the control. The positions must have been returned by another
749 Please note that the positions in a multiline wxTextCtrl do {\bf not}
750 correspond to the indices in the string returned by
751 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
752 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
753 obtain the correct results instead of extracting parts of the entire value. It
754 may also be more efficient, especially if the control contains a lot of data.
757 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
759 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
761 Gets the current selection span. If the returned values are equal, there was
764 Please note that the indices returned may be used with the other wxTextctrl
765 methods but don't necessarily represent the correct indices into the string
766 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
767 under Windows (at least,) you should use
768 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
771 \wxheading{Parameters}
773 \docparam{from}{The returned first position.}
775 \docparam{to}{The returned last position.}
777 \pythonnote{The wxPython version of this method returns a tuple
778 consisting of the from and to values.}
780 \perlnote{In wxPerl this method takes no parameter and returns a
781 2-element list {\tt ( from, to )}.}
784 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
786 \func{virtual wxString}{GetStringSelection}{\void}
788 Gets the text currently selected in the control. If there is no selection, the
789 returned string is empty.
792 \membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
794 \func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
796 Returns the style at this position in the text control. Not all platforms
797 support this function.
799 \wxheading{Return value}
801 {\tt true} on success, {\tt false} if an error occured - it may also mean that
802 the styles are not supported under this platform.
806 \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
809 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
811 \constfunc{wxString}{GetValue}{\void}
813 Gets the contents of the control. Notice that for a multiline text control,
814 the lines will be separated by (Unix-style) $\backslash$n characters, even
815 under Windows where they are separated by a $\backslash$r$\backslash$n
816 sequence in the native control.
819 \membersection{wxTextCtrl::HitTest}\label{wxtextctrlhittest}
821 \constfunc{wxTextCtrlHitTestResult}{HitTest}{\param{const wxPoint\& }{pt}, \param{wxTextCoord }{*col}, \param{wxTextCoord }{*row}}
823 This function finds the character at the specified position expressed in
824 pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
825 of the character closest to this position are returned in the \arg{col} and
826 \arg{row} parameters (unless the pointers are {\tt NULL} which is allowed).
828 Please note that this function is currently only implemented in wxUniv,
829 wxMSW and wxGTK2 ports.
833 \helpref{PositionToXY}{wxtextctrlpositiontoxy}, \helpref{XYToPosition}{wxtextctrlxytoposition}
835 \perlnote{In wxPerl this function takes only the position argument and
836 returns a 3-element list \texttt{(result, col, row)}}.
838 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
840 \constfunc{bool}{IsEditable}{\void}
842 Returns {\tt true} if the controls contents may be edited by user (note that it
843 always can be changed by the program), i.e. if the control hasn't been put in
844 read-only mode by a previous call to
845 \helpref{SetEditable}{wxtextctrlseteditable}.
848 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
850 \constfunc{bool}{IsModified}{\void}
852 Returns {\tt true} if the text has been modified by user. Note that calling
853 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
856 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
858 \constfunc{bool}{IsMultiLine}{\void}
860 Returns {\tt true} if this is a multi line edit control and {\tt false}
865 \helpref{IsSingleLine}{wxtextctrlissingleline}
868 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
870 \constfunc{bool}{IsSingleLine}{\void}
872 Returns {\tt true} if this is a single line edit control and {\tt false}
877 \helpref{IsMultiLine}{wxtextctrlissingleline}
880 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
882 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
884 Loads and displays the named file, if it exists.
886 \wxheading{Parameters}
888 \docparam{filename}{The filename of the file to load.}
890 \wxheading{Return value}
892 {\tt true} if successful, {\tt false} otherwise.
894 % VZ: commenting this out as: (a) the docs are wrong (you can't replace
895 % anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
896 %% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
898 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
900 %% Default handler for character input.
902 %% \wxheading{Remarks}
904 %% It is possible to intercept character
905 %% input by overriding this member. Call this function
906 %% to let the default behaviour take place; not calling
907 %% it results in the character being ignored. You can
908 %% replace the {\it keyCode} member of {\it event} to
909 %% translate keystrokes.
911 %% Note that Windows and Motif have different ways
912 %% of implementing the default behaviour. In Windows,
913 %% calling wxTextCtrl::OnChar immediately
914 %% processes the character. In Motif,
915 %% calling this function simply sets a flag
916 %% to let default processing happen. This might affect
917 %% the way in which you write your OnChar function
918 %% on different platforms.
920 %% \wxheading{See also}
922 %% \helpref{wxKeyEvent}{wxkeyevent}
925 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
927 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
929 This event handler function implements default drag and drop behaviour, which
930 is to load the first dropped file into the control.
932 \wxheading{Parameters}
934 \docparam{event}{The drop files event.}
938 This is not implemented on non-Windows platforms.
942 \helpref{wxDropFilesEvent}{wxdropfilesevent}
945 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
947 \func{virtual void}{Paste}{\void}
949 Pastes text from the clipboard to the text item.
952 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
954 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
956 Converts given position to a zero-based column, line number pair.
958 \wxheading{Parameters}
960 \docparam{pos}{Position.}
962 \docparam{x}{Receives zero based column number.}
964 \docparam{y}{Receives zero based line number.}
966 \wxheading{Return value}
968 {\tt true} on success, {\tt false} on failure (most likely due to a too large position
973 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
975 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
976 y values, so (x,y) = PositionToXY() is equivalent to the call described
979 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
980 returns a 2-element list {\tt ( x, y )}.}
983 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
985 \func{virtual void}{Redo}{\void}
987 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
988 if there is no redo facility.
991 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
993 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
995 Removes the text starting at the first given position up to (but not including)
996 the character at the last position.
998 \wxheading{Parameters}
1000 \docparam{from}{The first position.}
1002 \docparam{to}{The last position.}
1005 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
1007 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
1009 Replaces the text starting at the first position up to (but not including)
1010 the character at the last position with the given text.
1012 \wxheading{Parameters}
1014 \docparam{from}{The first position.}
1016 \docparam{to}{The last position.}
1018 \docparam{value}{The value to replace the existing text with.}
1021 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
1023 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
1025 Saves the contents of the control in a text file.
1027 \wxheading{Parameters}
1029 \docparam{filename}{The name of the file in which to save the text.}
1031 \wxheading{Return value}
1033 {\tt true} if the operation was successful, {\tt false} otherwise.
1036 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
1038 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
1040 Changes the default style to use for the new text which is going to be added
1041 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
1042 \helpref{AppendText}{wxtextctrlappendtext}.
1044 If either of the font, foreground, or background colour is not set in\rtfsp
1045 {\it style}, the values of the previous default style are used for them. If
1046 the previous default style didn't set them neither, the global font or colours
1047 of the text control itself are used as fall back.
1049 However if the {\it style} parameter is the default wxTextAttr, then the
1050 default style is just reset (instead of being combined with the new style which
1051 wouldn't change it at all).
1053 \wxheading{Parameters}
1055 \docparam{style}{The style for the new text.}
1057 \wxheading{Return value}
1059 {\tt true} on success, {\tt false} if an error occured - may also mean that
1060 the styles are not supported under this platform.
1062 \wxheading{See also}
1064 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
1067 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
1069 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
1071 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
1073 \wxheading{Parameters}
1075 \docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
1077 \wxheading{See also}
1079 \helpref{IsEditable}{wxtextctrliseditable}
1082 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
1084 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
1086 Sets the insertion point at the given position.
1088 \wxheading{Parameters}
1090 \docparam{pos}{Position to set.}
1093 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
1095 \func{virtual void}{SetInsertionPointEnd}{\void}
1097 Sets the insertion point at the end of the text control. This is equivalent
1098 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
1101 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
1103 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
1105 This function sets the maximum number of characters the user can enter into the
1106 control. In other words, it allows to limit the text value length to {\it len}
1107 not counting the terminating {\tt NUL} character.
1109 If {\it len} is $0$, the previously set max length limit, if any, is discarded
1110 and the user may enter as much text as the underlying native text control
1111 widget supports (typically at least 32Kb).
1113 If the user tries to enter more characters into the text control when it
1114 already is filled up to the maximal length, a
1115 {\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
1116 (giving it the possibility to show an explanatory message, for example) and the
1117 extra input is discarded.
1119 Note that under GTK+, this function may only be used with single line text controls.
1121 \wxheading{Compatibility}
1123 Only implemented in wxMSW/wxGTK starting with wxWidgets 2.3.2.
1126 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
1128 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
1130 Selects the text starting at the first position up to (but not including) the
1131 character at the last position. If both parameters are equal to $-1$ all text
1132 in the control is selected.
1134 \wxheading{Parameters}
1136 \docparam{from}{The first position.}
1138 \docparam{to}{The last position.}
1141 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
1143 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
1145 Changes the style of the given range. If any attribute within {\it style} is
1146 not set, the corresponding attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
1148 \wxheading{Parameters}
1150 \docparam{start}{The start of the range to change.}
1152 \docparam{end}{The end of the range to change.}
1154 \docparam{style}{The new style for the range.}
1156 \wxheading{Return value}
1158 {\tt true} on success, {\tt false} if an error occured - it may also mean that
1159 the styles are not supported under this platform.
1161 \wxheading{See also}
1163 \helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
1166 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
1168 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
1170 Sets the text value and marks the control as not-modified (which means that
1171 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
1172 after the call to SetValue).
1174 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
1177 \wxheading{Parameters}
1179 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
1182 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
1184 \func{void}{ShowPosition}{\param{long}{ pos}}
1186 Makes the line containing the given position visible.
1188 \wxheading{Parameters}
1190 \docparam{pos}{The position that should be visible.}
1193 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
1195 \func{virtual void}{Undo}{\void}
1197 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
1198 if there is no undo facility.
1201 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1203 \func{void}{WriteText}{\param{const wxString\& }{ text}}
1205 Writes the text into the text control at the current insertion position.
1207 \wxheading{Parameters}
1209 \docparam{text}{Text to write to the text control.}
1213 Newlines in the text string
1214 are the only control characters allowed, and they will cause appropriate
1215 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
1217 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.
1220 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1222 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
1224 Converts the given zero based column and line number to a position.
1226 \wxheading{Parameters}
1228 \docparam{x}{The column number.}
1230 \docparam{y}{The line number.}
1232 \wxheading{Return value}
1237 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1239 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1241 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1243 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1245 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1247 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1249 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1251 Operator definitions for appending to a text control, for example:
1254 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1256 (*wnd) << "Welcome to text control number " << 1 << ".\n";