1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextctrl.h
3 // Purpose: interface of wxRichTextCtrl and wxRichTextEvent
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxRichTextEvent
12 This is the event class for wxRichTextCtrl notifications.
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.
56 @category{events,richtext}
58 class wxRichTextEvent
: public wxNotifyEvent
64 wxRichTextEvent(const wxRichTextEvent
& event
);
70 The type of the event.
72 Window identifier. The value @c wxID_ANY indicates a default value.
74 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
77 Returns the character pressed, within a wxEVT_COMMAND_RICHTEXT_CHARACTER event.
79 wxChar
GetCharacter() const;
82 Returns flags indicating modifier keys pressed.
84 Possible values are wxRICHTEXT_CTRL_DOWN, wxRICHTEXT_SHIFT_DOWN, and wxRICHTEXT_ALT_DOWN.
89 Returns the new style sheet.
91 Can be used in a wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
92 wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
94 wxRichTextStyleSheet
* GetNewStyleSheet() const;
97 Returns the old style sheet.
99 Can be used in a wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
100 wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
102 wxRichTextStyleSheet
* GetOldStyleSheet() const;
105 Returns the buffer position at which the event occured.
107 long GetPosition() const;
110 Gets the range for the current operation.
112 const wxRichTextRange
& GetRange() const;
115 Sets the character variable.
117 void SetCharacter(wxChar ch
);
120 Sets flags indicating modifier keys pressed.
122 Possible values are wxRICHTEXT_CTRL_DOWN, wxRICHTEXT_SHIFT_DOWN, and wxRICHTEXT_ALT_DOWN.
124 void SetFlags(int flags
);
127 Sets the new style sheet variable.
129 void SetNewStyleSheet(wxRichTextStyleSheet
* sheet
);
132 Sets the old style sheet variable.
134 void SetOldStyleSheet(wxRichTextStyleSheet
* sheet
);
137 Sets the buffer position variable.
139 void SetPosition(long pos
);
142 Sets the range variable.
144 void SetRange(const wxRichTextRange
& range
);
150 @class wxRichTextCtrl
152 wxRichTextCtrl provides a generic, ground-up implementation of a text control
153 capable of showing multiple styles and images.
155 wxRichTextCtrl sends notification events: see wxRichTextEvent.
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.
160 For more information, see the @ref overview_richtextctrl.
164 @appearance{richtextctrl.png}
175 Constructor, creating and showing a rich text control.
178 Parent window. Must not be @NULL.
180 Window identifier. The value @c wxID_ANY indicates a default value.
194 @see Create(), wxValidator
196 wxRichTextCtrl(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
197 const wxString
& value
= wxEmptyString
,
198 const wxPoint
& pos
= wxDefaultPosition
,
199 const wxSize
& size
= wxDefaultSize
,
200 long style
= wxRE_MULTILINE
,
201 const wxValidator
& validator
= wxDefaultValidator
,
202 const wxString
& name
= wxTextCtrlNameStr
);
207 virtual ~wxRichTextCtrl();
210 Adds an image to the control's buffer.
212 virtual wxRichTextRange
AddImage(const wxImage
& image
);
215 Adds a new paragraph of text to the end of the buffer.
217 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
220 Sets the insertion point to the end of the buffer and writes the text.
222 virtual void AppendText(const wxString
& text
);
225 Applies the given alignment to the selection (undoable).
226 For alignment values, see wxTextAttr.
228 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
231 Apples bold to the selection (undoable).
233 virtual bool ApplyBoldToSelection();
236 Applies italic to the selection (undoable).
238 virtual bool ApplyItalicToSelection();
241 Applies the given style to the selection.
243 virtual bool ApplyStyle(wxRichTextStyleDefinition
* def
);
246 Applies the style sheet to the buffer, matching paragraph styles in the sheet
247 against named styles in the buffer.
249 This might be useful if the styles have changed.
250 If @a sheet is @NULL, the sheet set with SetStyleSheet() is used.
251 Currently this applies paragraph styles only.
253 bool ApplyStyleSheet(wxRichTextStyleSheet
* sheet
= NULL
);
256 Applies underline to the selection (undoable).
258 virtual bool ApplyUnderlineToSelection();
261 Returns @true if undo commands are being batched.
263 virtual bool BatchingUndo() const;
266 Begins using alignment.
267 For alignment values, see wxTextAttr.
269 bool BeginAlignment(wxTextAttrAlignment alignment
);
272 Starts batching undo history for commands.
274 virtual bool BeginBatchUndo(const wxString
& cmdName
);
282 Begins using the named character style.
284 bool BeginCharacterStyle(const wxString
& characterStyle
);
287 Begins using this font.
289 bool BeginFont(const wxFont
& font
);
292 Begins using the given point size.
294 bool BeginFontSize(int pointSize
);
302 Begins applying a left indent and subindent in tenths of a millimetre.
303 The subindent is an offset from the left edge of the paragraph, and is
304 used for all but the first line in a paragraph. A positive value will
305 cause the first line to appear to the left of the subsequent lines, and
306 a negative value will cause the first line to be indented to the right
307 of the subsequent lines.
309 wxRichTextBuffer uses indentation to render a bulleted item. The
310 content of the paragraph, including the first line, starts at the
311 @a leftIndent plus the @a leftSubIndent.
314 The distance between the margin and the bullet.
316 The distance between the left edge of the bullet and the left edge
317 of the actual paragraph.
319 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
322 Begins appling line spacing. @e spacing is a multiple, where 10 means
323 single-spacing, 15 means 1.5 spacing, and 20 means double spacing.
325 The ::wxTextAttrLineSpacing constants are defined for convenience.
327 bool BeginLineSpacing(int lineSpacing
);
330 Begins using a specified list style.
331 Optionally, you can also pass a level and a number.
333 bool BeginListStyle(const wxString
& listStyle
, int level
= 1,
337 Begins a numbered bullet.
339 This call will be needed for each item in the list, and the
340 application should take care of incrementing the numbering.
342 @a bulletNumber is a number, usually starting with 1.
343 @a leftIndent and @a leftSubIndent are values in tenths of a millimetre.
344 @a bulletStyle is a bitlist of the ::wxTextAttrBulletStyle values.
346 wxRichTextBuffer uses indentation to render a bulleted item.
347 The left indent is the distance between the margin and the bullet.
348 The content of the paragraph, including the first line, starts
349 at leftMargin + leftSubIndent.
350 So the distance between the left edge of the bullet and the
351 left of the actual paragraph is leftSubIndent.
353 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
,
355 int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
358 Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing
359 in tenths of a millimetre.
361 bool BeginParagraphSpacing(int before
, int after
);
364 Begins applying the named paragraph style.
366 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
369 Begins a right indent, specified in tenths of a millimetre.
371 bool BeginRightIndent(int rightIndent
);
374 Begins applying a style.
376 virtual bool BeginStyle(const wxTextAttr
& style
);
379 Starts suppressing undo history for commands.
381 virtual bool BeginSuppressUndo();
384 Begins applying a symbol bullet, using a character from the current font.
385 See BeginNumberedBullet() for an explanation of how indentation is used
386 to render the bulleted paragraph.
388 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
,
390 int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
393 Begins using this colour.
395 bool BeginTextColour(const wxColour
& colour
);
398 Begins applying wxTEXT_ATTR_URL to the content.
400 Pass a URL and optionally, a character style to apply, since it is common
401 to mark a URL with a familiar style such as blue text with underlining.
403 bool BeginURL(const wxString
& url
,
404 const wxString
& characterStyle
= wxEmptyString
);
407 Begins using underlining.
409 bool BeginUnderline();
412 Returns @true if selected content can be copied to the clipboard.
414 virtual bool CanCopy() const;
417 Returns @true if selected content can be copied to the clipboard and deleted.
419 virtual bool CanCut() const;
422 Returns @true if selected content can be deleted.
424 virtual bool CanDeleteSelection() const;
427 Returns @true if the clipboard content can be pasted to the buffer.
429 virtual bool CanPaste() const;
432 Returns @true if there is a command in the command history that can be redone.
434 virtual bool CanRedo() const;
437 Returns @true if there is a command in the command history that can be undone.
439 virtual bool CanUndo() const;
442 Clears the buffer content, leaving a single empty paragraph. Cannot be undone.
444 virtual void Clear();
448 Clears the list style from the given range, clearing list-related attributes
449 and applying any named paragraph style associated with each paragraph.
451 @a flags is a bit list of the following:
452 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
454 @see SetListStyle(), PromoteList(), NumberList().
456 bool ClearListStyle(const wxRichTextRange
& range
,
457 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
458 bool ClearListStyle(const wxRichTextRange
& range
,
459 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
463 Sends the event to the control.
465 virtual void Command(wxCommandEvent
& event
);
468 Copies the selected content (if any) to the clipboard.
473 Creates the underlying window.
475 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
476 const wxString
& value
= wxEmptyString
,
477 const wxPoint
& pos
= wxDefaultPosition
,
478 const wxSize
& size
= wxDefaultSize
,
479 long style
= wxRE_MULTILINE
,
480 const wxValidator
& validator
= wxDefaultValidator
,
481 const wxString
& name
= wxTextCtrlNameStr
);
484 Copies the selected content (if any) to the clipboard and deletes the selection.
490 Deletes the content within the given range.
492 virtual bool Delete(const wxRichTextRange
& range
);
495 Deletes content if there is a selection, e.g. when pressing a key.
496 Returns the new caret position in @e newPos, or leaves it if there
497 was no action. This is undoable.
499 bool DeleteSelectedContent(long* newPos
= NULL
);
502 Deletes the content in the selection, if any. This is undoable.
504 virtual void DeleteSelection();
507 Sets the buffer's modified status to @false, and clears the buffer's command
510 virtual void DiscardEdits();
518 Ends application of all styles in the current style stack.
520 virtual bool EndAllStyles();
523 Ends batching undo command history.
525 virtual bool EndBatchUndo();
533 Ends application of a named character style.
535 bool EndCharacterStyle();
543 Ends using a point size.
555 bool EndLeftIndent();
560 bool EndLineSpacing();
563 Ends using a specified list style.
568 Ends application of a numbered bullet.
570 bool EndNumberedBullet();
573 Ends paragraph spacing.
575 bool EndParagraphSpacing();
578 Ends application of a named character style.
580 bool EndParagraphStyle();
585 bool EndRightIndent();
588 Ends the current style.
590 virtual bool EndStyle();
593 Ends suppressing undo command history.
595 virtual bool EndSuppressUndo();
598 Ends applying a symbol bullet.
600 bool EndSymbolBullet();
603 Ends applying a text colour.
605 bool EndTextColour();
613 End applying underlining.
618 Helper function for extending the selection, returning @true if the selection
619 was changed. Selections are in caret positions.
621 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
624 Helper function for finding the caret position for the next word.
625 Direction is 1 (forward) or -1 (backwards).
627 virtual long FindNextWordPosition(int direction
= 1) const;
630 Call this function to prevent refresh and allow fast updates, and then Thaw() to
636 Gets the basic (overall) style.
638 This is the style of the whole buffer before further styles are applied,
639 unlike the default style, which only affects the style currently being
640 applied (for example, setting the default style to bold will cause
641 subsequently inserted text to be bold).
643 virtual const wxTextAttr
& GetBasicStyle() const;
647 Returns the buffer associated with the control.
649 const wxRichTextBuffer
GetBuffer();
650 const wxRichTextBuffer
& GetBuffer();
654 Returns the current caret position.
656 long GetCaretPosition() const;
659 Returns the caret height and position for the given character position.
661 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
664 Gets the command processor associated with the control's buffer.
666 wxCommandProcessor
* GetCommandProcessor() const;
669 Returns the current default style, which can be used to change how subsequently
670 inserted text is displayed.
672 virtual const wxTextAttr
& GetDefaultStyle() const;
675 Gets the size of the buffer beyond which layout is delayed during resizing.
676 This optimizes sizing for large buffers. The default is 20000.
678 long GetDelayedLayoutThreshold() const;
681 Gets the current filename associated with the control.
683 wxString
GetFilename() const;
686 Returns the first visible position in the current view.
688 long GetFirstVisiblePosition() const;
691 Returns flags that change the behaviour of loading or saving.
692 See the documentation for each handler class to see what flags are
693 relevant for each handler.
695 int GetHandlerFlags() const;
698 Returns the current insertion point.
700 virtual long GetInsertionPoint() const;
703 Returns the last position in the buffer.
705 virtual wxTextPos
GetLastPosition() const;
708 Returns the length of the specified line in characters.
710 virtual int GetLineLength(long lineNo
) const;
713 Returns the text for the given line.
715 virtual wxString
GetLineText(long lineNo
) const;
718 Transforms physical window position to logical (unscrolled) position.
720 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
723 Returns the number of lines in the buffer.
725 virtual int GetNumberOfLines() const;
728 Transforms logical (unscrolled) position to physical window position.
730 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
733 Gets the text for the given range.
734 The end point of range is specified as the last character position of
735 the span of text, plus one.
737 virtual wxString
GetRange(long from
, long to
) const;
740 Returns the range of the current selection.
741 The end point of range is specified as the last character position of the span
743 If the return values @a from and @a to are the same, there is no selection.
745 virtual void GetSelection(long* from
, long* to
) const;
748 Returns the selection range in character positions. -1, -1 means no selection.
750 wxRichTextRange
GetSelectionRange() const;
753 Returns the text within the current selection range, if any.
755 virtual wxString
GetStringSelection() const;
758 Gets the attributes at the given position.
759 This function gets the combined style - that is, the style you see on the
760 screen as a result of combining base style, paragraph style and character
763 To get the character or paragraph style alone, use GetUncombinedStyle().
765 virtual bool GetStyle(long position
, wxTextAttr
& style
);
768 Gets the attributes common to the specified range.
769 Attributes that differ in value within the range will not be included
772 virtual bool GetStyleForRange(const wxRichTextRange
& range
,
776 Returns the style sheet associated with the control, if any.
777 A style sheet allows named character and paragraph styles to be applied.
779 wxRichTextStyleSheet
* GetStyleSheet() const;
782 Gets the attributes at the given position.
783 This function gets the @e uncombined style - that is, the attributes associated
784 with the paragraph or character content, and not necessarily the combined
785 attributes you see on the screen.
786 To get the combined attributes, use GetStyle().
788 If you specify (any) paragraph attribute in @e style's flags, this function
789 will fetch the paragraph attributes.
790 Otherwise, it will return the character attributes.
792 virtual bool GetUncombinedStyle(long position
, wxTextAttr
& style
);
795 Returns the content of the entire control as a string.
797 virtual wxString
GetValue() const;
800 Internal helper function returning the line for the visible caret position.
801 If the caret is shown at the very end of the line, it means the next character
802 is actually on the following line.
803 So this function gets the line we're expecting to find if this is the case.
805 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
808 Test if this whole range has character attributes of the specified kind.
809 If any of the attributes are different within the range, the test fails.
811 You can use this to implement, for example, bold button updating.
812 @a style must have flags indicating which attributes are of interest.
814 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
,
815 const wxTextAttr
& style
) const;
818 Test if this whole range has paragraph attributes of the specified kind.
819 If any of the attributes are different within the range, the test fails.
820 You can use this to implement, for example, centering button updating.
821 @a style must have flags indicating which attributes are of interest.
823 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
,
824 const wxTextAttr
& style
) const;
827 Returns @true if there is a selection.
829 virtual bool HasSelection() const;
833 Finds the character at the given position in pixels.
834 @a pt is in device coords (not adjusted for the client area origin nor for
837 wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long* pos
) const;
838 const wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
840 wxTextCoord
* row
) const;
844 Initialises the members of the control.
849 Returns @true if the user has recently set the default style without moving
850 the caret, and therefore the UI needs to reflect the default style and not
851 the style at the caret.
853 Below is an example of code that uses this function to determine whether the UI
854 should show that the current style is bold.
856 @see SetAndShowDefaultStyle().
858 bool IsDefaultStyleShowing() const;
861 Returns @true if the control is editable.
863 virtual bool IsEditable() const;
866 Returns @true if Freeze has been called without a Thaw.
868 bool IsFrozen() const;
871 Returns @true if the buffer has been modified.
873 virtual bool IsModified() const;
876 Returns @true if the control is multiline.
878 bool IsMultiLine() const;
881 Returns @true if the given position is visible on the screen.
883 bool IsPositionVisible(long pos
) const;
886 Returns @true if all of the selection is aligned according to the specified flag.
888 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
);
891 Returns @true if all of the selection is bold.
893 virtual bool IsSelectionBold();
896 Returns @true if all of the selection is italic.
898 virtual bool IsSelectionItalics();
901 Returns @true if all of the selection is underlined.
903 virtual bool IsSelectionUnderlined();
906 Returns @true if the control is single-line.
907 Currently wxRichTextCtrl does not support single-line editing.
909 bool IsSingleLine() const;
912 Helper function implementing keyboard navigation.
914 virtual bool KeyboardNavigate(int keyCode
, int flags
);
917 Lays out the buffer, which must be done before certain operations, such as
918 setting the caret position.
919 This function should not normally be required by the application.
921 virtual bool LayoutContent(bool onlyVisibleRect
= false);
924 Inserts a line break at the current insertion point.
926 A line break forces wrapping within a paragraph, and can be introduced by
927 using this function, by appending the wxChar value @b wxRichTextLineBreakChar
928 to text content, or by typing Shift-Return.
930 virtual bool LineBreak();
933 Loads content into the control's buffer using the given type.
935 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
936 the filename extension.
938 This function looks for a suitable wxRichTextFileHandler object.
940 bool LoadFile(const wxString
& file
,
941 int type
= wxRICHTEXT_TYPE_ANY
);
944 Marks the buffer as modified.
946 virtual void MarkDirty();
949 Move the caret to the given character position.
951 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
954 Move the caret one visual step forward: this may mean setting a flag
955 and keeping the same position if we're going from the end of one line
956 to the start of the next, which may be the exact same caret position.
958 void MoveCaretBack(long oldPosition
);
961 Move the caret one visual step forward: this may mean setting a flag
962 and keeping the same position if we're going from the end of one line
963 to the start of the next, which may be the exact same caret position.
965 void MoveCaretForward(long oldPosition
);
968 Moves the caret down.
970 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
973 Moves to the end of the buffer.
975 virtual bool MoveEnd(int flags
= 0);
978 Moves to the start of the buffer.
980 virtual bool MoveHome(int flags
= 0);
985 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
990 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
993 Moves to the end of the line.
995 virtual bool MoveToLineEnd(int flags
= 0);
998 Moves to the start of the line.
1000 virtual bool MoveToLineStart(int flags
= 0);
1003 Moves to the end of the paragraph.
1005 virtual bool MoveToParagraphEnd(int flags
= 0);
1008 Moves to the start of the paragraph.
1010 virtual bool MoveToParagraphStart(int flags
= 0);
1015 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
1018 Inserts a new paragraph at the current insertion point. @see LineBreak().
1020 virtual bool Newline();
1024 Numbers the paragraphs in the given range.
1025 Pass flags to determine how the attributes are set.
1027 Either the style definition or the name of the style definition (in the current
1028 sheet) can be passed.
1030 @a flags is a bit list of the following:
1031 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1032 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1033 @a startFrom, otherwise existing attributes are used.
1034 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1035 as the level for all paragraphs, otherwise the current indentation will be used.
1037 @see SetListStyle(), PromoteList(), ClearListStyle().
1039 bool NumberList(const wxRichTextRange
& range
,
1040 const wxRichTextListStyleDefinition
* style
,
1041 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1043 int listLevel
= -1);
1044 bool Number(const wxRichTextRange
& range
,
1045 const wxString
& styleName
,
1046 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1048 int listLevel
= -1);
1052 Standard handler for the wxID_CLEAR command.
1054 void OnClear(wxCommandEvent
& event
);
1057 Shows a standard context menu with undo, redo, cut, copy, paste, clear, and
1058 select all commands.
1060 void OnContextMenu(wxContextMenuEvent
& event
);
1063 Standard handler for the wxID_COPY command.
1065 void OnCopy(wxCommandEvent
& event
);
1068 Standard handler for the wxID_CUT command.
1070 void OnCut(wxCommandEvent
& event
);
1073 Loads the first dropped file.
1075 void OnDropFiles(wxDropFilesEvent
& event
);
1078 Standard handler for the wxID_PASTE command.
1080 void OnPaste(wxCommandEvent
& event
);
1083 Standard handler for the wxID_REDO command.
1085 void OnRedo(wxCommandEvent
& event
);
1088 Standard handler for the wxID_SELECTALL command.
1090 void OnSelectAll(wxCommandEvent
& event
);
1093 Standard handler for the wxID_PASTE command.
1095 void OnUndo(wxCommandEvent
& event
);
1098 Standard update handler for the wxID_CLEAR command.
1100 void OnUpdateClear(wxUpdateUIEvent
& event
);
1103 Standard update handler for the wxID_COPY command.
1105 void OnUpdateCopy(wxUpdateUIEvent
& event
);
1108 Standard update handler for the wxID_CUT command.
1110 void OnUpdateCut(wxUpdateUIEvent
& event
);
1113 Standard update handler for the wxID_PASTE command.
1115 void OnUpdatePaste(wxUpdateUIEvent
& event
);
1118 Standard update handler for the wxID_REDO command.
1120 void OnUpdateRedo(wxUpdateUIEvent
& event
);
1123 Standard update handler for the wxID_SELECTALL command.
1125 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
1128 Standard update handler for the wxID_UNDO command.
1130 void OnUpdateUndo(wxUpdateUIEvent
& event
);
1133 Moves one or more pages down.
1135 virtual bool PageDown(int noPages
= 1, int flags
= 0);
1138 Moves one or more pages up.
1140 virtual bool PageUp(int noPages
= 1, int flags
= 0);
1143 Paints the background.
1145 virtual void PaintBackground(wxDC
& dc
);
1148 Pastes content from the clipboard to the buffer.
1150 virtual void Paste();
1153 Internal function to position the visible caret according to the current caret
1156 virtual void PositionCaret();
1159 Converts a text position to zero-based column and line numbers.
1161 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
1165 Promotes or demotes the paragraphs in the given range.
1166 A positive @a promoteBy produces a smaller indent, and a negative number
1167 produces a larger indent. Pass flags to determine how the attributes are set.
1168 Either the style definition or the name of the style definition (in the current
1169 sheet) can be passed.
1171 @a flags is a bit list of the following:
1172 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1173 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1174 @a startFrom, otherwise existing attributes are used.
1175 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1176 as the level for all paragraphs, otherwise the current indentation will be used.
1178 @see SetListStyle(), @see SetListStyle(), ClearListStyle().
1180 bool PromoteList(int promoteBy
, const wxRichTextRange
& range
,
1181 const wxRichTextListStyleDefinition
* style
,
1182 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1183 int listLevel
= -1);
1184 bool PromoteList(int promoteBy
, const wxRichTextRange
& range
,
1185 const wxString
& styleName
,
1186 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1187 int listLevel
= -1);
1191 Redoes the current command.
1193 virtual void Redo();
1196 Removes the content in the specified range.
1198 virtual void Remove(long from
, long to
);
1201 Replaces the content in the specified range with the string specified by
1204 virtual void Replace(long from
, long to
, const wxString
& value
);
1207 Saves the buffer content using the given type.
1209 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
1210 the filename extension.
1212 This function looks for a suitable wxRichTextFileHandler object.
1214 bool SaveFile(const wxString
& file
= wxEmptyString
,
1215 int type
= wxRICHTEXT_TYPE_ANY
);
1218 Scrolls @a position into view. This function takes a caret position.
1220 virtual bool ScrollIntoView(long position
, int keyCode
);
1223 Selects all the text in the buffer.
1225 virtual void SelectAll();
1228 Cancels any selection.
1230 virtual void SelectNone();
1233 Sets @a attr as the default style and tells the control that the UI should
1234 reflect this attribute until the user moves the caret.
1236 @see IsDefaultStyleShowing().
1238 void SetAndShowDefaultStyle(const wxTextAttr
& attr
);
1241 Sets the basic (overall) style.
1243 This is the style of the whole buffer before further styles are applied,
1244 unlike the default style, which only affects the style currently being
1245 applied (for example, setting the default style to bold will cause
1246 subsequently inserted text to be bold).
1248 virtual void SetBasicStyle(const wxTextAttr
& style
);
1251 The caret position is the character position just before the caret.
1252 A value of -1 means the caret is at the start of the buffer.
1254 void SetCaretPosition(long position
,
1255 bool showAtLineStart
= false);
1258 Sets the current default style, which can be used to change how subsequently
1259 inserted text is displayed.
1261 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
1264 Sets the default style to the style under the cursor.
1266 bool SetDefaultStyleToCursorStyle();
1269 Sets the size of the buffer beyond which layout is delayed during resizing.
1270 This optimizes sizing for large buffers. The default is 20000.
1272 void SetDelayedLayoutThreshold(long threshold
);
1275 Makes the control editable, or not.
1277 virtual void SetEditable(bool editable
);
1280 Sets the current filename.
1282 void SetFilename(const wxString
& filename
);
1285 Sets the font, and also the basic and default attributes
1286 (see wxRichTextCtrl::SetDefaultStyle).
1288 virtual bool SetFont(const wxFont
& font
);
1291 Sets flags that change the behaviour of loading or saving.
1293 See the documentation for each handler class to see what flags are
1294 relevant for each handler.
1296 void SetHandlerFlags(int flags
);
1299 Sets the insertion point.
1301 virtual void SetInsertionPoint(long pos
);
1304 Sets the insertion point to the end of the text control.
1306 virtual void SetInsertionPointEnd();
1310 Sets the list attributes for the given range, passing flags to determine how
1311 the attributes are set.
1313 Either the style definition or the name of the style definition (in the current
1314 sheet) can be passed.
1315 @a flags is a bit list of the following:
1316 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1317 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1318 @a startFrom, otherwise existing attributes are used.
1319 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1320 as the level for all paragraphs, otherwise the current indentation will be used.
1322 @see NumberList(), PromoteList(), ClearListStyle().
1324 bool SetListStyle(const wxRichTextRange
& range
,
1325 const wxRichTextListStyleDefinition
* style
,
1326 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1328 int listLevel
= -1);
1329 bool SetListStyle(const wxRichTextRange
& range
,
1330 const wxString
& styleName
,
1331 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1333 int listLevel
= -1);
1337 Sets the selection to the given range.
1338 The end point of range is specified as the last character position of the span
1341 So, for example, to set the selection for a character at position 5, use the
1344 virtual void SetSelection(long from
, long to
);
1347 Sets the selection to the given range.
1348 The end point of range is specified as the last character position of the span
1351 So, for example, to set the selection for a character at position 5, use the
1354 void SetSelectionRange(const wxRichTextRange
& range
);
1358 Sets the attributes for the given range.
1359 The end point of range is specified as the last character position of the span
1362 So, for example, to set the style for a character at position 5, use the range
1365 bool SetStyle(const wxRichTextRange
& range
,
1366 const wxTextAttr
& style
);
1367 bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
1372 Sets the attributes for the given range, passing flags to determine how the
1375 The end point of range is specified as the last character position of the span
1376 of text, plus one. So, for example, to set the style for a character at
1377 position 5, use the range (5,6).
1379 @a flags may contain a bit list of the following values:
1380 - wxRICHTEXT_SETSTYLE_NONE: no style flag.
1381 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
1383 - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
1384 if the combined style at this point is already the style in question.
1385 - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
1386 applied to paragraphs, and not the content.
1387 This allows content styling to be preserved independently from that
1388 of e.g. a named paragraph style.
1389 - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
1390 applied to characters, and not the paragraph.
1391 This allows content styling to be preserved independently from that
1392 of e.g. a named paragraph style.
1393 - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
1395 - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style. Only the style flags
1396 are used in this operation.
1398 bool SetStyleEx(const wxRichTextRange
& range
,
1399 const wxTextAttr
& style
,
1400 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1401 bool SetStyleEx(long start
, long end
,
1402 const wxTextAttr
& style
,
1403 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1407 Sets the style sheet associated with the control.
1408 A style sheet allows named character and paragraph styles to be applied.
1410 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1413 Replaces existing content with the given text.
1415 virtual void SetValue(const wxString
& value
);
1418 A helper function setting up scrollbars, for example after a resize.
1420 virtual void SetupScrollbars(bool atTop
= false);
1423 Scrolls the buffer so that the given position is in view.
1425 virtual void ShowPosition(long pos
);
1428 Returns @true if undo history suppression is on.
1430 virtual bool SuppressingUndo() const;
1433 Call this function to end a Freeze and refresh the display.
1438 Undoes the command at the top of the command history, if there is one.
1440 virtual void Undo();
1443 Moves a number of words to the left.
1445 virtual bool WordLeft(int noWords
= 1, int flags
= 0);
1448 Move a nuber of words to the right.
1450 virtual bool WordRight(int noWords
= 1, int flags
= 0);
1453 Loads an image from a file and writes it at the current insertion point.
1455 virtual bool WriteImage(const wxString
& filename
, wxBitmapType bitmapType
);
1458 Writes an image block at the current insertion point.
1460 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
);
1464 Write a bitmap or image at the current insertion point.
1465 Supply an optional type to use for internal and file storage of the raw data.
1467 bool WriteImage(const wxBitmap
& bitmap
,
1468 int bitmapType
= wxBITMAP_TYPE_PNG
);
1469 bool WriteImage(const wxImage
& image
,
1470 int bitmapType
= wxBITMAP_TYPE_PNG
);
1474 Writes text at the current position.
1476 virtual void WriteText(const wxString
& text
);
1479 Translates from column and line number to position.
1481 virtual long XYToPosition(long x
, long y
) const;
1486 Currently this simply returns @c wxSize(10, 10).
1488 virtual wxSize
DoGetBestSize() const;
1491 Initialises the command event.
1493 void InitCommandEvent(wxCommandEvent
& event
) const;