]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/richtext/richtextctrl.h
bb54cd707282d8085556e00131029de4a1480c07
[wxWidgets.git] / interface / wx / richtext / richtextctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextctrl.h
3 // Purpose: interface of wxRichTextCtrl and wxRichTextEvent
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxRichTextEvent
11
12 This is the event class for wxRichTextCtrl notifications.
13
14 @beginEventTable{wxRichTextEvent}
15 @event{EVT_RICHTEXT_CHARACTER(id, func)}
16 Process a wxEVT_COMMAND_RICHTEXT_CHARACTER event, generated when the user
17 presses a character key. Valid event functions: GetFlags, GetPosition, GetCharacter.
18 @event{EVT_RICHTEXT_DELETE(id, func)}
19 Process a wxEVT_COMMAND_RICHTEXT_DELETE event, generated when the user
20 presses the backspace or delete key. Valid event functions: GetFlags, GetPosition.
21 @event{EVT_RICHTEXT_RETURN(id, func)}
22 Process a wxEVT_COMMAND_RICHTEXT_RETURN event, generated when the user
23 presses the return key. Valid event functions: GetFlags, GetPosition.
24 @event{EVT_RICHTEXT_STYLE_CHANGED(id, func)}
25 Process a wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED event, generated when
26 styling has been applied to the control. Valid event functions: GetPosition, GetRange.
27 @event{EVT_RICHTEXT_STYLESHEET_CHANGED(id, func)}
28 Process a wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING event, generated
29 when the control's stylesheet has changed, for example the user added,
30 edited or deleted a style. Valid event functions: GetRange, GetPosition.
31 @event{EVT_RICHTEXT_STYLESHEET_REPLACING(id, func)}
32 Process a wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING event, generated
33 when the control's stylesheet is about to be replaced, for example when
34 a file is loaded into the control.
35 Valid event functions: Veto, GetOldStyleSheet, GetNewStyleSheet.
36 @event{EVT_RICHTEXT_STYLESHEET_REPLACED(id, func)}
37 Process a wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED event, generated
38 when the control's stylesheet has been replaced, for example when a file
39 is loaded into the control.
40 Valid event functions: GetOldStyleSheet, GetNewStyleSheet.
41 @event{EVT_RICHTEXT_CONTENT_INSERTED(id, func)}
42 Process a wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED event, generated when
43 content has been inserted into the control.
44 Valid event functions: GetPosition, GetRange.
45 @event{EVT_RICHTEXT_CONTENT_DELETED(id, func)}
46 Process a wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED event, generated when
47 content has been deleted from the control.
48 Valid event functions: GetPosition, GetRange.
49 @event{EVT_RICHTEXT_BUFFER_RESET(id, func)}
50 Process a wxEVT_COMMAND_RICHTEXT_BUFFER_RESET event, generated when the
51 buffer has been reset by deleting all content.
52 You can use this to set a default style for the first new paragraph.
53 @endEventTable
54
55 @library{wxrichtext}
56 @category{events,richtext}
57 */
58 class wxRichTextEvent : public wxNotifyEvent
59 {
60 public:
61 /**
62 Copy constructor.
63 */
64 wxRichTextEvent(const wxRichTextEvent& event);
65
66 /**
67 Constructor.
68
69 @param commandType
70 The type of the event.
71 @param id
72 Window identifier. The value @c wxID_ANY indicates a default value.
73 */
74 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
75
76 /**
77 Returns the character pressed, within a wxEVT_COMMAND_RICHTEXT_CHARACTER event.
78 */
79 wxChar GetCharacter() const;
80
81 /**
82 Returns flags indicating modifier keys pressed.
83
84 Possible values are wxRICHTEXT_CTRL_DOWN, wxRICHTEXT_SHIFT_DOWN, and wxRICHTEXT_ALT_DOWN.
85 */
86 int GetFlags() const;
87
88 /**
89 Returns the new style sheet.
90
91 Can be used in a wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
92 wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
93 */
94 wxRichTextStyleSheet* GetNewStyleSheet() const;
95
96 /**
97 Returns the old style sheet.
98
99 Can be used in a wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
100 wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
101 */
102 wxRichTextStyleSheet* GetOldStyleSheet() const;
103
104 /**
105 Returns the buffer position at which the event occured.
106 */
107 long GetPosition() const;
108
109 /**
110 Gets the range for the current operation.
111 */
112 const wxRichTextRange& GetRange() const;
113
114 /**
115 Sets the character variable.
116 */
117 void SetCharacter(wxChar ch);
118
119 /**
120 Sets flags indicating modifier keys pressed.
121
122 Possible values are wxRICHTEXT_CTRL_DOWN, wxRICHTEXT_SHIFT_DOWN, and wxRICHTEXT_ALT_DOWN.
123 */
124 void SetFlags(int flags);
125
126 /**
127 Sets the new style sheet variable.
128 */
129 void SetNewStyleSheet(wxRichTextStyleSheet* sheet);
130
131 /**
132 Sets the old style sheet variable.
133 */
134 void SetOldStyleSheet(wxRichTextStyleSheet* sheet);
135
136 /**
137 Sets the buffer position variable.
138 */
139 void SetPosition(long pos);
140
141 /**
142 Sets the range variable.
143 */
144 void SetRange(const wxRichTextRange& range);
145 };
146
147
148
149 /**
150 @class wxRichTextCtrl
151
152 wxRichTextCtrl provides a generic, ground-up implementation of a text control
153 capable of showing multiple styles and images.
154
155 wxRichTextCtrl sends notification events: see wxRichTextEvent.
156
157 It also sends the standard wxTextCtrl events wxEVT_COMMAND_TEXT_ENTER and
158 wxEVT_COMMAND_TEXT_UPDATED, and wxTextUrlEvent when URL content is clicked.
159
160 For more information, see the @ref overview_richtextctrl.
161
162 @beginStyleTable
163 @style{wxRE_CENTRE_CARET}
164 The control will try to keep the caret line centred vertically while editing.
165 wxRE_CENTER_CARET is a synonym for this style.
166 @style{wxRE_MULTILINE}
167 The control will be multiline (mandatory).
168 @style{wxRE_READONLY}
169 The control will not be editable.
170 @endStyleTable
171
172 @library{wxrichtext}
173 @category{richtext}
174 @appearance{richtextctrl.png}
175 */
176 class wxRichTextCtrl
177 {
178 public:
179 /**
180 Default Constructor.
181 */
182 wxRichTextCtrl();
183
184 /**
185 Constructor, creating and showing a rich text control.
186
187 @param parent
188 Parent window. Must not be @NULL.
189 @param id
190 Window identifier. The value @c wxID_ANY indicates a default value.
191 @param value
192 Default string.
193 @param pos
194 Window position.
195 @param size
196 Window size.
197 @param style
198 Window style.
199 @param validator
200 Window validator.
201 @param name
202 Window name.
203
204 @see Create(), wxValidator
205 */
206 wxRichTextCtrl(wxWindow* parent, wxWindowID id = wxID_ANY,
207 const wxString& value = wxEmptyString,
208 const wxPoint& pos = wxDefaultPosition,
209 const wxSize& size = wxDefaultSize,
210 long style = wxRE_MULTILINE,
211 const wxValidator& validator = wxDefaultValidator,
212 const wxString& name = wxTextCtrlNameStr);
213
214 /**
215 Destructor.
216 */
217 virtual ~wxRichTextCtrl();
218
219 /**
220 Adds an image to the control's buffer.
221 */
222 virtual wxRichTextRange AddImage(const wxImage& image);
223
224 /**
225 Adds a new paragraph of text to the end of the buffer.
226 */
227 virtual wxRichTextRange AddParagraph(const wxString& text);
228
229 /**
230 Sets the insertion point to the end of the buffer and writes the text.
231 */
232 virtual void AppendText(const wxString& text);
233
234 /**
235 Applies the given alignment to the selection (undoable).
236 For alignment values, see wxTextAttr.
237 */
238 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment);
239
240 /**
241 Apples bold to the selection (undoable).
242 */
243 virtual bool ApplyBoldToSelection();
244
245 /**
246 Applies italic to the selection (undoable).
247 */
248 virtual bool ApplyItalicToSelection();
249
250 /**
251 Applies the given style to the selection.
252 */
253 virtual bool ApplyStyle(wxRichTextStyleDefinition* def);
254
255 /**
256 Applies the style sheet to the buffer, matching paragraph styles in the sheet
257 against named styles in the buffer.
258
259 This might be useful if the styles have changed.
260 If @a sheet is @NULL, the sheet set with SetStyleSheet() is used.
261 Currently this applies paragraph styles only.
262 */
263 bool ApplyStyleSheet(wxRichTextStyleSheet* sheet = NULL);
264
265 /**
266 Applies underline to the selection (undoable).
267 */
268 virtual bool ApplyUnderlineToSelection();
269
270 /**
271 Returns @true if undo commands are being batched.
272 */
273 virtual bool BatchingUndo() const;
274
275 /**
276 Begins using alignment.
277 For alignment values, see wxTextAttr.
278 */
279 bool BeginAlignment(wxTextAttrAlignment alignment);
280
281 /**
282 Starts batching undo history for commands.
283 */
284 virtual bool BeginBatchUndo(const wxString& cmdName);
285
286 /**
287 Begins using bold.
288 */
289 bool BeginBold();
290
291 /**
292 Begins using the named character style.
293 */
294 bool BeginCharacterStyle(const wxString& characterStyle);
295
296 /**
297 Begins using this font.
298 */
299 bool BeginFont(const wxFont& font);
300
301 /**
302 Begins using the given point size.
303 */
304 bool BeginFontSize(int pointSize);
305
306 /**
307 Begins using italic.
308 */
309 bool BeginItalic();
310
311 /**
312 Begins applying a left indent and subindent in tenths of a millimetre.
313 The subindent is an offset from the left edge of the paragraph, and is
314 used for all but the first line in a paragraph. A positive value will
315 cause the first line to appear to the left of the subsequent lines, and
316 a negative value will cause the first line to be indented to the right
317 of the subsequent lines.
318
319 wxRichTextBuffer uses indentation to render a bulleted item. The
320 content of the paragraph, including the first line, starts at the
321 @a leftIndent plus the @a leftSubIndent.
322
323 @param leftIndent
324 The distance between the margin and the bullet.
325 @param leftSubIndent
326 The distance between the left edge of the bullet and the left edge
327 of the actual paragraph.
328 */
329 bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0);
330
331 /**
332 Begins appling line spacing. @e spacing is a multiple, where 10 means
333 single-spacing, 15 means 1.5 spacing, and 20 means double spacing.
334
335 The ::wxTextAttrLineSpacing constants are defined for convenience.
336 */
337 bool BeginLineSpacing(int lineSpacing);
338
339 /**
340 Begins using a specified list style.
341 Optionally, you can also pass a level and a number.
342 */
343 bool BeginListStyle(const wxString& listStyle, int level = 1,
344 int number = 1);
345
346 /**
347 Begins a numbered bullet.
348
349 This call will be needed for each item in the list, and the
350 application should take care of incrementing the numbering.
351
352 @a bulletNumber is a number, usually starting with 1.
353 @a leftIndent and @a leftSubIndent are values in tenths of a millimetre.
354 @a bulletStyle is a bitlist of the ::wxTextAttrBulletStyle values.
355
356 wxRichTextBuffer uses indentation to render a bulleted item.
357 The left indent is the distance between the margin and the bullet.
358 The content of the paragraph, including the first line, starts
359 at leftMargin + leftSubIndent.
360 So the distance between the left edge of the bullet and the
361 left of the actual paragraph is leftSubIndent.
362 */
363 bool BeginNumberedBullet(int bulletNumber, int leftIndent,
364 int leftSubIndent,
365 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD);
366
367 /**
368 Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing
369 in tenths of a millimetre.
370 */
371 bool BeginParagraphSpacing(int before, int after);
372
373 /**
374 Begins applying the named paragraph style.
375 */
376 bool BeginParagraphStyle(const wxString& paragraphStyle);
377
378 /**
379 Begins a right indent, specified in tenths of a millimetre.
380 */
381 bool BeginRightIndent(int rightIndent);
382
383 /**
384 Begins applying a style.
385 */
386 virtual bool BeginStyle(const wxTextAttr& style);
387
388 /**
389 Starts suppressing undo history for commands.
390 */
391 virtual bool BeginSuppressUndo();
392
393 /**
394 Begins applying a symbol bullet, using a character from the current font.
395 See BeginNumberedBullet() for an explanation of how indentation is used
396 to render the bulleted paragraph.
397 */
398 bool BeginSymbolBullet(const wxString& symbol, int leftIndent,
399 int leftSubIndent,
400 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL);
401
402 /**
403 Begins using this colour.
404 */
405 bool BeginTextColour(const wxColour& colour);
406
407 /**
408 Begins applying wxTEXT_ATTR_URL to the content.
409
410 Pass a URL and optionally, a character style to apply, since it is common
411 to mark a URL with a familiar style such as blue text with underlining.
412 */
413 bool BeginURL(const wxString& url,
414 const wxString& characterStyle = wxEmptyString);
415
416 /**
417 Begins using underlining.
418 */
419 bool BeginUnderline();
420
421 /**
422 Returns @true if selected content can be copied to the clipboard.
423 */
424 virtual bool CanCopy() const;
425
426 /**
427 Returns @true if selected content can be copied to the clipboard and deleted.
428 */
429 virtual bool CanCut() const;
430
431 /**
432 Returns @true if selected content can be deleted.
433 */
434 virtual bool CanDeleteSelection() const;
435
436 /**
437 Returns @true if the clipboard content can be pasted to the buffer.
438 */
439 virtual bool CanPaste() const;
440
441 /**
442 Returns @true if there is a command in the command history that can be redone.
443 */
444 virtual bool CanRedo() const;
445
446 /**
447 Returns @true if there is a command in the command history that can be undone.
448 */
449 virtual bool CanUndo() const;
450
451 /**
452 Clears the buffer content, leaving a single empty paragraph. Cannot be undone.
453 */
454 virtual void Clear();
455
456 /**
457 Clears the list style from the given range, clearing list-related attributes
458 and applying any named paragraph style associated with each paragraph.
459
460 @a flags is a bit list of the following:
461 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
462
463 @see SetListStyle(), PromoteList(), NumberList().
464 */
465 virtual bool ClearListStyle(const wxRichTextRange& range,
466 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
467
468 /**
469 Sends the event to the control.
470 */
471 virtual void Command(wxCommandEvent& event);
472
473 /**
474 Copies the selected content (if any) to the clipboard.
475 */
476 virtual void Copy();
477
478 /**
479 Creates the underlying window.
480 */
481 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
482 const wxString& value = wxEmptyString,
483 const wxPoint& pos = wxDefaultPosition,
484 const wxSize& size = wxDefaultSize,
485 long style = wxRE_MULTILINE,
486 const wxValidator& validator = wxDefaultValidator,
487 const wxString& name = wxTextCtrlNameStr);
488
489 /**
490 Copies the selected content (if any) to the clipboard and deletes the selection.
491 This is undoable.
492 */
493 virtual void Cut();
494
495 /**
496 Deletes the content within the given range.
497 */
498 virtual bool Delete(const wxRichTextRange& range);
499
500 /**
501 Deletes content if there is a selection, e.g. when pressing a key.
502 Returns the new caret position in @e newPos, or leaves it if there
503 was no action. This is undoable.
504
505 @beginWxPerlOnly
506 In wxPerl this method takes no arguments and returns a 2-element
507 list (ok, newPos).
508 @endWxPerlOnly
509 */
510 bool DeleteSelectedContent(long* newPos = NULL);
511
512 /**
513 Deletes the content in the selection, if any. This is undoable.
514 */
515 virtual void DeleteSelection();
516
517 /**
518 Sets the buffer's modified status to @false, and clears the buffer's command
519 history.
520 */
521 virtual void DiscardEdits();
522
523 /**
524 Ends alignment.
525 */
526 bool EndAlignment();
527
528 /**
529 Ends application of all styles in the current style stack.
530 */
531 virtual bool EndAllStyles();
532
533 /**
534 Ends batching undo command history.
535 */
536 virtual bool EndBatchUndo();
537
538 /**
539 Ends using bold.
540 */
541 bool EndBold();
542
543 /**
544 Ends application of a named character style.
545 */
546 bool EndCharacterStyle();
547
548 /**
549 Ends using a font.
550 */
551 bool EndFont();
552
553 /**
554 Ends using a point size.
555 */
556 bool EndFontSize();
557
558 /**
559 Ends using italic.
560 */
561 bool EndItalic();
562
563 /**
564 Ends left indent.
565 */
566 bool EndLeftIndent();
567
568 /**
569 Ends line spacing.
570 */
571 bool EndLineSpacing();
572
573 /**
574 Ends using a specified list style.
575 */
576 bool EndListStyle();
577
578 /**
579 Ends application of a numbered bullet.
580 */
581 bool EndNumberedBullet();
582
583 /**
584 Ends paragraph spacing.
585 */
586 bool EndParagraphSpacing();
587
588 /**
589 Ends application of a named character style.
590 */
591 bool EndParagraphStyle();
592
593 /**
594 Ends right indent.
595 */
596 bool EndRightIndent();
597
598 /**
599 Ends the current style.
600 */
601 virtual bool EndStyle();
602
603 /**
604 Ends suppressing undo command history.
605 */
606 virtual bool EndSuppressUndo();
607
608 /**
609 Ends applying a symbol bullet.
610 */
611 bool EndSymbolBullet();
612
613 /**
614 Ends applying a text colour.
615 */
616 bool EndTextColour();
617
618 /**
619 Ends applying a URL.
620 */
621 bool EndURL();
622
623 /**
624 End applying underlining.
625 */
626 bool EndUnderline();
627
628 /**
629 Helper function for extending the selection, returning @true if the selection
630 was changed. Selections are in caret positions.
631 */
632 virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
633
634 /**
635 Helper function for finding the caret position for the next word.
636 Direction is 1 (forward) or -1 (backwards).
637 */
638 virtual long FindNextWordPosition(int direction = 1) const;
639
640 /**
641 Call this function to prevent refresh and allow fast updates, and then Thaw() to
642 refresh the control.
643 */
644 void Freeze();
645
646 /**
647 Gets the basic (overall) style.
648
649 This is the style of the whole buffer before further styles are applied,
650 unlike the default style, which only affects the style currently being
651 applied (for example, setting the default style to bold will cause
652 subsequently inserted text to be bold).
653 */
654 virtual const wxTextAttr& GetBasicStyle() const;
655
656 //@{
657 /**
658 Returns the buffer associated with the control.
659 */
660 const wxRichTextBuffer GetBuffer();
661 const wxRichTextBuffer& GetBuffer();
662 //@}
663
664 /**
665 Returns the current caret position.
666 */
667 long GetCaretPosition() const;
668
669 /**
670 Returns the caret height and position for the given character position.
671
672 @beginWxPerlOnly
673 In wxPerl this method is implemented as
674 GetCaretPositionForIndex(@a position) returning a
675 2-element list (ok, rect).
676 @endWxPerlOnly
677 */
678 bool GetCaretPositionForIndex(long position, wxRect& rect);
679
680 /**
681 Gets the command processor associated with the control's buffer.
682 */
683 wxCommandProcessor* GetCommandProcessor() const;
684
685 /**
686 Returns the current default style, which can be used to change how subsequently
687 inserted text is displayed.
688 */
689 virtual const wxTextAttr& GetDefaultStyle() const;
690
691 /**
692 Gets the size of the buffer beyond which layout is delayed during resizing.
693 This optimizes sizing for large buffers. The default is 20000.
694 */
695 long GetDelayedLayoutThreshold() const;
696
697 /**
698 Gets the current filename associated with the control.
699 */
700 wxString GetFilename() const;
701
702 /**
703 Returns the first visible position in the current view.
704 */
705 long GetFirstVisiblePosition() const;
706
707 /**
708 Returns flags that change the behaviour of loading or saving.
709 See the documentation for each handler class to see what flags are
710 relevant for each handler.
711 */
712 int GetHandlerFlags() const;
713
714 /**
715 Returns the current insertion point.
716 */
717 virtual long GetInsertionPoint() const;
718
719 /**
720 Returns the last position in the buffer.
721 */
722 virtual wxTextPos GetLastPosition() const;
723
724 /**
725 Returns the length of the specified line in characters.
726 */
727 virtual int GetLineLength(long lineNo) const;
728
729 /**
730 Returns the text for the given line.
731 */
732 virtual wxString GetLineText(long lineNo) const;
733
734 /**
735 Transforms physical window position to logical (unscrolled) position.
736 */
737 wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
738
739 /**
740 Returns the number of lines in the buffer.
741 */
742 virtual int GetNumberOfLines() const;
743
744 /**
745 Transforms logical (unscrolled) position to physical window position.
746 */
747 wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
748
749 /**
750 Gets the text for the given range.
751 The end point of range is specified as the last character position of
752 the span of text, plus one.
753 */
754 virtual wxString GetRange(long from, long to) const;
755
756 /**
757 Returns the range of the current selection.
758 The end point of range is specified as the last character position of the span
759 of text, plus one.
760 If the return values @a from and @a to are the same, there is no selection.
761 */
762 virtual void GetSelection(long* from, long* to) const;
763
764 /**
765 Returns the selection range in character positions. -1, -1 means no selection.
766 */
767 wxRichTextRange GetSelectionRange() const;
768
769 /**
770 Returns the text within the current selection range, if any.
771 */
772 virtual wxString GetStringSelection() const;
773
774 /**
775 Gets the attributes at the given position.
776 This function gets the combined style - that is, the style you see on the
777 screen as a result of combining base style, paragraph style and character
778 style attributes.
779
780 To get the character or paragraph style alone, use GetUncombinedStyle().
781
782 @beginWxPerlOnly
783 In wxPerl this method is implemented as GetStyle(@a position)
784 returning a 2-element list (ok, attr).
785 @endWxPerlOnly
786 */
787 virtual bool GetStyle(long position, wxTextAttr& style);
788
789 /**
790 Gets the attributes common to the specified range.
791 Attributes that differ in value within the range will not be included
792 in @a style flags.
793
794 @beginWxPerlOnly
795 In wxPerl this method is implemented as GetStyleForRange(@a position)
796 returning a 2-element list (ok, attr).
797 @endWxPerlOnly
798 */
799 virtual bool GetStyleForRange(const wxRichTextRange& range,
800 wxTextAttr& style);
801
802 /**
803 Returns the style sheet associated with the control, if any.
804 A style sheet allows named character and paragraph styles to be applied.
805 */
806 wxRichTextStyleSheet* GetStyleSheet() const;
807
808 /**
809 Gets the attributes at the given position.
810 This function gets the @e uncombined style - that is, the attributes associated
811 with the paragraph or character content, and not necessarily the combined
812 attributes you see on the screen.
813 To get the combined attributes, use GetStyle().
814
815 If you specify (any) paragraph attribute in @e style's flags, this function
816 will fetch the paragraph attributes.
817 Otherwise, it will return the character attributes.
818
819 @beginWxPerlOnly
820 In wxPerl this method is implemented as GetUncombinedStyle(@a position)
821 returning a 2-element list (ok, attr).
822 @endWxPerlOnly
823 */
824 virtual bool GetUncombinedStyle(long position, wxTextAttr& style);
825
826 /**
827 Returns the content of the entire control as a string.
828 */
829 virtual wxString GetValue() const;
830
831 /**
832 Internal helper function returning the line for the visible caret position.
833 If the caret is shown at the very end of the line, it means the next character
834 is actually on the following line.
835 So this function gets the line we're expecting to find if this is the case.
836 */
837 wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
838
839 /**
840 Test if this whole range has character attributes of the specified kind.
841 If any of the attributes are different within the range, the test fails.
842
843 You can use this to implement, for example, bold button updating.
844 @a style must have flags indicating which attributes are of interest.
845 */
846 virtual bool HasCharacterAttributes(const wxRichTextRange& range,
847 const wxTextAttr& style) const;
848
849 /**
850 Test if this whole range has paragraph attributes of the specified kind.
851 If any of the attributes are different within the range, the test fails.
852 You can use this to implement, for example, centering button updating.
853 @a style must have flags indicating which attributes are of interest.
854 */
855 virtual bool HasParagraphAttributes(const wxRichTextRange& range,
856 const wxTextAttr& style) const;
857
858 /**
859 Returns @true if there is a selection.
860 */
861 virtual bool HasSelection() const;
862
863 //@{
864 /**
865 Finds the character at the given position in pixels.
866 @a pt is in device coords (not adjusted for the client area origin nor for
867 scrolling).
868 */
869 wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long* pos) const;
870 const wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
871 wxTextCoord* col,
872 wxTextCoord* row) const;
873 //@}
874
875 /**
876 Initialises the members of the control.
877 */
878 void Init();
879
880 /**
881 Returns @true if the user has recently set the default style without moving
882 the caret, and therefore the UI needs to reflect the default style and not
883 the style at the caret.
884
885 Below is an example of code that uses this function to determine whether the UI
886 should show that the current style is bold.
887
888 @see SetAndShowDefaultStyle().
889 */
890 bool IsDefaultStyleShowing() const;
891
892 /**
893 Returns @true if the control is editable.
894 */
895 virtual bool IsEditable() const;
896
897 /**
898 Returns @true if Freeze has been called without a Thaw.
899 */
900 bool IsFrozen() const;
901
902 /**
903 Returns @true if the buffer has been modified.
904 */
905 virtual bool IsModified() const;
906
907 /**
908 Returns @true if the control is multiline.
909 */
910 bool IsMultiLine() const;
911
912 /**
913 Returns @true if the given position is visible on the screen.
914 */
915 bool IsPositionVisible(long pos) const;
916
917 /**
918 Returns @true if all of the selection is aligned according to the specified flag.
919 */
920 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment);
921
922 /**
923 Returns @true if all of the selection is bold.
924 */
925 virtual bool IsSelectionBold();
926
927 /**
928 Returns @true if all of the selection is italic.
929 */
930 virtual bool IsSelectionItalics();
931
932 /**
933 Returns @true if all of the selection is underlined.
934 */
935 virtual bool IsSelectionUnderlined();
936
937 /**
938 Returns @true if the control is single-line.
939 Currently wxRichTextCtrl does not support single-line editing.
940 */
941 bool IsSingleLine() const;
942
943 /**
944 Helper function implementing keyboard navigation.
945 */
946 virtual bool KeyboardNavigate(int keyCode, int flags);
947
948 /**
949 Lays out the buffer, which must be done before certain operations, such as
950 setting the caret position.
951 This function should not normally be required by the application.
952 */
953 virtual bool LayoutContent(bool onlyVisibleRect = false);
954
955 /**
956 Inserts a line break at the current insertion point.
957
958 A line break forces wrapping within a paragraph, and can be introduced by
959 using this function, by appending the wxChar value @b wxRichTextLineBreakChar
960 to text content, or by typing Shift-Return.
961 */
962 virtual bool LineBreak();
963
964 /**
965 Loads content into the control's buffer using the given type.
966
967 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
968 the filename extension.
969
970 This function looks for a suitable wxRichTextFileHandler object.
971 */
972 bool LoadFile(const wxString& file,
973 int type = wxRICHTEXT_TYPE_ANY);
974
975 /**
976 Marks the buffer as modified.
977 */
978 virtual void MarkDirty();
979
980 /**
981 Move the caret to the given character position.
982
983 Please note that this does not update the current editing style
984 from the new position; to do that, call wxRichTextCtrl::SetInsertionPoint instead.
985 */
986 virtual bool MoveCaret(long pos, bool showAtLineStart = false);
987
988 /**
989 Move the caret one visual step forward: this may mean setting a flag
990 and keeping the same position if we're going from the end of one line
991 to the start of the next, which may be the exact same caret position.
992 */
993 void MoveCaretBack(long oldPosition);
994
995 /**
996 Move the caret one visual step forward: this may mean setting a flag
997 and keeping the same position if we're going from the end of one line
998 to the start of the next, which may be the exact same caret position.
999 */
1000 void MoveCaretForward(long oldPosition);
1001
1002 /**
1003 Moves the caret down.
1004 */
1005 virtual bool MoveDown(int noLines = 1, int flags = 0);
1006
1007 /**
1008 Moves to the end of the buffer.
1009 */
1010 virtual bool MoveEnd(int flags = 0);
1011
1012 /**
1013 Moves to the start of the buffer.
1014 */
1015 virtual bool MoveHome(int flags = 0);
1016
1017 /**
1018 Moves left.
1019 */
1020 virtual bool MoveLeft(int noPositions = 1, int flags = 0);
1021
1022 /**
1023 Moves right.
1024 */
1025 virtual bool MoveRight(int noPositions = 1, int flags = 0);
1026
1027 /**
1028 Moves to the end of the line.
1029 */
1030 virtual bool MoveToLineEnd(int flags = 0);
1031
1032 /**
1033 Moves to the start of the line.
1034 */
1035 virtual bool MoveToLineStart(int flags = 0);
1036
1037 /**
1038 Moves to the end of the paragraph.
1039 */
1040 virtual bool MoveToParagraphEnd(int flags = 0);
1041
1042 /**
1043 Moves to the start of the paragraph.
1044 */
1045 virtual bool MoveToParagraphStart(int flags = 0);
1046
1047 /**
1048 Moves up.
1049 */
1050 virtual bool MoveUp(int noLines = 1, int flags = 0);
1051
1052 /**
1053 Inserts a new paragraph at the current insertion point. @see LineBreak().
1054 */
1055 virtual bool Newline();
1056
1057 //@{
1058 /**
1059 Numbers the paragraphs in the given range.
1060 Pass flags to determine how the attributes are set.
1061
1062 Either the style definition or the name of the style definition (in the current
1063 sheet) can be passed.
1064
1065 @a flags is a bit list of the following:
1066 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1067 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1068 @a startFrom, otherwise existing attributes are used.
1069 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1070 as the level for all paragraphs, otherwise the current indentation will be used.
1071
1072 @see SetListStyle(), PromoteList(), ClearListStyle().
1073 */
1074 bool NumberList(const wxRichTextRange& range,
1075 const wxRichTextListStyleDefinition* style,
1076 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1077 int startFrom = -1,
1078 int listLevel = -1);
1079 bool Number(const wxRichTextRange& range,
1080 const wxString& styleName,
1081 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1082 int startFrom = -1,
1083 int listLevel = -1);
1084 //@}
1085
1086 /**
1087 Standard handler for the wxID_CLEAR command.
1088 */
1089 void OnClear(wxCommandEvent& event);
1090
1091 /**
1092 Shows a standard context menu with undo, redo, cut, copy, paste, clear, and
1093 select all commands.
1094 */
1095 void OnContextMenu(wxContextMenuEvent& event);
1096
1097 /**
1098 Standard handler for the wxID_COPY command.
1099 */
1100 void OnCopy(wxCommandEvent& event);
1101
1102 /**
1103 Standard handler for the wxID_CUT command.
1104 */
1105 void OnCut(wxCommandEvent& event);
1106
1107 /**
1108 Loads the first dropped file.
1109 */
1110 void OnDropFiles(wxDropFilesEvent& event);
1111
1112 /**
1113 Standard handler for the wxID_PASTE command.
1114 */
1115 void OnPaste(wxCommandEvent& event);
1116
1117 /**
1118 Standard handler for the wxID_REDO command.
1119 */
1120 void OnRedo(wxCommandEvent& event);
1121
1122 /**
1123 Standard handler for the wxID_SELECTALL command.
1124 */
1125 void OnSelectAll(wxCommandEvent& event);
1126
1127 /**
1128 Standard handler for the wxID_UNDO command.
1129 */
1130 void OnUndo(wxCommandEvent& event);
1131
1132 /**
1133 Standard update handler for the wxID_CLEAR command.
1134 */
1135 void OnUpdateClear(wxUpdateUIEvent& event);
1136
1137 /**
1138 Standard update handler for the wxID_COPY command.
1139 */
1140 void OnUpdateCopy(wxUpdateUIEvent& event);
1141
1142 /**
1143 Standard update handler for the wxID_CUT command.
1144 */
1145 void OnUpdateCut(wxUpdateUIEvent& event);
1146
1147 /**
1148 Standard update handler for the wxID_PASTE command.
1149 */
1150 void OnUpdatePaste(wxUpdateUIEvent& event);
1151
1152 /**
1153 Standard update handler for the wxID_REDO command.
1154 */
1155 void OnUpdateRedo(wxUpdateUIEvent& event);
1156
1157 /**
1158 Standard update handler for the wxID_SELECTALL command.
1159 */
1160 void OnUpdateSelectAll(wxUpdateUIEvent& event);
1161
1162 /**
1163 Standard update handler for the wxID_UNDO command.
1164 */
1165 void OnUpdateUndo(wxUpdateUIEvent& event);
1166
1167 /**
1168 Moves one or more pages down.
1169 */
1170 virtual bool PageDown(int noPages = 1, int flags = 0);
1171
1172 /**
1173 Moves one or more pages up.
1174 */
1175 virtual bool PageUp(int noPages = 1, int flags = 0);
1176
1177 /**
1178 Paints the background.
1179 */
1180 virtual void PaintBackground(wxDC& dc);
1181
1182 /**
1183 Other user defined painting after everything else (i.e. all text) is painted.
1184
1185 @since 2.9.1
1186 */
1187 virtual void PaintAboveContent(wxDC& dc);
1188
1189 /**
1190 Pastes content from the clipboard to the buffer.
1191 */
1192 virtual void Paste();
1193
1194 /**
1195 Internal function to position the visible caret according to the current caret
1196 position.
1197 */
1198 virtual void PositionCaret();
1199
1200 /**
1201 Converts a text position to zero-based column and line numbers.
1202 */
1203 virtual bool PositionToXY(long pos, long* x, long* y) const;
1204
1205 //@{
1206 /**
1207 Promotes or demotes the paragraphs in the given range.
1208 A positive @a promoteBy produces a smaller indent, and a negative number
1209 produces a larger indent. Pass flags to determine how the attributes are set.
1210 Either the style definition or the name of the style definition (in the current
1211 sheet) can be passed.
1212
1213 @a flags is a bit list of the following:
1214 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1215 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1216 @a startFrom, otherwise existing attributes are used.
1217 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1218 as the level for all paragraphs, otherwise the current indentation will be used.
1219
1220 @see SetListStyle(), @see SetListStyle(), ClearListStyle().
1221 */
1222 bool PromoteList(int promoteBy, const wxRichTextRange& range,
1223 const wxRichTextListStyleDefinition* style,
1224 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1225 int listLevel = -1);
1226 bool PromoteList(int promoteBy, const wxRichTextRange& range,
1227 const wxString& styleName,
1228 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1229 int listLevel = -1);
1230 //@}
1231
1232 /**
1233 Redoes the current command.
1234 */
1235 virtual void Redo();
1236
1237 /**
1238 Removes the content in the specified range.
1239 */
1240 virtual void Remove(long from, long to);
1241
1242 /**
1243 Replaces the content in the specified range with the string specified by
1244 @a value.
1245 */
1246 virtual void Replace(long from, long to, const wxString& value);
1247
1248 /**
1249 Saves the buffer content using the given type.
1250
1251 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
1252 the filename extension.
1253
1254 This function looks for a suitable wxRichTextFileHandler object.
1255 */
1256 bool SaveFile(const wxString& file = wxEmptyString,
1257 int type = wxRICHTEXT_TYPE_ANY);
1258
1259 /**
1260 Scrolls @a position into view. This function takes a caret position.
1261 */
1262 virtual bool ScrollIntoView(long position, int keyCode);
1263
1264 /**
1265 Selects all the text in the buffer.
1266 */
1267 virtual void SelectAll();
1268
1269 /**
1270 Cancels any selection.
1271 */
1272 virtual void SelectNone();
1273
1274 /**
1275 Sets @a attr as the default style and tells the control that the UI should
1276 reflect this attribute until the user moves the caret.
1277
1278 @see IsDefaultStyleShowing().
1279 */
1280 void SetAndShowDefaultStyle(const wxTextAttr& attr);
1281
1282 /**
1283 Sets the basic (overall) style.
1284
1285 This is the style of the whole buffer before further styles are applied,
1286 unlike the default style, which only affects the style currently being
1287 applied (for example, setting the default style to bold will cause
1288 subsequently inserted text to be bold).
1289 */
1290 virtual void SetBasicStyle(const wxTextAttr& style);
1291
1292 /**
1293 Sets the caret position.
1294
1295 The caret position is the character position just before the caret.
1296 A value of -1 means the caret is at the start of the buffer.
1297 Please note that this does not update the current editing style
1298 from the new position or cause the actual caret to be refreshed; to do that,
1299 call wxRichTextCtrl::SetInsertionPoint instead.
1300 */
1301 void SetCaretPosition(long position,
1302 bool showAtLineStart = false);
1303
1304 /**
1305 Sets the current default style, which can be used to change how subsequently
1306 inserted text is displayed.
1307 */
1308 virtual bool SetDefaultStyle(const wxTextAttr& style);
1309
1310 /**
1311 Sets the default style to the style under the cursor.
1312 */
1313 bool SetDefaultStyleToCursorStyle();
1314
1315 /**
1316 Sets the size of the buffer beyond which layout is delayed during resizing.
1317 This optimizes sizing for large buffers. The default is 20000.
1318 */
1319 void SetDelayedLayoutThreshold(long threshold);
1320
1321 /**
1322 Makes the control editable, or not.
1323 */
1324 virtual void SetEditable(bool editable);
1325
1326 /**
1327 Sets the current filename.
1328 */
1329 void SetFilename(const wxString& filename);
1330
1331 /**
1332 Sets the font, and also the basic and default attributes
1333 (see wxRichTextCtrl::SetDefaultStyle).
1334 */
1335 virtual bool SetFont(const wxFont& font);
1336
1337 /**
1338 Sets flags that change the behaviour of loading or saving.
1339
1340 See the documentation for each handler class to see what flags are
1341 relevant for each handler.
1342 */
1343 void SetHandlerFlags(int flags);
1344
1345 /**
1346 Sets the insertion point and causes the current editing style to be taken from
1347 the new position (unlike wxRichTextCtrl::SetCaretPosition).
1348 */
1349 virtual void SetInsertionPoint(long pos);
1350
1351 /**
1352 Sets the insertion point to the end of the text control.
1353 */
1354 virtual void SetInsertionPointEnd();
1355
1356 //@{
1357 /**
1358 Sets the list attributes for the given range, passing flags to determine how
1359 the attributes are set.
1360
1361 Either the style definition or the name of the style definition (in the current
1362 sheet) can be passed.
1363 @a flags is a bit list of the following:
1364 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1365 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1366 @a startFrom, otherwise existing attributes are used.
1367 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1368 as the level for all paragraphs, otherwise the current indentation will be used.
1369
1370 @see NumberList(), PromoteList(), ClearListStyle().
1371 */
1372 bool SetListStyle(const wxRichTextRange& range,
1373 const wxRichTextListStyleDefinition* style,
1374 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1375 int startFrom = -1,
1376 int listLevel = -1);
1377 bool SetListStyle(const wxRichTextRange& range,
1378 const wxString& styleName,
1379 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1380 int startFrom = -1,
1381 int listLevel = -1);
1382 //@}
1383
1384 /**
1385 Sets the selection to the given range.
1386 The end point of range is specified as the last character position of the span
1387 of text, plus one.
1388
1389 So, for example, to set the selection for a character at position 5, use the
1390 range (5,6).
1391 */
1392 virtual void SetSelection(long from, long to);
1393
1394 /**
1395 Sets the selection to the given range.
1396 The end point of range is specified as the last character position of the span
1397 of text, plus one.
1398
1399 So, for example, to set the selection for a character at position 5, use the
1400 range (5,6).
1401 */
1402 void SetSelectionRange(const wxRichTextRange& range);
1403
1404 //@{
1405 /**
1406 Sets the attributes for the given range.
1407 The end point of range is specified as the last character position of the span
1408 of text, plus one.
1409
1410 So, for example, to set the style for a character at position 5, use the range
1411 (5,6).
1412 */
1413 bool SetStyle(const wxRichTextRange& range,
1414 const wxTextAttr& style);
1415 bool SetStyle(long start, long end, const wxTextAttr& style);
1416 //@}
1417
1418 /**
1419 Sets the attributes for the given range, passing flags to determine how the
1420 attributes are set.
1421
1422 The end point of range is specified as the last character position of the span
1423 of text, plus one. So, for example, to set the style for a character at
1424 position 5, use the range (5,6).
1425
1426 @a flags may contain a bit list of the following values:
1427 - wxRICHTEXT_SETSTYLE_NONE: no style flag.
1428 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
1429 undoable.
1430 - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
1431 if the combined style at this point is already the style in question.
1432 - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
1433 applied to paragraphs, and not the content.
1434 This allows content styling to be preserved independently from that
1435 of e.g. a named paragraph style.
1436 - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
1437 applied to characters, and not the paragraph.
1438 This allows content styling to be preserved independently from that
1439 of e.g. a named paragraph style.
1440 - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
1441 the new style.
1442 - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style. Only the style flags
1443 are used in this operation.
1444 */
1445 virtual bool SetStyleEx(const wxRichTextRange& range,
1446 const wxTextAttr& style,
1447 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
1448
1449 /**
1450 Sets the style sheet associated with the control.
1451 A style sheet allows named character and paragraph styles to be applied.
1452 */
1453 void SetStyleSheet(wxRichTextStyleSheet* styleSheet);
1454
1455 /**
1456 Replaces existing content with the given text.
1457 */
1458 virtual void SetValue(const wxString& value);
1459
1460 /**
1461 A helper function setting up scrollbars, for example after a resize.
1462 */
1463 virtual void SetupScrollbars(bool atTop = false);
1464
1465 /**
1466 Scrolls the buffer so that the given position is in view.
1467 */
1468 virtual void ShowPosition(long pos);
1469
1470 /**
1471 Returns @true if undo history suppression is on.
1472 */
1473 virtual bool SuppressingUndo() const;
1474
1475 /**
1476 Call this function to end a Freeze and refresh the display.
1477 */
1478 void Thaw();
1479
1480 /**
1481 Undoes the command at the top of the command history, if there is one.
1482 */
1483 virtual void Undo();
1484
1485 /**
1486 Moves a number of words to the left.
1487 */
1488 virtual bool WordLeft(int noWords = 1, int flags = 0);
1489
1490 /**
1491 Move a nuber of words to the right.
1492 */
1493 virtual bool WordRight(int noWords = 1, int flags = 0);
1494
1495 /**
1496 Loads an image from a file and writes it at the current insertion point.
1497 */
1498 virtual bool WriteImage(const wxString& filename, wxBitmapType bitmapType);
1499
1500 /**
1501 Writes an image block at the current insertion point.
1502 */
1503 virtual bool WriteImage(const wxRichTextImageBlock& imageBlock);
1504
1505 //@{
1506 /**
1507 Write a bitmap or image at the current insertion point.
1508 Supply an optional type to use for internal and file storage of the raw data.
1509 */
1510 bool WriteImage(const wxBitmap& bitmap,
1511 int bitmapType = wxBITMAP_TYPE_PNG);
1512 bool WriteImage(const wxImage& image,
1513 int bitmapType = wxBITMAP_TYPE_PNG);
1514 //@}
1515
1516 /**
1517 Writes text at the current position.
1518 */
1519 virtual void WriteText(const wxString& text);
1520
1521 /**
1522 Translates from column and line number to position.
1523 */
1524 virtual long XYToPosition(long x, long y) const;
1525
1526 protected:
1527
1528 /**
1529 Currently this simply returns @c wxSize(10, 10).
1530 */
1531 virtual wxSize DoGetBestSize() const;
1532
1533 /**
1534 Initialises the command event.
1535 */
1536 void InitCommandEvent(wxCommandEvent& event) const;
1537 };
1538