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);
79 wxEvent
* Clone() const;
82 Returns the character pressed, within a wxEVT_COMMAND_RICHTEXT_CHARACTER event.
84 wxChar
GetCharacter() const;
87 Returns flags indicating modifier keys pressed.
89 Possible values are wxRICHTEXT_CTRL_DOWN, wxRICHTEXT_SHIFT_DOWN, and wxRICHTEXT_ALT_DOWN.
94 Returns the new style sheet.
96 Can be used in a wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
97 wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
99 wxRichTextStyleSheet
* GetNewStyleSheet() const;
102 Returns the old style sheet.
104 Can be used in a wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
105 wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
107 wxRichTextStyleSheet
* GetOldStyleSheet() const;
110 Returns the buffer position at which the event occured.
112 long GetPosition() const;
115 Gets the range for the current operation.
117 const wxRichTextRange
& GetRange() const;
120 Sets the character variable.
122 void SetCharacter(wxChar ch
);
125 Sets flags indicating modifier keys pressed.
127 Possible values are wxRICHTEXT_CTRL_DOWN, wxRICHTEXT_SHIFT_DOWN, and wxRICHTEXT_ALT_DOWN.
129 void SetFlags(int flags
);
132 Sets the new style sheet variable.
134 void SetNewStyleSheet(wxRichTextStyleSheet
* sheet
);
137 Sets the old style sheet variable.
139 void SetOldStyleSheet(wxRichTextStyleSheet
* sheet
);
142 Sets the buffer position variable.
144 void SetPosition(long pos
);
147 Sets the range variable.
149 void SetRange(const wxRichTextRange
& range
);
155 @class wxRichTextCtrl
157 wxRichTextCtrl provides a generic, ground-up implementation of a text control
158 capable of showing multiple styles and images.
160 wxRichTextCtrl sends notification events: see wxRichTextEvent.
162 It also sends the standard wxTextCtrl events wxEVT_COMMAND_TEXT_ENTER and
163 wxEVT_COMMAND_TEXT_UPDATED, and wxTextUrlEvent when URL content is clicked.
165 For more information, see the @ref overview_richtextctrl.
179 Constructor, creating and showing a rich text control.
182 Parent window. Must not be @NULL.
184 Window identifier. The value @c wxID_ANY indicates a default value.
198 @see Create(), wxValidator
200 wxRichTextCtrl(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
201 const wxString
& value
= wxEmptyString
,
202 const wxPoint
& pos
= wxDefaultPosition
,
203 const wxSize
& size
= wxDefaultSize
,
204 long style
= wxRE_MULTILINE
,
205 const wxValidator
& validator
= wxDefaultValidator
,
206 const wxString
& name
= wxTextCtrlNameStr
);
211 virtual ~wxRichTextCtrl();
214 Adds an image to the control's buffer.
216 virtual wxRichTextRange
AddImage(const wxImage
& image
);
219 Adds a new paragraph of text to the end of the buffer.
221 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
224 Sets the insertion point to the end of the buffer and writes the text.
226 virtual void AppendText(const wxString
& text
);
229 Applies the given alignment to the selection (undoable).
230 For alignment values, see wxTextAttr.
232 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
235 Apples bold to the selection (undoable).
237 virtual bool ApplyBoldToSelection();
240 Applies italic to the selection (undoable).
242 virtual bool ApplyItalicToSelection();
245 Applies the given style to the selection.
247 virtual bool ApplyStyle(wxRichTextStyleDefinition
* def
);
250 Applies the style sheet to the buffer, matching paragraph styles in the sheet
251 against named styles in the buffer.
253 This might be useful if the styles have changed.
254 If @a sheet is @NULL, the sheet set with SetStyleSheet() is used.
255 Currently this applies paragraph styles only.
257 bool ApplyStyleSheet(wxRichTextStyleSheet
* sheet
= NULL
);
260 Applies underline to the selection (undoable).
262 virtual bool ApplyUnderlineToSelection();
265 Returns @true if undo commands are being batched.
267 virtual bool BatchingUndo() const;
270 Begins using alignment.
271 For alignment values, see wxTextAttr.
273 bool BeginAlignment(wxTextAttrAlignment alignment
);
276 Starts batching undo history for commands.
278 virtual bool BeginBatchUndo(const wxString
& cmdName
);
286 Begins using the named character style.
288 bool BeginCharacterStyle(const wxString
& characterStyle
);
291 Begins using this font.
293 bool BeginFont(const wxFont
& font
);
296 Begins using the given point size.
298 bool BeginFontSize(int pointSize
);
306 Begins applying a left indent and subindent in tenths of a millimetre.
307 The subindent is an offset from the left edge of the paragraph, and is
308 used for all but the first line in a paragraph. A positive value will
309 cause the first line to appear to the left of the subsequent lines, and
310 a negative value will cause the first line to be indented to the right
311 of the subsequent lines.
313 wxRichTextBuffer uses indentation to render a bulleted item. The
314 content of the paragraph, including the first line, starts at the
315 @a leftIndent plus the @a leftSubIndent.
318 The distance between the margin and the bullet.
320 The distance between the left edge of the bullet and the left edge
321 of the actual paragraph.
323 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
326 Begins appling line spacing. @e spacing is a multiple, where 10 means
327 single-spacing, 15 means 1.5 spacing, and 20 means double spacing.
329 The ::wxTextAttrLineSpacing constants are defined for convenience.
331 bool BeginLineSpacing(int lineSpacing
);
334 Begins using a specified list style.
335 Optionally, you can also pass a level and a number.
337 bool BeginListStyle(const wxString
& listStyle
, int level
= 1,
341 Begins a numbered bullet.
343 This call will be needed for each item in the list, and the
344 application should take care of incrementing the numbering.
346 @a bulletNumber is a number, usually starting with 1.
347 @a leftIndent and @a leftSubIndent are values in tenths of a millimetre.
348 @a bulletStyle is a bitlist of the ::wxTextAttrBulletStyle values.
350 wxRichTextBuffer uses indentation to render a bulleted item.
351 The left indent is the distance between the margin and the bullet.
352 The content of the paragraph, including the first line, starts
353 at leftMargin + leftSubIndent.
354 So the distance between the left edge of the bullet and the
355 left of the actual paragraph is leftSubIndent.
357 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
,
359 int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
362 Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing
363 in tenths of a millimetre.
365 bool BeginParagraphSpacing(int before
, int after
);
368 Begins applying the named paragraph style.
370 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
373 Begins a right indent, specified in tenths of a millimetre.
375 bool BeginRightIndent(int rightIndent
);
378 Begins applying a style.
380 virtual bool BeginStyle(const wxTextAttr
& style
);
383 Starts suppressing undo history for commands.
385 virtual bool BeginSuppressUndo();
388 Begins applying a symbol bullet, using a character from the current font.
389 See BeginNumberedBullet() for an explanation of how indentation is used
390 to render the bulleted paragraph.
392 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
,
394 int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
397 Begins using this colour.
399 bool BeginTextColour(const wxColour
& colour
);
402 Begins applying wxTEXT_ATTR_URL to the content.
404 Pass a URL and optionally, a character style to apply, since it is common
405 to mark a URL with a familiar style such as blue text with underlining.
407 bool BeginURL(const wxString
& url
,
408 const wxString
& characterStyle
= wxEmptyString
);
411 Begins using underlining.
413 bool BeginUnderline();
416 Returns @true if selected content can be copied to the clipboard.
418 virtual bool CanCopy() const;
421 Returns @true if selected content can be copied to the clipboard and deleted.
423 virtual bool CanCut() const;
426 Returns @true if selected content can be deleted.
428 virtual bool CanDeleteSelection() const;
431 Returns @true if the clipboard content can be pasted to the buffer.
433 virtual bool CanPaste() const;
436 Returns @true if there is a command in the command history that can be redone.
438 virtual bool CanRedo() const;
441 Returns @true if there is a command in the command history that can be undone.
443 virtual bool CanUndo() const;
446 Clears the buffer content, leaving a single empty paragraph. Cannot be undone.
448 virtual void Clear();
452 Clears the list style from the given range, clearing list-related attributes
453 and applying any named paragraph style associated with each paragraph.
455 @a flags is a bit list of the following:
456 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
458 @see SetListStyle(), PromoteList(), NumberList().
460 bool ClearListStyle(const wxRichTextRange
& range
,
461 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
462 bool ClearListStyle(const wxRichTextRange
& range
,
463 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
467 Sends the event to the control.
469 virtual void Command(wxCommandEvent
& event
);
472 Copies the selected content (if any) to the clipboard.
477 Creates the underlying window.
479 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
480 const wxString
& value
= wxEmptyString
,
481 const wxPoint
& pos
= wxDefaultPosition
,
482 const wxSize
& size
= wxDefaultSize
,
483 long style
= wxRE_MULTILINE
,
484 const wxValidator
& validator
= wxDefaultValidator
,
485 const wxString
& name
= wxTextCtrlNameStr
);
488 Copies the selected content (if any) to the clipboard and deletes the selection.
494 Deletes the content within the given range.
496 virtual bool Delete(const wxRichTextRange
& range
);
499 Deletes content if there is a selection, e.g. when pressing a key.
500 Returns the new caret position in @e newPos, or leaves it if there
501 was no action. This is undoable.
503 bool DeleteSelectedContent(long* newPos
= NULL
);
506 Deletes the content in the selection, if any. This is undoable.
508 virtual void DeleteSelection();
511 Sets the buffer's modified status to @false, and clears the buffer's command
514 virtual void DiscardEdits();
522 Ends application of all styles in the current style stack.
524 virtual bool EndAllStyles();
527 Ends batching undo command history.
529 virtual bool EndBatchUndo();
537 Ends application of a named character style.
539 bool EndCharacterStyle();
547 Ends using a point size.
559 bool EndLeftIndent();
564 bool EndLineSpacing();
567 Ends using a specified list style.
572 Ends application of a numbered bullet.
574 bool EndNumberedBullet();
577 Ends paragraph spacing.
579 bool EndParagraphSpacing();
582 Ends application of a named character style.
584 bool EndParagraphStyle();
589 bool EndRightIndent();
592 Ends the current style.
594 virtual bool EndStyle();
597 Ends suppressing undo command history.
599 virtual bool EndSuppressUndo();
602 Ends applying a symbol bullet.
604 bool EndSymbolBullet();
607 Ends applying a text colour.
609 bool EndTextColour();
617 End applying underlining.
622 Helper function for extending the selection, returning @true if the selection
623 was changed. Selections are in caret positions.
625 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
628 Helper function for finding the caret position for the next word.
629 Direction is 1 (forward) or -1 (backwards).
631 virtual long FindNextWordPosition(int direction
= 1) const;
634 Call this function to prevent refresh and allow fast updates, and then Thaw() to
640 Gets the basic (overall) style.
642 This is the style of the whole buffer before further styles are applied,
643 unlike the default style, which only affects the style currently being
644 applied (for example, setting the default style to bold will cause
645 subsequently inserted text to be bold).
647 virtual const wxTextAttr
& GetBasicStyle() const;
651 Returns the buffer associated with the control.
653 const wxRichTextBuffer
GetBuffer();
654 const wxRichTextBuffer
& GetBuffer();
658 Returns the current caret position.
660 long GetCaretPosition() const;
663 Returns the caret height and position for the given character position.
665 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
668 Gets the command processor associated with the control's buffer.
670 wxCommandProcessor
* GetCommandProcessor() const;
673 Returns the current default style, which can be used to change how subsequently
674 inserted text is displayed.
676 virtual const wxTextAttr
& GetDefaultStyle() const;
679 Gets the size of the buffer beyond which layout is delayed during resizing.
680 This optimizes sizing for large buffers. The default is 20000.
682 long GetDelayedLayoutThreshold() const;
685 Gets the current filename associated with the control.
687 wxString
GetFilename() const;
690 Returns the first visible position in the current view.
692 long GetFirstVisiblePosition() const;
695 Returns flags that change the behaviour of loading or saving.
696 See the documentation for each handler class to see what flags are
697 relevant for each handler.
699 int GetHandlerFlags() const;
702 Returns the current insertion point.
704 virtual long GetInsertionPoint() const;
707 Returns the last position in the buffer.
709 virtual wxTextPos
GetLastPosition() const;
712 Returns the length of the specified line in characters.
714 virtual int GetLineLength(long lineNo
) const;
717 Returns the text for the given line.
719 virtual wxString
GetLineText(long lineNo
) const;
722 Transforms physical window position to logical (unscrolled) position.
724 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
727 Returns the number of lines in the buffer.
729 virtual int GetNumberOfLines() const;
732 Transforms logical (unscrolled) position to physical window position.
734 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
737 Gets the text for the given range.
738 The end point of range is specified as the last character position of
739 the span of text, plus one.
741 virtual wxString
GetRange(long from
, long to
) const;
744 Returns the range of the current selection.
745 The end point of range is specified as the last character position of the span
747 If the return values @a from and @a to are the same, there is no selection.
749 virtual void GetSelection(long* from
, long* to
) const;
752 Returns the selection range in character positions. -1, -1 means no selection.
754 wxRichTextRange
GetSelectionRange() const;
757 Returns the text within the current selection range, if any.
759 virtual wxString
GetStringSelection() const;
762 Gets the attributes at the given position.
763 This function gets the combined style - that is, the style you see on the
764 screen as a result of combining base style, paragraph style and character
767 To get the character or paragraph style alone, use GetUncombinedStyle().
769 virtual bool GetStyle(long position
, wxTextAttr
& style
);
772 Gets the attributes common to the specified range.
773 Attributes that differ in value within the range will not be included
776 virtual bool GetStyleForRange(const wxRichTextRange
& range
,
780 Returns the style sheet associated with the control, if any.
781 A style sheet allows named character and paragraph styles to be applied.
783 wxRichTextStyleSheet
* GetStyleSheet() const;
786 Gets the attributes at the given position.
787 This function gets the @e uncombined style - that is, the attributes associated
788 with the paragraph or character content, and not necessarily the combined
789 attributes you see on the screen.
790 To get the combined attributes, use GetStyle().
792 If you specify (any) paragraph attribute in @e style's flags, this function
793 will fetch the paragraph attributes.
794 Otherwise, it will return the character attributes.
796 virtual bool GetUncombinedStyle(long position
, wxTextAttr
& style
);
799 Returns the content of the entire control as a string.
801 virtual wxString
GetValue() const;
804 Internal helper function returning the line for the visible caret position.
805 If the caret is shown at the very end of the line, it means the next character
806 is actually on the following line.
807 So this function gets the line we're expecting to find if this is the case.
809 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
812 Test if this whole range has character attributes of the specified kind.
813 If any of the attributes are different within the range, the test fails.
815 You can use this to implement, for example, bold button updating.
816 @a style must have flags indicating which attributes are of interest.
818 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
,
819 const wxTextAttr
& style
) const;
822 Test if this whole range has paragraph attributes of the specified kind.
823 If any of the attributes are different within the range, the test fails.
824 You can use this to implement, for example, centering button updating.
825 @a style must have flags indicating which attributes are of interest.
827 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
,
828 const wxTextAttr
& style
) const;
831 Returns @true if there is a selection.
833 virtual bool HasSelection() const;
837 Finds the character at the given position in pixels.
838 @a pt is in device coords (not adjusted for the client area origin nor for
841 wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long* pos
) const;
842 const wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
844 wxTextCoord
* row
) const;
848 Initialises the members of the control.
853 Returns @true if the user has recently set the default style without moving
854 the caret, and therefore the UI needs to reflect the default style and not
855 the style at the caret.
857 Below is an example of code that uses this function to determine whether the UI
858 should show that the current style is bold.
860 @see SetAndShowDefaultStyle().
862 bool IsDefaultStyleShowing() const;
865 Returns @true if the control is editable.
867 virtual bool IsEditable() const;
870 Returns @true if Freeze has been called without a Thaw.
872 bool IsFrozen() const;
875 Returns @true if the buffer has been modified.
877 virtual bool IsModified() const;
880 Returns @true if the control is multiline.
882 bool IsMultiLine() const;
885 Returns @true if the given position is visible on the screen.
887 bool IsPositionVisible(long pos
) const;
890 Returns @true if all of the selection is aligned according to the specified flag.
892 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
);
895 Returns @true if all of the selection is bold.
897 virtual bool IsSelectionBold();
900 Returns @true if all of the selection is italic.
902 virtual bool IsSelectionItalics();
905 Returns @true if all of the selection is underlined.
907 virtual bool IsSelectionUnderlined();
910 Returns @true if the control is single-line.
911 Currently wxRichTextCtrl does not support single-line editing.
913 bool IsSingleLine() const;
916 Helper function implementing keyboard navigation.
918 virtual bool KeyboardNavigate(int keyCode
, int flags
);
921 Lays out the buffer, which must be done before certain operations, such as
922 setting the caret position.
923 This function should not normally be required by the application.
925 virtual bool LayoutContent(bool onlyVisibleRect
= false);
928 Inserts a line break at the current insertion point.
930 A line break forces wrapping within a paragraph, and can be introduced by
931 using this function, by appending the wxChar value @b wxRichTextLineBreakChar
932 to text content, or by typing Shift-Return.
934 virtual bool LineBreak();
937 Loads content into the control's buffer using the given type.
939 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
940 the filename extension.
942 This function looks for a suitable wxRichTextFileHandler object.
944 bool LoadFile(const wxString
& file
,
945 int type
= wxRICHTEXT_TYPE_ANY
);
948 Marks the buffer as modified.
950 virtual void MarkDirty();
953 Move the caret to the given character position.
955 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
958 Move the caret one visual step forward: this may mean setting a flag
959 and keeping the same position if we're going from the end of one line
960 to the start of the next, which may be the exact same caret position.
962 void MoveCaretBack(long oldPosition
);
965 Move the caret one visual step forward: this may mean setting a flag
966 and keeping the same position if we're going from the end of one line
967 to the start of the next, which may be the exact same caret position.
969 void MoveCaretForward(long oldPosition
);
972 Moves the caret down.
974 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
977 Moves to the end of the buffer.
979 virtual bool MoveEnd(int flags
= 0);
982 Moves to the start of the buffer.
984 virtual bool MoveHome(int flags
= 0);
989 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
994 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
997 Moves to the end of the line.
999 virtual bool MoveToLineEnd(int flags
= 0);
1002 Moves to the start of the line.
1004 virtual bool MoveToLineStart(int flags
= 0);
1007 Moves to the end of the paragraph.
1009 virtual bool MoveToParagraphEnd(int flags
= 0);
1012 Moves to the start of the paragraph.
1014 virtual bool MoveToParagraphStart(int flags
= 0);
1019 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
1022 Inserts a new paragraph at the current insertion point. @see LineBreak().
1024 virtual bool Newline();
1028 Numbers the paragraphs in the given range.
1029 Pass flags to determine how the attributes are set.
1031 Either the style definition or the name of the style definition (in the current
1032 sheet) can be passed.
1034 @a flags is a bit list of the following:
1035 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1036 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1037 @a startFrom, otherwise existing attributes are used.
1038 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1039 as the level for all paragraphs, otherwise the current indentation will be used.
1041 @see SetListStyle(), PromoteList(), ClearListStyle().
1043 bool NumberList(const wxRichTextRange
& range
,
1044 const wxRichTextListStyleDefinition
* style
,
1045 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1047 int listLevel
= -1);
1048 bool Number(const wxRichTextRange
& range
,
1049 const wxString
& styleName
,
1050 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1052 int listLevel
= -1);
1056 Standard handler for the wxID_CLEAR command.
1058 void OnClear(wxCommandEvent
& event
);
1061 Shows a standard context menu with undo, redo, cut, copy, paste, clear, and
1062 select all commands.
1064 void OnContextMenu(wxContextMenuEvent
& event
);
1067 Standard handler for the wxID_COPY command.
1069 void OnCopy(wxCommandEvent
& event
);
1072 Standard handler for the wxID_CUT command.
1074 void OnCut(wxCommandEvent
& event
);
1077 Loads the first dropped file.
1079 void OnDropFiles(wxDropFilesEvent
& event
);
1082 Standard handler for the wxID_PASTE command.
1084 void OnPaste(wxCommandEvent
& event
);
1087 Standard handler for the wxID_REDO command.
1089 void OnRedo(wxCommandEvent
& event
);
1092 Standard handler for the wxID_SELECTALL command.
1094 void OnSelectAll(wxCommandEvent
& event
);
1097 Standard handler for the wxID_PASTE command.
1099 void OnUndo(wxCommandEvent
& event
);
1102 Standard update handler for the wxID_CLEAR command.
1104 void OnUpdateClear(wxUpdateUIEvent
& event
);
1107 Standard update handler for the wxID_COPY command.
1109 void OnUpdateCopy(wxUpdateUIEvent
& event
);
1112 Standard update handler for the wxID_CUT command.
1114 void OnUpdateCut(wxUpdateUIEvent
& event
);
1117 Standard update handler for the wxID_PASTE command.
1119 void OnUpdatePaste(wxUpdateUIEvent
& event
);
1122 Standard update handler for the wxID_REDO command.
1124 void OnUpdateRedo(wxUpdateUIEvent
& event
);
1127 Standard update handler for the wxID_SELECTALL command.
1129 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
1132 Standard update handler for the wxID_UNDO command.
1134 void OnUpdateUndo(wxUpdateUIEvent
& event
);
1137 Moves one or more pages down.
1139 virtual bool PageDown(int noPages
= 1, int flags
= 0);
1142 Moves one or more pages up.
1144 virtual bool PageUp(int noPages
= 1, int flags
= 0);
1147 Paints the background.
1149 virtual void PaintBackground(wxDC
& dc
);
1152 Pastes content from the clipboard to the buffer.
1154 virtual void Paste();
1157 Internal function to position the visible caret according to the current caret
1160 virtual void PositionCaret();
1163 Converts a text position to zero-based column and line numbers.
1165 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
1169 Promotes or demotes the paragraphs in the given range.
1170 A positive @a promoteBy produces a smaller indent, and a negative number
1171 produces a larger indent. Pass flags to determine how the attributes are set.
1172 Either the style definition or the name of the style definition (in the current
1173 sheet) can be passed.
1175 @a flags is a bit list of the following:
1176 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1177 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1178 @a startFrom, otherwise existing attributes are used.
1179 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1180 as the level for all paragraphs, otherwise the current indentation will be used.
1182 @see SetListStyle(), @see SetListStyle(), ClearListStyle().
1184 bool PromoteList(int promoteBy
, const wxRichTextRange
& range
,
1185 const wxRichTextListStyleDefinition
* style
,
1186 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1187 int listLevel
= -1);
1188 bool PromoteList(int promoteBy
, const wxRichTextRange
& range
,
1189 const wxString
& styleName
,
1190 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1191 int listLevel
= -1);
1195 Redoes the current command.
1197 virtual void Redo();
1200 Removes the content in the specified range.
1202 virtual void Remove(long from
, long to
);
1205 Replaces the content in the specified range with the string specified by
1208 virtual void Replace(long from
, long to
, const wxString
& value
);
1211 Saves the buffer content using the given type.
1213 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
1214 the filename extension.
1216 This function looks for a suitable wxRichTextFileHandler object.
1218 bool SaveFile(const wxString
& file
= wxEmptyString
,
1219 int type
= wxRICHTEXT_TYPE_ANY
);
1222 Scrolls @a position into view. This function takes a caret position.
1224 virtual bool ScrollIntoView(long position
, int keyCode
);
1227 Selects all the text in the buffer.
1229 virtual void SelectAll();
1232 Cancels any selection.
1234 virtual void SelectNone();
1237 Sets @a attr as the default style and tells the control that the UI should
1238 reflect this attribute until the user moves the caret.
1240 @see IsDefaultStyleShowing().
1242 void SetAndShowDefaultStyle(const wxTextAttr
& attr
);
1245 Sets the basic (overall) style.
1247 This is the style of the whole buffer before further styles are applied,
1248 unlike the default style, which only affects the style currently being
1249 applied (for example, setting the default style to bold will cause
1250 subsequently inserted text to be bold).
1252 virtual void SetBasicStyle(const wxTextAttr
& style
);
1255 The caret position is the character position just before the caret.
1256 A value of -1 means the caret is at the start of the buffer.
1258 void SetCaretPosition(long position
,
1259 bool showAtLineStart
= false);
1262 Sets the current default style, which can be used to change how subsequently
1263 inserted text is displayed.
1265 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
1268 Sets the default style to the style under the cursor.
1270 bool SetDefaultStyleToCursorStyle();
1273 Sets the size of the buffer beyond which layout is delayed during resizing.
1274 This optimizes sizing for large buffers. The default is 20000.
1276 void SetDelayedLayoutThreshold(long threshold
);
1279 Makes the control editable, or not.
1281 virtual void SetEditable(bool editable
);
1284 Sets the current filename.
1286 void SetFilename(const wxString
& filename
);
1289 Sets the font, and also the basic and default attributes
1290 (see wxRichTextCtrl::SetDefaultStyle).
1292 virtual bool SetFont(const wxFont
& font
);
1295 Sets flags that change the behaviour of loading or saving.
1297 See the documentation for each handler class to see what flags are
1298 relevant for each handler.
1300 void SetHandlerFlags(int flags
);
1303 Sets the insertion point.
1305 virtual void SetInsertionPoint(long pos
);
1308 Sets the insertion point to the end of the text control.
1310 virtual void SetInsertionPointEnd();
1314 Sets the list attributes for the given range, passing flags to determine how
1315 the attributes are set.
1317 Either the style definition or the name of the style definition (in the current
1318 sheet) can be passed.
1319 @a flags is a bit list of the following:
1320 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
1321 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
1322 @a startFrom, otherwise existing attributes are used.
1323 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
1324 as the level for all paragraphs, otherwise the current indentation will be used.
1326 @see NumberList(), PromoteList(), ClearListStyle().
1328 bool SetListStyle(const wxRichTextRange
& range
,
1329 const wxRichTextListStyleDefinition
* style
,
1330 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1332 int listLevel
= -1);
1333 bool SetListStyle(const wxRichTextRange
& range
,
1334 const wxString
& styleName
,
1335 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
1337 int listLevel
= -1);
1341 Sets the selection to the given range.
1342 The end point of range is specified as the last character position of the span
1345 So, for example, to set the selection for a character at position 5, use the
1348 virtual void SetSelection(long from
, long to
);
1351 Sets the selection to the given range.
1352 The end point of range is specified as the last character position of the span
1355 So, for example, to set the selection for a character at position 5, use the
1358 void SetSelectionRange(const wxRichTextRange
& range
);
1362 Sets the attributes for the given range.
1363 The end point of range is specified as the last character position of the span
1366 So, for example, to set the style for a character at position 5, use the range
1369 bool SetStyle(const wxRichTextRange
& range
,
1370 const wxTextAttr
& style
);
1371 bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
1376 Sets the attributes for the given range, passing flags to determine how the
1379 The end point of range is specified as the last character position of the span
1380 of text, plus one. So, for example, to set the style for a character at
1381 position 5, use the range (5,6).
1383 @a flags may contain a bit list of the following values:
1384 - wxRICHTEXT_SETSTYLE_NONE: no style flag.
1385 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
1387 - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
1388 if the combined style at this point is already the style in question.
1389 - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
1390 applied to paragraphs, and not the content.
1391 This allows content styling to be preserved independently from that
1392 of e.g. a named paragraph style.
1393 - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
1394 applied to characters, and not the paragraph.
1395 This allows content styling to be preserved independently from that
1396 of e.g. a named paragraph style.
1397 - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
1399 - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style. Only the style flags
1400 are used in this operation.
1402 bool SetStyleEx(const wxRichTextRange
& range
,
1403 const wxTextAttr
& style
,
1404 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1405 bool SetStyleEx(long start
, long end
,
1406 const wxTextAttr
& style
,
1407 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1411 Sets the style sheet associated with the control.
1412 A style sheet allows named character and paragraph styles to be applied.
1414 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1417 Replaces existing content with the given text.
1419 virtual void SetValue(const wxString
& value
);
1422 A helper function setting up scrollbars, for example after a resize.
1424 virtual void SetupScrollbars(bool atTop
= false);
1427 Scrolls the buffer so that the given position is in view.
1429 virtual void ShowPosition(long pos
);
1432 Returns @true if undo history suppression is on.
1434 virtual bool SuppressingUndo() const;
1437 Call this function to end a Freeze and refresh the display.
1442 Undoes the command at the top of the command history, if there is one.
1444 virtual void Undo();
1447 Moves a number of words to the left.
1449 virtual bool WordLeft(int noWords
= 1, int flags
= 0);
1452 Move a nuber of words to the right.
1454 virtual bool WordRight(int noWords
= 1, int flags
= 0);
1457 Loads an image from a file and writes it at the current insertion point.
1459 virtual bool WriteImage(const wxString
& filename
, wxBitmapType bitmapType
);
1462 Writes an image block at the current insertion point.
1464 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
);
1468 Write a bitmap or image at the current insertion point.
1469 Supply an optional type to use for internal and file storage of the raw data.
1471 bool WriteImage(const wxBitmap
& bitmap
,
1472 int bitmapType
= wxBITMAP_TYPE_PNG
);
1473 bool WriteImage(const wxImage
& image
,
1474 int bitmapType
= wxBITMAP_TYPE_PNG
);
1478 Writes text at the current position.
1480 virtual void WriteText(const wxString
& text
);
1483 Translates from column and line number to position.
1485 virtual long XYToPosition(long x
, long y
) const;
1490 Currently this simply returns @c wxSize(10, 10).
1492 virtual wxSize
DoGetBestSize() const;
1495 Initialises the command event.
1497 void InitCommandEvent(wxCommandEvent
& event
) const;