+ double GetFontScale() const { return GetBuffer().GetFontScale(); }
+
+ /**
+ Sets the scale factor for displaying certain dimensions such as indentation and
+ inter-paragraph spacing. This can be useful when editing in a small control
+ where you still want legible text, but a minimum of wasted white space.
+ */
+ void SetDimensionScale(double dimScale, bool refresh = false);
+
+ /**
+ Returns the scale factor for displaying certain dimensions such as indentation
+ and inter-paragraph spacing.
+ */
+ double GetDimensionScale() const { return GetBuffer().GetDimensionScale(); }
+
+ /**
+ Sets an overall scale factor for displaying and editing the content.
+ */
+ void SetScale(double scale, bool refresh = false);
+
+ /**
+ Returns an overall scale factor for displaying and editing the content.
+ */
+ double GetScale() const;
+
+ /**
+ Returns an unscaled point.
+ */
+ wxPoint GetUnscaledPoint(const wxPoint& pt) const;
+
+ /**
+ Returns a scaled point.
+ */
+ wxPoint GetScaledPoint(const wxPoint& pt) const;
+
+ /**
+ Returns an unscaled size.
+ */
+ wxSize GetUnscaledSize(const wxSize& sz) const;
+
+ /**
+ Returns a scaled size.
+ */
+ wxSize GetScaledSize(const wxSize& sz) const;
+
+ /**
+ Returns an unscaled rectangle.
+ */
+ wxRect GetUnscaledRect(const wxRect& rect) const;
+
+ /**
+ Returns a scaled rectangle.
+ */
+ wxRect GetScaledRect(const wxRect& rect) const;
+
+ /**
+ Returns @true if this control can use virtual attributes and virtual text.
+ The default is @false.
+ */
+ bool GetVirtualAttributesEnabled() const;
+
+ /**
+ Pass @true to let the control use virtual attributes.
+ The default is @false.
+ */
+ void EnableVirtualAttributes(bool b);
+
+// Command handlers
+
+ /**
+ Sends the event to the control.
+ */
+ void Command(wxCommandEvent& event);
+
+ /**
+ Loads the first dropped file.
+ */
+ void OnDropFiles(wxDropFilesEvent& event);
+
+ void OnCaptureLost(wxMouseCaptureLostEvent& event);
+ void OnSysColourChanged(wxSysColourChangedEvent& event);
+
+ /**
+ Standard handler for the wxID_CUT command.
+ */
+ void OnCut(wxCommandEvent& event);
+
+ /**
+ Standard handler for the wxID_COPY command.
+ */
+ void OnCopy(wxCommandEvent& event);
+
+ /**
+ Standard handler for the wxID_PASTE command.
+ */
+ void OnPaste(wxCommandEvent& event);
+
+ /**
+ Standard handler for the wxID_UNDO command.
+ */
+ void OnUndo(wxCommandEvent& event);
+
+ /**
+ Standard handler for the wxID_REDO command.
+ */
+ void OnRedo(wxCommandEvent& event);
+
+ /**
+ Standard handler for the wxID_SELECTALL command.
+ */
+ void OnSelectAll(wxCommandEvent& event);
+
+ /**
+ Standard handler for property commands.
+ */
+ void OnProperties(wxCommandEvent& event);
+
+ /**
+ Standard handler for the wxID_CLEAR command.
+ */
+ void OnClear(wxCommandEvent& event);
+
+ /**
+ Standard update handler for the wxID_CUT command.
+ */
+ void OnUpdateCut(wxUpdateUIEvent& event);
+
+ /**
+ Standard update handler for the wxID_COPY command.
+ */
+ void OnUpdateCopy(wxUpdateUIEvent& event);
+
+ /**
+ Standard update handler for the wxID_PASTE command.
+ */
+ void OnUpdatePaste(wxUpdateUIEvent& event);
+
+ /**
+ Standard update handler for the wxID_UNDO command.
+ */
+ void OnUpdateUndo(wxUpdateUIEvent& event);
+
+ /**
+ Standard update handler for the wxID_REDO command.
+ */
+ void OnUpdateRedo(wxUpdateUIEvent& event);
+
+ /**
+ Standard update handler for the wxID_SELECTALL command.
+ */
+ void OnUpdateSelectAll(wxUpdateUIEvent& event);
+
+ /**
+ Standard update handler for property commands.
+ */
+
+ void OnUpdateProperties(wxUpdateUIEvent& event);
+
+ /**
+ Standard update handler for the wxID_CLEAR command.
+ */
+ void OnUpdateClear(wxUpdateUIEvent& event);
+
+ /**
+ Shows a standard context menu with undo, redo, cut, copy, paste, clear, and
+ select all commands.
+ */
+ void OnContextMenu(wxContextMenuEvent& event);
+
+// Event handlers
+
+ // Painting
+ void OnPaint(wxPaintEvent& event);
+ void OnEraseBackground(wxEraseEvent& event);
+
+ // Left-click
+ void OnLeftClick(wxMouseEvent& event);
+
+ // Left-up
+ void OnLeftUp(wxMouseEvent& event);
+
+ // Motion
+ void OnMoveMouse(wxMouseEvent& event);
+
+ // Left-double-click
+ void OnLeftDClick(wxMouseEvent& event);
+
+ // Middle-click
+ void OnMiddleClick(wxMouseEvent& event);
+
+ // Right-click
+ void OnRightClick(wxMouseEvent& event);
+
+ // Key press
+ void OnChar(wxKeyEvent& event);
+
+ // Sizing
+ void OnSize(wxSizeEvent& event);
+
+ // Setting/losing focus
+ void OnSetFocus(wxFocusEvent& event);
+ void OnKillFocus(wxFocusEvent& event);
+
+ // Idle-time processing
+ void OnIdle(wxIdleEvent& event);
+
+ // Scrolling
+ void OnScroll(wxScrollWinEvent& event);
+
+ /**
+ Sets the font, and also the basic and default attributes
+ (see wxRichTextCtrl::SetDefaultStyle).
+ */
+ virtual bool SetFont(const wxFont& font);
+
+ /**
+ A helper function setting up scrollbars, for example after a resize.
+ */
+ virtual void SetupScrollbars(bool atTop = false);
+
+ /**
+ Helper function implementing keyboard navigation.
+ */
+ virtual bool KeyboardNavigate(int keyCode, int flags);
+
+ /**
+ Paints the background.
+ */
+ virtual void PaintBackground(wxDC& dc);
+
+ /**
+ Other user defined painting after everything else (i.e.\ all text) is painted.
+
+ @since 2.9.1
+ */
+ virtual void PaintAboveContent(wxDC& WXUNUSED(dc)) {}
+
+#if wxRICHTEXT_BUFFERED_PAINTING
+ /**
+ Recreates the buffer bitmap if necessary.
+ */
+ virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
+#endif
+
+ // Write text
+ virtual void DoWriteText(const wxString& value, int flags = 0);
+
+ // Should we inherit colours?
+ virtual bool ShouldInheritColours() const;
+
+ /**
+ Internal function to position the visible caret according to the current caret
+ position.
+ */
+ virtual void PositionCaret(wxRichTextParagraphLayoutBox* container = NULL);
+
+ /**
+ Helper function for extending the selection, returning @true if the selection
+ was changed. Selections are in caret positions.
+ */
+ virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
+
+ /**
+ Scrolls @a position into view. This function takes a caret position.
+ */
+ virtual bool ScrollIntoView(long position, int keyCode);
+
+ /**
+ Refreshes the area affected by a selection change.
+ */
+ bool RefreshForSelectionChange(const wxRichTextSelection& oldSelection, const wxRichTextSelection& newSelection);
+
+ /**
+ Sets the caret position.
+
+ 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.
+ Please note that this does not update the current editing style
+ from the new position or cause the actual caret to be refreshed; to do that,
+ call wxRichTextCtrl::SetInsertionPoint instead.
+ */
+ void SetCaretPosition(long position, bool showAtLineStart = false) ;
+
+ /**
+ Returns the current caret position.
+ */
+ long GetCaretPosition() const;
+
+ /**
+ The adjusted caret position is the character position adjusted to take
+ into account whether we're at the start of a paragraph, in which case
+ style information should be taken from the next position, not current one.
+ */
+ long GetAdjustedCaretPosition(long caretPos) const;
+
+ /**
+ 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.
+ */
+ void MoveCaretBack(long oldPosition) ;
+
+ /**
+ Returns the caret height and position for the given character position.
+ If container is null, the current focus object will be used.
+
+ @beginWxPerlOnly
+ In wxPerl this method is implemented as
+ GetCaretPositionForIndex(@a position) returning a
+ 2-element list (ok, rect).
+ @endWxPerlOnly
+ */
+ bool GetCaretPositionForIndex(long position, wxRect& rect, wxRichTextParagraphLayoutBox* container = NULL);
+
+ /**
+ 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.
+ */
+ wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
+
+ /**
+ Gets the command processor associated with the control's buffer.
+ */
+ wxCommandProcessor* GetCommandProcessor() const;
+
+ /**
+ Deletes content if there is a selection, e.g. when pressing a key.
+ Returns the new caret position in @e newPos, or leaves it if there
+ was no action. This is undoable.
+
+ @beginWxPerlOnly
+ In wxPerl this method takes no arguments and returns a 2-element
+ list (ok, newPos).
+ @endWxPerlOnly
+ */
+ bool DeleteSelectedContent(long* newPos= NULL);
+
+ /**
+ Transforms logical (unscrolled) position to physical window position.
+ */
+ wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
+
+ /**
+ Transforms physical window position to logical (unscrolled) position.
+ */
+ wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
+
+ /**
+ Helper function for finding the caret position for the next word.
+ Direction is 1 (forward) or -1 (backwards).
+ */
+ virtual long FindNextWordPosition(int direction = 1) const;
+
+ /**
+ Returns @true if the given position is visible on the screen.
+ */
+ bool IsPositionVisible(long pos) const;
+
+ /**
+ Returns the first visible position in the current view.
+ */
+ long GetFirstVisiblePosition() const;
+
+ /**
+ Returns the caret position since the default formatting was changed. As
+ soon as this position changes, we no longer reflect the default style
+ in the UI. A value of -2 means that we should only reflect the style of the
+ content under the caret.
+ */
+ long GetCaretPositionForDefaultStyle() const;
+
+ /**
+ Set the caret position for the default style that the user is selecting.
+ */
+ void SetCaretPositionForDefaultStyle(long pos);
+
+ /**
+ 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.
+
+ @see SetAndShowDefaultStyle().
+ */
+ bool IsDefaultStyleShowing() const;
+
+ /**
+ Sets @a attr as the default style and tells the control that the UI should
+ reflect this attribute until the user moves the caret.
+
+ @see IsDefaultStyleShowing().
+ */
+ void SetAndShowDefaultStyle(const wxRichTextAttr& attr);
+
+ /**
+ Returns the first visible point in the window.
+ */
+ wxPoint GetFirstVisiblePoint() const;
+
+ /**
+ Returns the content of the entire control as a string.
+ */
+ virtual wxString GetValue() const;
+
+ /**
+ Replaces existing content with the given text.
+ */
+ virtual void SetValue(const wxString& value);
+
+
+// Implementation
+
+ /**
+ Processes the back key.
+ */
+ virtual bool ProcessBackKey(wxKeyEvent& event, int flags);
+
+ /**
+ Given a character position at which there is a list style, find the range
+ encompassing the same list style by looking backwards and forwards.
+ */
+ virtual wxRichTextRange FindRangeForList(long pos, bool& isNumberedList);
+
+ /**
+ Sets up the caret for the given position and container, after a mouse click.
+ */
+ bool SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox* container, long position, int hitTestFlags, bool extendSelection = false);
+
+ /**
+ Find the caret position for the combination of hit-test flags and character position.
+ Returns the caret position and also an indication of where to place the caret (caretLineStart)
+ since this is ambiguous (same position used for end of line and start of next).
+ */
+ long FindCaretPositionForCharacterPosition(long position, int hitTestFlags, wxRichTextParagraphLayoutBox* container,
+ bool& caretLineStart);
+
+ /**
+ Processes mouse movement in order to change the cursor
+ */
+ virtual bool ProcessMouseMovement(wxRichTextParagraphLayoutBox* container, wxRichTextObject* obj, long position, const wxPoint& pos);
+
+ /**
+ Font names take a long time to retrieve, so cache them (on demand).
+ */
+ static const wxArrayString& GetAvailableFontNames();
+
+ /**
+ Clears the cache of available font names.
+ */
+ static void ClearAvailableFontNames();
+
+ // implement wxTextEntry methods
+ virtual wxString DoGetValue() const;
+
+protected:
+ // implement the wxTextEntry pure virtual method
+ virtual wxWindow *GetEditableWindow();
+
+ // margins functions
+ virtual bool DoSetMargins(const wxPoint& pt);
+ virtual wxPoint DoGetMargins() const;
+
+
+// Overrides
+protected:
+
+ /**
+ Currently this simply returns @c wxSize(10, 10).
+ */
+ virtual wxSize DoGetBestSize() const ;
+
+ virtual void DoSetValue(const wxString& value, int flags = 0);
+
+ virtual void DoThaw();
+
+
+// Data members
+protected:
+#if wxRICHTEXT_BUFFERED_PAINTING
+ /// Buffer bitmap
+ wxBitmap m_bufferBitmap;
+#endif
+
+ /// Text buffer
+ wxRichTextBuffer m_buffer;
+
+ wxMenu* m_contextMenu;
+
+ /// Caret position (1 less than the character position, so -1 is the
+ /// first caret position).
+ long m_caretPosition;
+
+ /// Caret position when the default formatting has been changed. As
+ /// soon as this position changes, we no longer reflect the default style
+ /// in the UI.
+ long m_caretPositionForDefaultStyle;
+
+ /// Selection range in character positions. -2, -2 means no selection.
+ wxRichTextSelection m_selection;
+
+ wxRichTextCtrlSelectionState m_selectionState;
+
+ /// Anchor so we know how to extend the selection
+ /// It's a caret position since it's between two characters.
+ long m_selectionAnchor;
+
+ /// Anchor object if selecting multiple container objects, such as grid cells.
+ wxRichTextObject* m_selectionAnchorObject;
+
+ /// Are we editable?
+ bool m_editable;
+
+ /// Are we showing the caret position at the start of a line
+ /// instead of at the end of the previous one?
+ bool m_caretAtLineStart;
+
+ /// Are we dragging a selection?
+ bool m_dragging;
+
+ /// Do we need full layout in idle?
+ bool m_fullLayoutRequired;
+ wxLongLong m_fullLayoutTime;
+ long m_fullLayoutSavedPosition;
+
+ /// Threshold for doing delayed layout
+ long m_delayedLayoutThreshold;
+
+ /// Cursors
+ wxCursor m_textCursor;
+ wxCursor m_urlCursor;
+
+ static wxArrayString sm_availableFontNames;
+
+ wxRichTextContextMenuPropertiesInfo m_contextMenuPropertiesInfo;
+
+ /// The object that currently has the editing focus
+ wxRichTextParagraphLayoutBox* m_focusObject;
+};
+
+/**
+ @class wxRichTextEvent
+
+ This is the event class for wxRichTextCtrl notifications.
+
+ @beginEventTable{wxRichTextEvent}
+ @event{EVT_RICHTEXT_LEFT_CLICK(id, func)}
+ Process a @c wxEVT_RICHTEXT_LEFT_CLICK event, generated when the user
+ releases the left mouse button over an object.
+ @event{EVT_RICHTEXT_RIGHT_CLICK(id, func)}
+ Process a @c wxEVT_RICHTEXT_RIGHT_CLICK event, generated when the user
+ releases the right mouse button over an object.
+ @event{EVT_RICHTEXT_MIDDLE_CLICK(id, func)}
+ Process a @c wxEVT_RICHTEXT_MIDDLE_CLICK event, generated when the user
+ releases the middle mouse button over an object.
+ @event{EVT_RICHTEXT_LEFT_DCLICK(id, func)}
+ Process a @c wxEVT_RICHTEXT_LEFT_DCLICK event, generated when the user
+ double-clicks an object.
+ @event{EVT_RICHTEXT_RETURN(id, func)}
+ Process a @c wxEVT_RICHTEXT_RETURN event, generated when the user
+ presses the return key. Valid event functions: GetFlags, GetPosition.
+ @event{EVT_RICHTEXT_CHARACTER(id, func)}
+ Process a @c wxEVT_RICHTEXT_CHARACTER event, generated when the user
+ presses a character key. Valid event functions: GetFlags, GetPosition, GetCharacter.
+ @event{EVT_RICHTEXT_DELETE(id, func)}
+ Process a @c wxEVT_RICHTEXT_DELETE event, generated when the user
+ presses the backspace or delete key. Valid event functions: GetFlags, GetPosition.
+ @event{EVT_RICHTEXT_RETURN(id, func)}
+ Process a @c wxEVT_RICHTEXT_RETURN event, generated when the user
+ presses the return key. Valid event functions: GetFlags, GetPosition.
+ @event{EVT_RICHTEXT_STYLE_CHANGED(id, func)}
+ Process a @c wxEVT_RICHTEXT_STYLE_CHANGED event, generated when
+ styling has been applied to the control. Valid event functions: GetPosition, GetRange.
+ @event{EVT_RICHTEXT_STYLESHEET_CHANGED(id, func)}
+ Process a @c wxEVT_RICHTEXT_STYLESHEET_CHANGING event, generated
+ when the control's stylesheet has changed, for example the user added,
+ edited or deleted a style. Valid event functions: GetRange, GetPosition.
+ @event{EVT_RICHTEXT_STYLESHEET_REPLACING(id, func)}
+ Process a @c wxEVT_RICHTEXT_STYLESHEET_REPLACING event, generated
+ when the control's stylesheet is about to be replaced, for example when
+ a file is loaded into the control.
+ Valid event functions: Veto, GetOldStyleSheet, GetNewStyleSheet.
+ @event{EVT_RICHTEXT_STYLESHEET_REPLACED(id, func)}
+ Process a @c wxEVT_RICHTEXT_STYLESHEET_REPLACED event, generated
+ when the control's stylesheet has been replaced, for example when a file
+ is loaded into the control.
+ Valid event functions: GetOldStyleSheet, GetNewStyleSheet.
+ @event{EVT_RICHTEXT_PROPERTIES_CHANGED(id, func)}
+ Process a @c wxEVT_RICHTEXT_PROPERTIES_CHANGED event, generated when
+ properties have been applied to the control. Valid event functions: GetPosition, GetRange.
+ @event{EVT_RICHTEXT_CONTENT_INSERTED(id, func)}
+ Process a @c wxEVT_RICHTEXT_CONTENT_INSERTED event, generated when
+ content has been inserted into the control.
+ Valid event functions: GetPosition, GetRange.
+ @event{EVT_RICHTEXT_CONTENT_DELETED(id, func)}
+ Process a @c wxEVT_RICHTEXT_CONTENT_DELETED event, generated when
+ content has been deleted from the control.
+ Valid event functions: GetPosition, GetRange.
+ @event{EVT_RICHTEXT_BUFFER_RESET(id, func)}
+ Process a @c wxEVT_RICHTEXT_BUFFER_RESET event, generated when the
+ buffer has been reset by deleting all content.
+ You can use this to set a default style for the first new paragraph.
+ @event{EVT_RICHTEXT_SELECTION_CHANGED(id, func)}
+ Process a @c wxEVT_RICHTEXT_SELECTION_CHANGED event, generated when the
+ selection range has changed.
+ @event{EVT_RICHTEXT_FOCUS_OBJECT_CHANGED(id, func)}
+ Process a @c wxEVT_RICHTEXT_FOCUS_OBJECT_CHANGED event, generated when the
+ current focus object has changed.
+ @endEventTable
+
+ @library{wxrichtext}
+ @category{events,richtext}
+*/
+
+class wxRichTextEvent : public wxNotifyEvent
+{
+public:
+ /**
+ Constructor.
+
+ @param commandType
+ The type of the event.
+ @param id
+ Window identifier. The value @c wxID_ANY indicates a default value.
+ */
+ wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
+
+ /**
+ Copy constructor.
+ */
+ wxRichTextEvent(const wxRichTextEvent& event);
+
+ /**
+ Returns the buffer position at which the event occurred.
+ */
+ long GetPosition() const;
+
+ /**
+ Sets the buffer position variable.
+ */
+ void SetPosition(long pos);
+
+ /**
+ Returns flags indicating modifier keys pressed.
+
+ Possible values are @c wxRICHTEXT_CTRL_DOWN, @c wxRICHTEXT_SHIFT_DOWN, and @c wxRICHTEXT_ALT_DOWN.
+ */
+ int GetFlags() const;
+
+ /**
+ Sets flags indicating modifier keys pressed.
+
+ Possible values are @c wxRICHTEXT_CTRL_DOWN, @c wxRICHTEXT_SHIFT_DOWN, and @c wxRICHTEXT_ALT_DOWN.
+ */
+ void SetFlags(int flags);
+
+ /**
+ Returns the old style sheet.
+
+ Can be used in a @c wxEVT_RICHTEXT_STYLESHEET_CHANGING or
+ @c wxEVT_RICHTEXT_STYLESHEET_CHANGED event handler.
+ */
+ wxRichTextStyleSheet* GetOldStyleSheet() const;
+
+ /**
+ Sets the old style sheet variable.
+ */
+ void SetOldStyleSheet(wxRichTextStyleSheet* sheet);
+
+ /**
+ Returns the new style sheet.
+
+ Can be used in a @c wxEVT_RICHTEXT_STYLESHEET_CHANGING or
+ @c wxEVT_RICHTEXT_STYLESHEET_CHANGED event handler.
+ */
+ wxRichTextStyleSheet* GetNewStyleSheet() const;
+
+ /**
+ Sets the new style sheet variable.
+ */
+ void SetNewStyleSheet(wxRichTextStyleSheet* sheet);
+
+ /**
+ Gets the range for the current operation.
+ */
+ const wxRichTextRange& GetRange() const;
+
+ /**
+ Sets the range variable.
+ */
+ void SetRange(const wxRichTextRange& range);
+
+ /**
+ Returns the character pressed, within a @c wxEVT_RICHTEXT_CHARACTER event.
+ */
+ wxChar GetCharacter() const;
+
+ /**
+ Sets the character variable.
+ */
+ void SetCharacter(wxChar ch);
+
+ /**
+ Returns the container for which the event is relevant.
+ */
+ wxRichTextParagraphLayoutBox* GetContainer() const;
+
+ /**
+ Sets the container for which the event is relevant.
+ */
+ void SetContainer(wxRichTextParagraphLayoutBox* container);
+
+ /**
+ Returns the old container, for a focus change event.
+ */
+ wxRichTextParagraphLayoutBox* GetOldContainer() const;
+
+ /**
+ Sets the old container, for a focus change event.
+ */
+ void SetOldContainer(wxRichTextParagraphLayoutBox* container);
+
+ virtual wxEvent *Clone() const;
+
+protected:
+ int m_flags;
+ long m_position;
+ wxRichTextStyleSheet* m_oldStyleSheet;
+ wxRichTextStyleSheet* m_newStyleSheet;
+ wxRichTextRange m_range;
+ wxChar m_char;
+ wxRichTextParagraphLayoutBox* m_container;
+ wxRichTextParagraphLayoutBox* m_oldContainer;
+
+};
+