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::Merge
}\label{wxtextattrmerge
}
202 \func{void
}{Merge
}{\param{const wxTextAttr\&
}{ overlay
}}
204 Copies all defined/valid properties from
\arg{overlay
} to current object.
206 \func{static wxTextAttr
}{Merge
}{\param{const wxTextAttr\&
}{ base
},
\param{const wxTextAttr\&
}{ overlay
}}
208 Creates a new
{\tt wxTextAttr
} which is a merge of
\arg{base
} and
209 \arg{overlay
}. Properties defined in
\arg{overlay
} take precedence over those
210 in
\arg{base
}. Properties undefined/invalid in both are undefined in the
214 \membersection{wxTextAttr::SetAlignment
}\label{wxtextattrsetalignment
}
216 \func{void
}{SetAlignment
}{\param{wxTextAttrAlignment
}{ alignment
}}
218 Sets the paragraph alignment.
221 \membersection{wxTextAttr::SetBackgroundColour
}\label{wxtextattrsetbackgroundcolour
}
223 \func{void
}{SetBackgroundColour
}{\param{const wxColour\&
}{colour
}}
225 Sets the background colour.
228 \membersection{wxTextAttr::SetFlags
}\label{wxtextattrsetflags
}
230 \func{void
}{SetFlags
}{\param{long
}{ flags
}}
232 Pass a bitlist indicating which attributes will be set.
235 \membersection{wxTextAttr::SetFont
}\label{wxtextattrsetfont
}
237 \func{void
}{SetFont
}{\param{const wxFont\&
}{ font
}}
242 \membersection{wxTextAttr::SetLeftIndent
}\label{wxtextattrsetleftindent
}
244 \func{void
}{SetLeftIndent
}{\param{int
}{indent
},
\param{int
}{subIndent =
0}}
246 Sets the left indent in tenths of a millimetre.
247 subIndent sets the indent for all lines but the first line in a paragraph
248 relative to the first line.
251 \membersection{wxTextAttr::SetRightIndent
}\label{wxtextattrsetrightindent
}
253 \func{void
}{SetRightIndent
}{\param{int
}{indent
}}
255 Sets the right indent in tenths of a millimetre.
258 \membersection{wxTextAttr::SetTabs
}\label{wxtextattrsettabs
}
260 \func{void
}{SetTabs
}{\param{const wxArrayInt\&
}{ tabs
}}
262 Sets the array of integers representing the tab stops. Each
263 array element specifies the tab stop in tenths of a millimetre.
266 \membersection{wxTextAttr::SetTextColour
}\label{wxtextattrsettextcolour
}
268 \func{void
}{SetTextColour
}{\param{const wxColour\&
}{colour
}}
270 Sets the text colour.
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 \section{\class{wxTextCtrl
}}\label{wxtextctrl
}
277 A text control allows text to be displayed and edited. It may be
278 single line or multi-line.
280 \wxheading{Derived from
}
283 \helpref{wxControl
}{wxcontrol
}\\
284 \helpref{wxWindow
}{wxwindow
}\\
285 \helpref{wxEvtHandler
}{wxevthandler
}\\
286 \helpref{wxObject
}{wxobject
}
288 \wxheading{Include files
}
292 \wxheading{Window styles
}
295 \begin{twocollist
}\itemsep=
0pt
296 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
297 the event wxEVT
\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
298 is either processed internally by the control or used for navigation between
300 \twocolitem{\windowstyle{wxTE
\_PROCESS\_TAB}}{The control will receive
301 wxEVT
\_CHAR events for TAB pressed - normally, TAB is used for passing to the
302 next control in a dialog instead. For the control created with this style,
303 you can still use Ctrl-Enter to pass to the next control from the keyboard.
}
304 \twocolitem{\windowstyle{wxTE
\_MULTILINE}}{The text control allows multiple lines.
}
305 \twocolitem{\windowstyle{wxTE
\_PASSWORD}}{The text will be echoed as asterisks.
}
306 \twocolitem{\windowstyle{wxTE
\_READONLY}}{The text will not be user-editable.
}
307 \twocolitem{\windowstyle{wxTE
\_RICH}}{Use rich text control under Win32, this
308 allows to have more than
64KB of text in the control even under Win9x. This
309 style is ignored under other platforms.
}
310 \twocolitem{\windowstyle{wxTE
\_RICH2}}{Use rich text control version
2.0 or
3.0
311 under Win32, this style is ignored under other platforms
}
312 \twocolitem{\windowstyle{wxTE
\_AUTO\_URL}}{Highlight the URLs and generate the
313 wxTextUrlEvents when mouse events occur over them. This style is only supported
314 for wxTE
\_RICH Win32 and multi-line wxGTK2 text controls.
}
315 \twocolitem{\windowstyle{wxTE
\_NOHIDESEL}}{By default, the Windows text control
316 doesn't show the selection when it doesn't have focus - use this style to force
317 it to always show it. It doesn't do anything under other platforms.
}
318 \twocolitem{\windowstyle{wxHSCROLL
}}{A horizontal scrollbar will be created and
319 used, so that text won't be wrapped. No effect under wxGTK1.
}
320 \twocolitem{\windowstyle{wxTE
\_LEFT}}{The text in the control will be left-justified (default).
}
321 \twocolitem{\windowstyle{wxTE
\_CENTRE}}{The text in the control will be centered (currently wxMSW and wxGTK2 only).
}
322 \twocolitem{\windowstyle{wxTE
\_RIGHT}}{The text in the control will be right-justified (currently wxMSW and wxGTK2 only).
}
323 \twocolitem{\windowstyle{wxTE
\_DONTWRAP}}{Same as
{\tt wxHSCROLL
} style: don't wrap at all, show horizontal scrollbar instead.
}
324 \twocolitem{\windowstyle{wxTE
\_CHARWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv and wxGTK2 only).
}
325 \twocolitem{\windowstyle{wxTE
\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries (wxUniv and wxGTK2 only).
}
326 \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).
}
327 \twocolitem{\windowstyle{wxTE
\_CAPITALIZE}}{On PocketPC and Smartphone, causes the first letter to be capitalized.
}
330 See also
\helpref{window styles overview
}{windowstyles
} and
\helpref{wxTextCtrl::wxTextCtrl
}{wxtextctrlctor
}.
332 \wxheading{wxTextCtrl text format
}
334 The multiline text controls always store the text as a sequence of lines
335 separated by
{\tt $
\backslash$n
} characters, i.e. in the Unix text format even
336 on non-Unix platforms. This allows the user code to ignore the differences
337 between the platforms but at a price: the indices in the control such as those
338 returned by
\helpref{GetInsertionPoint
}{wxtextctrlgetinsertionpoint
} or
339 \helpref{GetSelection
}{wxtextctrlgetselection
} can
{\bf not
} be used as
340 indices into the string returned by
\helpref{GetValue
}{wxtextctrlgetvalue
} as
341 they're going to be slightly off for platforms using
342 {\tt $
\backslash$r$
\backslash$n
} as separator (as Windows does), for example.
344 Instead, if you need to obtain a substring between the $
2$ indices obtained
345 from the control with the help of the functions mentioned above, you should
346 use
\helpref{GetRange
}{wxtextctrlgetrange
}. And the indices themselves can
347 only be passed to other methods, for example
348 \helpref{SetInsertionPoint
}{wxtextctrlsetinsertionpoint
} or
349 \helpref{SetSelection
}{wxtextctrlsetselection
}.
351 To summarize: never use the indices returned by (multiline) wxTextCtrl as
352 indices into the string it contains, but only as arguments to be passed back
353 to the other wxTextCtrl methods.
355 \wxheading{wxTextCtrl styles
}
357 Multi-line text controls support the styles, i.e. provide a possibility to set
358 colours and font for individual characters in it (note that under Windows
{\tt
359 wxTE
\_RICH} style is required for style support). To use the styles you can
360 either call
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} before
361 inserting the text or call
\helpref{SetStyle
}{wxtextctrlsetstyle
} later to
362 change the style of the text already in the control (the first solution is
363 much more efficient).
365 In either case, if the style doesn't specify some of the attributes (for
366 example you only want to set the text colour but without changing the font nor
367 the text background), the values of the default style will be used for them.
368 If there is no default style, the attributes of the text control itself are
371 So the following code correctly describes what it does: the second call
372 to
\helpref{SetDefaultStyle
}{wxtextctrlsetdefaultstyle
} doesn't change the
373 text foreground colour (which stays red) while the last one doesn't change the
374 background colour (which stays grey):
378 text->SetDefaultStyle(wxTextAttr
(*wxRED));
379 text->AppendText("Red text\n");
380 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
381 text->AppendText("Red on grey text\n");
382 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
383 text->AppendText("Blue on grey text\n");
387 \wxheading{wxTextCtrl and C++ streams}
389 This class multiply-inherits from {\bf streambuf} where compilers allow,
390 allowing code such as the following:
394 wxTextCtrl *control = new wxTextCtrl(...);
396 ostream stream(control)
398 stream << 123.456 << " some text\n";
403 If your compiler does not support derivation from {\bf streambuf} and gives a
404 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
405 wxTextCtrl header file.
407 Note that independently of this setting you can always use wxTextCtrl itself
408 in a stream-like manner:
412 wxTextCtrl *control = new wxTextCtrl(...);
414 *control << 123.456 << " some text\n";
418 always works. However the possibility to create an ostream associated with
419 wxTextCtrl may be useful if you need to redirect the output of a function
420 taking an ostream as parameter to a text control.
422 Another commonly requested need is to redirect {\bf std::cout} to the text
423 control. This could be done in the following way:
429 wxTextCtrl *control = new wxTextCtrl(...);
431 std::streambuf *sbOld = std::cout.rdbuf();
432 std::cout.rdbuf(*control);
434 // use cout as usual, the output appears in the text control
437 std::cout.rdbuf(sbOld);
441 But wxWidgets provides a convenient class to make it even simpler so instead
448 wxTextCtrl *control = new wxTextCtrl(...);
450 wxStreamToTextRedirector redirect(control);
452 // all output to cout goes into the text control until the exit from current
457 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
460 \wxheading{Event handling}
462 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
463 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
464 automatically, when the control has the focus.
466 To process input from a text control, use these event handler macros to direct input to member
467 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
470 \begin{twocollist}\itemsep=0pt
471 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
472 generated when the text changes. Notice that this event will always be sent
473 when the text controls contents changes - whether this is due to user input or
474 comes from the program itself (for example, if SetValue() is called)}
475 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
476 generated when enter is pressed in a text control (which must have
477 wxTE\_PROCESS\_ENTER style for this event to be generated).}
478 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occurred over an URL
479 in the text control (wxMSW and wxGTK2 only)}
480 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
481 into the control than the limit set by
482 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
485 \latexignore{\rtfignore{\wxheading{Members}}}
488 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlctor}
490 \func{}{wxTextCtrl}{\void}
494 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
495 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
496 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
498 Constructor, creating and showing a text control.
500 \wxheading{Parameters}
502 \docparam{parent}{Parent window. Should not be NULL.}
504 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
506 \docparam{value}{Default text value.}
508 \docparam{pos}{Text control position.}
510 \docparam{size}{Text control size.}
512 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
514 \docparam{validator}{Window validator.}
516 \docparam{name}{Window name.}
520 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
521 for multi-line text controls.
522 Without a horizontal scrollbar, text lines that don't fit in the control's
523 size will be wrapped (but no newline character is inserted). Single line
524 controls don't have a horizontal scrollbar, the text is automatically scrolled
525 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
528 % VZ: this is no longer true
529 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
530 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
535 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
538 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}\label{wxtextctrldtor}
540 \func{}{\destruct{wxTextCtrl}}{\void}
542 Destructor, destroying the text control.
545 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
547 \func{void}{AppendText}{\param{const wxString\& }{ text}}
549 Appends the text to the end of the text control.
551 \wxheading{Parameters}
553 \docparam{text}{Text to write to the text control.}
557 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
558 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
562 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
565 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
567 \func{virtual bool}{CanCopy}{\void}
569 Returns {\tt true} if the selection can be copied to the clipboard.
572 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
574 \func{virtual bool}{CanCut}{\void}
576 Returns {\tt true} if the selection can be cut to the clipboard.
579 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
581 \func{virtual bool}{CanPaste}{\void}
583 Returns {\tt true} if the contents of the clipboard can be pasted into the
584 text control. On some platforms (Motif, GTK) this is an approximation
585 and returns {\tt true} if the control is editable, {\tt false} otherwise.
588 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
590 \func{virtual bool}{CanRedo}{\void}
592 Returns {\tt true} if there is a redo facility available and the last operation
596 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
598 \func{virtual bool}{CanUndo}{\void}
600 Returns {\tt true} if there is an undo facility available and the last operation
604 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
606 \func{virtual void}{Clear}{\void}
608 Clears the text in the control.
610 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
614 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
616 \func{virtual void}{Copy}{\void}
618 Copies the selected text to the clipboard under Motif and MS Windows.
621 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
623 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
624 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
625 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
627 Creates the text control for two-step construction. Derived classes
628 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}\rtfsp
632 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
634 \func{virtual void}{Cut}{\void}
636 Copies the selected text to the clipboard and removes the selection.
639 \membersection{wxTextCtrl::DiscardEdits}\label{wxtextctrldiscardedits}
641 \func{void}{DiscardEdits}{\void}
643 Resets the internal `modified' flag as if the current edits had been saved.
646 \membersection{wxTextCtrl::EmulateKeyPress}\label{wxtextctrlemulatekeypress}
648 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
650 This functions inserts into the control the character which would have been
651 inserted if the given key event had occurred in the text control. The
652 {\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
653 handler previously by wxWidgets.
655 Please note that this function doesn't currently work correctly for all keys
656 under any platform but MSW.
658 \wxheading{Return value}
660 {\tt true} if the event resulted in a change to the control, {\tt false}
664 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
666 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
668 Returns the style currently used for the new text.
672 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
675 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
677 \constfunc{virtual long}{GetInsertionPoint}{\void}
679 Returns the insertion point. This is defined as the zero based index of the
680 character position to the right of the insertion point. For example, if
681 the insertion point is at the end of the text control, it is equal to
682 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
683 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
685 The following code snippet safely returns the character at the insertion
686 point or the zero character if the point is at the end of the control.
690 char GetCurrentChar(wxTextCtrl *tc) {
691 if (tc->GetInsertionPoint() == tc->GetLastPosition())
693 return tc->GetValue[tc->GetInsertionPoint()];
699 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
701 \constfunc{virtual wxTextPos}{GetLastPosition}{\void}
703 Returns the zero based index of the last position in the text control,
704 which is equal to the number of characters in the control.
707 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
709 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
711 Gets the length of the specified line, not including any trailing newline
714 \wxheading{Parameters}
716 \docparam{lineNo}{Line number (starting from zero).}
718 \wxheading{Return value}
720 The length of the line, or -1 if {\it lineNo} was invalid.
723 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
725 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
727 Returns the contents of a given line in the text control, not including
728 any trailing newline character(s).
730 \wxheading{Parameters}
732 \docparam{lineNo}{The line number, starting from zero.}
734 \wxheading{Return value}
736 The contents of the line.
739 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
741 \constfunc{int}{GetNumberOfLines}{\void}
743 Returns the number of lines in the text control buffer.
747 Note that even empty text controls have one line (where the insertion point
748 is), so GetNumberOfLines() never returns $0$.
750 For wxGTK using GTK+ 1.2.x and earlier, the number of lines in a multi-line
751 text control is calculated by actually counting newline characters in the
752 buffer, i.e. this function returns the number of logical lines and doesn't
753 depend on whether any of them are wrapped. For all the other platforms, the
754 number of physical lines in the control is returned.
756 Also note that you may wish to avoid using functions that work with line
757 numbers if you are working with controls that contain large amounts of text as
758 this function has $O(N)$ complexity for $N$ being the number of lines.
761 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
763 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
765 Returns the string containing the text starting in the positions {\it from} and
766 up to {\it to} in the control. The positions must have been returned by another
769 Please note that the positions in a multiline wxTextCtrl do {\bf not}
770 correspond to the indices in the string returned by
771 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
772 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
773 obtain the correct results instead of extracting parts of the entire value. It
774 may also be more efficient, especially if the control contains a lot of data.
777 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
779 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
781 Gets the current selection span. If the returned values are equal, there was
784 Please note that the indices returned may be used with the other wxTextctrl
785 methods but don't necessarily represent the correct indices into the string
786 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
787 under Windows (at least,) you should use
788 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
791 \wxheading{Parameters}
793 \docparam{from}{The returned first position.}
795 \docparam{to}{The returned last position.}
797 \pythonnote{The wxPython version of this method returns a tuple
798 consisting of the from and to values.}
800 \perlnote{In wxPerl this method takes no parameter and returns a
801 2-element list {\tt ( from, to )}.}
804 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
806 \func{virtual wxString}{GetStringSelection}{\void}
808 Gets the text currently selected in the control. If there is no selection, the
809 returned string is empty.
812 \membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
814 \func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
816 Returns the style at this position in the text control. Not all platforms
817 support this function.
819 \wxheading{Return value}
821 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
822 the styles are not supported under this platform.
826 \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
829 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
831 \constfunc{wxString}{GetValue}{\void}
833 Gets the contents of the control. Notice that for a multiline text control,
834 the lines will be separated by (Unix-style) $\backslash$n characters, even
835 under Windows where they are separated by a $\backslash$r$\backslash$n
836 sequence in the native control.
839 \membersection{wxTextCtrl::HitTest}\label{wxtextctrlhittest}
841 \constfunc{wxTextCtrlHitTestResult}{HitTest}{\param{const wxPoint\& }{pt}, \param{wxTextCoord }{*col}, \param{wxTextCoord }{*row}}
843 This function finds the character at the specified position expressed in
844 pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
845 of the character closest to this position are returned in the \arg{col} and
846 \arg{row} parameters (unless the pointers are {\tt NULL} which is allowed).
848 Please note that this function is currently only implemented in wxUniv,
849 wxMSW and wxGTK2 ports.
853 \helpref{PositionToXY}{wxtextctrlpositiontoxy}, \helpref{XYToPosition}{wxtextctrlxytoposition}
855 \perlnote{In wxPerl this function takes only the position argument and
856 returns a 3-element list \texttt{(result, col, row)}}.
858 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
860 \constfunc{bool}{IsEditable}{\void}
862 Returns {\tt true} if the controls contents may be edited by user (note that it
863 always can be changed by the program), i.e. if the control hasn't been put in
864 read-only mode by a previous call to
865 \helpref{SetEditable}{wxtextctrlseteditable}.
868 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
870 \constfunc{bool}{IsModified}{\void}
872 Returns {\tt true} if the text has been modified by user. Note that calling
873 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
877 \helpref{MarkDirty}{wxtextctrlmarkdirty}
880 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
882 \constfunc{bool}{IsMultiLine}{\void}
884 Returns {\tt true} if this is a multi line edit control and {\tt false}
889 \helpref{IsSingleLine}{wxtextctrlissingleline}
892 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
894 \constfunc{bool}{IsSingleLine}{\void}
896 Returns {\tt true} if this is a single line edit control and {\tt false}
901 \helpref{IsMultiLine}{wxtextctrlissingleline}
904 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
906 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
908 Loads and displays the named file, if it exists.
910 \wxheading{Parameters}
912 \docparam{filename}{The filename of the file to load.}
914 \wxheading{Return value}
916 {\tt true} if successful, {\tt false} otherwise.
918 % VZ: commenting this out as: (a) the docs are wrong (you can't replace
919 % anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
920 %% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
922 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
924 %% Default handler for character input.
926 %% \wxheading{Remarks}
928 %% It is possible to intercept character
929 %% input by overriding this member. Call this function
930 %% to let the default behaviour take place; not calling
931 %% it results in the character being ignored. You can
932 %% replace the {\it keyCode} member of {\it event} to
933 %% translate keystrokes.
935 %% Note that Windows and Motif have different ways
936 %% of implementing the default behaviour. In Windows,
937 %% calling wxTextCtrl::OnChar immediately
938 %% processes the character. In Motif,
939 %% calling this function simply sets a flag
940 %% to let default processing happen. This might affect
941 %% the way in which you write your OnChar function
942 %% on different platforms.
944 %% \wxheading{See also}
946 %% \helpref{wxKeyEvent}{wxkeyevent}
949 \membersection{wxTextCtrl::MarkDirty}\label{wxtextctrlmarkdirty}
951 \func{void}{MarkDirty}{\void}
953 Mark text as modified (dirty).
957 \helpref{IsModified}{wxtextctrlismodified}
960 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
962 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
964 This event handler function implements default drag and drop behaviour, which
965 is to load the first dropped file into the control.
967 \wxheading{Parameters}
969 \docparam{event}{The drop files event.}
973 This is not implemented on non-Windows platforms.
977 \helpref{wxDropFilesEvent}{wxdropfilesevent}
980 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
982 \func{virtual void}{Paste}{\void}
984 Pastes text from the clipboard to the text item.
987 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
989 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
991 Converts given position to a zero-based column, line number pair.
993 \wxheading{Parameters}
995 \docparam{pos}{Position.}
997 \docparam{x}{Receives zero based column number.}
999 \docparam{y}{Receives zero based line number.}
1001 \wxheading{Return value}
1003 {\tt true} on success, {\tt false} on failure (most likely due to a too large position
1006 \wxheading{See also}
1008 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
1010 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
1011 y values, so (x,y) = PositionToXY() is equivalent to the call described
1014 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
1015 returns a 2-element list {\tt ( x, y )}.}
1018 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
1020 \func{virtual void}{Redo}{\void}
1022 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
1023 if there is no redo facility.
1026 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
1028 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
1030 Removes the text starting at the first given position up to (but not including)
1031 the character at the last position.
1033 \wxheading{Parameters}
1035 \docparam{from}{The first position.}
1037 \docparam{to}{The last position.}
1040 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
1042 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
1044 Replaces the text starting at the first position up to (but not including)
1045 the character at the last position with the given text.
1047 \wxheading{Parameters}
1049 \docparam{from}{The first position.}
1051 \docparam{to}{The last position.}
1053 \docparam{value}{The value to replace the existing text with.}
1056 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
1058 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
1060 Saves the contents of the control in a text file.
1062 \wxheading{Parameters}
1064 \docparam{filename}{The name of the file in which to save the text.}
1066 \wxheading{Return value}
1068 {\tt true} if the operation was successful, {\tt false} otherwise.
1071 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
1073 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
1075 Changes the default style to use for the new text which is going to be added
1076 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
1077 \helpref{AppendText}{wxtextctrlappendtext}.
1079 If either of the font, foreground, or background colour is not set in\rtfsp
1080 {\it style}, the values of the previous default style are used for them. If
1081 the previous default style didn't set them neither, the global font or colours
1082 of the text control itself are used as fall back.
1084 However if the {\it style} parameter is the default wxTextAttr, then the
1085 default style is just reset (instead of being combined with the new style which
1086 wouldn't change it at all).
1088 \wxheading{Parameters}
1090 \docparam{style}{The style for the new text.}
1092 \wxheading{Return value}
1094 {\tt true} on success, {\tt false} if an error occurred - may also mean that
1095 the styles are not supported under this platform.
1097 \wxheading{See also}
1099 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
1102 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
1104 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
1106 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
1108 \wxheading{Parameters}
1110 \docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
1112 \wxheading{See also}
1114 \helpref{IsEditable}{wxtextctrliseditable}
1117 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
1119 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
1121 Sets the insertion point at the given position.
1123 \wxheading{Parameters}
1125 \docparam{pos}{Position to set.}
1128 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
1130 \func{virtual void}{SetInsertionPointEnd}{\void}
1132 Sets the insertion point at the end of the text control. This is equivalent
1133 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
1136 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
1138 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
1140 This function sets the maximum number of characters the user can enter into the
1141 control. In other words, it allows to limit the text value length to {\it len}
1142 not counting the terminating {\tt NUL} character.
1144 If {\it len} is $0$, the previously set max length limit, if any, is discarded
1145 and the user may enter as much text as the underlying native text control
1146 widget supports (typically at least 32Kb).
1148 If the user tries to enter more characters into the text control when it
1149 already is filled up to the maximal length, a
1150 {\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
1151 (giving it the possibility to show an explanatory message, for example) and the
1152 extra input is discarded.
1154 Note that under GTK+, this function may only be used with single line text controls.
1156 \wxheading{Compatibility}
1158 Only implemented in wxMSW/wxGTK starting with wxWidgets 2.3.2.
1161 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
1163 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
1165 Selects the text starting at the first position up to (but not including) the
1166 character at the last position. If both parameters are equal to $-1$ all text
1167 in the control is selected.
1169 \wxheading{Parameters}
1171 \docparam{from}{The first position.}
1173 \docparam{to}{The last position.}
1176 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
1178 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
1180 Changes the style of the given range. If any attribute within {\it style} is
1181 not set, the corresponding attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
1183 \wxheading{Parameters}
1185 \docparam{start}{The start of the range to change.}
1187 \docparam{end}{The end of the range to change.}
1189 \docparam{style}{The new style for the range.}
1191 \wxheading{Return value}
1193 {\tt true} on success, {\tt false} if an error occurred - it may also mean that
1194 the styles are not supported under this platform.
1196 \wxheading{See also}
1198 \helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
1201 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
1203 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
1205 Sets the text value and marks the control as not-modified (which means that
1206 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
1207 after the call to SetValue).
1209 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
1212 \wxheading{Parameters}
1214 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
1217 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
1219 \func{void}{ShowPosition}{\param{long}{ pos}}
1221 Makes the line containing the given position visible.
1223 \wxheading{Parameters}
1225 \docparam{pos}{The position that should be visible.}
1228 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
1230 \func{virtual void}{Undo}{\void}
1232 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
1233 if there is no undo facility.
1236 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1238 \func{void}{WriteText}{\param{const wxString\& }{ text}}
1240 Writes the text into the text control at the current insertion position.
1242 \wxheading{Parameters}
1244 \docparam{text}{Text to write to the text control.}
1248 Newlines in the text string
1249 are the only control characters allowed, and they will cause appropriate
1250 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
1252 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.
1255 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1257 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
1259 Converts the given zero based column and line number to a position.
1261 \wxheading{Parameters}
1263 \docparam{x}{The column number.}
1265 \docparam{y}{The line number.}
1267 \wxheading{Return value}
1269 The position value, or -1 if {\tt x} or {\tt y} was invalid.
1272 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1274 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1276 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1278 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1280 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1282 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1284 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1286 Operator definitions for appending to a text control, for example:
1289 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1291 (*wnd) << "Welcome to text control number " << 1 << ".\n";