]> git.saurik.com Git - wxWidgets.git/blame - interface/textctrl.h
Finished review/fixes of GDI category of functions and macros.
[wxWidgets.git] / interface / textctrl.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: textctrl.h
e54c96f1 3// Purpose: interface of wxTextAttr
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxTextAttr
11 @wxheader{textctrl.h}
7c913512 12
23324ae1
FM
13 wxTextAttr represents the character and paragraph attributes, or style,
14 for a range of text in a wxTextCtrl or wxRichTextCtrl.
7c913512 15
23324ae1
FM
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
19 call a setter such
20 as SetFont, the relevant bit will be set.
7c913512 21
23324ae1
FM
22 @library{wxcore}
23 @category{richtext}
7c913512 24
e54c96f1 25 @see wxTextCtrl, wxRichTextCtrl
23324ae1 26*/
7c913512 27class wxTextAttr
23324ae1
FM
28{
29public:
30 //@{
31 /**
32 Constructors.
33 */
34 wxTextAttr();
7c913512
FM
35 wxTextAttr(const wxColour& colText,
36 const wxColour& colBack = wxNullColour,
37 const wxFont& font = wxNullFont,
38 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
39 wxTextAttr(const wxTextAttr& attr);
23324ae1
FM
40 //@}
41
42 /**
4cc4bfaf
FM
43 Applies the attributes in @a style to the original object, but not those
44 attributes from @a style that are the same as those in @a compareWith (if passed).
23324ae1
FM
45 */
46 bool Apply(const wxTextAttr& style,
4cc4bfaf 47 const wxTextAttr* compareWith = NULL);
23324ae1
FM
48
49 /**
50 Creates a font from the font attributes.
51 */
328f5751 52 wxFont CreateFont() const;
23324ae1
FM
53
54 /**
55 Returns the alignment flags.
56 See SetAlignment() for a list of available styles.
57 */
328f5751 58 wxTextAttrAlignment GetAlignment() const;
23324ae1
FM
59
60 /**
61 Returns the background colour.
62 */
328f5751 63 const wxColour GetBackgroundColour() const;
23324ae1
FM
64
65 /**
66 Returns a string containing the name of the font associated with the bullet
67 symbol.
68 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
69 */
328f5751 70 const wxString GetBulletFont() const;
23324ae1
FM
71
72 /**
73 Returns the standard bullet name, applicable if the bullet style is
74 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
75 Currently the following standard bullet names are supported:
23324ae1
FM
76 @c standard/circle
77 @c standard/square
78 @c standard/diamond
79 @c standard/triangle
23324ae1
FM
80 For wxRichTextCtrl users only: if you wish your rich text controls to support
81 further bullet graphics, you can derive a
82 class from wxRichTextRenderer or wxRichTextStdRenderer, override @c
83 DrawStandardBullet and @c EnumerateStandardBulletNames, and
84 set an instance of the class using wxRichTextBuffer::SetRenderer.
85 */
328f5751 86 const wxString GetBulletName() const;
23324ae1
FM
87
88 /**
89 Returns the bullet number.
90 */
328f5751 91 int GetBulletNumber() const;
23324ae1
FM
92
93 /**
94 Returns the bullet style.
95 See SetBulletStyle() for a list of available styles.
96 */
328f5751 97 int GetBulletStyle() const;
23324ae1
FM
98
99 /**
100 Returns the bullet text, which could be a symbol, or (for example) cached
101 outline text.
102 */
328f5751 103 const wxString GetBulletText() const;
23324ae1
FM
104
105 /**
106 Returns the name of the character style.
107 */
328f5751 108 const wxString GetCharacterStyleName() const;
23324ae1
FM
109
110 /**
111 Returns flags indicating which attributes are applicable.
112 See SetFlags() for a list of available flags.
113 */
328f5751 114 long GetFlags() const;
23324ae1
FM
115
116 /**
117 Creates and returns a font specified by the font attributes in the wxTextAttr
118 object. Note that
119 wxTextAttr does not store a wxFont object, so this is only a temporary font.
120 For greater
121 efficiency, access the font attributes directly.
122 */
328f5751 123 wxFont GetFont() const;
23324ae1
FM
124
125 /**
126 Gets the font attributes from the given font, using only the attributes
127 specified by @e flags.
128 */
129 bool GetFontAttributes(const wxFont& font,
130 int flags = wxTEXT_ATTR_FONT);
131
132 /**
133 Returns the font encoding.
134 */
328f5751 135 wxFontEncoding GetFontEncoding() const;
23324ae1
FM
136
137 /**
138 Returns the font face name.
139 */
328f5751 140 const wxString GetFontFaceName() const;
23324ae1
FM
141
142 /**
143 Returns the font size in points.
144 */
328f5751 145 int GetFontSize() const;
23324ae1
FM
146
147 /**
148 Returns the font style.
149 */
328f5751 150 int GetFontStyle() const;
23324ae1
FM
151
152 /**
153 Returns @true if the font is underlined.
154 */
328f5751 155 bool GetFontUnderlined() const;
23324ae1
FM
156
157 /**
158 Returns the font weight.
159 */
328f5751 160 int GetFontWeight() const;
23324ae1
FM
161
162 /**
163 Returns the left indent in tenths of a millimetre.
164 */
328f5751 165 long GetLeftIndent() const;
23324ae1
FM
166
167 /**
168 Returns the left sub-indent in tenths of a millimetre.
169 */
328f5751 170 long GetLeftSubIndent() const;
23324ae1
FM
171
172 /**
173 Returns the line spacing value, one of wxTEXT_ATTR_LINE_SPACING_NORMAL,
174 wxTEXT_ATTR_LINE_SPACING_HALF, and wxTEXT_ATTR_LINE_SPACING_TWICE.
175 */
328f5751 176 int GetLineSpacing() const;
23324ae1
FM
177
178 /**
179 Returns the name of the list style.
180 */
328f5751 181 const wxString GetListStyleName() const;
23324ae1
FM
182
183 /**
184 Returns the outline level.
185 */
328f5751 186 bool GetOutlineLevel() const;
23324ae1
FM
187
188 /**
189 Returns the space in tenths of a millimeter after the paragraph.
190 */
328f5751 191 int GetParagraphSpacingAfter() const;
23324ae1
FM
192
193 /**
194 Returns the space in tenths of a millimeter before the paragraph.
195 */
328f5751 196 int GetParagraphSpacingBefore() const;
23324ae1
FM
197
198 /**
199 Returns the name of the paragraph style.
200 */
328f5751 201 const wxString GetParagraphStyleName() const;
23324ae1
FM
202
203 /**
204 Returns the right indent in tenths of a millimeter.
205 */
328f5751 206 long GetRightIndent() const;
23324ae1
FM
207
208 /**
209 Returns an array of tab stops, each expressed in tenths of a millimeter. Each
210 stop
211 is measured from the left margin and therefore each value must be larger than
212 the last.
213 */
328f5751 214 const wxArrayInt GetTabs() const;
23324ae1
FM
215
216 /**
217 Returns the text foreground colour.
218 */
328f5751 219 const wxColour GetTextColour() const;
23324ae1
FM
220
221 /**
222 Returns the text effect bits of interest. See SetFlags() for further
223 information.
224 */
328f5751 225 int GetTextEffectFlags() const;
23324ae1
FM
226
227 /**
228 Returns the text effects, a bit list of styles. See SetTextEffects() for
229 details.
230 */
328f5751 231 int GetTextEffects() const;
23324ae1
FM
232
233 /**
234 Returns the URL for the content. Content with wxTEXT_ATTR_URL style
235 causes wxRichTextCtrl to show a hand cursor over it, and wxRichTextCtrl
236 generates
237 a wxTextUrlEvent when the content is clicked.
238 */
328f5751 239 const wxString GetURL() const;
23324ae1
FM
240
241 /**
242 Returns @true if the attribute object specifies alignment.
243 */
328f5751 244 bool HasAlignment() const;
23324ae1
FM
245
246 /**
247 Returns @true if the attribute object specifies a background colour.
248 */
328f5751 249 bool HasBackgroundColour() const;
23324ae1
FM
250
251 /**
252 Returns @true if the attribute object specifies a standard bullet name.
253 */
328f5751 254 bool HasBulletName() const;
23324ae1
FM
255
256 /**
257 Returns @true if the attribute object specifies a bullet number.
258 */
328f5751 259 bool HasBulletNumber() const;
23324ae1
FM
260
261 /**
262 Returns @true if the attribute object specifies a bullet style.
263 */
328f5751 264 bool HasBulletStyle() const;
23324ae1
FM
265
266 /**
267 Returns @true if the attribute object specifies bullet text (usually
268 specifying a symbol).
269 */
328f5751 270 bool HasBulletText() const;
23324ae1
FM
271
272 /**
273 Returns @true if the attribute object specifies a character style name.
274 */
328f5751 275 bool HasCharacterStyleName() const;
23324ae1
FM
276
277 /**
4cc4bfaf 278 Returns @true if the @a flag is present in the attribute object's flag
23324ae1
FM
279 bitlist.
280 */
328f5751 281 bool HasFlag(long flag) const;
23324ae1
FM
282
283 /**
284 Returns @true if the attribute object specifies any font attributes.
285 */
328f5751 286 bool HasFont() const;
23324ae1
FM
287
288 /**
289 Returns @true if the attribute object specifies an encoding.
290 */
328f5751 291 bool HasFontEncoding() const;
23324ae1
FM
292
293 /**
294 Returns @true if the attribute object specifies a font face name.
295 */
328f5751 296 bool HasFontFaceName() const;
23324ae1
FM
297
298 /**
299 Returns @true if the attribute object specifies italic style.
300 */
328f5751 301 bool HasFontItalic() const;
23324ae1
FM
302
303 /**
304 Returns @true if the attribute object specifies a font point size.
305 */
328f5751 306 bool HasFontSize() const;
23324ae1
FM
307
308 /**
309 Returns @true if the attribute object specifies either underlining or no
310 underlining.
311 */
328f5751 312 bool HasFontUnderlined() const;
23324ae1
FM
313
314 /**
315 Returns @true if the attribute object specifies font weight (bold, light or
316 normal).
317 */
328f5751 318 bool HasFontWeight() const;
23324ae1
FM
319
320 /**
321 Returns @true if the attribute object specifies a left indent.
322 */
328f5751 323 bool HasLeftIndent() const;
23324ae1
FM
324
325 /**
326 Returns @true if the attribute object specifies line spacing.
327 */
328f5751 328 bool HasLineSpacing() const;
23324ae1
FM
329
330 /**
331 Returns @true if the attribute object specifies a list style name.
332 */
328f5751 333 bool HasListStyleName() const;
23324ae1
FM
334
335 /**
336 Returns @true if the attribute object specifies an outline level.
337 */
328f5751 338 bool HasOutlineLevel() const;
23324ae1
FM
339
340 /**
341 Returns @true if the attribute object specifies a page break before this
342 paragraph.
343 */
328f5751 344 bool HasPageBreak() const;
23324ae1
FM
345
346 /**
347 Returns @true if the attribute object specifies spacing after a paragraph.
348 */
328f5751 349 bool HasParagraphSpacingAfter() const;
23324ae1
FM
350
351 /**
352 Returns @true if the attribute object specifies spacing before a paragraph.
353 */
328f5751 354 bool HasParagraphSpacingBefore() const;
23324ae1
FM
355
356 /**
357 Returns @true if the attribute object specifies a paragraph style name.
358 */
328f5751 359 bool HasParagraphStyleName() const;
23324ae1
FM
360
361 /**
362 Returns @true if the attribute object specifies a right indent.
363 */
328f5751 364 bool HasRightIndent() const;
23324ae1
FM
365
366 /**
367 Returns @true if the attribute object specifies tab stops.
368 */
328f5751 369 bool HasTabs() const;
23324ae1
FM
370
371 /**
372 Returns @true if the attribute object specifies a text foreground colour.
373 */
328f5751 374 bool HasTextColour() const;
23324ae1
FM
375
376 /**
377 Returns @true if the attribute object specifies text effects.
378 */
328f5751 379 bool HasTextEffects() const;
23324ae1
FM
380
381 /**
382 Returns @true if the attribute object specifies a URL.
383 */
328f5751 384 bool HasURL() const;
23324ae1
FM
385
386 /**
387 Returns @true if the object represents a character style, that is,
388 the flags specify a font or a text background or foreground colour.
389 */
328f5751 390 bool IsCharacterStyle() const;
23324ae1
FM
391
392 /**
393 Returns @false if we have any attributes set, @true otherwise.
394 */
328f5751 395 bool IsDefault() const;
23324ae1
FM
396
397 /**
398 Returns @true if the object represents a paragraph style, that is,
399 the flags specify alignment, indentation, tabs, paragraph spacing, or
400 bullet style.
401 */
328f5751 402 bool IsParagraphStyle() const;
23324ae1
FM
403
404 //@{
405 /**
4cc4bfaf
FM
406 Creates a new @c wxTextAttr which is a merge of @a base and
407 @e overlay. Properties defined in @a overlay take precedence over those
23324ae1
FM
408 in @e base. Properties undefined/invalid in both are undefined in the
409 result.
410 */
411 void Merge(const wxTextAttr& overlay);
7c913512
FM
412 static wxTextAttr Merge(const wxTextAttr& base,
413 const wxTextAttr& overlay);
23324ae1
FM
414 //@}
415
416 /**
417 Sets the paragraph alignment. These are the possible values for @e alignment:
418
23324ae1
FM
419 Of these, wxTEXT_ALIGNMENT_JUSTIFIED is unimplemented. In future justification
420 may be supported
421 when printing or previewing, only.
422 */
423 void SetAlignment(wxTextAttrAlignment alignment);
424
425 /**
426 Sets the background colour.
427 */
428 void SetBackgroundColour(const wxColour& colBack);
429
430 /**
431 Sets the name of the font associated with the bullet symbol.
432 Only valid for attributes with wxTEXT_ATTR_BULLET_SYMBOL.
433 */
434 void SetBulletFont(const wxString& font);
435
436 /**
437 Sets the standard bullet name, applicable if the bullet style is
438 wxTEXT_ATTR_BULLET_STYLE_STANDARD.
439 See GetBulletName() for a list
440 of supported names, and how to expand the range of supported types.
441 */
442 void SetBulletName(const wxString& name);
443
444 /**
445 Sets the bullet number.
446 */
447 void SetBulletNumber(int n);
448
449 /**
450 Sets the bullet style. The following styles can be passed:
451
23324ae1
FM
452 Currently wxTEXT_ATTR_BULLET_STYLE_BITMAP is not supported.
453 */
454 void SetBulletStyle(int style);
455
456 /**
457 Sets the bullet text, which could be a symbol, or (for example) cached outline
458 text.
459 */
460 void SetBulletText(const wxString text);
461
462 /**
463 Sets the character style name.
464 */
465 void SetCharacterStyleName(const wxString& name);
466
467 /**
468 Sets the flags determining which styles are being specified. The following
469 flags can be passed in a bitlist:
470 */
471 void SetFlags(long flags);
472
473 /**
474 Sets the attributes for the given font. Note that wxTextAttr does not store an
475 actual wxFont object.
476 */
477 void SetFont(const wxFont& font);
478
479 /**
480 Sets the font encoding.
481 */
482 void SetFontEncoding(wxFontEncoding encoding);
483
484 /**
485 Sets the paragraph alignment.
486 */
487 void SetFontFaceName(const wxString& faceName);
488
489 /**
490 Sets the font size in points.
491 */
492 void SetFontSize(int pointSize);
493
494 /**
495 Sets the font style (normal, italic or slanted).
496 */
497 void SetFontStyle(int fontStyle);
498
499 /**
500 Sets the font underlining.
501 */
502 void SetFontUnderlined(bool underlined);
503
504 /**
505 Sets the font weight.
506 */
507 void SetFontWeight(int fontWeight);
508
509 /**
510 Sets the left indent and left subindent in tenths of a millimetre.
23324ae1
FM
511 The sub-indent is an offset from the left of the paragraph, and is used for all
512 but the
513 first line in a paragraph. A positive value will cause the first line to appear
514 to the left
515 of the subsequent lines, and a negative value will cause the first line to be
516 indented
517 relative to the subsequent lines.
23324ae1
FM
518 wxRichTextBuffer uses indentation to render a bulleted item. The left indent is
519 the distance between
520 the margin and the bullet. The content of the paragraph, including the first
521 line, starts
522 at leftMargin + leftSubIndent. So the distance between the left edge of the
523 bullet and the
524 left of the actual paragraph is leftSubIndent.
525 */
526 void SetLeftIndent(int indent, int subIndent = 0);
527
528 /**
4cc4bfaf 529 Sets the line spacing. @a spacing is a multiple, where 10 means single-spacing,
23324ae1
FM
530 15 means 1.5 spacing, and 20 means double spacing. The following constants are
531 defined for convenience:
532 */
533 void SetLineSpacing(int spacing);
534
535 /**
536 Sets the list style name.
537 */
538 void SetListStyleName(const wxString& name);
539
540 /**
541 Specifies the outline level. Zero represents normal text. At present, the
542 outline level is
543 not used, but may be used in future for determining list levels and for
544 applications
545 that need to store document structure information.
546 */
547 void SetOutlineLevel(int level);
548
549 /**
550 Specifies a page break before this paragraph.
551 */
4cc4bfaf 552 void SetPageBreak(bool pageBreak = true);
23324ae1
FM
553
554 /**
555 Sets the spacing after a paragraph, in tenths of a millimetre.
556 */
557 void SetParagraphSpacingAfter(int spacing);
558
559 /**
560 Sets the spacing before a paragraph, in tenths of a millimetre.
561 */
562 void SetParagraphSpacingBefore(int spacing);
563
564 /**
565 Sets the name of the paragraph style.
566 */
567 void SetParagraphStyleName(const wxString& name);
568
569 /**
570 Sets the right indent in tenths of a millimetre.
571 */
572 void SetRightIndent(int indent);
573
574 /**
575 Sets the tab stops, expressed in tenths of a millimetre.
576 Each stop is measured from the left margin and therefore each value must be
577 larger than the last.
578 */
579 void SetTabs(const wxArrayInt& tabs);
580
581 /**
582 Sets the text foreground colout.
583 */
584 void SetTextColour(const wxColour& colText);
585
586 /**
587 Sets the text effect bits of interest. You should also pass wxTEXT_ATTR_EFFECTS
588 to SetFlags().
589 See SetFlags() for further information.
590 */
591 void SetTextEffectFlags(int flags);
592
593 /**
594 Sets the text effects, a bit list of styles.
23324ae1
FM
595 The following styles can be passed:
596
23324ae1
FM
597 Of these, only wxTEXT_ATTR_EFFECT_CAPITALS and wxTEXT_ATTR_EFFECT_STRIKETHROUGH
598 are implemented.
599 wxTEXT_ATTR_EFFECT_CAPITALS capitalises text when displayed (leaving the case
600 of the actual buffer
601 text unchanged), and wxTEXT_ATTR_EFFECT_STRIKETHROUGH draws a line through text.
23324ae1
FM
602 To set effects, you should also pass wxTEXT_ATTR_EFFECTS to SetFlags(), and call
603 SetTextEffectFlags() with the styles (taken from the
604 above set) that you are interested in setting.
605 */
606 void SetTextEffects(int effects);
607
608 /**
609 Sets the URL for the content. Sets the wxTEXT_ATTR_URL style; content with this
610 style
611 causes wxRichTextCtrl to show a hand cursor over it, and wxRichTextCtrl
612 generates
613 a wxTextUrlEvent when the content is clicked.
614 */
4cc4bfaf 615 void SetURL(const wxString& url);
23324ae1
FM
616
617 /**
618 Assignment from a wxTextAttr object.
619 */
620 void operator operator=(const wxTextAttr& attr);
621};
622
623
e54c96f1 624
23324ae1
FM
625/**
626 @class wxTextCtrl
627 @wxheader{textctrl.h}
7c913512 628
23324ae1
FM
629 A text control allows text to be displayed and edited. It may be
630 single line or multi-line.
7c913512 631
23324ae1
FM
632 @beginStyleTable
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.
648 @style{wxTE_RICH}:
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.
652 @style{wxTE_RICH2}:
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.
663 @style{wxHSCROLL}:
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.
671 @style{wxTE_LEFT}:
672 The text in the control will be left-justified (default).
673 @style{wxTE_CENTRE}:
674 The text in the control will be centered (currently wxMSW and
675 wxGTK2 only).
676 @style{wxTE_RIGHT}:
677 The text in the control will be right-justified (currently wxMSW
678 and wxGTK2 only).
679 @style{wxTE_DONTWRAP}:
680 Same as wxHSCROLL style: don't wrap at all, show horizontal
681 scrollbar instead.
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
693 capitalized.
694 @endStyleTable
7c913512 695
23324ae1
FM
696 @library{wxcore}
697 @category{ctrl}
698 @appearance{textctrl.png}
7c913512 699
e54c96f1 700 @see wxTextCtrl::Create, wxValidator
23324ae1
FM
701*/
702class wxTextCtrl : public wxControl
703{
704public:
705 //@{
706 /**
707 Constructor, creating and showing a text control.
708
7c913512 709 @param parent
4cc4bfaf 710 Parent window. Should not be @NULL.
7c913512 711 @param id
4cc4bfaf 712 Control identifier. A value of -1 denotes a default value.
7c913512 713 @param value
4cc4bfaf 714 Default text value.
7c913512 715 @param pos
4cc4bfaf 716 Text control position.
7c913512 717 @param size
4cc4bfaf 718 Text control size.
7c913512 719 @param style
4cc4bfaf 720 Window style. See wxTextCtrl.
7c913512 721 @param validator
4cc4bfaf 722 Window validator.
7c913512 723 @param name
4cc4bfaf 724 Window name.
23324ae1
FM
725
726 @remarks The horizontal scrollbar (wxHSCROLL style flag) will only be
4cc4bfaf
FM
727 created for multi-line text controls. Without a
728 horizontal scrollbar, text lines that don't fit in the
729 control's size will be wrapped (but no newline
730 character is inserted). Single line controls don't have
731 a horizontal scrollbar, the text is automatically
732 scrolled so that the insertion point is always visible.
23324ae1 733
4cc4bfaf 734 @see Create(), wxValidator
23324ae1
FM
735 */
736 wxTextCtrl();
7c913512
FM
737 wxTextCtrl(wxWindow* parent, wxWindowID id,
738 const wxString& value = "",
739 const wxPoint& pos = wxDefaultPosition,
740 const wxSize& size = wxDefaultSize,
741 long style = 0,
742 const wxValidator& validator = wxDefaultValidator,
743 const wxString& name = wxTextCtrlNameStr);
23324ae1
FM
744 //@}
745
746 /**
747 Destructor, destroying the text control.
748 */
749 ~wxTextCtrl();
750
751 /**
752 Appends the text to the end of the text control.
753
7c913512 754 @param text
4cc4bfaf 755 Text to write to the text control.
23324ae1
FM
756
757 @remarks After the text is appended, the insertion point will be at the
4cc4bfaf
FM
758 end of the text control. If this behaviour is not
759 desired, the programmer should use GetInsertionPoint
760 and SetInsertionPoint.
23324ae1 761
4cc4bfaf 762 @see WriteText()
23324ae1
FM
763 */
764 void AppendText(const wxString& text);
765
766 /**
767 Call this function to enable auto-completion of the text typed in a single-line
768 text control using the given @e choices.
23324ae1
FM
769 Notice that currently this function is only implemented in wxGTK2 and wxMSW
770 ports and does nothing under the other platforms.
e54c96f1
FM
771
772 @wxsince{2.9.0}
23324ae1
FM
773
774 @returns @true if the auto-completion was enabled or @false if the
4cc4bfaf
FM
775 operation failed, typically because auto-completion is
776 not supported by the current platform.
23324ae1 777
4cc4bfaf 778 @see AutoCompleteFileNames()
23324ae1
FM
779 */
780 bool AutoComplete(const wxArrayString& choices);
781
782 /**
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.
23324ae1
FM
785 Notice that currently this function is only implemented in wxGTK2 port and does
786 nothing under the other platforms.
e54c96f1
FM
787
788 @wxsince{2.9.0}
23324ae1
FM
789
790 @returns @true if the auto-completion was enabled or @false if the
4cc4bfaf
FM
791 operation failed, typically because auto-completion is
792 not supported by the current platform.
23324ae1 793
4cc4bfaf 794 @see AutoComplete()
23324ae1
FM
795 */
796 bool AutoCompleteFileNames();
797
798 /**
799 Returns @true if the selection can be copied to the clipboard.
800 */
801 virtual bool CanCopy();
802
803 /**
804 Returns @true if the selection can be cut to the clipboard.
805 */
806 virtual bool CanCut();
807
808 /**
809 Returns @true if the contents of the clipboard can be pasted into the
810 text control. On some platforms (Motif, GTK) this is an approximation
811 and returns @true if the control is editable, @false otherwise.
812 */
813 virtual bool CanPaste();
814
815 /**
816 Returns @true if there is a redo facility available and the last operation
817 can be redone.
818 */
819 virtual bool CanRedo();
820
821 /**
822 Returns @true if there is an undo facility available and the last operation
823 can be undone.
824 */
825 virtual bool CanUndo();
826
827 /**
828 Sets the text value and marks the control as not-modified (which means that
829 IsModified() would return @false immediately
830 after the call to SetValue).
7c913512 831 Note that this function will not generate the @c wxEVT_COMMAND_TEXT_UPDATED
23324ae1
FM
832 event.
833 This is the only difference with SetValue().
834 See @ref overview_progevent "this topic" for more information.
e54c96f1
FM
835
836 @wxsince{2.7.1}
23324ae1 837
7c913512 838 @param value
4cc4bfaf
FM
839 The new value to set. It may contain newline characters if the text control
840 is multi-line.
23324ae1
FM
841 */
842 virtual void ChangeValue(const wxString& value);
843
844 /**
845 Clears the text in the control.
23324ae1
FM
846 Note that this function will generate a @c wxEVT_COMMAND_TEXT_UPDATED
847 event.
848 */
849 virtual void Clear();
850
851 /**
852 Copies the selected text to the clipboard under Motif and MS Windows.
853 */
854 virtual void Copy();
855
856 /**
857 Creates the text control for two-step construction. Derived classes
858 should call or replace this function. See wxTextCtrl()
859 for further details.
860 */
861 bool Create(wxWindow* parent, wxWindowID id,
862 const wxString& value = "",
863 const wxPoint& pos = wxDefaultPosition,
864 const wxSize& size = wxDefaultSize,
865 long style = 0,
866 const wxValidator& validator = wxDefaultValidator,
867 const wxString& name = wxTextCtrlNameStr);
868
869 /**
870 Copies the selected text to the clipboard and removes the selection.
871 */
4cc4bfaf 872 virtual void Cut();
23324ae1
FM
873
874 /**
875 Resets the internal 'modified' flag as if the current edits had been saved.
876 */
877 void DiscardEdits();
878
879 /**
880 This functions inserts into the control the character which would have been
881 inserted if the given key event had occurred in the text control. The
4cc4bfaf 882 @a event object should be the same as the one passed to @c EVT_KEY_DOWN
23324ae1 883 handler previously by wxWidgets.
23324ae1
FM
884 Please note that this function doesn't currently work correctly for all keys
885 under any platform but MSW.
886
887 @returns @true if the event resulted in a change to the control, @false
4cc4bfaf 888 otherwise.
23324ae1
FM
889 */
890 bool EmulateKeyPress(const wxKeyEvent& event);
891
892 /**
893 Returns the style currently used for the new text.
894
4cc4bfaf 895 @see SetDefaultStyle()
23324ae1 896 */
328f5751 897 const wxTextAttr GetDefaultStyle() const;
23324ae1
FM
898
899 /**
900 Returns the insertion point. This is defined as the zero based index of the
901 character position to the right of the insertion point. For example, if
902 the insertion point is at the end of the text control, it is equal to
903 both GetValue().Length() and
904 GetLastPosition().
23324ae1
FM
905 The following code snippet safely returns the character at the insertion
906 point or the zero character if the point is at the end of the control.
907 */
328f5751 908 virtual long GetInsertionPoint() const;
23324ae1
FM
909
910 /**
911 Returns the zero based index of the last position in the text control,
912 which is equal to the number of characters in the control.
913 */
328f5751 914 virtual wxTextPos GetLastPosition() const;
23324ae1
FM
915
916 /**
917 Gets the length of the specified line, not including any trailing newline
918 character(s).
919
7c913512 920 @param lineNo
4cc4bfaf 921 Line number (starting from zero).
23324ae1
FM
922
923 @returns The length of the line, or -1 if lineNo was invalid.
924 */
328f5751 925 int GetLineLength(long lineNo) const;
23324ae1
FM
926
927 /**
928 Returns the contents of a given line in the text control, not including
929 any trailing newline character(s).
930
7c913512 931 @param lineNo
4cc4bfaf 932 The line number, starting from zero.
23324ae1
FM
933
934 @returns The contents of the line.
935 */
328f5751 936 wxString GetLineText(long lineNo) const;
23324ae1
FM
937
938 /**
939 Returns the number of lines in the text control buffer.
940
941 @remarks Note that even empty text controls have one line (where the
4cc4bfaf
FM
942 insertion point is), so GetNumberOfLines() never
943 returns 0.
23324ae1 944 */
328f5751 945 int GetNumberOfLines() const;
23324ae1
FM
946
947 /**
4cc4bfaf
FM
948 Returns the string containing the text starting in the positions @a from and
949 up to @a to in the control. The positions must have been returned by another
23324ae1 950 wxTextCtrl method.
23324ae1
FM
951 Please note that the positions in a multiline wxTextCtrl do @b not
952 correspond to the indices in the string returned by
953 GetValue() because of the different new line
954 representations (@c CR or @c CR LF) and so this method should be used to
955 obtain the correct results instead of extracting parts of the entire value. It
956 may also be more efficient, especially if the control contains a lot of data.
957 */
328f5751 958 virtual wxString GetRange(long from, long to) const;
23324ae1
FM
959
960 /**
961 Gets the current selection span. If the returned values are equal, there was
962 no selection.
23324ae1
FM
963 Please note that the indices returned may be used with the other wxTextctrl
964 methods but don't necessarily represent the correct indices into the string
965 returned by GetValue() for multiline controls
966 under Windows (at least,) you should use
967 GetStringSelection() to get the selected
968 text.
969
7c913512 970 @param from
4cc4bfaf 971 The returned first position.
7c913512 972 @param to
4cc4bfaf 973 The returned last position.
23324ae1 974 */
328f5751 975 virtual void GetSelection(long* from, long* to) const;
23324ae1
FM
976
977 /**
978 Gets the text currently selected in the control. If there is no selection, the
979 returned string is empty.
980 */
981 virtual wxString GetStringSelection();
982
983 /**
984 Returns the style at this position in the text control. Not all platforms
985 support this function.
986
987 @returns @true on success, @false if an error occurred - it may also mean
4cc4bfaf 988 that the styles are not supported under this platform.
23324ae1 989
4cc4bfaf 990 @see SetStyle(), wxTextAttr
23324ae1
FM
991 */
992 bool GetStyle(long position, wxTextAttr& style);
993
994 /**
995 Gets the contents of the control. Notice that for a multiline text control,
996 the lines will be separated by (Unix-style) \n characters, even
997 under Windows where they are separated by a \r\n
998 sequence in the native control.
999 */
328f5751 1000 wxString GetValue() const;
23324ae1
FM
1001
1002 /**
1003 This function finds the character at the specified position expressed in
1004 pixels. If the return code is not @c wxTE_HT_UNKNOWN the row and column
4cc4bfaf
FM
1005 of the character closest to this position are returned in the @a col and
1006 @a row parameters (unless the pointers are @NULL which is allowed).
23324ae1
FM
1007 Please note that this function is currently only implemented in wxUniv,
1008 wxMSW and wxGTK2 ports.
1009
4cc4bfaf 1010 @see PositionToXY(), XYToPosition()
23324ae1
FM
1011 */
1012 wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
1013 wxTextCoord col,
328f5751 1014 wxTextCoord row) const;
23324ae1
FM
1015
1016 /**
1017 Returns @true if the controls contents may be edited by user (note that it
1018 always can be changed by the program), i.e. if the control hasn't been put in
1019 read-only mode by a previous call to
1020 SetEditable().
1021 */
328f5751 1022 bool IsEditable() const;
23324ae1
FM
1023
1024 /**
7c913512 1025 Returns @true if the control is currently empty. This is the same as
23324ae1
FM
1026 @c GetValue().empty() but can be much more efficient for the multiline
1027 controls containing big amounts of text.
e54c96f1
FM
1028
1029 @wxsince{2.7.1}
23324ae1 1030 */
328f5751 1031 bool IsEmpty() const;
23324ae1
FM
1032
1033 /**
1034 Returns @true if the text has been modified by user. Note that calling
1035 SetValue() doesn't make the control modified.
1036
4cc4bfaf 1037 @see MarkDirty()
23324ae1 1038 */
328f5751 1039 bool IsModified() const;
23324ae1
FM
1040
1041 /**
1042 Returns @true if this is a multi line edit control and @false
1043 otherwise.
1044
4cc4bfaf 1045 @see IsSingleLine()
23324ae1 1046 */
328f5751 1047 bool IsMultiLine() const;
23324ae1
FM
1048
1049 /**
1050 Returns @true if this is a single line edit control and @false
1051 otherwise.
1052
4cc4bfaf 1053 @see @ref issingleline() IsMultiLine
23324ae1 1054 */
328f5751 1055 bool IsSingleLine() const;
23324ae1
FM
1056
1057 /**
1058 Loads and displays the named file, if it exists.
1059
7c913512 1060 @param filename
4cc4bfaf 1061 The filename of the file to load.
7c913512 1062 @param fileType
4cc4bfaf 1063 The type of file to load. This is currently ignored in wxTextCtrl.
23324ae1
FM
1064
1065 @returns @true if successful, @false otherwise.
1066 */
1067 bool LoadFile(const wxString& filename,
1068 int fileType = wxTEXT_TYPE_ANY);
1069
1070 /**
1071 Mark text as modified (dirty).
1072
4cc4bfaf 1073 @see IsModified()
23324ae1
FM
1074 */
1075 void MarkDirty();
1076
1077 /**
1078 This event handler function implements default drag and drop behaviour, which
1079 is to load the first dropped file into the control.
1080
7c913512 1081 @param event
4cc4bfaf 1082 The drop files event.
23324ae1
FM
1083
1084 @remarks This is not implemented on non-Windows platforms.
1085
4cc4bfaf 1086 @see wxDropFilesEvent
23324ae1
FM
1087 */
1088 void OnDropFiles(wxDropFilesEvent& event);
1089
1090 /**
1091 Pastes text from the clipboard to the text item.
1092 */
1093 virtual void Paste();
1094
1095 /**
1096 Converts given position to a zero-based column, line number pair.
1097
7c913512 1098 @param pos
4cc4bfaf 1099 Position.
7c913512 1100 @param x
4cc4bfaf 1101 Receives zero based column number.
7c913512 1102 @param y
4cc4bfaf 1103 Receives zero based line number.
23324ae1
FM
1104
1105 @returns @true on success, @false on failure (most likely due to a too
4cc4bfaf 1106 large position parameter).
23324ae1 1107
4cc4bfaf 1108 @see XYToPosition()
23324ae1 1109 */
328f5751 1110 bool PositionToXY(long pos, long* x, long* y) const;
23324ae1
FM
1111
1112 /**
1113 If there is a redo facility and the last operation can be redone, redoes the
1114 last operation. Does nothing
1115 if there is no redo facility.
1116 */
1117 virtual void Redo();
1118
1119 /**
1120 Removes the text starting at the first given position up to (but not including)
1121 the character at the last position.
1122
7c913512 1123 @param from
4cc4bfaf 1124 The first position.
7c913512 1125 @param to
4cc4bfaf 1126 The last position.
23324ae1
FM
1127 */
1128 virtual void Remove(long from, long to);
1129
1130 /**
1131 Replaces the text starting at the first position up to (but not including)
1132 the character at the last position with the given text.
1133
7c913512 1134 @param from
4cc4bfaf 1135 The first position.
7c913512 1136 @param to
4cc4bfaf 1137 The last position.
7c913512 1138 @param value
4cc4bfaf 1139 The value to replace the existing text with.
23324ae1
FM
1140 */
1141 virtual void Replace(long from, long to, const wxString& value);
1142
1143 /**
1144 Saves the contents of the control in a text file.
1145
7c913512 1146 @param filename
4cc4bfaf 1147 The name of the file in which to save the text.
7c913512 1148 @param fileType
4cc4bfaf 1149 The type of file to save. This is currently ignored in wxTextCtrl.
23324ae1
FM
1150
1151 @returns @true if the operation was successful, @false otherwise.
1152 */
1153 bool SaveFile(const wxString& filename,
1154 int fileType = wxTEXT_TYPE_ANY);
1155
1156 /**
1157 Changes the default style to use for the new text which is going to be added
1158 to the control using WriteText() or
1159 AppendText().
23324ae1
FM
1160 If either of the font, foreground, or background colour is not set in
1161 @e style, the values of the previous default style are used for them. If
1162 the previous default style didn't set them neither, the global font or colours
1163 of the text control itself are used as fall back.
4cc4bfaf 1164 However if the @a style parameter is the default wxTextAttr, then the
23324ae1
FM
1165 default style is just reset (instead of being combined with the new style which
1166 wouldn't change it at all).
1167
7c913512 1168 @param style
4cc4bfaf 1169 The style for the new text.
23324ae1
FM
1170
1171 @returns @true on success, @false if an error occurred - may also mean that
4cc4bfaf 1172 the styles are not supported under this platform.
23324ae1 1173
4cc4bfaf 1174 @see GetDefaultStyle()
23324ae1
FM
1175 */
1176 bool SetDefaultStyle(const wxTextAttr& style);
1177
1178 /**
1179 Makes the text item editable or read-only, overriding the @b wxTE_READONLY flag.
1180
7c913512 1181 @param editable
4cc4bfaf 1182 If @true, the control is editable. If @false, the control is read-only.
23324ae1 1183
4cc4bfaf 1184 @see IsEditable()
23324ae1
FM
1185 */
1186 virtual void SetEditable(const bool editable);
1187
1188 /**
1189 Sets the insertion point at the given position.
1190
7c913512 1191 @param pos
4cc4bfaf 1192 Position to set.
23324ae1
FM
1193 */
1194 virtual void SetInsertionPoint(long pos);
1195
1196 /**
1197 Sets the insertion point at the end of the text control. This is equivalent
1198 to wxTextCtrl::SetInsertionPoint(wxTextCtrl::GetLastPosition()).
1199 */
1200 virtual void SetInsertionPointEnd();
1201
1202 /**
1203 This function sets the maximum number of characters the user can enter into the
1204 control. In other words, it allows to limit the text value length to @e len
1205 not counting the terminating @c NUL character.
4cc4bfaf 1206 If @a len is 0, the previously set max length limit, if any, is discarded
23324ae1
FM
1207 and the user may enter as much text as the underlying native text control
1208 widget supports (typically at least 32Kb).
23324ae1
FM
1209 If the user tries to enter more characters into the text control when it
1210 already is filled up to the maximal length, a
1211 @c wxEVT_COMMAND_TEXT_MAXLEN event is sent to notify the program about it
1212 (giving it the possibility to show an explanatory message, for example) and the
1213 extra input is discarded.
23324ae1
FM
1214 Note that under GTK+, this function may only be used with single line text
1215 controls.
1216 */
1217 virtual void SetMaxLength(unsigned long len);
1218
1219 /**
1220 Marks the control as being modified by the user or not.
1221
4cc4bfaf 1222 @see MarkDirty(), DiscardEdits()
23324ae1
FM
1223 */
1224 void SetModified(bool modified);
1225
1226 /**
1227 Selects the text starting at the first position up to (but not including) the
1228 character at the last position. If both parameters are equal to -1 all text
1229 in the control is selected.
1230
7c913512 1231 @param from
4cc4bfaf 1232 The first position.
7c913512 1233 @param to
4cc4bfaf 1234 The last position.
23324ae1
FM
1235 */
1236 virtual void SetSelection(long from, long to);
1237
1238 /**
4cc4bfaf 1239 Changes the style of the given range. If any attribute within @a style is
23324ae1
FM
1240 not set, the corresponding attribute from GetDefaultStyle() is used.
1241
7c913512 1242 @param start
4cc4bfaf 1243 The start of the range to change.
7c913512 1244 @param end
4cc4bfaf 1245 The end of the range to change.
7c913512 1246 @param style
4cc4bfaf 1247 The new style for the range.
23324ae1
FM
1248
1249 @returns @true on success, @false if an error occurred - it may also mean
4cc4bfaf 1250 that the styles are not supported under this platform.
23324ae1 1251
4cc4bfaf 1252 @see GetStyle(), wxTextAttr
23324ae1
FM
1253 */
1254 bool SetStyle(long start, long end, const wxTextAttr& style);
1255
1256 /**
1257 Sets the text value and marks the control as not-modified (which means that
1258 IsModified() would return @false immediately
1259 after the call to SetValue).
23324ae1
FM
1260 Note that this function will generate a @c wxEVT_COMMAND_TEXT_UPDATED
1261 event.
23324ae1
FM
1262 This function is deprecated and should not be used in new code. Please use the
1263 ChangeValue() function instead.
1264
7c913512 1265 @param value
4cc4bfaf
FM
1266 The new value to set. It may contain newline characters if the text control
1267 is multi-line.
23324ae1
FM
1268 */
1269 virtual void SetValue(const wxString& value);
1270
1271 /**
1272 Makes the line containing the given position visible.
1273
7c913512 1274 @param pos
4cc4bfaf 1275 The position that should be visible.
23324ae1
FM
1276 */
1277 void ShowPosition(long pos);
1278
1279 /**
1280 If there is an undo facility and the last operation can be undone, undoes the
1281 last operation. Does nothing
1282 if there is no undo facility.
1283 */
1284 virtual void Undo();
1285
1286 /**
1287 Writes the text into the text control at the current insertion position.
1288
7c913512 1289 @param text
4cc4bfaf 1290 Text to write to the text control.
23324ae1
FM
1291
1292 @remarks Newlines in the text string are the only control characters
4cc4bfaf
FM
1293 allowed, and they will cause appropriate line breaks.
1294 See () and AppendText() for more
1295 convenient ways of writing to the window.
23324ae1
FM
1296 */
1297 void WriteText(const wxString& text);
1298
1299 /**
1300 Converts the given zero based column and line number to a position.
1301
7c913512 1302 @param x
4cc4bfaf 1303 The column number.
7c913512 1304 @param y
4cc4bfaf 1305 The line number.
23324ae1
FM
1306
1307 @returns The position value, or -1 if x or y was invalid.
1308 */
1309 long XYToPosition(long x, long y);
1310
1311 //@{
1312 /**
1313 Operator definitions for appending to a text control, for example:
1314 */
1315 wxTextCtrl operator(const wxString& s);
7c913512
FM
1316 wxTextCtrl operator(int i);
1317 wxTextCtrl operator(long i);
1318 wxTextCtrl operator(float f);
1319 wxTextCtrl operator(double d);
1320 wxTextCtrl operator(char c);
23324ae1
FM
1321 //@}
1322};
1323
1324
e54c96f1 1325
23324ae1
FM
1326/**
1327 @class wxStreamToTextRedirector
1328 @wxheader{textctrl.h}
7c913512 1329
23324ae1
FM
1330 This class can be used to (temporarily) redirect all output sent to a C++
1331 ostream object to a wxTextCtrl instead.
7c913512 1332
23324ae1
FM
1333 @b NB: Some compilers and/or build configurations don't support multiply
1334 inheriting wxTextCtrl from @c std::streambuf in which
7c913512 1335 case this class is not compiled in. You also must have @c wxUSE_STD_IOSTREAM
23324ae1
FM
1336 option on (i.e. set to 1) in your setup.h to be able to use it. Under Unix,
1337 specify @c --enable-std_iostreams switch when running configure for this.
7c913512 1338
23324ae1 1339 Example of usage:
7c913512 1340
23324ae1
FM
1341 @code
1342 using namespace std;
7c913512 1343
23324ae1 1344 wxTextCtrl *text = new wxTextCtrl(...);
7c913512 1345
23324ae1
FM
1346 {
1347 wxStreamToTextRedirector redirect(text);
7c913512 1348
23324ae1
FM
1349 // this goes to the text control
1350 cout "Hello, text!" endl;
1351 }
7c913512 1352
23324ae1
FM
1353 // this goes somewhere else, presumably to stdout
1354 cout "Hello, console!" endl;
1355 @endcode
7c913512
FM
1356
1357
23324ae1
FM
1358 @library{wxcore}
1359 @category{logging}
7c913512 1360
e54c96f1 1361 @see wxTextCtrl
23324ae1 1362*/
7c913512 1363class wxStreamToTextRedirector
23324ae1
FM
1364{
1365public:
1366 /**
4cc4bfaf 1367 The constructor starts redirecting output sent to @a ostr or @e cout for
23324ae1
FM
1368 the default parameter value to the text control @e text.
1369
7c913512 1370 @param text
4cc4bfaf 1371 The text control to append output too, must be non-@NULL
7c913512 1372 @param ostr
4cc4bfaf 1373 The C++ stream to redirect, cout is used if it is @NULL
23324ae1 1374 */
4cc4bfaf 1375 wxStreamToTextRedirector(wxTextCtrl text, ostream* ostr = NULL);
23324ae1
FM
1376
1377 /**
1378 When a wxStreamToTextRedirector object is destroyed, the redirection is ended
1379 and any output sent to the C++ ostream which had been specified at the time of
1380 the object construction will go to its original destination.
1381 */
1382 ~wxStreamToTextRedirector();
1383};
e54c96f1 1384