1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextbuffer.h
3 // Purpose: interface of wxRichTextBuffer
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 * File types in wxRichText context.
14 enum wxRichTextFileType
16 wxRICHTEXT_TYPE_ANY
= 0,
25 * Flags determining the available space, passed to Layout
28 #define wxRICHTEXT_FIXED_WIDTH 0x01
29 #define wxRICHTEXT_FIXED_HEIGHT 0x02
30 #define wxRICHTEXT_VARIABLE_WIDTH 0x04
31 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
33 // Only lay out the part of the buffer that lies within
34 // the rect passed to Layout.
35 #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
38 * Flags to pass to Draw
41 // Ignore paragraph cache optimization, e.g. for printing purposes
42 // where one line may be drawn higher (on the next page) compared
43 // with the previous line
44 #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01
47 * Flags returned from hit-testing
49 enum wxRichTextHitTestFlags
51 /// The point was not on this object
52 wxRICHTEXT_HITTEST_NONE
= 0x01,
54 /// The point was before the position returned from HitTest
55 wxRICHTEXT_HITTEST_BEFORE
= 0x02,
57 /// The point was after the position returned from HitTest
58 wxRICHTEXT_HITTEST_AFTER
= 0x04,
60 /// The point was on the position returned from HitTest
61 wxRICHTEXT_HITTEST_ON
= 0x08,
63 /// The point was on space outside content
64 wxRICHTEXT_HITTEST_OUTSIDE
= 0x10
68 * Flags for GetRangeSize
71 #define wxRICHTEXT_FORMATTED 0x01
72 #define wxRICHTEXT_UNFORMATTED 0x02
73 #define wxRICHTEXT_CACHE_SIZE 0x04
74 #define wxRICHTEXT_HEIGHT_ONLY 0x08
77 * Flags for SetStyle/SetListStyle
80 #define wxRICHTEXT_SETSTYLE_NONE 0x00
82 // Specifies that this operation should be undoable
83 #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
85 // Specifies that the style should not be applied if the
86 // combined style at this point is already the style in question.
87 #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
89 // Specifies that the style should only be applied to paragraphs,
90 // and not the content. This allows content styling to be
91 // preserved independently from that of e.g. a named paragraph style.
92 #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
94 // Specifies that the style should only be applied to characters,
95 // and not the paragraph. This allows content styling to be
96 // preserved independently from that of e.g. a named paragraph style.
97 #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
99 // For SetListStyle only: specifies starting from the given number, otherwise
100 // deduces number from existing attributes
101 #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
103 // For SetListStyle only: specifies the list level for all paragraphs, otherwise
104 // the current indentation will be used
105 #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
107 // Resets the existing style before applying the new style
108 #define wxRICHTEXT_SETSTYLE_RESET 0x40
110 // Removes the given style instead of applying it
111 #define wxRICHTEXT_SETSTYLE_REMOVE 0x80
114 * Flags for text insertion
117 #define wxRICHTEXT_INSERT_NONE 0x00
118 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
119 #define wxRICHTEXT_INSERT_INTERACTIVE 0x02
121 // A special flag telling the buffer to keep the first paragraph style
122 // as-is, when deleting a paragraph marker. In future we might pass a
123 // flag to InsertFragment and DeleteRange to indicate the appropriate mode.
124 #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000
127 * Default superscript/subscript font multiplication factor
130 #define wxSCRIPT_MUL_FACTOR 1.5
134 @class wxRichTextBuffer
136 This class represents the whole buffer associated with a wxRichTextCtrl.
141 @see wxTextAttr, wxRichTextCtrl
143 class wxRichTextBuffer
: public wxRichTextParagraphLayoutBox
154 wxRichTextBuffer(const wxRichTextBuffer
& obj
);
159 virtual ~wxRichTextBuffer();
162 Adds an event handler to the buffer's list of handlers.
164 A buffer associated with a control has the control as the only event handler,
165 but the application is free to add more if further notification is required.
166 All handlers are notified of an event originating from the buffer, such as
167 the replacement of a style sheet during loading.
169 The buffer never deletes any of the event handlers, unless RemoveEventHandler()
170 is called with @true as the second argument.
172 bool AddEventHandler(wxEvtHandler
* handler
);
177 static void AddHandler(wxRichTextFileHandler
* handler
);
180 Adds a paragraph of text.
182 virtual wxRichTextRange
AddParagraph(const wxString
& text
,
183 wxTextAttr
* paraStyle
= 0);
186 Returns @true if the buffer is currently collapsing commands into a single
189 virtual bool BatchingUndo() const;
192 Begins using alignment.
194 bool BeginAlignment(wxTextAttrAlignment alignment
);
197 Begins collapsing undo/redo commands. Note that this may not work properly
198 if combining commands that delete or insert content, changing ranges for
201 @a cmdName should be the name of the combined command that will appear
202 next to Undo and Redo in the edit menu.
204 virtual bool BeginBatchUndo(const wxString
& cmdName
);
212 Begins applying the named character style.
214 bool BeginCharacterStyle(const wxString
& characterStyle
);
217 Begins using this font.
219 bool BeginFont(const wxFont
& font
);
222 Begins using the given point size.
224 bool BeginFontSize(int pointSize
);
232 Begin using @a leftIndent for the left indent, and optionally @a leftSubIndent for
233 the sub-indent. Both are expressed in tenths of a millimetre.
235 The sub-indent is an offset from the left of the paragraph, and is used for all
236 but the first line in a paragraph. A positive value will cause the first line to appear
237 to the left of the subsequent lines, and a negative value will cause the first line to be
238 indented relative to the subsequent lines.
240 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
243 Begins line spacing using the specified value. @e spacing is a multiple, where
244 10 means single-spacing, 15 means 1.5 spacing, and 20 means double spacing.
246 The ::wxTextAttrLineSpacing enumeration values are defined for convenience.
248 bool BeginLineSpacing(int lineSpacing
);
251 Begins using a specified list style.
252 Optionally, you can also pass a level and a number.
254 bool BeginListStyle(const wxString
& listStyle
, int level
= 1,
258 Begins a numbered bullet.
260 This call will be needed for each item in the list, and the
261 application should take care of incrementing the numbering.
263 @a bulletNumber is a number, usually starting with 1.
264 @a leftIndent and @a leftSubIndent are values in tenths of a millimetre.
265 @a bulletStyle is a bitlist of the following values:
267 wxRichTextBuffer uses indentation to render a bulleted item.
268 The left indent is the distance between the margin and the bullet.
269 The content of the paragraph, including the first line, starts
270 at leftMargin + leftSubIndent.
271 So the distance between the left edge of the bullet and the
272 left of the actual paragraph is leftSubIndent.
274 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
,
276 int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
279 Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing
280 in tenths of a millimetre.
282 bool BeginParagraphSpacing(int before
, int after
);
285 Begins applying the named paragraph style.
287 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
290 Begins a right indent, specified in tenths of a millimetre.
292 bool BeginRightIndent(int rightIndent
);
295 Begins applying a standard bullet, using one of the standard bullet names
296 (currently @c standard/circle or @c standard/square.
298 See BeginNumberedBullet() for an explanation of how indentation is used to
299 render the bulleted paragraph.
301 bool BeginStandardBullet(const wxString
& bulletName
,
304 int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
);
307 Begins using a specified style.
309 virtual bool BeginStyle(const wxTextAttr
& style
);
312 Begins suppressing undo/redo commands. The way undo is suppressed may be
313 implemented differently by each command.
314 If not dealt with by a command implementation, then it will be implemented
315 automatically by not storing the command in the undo history when the
316 action is submitted to the command processor.
318 virtual bool BeginSuppressUndo();
321 Begins applying a symbol bullet, using a character from the current font.
323 See BeginNumberedBullet() for an explanation of how indentation is used
324 to render the bulleted paragraph.
326 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
,
328 int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
331 Begins using the specified text foreground colour.
333 bool BeginTextColour(const wxColour
& colour
);
336 Begins applying wxTEXT_ATTR_URL to the content.
338 Pass a URL and optionally, a character style to apply, since it is common
339 to mark a URL with a familiar style such as blue text with underlining.
341 bool BeginURL(const wxString
& url
,
342 const wxString
& characterStyle
= wxEmptyString
);
345 Begins using underline.
347 bool BeginUnderline();
350 Returns @true if content can be pasted from the clipboard.
352 virtual bool CanPasteFromClipboard() const;
355 Cleans up the file handlers.
357 static void CleanUpHandlers();
362 virtual void Clear();
366 Clears the list style from the given range, clearing list-related attributes
367 and applying any named paragraph style associated with each paragraph.
369 @a flags is a bit list of the following:
370 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
372 @see SetListStyle(), PromoteList(), NumberList()
374 bool ClearListStyle(const wxRichTextRange
& range
,
375 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
376 bool ClearListStyle(const wxRichTextRange
& range
,
377 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
381 Clears the style stack.
383 virtual void ClearStyleStack();
388 virtual wxRichTextObject
* Clone() const;
391 Copies the given buffer.
393 void Copy(const wxRichTextBuffer
& obj
);
396 Copy the given range to the clipboard.
398 virtual bool CopyToClipboard(const wxRichTextRange
& range
);
401 Submits a command to delete the given range.
403 bool DeleteRangeWithUndo(const wxRichTextRange
& range
,
404 wxRichTextCtrl
* ctrl
);
408 Dumps the contents of the buffer for debugging purposes.
411 void Dump(wxTextOutputStream
& stream
);
420 Ends all styles that have been started with a Begin... command.
422 virtual bool EndAllStyles();
425 Ends collapsing undo/redo commands, and submits the combined command.
427 virtual bool EndBatchUndo();
435 Ends using the named character style.
437 bool EndCharacterStyle();
445 Ends using a point size.
455 Ends using a left indent.
457 bool EndLeftIndent();
460 Ends using a line spacing.
462 bool EndLineSpacing();
465 Ends using a specified list style.
470 Ends a numbered bullet.
472 bool EndNumberedBullet();
475 Ends paragraph spacing.
477 bool EndParagraphSpacing();
480 Ends applying a named character style.
482 bool EndParagraphStyle();
485 Ends using a right indent.
487 bool EndRightIndent();
490 Ends using a standard bullet.
492 bool EndStandardBullet();
495 Ends the current style.
497 virtual bool EndStyle();
500 Ends suppressing undo/redo commands.
502 virtual bool EndSuppressUndo();
505 Ends using a symbol bullet.
507 bool EndSymbolBullet();
510 Ends using a text foreground colour.
512 bool EndTextColour();
520 Ends using underline.
525 Finds a handler by type.
527 static wxRichTextFileHandler
* FindHandler(wxRichTextFileType imageType
);
530 Finds a handler by extension and type.
532 static wxRichTextFileHandler
* FindHandler(const wxString
& extension
, wxRichTextFileType imageType
);
535 Finds a handler by name.
537 static wxRichTextFileHandler
* FindHandler(const wxString
& name
);
540 Finds a handler by filename or, if supplied, type.
542 static wxRichTextFileHandler
* FindHandlerFilenameOrType(const wxString
& filename
, wxRichTextFileType imageType
);
545 Gets the basic (overall) style.
547 This is the style of the whole buffer before further styles are applied,
548 unlike the default style, which only affects the style currently being
549 applied (for example, setting the default style to bold will cause
550 subsequently inserted text to be bold).
552 virtual const wxTextAttr
& GetBasicStyle() const;
555 Gets the collapsed command.
557 virtual wxRichTextCommand
* GetBatchedCommand() const;
560 Gets the command processor.
561 A text buffer always creates its own command processor when it is initialized.
563 wxCommandProcessor
* GetCommandProcessor() const;
566 Returns the current default style, affecting the style currently being applied
567 (for example, setting the default style to bold will cause subsequently
568 inserted text to be bold).
570 virtual const wxTextAttr
& GetDefaultStyle() const;
573 Gets a wildcard incorporating all visible handlers.
574 If @a types is present, it will be filled with the file type corresponding
575 to each filter. This can be used to determine the type to pass to LoadFile()
576 given a selected filter.
578 static wxString
GetExtWildcard(bool combine
= false, bool save
= false,
579 wxArrayInt
* types
= NULL
);
582 Returns the list of file handlers.
584 static wxList
& GetHandlers();
587 Returns the object to be used to render certain aspects of the content, such as
590 static wxRichTextRenderer
* GetRenderer();
593 Gets the attributes at the given position.
595 This function gets the combined style - that is, the style you see on the
596 screen as a result of combining base style, paragraph style and character
597 style attributes. To get the character or paragraph style alone,
598 use GetUncombinedStyle().
600 virtual bool GetStyle(long position
, wxTextAttr
& style
);
603 This function gets a style representing the common, combined attributes in the
605 Attributes which have different values within the specified range will not be
606 included the style flags.
608 The function is used to get the attributes to display in the formatting dialog:
609 the user can edit the attributes common to the selection, and optionally specify the
610 values of further attributes to be applied uniformly.
612 To apply the edited attributes, you can use SetStyle() specifying
613 the wxRICHTEXT_SETSTYLE_OPTIMIZE flag, which will only apply attributes that
614 are different from the @e combined attributes within the range.
615 So, the user edits the effective, displayed attributes for the range,
616 but his choice won't be applied unnecessarily to content. As an example,
617 say the style for a paragraph specifies bold, but the paragraph text doesn't
619 The combined style is bold, and this is what the user will see on-screen and
620 in the formatting dialog. The user now specifies red text, in addition to bold.
621 When applying with SetStyle(), the content font weight attributes won't be
622 changed to bold because this is already specified by the paragraph.
623 However the text colour attributes @e will be changed to show red.
625 virtual bool GetStyleForRange(const wxRichTextRange
& range
,
629 Returns the current style sheet associated with the buffer, if any.
631 virtual wxRichTextStyleSheet
* GetStyleSheet() const;
634 Get the size of the style stack, for example to check correct nesting.
636 virtual size_t GetStyleStackSize() const;
639 Gets the attributes at the given position.
641 This function gets the @e uncombined style - that is, the attributes associated
642 with the paragraph or character content, and not necessarily the combined
643 attributes you see on the screen. To get the combined attributes, use GetStyle().
644 If you specify (any) paragraph attribute in @e style's flags, this function
645 will fetch the paragraph attributes.
646 Otherwise, it will return the character attributes.
648 virtual bool GetUncombinedStyle(long position
, wxTextAttr
& style
);
651 Finds the text position for the given position, putting the position in
652 @a textPosition if one is found.
653 @a pt is in logical units (a zero y position is at the beginning of the buffer).
655 @return One of the ::wxRichTextHitTestFlags values.
657 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
665 Initialises the standard handlers.
666 Currently, only the plain text loading/saving handler is initialised by default.
668 static void InitStandardHandlers();
671 Inserts a handler at the front of the list.
673 static void InsertHandler(wxRichTextFileHandler
* handler
);
676 Submits a command to insert the given image.
678 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
,
679 wxRichTextCtrl
* ctrl
, int flags
= 0);
682 Submits a command to insert a newline.
684 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, int flags
= 0);
687 Submits a command to insert the given text.
689 bool InsertTextWithUndo(long pos
, const wxString
& text
,
690 wxRichTextCtrl
* ctrl
, int flags
= 0);
693 Returns @true if the buffer has been modified.
695 bool IsModified() const;
698 Loads content from a stream.
700 virtual bool LoadFile(wxInputStream
& stream
,
701 wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
704 Loads content from a file.
706 virtual bool LoadFile(const wxString
& filename
,
707 wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
710 Marks the buffer as modified or unmodified.
712 void Modify(bool modify
= true);
716 Numbers the paragraphs in the given range.
718 Pass flags to determine how the attributes are set.
719 Either the style definition or the name of the style definition (in the current
720 sheet) can be passed.
722 @a flags is a bit list of the following:
723 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
724 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
725 @a startFrom, otherwise existing attributes are used.
726 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
727 as the level for all paragraphs, otherwise the current indentation will be used.
729 @see SetListStyle(), PromoteList(), ClearListStyle()
731 bool NumberList(const wxRichTextRange
& range
,
732 const wxRichTextListStyleDefinition
* style
,
733 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
736 bool Number(const wxRichTextRange
& range
,
737 const wxString
& styleName
,
738 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
744 Pastes the clipboard content to the buffer at the given position.
746 virtual bool PasteFromClipboard(long position
);
750 Promotes or demotes the paragraphs in the given range.
752 A positive @a promoteBy produces a smaller indent, and a negative number
753 produces a larger indent. Pass flags to determine how the attributes are set.
754 Either the style definition or the name of the style definition (in the current
755 sheet) can be passed.
757 @a flags is a bit list of the following:
758 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
759 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
760 @a startFrom, otherwise existing attributes are used.
761 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
762 as the level for all paragraphs, otherwise the current indentation will be used.
764 @see SetListStyle(), SetListStyle(), ClearListStyle()
766 bool PromoteList(int promoteBy
, const wxRichTextRange
& range
,
767 const wxRichTextListStyleDefinition
* style
,
768 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
770 bool PromoteList(int promoteBy
, const wxRichTextRange
& range
,
771 const wxString
& styleName
,
772 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
777 Removes an event handler from the buffer's list of handlers, deleting the
778 object if @a deleteHandler is @true.
780 bool RemoveEventHandler(wxEvtHandler
* handler
,
781 bool deleteHandler
= false);
786 static bool RemoveHandler(const wxString
& name
);
789 Clears the buffer, adds a new blank paragraph, and clears the command history.
791 virtual void ResetAndClearCommands();
794 Saves content to a stream.
796 virtual bool SaveFile(wxOutputStream
& stream
,
797 wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
800 Saves content to a file.
802 virtual bool SaveFile(const wxString
& filename
,
803 wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
806 Sets the basic (overall) style. This is the style of the whole
807 buffer before further styles are applied, unlike the default style, which
808 only affects the style currently being applied (for example, setting the default
809 style to bold will cause subsequently inserted text to be bold).
811 virtual void SetBasicStyle(const wxTextAttr
& style
);
814 Sets the default style, affecting the style currently being applied
815 (for example, setting the default style to bold will cause subsequently
816 inserted text to be bold).
818 This is not cumulative - setting the default style will replace the previous
821 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
825 Sets the list attributes for the given range, passing flags to determine how
826 the attributes are set.
827 Either the style definition or the name of the style definition (in the current
828 sheet) can be passed.
830 @a flags is a bit list of the following:
831 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
832 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
833 @a startFrom, otherwise existing attributes are used.
834 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
835 as the level for all paragraphs, otherwise the current indentation will be used.
837 @see NumberList(), PromoteList(), ClearListStyle().
839 bool SetListStyle(const wxRichTextRange
& range
,
840 const wxRichTextListStyleDefinition
* style
,
841 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
844 bool SetListStyle(const wxRichTextRange
& range
,
845 const wxString
& styleName
,
846 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
,
852 Sets @a renderer as the object to be used to render certain aspects of the
853 content, such as bullets.
855 You can override default rendering by deriving a new class from
856 wxRichTextRenderer or wxRichTextStdRenderer, overriding one or more
857 virtual functions, and setting an instance of the class using this function.
859 static void SetRenderer(wxRichTextRenderer
* renderer
);
862 Sets the attributes for the given range. Pass flags to determine how the
865 The end point of range is specified as the last character position of the span
866 of text. So, for example, to set the style for a character at position 5,
868 This differs from the wxRichTextCtrl API, where you would specify (5,6).
870 @a flags may contain a bit list of the following values:
871 - wxRICHTEXT_SETSTYLE_NONE: no style flag.
872 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
874 - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
875 if the combined style at this point is already the style in question.
876 - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
877 applied to paragraphs, and not the content.
878 This allows content styling to be preserved independently from that
879 of e.g. a named paragraph style.
880 - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
881 applied to characters, and not the paragraph.
882 This allows content styling to be preserved independently from that
883 of e.g. a named paragraph style.
884 - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
886 - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style.
887 Only the style flags are used in this operation.
889 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
,
890 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
893 Sets the current style sheet, if any.
895 This will allow the application to use named character and paragraph
896 styles found in the style sheet.
898 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
901 Submit an action immediately, or delay it according to whether collapsing is on.
903 virtual bool SubmitAction(wxRichTextAction
* action
);
906 Returns @true if undo suppression is currently on.
908 virtual bool SuppressingUndo() const;
914 @class wxRichTextFileHandler
916 This is the base class for file handlers, for loading and/or saving content
917 associated with a wxRichTextBuffer.
922 class wxRichTextFileHandler
: public wxObject
928 wxRichTextFileHandler(const wxString
& name
= wxEmptyString
,
929 const wxString
& ext
= wxEmptyString
,
933 Override this function and return @true if this handler can we handle
936 By default, this function checks the extension.
938 virtual bool CanHandle(const wxString
& filename
) const;
941 Override and return @true if this handler can load content.
943 virtual bool CanLoad() const;
946 Override and return @true if this handler can save content.
948 virtual bool CanSave() const;
951 Returns the encoding associated with the handler (if any).
953 const wxString
& GetEncoding() const;
956 Returns the extension associated with the handler.
958 wxString
GetExtension() const;
961 Returns flags that change the behaviour of loading or saving.
963 See the documentation for each handler class to see what flags are
964 relevant for each handler.
966 int GetFlags() const;
969 Returns the name of the handler.
971 wxString
GetName() const;
974 Returns the type of the handler.
979 Returns @true if this handler should be visible to the user.
981 virtual bool IsVisible() const;
985 Loads content from a stream or file.
986 Not all handlers will implement file loading.
988 bool LoadFile(wxRichTextBuffer
* buffer
, wxInputStream
& stream
);
989 bool LoadFile(wxRichTextBuffer
* buffer
, const wxString
& filename
);
994 Saves content to a stream or file.
995 Not all handlers will implement file saving.
997 bool SaveFile(wxRichTextBuffer
* buffer
, wxOutputStream
& stream
);
998 bool SaveFile(wxRichTextBuffer
* buffer
, const wxString
& filename
);
1002 Sets the encoding to use when saving a file.
1003 If empty, a suitable encoding is chosen.
1005 void SetEncoding(const wxString
& encoding
);
1008 Sets the default extension to recognise.
1010 void SetExtension(const wxString
& ext
);
1013 Sets flags that change the behaviour of loading or saving.
1014 See the documentation for each handler class to see what flags are relevant
1017 You call this function directly if you are using a file handler explicitly
1018 (without going through the text control or buffer LoadFile/SaveFile API).
1019 Or, you can call the control or buffer's SetHandlerFlags function to set
1020 the flags that will be used for subsequent load and save operations.
1022 void SetFlags(int flags
);
1025 Sets the name of the handler.
1027 void SetName(const wxString
& name
);
1030 Sets the handler type.
1032 void SetType(int type
);
1035 Sets whether the handler should be visible to the user (via the application's
1036 load and save dialogs).
1038 virtual void SetVisible(bool visible
);
1042 Override to load content from @a stream into @a buffer.
1044 virtual bool DoLoadFile(wxRichTextBuffer
* buffer
,
1045 wxInputStream
& stream
) = 0;
1048 Override to save content to @a stream from @a buffer.
1050 virtual bool DoSaveFile(wxRichTextBuffer
* buffer
,
1051 wxOutputStream
& stream
) = 0;
1057 @class wxRichTextRange
1059 This class stores beginning and end positions for a range of data.
1061 @library{wxrichtext}
1064 class wxRichTextRange
1071 wxRichTextRange(long start
, long end
);
1072 wxRichTextRange(const wxRichTextRange
& range
);
1082 Returns @true if the given position is within this range.
1083 Does not match if the range is empty.
1085 bool Contains(long pos
) const;
1088 Converts the internal range, which uses the first and last character positions
1089 of the range, to the API-standard range, whose end is one past the last
1090 character in the range.
1091 In other words, one is added to the end position.
1093 wxRichTextRange
FromInternal() const;
1096 Returns the end position.
1098 long GetEnd() const;
1101 Returns the length of the range.
1103 long GetLength() const;
1106 Returns the start of the range.
1108 long GetStart() const;
1111 Returns @true if this range is completely outside @e range.
1113 bool IsOutside(const wxRichTextRange
& range
) const;
1116 Returns @true if this range is completely within @e range.
1118 bool IsWithin(const wxRichTextRange
& range
) const;
1121 Limits this range to be within @e range.
1123 bool LimitTo(const wxRichTextRange
& range
);
1126 Sets the end of the range.
1128 void SetEnd(long end
);
1133 void SetRange(long start
, long end
);
1136 Sets the start of the range.
1138 void SetStart(long start
);
1141 Swaps the start and end.
1146 Converts the API-standard range, whose end is one past the last character in
1147 the range, to the internal form, which uses the first and last character
1148 positions of the range.
1149 In other words, one is subtracted from the end position.
1151 wxRichTextRange
ToInternal() const;
1154 Adds @a range to this range.
1156 wxRichTextRange
operator+(const wxRichTextRange
& range
) const;
1159 Subtracts @a range from this range.
1161 wxRichTextRange
operator-(const wxRichTextRange
& range
) const;
1164 Assigns @a range to this range.
1166 void operator=(const wxRichTextRange
& range
);
1169 Returns @true if @a range is the same as this range.
1171 bool operator==(const wxRichTextRange
& range
) const;