Applied patch #13534: wxRichTextCtrl: Make it easier to use TextEffects flags
[wxWidgets.git] / interface / wx / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: textctrl.h
3 // Purpose: interface of wxTextAttr
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9
10 /**
11 One of the following values can be passed to wxTextAttr::SetAlignment to determine paragraph alignment.
12 */
13 enum wxTextAttrAlignment
14 {
15 wxTEXT_ALIGNMENT_DEFAULT,
16 wxTEXT_ALIGNMENT_LEFT,
17 wxTEXT_ALIGNMENT_CENTRE,
18 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
19 wxTEXT_ALIGNMENT_RIGHT,
20
21 /** wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented.
22 In future justification may be supported when printing or previewing, only. */
23 wxTEXT_ALIGNMENT_JUSTIFIED
24 };
25
26 /**
27 The following values are passed in a bitlist to wxTextAttr::SetFlags() to
28 determine what attributes will be considered when setting the attributes for a text control.
29 */
30 enum wxTextAttrFlags
31 {
32 wxTEXT_ATTR_TEXT_COLOUR = 0x00000001,
33 wxTEXT_ATTR_BACKGROUND_COLOUR = 0x00000002,
34
35 wxTEXT_ATTR_FONT_FACE = 0x00000004,
36 wxTEXT_ATTR_FONT_SIZE = 0x00000008,
37 wxTEXT_ATTR_FONT_WEIGHT = 0x00000010,
38 wxTEXT_ATTR_FONT_ITALIC = 0x00000020,
39 wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040,
40 wxTEXT_ATTR_FONT_ENCODING = 0x02000000,
41 wxTEXT_ATTR_FONT_FAMILY = 0x04000000,
42
43 /**
44 Defined as the combination of all @c wxTEXT_ATTR_FONT_* values above.
45 */
46 wxTEXT_ATTR_FONT = \
47 ( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \
48 wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ),
49
50 wxTEXT_ATTR_ALIGNMENT = 0x00000080,
51 wxTEXT_ATTR_LEFT_INDENT = 0x00000100,
52 wxTEXT_ATTR_RIGHT_INDENT = 0x00000200,
53 wxTEXT_ATTR_TABS = 0x00000400,
54 wxTEXT_ATTR_PARA_SPACING_AFTER = 0x00000800,
55 wxTEXT_ATTR_PARA_SPACING_BEFORE = 0x00001000,
56 wxTEXT_ATTR_LINE_SPACING = 0x00002000,
57 wxTEXT_ATTR_CHARACTER_STYLE_NAME = 0x00004000,
58 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME = 0x00008000,
59 wxTEXT_ATTR_LIST_STYLE_NAME = 0x00010000,
60
61 wxTEXT_ATTR_BULLET_STYLE = 0x00020000,
62 wxTEXT_ATTR_BULLET_NUMBER = 0x00040000,
63 wxTEXT_ATTR_BULLET_TEXT = 0x00080000,
64 wxTEXT_ATTR_BULLET_NAME = 0x00100000,
65
66 /**
67 Defined as the combination of all @c wxTEXT_ATTR_BULLET_* values above.
68 */
69 wxTEXT_ATTR_BULLET = \
70 ( wxTEXT_ATTR_BULLET_STYLE | wxTEXT_ATTR_BULLET_NUMBER | wxTEXT_ATTR_BULLET_TEXT | \
71 wxTEXT_ATTR_BULLET_NAME ),
72
73 wxTEXT_ATTR_URL = 0x00200000,
74 wxTEXT_ATTR_PAGE_BREAK = 0x00400000,
75 wxTEXT_ATTR_EFFECTS = 0x00800000,
76 wxTEXT_ATTR_OUTLINE_LEVEL = 0x01000000,
77
78 /**
79 Combines the styles @c wxTEXT_ATTR_FONT, @c wxTEXT_ATTR_EFFECTS, @c wxTEXT_ATTR_BACKGROUND_COLOUR,
80 @c wxTEXT_ATTR_TEXT_COLOUR, @c wxTEXT_ATTR_CHARACTER_STYLE_NAME, @c wxTEXT_ATTR_URL.
81 */
82
83 wxTEXT_ATTR_CHARACTER = \
84 (wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS| \
85 wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL),
86
87 /**
88 Combines all the styles regarding text paragraphs.
89 */
90 wxTEXT_ATTR_PARAGRAPH = \
91 (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
92 wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
93 wxTEXT_ATTR_BULLET|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL),
94
95 /**
96 Combines all previous values.
97 */
98 wxTEXT_ATTR_ALL = (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
99 };
100
101 /**
102 Styles for wxTextAttr::SetBulletStyle. They can be combined together as a bitlist.
103 */
104 enum wxTextAttrBulletStyle
105 {
106 wxTEXT_ATTR_BULLET_STYLE_NONE = 0x00000000,
107 wxTEXT_ATTR_BULLET_STYLE_ARABIC = 0x00000001,
108 wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER = 0x00000002,
109 wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER = 0x00000004,
110 wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER = 0x00000008,
111 wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER = 0x00000010,
112 wxTEXT_ATTR_BULLET_STYLE_SYMBOL = 0x00000020,
113
114 /** wxTEXT_ATTR_BULLET_STYLE_BITMAP is unimplemented. */
115 wxTEXT_ATTR_BULLET_STYLE_BITMAP = 0x00000040,
116 wxTEXT_ATTR_BULLET_STYLE_PARENTHESES = 0x00000080,
117 wxTEXT_ATTR_BULLET_STYLE_PERIOD = 0x00000100,
118 wxTEXT_ATTR_BULLET_STYLE_STANDARD = 0x00000200,
119 wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS = 0x00000400,
120 wxTEXT_ATTR_BULLET_STYLE_OUTLINE = 0x00000800,
121
122 wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT = 0x00000000,
123 wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT = 0x00001000,
124 wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE = 0x00002000
125 };
126
127 /**
128 Styles for wxTextAttr::SetTextEffects(). They can be combined together as a bitlist.
129
130 Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
131 wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
132 */
133 enum wxTextAttrEffects
134 {
135 wxTEXT_ATTR_EFFECT_NONE = 0x00000000,
136 wxTEXT_ATTR_EFFECT_CAPITALS = 0x00000001,
137 wxTEXT_ATTR_EFFECT_SMALL_CAPITALS = 0x00000002,
138 wxTEXT_ATTR_EFFECT_STRIKETHROUGH = 0x00000004,
139 wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH = 0x00000008,
140 wxTEXT_ATTR_EFFECT_SHADOW = 0x00000010,
141 wxTEXT_ATTR_EFFECT_EMBOSS = 0x00000020,
142 wxTEXT_ATTR_EFFECT_OUTLINE = 0x00000040,
143 wxTEXT_ATTR_EFFECT_ENGRAVE = 0x00000080,
144 wxTEXT_ATTR_EFFECT_SUPERSCRIPT = 0x00000100,
145 wxTEXT_ATTR_EFFECT_SUBSCRIPT = 0x00000200
146 };
147
148 /**
149 Convenience line spacing values; see wxTextAttr::SetLineSpacing().
150 */
151 enum wxTextAttrLineSpacing
152 {
153 wxTEXT_ATTR_LINE_SPACING_NORMAL = 10,
154 wxTEXT_ATTR_LINE_SPACING_HALF = 15,
155 wxTEXT_ATTR_LINE_SPACING_TWICE = 20
156 };
157
158
159 /**
160 Describes the possible return values of wxTextCtrl::HitTest().
161
162 The element names correspond to the relationship between the point asked
163 for and the character returned, e.g. @c wxTE_HT_BEFORE means that the point
164 is before (leftward or upward) it and so on.
165 */
166 enum wxTextCtrlHitTestResult
167 {
168 /// Indicates that wxTextCtrl::HitTest() is not implemented on this
169 /// platform.
170 wxTE_HT_UNKNOWN = -2,
171
172 /// The point is before the character returned.
173 wxTE_HT_BEFORE,
174
175 /// The point is directly on the character returned.
176 wxTE_HT_ON_TEXT,
177
178 /// The point is below the last line of the control.
179 wxTE_HT_BELOW,
180
181 /// The point is beyond the end of line containing the character returned.
182 wxTE_HT_BEYOND
183 };
184
185
186 /**
187 @class wxTextAttr
188
189 wxTextAttr represents the character and paragraph attributes, or style,
190 for a range of text in a wxTextCtrl or wxRichTextCtrl.
191
192 When setting up a wxTextAttr object, pass a bitlist mask to
193 wxTextAttr::SetFlags() to indicate which style elements should be changed.
194 As a convenience, when you call a setter such as SetFont, the relevant bit
195 will be set.
196
197 @library{wxcore}
198 @category{richtext}
199
200 @see wxTextCtrl, wxRichTextCtrl
201 */
202 class wxTextAttr
203 {
204 public:
205 //@{
206 /**
207 Constructors.
208 */
209 wxTextAttr();
210 wxTextAttr(const wxColour& colText,
211 const wxColour& colBack = wxNullColour,
212 const wxFont& font = wxNullFont,
213 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
214 wxTextAttr(const wxTextAttr& attr);
215 //@}
216
217 /**
218 Applies the attributes in @a style to the original object, but not those
219 attributes from @a style that are the same as those in @a compareWith (if passed).
220 */
221 bool Apply(const wxTextAttr& style,
222 const wxTextAttr* compareWith = NULL);
223
224 /**
225 Copies all defined/valid properties from overlay to current object.
226 */
227 void Merge(const wxTextAttr& overlay);
228
229 /**
230 Creates a new @c wxTextAttr which is a merge of @a base and @a overlay.
231
232 Properties defined in @a overlay take precedence over those in @a base.
233 Properties undefined/invalid in both are undefined in the result.
234 */
235 static wxTextAttr Merge(const wxTextAttr& base,
236 const wxTextAttr& overlay);
237
238
239 /**
240 @name GetXXX functions
241 */
242
243 //@{
244
245 /**
246 Returns the alignment flags.
247 See ::wxTextAttrAlignment for a list of available styles.
248 */
249 wxTextAttrAlignment GetAlignment() const;
250
251 /**
252 Returns the background colour.
253 */
254 const wxColour& GetBackgroundColour() const;
255
256 /**
257 Returns a string containing the name of the font associated with the bullet symbol.
258 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
259 */
260 const wxString& GetBulletFont() const;
261
262 /**
263 Returns the standard bullet name, applicable if the bullet style is
264 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
265
266 Currently the following standard bullet names are supported:
267 - @c standard/circle
268 - @c standard/square
269 - @c standard/diamond
270 - @c standard/triangle
271
272 @note
273 For wxRichTextCtrl users only: if you wish your rich text controls to support
274 further bullet graphics, you can derive a class from wxRichTextRenderer or
275 wxRichTextStdRenderer, override @c DrawStandardBullet and @c EnumerateStandardBulletNames,
276 and set an instance of the class using wxRichTextBuffer::SetRenderer.
277 */
278 const wxString& GetBulletName() const;
279
280 /**
281 Returns the bullet number.
282 */
283 int GetBulletNumber() const;
284
285 /**
286 Returns the bullet style.
287 See ::wxTextAttrBulletStyle for a list of available styles.
288 */
289 int GetBulletStyle() const;
290
291 /**
292 Returns the bullet text, which could be a symbol, or (for example) cached
293 outline text.
294 */
295 const wxString& GetBulletText() const;
296
297 /**
298 Returns the name of the character style.
299 */
300 const wxString& GetCharacterStyleName() const;
301
302 /**
303 Returns flags indicating which attributes are applicable.
304 See SetFlags() for a list of available flags.
305 */
306 long GetFlags() const;
307
308 /**
309 Creates and returns a font specified by the font attributes in the wxTextAttr
310 object. Note that wxTextAttr does not store a wxFont object, so this is only
311 a temporary font.
312
313 For greater efficiency, access the font attributes directly.
314 */
315 wxFont GetFont() const;
316
317 /**
318 Gets the font attributes from the given font, using only the attributes
319 specified by @a flags.
320 */
321 bool GetFontAttributes(const wxFont& font,
322 int flags = wxTEXT_ATTR_FONT);
323
324 /**
325 Returns the font encoding.
326 */
327 wxFontEncoding GetFontEncoding() const;
328
329 /**
330 Returns the font face name.
331 */
332 const wxString& GetFontFaceName() const;
333
334 /**
335 Returns the font family.
336 */
337 wxFontFamily GetFontFamily() const;
338
339 /**
340 Returns the font size in points.
341 */
342 int GetFontSize() const;
343
344 /**
345 Returns the font style.
346 */
347 wxFontStyle GetFontStyle() const;
348
349 /**
350 Returns @true if the font is underlined.
351 */
352 bool GetFontUnderlined() const;
353
354 /**
355 Returns the font weight.
356 */
357 wxFontWeight GetFontWeight() const;
358
359 /**
360 Returns the left indent in tenths of a millimetre.
361 */
362 long GetLeftIndent() const;
363
364 /**
365 Returns the left sub-indent in tenths of a millimetre.
366 */
367 long GetLeftSubIndent() const;
368
369 /**
370 Returns the line spacing value, one of ::wxTextAttrLineSpacing values.
371 */
372 int GetLineSpacing() const;
373
374 /**
375 Returns the name of the list style.
376 */
377 const wxString& GetListStyleName() const;
378
379 /**
380 Returns the outline level.
381 */
382 int GetOutlineLevel() const;
383
384 /**
385 Returns the space in tenths of a millimeter after the paragraph.
386 */
387 int GetParagraphSpacingAfter() const;
388
389 /**
390 Returns the space in tenths of a millimeter before the paragraph.
391 */
392 int GetParagraphSpacingBefore() const;
393
394 /**
395 Returns the name of the paragraph style.
396 */
397 const wxString& GetParagraphStyleName() const;
398
399 /**
400 Returns the right indent in tenths of a millimeter.
401 */
402 long GetRightIndent() const;
403
404 /**
405 Returns an array of tab stops, each expressed in tenths of a millimeter.
406
407 Each stop is measured from the left margin and therefore each value must
408 be larger than the last.
409 */
410 const wxArrayInt& GetTabs() const;
411
412 /**
413 Returns the text foreground colour.
414 */
415 const wxColour& GetTextColour() const;
416
417 /**
418 Returns the text effect bits of interest.
419 See SetFlags() for further information.
420 */
421 int GetTextEffectFlags() const;
422
423 /**
424 Returns the text effects, a bit list of styles.
425 See SetTextEffects() for details.
426 */
427 int GetTextEffects() const;
428
429 /**
430 Returns the URL for the content.
431
432 Content with @a wxTEXT_ATTR_URL style causes wxRichTextCtrl to show a
433 hand cursor over it, and wxRichTextCtrl generates a wxTextUrlEvent
434 when the content is clicked.
435 */
436 const wxString& GetURL() const;
437
438 //@}
439
440
441
442 /**
443 @name HasXXX and IsXXX functions
444 */
445
446 //@{
447
448 /**
449 Returns @true if the attribute object specifies alignment.
450 */
451 bool HasAlignment() const;
452
453 /**
454 Returns @true if the attribute object specifies a background colour.
455 */
456 bool HasBackgroundColour() const;
457
458 /**
459 Returns @true if the attribute object specifies a standard bullet name.
460 */
461 bool HasBulletName() const;
462
463 /**
464 Returns @true if the attribute object specifies a bullet number.
465 */
466 bool HasBulletNumber() const;
467
468 /**
469 Returns @true if the attribute object specifies a bullet style.
470 */
471 bool HasBulletStyle() const;
472
473 /**
474 Returns @true if the attribute object specifies bullet text (usually
475 specifying a symbol).
476 */
477 bool HasBulletText() const;
478
479 /**
480 Returns @true if the attribute object specifies a character style name.
481 */
482 bool HasCharacterStyleName() const;
483
484 /**
485 Returns @true if the @a flag is present in the attribute object's flag
486 bitlist.
487 */
488 bool HasFlag(long flag) const;
489
490 /**
491 Returns @true if the attribute object specifies any font attributes.
492 */
493 bool HasFont() const;
494
495 /**
496 Returns @true if the attribute object specifies an encoding.
497 */
498 bool HasFontEncoding() const;
499
500 /**
501 Returns @true if the attribute object specifies a font face name.
502 */
503 bool HasFontFaceName() const;
504
505 /**
506 Returns @true if the attribute object specifies a font family.
507 */
508 bool HasFontFamily() const;
509
510 /**
511 Returns @true if the attribute object specifies italic style.
512 */
513 bool HasFontItalic() const;
514
515 /**
516 Returns @true if the attribute object specifies a font point size.
517 */
518 bool HasFontSize() const;
519
520 /**
521 Returns @true if the attribute object specifies either underlining or no
522 underlining.
523 */
524 bool HasFontUnderlined() const;
525
526 /**
527 Returns @true if the attribute object specifies font weight (bold, light or
528 normal).
529 */
530 bool HasFontWeight() const;
531
532 /**
533 Returns @true if the attribute object specifies a left indent.
534 */
535 bool HasLeftIndent() const;
536
537 /**
538 Returns @true if the attribute object specifies line spacing.
539 */
540 bool HasLineSpacing() const;
541
542 /**
543 Returns @true if the attribute object specifies a list style name.
544 */
545 bool HasListStyleName() const;
546
547 /**
548 Returns @true if the attribute object specifies an outline level.
549 */
550 bool HasOutlineLevel() const;
551
552 /**
553 Returns @true if the attribute object specifies a page break before this
554 paragraph.
555 */
556 bool HasPageBreak() const;
557
558 /**
559 Returns @true if the attribute object specifies spacing after a paragraph.
560 */
561 bool HasParagraphSpacingAfter() const;
562
563 /**
564 Returns @true if the attribute object specifies spacing before a paragraph.
565 */
566 bool HasParagraphSpacingBefore() const;
567
568 /**
569 Returns @true if the attribute object specifies a paragraph style name.
570 */
571 bool HasParagraphStyleName() const;
572
573 /**
574 Returns @true if the attribute object specifies a right indent.
575 */
576 bool HasRightIndent() const;
577
578 /**
579 Returns @true if the attribute object specifies tab stops.
580 */
581 bool HasTabs() const;
582
583 /**
584 Returns @true if the attribute object specifies a text foreground colour.
585 */
586 bool HasTextColour() const;
587
588 /**
589 Returns @true if the attribute object specifies text effects.
590 */
591 bool HasTextEffects() const;
592
593 /**
594 Returns @true if the attribute object specifies a URL.
595 */
596 bool HasURL() const;
597
598 /**
599 Returns @true if the object represents a character style, that is,
600 the flags specify a font or a text background or foreground colour.
601 */
602 bool IsCharacterStyle() const;
603
604 /**
605 Returns @false if we have any attributes set, @true otherwise.
606 */
607 bool IsDefault() const;
608
609 /**
610 Returns @true if the object represents a paragraph style, that is,
611 the flags specify alignment, indentation, tabs, paragraph spacing, or
612 bullet style.
613 */
614 bool IsParagraphStyle() const;
615
616 //@}
617
618
619 /**
620 @name SetXXX functions
621 */
622
623 //@{
624
625 /**
626 Sets the paragraph alignment. See ::wxTextAttrAlignment enumeration values.
627
628 Of these, wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented.
629 In future justification may be supported when printing or previewing, only.
630 */
631 void SetAlignment(wxTextAttrAlignment alignment);
632
633 /**
634 Sets the background colour.
635 */
636 void SetBackgroundColour(const wxColour& colBack);
637
638 /**
639 Sets the name of the font associated with the bullet symbol.
640 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
641 */
642 void SetBulletFont(const wxString& font);
643
644 /**
645 Sets the standard bullet name, applicable if the bullet style is
646 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
647
648 See GetBulletName() for a list of supported names, and how
649 to expand the range of supported types.
650 */
651 void SetBulletName(const wxString& name);
652
653 /**
654 Sets the bullet number.
655 */
656 void SetBulletNumber(int n);
657
658 /**
659 Sets the bullet style.
660
661 The ::wxTextAttrBulletStyle enumeration values are all supported,
662 except for wxTEXT_ATTR_BULLET_STYLE_BITMAP.
663 */
664 void SetBulletStyle(int style);
665
666 /**
667 Sets the bullet text, which could be a symbol, or (for example) cached
668 outline text.
669 */
670 void SetBulletText(const wxString& text);
671
672 /**
673 Sets the character style name.
674 */
675 void SetCharacterStyleName(const wxString& name);
676
677 /**
678 Sets the flags determining which styles are being specified.
679 The ::wxTextAttrFlags values can be passed in a bitlist.
680 */
681 void SetFlags(long flags);
682
683 /**
684 Sets the attributes for the given font.
685 Note that wxTextAttr does not store an actual wxFont object.
686 */
687 void SetFont(const wxFont& font, int flags = wxTEXT_ATTR_FONT);
688
689 /**
690 Sets the font encoding.
691 */
692 void SetFontEncoding(wxFontEncoding encoding);
693
694 /**
695 Sets the font face name.
696 */
697 void SetFontFaceName(const wxString& faceName);
698
699 /**
700 Sets the font family.
701 */
702 void SetFontFamily(wxFontFamily family);
703
704 /**
705 Sets the font size in points.
706 */
707 void SetFontSize(int pointSize);
708
709 /**
710 Sets the font style (normal, italic or slanted).
711 */
712 void SetFontStyle(wxFontStyle fontStyle);
713
714 /**
715 Sets the font underlining.
716 */
717 void SetFontUnderlined(bool underlined);
718
719 /**
720 Sets the font weight.
721 */
722 void SetFontWeight(wxFontWeight fontWeight);
723
724 /**
725 Sets the left indent and left subindent in tenths of a millimetre.
726 The sub-indent is an offset from the left of the paragraph, and is used for all
727 but the first line in a paragraph.
728
729 A positive value will cause the first line to appear to the left
730 of the subsequent lines, and a negative value will cause the first line to be
731 indented relative to the subsequent lines.
732
733 wxRichTextBuffer uses indentation to render a bulleted item.
734 The left indent is the distance between the margin and the bullet.
735 The content of the paragraph, including the first line, starts
736 at leftMargin + leftSubIndent.
737 So the distance between the left edge of the bullet and the
738 left of the actual paragraph is leftSubIndent.
739 */
740 void SetLeftIndent(int indent, int subIndent = 0);
741
742 /**
743 Sets the line spacing. @a spacing is a multiple, where 10 means single-spacing,
744 15 means 1.5 spacing, and 20 means double spacing.
745 The ::wxTextAttrLineSpacing values are defined for convenience.
746 */
747 void SetLineSpacing(int spacing);
748
749 /**
750 Sets the list style name.
751 */
752 void SetListStyleName(const wxString& name);
753
754 /**
755 Specifies the outline level. Zero represents normal text.
756 At present, the outline level is not used, but may be used in future for
757 determining list levels and for applications that need to store document
758 structure information.
759 */
760 void SetOutlineLevel(int level);
761
762 /**
763 Specifies a page break before this paragraph.
764 */
765 void SetPageBreak(bool pageBreak = true);
766
767 /**
768 Sets the spacing after a paragraph, in tenths of a millimetre.
769 */
770 void SetParagraphSpacingAfter(int spacing);
771
772 /**
773 Sets the spacing before a paragraph, in tenths of a millimetre.
774 */
775 void SetParagraphSpacingBefore(int spacing);
776
777 /**
778 Sets the name of the paragraph style.
779 */
780 void SetParagraphStyleName(const wxString& name);
781
782 /**
783 Sets the right indent in tenths of a millimetre.
784 */
785 void SetRightIndent(int indent);
786
787 /**
788 Sets the tab stops, expressed in tenths of a millimetre.
789 Each stop is measured from the left margin and therefore each value must be
790 larger than the last.
791 */
792 void SetTabs(const wxArrayInt& tabs);
793
794 /**
795 Sets the text foreground colour.
796 */
797 void SetTextColour(const wxColour& colText);
798
799 /**
800 Sets the text effect bits of interest.
801
802 You should also pass wxTEXT_ATTR_EFFECTS to SetFlags().
803 See SetFlags() for further information.
804 */
805 void SetTextEffectFlags(int flags);
806
807 /**
808 Sets the text effects, a bit list of styles.
809 The ::wxTextAttrEffects enumeration values can be used.
810
811 Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
812 wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
813
814 wxTEXT_ATTR_EFFECT_CAPITALS capitalises text when displayed (leaving the case
815 of the actual buffer text unchanged), and wxTEXT_ATTR_EFFECT_STRIKETHROUGH draws
816 a line through text.
817
818 To set effects, you should also pass wxTEXT_ATTR_EFFECTS to SetFlags(), and call
819 SetTextEffectFlags() with the styles (taken from the above set) that you
820 are interested in setting.
821 */
822 void SetTextEffects(int effects);
823
824 /**
825 Sets the URL for the content. Sets the wxTEXT_ATTR_URL style; content with this
826 style causes wxRichTextCtrl to show a hand cursor over it, and wxRichTextCtrl
827 generates a wxTextUrlEvent when the content is clicked.
828 */
829 void SetURL(const wxString& url);
830
831 //@}
832
833
834 /**
835 Assignment from a wxTextAttr object.
836 */
837 void operator operator=(const wxTextAttr& attr);
838 };
839
840
841 /**
842 @class wxTextCtrl
843
844 A text control allows text to be displayed and edited.
845
846 It may be single line or multi-line. Notice that a lot of methods of the
847 text controls are found in the base wxTextEntry class which is a common
848 base class for wxTextCtrl and other controls using a single line text entry
849 field (e.g. wxComboBox).
850
851 @beginStyleTable
852 @style{wxTE_PROCESS_ENTER}
853 The control will generate the event @c wxEVT_COMMAND_TEXT_ENTER
854 (otherwise pressing Enter key is either processed internally by the
855 control or used for navigation between dialog controls).
856 @style{wxTE_PROCESS_TAB}
857 The control will receive @c wxEVT_CHAR events for TAB pressed -
858 normally, TAB is used for passing to the next control in a dialog
859 instead. For the control created with this style, you can still use
860 Ctrl-Enter to pass to the next control from the keyboard.
861 @style{wxTE_MULTILINE}
862 The text control allows multiple lines. If this style is not
863 specified, line break characters should not be used in the controls
864 value.
865 @style{wxTE_PASSWORD}
866 The text will be echoed as asterisks.
867 @style{wxTE_READONLY}
868 The text will not be user-editable.
869 @style{wxTE_RICH}
870 Use rich text control under Win32, this allows to have more than
871 64KB of text in the control even under Win9x. This style is ignored
872 under other platforms.
873 @style{wxTE_RICH2}
874 Use rich text control version 2.0 or 3.0 under Win32, this style is
875 ignored under other platforms
876 @style{wxTE_AUTO_URL}
877 Highlight the URLs and generate the wxTextUrlEvents when mouse
878 events occur over them. This style is only supported for wxTE_RICH
879 Win32 and multi-line wxGTK2 text controls.
880 @style{wxTE_NOHIDESEL}
881 By default, the Windows text control doesn't show the selection
882 when it doesn't have focus - use this style to force it to always
883 show it. It doesn't do anything under other platforms.
884 @style{wxHSCROLL}
885 A horizontal scrollbar will be created and used, so that text won't
886 be wrapped. No effect under wxGTK1.
887 @style{wxTE_NO_VSCROLL}
888 For multiline controls only: vertical scrollbar will never be
889 created. This limits the amount of text which can be entered into
890 the control to what can be displayed in it under MSW but not under
891 GTK2. Currently not implemented for the other platforms.
892 @style{wxTE_LEFT}
893 The text in the control will be left-justified (default).
894 @style{wxTE_CENTRE}
895 The text in the control will be centered (currently wxMSW and
896 wxGTK2 only).
897 @style{wxTE_RIGHT}
898 The text in the control will be right-justified (currently wxMSW
899 and wxGTK2 only).
900 @style{wxTE_DONTWRAP}
901 Same as wxHSCROLL style: don't wrap at all, show horizontal
902 scrollbar instead.
903 @style{wxTE_CHARWRAP}
904 Wrap the lines too long to be shown entirely at any position
905 (wxUniv and wxGTK2 only).
906 @style{wxTE_WORDWRAP}
907 Wrap the lines too long to be shown entirely at word boundaries
908 (wxUniv and wxGTK2 only).
909 @style{wxTE_BESTWRAP}
910 Wrap the lines at word boundaries or at any other character if
911 there are words longer than the window width (this is the default).
912 @style{wxTE_CAPITALIZE}
913 On PocketPC and Smartphone, causes the first letter to be
914 capitalized.
915 @endStyleTable
916
917 Note that alignment styles (wxTE_LEFT, wxTE_CENTRE and wxTE_RIGHT) can be
918 changed dynamically after control creation on wxMSW and wxGTK. wxTE_READONLY,
919 wxTE_PASSWORD and wrapping styles can be dynamically changed under wxGTK but
920 not wxMSW. The other styles can be only set during control creation.
921
922
923 @section textctrl_text_format wxTextCtrl Text Format
924
925 The multiline text controls always store the text as a sequence of lines
926 separated by @c '\\n' characters, i.e. in the Unix text format even on
927 non-Unix platforms. This allows the user code to ignore the differences
928 between the platforms but at a price: the indices in the control such as
929 those returned by GetInsertionPoint() or GetSelection() can @b not be used
930 as indices into the string returned by GetValue() as they're going to be
931 slightly off for platforms using @c "\\r\\n" as separator (as Windows
932 does).
933
934 Instead, if you need to obtain a substring between the 2 indices obtained
935 from the control with the help of the functions mentioned above, you should
936 use GetRange(). And the indices themselves can only be passed to other
937 methods, for example SetInsertionPoint() or SetSelection().
938
939 To summarize: never use the indices returned by (multiline) wxTextCtrl as
940 indices into the string it contains, but only as arguments to be passed
941 back to the other wxTextCtrl methods. This problem doesn't arise for
942 single-line platforms however where the indices in the control do
943 correspond to the positions in the value string.
944
945
946 @section textctrl_styles wxTextCtrl Styles.
947
948 Multi-line text controls support styling, i.e. provide a possibility to set
949 colours and font for individual characters in it (note that under Windows
950 @c wxTE_RICH style is required for style support). To use the styles you
951 can either call SetDefaultStyle() before inserting the text or call
952 SetStyle() later to change the style of the text already in the control
953 (the first solution is much more efficient).
954
955 In either case, if the style doesn't specify some of the attributes (for
956 example you only want to set the text colour but without changing the font
957 nor the text background), the values of the default style will be used for
958 them. If there is no default style, the attributes of the text control
959 itself are used.
960
961 So the following code correctly describes what it does: the second call to
962 SetDefaultStyle() doesn't change the text foreground colour (which stays
963 red) while the last one doesn't change the background colour (which stays
964 grey):
965
966 @code
967 text->SetDefaultStyle(wxTextAttr(*wxRED));
968 text->AppendText("Red text\n");
969 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
970 text->AppendText("Red on grey text\n");
971 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
972 text->AppendText("Blue on grey text\n");
973 @endcode
974
975
976 @section textctrl_cpp_streams wxTextCtrl and C++ Streams
977
978 This class multiply-inherits from @c std::streambuf (except for some really
979 old compilers using non-standard iostream library), allowing code such as
980 the following:
981
982 @code
983 wxTextCtrl *control = new wxTextCtrl(...);
984
985 ostream stream(control)
986
987 stream << 123.456 << " some text\n";
988 stream.flush();
989 @endcode
990
991 Note that even if your compiler doesn't support this (the symbol
992 @c wxHAS_TEXT_WINDOW_STREAM has value of 0 then) you can still use
993 wxTextCtrl itself in a stream-like manner:
994
995 @code
996 wxTextCtrl *control = new wxTextCtrl(...);
997
998 *control << 123.456 << " some text\n";
999 @endcode
1000
1001 However the possibility to create an ostream associated with wxTextCtrl may
1002 be useful if you need to redirect the output of a function taking an
1003 ostream as parameter to a text control.
1004
1005 Another commonly requested need is to redirect @c std::cout to the text
1006 control. This may be done in the following way:
1007
1008 @code
1009 #include <iostream>
1010
1011 wxTextCtrl *control = new wxTextCtrl(...);
1012
1013 std::streambuf *sbOld = std::cout.rdbuf();
1014 std::cout.rdbuf(control);
1015
1016 // use cout as usual, the output appears in the text control
1017 ...
1018
1019 std::cout.rdbuf(sbOld);
1020 @endcode
1021
1022 But wxWidgets provides a convenient class to make it even simpler so
1023 instead you may just do
1024
1025 @code
1026 #include <iostream>
1027
1028 wxTextCtrl *control = new wxTextCtrl(...);
1029
1030 wxStreamToTextRedirector redirect(control);
1031
1032 // all output to cout goes into the text control until the exit from
1033 // current scope
1034 @endcode
1035
1036 See wxStreamToTextRedirector for more details.
1037
1038
1039 @section textctrl_event_handling Event Handling.
1040
1041 The following commands are processed by default event handlers in
1042 wxTextCtrl: @c wxID_CUT, @c wxID_COPY, @c wxID_PASTE, @c wxID_UNDO, @c
1043 wxID_REDO. The associated UI update events are also processed
1044 automatically, when the control has the focus.
1045
1046 @beginEventEmissionTable{wxCommandEvent}
1047 @event{EVT_TEXT(id, func)}
1048 Respond to a @c wxEVT_COMMAND_TEXT_UPDATED event, generated when the text
1049 changes. Notice that this event will be sent when the text controls
1050 contents changes -- whether this is due to user input or comes from the
1051 program itself (for example, if wxTextCtrl::SetValue() is called); see
1052 wxTextCtrl::ChangeValue() for a function which does not send this event.
1053 This event is however not sent during the control creation.
1054 @event{EVT_TEXT_ENTER(id, func)}
1055 Respond to a @c wxEVT_COMMAND_TEXT_ENTER event, generated when enter is
1056 pressed in a text control which must have wxTE_PROCESS_ENTER style for
1057 this event to be generated.
1058 @event{EVT_TEXT_URL(id, func)}
1059 A mouse event occurred over an URL in the text control (wxMSW and
1060 wxGTK2 only currently).
1061 @event{EVT_TEXT_MAXLEN(id, func)}
1062 This event is generated when the user tries to enter more text into the
1063 control than the limit set by wxTextCtrl::SetMaxLength(), see its description.
1064 @endEventTable
1065
1066 @library{wxcore}
1067 @category{ctrl}
1068 @appearance{textctrl.png}
1069
1070 @see wxTextCtrl::Create, wxValidator
1071 */
1072 class wxTextCtrl : public wxControl,
1073 public wxTextEntry
1074 {
1075 public:
1076 /**
1077 Default ctor.
1078 */
1079 wxTextCtrl();
1080
1081 /**
1082 Constructor, creating and showing a text control.
1083
1084 @param parent
1085 Parent window. Should not be @NULL.
1086 @param id
1087 Control identifier. A value of -1 denotes a default value.
1088 @param value
1089 Default text value.
1090 @param pos
1091 Text control position.
1092 @param size
1093 Text control size.
1094 @param style
1095 Window style. See wxTextCtrl.
1096 @param validator
1097 Window validator.
1098 @param name
1099 Window name.
1100
1101 @remarks
1102 The horizontal scrollbar (wxHSCROLL style flag) will only be
1103 created for multi-line text controls. Without a horizontal
1104 scrollbar, text lines that don't fit in the control's size will be
1105 wrapped (but no newline character is inserted).
1106 Single line controls don't have a horizontal scrollbar, the text is
1107 automatically scrolled so that the insertion point is always visible.
1108
1109 @see Create(), wxValidator
1110 */
1111 wxTextCtrl(wxWindow* parent, wxWindowID id,
1112 const wxString& value = wxEmptyString,
1113 const wxPoint& pos = wxDefaultPosition,
1114 const wxSize& size = wxDefaultSize,
1115 long style = 0,
1116 const wxValidator& validator = wxDefaultValidator,
1117 const wxString& name = wxTextCtrlNameStr);
1118
1119 /**
1120 Destructor, destroying the text control.
1121 */
1122 virtual ~wxTextCtrl();
1123
1124 /**
1125 Creates the text control for two-step construction.
1126
1127 This method should be called if the default constructor was used for
1128 the control creation. Its parameters have the same meaning as for the
1129 non-default constructor.
1130 */
1131 bool Create(wxWindow* parent, wxWindowID id,
1132 const wxString& value = wxEmptyString,
1133 const wxPoint& pos = wxDefaultPosition,
1134 const wxSize& size = wxDefaultSize, long style = 0,
1135 const wxValidator& validator = wxDefaultValidator,
1136 const wxString& name = wxTextCtrlNameStr);
1137
1138 /**
1139 Copies the selected text to the clipboard and removes the selection.
1140 */
1141 virtual void Cut();
1142
1143 /**
1144 Resets the internal modified flag as if the current changes had been
1145 saved.
1146 */
1147 virtual void DiscardEdits();
1148
1149 /**
1150 This function inserts into the control the character which would have
1151 been inserted if the given key event had occurred in the text control.
1152
1153 The @a event object should be the same as the one passed to @c EVT_KEY_DOWN
1154 handler previously by wxWidgets. Please note that this function doesn't
1155 currently work correctly for all keys under any platform but MSW.
1156
1157 @return
1158 @true if the event resulted in a change to the control, @false otherwise.
1159 */
1160 virtual bool EmulateKeyPress(const wxKeyEvent& event);
1161
1162 /**
1163 Returns the style currently used for the new text.
1164
1165 @see SetDefaultStyle()
1166 */
1167 virtual const wxTextAttr& GetDefaultStyle() const;
1168
1169 /**
1170 Gets the length of the specified line, not including any trailing
1171 newline character(s).
1172
1173 @param lineNo
1174 Line number (starting from zero).
1175
1176 @return
1177 The length of the line, or -1 if @a lineNo was invalid.
1178 */
1179 virtual int GetLineLength(long lineNo) const;
1180
1181 /**
1182 Returns the contents of a given line in the text control, not including
1183 any trailing newline character(s).
1184
1185 @param lineNo
1186 The line number, starting from zero.
1187
1188 @return
1189 The contents of the line.
1190 */
1191 virtual wxString GetLineText(long lineNo) const;
1192
1193 /**
1194 Returns the number of lines in the text control buffer.
1195
1196 The returned number is the number of logical lines, i.e. just the count
1197 of the number of newline characters in the control + 1, for wxGTK and
1198 wxOSX/Cocoa ports while it is the number of physical lines, i.e. the
1199 count of lines actually shown in the control, in wxMSW and wxOSX/Carbon.
1200 Because of this discrepancy, it is not recommended to use this function.
1201
1202 @remarks
1203 Note that even empty text controls have one line (where the
1204 insertion point is), so GetNumberOfLines() never returns 0.
1205 */
1206 virtual int GetNumberOfLines() const;
1207
1208 /**
1209 Returns the style at this position in the text control.
1210
1211 Not all platforms support this function.
1212
1213 @return
1214 @true on success, @false if an error occurred (this may also mean
1215 that the styles are not supported under this platform).
1216
1217 @see SetStyle(), wxTextAttr
1218 */
1219 virtual bool GetStyle(long position, wxTextAttr& style);
1220
1221 //@{
1222 /**
1223 This function finds the character at the specified position expressed
1224 in pixels.
1225
1226 The two overloads of this method allow to find either the position of
1227 the character, as an index into the text control contents, or its row
1228 and column.
1229
1230 If the return code is not @c wxTE_HT_UNKNOWN the row and column of the
1231 character closest to this position are returned, otherwise the output
1232 parameters are not modified.
1233
1234 Please note that this function is currently only implemented in wxUniv,
1235 wxMSW and wxGTK2 ports and always returns @c wxTE_HT_UNKNOWN in the
1236 other ports.
1237
1238 @beginWxPerlOnly
1239 In wxPerl this function takes only the @a pt argument and
1240 returns a 3-element list (result, col, row).
1241 @endWxPerlOnly
1242
1243 @param pt
1244 The position of the point to check, in window device coordinates.
1245 @param col
1246 Receives the column of the character at the given position. May be
1247 @NULL.
1248 @param row
1249 Receives the row of the character at the given position. May be
1250 @NULL.
1251 @param pos
1252 Receives the position of the character at the given position. May
1253 be @NULL.
1254
1255 @see PositionToXY(), XYToPosition()
1256 */
1257 wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
1258 wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
1259 wxTextCoord *col,
1260 wxTextCoord *row) const;
1261 //@}
1262
1263 /**
1264 Returns @true if the text has been modified by user.
1265
1266 Note that calling SetValue() doesn't make the control modified.
1267
1268 @see MarkDirty()
1269 */
1270 virtual bool IsModified() const;
1271
1272 /**
1273 Returns @true if this is a multi line edit control and @false otherwise.
1274
1275 @see IsSingleLine()
1276 */
1277 bool IsMultiLine() const;
1278
1279 /**
1280 Returns @true if this is a single line edit control and @false otherwise.
1281
1282 @see IsSingleLine(), IsMultiLine()
1283 */
1284 bool IsSingleLine() const;
1285
1286 /**
1287 Loads and displays the named file, if it exists.
1288
1289 @param filename
1290 The filename of the file to load.
1291 @param fileType
1292 The type of file to load. This is currently ignored in wxTextCtrl.
1293
1294 @return
1295 @true if successful, @false otherwise.
1296 */
1297 bool LoadFile(const wxString& filename,
1298 int fileType = wxTEXT_TYPE_ANY);
1299
1300 /**
1301 Mark text as modified (dirty).
1302
1303 @see IsModified()
1304 */
1305 virtual void MarkDirty();
1306
1307 /**
1308 This event handler function implements default drag and drop behaviour,
1309 which is to load the first dropped file into the control.
1310
1311 @param event
1312 The drop files event.
1313
1314 @remarks This is not implemented on non-Windows platforms.
1315
1316 @see wxDropFilesEvent
1317 */
1318 void OnDropFiles(wxDropFilesEvent& event);
1319
1320 /**
1321 Converts given position to a zero-based column, line number pair.
1322
1323 @param pos
1324 Position.
1325 @param x
1326 Receives zero based column number.
1327 @param y
1328 Receives zero based line number.
1329
1330 @return
1331 @true on success, @false on failure (most likely due to a too large
1332 position parameter).
1333
1334 @beginWxPerlOnly
1335 In wxPerl this function takes only the @a pos argument and
1336 returns a 2-element list (x, y).
1337 @endWxPerlOnly
1338
1339 @see XYToPosition()
1340 */
1341 virtual bool PositionToXY(long pos, long* x, long* y) const;
1342
1343 /**
1344 Converts given text position to client coordinates in pixels.
1345
1346 This function allows to find where is the character at the given
1347 position displayed in the text control.
1348
1349 @onlyfor{wxmsw,wxgtk}. Additionally, wxGTK only implements this method
1350 for multiline controls and ::wxDefaultPosition is always returned for
1351 the single line ones.
1352
1353 @param pos
1354 Text position in 0 to GetLastPosition() range (inclusive).
1355 @return
1356 On success returns a wxPoint which contains client coordinates for
1357 the given position in pixels, otherwise returns ::wxDefaultPosition.
1358
1359 @since 2.9.3
1360
1361 @see XYToPosition(), PositionToXY()
1362 */
1363 wxPoint PositionToCoords(long pos) const;
1364
1365 /**
1366 Saves the contents of the control in a text file.
1367
1368 @param filename
1369 The name of the file in which to save the text.
1370 @param fileType
1371 The type of file to save. This is currently ignored in wxTextCtrl.
1372
1373 @return
1374 @true if the operation was successful, @false otherwise.
1375 */
1376 bool SaveFile(const wxString& filename = wxEmptyString,
1377 int fileType = wxTEXT_TYPE_ANY);
1378
1379 /**
1380 Changes the default style to use for the new text which is going to be
1381 added to the control using WriteText() or AppendText().
1382
1383 If either of the font, foreground, or background colour is not set in
1384 @a style, the values of the previous default style are used for them.
1385 If the previous default style didn't set them neither, the global font
1386 or colours of the text control itself are used as fall back.
1387
1388 However if the @a style parameter is the default wxTextAttr, then the default
1389 style is just reset (instead of being combined with the new style which
1390 wouldn't change it at all).
1391
1392 @param style
1393 The style for the new text.
1394
1395 @return
1396 @true on success, @false if an error occurred (this may also mean
1397 that the styles are not supported under this platform).
1398
1399 @see GetDefaultStyle()
1400 */
1401 virtual bool SetDefaultStyle(const wxTextAttr& style);
1402
1403 /**
1404 Marks the control as being modified by the user or not.
1405
1406 @see MarkDirty(), DiscardEdits()
1407 */
1408 void SetModified(bool modified);
1409
1410 /**
1411 Changes the style of the given range.
1412
1413 If any attribute within @a style is not set, the corresponding
1414 attribute from GetDefaultStyle() is used.
1415
1416 @param start
1417 The start of the range to change.
1418 @param end
1419 The end of the range to change.
1420 @param style
1421 The new style for the range.
1422
1423 @return
1424 @true on success, @false if an error occurred (this may also mean
1425 that the styles are not supported under this platform).
1426
1427 @see GetStyle(), wxTextAttr
1428 */
1429 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
1430
1431 /**
1432 Makes the line containing the given position visible.
1433
1434 @param pos
1435 The position that should be visible.
1436 */
1437 virtual void ShowPosition(long pos);
1438
1439 /**
1440 Converts the given zero based column and line number to a position.
1441
1442 @param x
1443 The column number.
1444 @param y
1445 The line number.
1446
1447 @return
1448 The position value, or -1 if x or y was invalid.
1449 */
1450 virtual long XYToPosition(long x, long y) const;
1451
1452 //@{
1453 /**
1454 Operator definitions for appending to a text control.
1455
1456 These operators can be used as with the standard C++ streams, for
1457 example:
1458 @code
1459 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1460
1461 (*wnd) << "Welcome to text control number " << 1 << ".\n";
1462 @endcode
1463 */
1464
1465 wxTextCtrl& operator<<(const wxString& s);
1466 wxTextCtrl& operator<<(int i);
1467 wxTextCtrl& operator<<(long i);
1468 wxTextCtrl& operator<<(float f);
1469 wxTextCtrl& operator<<(double d);
1470 wxTextCtrl& operator<<(char c);
1471 wxTextCtrl& operator<<(wchar_t c);
1472 //@}
1473 };
1474
1475
1476
1477 /**
1478 @class wxStreamToTextRedirector
1479
1480 This class can be used to (temporarily) redirect all output sent to a C++
1481 ostream object to a wxTextCtrl instead.
1482
1483 @note
1484 Some compilers and/or build configurations don't support multiply
1485 inheriting wxTextCtrl from @c std::streambuf in which case this class is
1486 not compiled in.
1487 You also must have @c wxUSE_STD_IOSTREAM option on (i.e. set to 1) in your
1488 @c setup.h to be able to use it. Under Unix, specify @c --enable-std_iostreams
1489 switch when running configure for this.
1490
1491 Example of usage:
1492
1493 @code
1494 using namespace std;
1495 wxTextCtrl* text = new wxTextCtrl(...);
1496 {
1497 wxStreamToTextRedirector redirect(text);
1498
1499 // this goes to the text control
1500 cout << "Hello, text!" << endl;
1501 }
1502 // this goes somewhere else, presumably to stdout
1503 cout << "Hello, console!" << endl;
1504 @endcode
1505
1506 @library{wxcore}
1507 @category{logging}
1508
1509 @see wxTextCtrl
1510 */
1511 class wxStreamToTextRedirector
1512 {
1513 public:
1514 /**
1515 The constructor starts redirecting output sent to @a ostr or @a cout for
1516 the default parameter value to the text control @a text.
1517
1518 @param text
1519 The text control to append output too, must be non-@NULL
1520 @param ostr
1521 The C++ stream to redirect, cout is used if it is @NULL
1522 */
1523 wxStreamToTextRedirector(wxTextCtrl *text, ostream* ostr);
1524
1525 /**
1526 When a wxStreamToTextRedirector object is destroyed, the redirection is ended
1527 and any output sent to the C++ ostream which had been specified at the time of
1528 the object construction will go to its original destination.
1529 */
1530 ~wxStreamToTextRedirector();
1531 };
1532