1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextctrl.h
3 // Purpose: A rich edit control
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
20 #define wxRE_READONLY 0x0010
21 #define wxRE_MULTILINE 0x0020
22 #define wxRE_CENTRE_CARET 0x8000
23 #define wxRE_CENTER_CARET wxRE_CENTRE_CARET
29 #define wxRICHTEXT_SHIFT_DOWN 0x01
30 #define wxRICHTEXT_CTRL_DOWN 0x02
31 #define wxRICHTEXT_ALT_DOWN 0x04
37 // Don't draw guide lines around boxes and tables
38 #define wxRICHTEXT_EX_NO_GUIDELINES 0x00000100
45 #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
46 #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)
47 #define wxRICHTEXT_DEFAULT_SPACING 3
48 #define wxRICHTEXT_DEFAULT_MARGIN 3
49 #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
50 #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
51 #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
52 #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
53 #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
54 #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2
55 // Minimum buffer size before delayed layout kicks in
56 #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
57 // Milliseconds before layout occurs after resize
58 #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
62 #define wxID_RICHTEXT_PROPERTIES1 (wxID_HIGHEST + 1)
63 #define wxID_RICHTEXT_PROPERTIES2 (wxID_HIGHEST + 2)
64 #define wxID_RICHTEXT_PROPERTIES3 (wxID_HIGHEST + 3)
67 Normal selection occurs initially and as user drags within one container.
68 Common ancestor selection occurs when the user starts dragging across containers
69 that have a common ancestor, for example the cells in a table.
72 enum wxRichTextCtrlSelectionState
74 wxRichTextCtrlSelectionState_Normal
,
75 wxRichTextCtrlSelectionState_CommonAncestor
79 @class wxRichTextContextMenuPropertiesInfo
81 wxRichTextContextMenuPropertiesInfo keeps track of objects that appear in the context menu,
82 whose properties are available to be edited.
85 class wxRichTextContextMenuPropertiesInfo
91 wxRichTextContextMenuPropertiesInfo();
103 bool AddItem(const wxString
& label
, wxRichTextObject
* obj
);
106 Returns the number of menu items that were added.
108 int AddMenuItems(wxMenu
* menu
, int startCmd
= wxID_RICHTEXT_PROPERTIES1
) const;
111 Adds appropriate menu items for the current container and clicked on object
112 (and container's parent, if appropriate).
114 int AddItems(wxRichTextCtrl
* ctrl
, wxRichTextObject
* container
, wxRichTextObject
* obj
);
124 Returns the nth label.
126 wxString
GetLabel(int n
) const;
129 Returns the nth object.
131 wxRichTextObject
* GetObject(int n
) const;
134 Returns the array of objects.
136 wxRichTextObjectPtrArray
& GetObjects();
139 Returns the array of objects.
141 const wxRichTextObjectPtrArray
& GetObjects() const;
144 Returns the array of labels.
146 wxArrayString
& GetLabels();
149 Returns the array of labels.
151 const wxArrayString
& GetLabels() const;
154 Returns the number of items.
156 int GetCount() const;
158 wxRichTextObjectPtrArray m_objects
;
159 wxArrayString m_labels
;
163 @class wxRichTextCtrl
165 wxRichTextCtrl provides a generic, ground-up implementation of a text control
166 capable of showing multiple styles and images.
168 wxRichTextCtrl sends notification events: see wxRichTextEvent.
170 It also sends the standard wxTextCtrl events @c wxEVT_TEXT_ENTER and
171 @c wxEVT_TEXT, and wxTextUrlEvent when URL content is clicked.
173 For more information, see the @ref overview_richtextctrl.
176 @style{wxRE_CENTRE_CARET}
177 The control will try to keep the caret line centred vertically while editing.
178 wxRE_CENTER_CARET is a synonym for this style.
179 @style{wxRE_MULTILINE}
180 The control will be multiline (mandatory).
181 @style{wxRE_READONLY}
182 The control will not be editable.
187 @appearance{richtextctrl}
191 class wxRichTextCtrl
: public wxControl
,
192 public wxTextCtrlIface
,
193 public wxScrollHelper
204 Constructor, creating and showing a rich text control.
207 Parent window. Must not be @NULL.
209 Window identifier. The value @c wxID_ANY indicates a default value.
223 @see Create(), wxValidator
225 wxRichTextCtrl( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
226 long style
= wxRE_MULTILINE
, const wxValidator
& validator
= wxDefaultValidator
, const wxString
& name
= wxTextCtrlNameStr
);
231 virtual ~wxRichTextCtrl( );
236 Creates the underlying window.
238 bool Create( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
239 long style
= wxRE_MULTILINE
, const wxValidator
& validator
= wxDefaultValidator
, const wxString
& name
= wxTextCtrlNameStr
);
242 Initialises the members of the control.
249 Gets the text for the given range.
250 The end point of range is specified as the last character position of
251 the span of text, plus one.
253 virtual wxString
GetRange(long from
, long to
) const;
256 Returns the length of the specified line in characters.
258 virtual int GetLineLength(long lineNo
) const ;
261 Returns the text for the given line.
263 virtual wxString
GetLineText(long lineNo
) const ;
266 Returns the number of lines in the buffer.
268 virtual int GetNumberOfLines() const ;
271 Returns @true if the buffer has been modified.
273 virtual bool IsModified() const ;
276 Returns @true if the control is editable.
278 virtual bool IsEditable() const ;
281 Returns @true if the control is single-line.
282 Currently wxRichTextCtrl does not support single-line editing.
284 bool IsSingleLine() const;
287 Returns @true if the control is multiline.
289 bool IsMultiLine() const;
293 Returns the range of the current selection.
294 The end point of range is specified as the last character position of the span
296 If the return values @a from and @a to are the same, there is no selection.
298 virtual void GetSelection(long* from
, long* to
) const;
299 const wxRichTextSelection
& GetSelection() const;
300 wxRichTextSelection
& GetSelection();
304 Returns the text within the current selection range, if any.
306 virtual wxString
GetStringSelection() const;
309 Gets the current filename associated with the control.
311 wxString
GetFilename() const;
314 Sets the current filename.
316 void SetFilename(const wxString
& filename
);
319 Sets the size of the buffer beyond which layout is delayed during resizing.
320 This optimizes sizing for large buffers. The default is 20000.
322 void SetDelayedLayoutThreshold(long threshold
);
325 Gets the size of the buffer beyond which layout is delayed during resizing.
326 This optimizes sizing for large buffers. The default is 20000.
328 long GetDelayedLayoutThreshold() const;
332 bool GetFullLayoutRequired() const;
336 void SetFullLayoutRequired(bool b
);
340 wxLongLong
GetFullLayoutTime() const;
344 void SetFullLayoutTime(wxLongLong t
);
348 long GetFullLayoutSavedPosition() const;
352 void SetFullLayoutSavedPosition(long p
);
354 // Force any pending layout due to large buffer
357 void ForceDelayedLayout();
360 Sets the text (normal) cursor.
362 void SetTextCursor(const wxCursor
& cursor
);
365 Returns the text (normal) cursor.
367 wxCursor
GetTextCursor() const;
370 Sets the cursor to be used over URLs.
372 void SetURLCursor(const wxCursor
& cursor
);
375 Returns the cursor to be used over URLs.
377 wxCursor
GetURLCursor() const;
380 Returns @true if we are showing the caret position at the start of a line
381 instead of at the end of the previous one.
383 bool GetCaretAtLineStart() const;
386 Sets a flag to remember that we are showing the caret position at the start of a line
387 instead of at the end of the previous one.
389 void SetCaretAtLineStart(bool atStart
);
392 Returns @true if we are extending a selection.
394 bool GetDragging() const;
397 Sets a flag to remember if we are extending a selection.
399 void SetDragging(bool dragging
);
402 Are we trying to start Drag'n'Drop?
404 bool GetPreDrag() const;
407 Set if we're trying to start Drag'n'Drop
409 void SetPreDrag(bool pd
);
412 Get the possible Drag'n'Drop start point
414 const wxPoint
GetDragStartPoint() const;
417 Set the possible Drag'n'Drop start point
419 void SetDragStartPoint(wxPoint sp
);
422 Get the possible Drag'n'Drop start time
424 const wxDateTime
GetDragStartTime() const;
427 Set the possible Drag'n'Drop start time
429 void SetDragStartTime(wxDateTime st
);
431 #if wxRICHTEXT_BUFFERED_PAINTING
434 Returns the buffer bitmap if using buffered painting.
436 const wxBitmap
& GetBufferBitmap() const;
437 wxBitmap
& GetBufferBitmap();
442 Returns the current context menu.
444 wxMenu
* GetContextMenu() const;
447 Sets the current context menu.
449 void SetContextMenu(wxMenu
* menu
);
452 Returns an anchor so we know how to extend the selection.
453 It's a caret position since it's between two characters.
455 long GetSelectionAnchor() const;
458 Sets an anchor so we know how to extend the selection.
459 It's a caret position since it's between two characters.
461 void SetSelectionAnchor(long anchor
);
464 Returns the anchor object if selecting multiple containers.
466 wxRichTextObject
* GetSelectionAnchorObject() const;
469 Sets the anchor object if selecting multiple containers.
471 void SetSelectionAnchorObject(wxRichTextObject
* anchor
);
475 Returns an object that stores information about context menu property item(s),
476 in order to communicate between the context menu event handler and the code
477 that responds to it. The wxRichTextContextMenuPropertiesInfo stores one
478 item for each object that could respond to a property-editing event. If
479 objects are nested, several might be editable.
481 wxRichTextContextMenuPropertiesInfo
& GetContextMenuPropertiesInfo();
482 const wxRichTextContextMenuPropertiesInfo
& GetContextMenuPropertiesInfo() const;
486 Returns the wxRichTextObject object that currently has the editing focus.
487 If there are no composite objects, this will be the top-level buffer.
489 wxRichTextParagraphLayoutBox
* GetFocusObject() const;
492 Setter for m_focusObject.
494 void StoreFocusObject(wxRichTextParagraphLayoutBox
* obj
);
497 Sets the wxRichTextObject object that currently has the editing focus.
498 @param setCaretPosition
499 Optionally set the caret position.
501 bool SetFocusObject(wxRichTextParagraphLayoutBox
* obj
, bool setCaretPosition
= true);
506 Invalidates the whole buffer to trigger painting later.
511 Clears the buffer content, leaving a single empty paragraph. Cannot be undone.
513 virtual void Clear();
516 Replaces the content in the specified range with the string specified by
519 virtual void Replace(long from
, long to
, const wxString
& value
);
522 Removes the content in the specified range.
524 virtual void Remove(long from
, long to
);
527 Loads content into the control's buffer using the given type.
529 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
530 the filename extension.
532 This function looks for a suitable wxRichTextFileHandler object.
534 bool LoadFile(const wxString
& file
,
535 int type
= wxRICHTEXT_TYPE_ANY
);
538 Helper function for LoadFile(). Loads content into the control's buffer using the given type.
540 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
541 the filename extension.
543 This function looks for a suitable wxRichTextFileHandler object.
545 virtual bool DoLoadFile(const wxString
& file
, int fileType
);
548 Saves the buffer content using the given type.
550 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
551 the filename extension.
553 This function looks for a suitable wxRichTextFileHandler object.
555 bool SaveFile(const wxString
& file
= wxEmptyString
,
556 int type
= wxRICHTEXT_TYPE_ANY
);
559 Helper function for SaveFile(). Saves the buffer content using the given type.
561 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
562 the filename extension.
564 This function looks for a suitable wxRichTextFileHandler object.
566 virtual bool DoSaveFile(const wxString
& file
= wxEmptyString
,
567 int fileType
= wxRICHTEXT_TYPE_ANY
);
570 Sets flags that change the behaviour of loading or saving.
572 See the documentation for each handler class to see what flags are
573 relevant for each handler.
575 void SetHandlerFlags(int flags
);
578 Returns flags that change the behaviour of loading or saving.
579 See the documentation for each handler class to see what flags are
580 relevant for each handler.
582 int GetHandlerFlags() const;
585 Marks the buffer as modified.
587 virtual void MarkDirty();
590 Sets the buffer's modified status to @false, and clears the buffer's command
593 virtual void DiscardEdits();
596 void SetModified(bool modified
);
599 Sets the maximum number of characters that may be entered in a single line
600 text control. For compatibility only; currently does nothing.
602 virtual void SetMaxLength(unsigned long len
);
605 Writes text at the current position.
607 virtual void WriteText(const wxString
& text
);
610 Sets the insertion point to the end of the buffer and writes the text.
612 virtual void AppendText(const wxString
& text
);
616 Gets the attributes at the given position.
617 This function gets the combined style - that is, the style you see on the
618 screen as a result of combining base style, paragraph style and character
621 To get the character or paragraph style alone, use GetUncombinedStyle().
624 In wxPerl this method is implemented as GetStyle(@a position)
625 returning a 2-element list (ok, attr).
628 virtual bool GetStyle(long position
, wxTextAttr
& style
);
629 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
630 virtual bool GetStyle(long position
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
);
635 Sets the attributes for the given range.
636 The end point of range is specified as the last character position of the span
639 So, for example, to set the style for a character at position 5, use the range
642 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
643 virtual bool SetStyle(long start
, long end
, const wxRichTextAttr
& style
);
644 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
);
645 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
);
649 Sets the attributes for a single object
651 virtual void SetStyle(wxRichTextObject
*obj
, const wxRichTextAttr
& textAttr
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
655 Gets the attributes common to the specified range.
656 Attributes that differ in value within the range will not be included
660 In wxPerl this method is implemented as GetStyleForRange(@a position)
661 returning a 2-element list (ok, attr).
664 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxTextAttr
& style
);
665 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
);
666 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
);
670 Sets the attributes for the given range, passing flags to determine how the
673 The end point of range is specified as the last character position of the span
674 of text, plus one. So, for example, to set the style for a character at
675 position 5, use the range (5,6).
677 @a flags may contain a bit list of the following values:
678 - wxRICHTEXT_SETSTYLE_NONE: no style flag.
679 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
681 - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
682 if the combined style at this point is already the style in question.
683 - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
684 applied to paragraphs, and not the content.
685 This allows content styling to be preserved independently from that
686 of e.g. a named paragraph style.
687 - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
688 applied to characters, and not the paragraph.
689 This allows content styling to be preserved independently from that
690 of e.g. a named paragraph style.
691 - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
693 - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style. Only the style flags
694 are used in this operation.
696 virtual bool SetStyleEx(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
700 Gets the attributes at the given position.
701 This function gets the @e uncombined style - that is, the attributes associated
702 with the paragraph or character content, and not necessarily the combined
703 attributes you see on the screen.
704 To get the combined attributes, use GetStyle().
706 If you specify (any) paragraph attribute in @e style's flags, this function
707 will fetch the paragraph attributes.
708 Otherwise, it will return the character attributes.
711 In wxPerl this method is implemented as GetUncombinedStyle(@a position)
712 returning a 2-element list (ok, attr).
715 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
716 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
);
721 Sets the current default style, which can be used to change how subsequently
722 inserted text is displayed.
724 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
725 virtual bool SetDefaultStyle(const wxRichTextAttr
& style
);
729 Returns the current default style, which can be used to change how subsequently
730 inserted text is displayed.
732 virtual const wxRichTextAttr
& GetDefaultStyleEx() const;
734 //virtual const wxTextAttr& GetDefaultStyle() const;
738 Sets the list attributes for the given range, passing flags to determine how
739 the attributes are set.
741 Either the style definition or the name of the style definition (in the current
742 sheet) can be passed.
743 @a flags is a bit list of the following:
744 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
745 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
746 @a startFrom, otherwise existing attributes are used.
747 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
748 as the level for all paragraphs, otherwise the current indentation will be used.
750 @see NumberList(), PromoteList(), ClearListStyle().
752 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
753 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
757 Clears the list style from the given range, clearing list-related attributes
758 and applying any named paragraph style associated with each paragraph.
760 @a flags is a bit list of the following:
761 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
763 @see SetListStyle(), PromoteList(), NumberList().
765 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
769 Numbers the paragraphs in the given range.
770 Pass flags to determine how the attributes are set.
772 Either the style definition or the name of the style definition (in the current
773 sheet) can be passed.
775 @a flags is a bit list of the following:
776 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
777 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
778 @a startFrom, otherwise existing attributes are used.
779 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
780 as the level for all paragraphs, otherwise the current indentation will be used.
782 @see SetListStyle(), PromoteList(), ClearListStyle().
784 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
785 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
790 Promotes or demotes the paragraphs in the given range.
791 A positive @a promoteBy produces a smaller indent, and a negative number
792 produces a larger indent. Pass flags to determine how the attributes are set.
793 Either the style definition or the name of the style definition (in the current
794 sheet) can be passed.
796 @a flags is a bit list of the following:
797 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
798 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
799 @a startFrom, otherwise existing attributes are used.
800 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
801 as the level for all paragraphs, otherwise the current indentation will be used.
803 @see SetListStyle(), @see SetListStyle(), ClearListStyle().
805 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
806 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
810 Sets the properties for the given range, passing flags to determine how the
811 attributes are set. You can merge properties or replace them.
813 The end point of range is specified as the last character position of the span
814 of text, plus one. So, for example, to set the properties for a character at
815 position 5, use the range (5,6).
817 @a flags may contain a bit list of the following values:
818 - wxRICHTEXT_SETSPROPERTIES_NONE: no flag.
819 - wxRICHTEXT_SETPROPERTIES_WITH_UNDO: specifies that this operation should be
821 - wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY: specifies that the properties should only be
822 applied to paragraphs, and not the content.
823 - wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY: specifies that the properties should only be
824 applied to characters, and not the paragraph.
825 - wxRICHTEXT_SETPROPERTIES_RESET: resets (clears) the existing properties before applying
827 - wxRICHTEXT_SETPROPERTIES_REMOVE: removes the specified properties.
829 virtual bool SetProperties(const wxRichTextRange
& range
, const wxRichTextProperties
& properties
, int flags
= wxRICHTEXT_SETPROPERTIES_WITH_UNDO
);
832 Deletes the content within the given range.
834 virtual bool Delete(const wxRichTextRange
& range
);
837 Translates from column and line number to position.
839 virtual long XYToPosition(long x
, long y
) const;
842 Converts a text position to zero-based column and line numbers.
844 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
847 Scrolls the buffer so that the given position is in view.
849 virtual void ShowPosition(long pos
);
853 Finds the character at the given position in pixels.
854 @a pt is in device coords (not adjusted for the client area origin nor for
857 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
858 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
860 wxTextCoord
*row
) const;
863 Finds the container at the given point, which is assumed to be in client coordinates.
865 wxRichTextParagraphLayoutBox
* FindContainerAtPoint(const wxPoint pt
, long& position
, int& hit
, wxRichTextObject
* hitObj
, int flags
= 0);
868 // Clipboard operations
871 Copies the selected content (if any) to the clipboard.
876 Copies the selected content (if any) to the clipboard and deletes the selection.
882 Pastes content from the clipboard to the buffer.
884 virtual void Paste();
887 Deletes the content in the selection, if any. This is undoable.
889 virtual void DeleteSelection();
892 Returns @true if selected content can be copied to the clipboard.
894 virtual bool CanCopy() const;
897 Returns @true if selected content can be copied to the clipboard and deleted.
899 virtual bool CanCut() const;
902 Returns @true if the clipboard content can be pasted to the buffer.
904 virtual bool CanPaste() const;
907 Returns @true if selected content can be deleted.
909 virtual bool CanDeleteSelection() const;
912 Undoes the command at the top of the command history, if there is one.
917 Redoes the current command.
922 Returns @true if there is a command in the command history that can be undone.
924 virtual bool CanUndo() const;
927 Returns @true if there is a command in the command history that can be redone.
929 virtual bool CanRedo() const;
932 Sets the insertion point and causes the current editing style to be taken from
933 the new position (unlike wxRichTextCtrl::SetCaretPosition).
935 virtual void SetInsertionPoint(long pos
);
938 Sets the insertion point to the end of the text control.
940 virtual void SetInsertionPointEnd();
943 Returns the current insertion point.
945 virtual long GetInsertionPoint() const;
948 Returns the last position in the buffer.
950 virtual wxTextPos
GetLastPosition() const;
954 Sets the selection to the given range.
955 The end point of range is specified as the last character position of the span
958 So, for example, to set the selection for a character at position 5, use the
961 virtual void SetSelection(long from
, long to
);
962 void SetSelection(const wxRichTextSelection
& sel
);
967 Selects all the text in the buffer.
969 virtual void SelectAll();
972 Makes the control editable, or not.
974 virtual void SetEditable(bool editable
);
977 Returns @true if there is a selection and the object containing the selection
978 was the same as the current focus object.
980 virtual bool HasSelection() const;
983 Returns @true if there was a selection, whether or not the current focus object
984 is the same as the selection's container object.
986 virtual bool HasUnfocusedSelection() const;
990 Write a bitmap or image at the current insertion point.
991 Supply an optional type to use for internal and file storage of the raw data.
993 virtual bool WriteImage(const wxImage
& image
, wxBitmapType bitmapType
= wxBITMAP_TYPE_PNG
,
994 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
996 virtual bool WriteImage(const wxBitmap
& bitmap
, wxBitmapType bitmapType
= wxBITMAP_TYPE_PNG
,
997 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
1001 Loads an image from a file and writes it at the current insertion point.
1003 virtual bool WriteImage(const wxString
& filename
, wxBitmapType bitmapType
,
1004 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
1007 Writes an image block at the current insertion point.
1009 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
,
1010 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
1013 Write a text box at the current insertion point, returning the text box.
1014 You can then call SetFocusObject() to set the focus to the new object.
1016 virtual wxRichTextBox
* WriteTextBox(const wxRichTextAttr
& textAttr
= wxRichTextAttr());
1019 Writes a field at the current insertion point.
1022 The field type, matching an existing field type definition.
1024 Extra data for the field.
1026 Optional attributes.
1028 @see wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard
1030 virtual wxRichTextField
* WriteField(const wxString
& fieldType
, const wxRichTextProperties
& properties
,
1031 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
1034 Write a table at the current insertion point, returning the table.
1035 You can then call SetFocusObject() to set the focus to the new object.
1037 virtual wxRichTextTable
* WriteTable(int rows
, int cols
, const wxRichTextAttr
& tableAttr
= wxRichTextAttr(), const wxRichTextAttr
& cellAttr
= wxRichTextAttr());
1040 Inserts a new paragraph at the current insertion point. @see LineBreak().
1042 virtual bool Newline();
1045 Inserts a line break at the current insertion point.
1047 A line break forces wrapping within a paragraph, and can be introduced by
1048 using this function, by appending the wxChar value @b wxRichTextLineBreakChar
1049 to text content, or by typing Shift-Return.
1051 virtual bool LineBreak();
1054 Sets the basic (overall) style.
1056 This is the style of the whole buffer before further styles are applied,
1057 unlike the default style, which only affects the style currently being
1058 applied (for example, setting the default style to bold will cause
1059 subsequently inserted text to be bold).
1061 virtual void SetBasicStyle(const wxRichTextAttr
& style
);
1064 Gets the basic (overall) style.
1066 This is the style of the whole buffer before further styles are applied,
1067 unlike the default style, which only affects the style currently being
1068 applied (for example, setting the default style to bold will cause
1069 subsequently inserted text to be bold).
1071 virtual const wxRichTextAttr
& GetBasicStyle() const;
1074 Begins applying a style.
1076 virtual bool BeginStyle(const wxRichTextAttr
& style
);
1079 Ends the current style.
1081 virtual bool EndStyle();
1084 Ends application of all styles in the current style stack.
1086 virtual bool EndAllStyles();
1099 Begins using italic.
1109 Begins using underlining.
1111 bool BeginUnderline();
1114 End applying underlining.
1116 bool EndUnderline();
1119 Begins using the given point size.
1121 bool BeginFontSize(int pointSize
);
1124 Ends using a point size.
1129 Begins using this font.
1131 bool BeginFont(const wxFont
& font
);
1139 Begins using this colour.
1141 bool BeginTextColour(const wxColour
& colour
);
1144 Ends applying a text colour.
1146 bool EndTextColour();
1149 Begins using alignment.
1150 For alignment values, see wxTextAttr.
1152 bool BeginAlignment(wxTextAttrAlignment alignment
);
1157 bool EndAlignment();
1160 Begins applying a left indent and subindent in tenths of a millimetre.
1161 The subindent is an offset from the left edge of the paragraph, and is
1162 used for all but the first line in a paragraph. A positive value will
1163 cause the first line to appear to the left of the subsequent lines, and
1164 a negative value will cause the first line to be indented to the right
1165 of the subsequent lines.
1167 wxRichTextBuffer uses indentation to render a bulleted item. The
1168 content of the paragraph, including the first line, starts at the
1169 @a leftIndent plus the @a leftSubIndent.
1172 The distance between the margin and the bullet.
1173 @param leftSubIndent
1174 The distance between the left edge of the bullet and the left edge
1175 of the actual paragraph.
1177 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
1182 bool EndLeftIndent();
1185 Begins a right indent, specified in tenths of a millimetre.
1187 bool BeginRightIndent(int rightIndent
);
1192 bool EndRightIndent();
1195 Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing
1196 in tenths of a millimetre.
1198 bool BeginParagraphSpacing(int before
, int after
);
1201 Ends paragraph spacing.
1203 bool EndParagraphSpacing();
1206 Begins appling line spacing. @e spacing is a multiple, where 10 means
1207 single-spacing, 15 means 1.5 spacing, and 20 means double spacing.
1209 The ::wxTextAttrLineSpacing constants are defined for convenience.
1211 bool BeginLineSpacing(int lineSpacing
);
1216 bool EndLineSpacing();
1219 Begins a numbered bullet.
1221 This call will be needed for each item in the list, and the
1222 application should take care of incrementing the numbering.
1224 @a bulletNumber is a number, usually starting with 1.
1225 @a leftIndent and @a leftSubIndent are values in tenths of a millimetre.
1226 @a bulletStyle is a bitlist of the ::wxTextAttrBulletStyle values.
1228 wxRichTextBuffer uses indentation to render a bulleted item.
1229 The left indent is the distance between the margin and the bullet.
1230 The content of the paragraph, including the first line, starts
1231 at leftMargin + leftSubIndent.
1232 So the distance between the left edge of the bullet and the
1233 left of the actual paragraph is leftSubIndent.
1235 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
1238 Ends application of a numbered bullet.
1240 bool EndNumberedBullet();
1243 Begins applying a symbol bullet, using a character from the current font.
1244 See BeginNumberedBullet() for an explanation of how indentation is used
1245 to render the bulleted paragraph.
1247 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
1250 Ends applying a symbol bullet.
1252 bool EndSymbolBullet();
1255 Begins applying a symbol bullet.
1257 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
);
1260 Begins applying a standard bullet.
1262 bool EndStandardBullet();
1265 Begins using the named character style.
1267 bool BeginCharacterStyle(const wxString
& characterStyle
);
1270 Ends application of a named character style.
1272 bool EndCharacterStyle();
1275 Begins applying the named paragraph style.
1277 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
1280 Ends application of a named paragraph style.
1282 bool EndParagraphStyle();
1285 Begins using a specified list style.
1286 Optionally, you can also pass a level and a number.
1288 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1);
1291 Ends using a specified list style.
1293 bool EndListStyle();
1296 Begins applying wxTEXT_ATTR_URL to the content.
1298 Pass a URL and optionally, a character style to apply, since it is common
1299 to mark a URL with a familiar style such as blue text with underlining.
1301 bool BeginURL(const wxString
& url
, const wxString
& characterStyle
= wxEmptyString
);
1304 Ends applying a URL.
1309 Sets the default style to the style under the cursor.
1311 bool SetDefaultStyleToCursorStyle();
1314 Cancels any selection.
1316 virtual void SelectNone();
1319 Selects the word at the given character position.
1321 virtual bool SelectWord(long position
);
1324 Returns the selection range in character positions. -1, -1 means no selection.
1326 The range is in API convention, i.e. a single character selection is denoted
1329 wxRichTextRange
GetSelectionRange() const;
1332 Sets the selection to the given range.
1333 The end point of range is specified as the last character position of the span
1336 So, for example, to set the selection for a character at position 5, use the
1339 void SetSelectionRange(const wxRichTextRange
& range
);
1342 Returns the selection range in character positions. -2, -2 means no selection
1343 -1, -1 means select everything.
1344 The range is in internal format, i.e. a single character selection is denoted
1347 wxRichTextRange
GetInternalSelectionRange() const;
1350 Sets the selection range in character positions. -2, -2 means no selection
1351 -1, -1 means select everything.
1352 The range is in internal format, i.e. a single character selection is denoted
1355 void SetInternalSelectionRange(const wxRichTextRange
& range
);
1358 Adds a new paragraph of text to the end of the buffer.
1360 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
1363 Adds an image to the control's buffer.
1365 virtual wxRichTextRange
AddImage(const wxImage
& image
);
1368 Lays out the buffer, which must be done before certain operations, such as
1369 setting the caret position.
1370 This function should not normally be required by the application.
1372 virtual bool LayoutContent(bool onlyVisibleRect
= false);
1375 Move the caret to the given character position.
1377 Please note that this does not update the current editing style
1378 from the new position; to do that, call wxRichTextCtrl::SetInsertionPoint instead.
1380 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false, wxRichTextParagraphLayoutBox
* container
= NULL
);
1385 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
1390 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
1393 Moves to the start of the paragraph.
1395 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
1398 Moves the caret down.
1400 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
1403 Moves to the end of the line.
1405 virtual bool MoveToLineEnd(int flags
= 0);
1408 Moves to the start of the line.
1410 virtual bool MoveToLineStart(int flags
= 0);
1413 Moves to the end of the paragraph.
1415 virtual bool MoveToParagraphEnd(int flags
= 0);
1418 Moves to the start of the paragraph.
1420 virtual bool MoveToParagraphStart(int flags
= 0);
1423 Moves to the start of the buffer.
1425 virtual bool MoveHome(int flags
= 0);
1428 Moves to the end of the buffer.
1430 virtual bool MoveEnd(int flags
= 0);
1433 Moves one or more pages up.
1435 virtual bool PageUp(int noPages
= 1, int flags
= 0);
1438 Moves one or more pages down.
1440 virtual bool PageDown(int noPages
= 1, int flags
= 0);
1443 Moves a number of words to the left.
1445 virtual bool WordLeft(int noPages
= 1, int flags
= 0);
1448 Move a nuber of words to the right.
1450 virtual bool WordRight(int noPages
= 1, int flags
= 0);
1454 Returns the buffer associated with the control.
1456 wxRichTextBuffer
& GetBuffer();
1457 const wxRichTextBuffer
& GetBuffer() const;
1461 Starts batching undo history for commands.
1463 virtual bool BeginBatchUndo(const wxString
& cmdName
);
1466 Ends batching undo command history.
1468 virtual bool EndBatchUndo();
1471 Returns @true if undo commands are being batched.
1473 virtual bool BatchingUndo() const;
1476 Starts suppressing undo history for commands.
1478 virtual bool BeginSuppressUndo();
1481 Ends suppressing undo command history.
1483 virtual bool EndSuppressUndo();
1486 Returns @true if undo history suppression is on.
1488 virtual bool SuppressingUndo() const;
1491 Test if this whole range has character attributes of the specified kind.
1492 If any of the attributes are different within the range, the test fails.
1494 You can use this to implement, for example, bold button updating.
1495 @a style must have flags indicating which attributes are of interest.
1497 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1501 Test if this whole range has paragraph attributes of the specified kind.
1502 If any of the attributes are different within the range, the test fails.
1503 You can use this to implement, for example, centering button updating.
1504 @a style must have flags indicating which attributes are of interest.
1506 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1510 Returns @true if all of the selection, or the content at the caret position, is bold.
1512 virtual bool IsSelectionBold();
1515 Returns @true if all of the selection, or the content at the caret position, is italic.
1517 virtual bool IsSelectionItalics();
1520 Returns @true if all of the selection, or the content at the caret position, is underlined.
1522 virtual bool IsSelectionUnderlined();
1525 Returns @true if all of the selection, or the content at the current caret position, has the supplied wxTextAttrEffects flag(s).
1527 virtual bool DoesSelectionHaveTextEffectFlag(int flag
);
1530 Returns @true if all of the selection is aligned according to the specified flag.
1532 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
);
1535 Apples bold to the selection or the default style (undoable).
1537 virtual bool ApplyBoldToSelection();
1540 Applies italic to the selection or the default style (undoable).
1542 virtual bool ApplyItalicToSelection();
1545 Applies underline to the selection or the default style (undoable).
1547 virtual bool ApplyUnderlineToSelection();
1550 Applies one or more wxTextAttrEffects flags to the selection (undoable).
1551 If there is no selection, it is applied to the default style.
1553 virtual bool ApplyTextEffectToSelection(int flags
);
1556 Applies the given alignment to the selection or the default style (undoable).
1557 For alignment values, see wxTextAttr.
1559 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
1562 Applies the style sheet to the buffer, matching paragraph styles in the sheet
1563 against named styles in the buffer.
1565 This might be useful if the styles have changed.
1566 If @a sheet is @NULL, the sheet set with SetStyleSheet() is used.
1567 Currently this applies paragraph styles only.
1569 virtual bool ApplyStyle(wxRichTextStyleDefinition
* def
);
1572 Sets the style sheet associated with the control.
1573 A style sheet allows named character and paragraph styles to be applied.
1575 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1578 Returns the style sheet associated with the control, if any.
1579 A style sheet allows named character and paragraph styles to be applied.
1581 wxRichTextStyleSheet
* GetStyleSheet() const;
1584 Push the style sheet to top of stack.
1586 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1589 Pops the style sheet from top of stack.
1591 wxRichTextStyleSheet
* PopStyleSheet();
1594 Applies the style sheet to the buffer, for example if the styles have changed.
1596 bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
= NULL
);
1599 Shows the given context menu, optionally adding appropriate property-editing commands for the current position in the object hierarchy.
1601 virtual bool ShowContextMenu(wxMenu
* menu
, const wxPoint
& pt
, bool addPropertyCommands
);
1604 Prepares the context menu, optionally adding appropriate property-editing commands.
1605 Returns the number of property commands added.
1607 virtual int PrepareContextMenu(wxMenu
* menu
, const wxPoint
& pt
, bool addPropertyCommands
);
1610 Returns @true if we can edit the object's properties via a GUI.
1612 virtual bool CanEditProperties(wxRichTextObject
* obj
) const;
1615 Edits the object's properties via a GUI.
1617 virtual bool EditProperties(wxRichTextObject
* obj
, wxWindow
* parent
);
1620 Gets the object's properties menu label.
1622 virtual wxString
GetPropertiesMenuLabel(wxRichTextObject
* obj
);
1625 Prepares the content just before insertion (or after buffer reset). Called by the same function in wxRichTextBuffer.
1626 Currently is only called if undo mode is on.
1628 virtual void PrepareContent(wxRichTextParagraphLayoutBox
& container
);
1631 Can we delete this range?
1632 Sends an event to the control.
1634 virtual bool CanDeleteRange(wxRichTextParagraphLayoutBox
& container
, const wxRichTextRange
& range
) const;
1637 Can we insert content at this position?
1638 Sends an event to the control.
1640 virtual bool CanInsertContent(wxRichTextParagraphLayoutBox
& container
, long pos
) const;
1643 Enable or disable the vertical scrollbar.
1645 virtual void EnableVerticalScrollbar(bool enable
);
1648 Returns @true if the vertical scrollbar is enabled.
1650 virtual bool GetVerticalScrollbarEnabled() const;
1653 Sets the scale factor for displaying fonts, for example for more comfortable
1656 void SetFontScale(double fontScale
, bool refresh
= false);
1659 Returns the scale factor for displaying fonts, for example for more comfortable
1662 double GetFontScale() const { return GetBuffer().GetFontScale(); }
1665 Sets the scale factor for displaying certain dimensions such as indentation and
1666 inter-paragraph spacing. This can be useful when editing in a small control
1667 where you still want legible text, but a minimum of wasted white space.
1669 void SetDimensionScale(double dimScale
, bool refresh
= false);
1672 Returns the scale factor for displaying certain dimensions such as indentation
1673 and inter-paragraph spacing.
1675 double GetDimensionScale() const { return GetBuffer().GetDimensionScale(); }
1678 Sets an overall scale factor for displaying and editing the content.
1680 void SetScale(double scale
, bool refresh
= false);
1683 Returns an overall scale factor for displaying and editing the content.
1685 double GetScale() const;
1688 Returns an unscaled point.
1690 wxPoint
GetUnscaledPoint(const wxPoint
& pt
) const;
1693 Returns a scaled point.
1695 wxPoint
GetScaledPoint(const wxPoint
& pt
) const;
1698 Returns an unscaled size.
1700 wxSize
GetUnscaledSize(const wxSize
& sz
) const;
1703 Returns a scaled size.
1705 wxSize
GetScaledSize(const wxSize
& sz
) const;
1708 Returns an unscaled rectangle.
1710 wxRect
GetUnscaledRect(const wxRect
& rect
) const;
1713 Returns a scaled rectangle.
1715 wxRect
GetScaledRect(const wxRect
& rect
) const;
1718 Returns @true if this control can use virtual attributes and virtual text.
1719 The default is @false.
1721 bool GetVirtualAttributesEnabled() const;
1724 Pass @true to let the control use virtual attributes.
1725 The default is @false.
1727 void EnableVirtualAttributes(bool b
);
1732 Sends the event to the control.
1734 void Command(wxCommandEvent
& event
);
1737 Loads the first dropped file.
1739 void OnDropFiles(wxDropFilesEvent
& event
);
1741 void OnCaptureLost(wxMouseCaptureLostEvent
& event
);
1742 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
1745 Standard handler for the wxID_CUT command.
1747 void OnCut(wxCommandEvent
& event
);
1750 Standard handler for the wxID_COPY command.
1752 void OnCopy(wxCommandEvent
& event
);
1755 Standard handler for the wxID_PASTE command.
1757 void OnPaste(wxCommandEvent
& event
);
1760 Standard handler for the wxID_UNDO command.
1762 void OnUndo(wxCommandEvent
& event
);
1765 Standard handler for the wxID_REDO command.
1767 void OnRedo(wxCommandEvent
& event
);
1770 Standard handler for the wxID_SELECTALL command.
1772 void OnSelectAll(wxCommandEvent
& event
);
1775 Standard handler for property commands.
1777 void OnProperties(wxCommandEvent
& event
);
1780 Standard handler for the wxID_CLEAR command.
1782 void OnClear(wxCommandEvent
& event
);
1785 Standard update handler for the wxID_CUT command.
1787 void OnUpdateCut(wxUpdateUIEvent
& event
);
1790 Standard update handler for the wxID_COPY command.
1792 void OnUpdateCopy(wxUpdateUIEvent
& event
);
1795 Standard update handler for the wxID_PASTE command.
1797 void OnUpdatePaste(wxUpdateUIEvent
& event
);
1800 Standard update handler for the wxID_UNDO command.
1802 void OnUpdateUndo(wxUpdateUIEvent
& event
);
1805 Standard update handler for the wxID_REDO command.
1807 void OnUpdateRedo(wxUpdateUIEvent
& event
);
1810 Standard update handler for the wxID_SELECTALL command.
1812 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
1815 Standard update handler for property commands.
1818 void OnUpdateProperties(wxUpdateUIEvent
& event
);
1821 Standard update handler for the wxID_CLEAR command.
1823 void OnUpdateClear(wxUpdateUIEvent
& event
);
1826 Shows a standard context menu with undo, redo, cut, copy, paste, clear, and
1827 select all commands.
1829 void OnContextMenu(wxContextMenuEvent
& event
);
1834 void OnPaint(wxPaintEvent
& event
);
1835 void OnEraseBackground(wxEraseEvent
& event
);
1838 void OnLeftClick(wxMouseEvent
& event
);
1841 void OnLeftUp(wxMouseEvent
& event
);
1844 void OnMoveMouse(wxMouseEvent
& event
);
1846 // Left-double-click
1847 void OnLeftDClick(wxMouseEvent
& event
);
1850 void OnMiddleClick(wxMouseEvent
& event
);
1853 void OnRightClick(wxMouseEvent
& event
);
1856 void OnChar(wxKeyEvent
& event
);
1859 void OnSize(wxSizeEvent
& event
);
1861 // Setting/losing focus
1862 void OnSetFocus(wxFocusEvent
& event
);
1863 void OnKillFocus(wxFocusEvent
& event
);
1865 // Idle-time processing
1866 void OnIdle(wxIdleEvent
& event
);
1869 void OnScroll(wxScrollWinEvent
& event
);
1872 Sets the font, and also the basic and default attributes
1873 (see wxRichTextCtrl::SetDefaultStyle).
1875 virtual bool SetFont(const wxFont
& font
);
1878 A helper function setting up scrollbars, for example after a resize.
1880 virtual void SetupScrollbars(bool atTop
= false);
1883 Helper function implementing keyboard navigation.
1885 virtual bool KeyboardNavigate(int keyCode
, int flags
);
1888 Paints the background.
1890 virtual void PaintBackground(wxDC
& dc
);
1893 Other user defined painting after everything else (i.e.\ all text) is painted.
1897 virtual void PaintAboveContent(wxDC
& WXUNUSED(dc
)) {}
1899 #if wxRICHTEXT_BUFFERED_PAINTING
1901 Recreates the buffer bitmap if necessary.
1903 virtual bool RecreateBuffer(const wxSize
& size
= wxDefaultSize
);
1907 virtual void DoWriteText(const wxString
& value
, int flags
= 0);
1909 // Should we inherit colours?
1910 virtual bool ShouldInheritColours() const;
1913 Internal function to position the visible caret according to the current caret
1916 virtual void PositionCaret(wxRichTextParagraphLayoutBox
* container
= NULL
);
1919 Helper function for extending the selection, returning @true if the selection
1920 was changed. Selections are in caret positions.
1922 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
1925 Scrolls @a position into view. This function takes a caret position.
1927 virtual bool ScrollIntoView(long position
, int keyCode
);
1930 Refreshes the area affected by a selection change.
1932 bool RefreshForSelectionChange(const wxRichTextSelection
& oldSelection
, const wxRichTextSelection
& newSelection
);
1935 Sets the caret position.
1937 The caret position is the character position just before the caret.
1938 A value of -1 means the caret is at the start of the buffer.
1939 Please note that this does not update the current editing style
1940 from the new position or cause the actual caret to be refreshed; to do that,
1941 call wxRichTextCtrl::SetInsertionPoint instead.
1943 void SetCaretPosition(long position
, bool showAtLineStart
= false) ;
1946 Returns the current caret position.
1948 long GetCaretPosition() const;
1951 The adjusted caret position is the character position adjusted to take
1952 into account whether we're at the start of a paragraph, in which case
1953 style information should be taken from the next position, not current one.
1955 long GetAdjustedCaretPosition(long caretPos
) const;
1958 Move the caret one visual step forward: this may mean setting a flag
1959 and keeping the same position if we're going from the end of one line
1960 to the start of the next, which may be the exact same caret position.
1962 void MoveCaretForward(long oldPosition
) ;
1965 Move the caret one visual step forward: this may mean setting a flag
1966 and keeping the same position if we're going from the end of one line
1967 to the start of the next, which may be the exact same caret position.
1969 void MoveCaretBack(long oldPosition
) ;
1972 Returns the caret height and position for the given character position.
1973 If container is null, the current focus object will be used.
1976 In wxPerl this method is implemented as
1977 GetCaretPositionForIndex(@a position) returning a
1978 2-element list (ok, rect).
1981 bool GetCaretPositionForIndex(long position
, wxRect
& rect
, wxRichTextParagraphLayoutBox
* container
= NULL
);
1984 Internal helper function returning the line for the visible caret position.
1985 If the caret is shown at the very end of the line, it means the next character
1986 is actually on the following line.
1987 So this function gets the line we're expecting to find if this is the case.
1989 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
1992 Gets the command processor associated with the control's buffer.
1994 wxCommandProcessor
* GetCommandProcessor() const;
1997 Deletes content if there is a selection, e.g. when pressing a key.
1998 Returns the new caret position in @e newPos, or leaves it if there
1999 was no action. This is undoable.
2002 In wxPerl this method takes no arguments and returns a 2-element
2006 bool DeleteSelectedContent(long* newPos
= NULL
);
2009 Transforms logical (unscrolled) position to physical window position.
2011 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
2014 Transforms physical window position to logical (unscrolled) position.
2016 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
2019 Helper function for finding the caret position for the next word.
2020 Direction is 1 (forward) or -1 (backwards).
2022 virtual long FindNextWordPosition(int direction
= 1) const;
2025 Returns @true if the given position is visible on the screen.
2027 bool IsPositionVisible(long pos
) const;
2030 Returns the first visible position in the current view.
2032 long GetFirstVisiblePosition() const;
2035 Returns the caret position since the default formatting was changed. As
2036 soon as this position changes, we no longer reflect the default style
2037 in the UI. A value of -2 means that we should only reflect the style of the
2038 content under the caret.
2040 long GetCaretPositionForDefaultStyle() const;
2043 Set the caret position for the default style that the user is selecting.
2045 void SetCaretPositionForDefaultStyle(long pos
);
2048 Returns @true if the user has recently set the default style without moving
2049 the caret, and therefore the UI needs to reflect the default style and not
2050 the style at the caret.
2052 Below is an example of code that uses this function to determine whether the UI
2053 should show that the current style is bold.
2055 @see SetAndShowDefaultStyle().
2057 bool IsDefaultStyleShowing() const;
2060 Sets @a attr as the default style and tells the control that the UI should
2061 reflect this attribute until the user moves the caret.
2063 @see IsDefaultStyleShowing().
2065 void SetAndShowDefaultStyle(const wxRichTextAttr
& attr
);
2068 Returns the first visible point in the window.
2070 wxPoint
GetFirstVisiblePoint() const;
2073 Returns the content of the entire control as a string.
2075 virtual wxString
GetValue() const;
2078 Replaces existing content with the given text.
2080 virtual void SetValue(const wxString
& value
);
2086 Processes the back key.
2088 virtual bool ProcessBackKey(wxKeyEvent
& event
, int flags
);
2091 Given a character position at which there is a list style, find the range
2092 encompassing the same list style by looking backwards and forwards.
2094 virtual wxRichTextRange
FindRangeForList(long pos
, bool& isNumberedList
);
2097 Sets up the caret for the given position and container, after a mouse click.
2099 bool SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox
* container
, long position
, int hitTestFlags
, bool extendSelection
= false);
2102 Find the caret position for the combination of hit-test flags and character position.
2103 Returns the caret position and also an indication of where to place the caret (caretLineStart)
2104 since this is ambiguous (same position used for end of line and start of next).
2106 long FindCaretPositionForCharacterPosition(long position
, int hitTestFlags
, wxRichTextParagraphLayoutBox
* container
,
2107 bool& caretLineStart
);
2110 Processes mouse movement in order to change the cursor
2112 virtual bool ProcessMouseMovement(wxRichTextParagraphLayoutBox
* container
, wxRichTextObject
* obj
, long position
, const wxPoint
& pos
);
2115 Font names take a long time to retrieve, so cache them (on demand).
2117 static const wxArrayString
& GetAvailableFontNames();
2120 Clears the cache of available font names.
2122 static void ClearAvailableFontNames();
2124 // implement wxTextEntry methods
2125 virtual wxString
DoGetValue() const;
2128 // implement the wxTextEntry pure virtual method
2129 virtual wxWindow
*GetEditableWindow();
2131 // margins functions
2132 virtual bool DoSetMargins(const wxPoint
& pt
);
2133 virtual wxPoint
DoGetMargins() const;
2140 Currently this simply returns @c wxSize(10, 10).
2142 virtual wxSize
DoGetBestSize() const ;
2144 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
2146 virtual void DoThaw();
2151 #if wxRICHTEXT_BUFFERED_PAINTING
2153 wxBitmap m_bufferBitmap
;
2157 wxRichTextBuffer m_buffer
;
2159 wxMenu
* m_contextMenu
;
2161 /// Caret position (1 less than the character position, so -1 is the
2162 /// first caret position).
2163 long m_caretPosition
;
2165 /// Caret position when the default formatting has been changed. As
2166 /// soon as this position changes, we no longer reflect the default style
2168 long m_caretPositionForDefaultStyle
;
2170 /// Selection range in character positions. -2, -2 means no selection.
2171 wxRichTextSelection m_selection
;
2173 wxRichTextCtrlSelectionState m_selectionState
;
2175 /// Anchor so we know how to extend the selection
2176 /// It's a caret position since it's between two characters.
2177 long m_selectionAnchor
;
2179 /// Anchor object if selecting multiple container objects, such as grid cells.
2180 wxRichTextObject
* m_selectionAnchorObject
;
2182 /// Are we editable?
2185 /// Are we showing the caret position at the start of a line
2186 /// instead of at the end of the previous one?
2187 bool m_caretAtLineStart
;
2189 /// Are we dragging a selection?
2192 /// Do we need full layout in idle?
2193 bool m_fullLayoutRequired
;
2194 wxLongLong m_fullLayoutTime
;
2195 long m_fullLayoutSavedPosition
;
2197 /// Threshold for doing delayed layout
2198 long m_delayedLayoutThreshold
;
2201 wxCursor m_textCursor
;
2202 wxCursor m_urlCursor
;
2204 static wxArrayString sm_availableFontNames
;
2206 wxRichTextContextMenuPropertiesInfo m_contextMenuPropertiesInfo
;
2208 /// The object that currently has the editing focus
2209 wxRichTextParagraphLayoutBox
* m_focusObject
;
2213 @class wxRichTextEvent
2215 This is the event class for wxRichTextCtrl notifications.
2217 @beginEventTable{wxRichTextEvent}
2218 @event{EVT_RICHTEXT_LEFT_CLICK(id, func)}
2219 Process a @c wxEVT_RICHTEXT_LEFT_CLICK event, generated when the user
2220 releases the left mouse button over an object.
2221 @event{EVT_RICHTEXT_RIGHT_CLICK(id, func)}
2222 Process a @c wxEVT_RICHTEXT_RIGHT_CLICK event, generated when the user
2223 releases the right mouse button over an object.
2224 @event{EVT_RICHTEXT_MIDDLE_CLICK(id, func)}
2225 Process a @c wxEVT_RICHTEXT_MIDDLE_CLICK event, generated when the user
2226 releases the middle mouse button over an object.
2227 @event{EVT_RICHTEXT_LEFT_DCLICK(id, func)}
2228 Process a @c wxEVT_RICHTEXT_LEFT_DCLICK event, generated when the user
2229 double-clicks an object.
2230 @event{EVT_RICHTEXT_RETURN(id, func)}
2231 Process a @c wxEVT_RICHTEXT_RETURN event, generated when the user
2232 presses the return key. Valid event functions: GetFlags, GetPosition.
2233 @event{EVT_RICHTEXT_CHARACTER(id, func)}
2234 Process a @c wxEVT_RICHTEXT_CHARACTER event, generated when the user
2235 presses a character key. Valid event functions: GetFlags, GetPosition, GetCharacter.
2236 @event{EVT_RICHTEXT_DELETE(id, func)}
2237 Process a @c wxEVT_RICHTEXT_DELETE event, generated when the user
2238 presses the backspace or delete key. Valid event functions: GetFlags, GetPosition.
2239 @event{EVT_RICHTEXT_RETURN(id, func)}
2240 Process a @c wxEVT_RICHTEXT_RETURN event, generated when the user
2241 presses the return key. Valid event functions: GetFlags, GetPosition.
2242 @event{EVT_RICHTEXT_STYLE_CHANGED(id, func)}
2243 Process a @c wxEVT_RICHTEXT_STYLE_CHANGED event, generated when
2244 styling has been applied to the control. Valid event functions: GetPosition, GetRange.
2245 @event{EVT_RICHTEXT_STYLESHEET_CHANGED(id, func)}
2246 Process a @c wxEVT_RICHTEXT_STYLESHEET_CHANGING event, generated
2247 when the control's stylesheet has changed, for example the user added,
2248 edited or deleted a style. Valid event functions: GetRange, GetPosition.
2249 @event{EVT_RICHTEXT_STYLESHEET_REPLACING(id, func)}
2250 Process a @c wxEVT_RICHTEXT_STYLESHEET_REPLACING event, generated
2251 when the control's stylesheet is about to be replaced, for example when
2252 a file is loaded into the control.
2253 Valid event functions: Veto, GetOldStyleSheet, GetNewStyleSheet.
2254 @event{EVT_RICHTEXT_STYLESHEET_REPLACED(id, func)}
2255 Process a @c wxEVT_RICHTEXT_STYLESHEET_REPLACED event, generated
2256 when the control's stylesheet has been replaced, for example when a file
2257 is loaded into the control.
2258 Valid event functions: GetOldStyleSheet, GetNewStyleSheet.
2259 @event{EVT_RICHTEXT_PROPERTIES_CHANGED(id, func)}
2260 Process a @c wxEVT_RICHTEXT_PROPERTIES_CHANGED event, generated when
2261 properties have been applied to the control. Valid event functions: GetPosition, GetRange.
2262 @event{EVT_RICHTEXT_CONTENT_INSERTED(id, func)}
2263 Process a @c wxEVT_RICHTEXT_CONTENT_INSERTED event, generated when
2264 content has been inserted into the control.
2265 Valid event functions: GetPosition, GetRange.
2266 @event{EVT_RICHTEXT_CONTENT_DELETED(id, func)}
2267 Process a @c wxEVT_RICHTEXT_CONTENT_DELETED event, generated when
2268 content has been deleted from the control.
2269 Valid event functions: GetPosition, GetRange.
2270 @event{EVT_RICHTEXT_BUFFER_RESET(id, func)}
2271 Process a @c wxEVT_RICHTEXT_BUFFER_RESET event, generated when the
2272 buffer has been reset by deleting all content.
2273 You can use this to set a default style for the first new paragraph.
2274 @event{EVT_RICHTEXT_SELECTION_CHANGED(id, func)}
2275 Process a @c wxEVT_RICHTEXT_SELECTION_CHANGED event, generated when the
2276 selection range has changed.
2277 @event{EVT_RICHTEXT_FOCUS_OBJECT_CHANGED(id, func)}
2278 Process a @c wxEVT_RICHTEXT_FOCUS_OBJECT_CHANGED event, generated when the
2279 current focus object has changed.
2282 @library{wxrichtext}
2283 @category{events,richtext}
2286 class wxRichTextEvent
: public wxNotifyEvent
2293 The type of the event.
2295 Window identifier. The value @c wxID_ANY indicates a default value.
2297 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0);
2302 wxRichTextEvent(const wxRichTextEvent
& event
);
2305 Returns the buffer position at which the event occurred.
2307 long GetPosition() const;
2310 Sets the buffer position variable.
2312 void SetPosition(long pos
);
2315 Returns flags indicating modifier keys pressed.
2317 Possible values are @c wxRICHTEXT_CTRL_DOWN, @c wxRICHTEXT_SHIFT_DOWN, and @c wxRICHTEXT_ALT_DOWN.
2319 int GetFlags() const;
2322 Sets flags indicating modifier keys pressed.
2324 Possible values are @c wxRICHTEXT_CTRL_DOWN, @c wxRICHTEXT_SHIFT_DOWN, and @c wxRICHTEXT_ALT_DOWN.
2326 void SetFlags(int flags
);
2329 Returns the old style sheet.
2331 Can be used in a @c wxEVT_RICHTEXT_STYLESHEET_CHANGING or
2332 @c wxEVT_RICHTEXT_STYLESHEET_CHANGED event handler.
2334 wxRichTextStyleSheet
* GetOldStyleSheet() const;
2337 Sets the old style sheet variable.
2339 void SetOldStyleSheet(wxRichTextStyleSheet
* sheet
);
2342 Returns the new style sheet.
2344 Can be used in a @c wxEVT_RICHTEXT_STYLESHEET_CHANGING or
2345 @c wxEVT_RICHTEXT_STYLESHEET_CHANGED event handler.
2347 wxRichTextStyleSheet
* GetNewStyleSheet() const;
2350 Sets the new style sheet variable.
2352 void SetNewStyleSheet(wxRichTextStyleSheet
* sheet
);
2355 Gets the range for the current operation.
2357 const wxRichTextRange
& GetRange() const;
2360 Sets the range variable.
2362 void SetRange(const wxRichTextRange
& range
);
2365 Returns the character pressed, within a @c wxEVT_RICHTEXT_CHARACTER event.
2367 wxChar
GetCharacter() const;
2370 Sets the character variable.
2372 void SetCharacter(wxChar ch
);
2375 Returns the container for which the event is relevant.
2377 wxRichTextParagraphLayoutBox
* GetContainer() const;
2380 Sets the container for which the event is relevant.
2382 void SetContainer(wxRichTextParagraphLayoutBox
* container
);
2385 Returns the old container, for a focus change event.
2387 wxRichTextParagraphLayoutBox
* GetOldContainer() const;
2390 Sets the old container, for a focus change event.
2392 void SetOldContainer(wxRichTextParagraphLayoutBox
* container
);
2394 virtual wxEvent
*Clone() const;
2399 wxRichTextStyleSheet
* m_oldStyleSheet
;
2400 wxRichTextStyleSheet
* m_newStyleSheet
;
2401 wxRichTextRange m_range
;
2403 wxRichTextParagraphLayoutBox
* m_container
;
2404 wxRichTextParagraphLayoutBox
* m_oldContainer
;
2409 wxEventType wxEVT_RICHTEXT_LEFT_CLICK
;
2410 wxEventType wxEVT_RICHTEXT_RIGHT_CLICK
;
2411 wxEventType wxEVT_RICHTEXT_MIDDLE_CLICK
;
2412 wxEventType wxEVT_RICHTEXT_LEFT_DCLICK
;
2413 wxEventType wxEVT_RICHTEXT_RETURN
;
2414 wxEventType wxEVT_RICHTEXT_CHARACTER
;
2415 wxEventType wxEVT_RICHTEXT_DELETE
;
2417 wxEventType wxEVT_RICHTEXT_STYLESHEET_CHANGING
;
2418 wxEventType wxEVT_RICHTEXT_STYLESHEET_CHANGED
;
2419 wxEventType wxEVT_RICHTEXT_STYLESHEET_REPLACING
;
2420 wxEventType wxEVT_RICHTEXT_STYLESHEET_REPLACED
;
2422 wxEventType wxEVT_RICHTEXT_CONTENT_INSERTED
;
2423 wxEventType wxEVT_RICHTEXT_CONTENT_DELETED
;
2424 wxEventType wxEVT_RICHTEXT_STYLE_CHANGED
;
2425 wxEventType wxEVT_RICHTEXT_PROPERTIES_CHANGED
;
2426 wxEventType wxEVT_RICHTEXT_SELECTION_CHANGED
;
2427 wxEventType wxEVT_RICHTEXT_BUFFER_RESET
;
2428 wxEventType wxEVT_RICHTEXT_FOCUS_OBJECT_CHANGED
;