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 \latexignore{\rtfignore{\wxheading{Members
}}}
76 \membersection{wxTextAttr::wxTextAttr
}\label{wxtextattrctor
}
78 \func{}{wxTextAttr
}{\void}
80 \func{}{wxTextAttr
}{\param{const wxColour\&
}{colText
},
\param{const wxColour\&
}{colBack = wxNullColour
},
81 \param{const wxFont\&
}{font = wxNullFont
},
\param{wxTextAttrAlignment
}{alignment = wxTEXT
\_ALIGNMENT\_DEFAULT}}
83 The constructors initialize one or more of the text foreground colour, background
84 colour, font, and alignment. The values not initialized in the constructor can be set
85 later, otherwise
\helpref{wxTextCtrl::SetStyle
}{wxtextctrlsetstyle
} will use
86 the default values for them.
89 \membersection{wxTextAttr::GetAlignment
}\label{wxtextattrgetalignment
}
91 \constfunc{wxTextAttrAlignment
}{GetAlignment
}{\void}
93 Returns the paragraph alignment.
96 \membersection{wxTextAttr::GetBackgroundColour
}\label{wxtextattrgetbackgroundcolour
}
98 \constfunc{const wxColour\&
}{GetBackgroundColour
}{\void}
100 Return the background colour specified by this attribute.
103 \membersection{wxTextAttr::GetFont
}\label{wxtextattrgetfont
}
105 \constfunc{const wxFont\&
}{GetFont
}{\void}
107 Return the text font specified by this attribute.
110 \membersection{wxTextAttr::GetLeftIndent
}\label{wxtextattrgetleftindent
}
112 \constfunc{int
}{GetLeftIndent
}{\void}
114 Returns the left indent in tenths of a millimetre.
117 \membersection{wxTextAttr::GetLeftSubIndent
}\label{wxtextattrgetleftsubindent
}
119 \constfunc{int
}{GetLeftSubIndent
}{\void}
121 Returns the left sub indent for all lines but the first line in a paragraph in
122 tenths of a millimetre.
125 \membersection{wxTextAttr::GetRightIndent
}\label{wxtextattrgetrightindent
}
127 \constfunc{int
}{GetRightIndent
}{\void}
129 Returns the right indent in tenths of a millimetre.
132 \membersection{wxTextAttr::GetTabs
}\label{wxtextattrgettabs
}
134 \constfunc{const wxArrayInt\&
}{GetTabs
}{\void}
136 Returns the array of integers representing the tab stops. Each
137 array element specifies the tab stop in tenths of a millimetre.
140 \membersection{wxTextAttr::GetTextColour
}\label{wxtextattrgettextcolour
}
142 \constfunc{const wxColour\&
}{GetTextColour
}{\void}
144 Return the text colour specified by this attribute.
147 \membersection{wxTextAttr::HasBackgroundColour
}\label{wxtextattrhasbackgroundcolour
}
149 \constfunc{bool
}{HasBackgroundColour
}{\void}
151 Returns
{\tt true
} if this style specifies the background colour to use.
154 \membersection{wxTextAttr::HasFont
}\label{wxtextattrhasfont
}
156 \constfunc{bool
}{HasFont
}{\void}
158 Returns
{\tt true
} if this style specifies the font to use.
161 \membersection{wxTextAttr::HasTextColour
}\label{wxtextattrhastextcolour
}
163 \constfunc{bool
}{HasTextColour
}{\void}
165 Returns
{\tt true
} if this style specifies the foreground colour to use.
168 \membersection{wxTextAttr::GetFlags
}\label{wxtextattrgetflags
}
170 \func{long
}{GetFlags
}{\void}
172 Returns a bitlist indicating which attributes will be set.
175 \membersection{wxTextAttr::IsDefault
}\label{wxtextattrisdefault
}
177 \constfunc{bool
}{IsDefault
}{\void}
179 Returns
{\tt true
} if this style specifies any non-default attributes.
182 \membersection{wxTextAttr::Merge
}\label{wxtextattrmerge
}
184 \func{void
}{Merge
}{\param{const wxTextAttr\&
}{ overlay
}}
186 Copies all defined/valid properties from
\arg{overlay
} to current object.
188 \func{static wxTextAttr
}{Merge
}{\param{const wxTextAttr\&
}{ base
},
\param{const wxTextAttr\&
}{ overlay
}}
190 Creates a new
{\tt wxTextAttr
} which is a merge of
\arg{base
} and
191 \arg{overlay
}. Properties defined in
\arg{overlay
} take precedence over those
192 in
\arg{base
}. Properties undefined/invalid in both are undefined in the
196 \membersection{wxTextAttr::SetAlignment
}\label{wxtextattrsetalignment
}
198 \func{void
}{SetAlignment
}{\param{wxTextAttrAlignment
}{ alignment
}}
200 Sets the paragraph alignment.
203 \membersection{wxTextAttr::SetBackgroundColour
}\label{wxtextattrsetbackgroundcolour
}
205 \func{void
}{SetBackgroundColour
}{\param{const wxColour\&
}{colour
}}
207 Sets the background colour.
210 \membersection{wxTextAttr::SetFlags
}\label{wxtextattrsetflags
}
212 \func{void
}{SetFlags
}{\param{long
}{ flags
}}
214 Pass a bitlist indicating which attributes will be set.
217 \membersection{wxTextAttr::SetFont
}\label{wxtextattrsetfont
}
219 \func{void
}{SetFont
}{\param{const wxFont\&
}{ font
}}
224 \membersection{wxTextAttr::SetLeftIndent
}\label{wxtextattrsetleftindent
}
226 \func{void
}{SetLeftIndent
}{\param{int
}{indent
},
\param{int
}{subIndent =
0}}
228 Sets the left indent in tenths of a millimetre.
229 subIndent sets the indent for all lines but the first line in a paragraph
230 relative to the first line.
233 \membersection{wxTextAttr::SetRightIndent
}\label{wxtextattrsetrightindent
}
235 \func{void
}{SetRightIndent
}{\param{int
}{indent
}}
237 Sets the right indent in tenths of a millimetre.
240 \membersection{wxTextAttr::SetTabs
}\label{wxtextattrsettabs
}
242 \func{void
}{SetTabs
}{\param{const wxArrayInt\&
}{ tabs
}}
244 Sets the array of integers representing the tab stops. Each
245 array element specifies the tab stop in tenths of a millimetre.
248 \membersection{wxTextAttr::SetTextColour
}\label{wxtextattrsettextcolour
}
250 \func{void
}{SetTextColour
}{\param{const wxColour\&
}{colour
}}
252 Sets the text colour.
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
259 A text control allows text to be displayed and edited. It may be
260 single line or multi-line.
262 \wxheading{Derived from
}
265 \helpref{wxControl
}{wxcontrol
}\\
266 \helpref{wxWindow
}{wxwindow
}\\
267 \helpref{wxEvtHandler
}{wxevthandler
}\\
268 \helpref{wxObject
}{wxobject
}
270 \wxheading{Include files
}
274 \wxheading{Window styles
}
277 \begin{twocollist
}\itemsep=
0pt
278 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
279 the event wxEVT
\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
280 is either processed internally by the control or used for navigation between
282 \twocolitem{\windowstyle{wxTE
\_PROCESS\_TAB}}{The control will receive
283 wxEVT
\_CHAR events for TAB pressed - normally, TAB is used for passing to the
284 next control in a dialog instead. For the control created with this style,
285 you can still use Ctrl-Enter to pass to the next control from the keyboard.
}
286 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
287 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
288 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
289 \twocolitem{\windowstyle{wxTE
\_RICH}}{Use rich text control under Win32, this
290 allows to have more than
64KB of text in the control even under Win9x. This
291 style is ignored under other platforms.
}
292 \twocolitem{\windowstyle{wxTE
\_RICH2}}{Use rich text control version
2.0 or
3.0
293 under Win32, this style is ignored under other platforms
}
294 \twocolitem{\windowstyle{wxTE
\_AUTO\_URL}}{Highlight the URLs and generate the
295 wxTextUrlEvents when mouse events occur over them. This style is only supported
296 for wxTE
\_RICH Win32 and multi-line wxGTK2 text controls.
}
297 \twocolitem{\windowstyle{wxTE
\_NOHIDESEL}}{By default, the Windows text control
298 doesn't show the selection when it doesn't have focus - use this style to force
299 it to always show it. It doesn't do anything under other platforms.
}
300 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created and
301 used, so that text won't be wrapped. No effect under wxGTK1.
}
302 \twocolitem{\windowstyle{wxTE
\_LEFT}}{The text in the control will be left-justified (default).
}
303 \twocolitem{\windowstyle{wxTE
\_CENTRE}}{The text in the control will be centered (currently wxMSW and wxGTK2 only).
}
304 \twocolitem{\windowstyle{wxTE
\_RIGHT}}{The text in the control will be right-justified (currently wxMSW and wxGTK2 only).
}
305 \twocolitem{\windowstyle{wxTE
\_DONTWRAP}}{Same as
{\tt wxHSCROLL
} style: don't wrap at all, show horizontal scrollbar instead.
}
306 \twocolitem{\windowstyle{wxTE
\_CHARWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv and wxGTK2 only).
}
307 \twocolitem{\windowstyle{wxTE
\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries (wxUniv and wxGTK2 only).
}
308 \twocolitem{\windowstyle{wxTE
\_BESTWRAP}}{Wrap the lines at word boundaries or at any other character if there are words longer than the window width (this is the default).
}
309 \twocolitem{\windowstyle{wxTE
\_CAPITALIZE}}{On PocketPC and Smartphone, causes the first letter to be capitalized.
}
312 See also
\helpref{window styles overview
}{windowstyles
} and
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlctor
}.
314 \wxheading{wxTextCtrl text format
}
316 The multiline text controls always store the text as a sequence of lines
317 separated by
{\tt $
\backslash$n
} characters, i.e. in the Unix text format even
318 on non-Unix platforms. This allows the user code to ignore the differences
319 between the platforms but at a price: the indices in the control such as those
320 returned by
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} or
321 \helpref{GetSelection
}{wxtextctrlgetselection
} can
{\bf not
} be used as
322 indices into the string returned by
\helpref{GetValue
}{wxtextctrlgetvalue
} as
323 they're going to be slightly off for platforms using
324 {\tt $
\backslash$r$
\backslash$n
} as separator (as Windows does), for example.
326 Instead, if you need to obtain a substring between the $
2$ indices obtained
327 from the control with the help of the functions mentioned above, you should
328 use
\helpref{GetRange
}{wxtextctrlgetrange
}. And the indices themselves can
329 only be passed to other methods, for example
330 \helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
} or
331 \helpref{SetSelection
}{wxtextctrlsetselection
}.
333 To summarize: never use the indices returned by (multiline) wxTextCtrl as
334 indices into the string it contains, but only as arguments to be passed back
335 to the other wxTextCtrl methods.
337 \wxheading{wxTextCtrl styles
}
339 Multi-line text controls support the styles, i.e. provide a possibility to set
340 colours and font for individual characters in it (note that under Windows
{\tt
341 wxTE
\_RICH} style is required for style support). To use the styles you can
342 either call
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} before
343 inserting the text or call
\helpref{SetStyle
}{wxtextctrlsetstyle
} later to
344 change the style of the text already in the control (the first solution is
345 much more efficient).
347 In either case, if the style doesn't specify some of the attributes (for
348 example you only want to set the text colour but without changing the font nor
349 the text background), the values of the default style will be used for them.
350 If there is no default style, the attributes of the text control itself are
353 So the following code correctly describes what it does: the second call
354 to
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} doesn't change the
355 text foreground colour (which stays red) while the last one doesn't change the
356 background colour (which stays grey):
360 text->SetDefaultStyle(wxTextAttr
(*wxRED));
361 text->AppendText("Red text\n");
362 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
363 text->AppendText("Red on grey text\n");
364 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
365 text->AppendText("Blue on grey text\n");
369 \wxheading{wxTextCtrl and C++ streams}
371 This class multiply-inherits from {\bf streambuf} where compilers allow,
372 allowing code such as the following:
376 wxTextCtrl *control = new wxTextCtrl(...);
378 ostream stream(control)
380 stream << 123.456 << " some text\n";
385 If your compiler does not support derivation from {\bf streambuf} and gives a
386 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
387 wxTextCtrl header file.
389 Note that independently of this setting you can always use wxTextCtrl itself
390 in a stream-like manner:
394 wxTextCtrl *control = new wxTextCtrl(...);
396 *control << 123.456 << " some text\n";
400 always works. However the possibility to create an ostream associated with
401 wxTextCtrl may be useful if you need to redirect the output of a function
402 taking an ostream as parameter to a text control.
404 Another commonly requested need is to redirect {\bf std::cout} to the text
405 control. This could be done in the following way:
411 wxTextCtrl *control = new wxTextCtrl(...);
413 std::streambuf *sbOld = std::cout.rdbuf();
414 std::cout.rdbuf(*control);
416 // use cout as usual, the output appears in the text control
419 std::cout.rdbuf(sbOld);
423 But wxWidgets provides a convenient class to make it even simpler so instead
430 wxTextCtrl *control = new wxTextCtrl(...);
432 wxStreamToTextRedirector redirect(control);
434 // all output to cout goes into the text control until the exit from current
439 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
442 \wxheading{Constants}
444 The values below are the possible return codes of the
445 \helpref{HitTest}{wxtextctrlhittest} method:
449 // the point asked is ...
450 enum wxTextCtrlHitTestResult
452 wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented
453 wxTE_HT_BEFORE, // either to the left or upper
454 wxTE_HT_ON_TEXT, // directly on
455 wxTE_HT_BELOW, // below [the last line]
456 wxTE_HT_BEYOND // after [the end of line]
458 // ... the character returned
463 \wxheading{Event handling}
465 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
466 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
467 automatically, when the control has the focus.
469 To process input from a text control, use these event handler macros to direct input to member
470 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
473 \begin{twocollist}\itemsep=0pt
474 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
475 generated when the text changes. Notice that this event will always be sent
476 when the text controls contents changes - whether this is due to user input or
477 comes from the program itself (for example, if SetValue() is called)}
478 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
479 generated when enter is pressed in a text control (which must have
480 wxTE\_PROCESS\_ENTER style for this event to be generated).}
481 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occurred over an URL
482 in the text control (wxMSW and wxGTK2 only)}
483 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
484 into the control than the limit set by
485 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
488 \latexignore{\rtfignore{\wxheading{Members}}}
491 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlctor}
493 \func{}{wxTextCtrl}{\void}
497 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
498 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
499 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
501 Constructor, creating and showing a text control.
503 \wxheading{Parameters}
505 \docparam{parent}{Parent window. Should not be NULL.}
507 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
509 \docparam{value}{Default text value.}
511 \docparam{pos}{Text control position.}
513 \docparam{size}{Text control size.}
515 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
517 \docparam{validator}{Window validator.}
519 \docparam{name}{Window name.}
523 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
524 for multi-line text controls.
525 Without a horizontal scrollbar, text lines that don't fit in the control's
526 size will be wrapped (but no newline character is inserted). Single line
527 controls don't have a horizontal scrollbar, the text is automatically scrolled
528 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
531 % VZ: this is no longer true
532 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
533 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
538 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
541 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}\label{wxtextctrldtor}
543 \func{}{\destruct{wxTextCtrl}}{\void}
545 Destructor, destroying the text control.
548 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
550 \func{void}{AppendText}{\param{const wxString\& }{ text}}
552 Appends the text to the end of the text control.
554 \wxheading{Parameters}
556 \docparam{text}{Text to write to the text control.}
560 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
561 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
565 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
568 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
570 \func{virtual bool}{CanCopy}{\void}
572 Returns {\tt true} if the selection can be copied to the clipboard.
575 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
577 \func{virtual bool}{CanCut}{\void}
579 Returns {\tt true} if the selection can be cut to the clipboard.
582 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
584 \func{virtual bool}{CanPaste}{\void}
586 Returns {\tt true} if the contents of the clipboard can be pasted into the
587 text control. On some platforms (Motif, GTK) this is an approximation
588 and returns {\tt true} if the control is editable, {\tt false} otherwise.
591 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
593 \func{virtual bool}{CanRedo}{\void}
595 Returns {\tt true} if there is a redo facility available and the last operation
599 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
601 \func{virtual bool}{CanUndo}{\void}
603 Returns {\tt true} if there is an undo facility available and the last operation
607 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
609 \func{virtual void}{Clear}{\void}
611 Clears the text in the control.
613 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
617 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
619 \func{virtual void}{Copy}{\void}
621 Copies the selected text to the clipboard under Motif and MS Windows.
624 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
626 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
627 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
628 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
630 Creates the text control for two-step construction. Derived classes
631 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}\rtfsp
635 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
637 \func{virtual void}{Cut}{\void}
639 Copies the selected text to the clipboard and removes the selection.
642 \membersection{wxTextCtrl::DiscardEdits}\label{wxtextctrldiscardedits}
644 \func{void}{DiscardEdits}{\void}
646 Resets the internal `modified' flag as if the current edits had been saved.
649 \membersection{wxTextCtrl::EmulateKeyPress}\label{wxtextctrlemulatekeypress}
651 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
653 This functions inserts into the control the character which would have been
654 inserted if the given key event had occurred in the text control. The
655 {\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
656 handler previously by wxWidgets.
658 Please note that this function doesn't currently work correctly for all keys
659 under any platform but MSW.
661 \wxheading{Return value}
663 {\tt true} if the event resulted in a change to the control, {\tt false}
667 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
669 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
671 Returns the style currently used for the new text.
675 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
678 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
680 \constfunc{virtual long}{GetInsertionPoint}{\void}
682 Returns the insertion point. This is defined as the zero based index of the
683 character position to the right of the insertion point. For example, if
684 the insertion point is at the end of the text control, it is equal to
685 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
686 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
688 The following code snippet safely returns the character at the insertion
689 point or the zero character if the point is at the end of the control.
693 char GetCurrentChar(wxTextCtrl *tc) {
694 if (tc->GetInsertionPoint() == tc->GetLastPosition())
696 return tc->GetValue[tc->GetInsertionPoint()];
702 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
704 \constfunc{virtual wxTextPos}{GetLastPosition}{\void}
706 Returns the zero based index of the last position in the text control,
707 which is equal to the number of characters in the control.
710 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
712 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
714 Gets the length of the specified line, not including any trailing newline
717 \wxheading{Parameters}
719 \docparam{lineNo}{Line number (starting from zero).}
721 \wxheading{Return value}
723 The length of the line, or -1 if {\it lineNo} was invalid.
726 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
728 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
730 Returns the contents of a given line in the text control, not including
731 any trailing newline character(s).
733 \wxheading{Parameters}
735 \docparam{lineNo}{The line number, starting from zero.}
737 \wxheading{Return value}
739 The contents of the line.
742 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
744 \constfunc{int}{GetNumberOfLines}{\void}
746 Returns the number of lines in the text control buffer.
750 Note that even empty text controls have one line (where the insertion point
751 is), so GetNumberOfLines() never returns $0$.
753 For wxGTK using GTK+ 1.2.x and earlier, the number of lines in a multi-line
754 text control is calculated by actually counting newline characters in the
755 buffer, i.e. this function returns the number of logical lines and doesn't
756 depend on whether any of them are wrapped. For all the other platforms, the
757 number of physical lines in the control is returned.
759 Also note that you may wish to avoid using functions that work with line
760 numbers if you are working with controls that contain large amounts of text as
761 this function has $O(N)$ complexity for $N$ being the number of lines.
764 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
766 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
768 Returns the string containing the text starting in the positions {\it from} and
769 up to {\it to} in the control. The positions must have been returned by another
772 Please note that the positions in a multiline wxTextCtrl do {\bf not}
773 correspond to the indices in the string returned by
774 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
775 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
776 obtain the correct results instead of extracting parts of the entire value. It
777 may also be more efficient, especially if the control contains a lot of data.
780 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
782 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
784 Gets the current selection span. If the returned values are equal, there was
787 Please note that the indices returned may be used with the other wxTextctrl
788 methods but don't necessarily represent the correct indices into the string
789 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
790 under Windows (at least,) you should use
791 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
794 \wxheading{Parameters}
796 \docparam{from}{The returned first position.}
798 \docparam{to}{The returned last position.}
800 \pythonnote{The wxPython version of this method returns a tuple
801 consisting of the from and to values.}
803 \perlnote{In wxPerl this method takes no parameter and returns a
804 2-element list {\tt ( from, to )}.}
807 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
809 \func{virtual wxString}{GetStringSelection}{\void}
811 Gets the text currently selected in the control. If there is no selection, the
812 returned string is empty.
815 \membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
817 \func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
819 Returns the style at this position in the text control. Not all platforms
820 support this function.
822 \wxheading{Return value}
824 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
825 the styles are not supported under this platform.
829 \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
832 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
834 \constfunc{wxString}{GetValue}{\void}
836 Gets the contents of the control. Notice that for a multiline text control,
837 the lines will be separated by (Unix-style) $\backslash$n characters, even
838 under Windows where they are separated by a $\backslash$r$\backslash$n
839 sequence in the native control.
842 \membersection{wxTextCtrl::HitTest}\label{wxtextctrlhittest}
844 \constfunc{wxTextCtrlHitTestResult}{HitTest}{\param{const wxPoint\& }{pt}, \param{wxTextCoord }{*col}, \param{wxTextCoord }{*row}}
846 This function finds the character at the specified position expressed in
847 pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
848 of the character closest to this position are returned in the \arg{col} and
849 \arg{row} parameters (unless the pointers are {\tt NULL} which is allowed).
851 Please note that this function is currently only implemented in wxUniv,
852 wxMSW and wxGTK2 ports.
856 \helpref{PositionToXY}{wxtextctrlpositiontoxy}, \helpref{XYToPosition}{wxtextctrlxytoposition}
858 \perlnote{In wxPerl this function takes only the position argument and
859 returns a 3-element list \texttt{(result, col, row)}}.
861 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
863 \constfunc{bool}{IsEditable}{\void}
865 Returns {\tt true} if the controls contents may be edited by user (note that it
866 always can be changed by the program), i.e. if the control hasn't been put in
867 read-only mode by a previous call to
868 \helpref{SetEditable}{wxtextctrlseteditable}.
871 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
873 \constfunc{bool}{IsModified}{\void}
875 Returns {\tt true} if the text has been modified by user. Note that calling
876 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
880 \helpref{MarkDirty}{wxtextctrlmarkdirty}
883 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
885 \constfunc{bool}{IsMultiLine}{\void}
887 Returns {\tt true} if this is a multi line edit control and {\tt false}
892 \helpref{IsSingleLine}{wxtextctrlissingleline}
895 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
897 \constfunc{bool}{IsSingleLine}{\void}
899 Returns {\tt true} if this is a single line edit control and {\tt false}
904 \helpref{IsMultiLine}{wxtextctrlissingleline}
907 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
909 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
911 Loads and displays the named file, if it exists.
913 \wxheading{Parameters}
915 \docparam{filename}{The filename of the file to load.}
917 \wxheading{Return value}
919 {\tt true} if successful, {\tt false} otherwise.
921 % VZ: commenting this out as: (a) the docs are wrong (you can't replace
922 % anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
923 %% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
925 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
927 %% Default handler for character input.
929 %% \wxheading{Remarks}
931 %% It is possible to intercept character
932 %% input by overriding this member. Call this function
933 %% to let the default behaviour take place; not calling
934 %% it results in the character being ignored. You can
935 %% replace the {\it keyCode} member of {\it event} to
936 %% translate keystrokes.
938 %% Note that Windows and Motif have different ways
939 %% of implementing the default behaviour. In Windows,
940 %% calling wxTextCtrl::OnChar immediately
941 %% processes the character. In Motif,
942 %% calling this function simply sets a flag
943 %% to let default processing happen. This might affect
944 %% the way in which you write your OnChar function
945 %% on different platforms.
947 %% \wxheading{See also}
949 %% \helpref{wxKeyEvent}{wxkeyevent}
952 \membersection{wxTextCtrl::MarkDirty}\label{wxtextctrlmarkdirty}
954 \func{void}{MarkDirty}{\void}
956 Mark text as modified (dirty).
960 \helpref{IsModified}{wxtextctrlismodified}
963 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
965 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
967 This event handler function implements default drag and drop behaviour, which
968 is to load the first dropped file into the control.
970 \wxheading{Parameters}
972 \docparam{event}{The drop files event.}
976 This is not implemented on non-Windows platforms.
980 \helpref{wxDropFilesEvent}{wxdropfilesevent}
983 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
985 \func{virtual void}{Paste}{\void}
987 Pastes text from the clipboard to the text item.
990 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
992 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
994 Converts given position to a zero-based column, line number pair.
996 \wxheading{Parameters}
998 \docparam{pos}{Position.}
1000 \docparam{x}{Receives zero based column number.}
1002 \docparam{y}{Receives zero based line number.}
1004 \wxheading{Return value}
1006 {\tt true} on success, {\tt false} on failure (most likely due to a too large position
1009 \wxheading{See also}
1011 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
1013 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
1014 y values, so (x,y) = PositionToXY() is equivalent to the call described
1017 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
1018 returns a 2-element list {\tt ( x, y )}.}
1021 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
1023 \func{virtual void}{Redo}{\void}
1025 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
1026 if there is no redo facility.
1029 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
1031 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
1033 Removes the text starting at the first given position up to (but not including)
1034 the character at the last position.
1036 \wxheading{Parameters}
1038 \docparam{from}{The first position.}
1040 \docparam{to}{The last position.}
1043 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
1045 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
1047 Replaces the text starting at the first position up to (but not including)
1048 the character at the last position with the given text.
1050 \wxheading{Parameters}
1052 \docparam{from}{The first position.}
1054 \docparam{to}{The last position.}
1056 \docparam{value}{The value to replace the existing text with.}
1059 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
1061 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
1063 Saves the contents of the control in a text file.
1065 \wxheading{Parameters}
1067 \docparam{filename}{The name of the file in which to save the text.}
1069 \wxheading{Return value}
1071 {\tt true} if the operation was successful, {\tt false} otherwise.
1074 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
1076 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
1078 Changes the default style to use for the new text which is going to be added
1079 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
1080 \helpref{AppendText}{wxtextctrlappendtext}.
1082 If either of the font, foreground, or background colour is not set in\rtfsp
1083 {\it style}, the values of the previous default style are used for them. If
1084 the previous default style didn't set them neither, the global font or colours
1085 of the text control itself are used as fall back.
1087 However if the {\it style} parameter is the default wxTextAttr, then the
1088 default style is just reset (instead of being combined with the new style which
1089 wouldn't change it at all).
1091 \wxheading{Parameters}
1093 \docparam{style}{The style for the new text.}
1095 \wxheading{Return value}
1097 {\tt true} on success, {\tt false} if an error occurred - may also mean that
1098 the styles are not supported under this platform.
1100 \wxheading{See also}
1102 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
1105 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
1107 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
1109 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
1111 \wxheading{Parameters}
1113 \docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
1115 \wxheading{See also}
1117 \helpref{IsEditable}{wxtextctrliseditable}
1120 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
1122 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
1124 Sets the insertion point at the given position.
1126 \wxheading{Parameters}
1128 \docparam{pos}{Position to set.}
1131 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
1133 \func{virtual void}{SetInsertionPointEnd}{\void}
1135 Sets the insertion point at the end of the text control. This is equivalent
1136 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
1139 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
1141 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
1143 This function sets the maximum number of characters the user can enter into the
1144 control. In other words, it allows to limit the text value length to {\it len}
1145 not counting the terminating {\tt NUL} character.
1147 If {\it len} is $0$, the previously set max length limit, if any, is discarded
1148 and the user may enter as much text as the underlying native text control
1149 widget supports (typically at least 32Kb).
1151 If the user tries to enter more characters into the text control when it
1152 already is filled up to the maximal length, a
1153 {\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
1154 (giving it the possibility to show an explanatory message, for example) and the
1155 extra input is discarded.
1157 Note that under GTK+, this function may only be used with single line text controls.
1159 \wxheading{Compatibility}
1161 Only implemented in wxMSW/wxGTK starting with wxWidgets 2.3.2.
1164 \membersection{wxTextCtrl::SetModified}\label{wxtextctrlsetmodified}
1166 \func{void}{SetModified}{\param{bool }{modified}}
1168 Marks the control as being modified by the user or not.
1170 \wxheading{See also}
1172 \helpref{MarkDirty}{wxtextctrlmarkdirty}, \helpref{DiscardEdits}{wxtextctrldiscardedits}
1175 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
1177 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
1179 Selects the text starting at the first position up to (but not including) the
1180 character at the last position. If both parameters are equal to $-1$ all text
1181 in the control is selected.
1183 \wxheading{Parameters}
1185 \docparam{from}{The first position.}
1187 \docparam{to}{The last position.}
1190 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
1192 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
1194 Changes the style of the given range. If any attribute within {\it style} is
1195 not set, the corresponding attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
1197 \wxheading{Parameters}
1199 \docparam{start}{The start of the range to change.}
1201 \docparam{end}{The end of the range to change.}
1203 \docparam{style}{The new style for the range.}
1205 \wxheading{Return value}
1207 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
1208 the styles are not supported under this platform.
1210 \wxheading{See also}
1212 \helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
1215 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
1217 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
1219 Sets the text value and marks the control as not-modified (which means that
1220 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
1221 after the call to SetValue).
1223 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
1226 \wxheading{Parameters}
1228 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
1231 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
1233 \func{void}{ShowPosition}{\param{long}{ pos}}
1235 Makes the line containing the given position visible.
1237 \wxheading{Parameters}
1239 \docparam{pos}{The position that should be visible.}
1242 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
1244 \func{virtual void}{Undo}{\void}
1246 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
1247 if there is no undo facility.
1250 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1252 \func{void}{WriteText}{\param{const wxString\& }{ text}}
1254 Writes the text into the text control at the current insertion position.
1256 \wxheading{Parameters}
1258 \docparam{text}{Text to write to the text control.}
1262 Newlines in the text string
1263 are the only control characters allowed, and they will cause appropriate
1264 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
1266 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.
1269 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1271 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
1273 Converts the given zero based column and line number to a position.
1275 \wxheading{Parameters}
1277 \docparam{x}{The column number.}
1279 \docparam{y}{The line number.}
1281 \wxheading{Return value}
1283 The position value, or -1 if {\tt x} or {\tt y} was invalid.
1286 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1288 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1290 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1292 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1294 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1296 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1298 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1300 Operator definitions for appending to a text control, for example:
1303 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1305 (*wnd) << "Welcome to text control number " << 1 << ".\n";