1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxTextAttr class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 wxTextAttr represents the character and paragraph attributes, or style,
14 for a range of text in a wxTextCtrl or wxRichTextCtrl.
16 When setting up a wxTextAttr object, pass a bitlist mask to
17 wxTextAttr::SetFlags to
18 indicate which style elements should be changed. As a convenience, when you
20 as SetFont, the relevant bit will be set.
26 wxTextCtrl, wxRichTextCtrl
36 wxTextAttr(const wxColour
& colText
,
37 const wxColour
& colBack
= wxNullColour
,
38 const wxFont
& font
= wxNullFont
,
39 wxTextAttrAlignment alignment
= wxTEXT_ALIGNMENT_DEFAULT
);
40 wxTextAttr(const wxTextAttr
& attr
);
44 Applies the attributes in @a style to the original object, but not those
45 attributes from @a style that are the same as those in @a compareWith (if passed).
47 bool Apply(const wxTextAttr
& style
,
48 const wxTextAttr
* compareWith
= NULL
);
51 Creates a font from the font attributes.
53 wxFont
CreateFont() const;
56 Returns the alignment flags.
57 See SetAlignment() for a list of available styles.
59 wxTextAttrAlignment
GetAlignment() const;
62 Returns the background colour.
64 const wxColour
GetBackgroundColour() const;
67 Returns a string containing the name of the font associated with the bullet
69 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
71 const wxString
GetBulletFont() const;
74 Returns the standard bullet name, applicable if the bullet style is
75 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
76 Currently the following standard bullet names are supported:
81 For wxRichTextCtrl users only: if you wish your rich text controls to support
82 further bullet graphics, you can derive a
83 class from wxRichTextRenderer or wxRichTextStdRenderer, override @c
84 DrawStandardBullet and @c EnumerateStandardBulletNames, and
85 set an instance of the class using wxRichTextBuffer::SetRenderer.
87 const wxString
GetBulletName() const;
90 Returns the bullet number.
92 int GetBulletNumber() const;
95 Returns the bullet style.
96 See SetBulletStyle() for a list of available styles.
98 int GetBulletStyle() const;
101 Returns the bullet text, which could be a symbol, or (for example) cached
104 const wxString
GetBulletText() const;
107 Returns the name of the character style.
109 const wxString
GetCharacterStyleName() const;
112 Returns flags indicating which attributes are applicable.
113 See SetFlags() for a list of available flags.
115 long GetFlags() const;
118 Creates and returns a font specified by the font attributes in the wxTextAttr
120 wxTextAttr does not store a wxFont object, so this is only a temporary font.
122 efficiency, access the font attributes directly.
124 wxFont
GetFont() const;
127 Gets the font attributes from the given font, using only the attributes
128 specified by @e flags.
130 bool GetFontAttributes(const wxFont
& font
,
131 int flags
= wxTEXT_ATTR_FONT
);
134 Returns the font encoding.
136 wxFontEncoding
GetFontEncoding() const;
139 Returns the font face name.
141 const wxString
GetFontFaceName() const;
144 Returns the font size in points.
146 int GetFontSize() const;
149 Returns the font style.
151 int GetFontStyle() const;
154 Returns @true if the font is underlined.
156 bool GetFontUnderlined() const;
159 Returns the font weight.
161 int GetFontWeight() const;
164 Returns the left indent in tenths of a millimetre.
166 long GetLeftIndent() const;
169 Returns the left sub-indent in tenths of a millimetre.
171 long GetLeftSubIndent() const;
174 Returns the line spacing value, one of wxTEXT_ATTR_LINE_SPACING_NORMAL,
175 wxTEXT_ATTR_LINE_SPACING_HALF, and wxTEXT_ATTR_LINE_SPACING_TWICE.
177 int GetLineSpacing() const;
180 Returns the name of the list style.
182 const wxString
GetListStyleName() const;
185 Returns the outline level.
187 bool GetOutlineLevel() const;
190 Returns the space in tenths of a millimeter after the paragraph.
192 int GetParagraphSpacingAfter() const;
195 Returns the space in tenths of a millimeter before the paragraph.
197 int GetParagraphSpacingBefore() const;
200 Returns the name of the paragraph style.
202 const wxString
GetParagraphStyleName() const;
205 Returns the right indent in tenths of a millimeter.
207 long GetRightIndent() const;
210 Returns an array of tab stops, each expressed in tenths of a millimeter. Each
212 is measured from the left margin and therefore each value must be larger than
215 const wxArrayInt
GetTabs() const;
218 Returns the text foreground colour.
220 const wxColour
GetTextColour() const;
223 Returns the text effect bits of interest. See SetFlags() for further
226 int GetTextEffectFlags() const;
229 Returns the text effects, a bit list of styles. See SetTextEffects() for
232 int GetTextEffects() const;
235 Returns the URL for the content. Content with wxTEXT_ATTR_URL style
236 causes wxRichTextCtrl to show a hand cursor over it, and wxRichTextCtrl
238 a wxTextUrlEvent when the content is clicked.
240 const wxString
GetURL() const;
243 Returns @true if the attribute object specifies alignment.
245 bool HasAlignment() const;
248 Returns @true if the attribute object specifies a background colour.
250 bool HasBackgroundColour() const;
253 Returns @true if the attribute object specifies a standard bullet name.
255 bool HasBulletName() const;
258 Returns @true if the attribute object specifies a bullet number.
260 bool HasBulletNumber() const;
263 Returns @true if the attribute object specifies a bullet style.
265 bool HasBulletStyle() const;
268 Returns @true if the attribute object specifies bullet text (usually
269 specifying a symbol).
271 bool HasBulletText() const;
274 Returns @true if the attribute object specifies a character style name.
276 bool HasCharacterStyleName() const;
279 Returns @true if the @a flag is present in the attribute object's flag
282 bool HasFlag(long flag
) const;
285 Returns @true if the attribute object specifies any font attributes.
287 bool HasFont() const;
290 Returns @true if the attribute object specifies an encoding.
292 bool HasFontEncoding() const;
295 Returns @true if the attribute object specifies a font face name.
297 bool HasFontFaceName() const;
300 Returns @true if the attribute object specifies italic style.
302 bool HasFontItalic() const;
305 Returns @true if the attribute object specifies a font point size.
307 bool HasFontSize() const;
310 Returns @true if the attribute object specifies either underlining or no
313 bool HasFontUnderlined() const;
316 Returns @true if the attribute object specifies font weight (bold, light or
319 bool HasFontWeight() const;
322 Returns @true if the attribute object specifies a left indent.
324 bool HasLeftIndent() const;
327 Returns @true if the attribute object specifies line spacing.
329 bool HasLineSpacing() const;
332 Returns @true if the attribute object specifies a list style name.
334 bool HasListStyleName() const;
337 Returns @true if the attribute object specifies an outline level.
339 bool HasOutlineLevel() const;
342 Returns @true if the attribute object specifies a page break before this
345 bool HasPageBreak() const;
348 Returns @true if the attribute object specifies spacing after a paragraph.
350 bool HasParagraphSpacingAfter() const;
353 Returns @true if the attribute object specifies spacing before a paragraph.
355 bool HasParagraphSpacingBefore() const;
358 Returns @true if the attribute object specifies a paragraph style name.
360 bool HasParagraphStyleName() const;
363 Returns @true if the attribute object specifies a right indent.
365 bool HasRightIndent() const;
368 Returns @true if the attribute object specifies tab stops.
370 bool HasTabs() const;
373 Returns @true if the attribute object specifies a text foreground colour.
375 bool HasTextColour() const;
378 Returns @true if the attribute object specifies text effects.
380 bool HasTextEffects() const;
383 Returns @true if the attribute object specifies a URL.
388 Returns @true if the object represents a character style, that is,
389 the flags specify a font or a text background or foreground colour.
391 bool IsCharacterStyle() const;
394 Returns @false if we have any attributes set, @true otherwise.
396 bool IsDefault() const;
399 Returns @true if the object represents a paragraph style, that is,
400 the flags specify alignment, indentation, tabs, paragraph spacing, or
403 bool IsParagraphStyle() const;
407 Creates a new @c wxTextAttr which is a merge of @a base and
408 @e overlay. Properties defined in @a overlay take precedence over those
409 in @e base. Properties undefined/invalid in both are undefined in the
412 void Merge(const wxTextAttr
& overlay
);
413 static wxTextAttr
Merge(const wxTextAttr
& base
,
414 const wxTextAttr
& overlay
);
418 Sets the paragraph alignment. These are the possible values for @e alignment:
420 Of these, wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented. In future justification
422 when printing or previewing, only.
424 void SetAlignment(wxTextAttrAlignment alignment
);
427 Sets the background colour.
429 void SetBackgroundColour(const wxColour
& colBack
);
432 Sets the name of the font associated with the bullet symbol.
433 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
435 void SetBulletFont(const wxString
& font
);
438 Sets the standard bullet name, applicable if the bullet style is
439 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
440 See GetBulletName() for a list
441 of supported names, and how to expand the range of supported types.
443 void SetBulletName(const wxString
& name
);
446 Sets the bullet number.
448 void SetBulletNumber(int n
);
451 Sets the bullet style. The following styles can be passed:
453 Currently wxTEXT_ATTR_BULLET_STYLE_BITMAP is not supported.
455 void SetBulletStyle(int style
);
458 Sets the bullet text, which could be a symbol, or (for example) cached outline
461 void SetBulletText(const wxString text
);
464 Sets the character style name.
466 void SetCharacterStyleName(const wxString
& name
);
469 Sets the flags determining which styles are being specified. The following
470 flags can be passed in a bitlist:
472 void SetFlags(long flags
);
475 Sets the attributes for the given font. Note that wxTextAttr does not store an
476 actual wxFont object.
478 void SetFont(const wxFont
& font
);
481 Sets the font encoding.
483 void SetFontEncoding(wxFontEncoding encoding
);
486 Sets the paragraph alignment.
488 void SetFontFaceName(const wxString
& faceName
);
491 Sets the font size in points.
493 void SetFontSize(int pointSize
);
496 Sets the font style (normal, italic or slanted).
498 void SetFontStyle(int fontStyle
);
501 Sets the font underlining.
503 void SetFontUnderlined(bool underlined
);
506 Sets the font weight.
508 void SetFontWeight(int fontWeight
);
511 Sets the left indent and left subindent in tenths of a millimetre.
512 The sub-indent is an offset from the left of the paragraph, and is used for all
514 first line in a paragraph. A positive value will cause the first line to appear
516 of the subsequent lines, and a negative value will cause the first line to be
518 relative to the subsequent lines.
519 wxRichTextBuffer uses indentation to render a bulleted item. The left indent is
521 the margin and the bullet. The content of the paragraph, including the first
523 at leftMargin + leftSubIndent. So the distance between the left edge of the
525 left of the actual paragraph is leftSubIndent.
527 void SetLeftIndent(int indent
, int subIndent
= 0);
530 Sets the line spacing. @a spacing is a multiple, where 10 means single-spacing,
531 15 means 1.5 spacing, and 20 means double spacing. The following constants are
532 defined for convenience:
534 void SetLineSpacing(int spacing
);
537 Sets the list style name.
539 void SetListStyleName(const wxString
& name
);
542 Specifies the outline level. Zero represents normal text. At present, the
544 not used, but may be used in future for determining list levels and for
546 that need to store document structure information.
548 void SetOutlineLevel(int level
);
551 Specifies a page break before this paragraph.
553 void SetPageBreak(bool pageBreak
= true);
556 Sets the spacing after a paragraph, in tenths of a millimetre.
558 void SetParagraphSpacingAfter(int spacing
);
561 Sets the spacing before a paragraph, in tenths of a millimetre.
563 void SetParagraphSpacingBefore(int spacing
);
566 Sets the name of the paragraph style.
568 void SetParagraphStyleName(const wxString
& name
);
571 Sets the right indent in tenths of a millimetre.
573 void SetRightIndent(int indent
);
576 Sets the tab stops, expressed in tenths of a millimetre.
577 Each stop is measured from the left margin and therefore each value must be
578 larger than the last.
580 void SetTabs(const wxArrayInt
& tabs
);
583 Sets the text foreground colout.
585 void SetTextColour(const wxColour
& colText
);
588 Sets the text effect bits of interest. You should also pass wxTEXT_ATTR_EFFECTS
590 See SetFlags() for further information.
592 void SetTextEffectFlags(int flags
);
595 Sets the text effects, a bit list of styles.
596 The following styles can be passed:
598 Of these, only wxTEXT_ATTR_EFFECT_CAPITALS and wxTEXT_ATTR_EFFECT_STRIKETHROUGH
600 wxTEXT_ATTR_EFFECT_CAPITALS capitalises text when displayed (leaving the case
602 text unchanged), and wxTEXT_ATTR_EFFECT_STRIKETHROUGH draws a line through text.
603 To set effects, you should also pass wxTEXT_ATTR_EFFECTS to SetFlags(), and call
604 SetTextEffectFlags() with the styles (taken from the
605 above set) that you are interested in setting.
607 void SetTextEffects(int effects
);
610 Sets the URL for the content. Sets the wxTEXT_ATTR_URL style; content with this
612 causes wxRichTextCtrl to show a hand cursor over it, and wxRichTextCtrl
614 a wxTextUrlEvent when the content is clicked.
616 void SetURL(const wxString
& url
);
619 Assignment from a wxTextAttr object.
621 void operator operator=(const wxTextAttr
& attr
);
627 @wxheader{textctrl.h}
629 A text control allows text to be displayed and edited. It may be
630 single line or multi-line.
633 @style{wxTE_PROCESS_ENTER}:
634 The control will generate the event wxEVT_COMMAND_TEXT_ENTER
635 (otherwise pressing Enter key is either processed internally by the
636 control or used for navigation between dialog controls).
637 @style{wxTE_PROCESS_TAB}:
638 The control will receive wxEVT_CHAR events for TAB pressed -
639 normally, TAB is used for passing to the next control in a dialog
640 instead. For the control created with this style, you can still use
641 Ctrl-Enter to pass to the next control from the keyboard.
642 @style{wxTE_MULTILINE}:
643 The text control allows multiple lines.
644 @style{wxTE_PASSWORD}:
645 The text will be echoed as asterisks.
646 @style{wxTE_READONLY}:
647 The text will not be user-editable.
649 Use rich text control under Win32, this allows to have more than
650 64KB of text in the control even under Win9x. This style is ignored
651 under other platforms.
653 Use rich text control version 2.0 or 3.0 under Win32, this style is
654 ignored under other platforms
655 @style{wxTE_AUTO_URL}:
656 Highlight the URLs and generate the wxTextUrlEvents when mouse
657 events occur over them. This style is only supported for wxTE_RICH
658 Win32 and multi-line wxGTK2 text controls.
659 @style{wxTE_NOHIDESEL}:
660 By default, the Windows text control doesn't show the selection
661 when it doesn't have focus - use this style to force it to always
662 show it. It doesn't do anything under other platforms.
664 A horizontal scrollbar will be created and used, so that text won't
665 be wrapped. No effect under wxGTK1.
666 @style{wxTE_NO_VSCROLL}:
667 For multiline controls only: vertical scrollbar will never be
668 created. This limits the amount of text which can be entered into
669 the control to what can be displayed in it under MSW but not under
670 GTK2. Currently not implemented for the other platforms.
672 The text in the control will be left-justified (default).
674 The text in the control will be centered (currently wxMSW and
677 The text in the control will be right-justified (currently wxMSW
679 @style{wxTE_DONTWRAP}:
680 Same as wxHSCROLL style: don't wrap at all, show horizontal
682 @style{wxTE_CHARWRAP}:
683 Wrap the lines too long to be shown entirely at any position
684 (wxUniv and wxGTK2 only).
685 @style{wxTE_WORDWRAP}:
686 Wrap the lines too long to be shown entirely at word boundaries
687 (wxUniv and wxGTK2 only).
688 @style{wxTE_BESTWRAP}:
689 Wrap the lines at word boundaries or at any other character if
690 there are words longer than the window width (this is the default).
691 @style{wxTE_CAPITALIZE}:
692 On PocketPC and Smartphone, causes the first letter to be
698 @appearance{textctrl.png}
701 wxTextCtrl::Create, wxValidator
703 class wxTextCtrl
: public wxControl
708 Constructor, creating and showing a text control.
711 Parent window. Should not be @NULL.
713 Control identifier. A value of -1 denotes a default value.
717 Text control position.
721 Window style. See wxTextCtrl.
727 @remarks The horizontal scrollbar (wxHSCROLL style flag) will only be
728 created for multi-line text controls. Without a
729 horizontal scrollbar, text lines that don't fit in the
730 control's size will be wrapped (but no newline
731 character is inserted). Single line controls don't have
732 a horizontal scrollbar, the text is automatically
733 scrolled so that the insertion point is always visible.
735 @see Create(), wxValidator
738 wxTextCtrl(wxWindow
* parent
, wxWindowID id
,
739 const wxString
& value
= "",
740 const wxPoint
& pos
= wxDefaultPosition
,
741 const wxSize
& size
= wxDefaultSize
,
743 const wxValidator
& validator
= wxDefaultValidator
,
744 const wxString
& name
= wxTextCtrlNameStr
);
748 Destructor, destroying the text control.
753 Appends the text to the end of the text control.
756 Text to write to the text control.
758 @remarks After the text is appended, the insertion point will be at the
759 end of the text control. If this behaviour is not
760 desired, the programmer should use GetInsertionPoint
761 and SetInsertionPoint.
765 void AppendText(const wxString
& text
);
768 Call this function to enable auto-completion of the text typed in a single-line
769 text control using the given @e choices.
770 Notice that currently this function is only implemented in wxGTK2 and wxMSW
771 ports and does nothing under the other platforms.
772 This function is new since wxWidgets version 2.9.0
774 @returns @true if the auto-completion was enabled or @false if the
775 operation failed, typically because auto-completion is
776 not supported by the current platform.
778 @see AutoCompleteFileNames()
780 bool AutoComplete(const wxArrayString
& choices
);
783 Call this function to enable auto-completion of the text typed in a single-line
784 text control using all valid file system paths.
785 Notice that currently this function is only implemented in wxGTK2 port and does
786 nothing under the other platforms.
787 This function is new since wxWidgets version 2.9.0
789 @returns @true if the auto-completion was enabled or @false if the
790 operation failed, typically because auto-completion is
791 not supported by the current platform.
795 bool AutoCompleteFileNames();
798 Returns @true if the selection can be copied to the clipboard.
800 virtual bool CanCopy();
803 Returns @true if the selection can be cut to the clipboard.
805 virtual bool CanCut();
808 Returns @true if the contents of the clipboard can be pasted into the
809 text control. On some platforms (Motif, GTK) this is an approximation
810 and returns @true if the control is editable, @false otherwise.
812 virtual bool CanPaste();
815 Returns @true if there is a redo facility available and the last operation
818 virtual bool CanRedo();
821 Returns @true if there is an undo facility available and the last operation
824 virtual bool CanUndo();
827 Sets the text value and marks the control as not-modified (which means that
828 IsModified() would return @false immediately
829 after the call to SetValue).
830 Note that this function will not generate the @c wxEVT_COMMAND_TEXT_UPDATED
832 This is the only difference with SetValue().
833 See @ref overview_progevent "this topic" for more information.
834 This function is new since wxWidgets version 2.7.1
837 The new value to set. It may contain newline characters if the text control
840 virtual void ChangeValue(const wxString
& value
);
843 Clears the text in the control.
844 Note that this function will generate a @c wxEVT_COMMAND_TEXT_UPDATED
847 virtual void Clear();
850 Copies the selected text to the clipboard under Motif and MS Windows.
855 Creates the text control for two-step construction. Derived classes
856 should call or replace this function. See wxTextCtrl()
859 bool Create(wxWindow
* parent
, wxWindowID id
,
860 const wxString
& value
= "",
861 const wxPoint
& pos
= wxDefaultPosition
,
862 const wxSize
& size
= wxDefaultSize
,
864 const wxValidator
& validator
= wxDefaultValidator
,
865 const wxString
& name
= wxTextCtrlNameStr
);
868 Copies the selected text to the clipboard and removes the selection.
873 Resets the internal 'modified' flag as if the current edits had been saved.
878 This functions inserts into the control the character which would have been
879 inserted if the given key event had occurred in the text control. The
880 @a event object should be the same as the one passed to @c EVT_KEY_DOWN
881 handler previously by wxWidgets.
882 Please note that this function doesn't currently work correctly for all keys
883 under any platform but MSW.
885 @returns @true if the event resulted in a change to the control, @false
888 bool EmulateKeyPress(const wxKeyEvent
& event
);
891 Returns the style currently used for the new text.
893 @see SetDefaultStyle()
895 const wxTextAttr
GetDefaultStyle() const;
898 Returns the insertion point. This is defined as the zero based index of the
899 character position to the right of the insertion point. For example, if
900 the insertion point is at the end of the text control, it is equal to
901 both GetValue().Length() and
903 The following code snippet safely returns the character at the insertion
904 point or the zero character if the point is at the end of the control.
906 virtual long GetInsertionPoint() const;
909 Returns the zero based index of the last position in the text control,
910 which is equal to the number of characters in the control.
912 virtual wxTextPos
GetLastPosition() const;
915 Gets the length of the specified line, not including any trailing newline
919 Line number (starting from zero).
921 @returns The length of the line, or -1 if lineNo was invalid.
923 int GetLineLength(long lineNo
) const;
926 Returns the contents of a given line in the text control, not including
927 any trailing newline character(s).
930 The line number, starting from zero.
932 @returns The contents of the line.
934 wxString
GetLineText(long lineNo
) const;
937 Returns the number of lines in the text control buffer.
939 @remarks Note that even empty text controls have one line (where the
940 insertion point is), so GetNumberOfLines() never
943 int GetNumberOfLines() const;
946 Returns the string containing the text starting in the positions @a from and
947 up to @a to in the control. The positions must have been returned by another
949 Please note that the positions in a multiline wxTextCtrl do @b not
950 correspond to the indices in the string returned by
951 GetValue() because of the different new line
952 representations (@c CR or @c CR LF) and so this method should be used to
953 obtain the correct results instead of extracting parts of the entire value. It
954 may also be more efficient, especially if the control contains a lot of data.
956 virtual wxString
GetRange(long from
, long to
) const;
959 Gets the current selection span. If the returned values are equal, there was
961 Please note that the indices returned may be used with the other wxTextctrl
962 methods but don't necessarily represent the correct indices into the string
963 returned by GetValue() for multiline controls
964 under Windows (at least,) you should use
965 GetStringSelection() to get the selected
969 The returned first position.
971 The returned last position.
973 virtual void GetSelection(long* from
, long* to
) const;
976 Gets the text currently selected in the control. If there is no selection, the
977 returned string is empty.
979 virtual wxString
GetStringSelection();
982 Returns the style at this position in the text control. Not all platforms
983 support this function.
985 @returns @true on success, @false if an error occurred - it may also mean
986 that the styles are not supported under this platform.
988 @see SetStyle(), wxTextAttr
990 bool GetStyle(long position
, wxTextAttr
& style
);
993 Gets the contents of the control. Notice that for a multiline text control,
994 the lines will be separated by (Unix-style) \n characters, even
995 under Windows where they are separated by a \r\n
996 sequence in the native control.
998 wxString
GetValue() const;
1001 This function finds the character at the specified position expressed in
1002 pixels. If the return code is not @c wxTE_HT_UNKNOWN the row and column
1003 of the character closest to this position are returned in the @a col and
1004 @a row parameters (unless the pointers are @NULL which is allowed).
1005 Please note that this function is currently only implemented in wxUniv,
1006 wxMSW and wxGTK2 ports.
1008 @see PositionToXY(), XYToPosition()
1010 wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
1012 wxTextCoord row
) const;
1015 Returns @true if the controls contents may be edited by user (note that it
1016 always can be changed by the program), i.e. if the control hasn't been put in
1017 read-only mode by a previous call to
1020 bool IsEditable() const;
1023 Returns @true if the control is currently empty. This is the same as
1024 @c GetValue().empty() but can be much more efficient for the multiline
1025 controls containing big amounts of text.
1026 This function is new since wxWidgets version 2.7.1
1028 bool IsEmpty() const;
1031 Returns @true if the text has been modified by user. Note that calling
1032 SetValue() doesn't make the control modified.
1036 bool IsModified() const;
1039 Returns @true if this is a multi line edit control and @false
1044 bool IsMultiLine() const;
1047 Returns @true if this is a single line edit control and @false
1050 @see @ref issingleline() IsMultiLine
1052 bool IsSingleLine() const;
1055 Loads and displays the named file, if it exists.
1058 The filename of the file to load.
1060 The type of file to load. This is currently ignored in wxTextCtrl.
1062 @returns @true if successful, @false otherwise.
1064 bool LoadFile(const wxString
& filename
,
1065 int fileType
= wxTEXT_TYPE_ANY
);
1068 Mark text as modified (dirty).
1075 This event handler function implements default drag and drop behaviour, which
1076 is to load the first dropped file into the control.
1079 The drop files event.
1081 @remarks This is not implemented on non-Windows platforms.
1083 @see wxDropFilesEvent
1085 void OnDropFiles(wxDropFilesEvent
& event
);
1088 Pastes text from the clipboard to the text item.
1090 virtual void Paste();
1093 Converts given position to a zero-based column, line number pair.
1098 Receives zero based column number.
1100 Receives zero based line number.
1102 @returns @true on success, @false on failure (most likely due to a too
1103 large position parameter).
1107 bool PositionToXY(long pos
, long* x
, long* y
) const;
1110 If there is a redo facility and the last operation can be redone, redoes the
1111 last operation. Does nothing
1112 if there is no redo facility.
1114 virtual void Redo();
1117 Removes the text starting at the first given position up to (but not including)
1118 the character at the last position.
1125 virtual void Remove(long from
, long to
);
1128 Replaces the text starting at the first position up to (but not including)
1129 the character at the last position with the given text.
1136 The value to replace the existing text with.
1138 virtual void Replace(long from
, long to
, const wxString
& value
);
1141 Saves the contents of the control in a text file.
1144 The name of the file in which to save the text.
1146 The type of file to save. This is currently ignored in wxTextCtrl.
1148 @returns @true if the operation was successful, @false otherwise.
1150 bool SaveFile(const wxString
& filename
,
1151 int fileType
= wxTEXT_TYPE_ANY
);
1154 Changes the default style to use for the new text which is going to be added
1155 to the control using WriteText() or
1157 If either of the font, foreground, or background colour is not set in
1158 @e style, the values of the previous default style are used for them. If
1159 the previous default style didn't set them neither, the global font or colours
1160 of the text control itself are used as fall back.
1161 However if the @a style parameter is the default wxTextAttr, then the
1162 default style is just reset (instead of being combined with the new style which
1163 wouldn't change it at all).
1166 The style for the new text.
1168 @returns @true on success, @false if an error occurred - may also mean that
1169 the styles are not supported under this platform.
1171 @see GetDefaultStyle()
1173 bool SetDefaultStyle(const wxTextAttr
& style
);
1176 Makes the text item editable or read-only, overriding the @b wxTE_READONLY flag.
1179 If @true, the control is editable. If @false, the control is read-only.
1183 virtual void SetEditable(const bool editable
);
1186 Sets the insertion point at the given position.
1191 virtual void SetInsertionPoint(long pos
);
1194 Sets the insertion point at the end of the text control. This is equivalent
1195 to wxTextCtrl::SetInsertionPoint(wxTextCtrl::GetLastPosition()).
1197 virtual void SetInsertionPointEnd();
1200 This function sets the maximum number of characters the user can enter into the
1201 control. In other words, it allows to limit the text value length to @e len
1202 not counting the terminating @c NUL character.
1203 If @a len is 0, the previously set max length limit, if any, is discarded
1204 and the user may enter as much text as the underlying native text control
1205 widget supports (typically at least 32Kb).
1206 If the user tries to enter more characters into the text control when it
1207 already is filled up to the maximal length, a
1208 @c wxEVT_COMMAND_TEXT_MAXLEN event is sent to notify the program about it
1209 (giving it the possibility to show an explanatory message, for example) and the
1210 extra input is discarded.
1211 Note that under GTK+, this function may only be used with single line text
1214 virtual void SetMaxLength(unsigned long len
);
1217 Marks the control as being modified by the user or not.
1219 @see MarkDirty(), DiscardEdits()
1221 void SetModified(bool modified
);
1224 Selects the text starting at the first position up to (but not including) the
1225 character at the last position. If both parameters are equal to -1 all text
1226 in the control is selected.
1233 virtual void SetSelection(long from
, long to
);
1236 Changes the style of the given range. If any attribute within @a style is
1237 not set, the corresponding attribute from GetDefaultStyle() is used.
1240 The start of the range to change.
1242 The end of the range to change.
1244 The new style for the range.
1246 @returns @true on success, @false if an error occurred - it may also mean
1247 that the styles are not supported under this platform.
1249 @see GetStyle(), wxTextAttr
1251 bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
1254 Sets the text value and marks the control as not-modified (which means that
1255 IsModified() would return @false immediately
1256 after the call to SetValue).
1257 Note that this function will generate a @c wxEVT_COMMAND_TEXT_UPDATED
1259 This function is deprecated and should not be used in new code. Please use the
1260 ChangeValue() function instead.
1263 The new value to set. It may contain newline characters if the text control
1266 virtual void SetValue(const wxString
& value
);
1269 Makes the line containing the given position visible.
1272 The position that should be visible.
1274 void ShowPosition(long pos
);
1277 If there is an undo facility and the last operation can be undone, undoes the
1278 last operation. Does nothing
1279 if there is no undo facility.
1281 virtual void Undo();
1284 Writes the text into the text control at the current insertion position.
1287 Text to write to the text control.
1289 @remarks Newlines in the text string are the only control characters
1290 allowed, and they will cause appropriate line breaks.
1291 See () and AppendText() for more
1292 convenient ways of writing to the window.
1294 void WriteText(const wxString
& text
);
1297 Converts the given zero based column and line number to a position.
1304 @returns The position value, or -1 if x or y was invalid.
1306 long XYToPosition(long x
, long y
);
1310 Operator definitions for appending to a text control, for example:
1312 wxTextCtrl
operator(const wxString
& s
);
1313 wxTextCtrl
operator(int i
);
1314 wxTextCtrl
operator(long i
);
1315 wxTextCtrl
operator(float f
);
1316 wxTextCtrl
operator(double d
);
1317 wxTextCtrl
operator(char c
);
1323 @class wxStreamToTextRedirector
1324 @wxheader{textctrl.h}
1326 This class can be used to (temporarily) redirect all output sent to a C++
1327 ostream object to a wxTextCtrl instead.
1329 @b NB: Some compilers and/or build configurations don't support multiply
1330 inheriting wxTextCtrl from @c std::streambuf in which
1331 case this class is not compiled in. You also must have @c wxUSE_STD_IOSTREAM
1332 option on (i.e. set to 1) in your setup.h to be able to use it. Under Unix,
1333 specify @c --enable-std_iostreams switch when running configure for this.
1338 using namespace std;
1340 wxTextCtrl *text = new wxTextCtrl(...);
1343 wxStreamToTextRedirector redirect(text);
1345 // this goes to the text control
1346 cout "Hello, text!" endl;
1349 // this goes somewhere else, presumably to stdout
1350 cout "Hello, console!" endl;
1360 class wxStreamToTextRedirector
1364 The constructor starts redirecting output sent to @a ostr or @e cout for
1365 the default parameter value to the text control @e text.
1368 The text control to append output too, must be non-@NULL
1370 The C++ stream to redirect, cout is used if it is @NULL
1372 wxStreamToTextRedirector(wxTextCtrl text
, ostream
* ostr
= NULL
);
1375 When a wxStreamToTextRedirector object is destroyed, the redirection is ended
1376 and any output sent to the C++ ostream which had been specified at the time of
1377 the object construction will go to its original destination.
1379 ~wxStreamToTextRedirector();