1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTextAttr
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 wxTextCtrl style flags
12 #define wxTE_NO_VSCROLL 0x0002
14 #define wxTE_READONLY 0x0010
15 #define wxTE_MULTILINE 0x0020
16 #define wxTE_PROCESS_TAB 0x0040
19 #define wxTE_LEFT 0x0000 // 0x0000
20 #define wxTE_CENTER wxALIGN_CENTER_HORIZONTAL // 0x0100
21 #define wxTE_RIGHT wxALIGN_RIGHT // 0x0200
22 #define wxTE_CENTRE wxTE_CENTER
24 // this style means to use RICHEDIT control and does something only under wxMSW
25 // and Win32 and is silently ignored under all other platforms
26 #define wxTE_RICH 0x0080
28 #define wxTE_PROCESS_ENTER 0x0400
29 #define wxTE_PASSWORD 0x0800
31 // automatically detect the URLs and generate the events when mouse is
32 // moved/clicked over an URL
34 // this is for Win32 richedit and wxGTK2 multiline controls only so far
35 #define wxTE_AUTO_URL 0x1000
37 // by default, the Windows text control doesn't show the selection when it
38 // doesn't have focus - use this style to force it to always show it
39 #define wxTE_NOHIDESEL 0x2000
41 // use wxHSCROLL to not wrap text at all, wxTE_CHARWRAP to wrap it at any
42 // position and wxTE_WORDWRAP to wrap at words boundary
44 // if no wrapping style is given at all, the control wraps at word boundary
45 #define wxTE_DONTWRAP wxHSCROLL
46 #define wxTE_CHARWRAP 0x4000 // wrap at any position
47 #define wxTE_WORDWRAP 0x0001 // wrap only at words boundaries
48 #define wxTE_BESTWRAP 0x0000 // this is the default
50 // force using RichEdit version 2.0 or 3.0 instead of 1.0 (default) for
51 // wxTE_RICH controls - can be used together with or instead of wxTE_RICH
52 #define wxTE_RICH2 0x8000
57 wxTextCoord is a line or row number
59 typedef long wxTextCoord
;
63 One of the following values can be passed to wxTextAttr::SetAlignment to determine paragraph alignment.
65 enum wxTextAttrAlignment
67 wxTEXT_ALIGNMENT_DEFAULT
,
68 wxTEXT_ALIGNMENT_LEFT
,
69 wxTEXT_ALIGNMENT_CENTRE
,
70 wxTEXT_ALIGNMENT_CENTER
= wxTEXT_ALIGNMENT_CENTRE
,
71 wxTEXT_ALIGNMENT_RIGHT
,
73 /** wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented.
74 In future justification may be supported when printing or previewing, only. */
75 wxTEXT_ALIGNMENT_JUSTIFIED
79 The following values are passed in a bitlist to wxTextAttr::SetFlags() to
80 determine what attributes will be considered when setting the attributes for a text control.
84 wxTEXT_ATTR_TEXT_COLOUR
= 0x00000001,
85 wxTEXT_ATTR_BACKGROUND_COLOUR
= 0x00000002,
87 wxTEXT_ATTR_FONT_FACE
= 0x00000004,
88 wxTEXT_ATTR_FONT_SIZE
= 0x00000008,
89 wxTEXT_ATTR_FONT_WEIGHT
= 0x00000010,
90 wxTEXT_ATTR_FONT_ITALIC
= 0x00000020,
91 wxTEXT_ATTR_FONT_UNDERLINE
= 0x00000040,
92 wxTEXT_ATTR_FONT_ENCODING
= 0x02000000,
93 wxTEXT_ATTR_FONT_FAMILY
= 0x04000000,
96 Defined as the combination of all @c wxTEXT_ATTR_FONT_* values above.
99 ( wxTEXT_ATTR_FONT_FACE
| wxTEXT_ATTR_FONT_SIZE
| wxTEXT_ATTR_FONT_WEIGHT
| \
100 wxTEXT_ATTR_FONT_ITALIC
| wxTEXT_ATTR_FONT_UNDERLINE
| wxTEXT_ATTR_FONT_ENCODING
| wxTEXT_ATTR_FONT_FAMILY
),
102 wxTEXT_ATTR_ALIGNMENT
= 0x00000080,
103 wxTEXT_ATTR_LEFT_INDENT
= 0x00000100,
104 wxTEXT_ATTR_RIGHT_INDENT
= 0x00000200,
105 wxTEXT_ATTR_TABS
= 0x00000400,
106 wxTEXT_ATTR_PARA_SPACING_AFTER
= 0x00000800,
107 wxTEXT_ATTR_PARA_SPACING_BEFORE
= 0x00001000,
108 wxTEXT_ATTR_LINE_SPACING
= 0x00002000,
109 wxTEXT_ATTR_CHARACTER_STYLE_NAME
= 0x00004000,
110 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
= 0x00008000,
111 wxTEXT_ATTR_LIST_STYLE_NAME
= 0x00010000,
113 wxTEXT_ATTR_BULLET_STYLE
= 0x00020000,
114 wxTEXT_ATTR_BULLET_NUMBER
= 0x00040000,
115 wxTEXT_ATTR_BULLET_TEXT
= 0x00080000,
116 wxTEXT_ATTR_BULLET_NAME
= 0x00100000,
119 Defined as the combination of all @c wxTEXT_ATTR_BULLET_* values above.
121 wxTEXT_ATTR_BULLET
= \
122 ( wxTEXT_ATTR_BULLET_STYLE
| wxTEXT_ATTR_BULLET_NUMBER
| wxTEXT_ATTR_BULLET_TEXT
| \
123 wxTEXT_ATTR_BULLET_NAME
),
125 wxTEXT_ATTR_URL
= 0x00200000,
126 wxTEXT_ATTR_PAGE_BREAK
= 0x00400000,
127 wxTEXT_ATTR_EFFECTS
= 0x00800000,
128 wxTEXT_ATTR_OUTLINE_LEVEL
= 0x01000000,
131 Combines the styles @c wxTEXT_ATTR_FONT, @c wxTEXT_ATTR_EFFECTS, @c wxTEXT_ATTR_BACKGROUND_COLOUR,
132 @c wxTEXT_ATTR_TEXT_COLOUR, @c wxTEXT_ATTR_CHARACTER_STYLE_NAME, @c wxTEXT_ATTR_URL.
135 wxTEXT_ATTR_CHARACTER
= \
136 (wxTEXT_ATTR_FONT
|wxTEXT_ATTR_EFFECTS
| \
137 wxTEXT_ATTR_BACKGROUND_COLOUR
|wxTEXT_ATTR_TEXT_COLOUR
|wxTEXT_ATTR_CHARACTER_STYLE_NAME
|wxTEXT_ATTR_URL
),
140 Combines all the styles regarding text paragraphs.
142 wxTEXT_ATTR_PARAGRAPH
= \
143 (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_TABS
|\
144 wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|wxTEXT_ATTR_LINE_SPACING
|\
145 wxTEXT_ATTR_BULLET
|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
|wxTEXT_ATTR_LIST_STYLE_NAME
|wxTEXT_ATTR_OUTLINE_LEVEL
),
148 Combines all previous values.
150 wxTEXT_ATTR_ALL
= (wxTEXT_ATTR_CHARACTER
|wxTEXT_ATTR_PARAGRAPH
)
154 Styles for wxTextAttr::SetBulletStyle. They can be combined together as a bitlist.
156 enum wxTextAttrBulletStyle
158 wxTEXT_ATTR_BULLET_STYLE_NONE
= 0x00000000,
159 wxTEXT_ATTR_BULLET_STYLE_ARABIC
= 0x00000001,
160 wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER
= 0x00000002,
161 wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER
= 0x00000004,
162 wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER
= 0x00000008,
163 wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER
= 0x00000010,
164 wxTEXT_ATTR_BULLET_STYLE_SYMBOL
= 0x00000020,
166 /** wxTEXT_ATTR_BULLET_STYLE_BITMAP is unimplemented. */
167 wxTEXT_ATTR_BULLET_STYLE_BITMAP
= 0x00000040,
168 wxTEXT_ATTR_BULLET_STYLE_PARENTHESES
= 0x00000080,
169 wxTEXT_ATTR_BULLET_STYLE_PERIOD
= 0x00000100,
170 wxTEXT_ATTR_BULLET_STYLE_STANDARD
= 0x00000200,
171 wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS
= 0x00000400,
172 wxTEXT_ATTR_BULLET_STYLE_OUTLINE
= 0x00000800,
174 wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT
= 0x00000000,
175 wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT
= 0x00001000,
176 wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE
= 0x00002000
180 Styles for wxTextAttr::SetTextEffects(). They can be combined together as a bitlist.
182 Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
183 wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
185 enum wxTextAttrEffects
187 wxTEXT_ATTR_EFFECT_NONE
= 0x00000000,
188 wxTEXT_ATTR_EFFECT_CAPITALS
= 0x00000001,
189 wxTEXT_ATTR_EFFECT_SMALL_CAPITALS
= 0x00000002,
190 wxTEXT_ATTR_EFFECT_STRIKETHROUGH
= 0x00000004,
191 wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH
= 0x00000008,
192 wxTEXT_ATTR_EFFECT_SHADOW
= 0x00000010,
193 wxTEXT_ATTR_EFFECT_EMBOSS
= 0x00000020,
194 wxTEXT_ATTR_EFFECT_OUTLINE
= 0x00000040,
195 wxTEXT_ATTR_EFFECT_ENGRAVE
= 0x00000080,
196 wxTEXT_ATTR_EFFECT_SUPERSCRIPT
= 0x00000100,
197 wxTEXT_ATTR_EFFECT_SUBSCRIPT
= 0x00000200
201 Convenience line spacing values; see wxTextAttr::SetLineSpacing().
203 enum wxTextAttrLineSpacing
205 wxTEXT_ATTR_LINE_SPACING_NORMAL
= 10,
206 wxTEXT_ATTR_LINE_SPACING_HALF
= 15,
207 wxTEXT_ATTR_LINE_SPACING_TWICE
= 20
212 Describes the possible return values of wxTextCtrl::HitTest().
214 The element names correspond to the relationship between the point asked
215 for and the character returned, e.g. @c wxTE_HT_BEFORE means that the point
216 is before (leftward or upward) it and so on.
218 enum wxTextCtrlHitTestResult
220 /// Indicates that wxTextCtrl::HitTest() is not implemented on this
222 wxTE_HT_UNKNOWN
= -2,
224 /// The point is before the character returned.
227 /// The point is directly on the character returned.
230 /// The point is below the last line of the control.
233 /// The point is beyond the end of line containing the character returned.
241 wxTextAttr represents the character and paragraph attributes, or style,
242 for a range of text in a wxTextCtrl or wxRichTextCtrl.
244 When setting up a wxTextAttr object, pass a bitlist mask to
245 wxTextAttr::SetFlags() to indicate which style elements should be changed.
246 As a convenience, when you call a setter such as SetFont, the relevant bit
252 @see wxTextCtrl, wxRichTextCtrl
262 wxTextAttr(const wxColour
& colText
,
263 const wxColour
& colBack
= wxNullColour
,
264 const wxFont
& font
= wxNullFont
,
265 wxTextAttrAlignment alignment
= wxTEXT_ALIGNMENT_DEFAULT
);
266 wxTextAttr(const wxTextAttr
& attr
);
270 Applies the attributes in @a style to the original object, but not those
271 attributes from @a style that are the same as those in @a compareWith (if passed).
273 bool Apply(const wxTextAttr
& style
,
274 const wxTextAttr
* compareWith
= NULL
);
277 Copies all defined/valid properties from overlay to current object.
279 void Merge(const wxTextAttr
& overlay
);
282 Creates a new @c wxTextAttr which is a merge of @a base and @a overlay.
284 Properties defined in @a overlay take precedence over those in @a base.
285 Properties undefined/invalid in both are undefined in the result.
287 static wxTextAttr
Merge(const wxTextAttr
& base
,
288 const wxTextAttr
& overlay
);
292 @name GetXXX functions
298 Returns the alignment flags.
299 See ::wxTextAttrAlignment for a list of available styles.
301 wxTextAttrAlignment
GetAlignment() const;
304 Returns the background colour.
306 const wxColour
& GetBackgroundColour() const;
309 Returns a string containing the name of the font associated with the bullet symbol.
310 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
312 const wxString
& GetBulletFont() const;
315 Returns the standard bullet name, applicable if the bullet style is
316 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
318 Currently the following standard bullet names are supported:
321 - @c standard/diamond
322 - @c standard/triangle
325 For wxRichTextCtrl users only: if you wish your rich text controls to support
326 further bullet graphics, you can derive a class from wxRichTextRenderer or
327 wxRichTextStdRenderer, override @c DrawStandardBullet and @c EnumerateStandardBulletNames,
328 and set an instance of the class using wxRichTextBuffer::SetRenderer.
330 const wxString
& GetBulletName() const;
333 Returns the bullet number.
335 int GetBulletNumber() const;
338 Returns the bullet style.
339 See ::wxTextAttrBulletStyle for a list of available styles.
341 int GetBulletStyle() const;
344 Returns the bullet text, which could be a symbol, or (for example) cached
347 const wxString
& GetBulletText() const;
350 Returns the name of the character style.
352 const wxString
& GetCharacterStyleName() const;
355 Returns flags indicating which attributes are applicable.
356 See SetFlags() for a list of available flags.
358 long GetFlags() const;
361 Creates and returns a font specified by the font attributes in the wxTextAttr
362 object. Note that wxTextAttr does not store a wxFont object, so this is only
365 For greater efficiency, access the font attributes directly.
367 wxFont
GetFont() const;
370 Gets the font attributes from the given font, using only the attributes
371 specified by @a flags.
373 bool GetFontAttributes(const wxFont
& font
,
374 int flags
= wxTEXT_ATTR_FONT
);
377 Returns the font encoding.
379 wxFontEncoding
GetFontEncoding() const;
382 Returns the font face name.
384 const wxString
& GetFontFaceName() const;
387 Returns the font family.
389 wxFontFamily
GetFontFamily() const;
392 Returns the font size in points.
394 int GetFontSize() const;
397 Returns the font style.
399 wxFontStyle
GetFontStyle() const;
402 Returns @true if the font is underlined.
404 bool GetFontUnderlined() const;
407 Returns the font weight.
409 wxFontWeight
GetFontWeight() const;
412 Returns the left indent in tenths of a millimetre.
414 long GetLeftIndent() const;
417 Returns the left sub-indent in tenths of a millimetre.
419 long GetLeftSubIndent() const;
422 Returns the line spacing value, one of ::wxTextAttrLineSpacing values.
424 int GetLineSpacing() const;
427 Returns the name of the list style.
429 const wxString
& GetListStyleName() const;
432 Returns the outline level.
434 int GetOutlineLevel() const;
437 Returns the space in tenths of a millimeter after the paragraph.
439 int GetParagraphSpacingAfter() const;
442 Returns the space in tenths of a millimeter before the paragraph.
444 int GetParagraphSpacingBefore() const;
447 Returns the name of the paragraph style.
449 const wxString
& GetParagraphStyleName() const;
452 Returns the right indent in tenths of a millimeter.
454 long GetRightIndent() const;
457 Returns an array of tab stops, each expressed in tenths of a millimeter.
459 Each stop is measured from the left margin and therefore each value must
460 be larger than the last.
462 const wxArrayInt
& GetTabs() const;
465 Returns the text foreground colour.
467 const wxColour
& GetTextColour() const;
470 Returns the text effect bits of interest.
471 See SetFlags() for further information.
473 int GetTextEffectFlags() const;
476 Returns the text effects, a bit list of styles.
477 See SetTextEffects() for details.
479 int GetTextEffects() const;
482 Returns the URL for the content.
484 Content with @a wxTEXT_ATTR_URL style causes wxRichTextCtrl to show a
485 hand cursor over it, and wxRichTextCtrl generates a wxTextUrlEvent
486 when the content is clicked.
488 const wxString
& GetURL() const;
495 @name HasXXX and IsXXX functions
501 Returns @true if the attribute object specifies alignment.
503 bool HasAlignment() const;
506 Returns @true if the attribute object specifies a background colour.
508 bool HasBackgroundColour() const;
511 Returns @true if the attribute object specifies a standard bullet name.
513 bool HasBulletName() const;
516 Returns @true if the attribute object specifies a bullet number.
518 bool HasBulletNumber() const;
521 Returns @true if the attribute object specifies a bullet style.
523 bool HasBulletStyle() const;
526 Returns @true if the attribute object specifies bullet text (usually
527 specifying a symbol).
529 bool HasBulletText() const;
532 Returns @true if the attribute object specifies a character style name.
534 bool HasCharacterStyleName() const;
537 Returns @true if the @a flag is present in the attribute object's flag
540 bool HasFlag(long flag
) const;
543 Returns @true if the attribute object specifies any font attributes.
545 bool HasFont() const;
548 Returns @true if the attribute object specifies an encoding.
550 bool HasFontEncoding() const;
553 Returns @true if the attribute object specifies a font face name.
555 bool HasFontFaceName() const;
558 Returns @true if the attribute object specifies a font family.
560 bool HasFontFamily() const;
563 Returns @true if the attribute object specifies italic style.
565 bool HasFontItalic() const;
568 Returns @true if the attribute object specifies a font point size.
570 bool HasFontSize() const;
573 Returns @true if the attribute object specifies either underlining or no
576 bool HasFontUnderlined() const;
579 Returns @true if the attribute object specifies font weight (bold, light or
582 bool HasFontWeight() const;
585 Returns @true if the attribute object specifies a left indent.
587 bool HasLeftIndent() const;
590 Returns @true if the attribute object specifies line spacing.
592 bool HasLineSpacing() const;
595 Returns @true if the attribute object specifies a list style name.
597 bool HasListStyleName() const;
600 Returns @true if the attribute object specifies an outline level.
602 bool HasOutlineLevel() const;
605 Returns @true if the attribute object specifies a page break before this
608 bool HasPageBreak() const;
611 Returns @true if the attribute object specifies spacing after a paragraph.
613 bool HasParagraphSpacingAfter() const;
616 Returns @true if the attribute object specifies spacing before a paragraph.
618 bool HasParagraphSpacingBefore() const;
621 Returns @true if the attribute object specifies a paragraph style name.
623 bool HasParagraphStyleName() const;
626 Returns @true if the attribute object specifies a right indent.
628 bool HasRightIndent() const;
631 Returns @true if the attribute object specifies tab stops.
633 bool HasTabs() const;
636 Returns @true if the attribute object specifies a text foreground colour.
638 bool HasTextColour() const;
641 Returns @true if the attribute object specifies text effects.
643 bool HasTextEffects() const;
646 Returns @true if the attribute object specifies a URL.
651 Returns @true if the object represents a character style, that is,
652 the flags specify a font or a text background or foreground colour.
654 bool IsCharacterStyle() const;
657 Returns @false if we have any attributes set, @true otherwise.
659 bool IsDefault() const;
662 Returns @true if the object represents a paragraph style, that is,
663 the flags specify alignment, indentation, tabs, paragraph spacing, or
666 bool IsParagraphStyle() const;
672 @name SetXXX functions
678 Sets the paragraph alignment. See ::wxTextAttrAlignment enumeration values.
680 Of these, wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented.
681 In future justification may be supported when printing or previewing, only.
683 void SetAlignment(wxTextAttrAlignment alignment
);
686 Sets the background colour.
688 void SetBackgroundColour(const wxColour
& colBack
);
691 Sets the name of the font associated with the bullet symbol.
692 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
694 void SetBulletFont(const wxString
& font
);
697 Sets the standard bullet name, applicable if the bullet style is
698 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
700 See GetBulletName() for a list of supported names, and how
701 to expand the range of supported types.
703 void SetBulletName(const wxString
& name
);
706 Sets the bullet number.
708 void SetBulletNumber(int n
);
711 Sets the bullet style.
713 The ::wxTextAttrBulletStyle enumeration values are all supported,
714 except for wxTEXT_ATTR_BULLET_STYLE_BITMAP.
716 void SetBulletStyle(int style
);
719 Sets the bullet text, which could be a symbol, or (for example) cached
722 void SetBulletText(const wxString
& text
);
725 Sets the character style name.
727 void SetCharacterStyleName(const wxString
& name
);
730 Sets the flags determining which styles are being specified.
731 The ::wxTextAttrFlags values can be passed in a bitlist.
733 void SetFlags(long flags
);
736 Sets the attributes for the given font.
737 Note that wxTextAttr does not store an actual wxFont object.
739 void SetFont(const wxFont
& font
, int flags
= wxTEXT_ATTR_FONT
);
742 Sets the font encoding.
744 void SetFontEncoding(wxFontEncoding encoding
);
747 Sets the font face name.
749 void SetFontFaceName(const wxString
& faceName
);
752 Sets the font family.
754 void SetFontFamily(wxFontFamily family
);
757 Sets the font size in points.
759 void SetFontSize(int pointSize
);
762 Sets the font style (normal, italic or slanted).
764 void SetFontStyle(wxFontStyle fontStyle
);
767 Sets the font underlining.
769 void SetFontUnderlined(bool underlined
);
772 Sets the font weight.
774 void SetFontWeight(wxFontWeight fontWeight
);
777 Sets the left indent and left subindent in tenths of a millimetre.
778 The sub-indent is an offset from the left of the paragraph, and is used for all
779 but the first line in a paragraph.
781 A positive value will cause the first line to appear to the left
782 of the subsequent lines, and a negative value will cause the first line to be
783 indented relative to the subsequent lines.
785 wxRichTextBuffer uses indentation to render a bulleted item.
786 The left indent is the distance between the margin and the bullet.
787 The content of the paragraph, including the first line, starts
788 at leftMargin + leftSubIndent.
789 So the distance between the left edge of the bullet and the
790 left of the actual paragraph is leftSubIndent.
792 void SetLeftIndent(int indent
, int subIndent
= 0);
795 Sets the line spacing. @a spacing is a multiple, where 10 means single-spacing,
796 15 means 1.5 spacing, and 20 means double spacing.
797 The ::wxTextAttrLineSpacing values are defined for convenience.
799 void SetLineSpacing(int spacing
);
802 Sets the list style name.
804 void SetListStyleName(const wxString
& name
);
807 Specifies the outline level. Zero represents normal text.
808 At present, the outline level is not used, but may be used in future for
809 determining list levels and for applications that need to store document
810 structure information.
812 void SetOutlineLevel(int level
);
815 Specifies a page break before this paragraph.
817 void SetPageBreak(bool pageBreak
= true);
820 Sets the spacing after a paragraph, in tenths of a millimetre.
822 void SetParagraphSpacingAfter(int spacing
);
825 Sets the spacing before a paragraph, in tenths of a millimetre.
827 void SetParagraphSpacingBefore(int spacing
);
830 Sets the name of the paragraph style.
832 void SetParagraphStyleName(const wxString
& name
);
835 Sets the right indent in tenths of a millimetre.
837 void SetRightIndent(int indent
);
840 Sets the tab stops, expressed in tenths of a millimetre.
841 Each stop is measured from the left margin and therefore each value must be
842 larger than the last.
844 void SetTabs(const wxArrayInt
& tabs
);
847 Sets the text foreground colour.
849 void SetTextColour(const wxColour
& colText
);
852 Sets the text effect bits of interest.
854 You should also pass wxTEXT_ATTR_EFFECTS to SetFlags().
855 See SetFlags() for further information.
857 void SetTextEffectFlags(int flags
);
860 Sets the text effects, a bit list of styles.
861 The ::wxTextAttrEffects enumeration values can be used.
863 Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
864 wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
866 wxTEXT_ATTR_EFFECT_CAPITALS capitalises text when displayed (leaving the case
867 of the actual buffer text unchanged), and wxTEXT_ATTR_EFFECT_STRIKETHROUGH draws
870 To set effects, you should also pass wxTEXT_ATTR_EFFECTS to SetFlags(), and call
871 SetTextEffectFlags() with the styles (taken from the above set) that you
872 are interested in setting.
874 void SetTextEffects(int effects
);
877 Sets the URL for the content. Sets the wxTEXT_ATTR_URL style; content with this
878 style causes wxRichTextCtrl to show a hand cursor over it, and wxRichTextCtrl
879 generates a wxTextUrlEvent when the content is clicked.
881 void SetURL(const wxString
& url
);
887 Assignment from a wxTextAttr object.
889 void operator=(const wxTextAttr
& attr
);
896 A text control allows text to be displayed and edited.
898 It may be single line or multi-line. Notice that a lot of methods of the
899 text controls are found in the base wxTextEntry class which is a common
900 base class for wxTextCtrl and other controls using a single line text entry
901 field (e.g. wxComboBox).
904 @style{wxTE_PROCESS_ENTER}
905 The control will generate the event @c wxEVT_COMMAND_TEXT_ENTER
906 (otherwise pressing Enter key is either processed internally by the
907 control or used for navigation between dialog controls).
908 @style{wxTE_PROCESS_TAB}
909 The control will receive @c wxEVT_CHAR events for TAB pressed -
910 normally, TAB is used for passing to the next control in a dialog
911 instead. For the control created with this style, you can still use
912 Ctrl-Enter to pass to the next control from the keyboard.
913 @style{wxTE_MULTILINE}
914 The text control allows multiple lines. If this style is not
915 specified, line break characters should not be used in the controls
917 @style{wxTE_PASSWORD}
918 The text will be echoed as asterisks.
919 @style{wxTE_READONLY}
920 The text will not be user-editable.
922 Use rich text control under Win32, this allows to have more than
923 64KB of text in the control even under Win9x. This style is ignored
924 under other platforms.
926 Use rich text control version 2.0 or 3.0 under Win32, this style is
927 ignored under other platforms
928 @style{wxTE_AUTO_URL}
929 Highlight the URLs and generate the wxTextUrlEvents when mouse
930 events occur over them. This style is only supported for wxTE_RICH
931 Win32 and multi-line wxGTK2 text controls.
932 @style{wxTE_NOHIDESEL}
933 By default, the Windows text control doesn't show the selection
934 when it doesn't have focus - use this style to force it to always
935 show it. It doesn't do anything under other platforms.
937 A horizontal scrollbar will be created and used, so that text won't
938 be wrapped. No effect under wxGTK1.
939 @style{wxTE_NO_VSCROLL}
940 For multiline controls only: vertical scrollbar will never be
941 created. This limits the amount of text which can be entered into
942 the control to what can be displayed in it under MSW but not under
943 GTK2. Currently not implemented for the other platforms.
945 The text in the control will be left-justified (default).
947 The text in the control will be centered (currently wxMSW and
950 The text in the control will be right-justified (currently wxMSW
952 @style{wxTE_DONTWRAP}
953 Same as wxHSCROLL style: don't wrap at all, show horizontal
955 @style{wxTE_CHARWRAP}
956 Wrap the lines too long to be shown entirely at any position
957 (wxUniv and wxGTK2 only).
958 @style{wxTE_WORDWRAP}
959 Wrap the lines too long to be shown entirely at word boundaries
960 (wxUniv and wxGTK2 only).
961 @style{wxTE_BESTWRAP}
962 Wrap the lines at word boundaries or at any other character if
963 there are words longer than the window width (this is the default).
964 @style{wxTE_CAPITALIZE}
965 On PocketPC and Smartphone, causes the first letter to be
969 Note that alignment styles (wxTE_LEFT, wxTE_CENTRE and wxTE_RIGHT) can be
970 changed dynamically after control creation on wxMSW and wxGTK. wxTE_READONLY,
971 wxTE_PASSWORD and wrapping styles can be dynamically changed under wxGTK but
972 not wxMSW. The other styles can be only set during control creation.
975 @section textctrl_text_format wxTextCtrl Text Format
977 The multiline text controls always store the text as a sequence of lines
978 separated by @c '\\n' characters, i.e. in the Unix text format even on
979 non-Unix platforms. This allows the user code to ignore the differences
980 between the platforms but at a price: the indices in the control such as
981 those returned by GetInsertionPoint() or GetSelection() can @b not be used
982 as indices into the string returned by GetValue() as they're going to be
983 slightly off for platforms using @c "\\r\\n" as separator (as Windows
986 Instead, if you need to obtain a substring between the 2 indices obtained
987 from the control with the help of the functions mentioned above, you should
988 use GetRange(). And the indices themselves can only be passed to other
989 methods, for example SetInsertionPoint() or SetSelection().
991 To summarize: never use the indices returned by (multiline) wxTextCtrl as
992 indices into the string it contains, but only as arguments to be passed
993 back to the other wxTextCtrl methods. This problem doesn't arise for
994 single-line platforms however where the indices in the control do
995 correspond to the positions in the value string.
998 @section textctrl_styles wxTextCtrl Styles.
1000 Multi-line text controls support styling, i.e. provide a possibility to set
1001 colours and font for individual characters in it (note that under Windows
1002 @c wxTE_RICH style is required for style support). To use the styles you
1003 can either call SetDefaultStyle() before inserting the text or call
1004 SetStyle() later to change the style of the text already in the control
1005 (the first solution is much more efficient).
1007 In either case, if the style doesn't specify some of the attributes (for
1008 example you only want to set the text colour but without changing the font
1009 nor the text background), the values of the default style will be used for
1010 them. If there is no default style, the attributes of the text control
1013 So the following code correctly describes what it does: the second call to
1014 SetDefaultStyle() doesn't change the text foreground colour (which stays
1015 red) while the last one doesn't change the background colour (which stays
1019 text->SetDefaultStyle(wxTextAttr(*wxRED));
1020 text->AppendText("Red text\n");
1021 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
1022 text->AppendText("Red on grey text\n");
1023 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
1024 text->AppendText("Blue on grey text\n");
1028 @section textctrl_cpp_streams wxTextCtrl and C++ Streams
1030 This class multiply-inherits from @c std::streambuf (except for some really
1031 old compilers using non-standard iostream library), allowing code such as
1035 wxTextCtrl *control = new wxTextCtrl(...);
1037 ostream stream(control)
1039 stream << 123.456 << " some text\n";
1043 Note that even if your compiler doesn't support this (the symbol
1044 @c wxHAS_TEXT_WINDOW_STREAM has value of 0 then) you can still use
1045 wxTextCtrl itself in a stream-like manner:
1048 wxTextCtrl *control = new wxTextCtrl(...);
1050 *control << 123.456 << " some text\n";
1053 However the possibility to create an ostream associated with wxTextCtrl may
1054 be useful if you need to redirect the output of a function taking an
1055 ostream as parameter to a text control.
1057 Another commonly requested need is to redirect @c std::cout to the text
1058 control. This may be done in the following way:
1063 wxTextCtrl *control = new wxTextCtrl(...);
1065 std::streambuf *sbOld = std::cout.rdbuf();
1066 std::cout.rdbuf(control);
1068 // use cout as usual, the output appears in the text control
1071 std::cout.rdbuf(sbOld);
1074 But wxWidgets provides a convenient class to make it even simpler so
1075 instead you may just do
1080 wxTextCtrl *control = new wxTextCtrl(...);
1082 wxStreamToTextRedirector redirect(control);
1084 // all output to cout goes into the text control until the exit from
1088 See wxStreamToTextRedirector for more details.
1091 @section textctrl_event_handling Event Handling.
1093 The following commands are processed by default event handlers in
1094 wxTextCtrl: @c wxID_CUT, @c wxID_COPY, @c wxID_PASTE, @c wxID_UNDO, @c
1095 wxID_REDO. The associated UI update events are also processed
1096 automatically, when the control has the focus.
1098 @beginEventEmissionTable{wxCommandEvent}
1099 @event{EVT_TEXT(id, func)}
1100 Respond to a @c wxEVT_COMMAND_TEXT_UPDATED event, generated when the text
1101 changes. Notice that this event will be sent when the text controls
1102 contents changes -- whether this is due to user input or comes from the
1103 program itself (for example, if wxTextCtrl::SetValue() is called); see
1104 wxTextCtrl::ChangeValue() for a function which does not send this event.
1105 This event is however not sent during the control creation.
1106 @event{EVT_TEXT_ENTER(id, func)}
1107 Respond to a @c wxEVT_COMMAND_TEXT_ENTER event, generated when enter is
1108 pressed in a text control which must have wxTE_PROCESS_ENTER style for
1109 this event to be generated.
1110 @event{EVT_TEXT_URL(id, func)}
1111 A mouse event occurred over an URL in the text control (wxMSW and
1112 wxGTK2 only currently).
1113 @event{EVT_TEXT_MAXLEN(id, func)}
1114 This event is generated when the user tries to enter more text into the
1115 control than the limit set by wxTextCtrl::SetMaxLength(), see its description.
1120 @appearance{textctrl.png}
1122 @see wxTextCtrl::Create, wxValidator
1124 class wxTextCtrl
: public wxControl
,
1134 Constructor, creating and showing a text control.
1137 Parent window. Should not be @NULL.
1139 Control identifier. A value of -1 denotes a default value.
1143 Text control position.
1147 Window style. See wxTextCtrl.
1154 The horizontal scrollbar (wxHSCROLL style flag) will only be
1155 created for multi-line text controls. Without a horizontal
1156 scrollbar, text lines that don't fit in the control's size will be
1157 wrapped (but no newline character is inserted).
1158 Single line controls don't have a horizontal scrollbar, the text is
1159 automatically scrolled so that the insertion point is always visible.
1161 @see Create(), wxValidator
1163 wxTextCtrl(wxWindow
* parent
, wxWindowID id
,
1164 const wxString
& value
= wxEmptyString
,
1165 const wxPoint
& pos
= wxDefaultPosition
,
1166 const wxSize
& size
= wxDefaultSize
,
1168 const wxValidator
& validator
= wxDefaultValidator
,
1169 const wxString
& name
= wxTextCtrlNameStr
);
1172 Destructor, destroying the text control.
1174 virtual ~wxTextCtrl();
1177 Creates the text control for two-step construction.
1179 This method should be called if the default constructor was used for
1180 the control creation. Its parameters have the same meaning as for the
1181 non-default constructor.
1183 bool Create(wxWindow
* parent
, wxWindowID id
,
1184 const wxString
& value
= wxEmptyString
,
1185 const wxPoint
& pos
= wxDefaultPosition
,
1186 const wxSize
& size
= wxDefaultSize
, long style
= 0,
1187 const wxValidator
& validator
= wxDefaultValidator
,
1188 const wxString
& name
= wxTextCtrlNameStr
);
1191 Copies the selected text to the clipboard and removes the selection.
1196 Resets the internal modified flag as if the current changes had been
1199 virtual void DiscardEdits();
1202 This function inserts into the control the character which would have
1203 been inserted if the given key event had occurred in the text control.
1205 The @a event object should be the same as the one passed to @c EVT_KEY_DOWN
1206 handler previously by wxWidgets. Please note that this function doesn't
1207 currently work correctly for all keys under any platform but MSW.
1210 @true if the event resulted in a change to the control, @false otherwise.
1212 virtual bool EmulateKeyPress(const wxKeyEvent
& event
);
1215 Returns the style currently used for the new text.
1217 @see SetDefaultStyle()
1219 virtual const wxTextAttr
& GetDefaultStyle() const;
1222 Gets the length of the specified line, not including any trailing
1223 newline character(s).
1226 Line number (starting from zero).
1229 The length of the line, or -1 if @a lineNo was invalid.
1231 virtual int GetLineLength(long lineNo
) const;
1234 Returns the contents of a given line in the text control, not including
1235 any trailing newline character(s).
1238 The line number, starting from zero.
1241 The contents of the line.
1243 virtual wxString
GetLineText(long lineNo
) const;
1246 Returns the number of lines in the text control buffer.
1248 The returned number is the number of logical lines, i.e. just the count
1249 of the number of newline characters in the control + 1, for wxGTK and
1250 wxOSX/Cocoa ports while it is the number of physical lines, i.e. the
1251 count of lines actually shown in the control, in wxMSW and wxOSX/Carbon.
1252 Because of this discrepancy, it is not recommended to use this function.
1255 Note that even empty text controls have one line (where the
1256 insertion point is), so GetNumberOfLines() never returns 0.
1258 virtual int GetNumberOfLines() const;
1261 Returns the style at this position in the text control.
1263 Not all platforms support this function.
1266 @true on success, @false if an error occurred (this may also mean
1267 that the styles are not supported under this platform).
1269 @see SetStyle(), wxTextAttr
1271 virtual bool GetStyle(long position
, wxTextAttr
& style
);
1275 This function finds the character at the specified position expressed
1278 The two overloads of this method allow to find either the position of
1279 the character, as an index into the text control contents, or its row
1282 If the return code is not @c wxTE_HT_UNKNOWN the row and column of the
1283 character closest to this position are returned, otherwise the output
1284 parameters are not modified.
1286 Please note that this function is currently only implemented in wxUniv,
1287 wxMSW and wxGTK2 ports and always returns @c wxTE_HT_UNKNOWN in the
1291 In wxPerl this function takes only the @a pt argument and
1292 returns a 3-element list (result, col, row).
1296 The position of the point to check, in window device coordinates.
1298 Receives the column of the character at the given position. May be
1301 Receives the row of the character at the given position. May be
1304 Receives the position of the character at the given position. May
1307 @see PositionToXY(), XYToPosition()
1309 wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
1310 wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
1312 wxTextCoord
*row
) const;
1316 Returns @true if the text has been modified by user.
1318 Note that calling SetValue() doesn't make the control modified.
1322 virtual bool IsModified() const;
1325 Returns @true if this is a multi line edit control and @false otherwise.
1329 bool IsMultiLine() const;
1332 Returns @true if this is a single line edit control and @false otherwise.
1334 @see IsSingleLine(), IsMultiLine()
1336 bool IsSingleLine() const;
1339 Loads and displays the named file, if it exists.
1342 The filename of the file to load.
1344 The type of file to load. This is currently ignored in wxTextCtrl.
1347 @true if successful, @false otherwise.
1349 bool LoadFile(const wxString
& filename
,
1350 int fileType
= wxTEXT_TYPE_ANY
);
1353 Mark text as modified (dirty).
1357 virtual void MarkDirty();
1360 This event handler function implements default drag and drop behaviour,
1361 which is to load the first dropped file into the control.
1364 The drop files event.
1366 @remarks This is not implemented on non-Windows platforms.
1368 @see wxDropFilesEvent
1370 void OnDropFiles(wxDropFilesEvent
& event
);
1373 Converts given position to a zero-based column, line number pair.
1378 Receives zero based column number.
1380 Receives zero based line number.
1383 @true on success, @false on failure (most likely due to a too large
1384 position parameter).
1387 In wxPerl this function takes only the @a pos argument and
1388 returns a 2-element list (x, y).
1393 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
1396 Converts given text position to client coordinates in pixels.
1398 This function allows to find where is the character at the given
1399 position displayed in the text control.
1401 @onlyfor{wxmsw,wxgtk}. Additionally, wxGTK only implements this method
1402 for multiline controls and ::wxDefaultPosition is always returned for
1403 the single line ones.
1406 Text position in 0 to GetLastPosition() range (inclusive).
1408 On success returns a wxPoint which contains client coordinates for
1409 the given position in pixels, otherwise returns ::wxDefaultPosition.
1413 @see XYToPosition(), PositionToXY()
1415 wxPoint
PositionToCoords(long pos
) const;
1418 Saves the contents of the control in a text file.
1421 The name of the file in which to save the text.
1423 The type of file to save. This is currently ignored in wxTextCtrl.
1426 @true if the operation was successful, @false otherwise.
1428 bool SaveFile(const wxString
& filename
= wxEmptyString
,
1429 int fileType
= wxTEXT_TYPE_ANY
);
1432 Changes the default style to use for the new text which is going to be
1433 added to the control using WriteText() or AppendText().
1435 If either of the font, foreground, or background colour is not set in
1436 @a style, the values of the previous default style are used for them.
1437 If the previous default style didn't set them neither, the global font
1438 or colours of the text control itself are used as fall back.
1440 However if the @a style parameter is the default wxTextAttr, then the default
1441 style is just reset (instead of being combined with the new style which
1442 wouldn't change it at all).
1445 The style for the new text.
1448 @true on success, @false if an error occurred (this may also mean
1449 that the styles are not supported under this platform).
1451 @see GetDefaultStyle()
1453 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
1456 Marks the control as being modified by the user or not.
1458 @see MarkDirty(), DiscardEdits()
1460 void SetModified(bool modified
);
1463 Changes the style of the given range.
1465 If any attribute within @a style is not set, the corresponding
1466 attribute from GetDefaultStyle() is used.
1469 The start of the range to change.
1471 The end of the range to change.
1473 The new style for the range.
1476 @true on success, @false if an error occurred (this may also mean
1477 that the styles are not supported under this platform).
1479 @see GetStyle(), wxTextAttr
1481 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
1484 Makes the line containing the given position visible.
1487 The position that should be visible.
1489 virtual void ShowPosition(long pos
);
1492 Converts the given zero based column and line number to a position.
1500 The position value, or -1 if x or y was invalid.
1502 virtual long XYToPosition(long x
, long y
) const;
1506 Operator definitions for appending to a text control.
1508 These operators can be used as with the standard C++ streams, for
1511 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1513 (*wnd) << "Welcome to text control number " << 1 << ".\n";
1517 wxTextCtrl
& operator<<(const wxString
& s
);
1518 wxTextCtrl
& operator<<(int i
);
1519 wxTextCtrl
& operator<<(long i
);
1520 wxTextCtrl
& operator<<(float f
);
1521 wxTextCtrl
& operator<<(double d
);
1522 wxTextCtrl
& operator<<(char c
);
1523 wxTextCtrl
& operator<<(wchar_t c
);
1530 @class wxStreamToTextRedirector
1532 This class can be used to (temporarily) redirect all output sent to a C++
1533 ostream object to a wxTextCtrl instead.
1536 Some compilers and/or build configurations don't support multiply
1537 inheriting wxTextCtrl from @c std::streambuf in which case this class is
1539 You also must have @c wxUSE_STD_IOSTREAM option on (i.e. set to 1) in your
1540 @c setup.h to be able to use it. Under Unix, specify @c --enable-std_iostreams
1541 switch when running configure for this.
1546 using namespace std;
1547 wxTextCtrl* text = new wxTextCtrl(...);
1549 wxStreamToTextRedirector redirect(text);
1551 // this goes to the text control
1552 cout << "Hello, text!" << endl;
1554 // this goes somewhere else, presumably to stdout
1555 cout << "Hello, console!" << endl;
1563 class wxStreamToTextRedirector
1567 The constructor starts redirecting output sent to @a ostr or @a cout for
1568 the default parameter value to the text control @a text.
1571 The text control to append output too, must be non-@NULL
1573 The C++ stream to redirect, cout is used if it is @NULL
1575 wxStreamToTextRedirector(wxTextCtrl
*text
, ostream
* ostr
);
1578 When a wxStreamToTextRedirector object is destroyed, the redirection is ended
1579 and any output sent to the C++ ostream which had been specified at the time of
1580 the object construction will go to its original destination.
1582 ~wxStreamToTextRedirector();