wxRichTextCtrl provides a generic, ground-up implementation of a text control capable of showing multiple styles and images.
wxRichTextCtrl sends notification events: see wxRichTextEvent. It also sends the standard wxTextCtrl events wxEVT_COMMAND_TEXT_ENTER and wxEVT_COMMAND_TEXT_UPDATED, and wxTextUrlEvent when URL content is clicked.
For more information, see the wxRichTextCtrl overview.
Derived from
wxTextCtrlBase
Include files
<wx/richtext/richtextctrl.h>
Data structures
Members
wxRichTextCtrl::wxRichTextCtrl
wxRichTextCtrl::~wxRichTextCtrl
wxRichTextCtrl::AddImage
wxRichTextCtrl::AddParagraph
wxRichTextCtrl::AppendText
wxRichTextCtrl::ApplyAlignmentToSelection
wxRichTextCtrl::ApplyBoldToSelection
wxRichTextCtrl::ApplyItalicToSelection
wxRichTextCtrl::ApplyStyle
wxRichTextCtrl::ApplyStyleSheet
wxRichTextCtrl::ApplyUnderlineToSelection
wxRichTextCtrl::BatchingUndo
wxRichTextCtrl::BeginAlignment
wxRichTextCtrl::BeginBatchUndo
wxRichTextCtrl::BeginBold
wxRichTextCtrl::BeginCharacterStyle
wxRichTextCtrl::BeginFont
wxRichTextCtrl::BeginFontSize
wxRichTextCtrl::BeginItalic
wxRichTextCtrl::BeginLeftIndent
wxRichTextCtrl::BeginLineSpacing
wxRichTextCtrl::BeginListStyle
wxRichTextCtrl::BeginNumberedBullet
wxRichTextCtrl::BeginParagraphSpacing
wxRichTextCtrl::BeginParagraphStyle
wxRichTextCtrl::BeginRightIndent
wxRichTextCtrl::BeginStyle
wxRichTextCtrl::BeginSuppressUndo
wxRichTextCtrl::BeginSymbolBullet
wxRichTextCtrl::BeginTextColour
wxRichTextCtrl::BeginUnderline
wxRichTextCtrl::BeginURL
wxRichTextCtrl::CanCopy
wxRichTextCtrl::CanCut
wxRichTextCtrl::CanDeleteSelection
wxRichTextCtrl::CanPaste
wxRichTextCtrl::CanRedo
wxRichTextCtrl::CanUndo
wxRichTextCtrl::Clear
wxRichTextCtrl::ClearListStyle
wxRichTextCtrl::Command
wxRichTextCtrl::Copy
wxRichTextCtrl::Create
wxRichTextCtrl::Cut
wxRichTextCtrl::Delete
wxRichTextCtrl::DeleteSelectedContent
wxRichTextCtrl::DeleteSelection
wxRichTextCtrl::DiscardEdits
wxRichTextCtrl::DoGetBestSize
wxRichTextCtrl::EndAlignment
wxRichTextCtrl::EndAllStyles
wxRichTextCtrl::EndBatchUndo
wxRichTextCtrl::EndBold
wxRichTextCtrl::EndCharacterStyle
wxRichTextCtrl::EndFont
wxRichTextCtrl::EndFontSize
wxRichTextCtrl::EndItalic
wxRichTextCtrl::EndLeftIndent
wxRichTextCtrl::EndLineSpacing
wxRichTextCtrl::EndListStyle
wxRichTextCtrl::EndNumberedBullet
wxRichTextCtrl::EndParagraphSpacing
wxRichTextCtrl::EndParagraphStyle
wxRichTextCtrl::EndRightIndent
wxRichTextCtrl::EndStyle
wxRichTextCtrl::EndSuppressUndo
wxRichTextCtrl::EndSymbolBullet
wxRichTextCtrl::EndTextColour
wxRichTextCtrl::EndUnderline
wxRichTextCtrl::EndURL
wxRichTextCtrl::ExtendSelection
wxRichTextCtrl::FindNextWordPosition
wxRichTextCtrl::Freeze
wxRichTextCtrl::GetBasicStyle
wxRichTextCtrl::GetBuffer
wxRichTextCtrl::GetCaretPosition
wxRichTextCtrl::GetCaretPositionForIndex
wxRichTextCtrl::GetCommandProcessor
wxRichTextCtrl::GetDefaultStyleEx
wxRichTextCtrl::GetDelayedLayoutThreshold
wxRichTextCtrl::GetFilename
wxRichTextCtrl::GetFirstVisiblePosition
wxRichTextCtrl::GetHandlerFlags
wxRichTextCtrl::GetInsertionPoint
wxRichTextCtrl::GetLastPosition
wxRichTextCtrl::GetLineLength
wxRichTextCtrl::GetLineText
wxRichTextCtrl::GetLogicalPoint
wxRichTextCtrl::GetNumberOfLines
wxRichTextCtrl::GetPhysicalPoint
wxRichTextCtrl::GetRange
wxRichTextCtrl::GetSelection
wxRichTextCtrl::GetSelectionRange
wxRichTextCtrl::GetStringSelection
wxRichTextCtrl::GetStyle
wxRichTextCtrl::GetStyleForRange
wxRichTextCtrl::GetStyleSheet
wxRichTextCtrl::GetUncombinedStyle
wxRichTextCtrl::GetValue
wxRichTextCtrl::GetVisibleLineForCaretPosition
wxRichTextCtrl::HasCharacterAttributes
wxRichTextCtrl::HasParagraphAttributes
wxRichTextCtrl::HasSelection
wxRichTextCtrl::HitTest
wxRichTextCtrl::Init
wxRichTextCtrl::InitCommandEvent
wxRichTextCtrl::IsDefaultStyleShowing
wxRichTextCtrl::IsEditable
wxRichTextCtrl::IsFrozen
wxRichTextCtrl::IsModified
wxRichTextCtrl::IsMultiLine
wxRichTextCtrl::IsPositionVisible
wxRichTextCtrl::IsSelectionAligned
wxRichTextCtrl::IsSelectionBold
wxRichTextCtrl::IsSelectionItalics
wxRichTextCtrl::IsSelectionUnderlined
wxRichTextCtrl::IsSingleLine
wxRichTextCtrl::KeyboardNavigate
wxRichTextCtrl::LayoutContent
wxRichTextCtrl::LineBreak
wxRichTextCtrl::LoadFile
wxRichTextCtrl::MarkDirty
wxRichTextCtrl::MoveCaret
wxRichTextCtrl::MoveCaretBack
wxRichTextCtrl::MoveCaretForward
wxRichTextCtrl::MoveDown
wxRichTextCtrl::MoveEnd
wxRichTextCtrl::MoveHome
wxRichTextCtrl::MoveLeft
wxRichTextCtrl::MoveRight
wxRichTextCtrl::MoveToLineEnd
wxRichTextCtrl::MoveToLineStart
wxRichTextCtrl::MoveToParagraphEnd
wxRichTextCtrl::MoveToParagraphStart
wxRichTextCtrl::MoveUp
wxRichTextCtrl::Newline
wxRichTextCtrl::NumberList
wxRichTextCtrl::OnClear
wxRichTextCtrl::OnContextMenu
wxRichTextCtrl::OnCopy
wxRichTextCtrl::OnCut
wxRichTextCtrl::OnDropFiles
wxRichTextCtrl::OnPaste
wxRichTextCtrl::OnRedo
wxRichTextCtrl::OnSelectAll
wxRichTextCtrl::OnUndo
wxRichTextCtrl::OnUpdateClear
wxRichTextCtrl::OnUpdateCopy
wxRichTextCtrl::OnUpdateCut
wxRichTextCtrl::OnUpdatePaste
wxRichTextCtrl::OnUpdateRedo
wxRichTextCtrl::OnUpdateSelectAll
wxRichTextCtrl::OnUpdateUndo
wxRichTextCtrl::PageDown
wxRichTextCtrl::PageUp
wxRichTextCtrl::PaintBackground
wxRichTextCtrl::Paste
wxRichTextCtrl::PositionCaret
wxRichTextCtrl::PositionToXY
wxRichTextCtrl::PromoteList
wxRichTextCtrl::Redo
wxRichTextCtrl::Remove
wxRichTextCtrl::Replace
wxRichTextCtrl::SaveFile
wxRichTextCtrl::ScrollIntoView
wxRichTextCtrl::SelectAll
wxRichTextCtrl::SelectNone
wxRichTextCtrl::SetAndShowDefaultStyle
wxRichTextCtrl::SetBasicStyle
wxRichTextCtrl::SetCaretPosition
wxRichTextCtrl::SetDefaultStyle
wxRichTextCtrl::SetDefaultStyleToCursorStyle
wxRichTextCtrl::SetDelayedLayoutThreshold
wxRichTextCtrl::SetEditable
wxRichTextCtrl::SetFilename
wxRichTextCtrl::SetFont
wxRichTextCtrl::SetHandlerFlags
wxRichTextCtrl::SetInsertionPoint
wxRichTextCtrl::SetInsertionPointEnd
wxRichTextCtrl::SetListStyle
wxRichTextCtrl::SetSelection
wxRichTextCtrl::SetSelectionRange
wxRichTextCtrl::SetStyle
wxRichTextCtrl::SetStyleEx
wxRichTextCtrl::SetStyleSheet
wxRichTextCtrl::SetValue
wxRichTextCtrl::SetupScrollbars
wxRichTextCtrl::ShowPosition
wxRichTextCtrl::SuppressingUndo
wxRichTextCtrl::Thaw
wxRichTextCtrl::Undo
wxRichTextCtrl::WordLeft
wxRichTextCtrl::WordRight
wxRichTextCtrl::WriteImage
wxRichTextCtrl::WriteText
wxRichTextCtrl::XYToPosition
wxRichTextCtrl()
wxRichTextCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr)
Constructors.
~wxRichTextCtrl()
Destructor.
wxRichTextRange AddImage(const wxImage& image)
Adds an image to the control's buffer.
wxRichTextRange AddParagraph(const wxString& text)
Adds a new paragraph of text to the end of the buffer.
void AppendText(const wxString& text)
Sets the insertion point to the end of the buffer and writes the text.
bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment)
Applies the given alignment to the selection (undoable).
For alignment values, see wxTextAttrEx.
bool ApplyBoldToSelection()
Apples bold to the selection (undoable).
bool ApplyItalicToSelection()
Applies italic to the selection (undoable).
bool ApplyStyle(wxRichTextStyleDefinition* def)
Applies the given style to the selection.
bool ApplyStyleSheet(wxRichTextStyleSheet* sheet = NULL)
Applies the style sheet to the buffer, matching paragraph styles in the sheet against named styles in the buffer. This might be useful if the styles have changed. If sheet is NULL, the sheet set with SetStyleSheet is used.
Currently this applies paragraph styles only.
bool ApplyUnderlineToSelection()
Applies underline to the selection (undoable).
bool BatchingUndo() const
Returns true if undo commands are being batched.
bool BeginAlignment(wxTextAttrAlignment alignment)
Begins using alignment
For alignment values, see wxTextAttrEx.
bool BeginBatchUndo(const wxString& cmdName)
Starts batching undo history for commands.
bool BeginBold()
Begins using bold.
bool BeginCharacterStyle(const wxString& characterStyle)
Begins using the named character style.
bool BeginFont(const wxFont& font)
Begins using this font.
bool BeginFontSize(int pointSize)
Begins using the given point size.
bool BeginItalic()
Begins using italic.
bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0)
Begins applying a left indent and subindent in tenths of a millimetre.
The sub-indent is an offset from the left of the paragraph, and is used for all but the first line in a paragraph. A positive value will cause the first line to appear to the left of the subsequent lines, and a negative value will cause the first line to be indented relative to the subsequent lines.
wxRichTextBuffer uses indentation to render a bulleted item. The left indent is the distance between the margin and the bullet. The content of the paragraph, including the first line, starts at leftMargin + leftSubIndent. So the distance between the left edge of the bullet and the left of the actual paragraph is leftSubIndent.
bool BeginLineSpacing(int lineSpacing)
Begins appling line spacing. spacing is a multiple, where 10 means single-spacing, 15 means 1.5 spacing, and 20 means double spacing. The following constants are defined for convenience:
#define wxTEXT_ATTR_LINE_SPACING_NORMAL 10
#define wxTEXT_ATTR_LINE_SPACING_HALF 15
#define wxTEXT_ATTR_LINE_SPACING_TWICE 20
bool BeginListStyle(const wxString& listStyle, int level=1, int number=1)
Begins using a specified list style. Optionally, you can also pass a level and a number.
bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD)
Begins a numbered bullet. This call will be needed for each item in the list, and the application should take care of incrementing the numbering.
bulletNumber is a number, usually starting with 1.
leftIndent and leftSubIndent are values in tenths of a millimetre.
bulletStyle is a bitlist of the following values:
#define wxTEXT_ATTR_BULLET_STYLE_NONE 0x00000000
#define wxTEXT_ATTR_BULLET_STYLE_ARABIC 0x00000001
#define wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER 0x00000002
#define wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER 0x00000004
#define wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER 0x00000008
#define wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER 0x00000010
#define wxTEXT_ATTR_BULLET_STYLE_SYMBOL 0x00000020
#define wxTEXT_ATTR_BULLET_STYLE_BITMAP 0x00000040
#define wxTEXT_ATTR_BULLET_STYLE_PARENTHESES 0x00000080
#define wxTEXT_ATTR_BULLET_STYLE_PERIOD 0x00000100
#define wxTEXT_ATTR_BULLET_STYLE_STANDARD 0x00000200
#define wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS 0x00000400
#define wxTEXT_ATTR_BULLET_STYLE_OUTLINE 0x00000800
#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT 0x00000000
#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT 0x00001000
#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE 0x00002000
wxRichTextBuffer uses indentation to render a bulleted item. The left indent is the distance between the margin and the bullet. The content of the paragraph, including the first line, starts at leftMargin + leftSubIndent. So the distance between the left edge of the bullet and the left of the actual paragraph is leftSubIndent.
bool BeginParagraphSpacing(int before, int after)
Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing in tenths of a millimetre.
bool BeginParagraphStyle(const wxString& paragraphStyle)
Begins applying the named paragraph style.
bool BeginRightIndent(int rightIndent)
Begins a right indent, specified in tenths of a millimetre.
bool BeginStyle(const wxTextAttrEx& style)
Begins applying a style.
bool BeginSuppressUndo()
Starts suppressing undo history for commands.
bool BeginSymbolBullet(wxChar symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL)
Begins applying a symbol bullet, using a character from the current font. See BeginNumberedBullet for an explanation of how indentation is used to render the bulleted paragraph.
bool BeginTextColour(const wxColour& colour)
Begins using this colour.
bool BeginUnderline()
Begins using underlining.
bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString)
Begins applying wxTEXT_ATTR_URL to the content. Pass a URL and optionally, a character style to apply, since it is common to mark a URL with a familiar style such as blue text with underlining.
bool CanCopy() const
Returns true if selected content can be copied to the clipboard.
bool CanCut() const
Returns true if selected content can be copied to the clipboard and deleted.
bool CanDeleteSelection() const
Returns true if selected content can be deleted.
bool CanPaste() const
Returns true if the clipboard content can be pasted to the buffer.
bool CanRedo() const
Returns true if there is a command in the command history that can be redone.
bool CanUndo() const
Returns true if there is a command in the command history that can be undone.
void Clear()
Clears the buffer content, leaving a single empty paragraph. Cannot be undone.
bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO)
bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO)
Clears the list style from the given range, clearing list-related attributes and applying any named paragraph style associated with each paragraph.
flags is a bit list of the following:
See also wxRichTextCtrl::SetListStyle, wxRichTextCtrl::PromoteList, wxRichTextCtrl::NumberList.
void Command(wxCommandEvent& event)
Sends the event to the control.
void Copy()
Copies the selected content (if any) to the clipboard.
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr)
Creates the underlying window.
void Cut()
Copies the selected content (if any) to the clipboard and deletes the selection. This is undoable.
bool Delete(const wxRichTextRange& range)
Deletes the content within the given range.
bool DeleteSelectedContent(long* newPos = NULL)
Deletes content if there is a selection, e.g. when pressing a key. Returns the new caret position in newPos, or leaves it if there was no action. This is undoable.
void DeleteSelection()
Deletes the content in the selection, if any. This is undoable.
void DiscardEdits()
Sets the buffer's modified status to false, and clears the buffer's command history.
wxSize DoGetBestSize() const
Currently this simply returns wxSize(10, 10).
bool EndAlignment()
Ends alignment.
bool EndAllStyles()
Ends application of all styles in the current style stack.
bool EndBatchUndo()
Ends batching undo command history.
bool EndBold()
Ends using bold.
bool EndCharacterStyle()
Ends application of a named character style.
bool EndFont()
Ends using a font.
bool EndFontSize()
Ends using a point size.
bool EndItalic()
Ends using italic.
bool EndLeftIndent()
Ends left indent.
bool EndLineSpacing()
Ends line spacing.
bool EndListStyle()
Ends using a specified list style.
bool EndNumberedBullet()
Ends application of a numbered bullet.
bool EndParagraphSpacing()
Ends paragraph spacing.
bool EndParagraphStyle()
Ends application of a named character style.
bool EndRightIndent()
Ends right indent.
bool EndStyle()
Ends the current style.
bool EndSuppressUndo()
Ends suppressing undo command history.
bool EndSymbolBullet()
Ends applying a symbol bullet.
bool EndTextColour()
Ends applying a text colour.
bool EndUnderline()
End applying underlining.
bool EndURL()
Ends applying a URL.
bool ExtendSelection(long oldPosition, long newPosition, int flags)
Helper function for extending the selection, returning true if the selection was changed. Selections are in caret positions.
long FindNextWordPosition(int direction = 1) const
Helper function for finding the caret position for the next word. Direction is 1 (forward) or -1 (backwards).
void Freeze()
Call this function to prevent refresh and allow fast updates, and then Thaw to refresh the control.
const wxTextAttrEx& GetBasicStyle() const
Gets the basic (overall) style. This is the style of the whole buffer before further styles are applied, unlike the default style, which only affects the style currently being applied (for example, setting the default style to bold will cause subsequently inserted text to be bold).
const wxRichTextBuffer& GetBuffer() const
wxRichTextBuffer& GetBuffer()
Returns the buffer associated with the control.
long GetCaretPosition() const
Returns the current caret position.
bool GetCaretPositionForIndex(long position, wxRect& rect)
Returns the caret height and position for the given character position
wxCommandProcessor* GetCommandProcessor() const
Gets the command processor associated with the control's buffer.
const wxTextAttrEx& GetDefaultStyleEx() const
Returns the current default style, which can be used to change how subsequently inserted text is displayed. When wxTextAttrEx is merged with wxTextAttr, this function will become GetDefaultStyle.
long GetDelayedLayoutThreshold() const
Gets the size of the buffer beyond which layout is delayed during resizing. This optimizes sizing for large buffers. The default is 20000.
wxString GetFilename() const
Gets the current filename associated with the control.
long GetFirstVisiblePosition() const
Returns the first visible position in the current view.
int GetHandlerFlags() const
Returns flags that change the behaviour of loading or saving. See the documentation for each handler class to see what flags are relevant for each handler.
long GetInsertionPoint() const
Returns the current insertion point.
wxTextPos GetLastPosition() const
Returns the last position in the buffer.
int GetLineLength(long lineNo) const
Returns the length of the specified line in characters.
wxString GetLineText(long lineNo) const
Returns the text for the given line.
wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const
Transforms physical window position to logical (unscrolled) position.
int GetNumberOfLines() const
Returns the number of lines in the buffer.
wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const
Transforms logical (unscrolled) position to physical window position.
wxString GetRange(long from, long to) const
Gets the text for the given range.
The end point of range is specified as the last character position of the span of text, plus one.
void GetSelection(long* from, long* to) const
Returns the range of the current selection.
The end point of range is specified as the last character position of the span of text, plus one.
If the return values from and to are the same, there is no selection.
const wxRichTextRange& GetSelectionRange() const
Returns the selection range in character positions. -1, -1 means no selection.
wxString GetStringSelection() const
Returns the text within the current selection range, if any.
bool GetStyle(long position, wxRichTextAttr& style)
bool GetStyle(long position, wxTextAttrEx& style)
bool GetStyle(long position, wxTextAttr& style)
Gets the attributes at the given position. The wxRichTextAttr version is generally more efficient because it does not use wxFont objects.
This function gets the combined style - that is, the style you see on the screen as a result of combining base style, paragraph style and character style attributes. To get the character or paragraph style alone, use GetUncombinedStyle.
bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style)
bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style)
Gets the attributes common to the specified range. Attributes that differ in value within the range will not be included in style's flags.
wxRichTextStyleSheet* GetStyleSheet() const
Returns the style sheet associated with the control, if any. A style sheet allows named character and paragraph styles to be applied.
bool GetUncombinedStyle(long position, wxRichTextAttr& style)
bool GetUncombinedStyle(long position, wxTextAttrEx& style)
bool GetUncombinedStyle(long position, wxTextAttr& style)
Gets the attributes at the given position. The wxRichTextAttr version is generally more efficient because it does not use wxFont objects.
This function gets the uncombined style - that is, the attributes associated with the paragraph or character content, and not necessarily the combined attributes you see on the screen. To get the combined attributes, use GetStyle.
If you specify (any) paragraph attribute in style's flags, this function will fetch the paragraph attributes. Otherwise, it will return the character attributes.
wxString GetValue() const
Returns the content of the entire control as a string.
wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const
Internal helper function returning the line for the visible caret position. If the caret is shown at the very end of the line, it means the next character is actually on the following line. So this function gets the line we're expecting to find if this is the case.
bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
Test if this whole range has character attributes of the specified kind. If any of the attributes are different within the range, the test fails. You can use this to implement, for example, bold button updating. style must have flags indicating which attributes are of interest.
bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
Test if this whole range has paragraph attributes of the specified kind. If any of the attributes are different within the range, the test fails. You can use this to implement, for example, centering button updating. style must have flags indicating which attributes are of interest.
bool HasSelection() const
Returns true if there is a selection.
wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long* pos) const
wxTextCtrlHitTestResult HitTest(const wxPoint& pt, wxTextCoord* col, wxTextCoord* row) const
Finds the character at the given position in pixels.
pt is in device coords (not adjusted for the client area origin nor for scrolling).
void Init()
Initialises the members of the control.
void InitCommandEvent(wxCommandEvent& event) const
Initialises the command event.
bool IsDefaultStyleShowing() const
Returns true if the user has recently set the default style without moving the caret, and therefore the UI needs to reflect the default style and not the style at the caret.
Below is an example of code that uses this function to determine whether the UI should show that the current style is bold.
/// Is all of the selection bold? bool wxRichTextCtrl::IsSelectionBold() { if (HasSelection()) { wxRichTextAttr attr; wxRichTextRange range = GetInternalSelectionRange(); attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); attr.SetFontWeight(wxBOLD); return HasCharacterAttributes(range, attr); } else { // If no selection, then we need to combine current style with default style // to see what the effect would be if we started typing. wxRichTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); long pos = GetAdjustedCaretPosition(GetCaretPosition()); if (GetStyle(pos, attr)) { if (IsDefaultStyleShowing()) wxRichTextApplyStyle(attr, GetDefaultStyleEx()); return attr.GetFontWeight() == wxBOLD; } } return false; }See also SetAndShowDefaultStyle.
bool IsEditable() const
Returns true if the control is editable.
bool IsFrozen() const
Returns true if Freeze has been called without a Thaw.
bool IsModified() const
Returns true if the buffer has been modified.
bool IsMultiLine() const
Returns true if the control is multiline.
bool IsPositionVisible(long pos) const
Returns true if the given position is visible on the screen.
bool IsSelectionAligned(wxTextAttrAlignment alignment) const
Returns true if all of the selection is aligned according to the specified flag.
bool IsSelectionBold() const
Returns true if all of the selection is bold.
bool IsSelectionItalics() const
Returns true if all of the selection is italic.
bool IsSelectionUnderlined() const
Returns true if all of the selection is underlined.
bool IsSingleLine() const
Returns true if the control is single-line. Currently wxRichTextCtrl does not support single-line editing.
bool KeyboardNavigate(int keyCode, int flags)
Helper function implementing keyboard navigation.
bool LayoutContent(bool onlyVisibleRect = false)
Lays out the buffer, which must be done before certain operations, such as setting the caret position. This function should not normally be required by the application.
bool LineBreak()
Inserts a line break at the current insertion point. A line break forces wrapping within a paragraph, and can be introduced by using this function, by appending the wxChar value wxRichTextLineBreakChar to text content, or by typing Shift-Return.
bool LoadFile(const wxString& file, int type = wxRICHTEXT_TYPE_ANY)
Loads content into the control's buffer using the given type. If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from the filename extension.
This function looks for a suitable wxRichTextFileHandler object.
void MarkDirty()
Marks the buffer as modified.
bool MoveCaret(long pos, bool showAtLineStart = false)
Move the caret to the given character position.
void MoveCaretBack(long oldPosition)
Move the caret one visual step forward: this may mean setting a flag and keeping the same position if we're going from the end of one line to the start of the next, which may be the exact same caret position.
void MoveCaretForward(long oldPosition)
Move the caret one visual step forward: this may mean setting a flag and keeping the same position if we're going from the end of one line to the start of the next, which may be the exact same caret position.
bool MoveDown(int noLines = 1, int flags = 0)
Moves the caret down.
bool MoveEnd(int flags = 0)
Moves to the end of the buffer.
bool MoveHome(int flags = 0)
Moves to the start of the buffer.
bool MoveLeft(int noPositions = 1, int flags = 0)
Moves left.
bool MoveRight(int noPositions = 1, int flags = 0)
Moves right.
bool MoveToLineEnd(int flags = 0)
Moves to the end of the line.
bool MoveToLineStart(int flags = 0)
Moves to the start of the line.
bool MoveToParagraphEnd(int flags = 0)
Moves to the end of the paragraph.
bool MoveToParagraphStart(int flags = 0)
Moves to the start of the paragraph.
bool MoveUp(int noLines = 1, int flags = 0)
Moves up.
bool Newline()
Inserts a new paragraph at the current insertion point. See also wxRichTextCtrl::LineBreak.
bool NumberList(const wxRichTextRange& range, const wxRichTextListStyleDefinition* style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = -1, int listLevel = -1)
bool Number(const wxRichTextRange& range, const wxString& styleName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = -1, int listLevel = -1)
Numbers the paragraphs in the given range. Pass flags to determine how the attributes are set. Either the style definition or the name of the style definition (in the current sheet) can be passed.
flags is a bit list of the following:
See also wxRichTextCtrl::SetListStyle, wxRichTextCtrl::PromoteList, wxRichTextCtrl::ClearListStyle.
void OnClear(wxCommandEvent& event)
Standard handler for the wxID_CLEAR command.
void OnContextMenu(wxContextMenuEvent& event)
Shows a standard context menu with undo, redo, cut, copy, paste, clear, and select all commands.
void OnCopy(wxCommandEvent& event)
Standard handler for the wxID_COPY command.
void OnCut(wxCommandEvent& event)
Standard handler for the wxID_CUT command.
void OnDropFiles(wxDropFilesEvent& event)
Loads the first dropped file.
void OnPaste(wxCommandEvent& event)
Standard handler for the wxID_PASTE command.
void OnRedo(wxCommandEvent& event)
Standard handler for the wxID_REDO command.
void OnSelectAll(wxCommandEvent& event)
Standard handler for the wxID_SELECTALL command.
void OnUndo(wxCommandEvent& event)
Standard handler for the wxID_PASTE command.
void OnUpdateClear(wxUpdateUIEvent& event)
Standard update handler for the wxID_CLEAR command.
void OnUpdateCopy(wxUpdateUIEvent& event)
Standard update handler for the wxID_COPY command.
void OnUpdateCut(wxUpdateUIEvent& event)
Standard update handler for the wxID_CUT command.
void OnUpdatePaste(wxUpdateUIEvent& event)
Standard update handler for the wxID_PASTE command.
void OnUpdateRedo(wxUpdateUIEvent& event)
Standard update handler for the wxID_REDO command.
void OnUpdateSelectAll(wxUpdateUIEvent& event)
Standard update handler for the wxID_SELECTALL command.
void OnUpdateUndo(wxUpdateUIEvent& event)
Standard update handler for the wxID_UNDO command.
bool PageDown(int noPages = 1, int flags = 0)
Moves one or more pages down.
bool PageUp(int noPages = 1, int flags = 0)
Moves one or more pages up.
void PaintBackground(wxDC& dc)
Paints the background.
void Paste()
Pastes content from the clipboard to the buffer.
void PositionCaret()
Internal function to position the visible caret according to the current caret position.
bool PositionToXY(long pos, long* x, long* y) const
Converts a text position to zero-based column and line numbers.
bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxRichTextListStyleDefinition* style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int listLevel = -1)
bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& styleName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int listLevel = -1)
Promotes or demotes the paragraphs in the given range. A positive promoteBy produces a smaller indent, and a negative number produces a larger indent. Pass flags to determine how the attributes are set. Either the style definition or the name of the style definition (in the current sheet) can be passed.
flags is a bit list of the following:
See also wxRichTextCtrl::SetListStyle, See also wxRichTextCtrl::SetListStyle, wxRichTextCtrl::ClearListStyle.
void Redo()
Redoes the current command.
void Remove(long from, long to)
Removes the content in the specified range.
void Replace(long from, long to, const wxString& value)
Replaces the content in the specified range with the string specified by value.
bool SaveFile(const wxString& file = wxEmptyString, int type = wxRICHTEXT_TYPE_ANY)
Saves the buffer content using the given type. If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from the filename extension.
This function looks for a suitable wxRichTextFileHandler object.
bool ScrollIntoView(long position, int keyCode)
Scrolls position into view. This function takes a caret position.
void SelectAll()
Selects all the text in the buffer.
void SelectNone()
Cancels any selection.
void SetAndShowDefaultStyle(const wxRichTextAttr& attr)
Sets attr as the default style and tells the control that the UI should reflect this attribute until the user moves the caret.
See also IsDefaultStyleShowing.
void SetBasicStyle(const wxRichTextAttr& style)
void SetBasicStyle(const wxTextAttrEx& style)
Sets the basic (overall) style. This is the style of the whole buffer before further styles are applied, unlike the default style, which only affects the style currently being applied (for example, setting the default style to bold will cause subsequently inserted text to be bold).
void SetCaretPosition(long position, bool showAtLineStart = false)
The caret position is the character position just before the caret. A value of -1 means the caret is at the start of the buffer.
bool SetDefaultStyle(const wxTextAttrEx& style)
Sets the current default style, which can be used to change how subsequently inserted text is displayed.
bool SetDefaultStyleToCursorStyle()
Sets the default style to the style under the cursor.
void SetDelayedLayoutThreshold(long threshold)
Sets the size of the buffer beyond which layout is delayed during resizing. This optimizes sizing for large buffers. The default is 20000.
void SetEditable(bool editable)
Makes the control editable, or not.
void SetFilename(const wxString& filename)
Sets the current filename.
bool SetFont(const wxFont& font)
Sets the font, and also the basic and default attributes (see SetDefaultStyle).
void SetHandlerFlags(int flags)
Sets flags that change the behaviour of loading or saving. See the documentation for each handler class to see what flags are relevant for each handler.
void SetInsertionPoint(long pos)
Sets the insertion point.
void SetInsertionPointEnd()
Sets the insertion point to the end of the text control.
bool SetListStyle(const wxRichTextRange& range, const wxRichTextListStyleDefinition* style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = -1, int listLevel = -1)
bool SetListStyle(const wxRichTextRange& range, const wxString& styleName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = -1, int listLevel = -1)
Sets the list attributes for the given range, passing flags to determine how the attributes are set. Either the style definition or the name of the style definition (in the current sheet) can be passed.
flags is a bit list of the following:
See also wxRichTextCtrl::NumberList, wxRichTextCtrl::PromoteList, wxRichTextCtrl::ClearListStyle.
void SetSelection(long from, long to)
Sets the selection to the given range.
The end point of range is specified as the last character position of the span of text, plus one. So, for example, to set the selection for a character at position 5, use the range (5,6).
void SetSelectionRange(const wxRichTextRange& range)
Sets the selection to the given range.
The end point of range is specified as the last character position of the span of text, plus one. So, for example, to set the selection for a character at position 5, use the range (5,6).
bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style)
bool SetStyle(long start, long end, const wxTextAttrEx& style)
bool SetStyle(long start, long end, const wxTextAttr& style)
Sets the attributes for the given range. The wxRichTextAttr version is more efficient because it does not use wxFont objects.
The end point of range is specified as the last character position of the span of text, plus one. So, for example, to set the style for a character at position 5, use the range (5,6).
bool SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO)
bool SetStyleEx(const wxRichTextRange& range, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO)
bool SetStyleEx(long start, long end, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO)
Sets the attributes for the given range, passing flags to determine how the attributes are set. The wxRichTextAttr version is more efficient because it does not use wxFont objects.
The end point of range is specified as the last character position of the span of text, plus one. So, for example, to set the style for a character at position 5, use the range (5,6).
flags may contain a bit list of the following values:
void SetStyleSheet(wxRichTextStyleSheet* styleSheet)
Sets the style sheet associated with the control. A style sheet allows named character and paragraph styles to be applied.
void SetValue(const wxString& value)
Replaces existing content with the given text.
void SetupScrollbars(bool atTop = false)
A helper function setting up scrollbars, for example after a resize.
void ShowPosition(long pos)
Scrolls the buffer so that the given position is in view.
bool SuppressingUndo() const
Returns true if undo history suppression is on.
void Thaw()
Call this function to end a Freeze and refresh the display.
void Undo()
Undoes the command at the top of the command history, if there is one.
bool WordLeft(int noWords = 1, int flags = 0)
Moves a number of words to the left.
bool WordRight(int noWords = 1, int flags = 0)
Move a nuber of words to the right.
bool WriteImage(const wxString& filename, int bitmapType)
Loads an image from a file and writes it at the current insertion point.
bool WriteImage(const wxRichTextImageBlock& imageBlock)
Writes an image block at the current insertion point.
bool WriteImage(const wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG)
bool WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG)
Write a bitmap or image at the current insertion point. Supply an optional type to use for internal and file storage of the raw data.
void WriteText(const wxString& text)
Writes text at the current position.
long XYToPosition(long x, long y) const
Translates from column and line number to position.