X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5d7836c47de679f03b1b7e738c77164c11bd3689..b20ca9976d1e6aeb1a1854fae362d3d68464433a:/include/wx/richtext/richtextbuffer.h?ds=sidebyside diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index f0b9a90dac..38c3b901c0 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -1,14 +1,17 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: richtextbuffer.h +// Name: wx/richtext/richtextbuffer.h // Purpose: Buffer for wxRichTextCtrl // Author: Julian Smart -// Modified by: +// Modified by: // Created: 2005-09-30 -// RCS-ID: +// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +#ifndef _WX_RICHTEXTBUFFER_H_ +#define _WX_RICHTEXTBUFFER_H_ + /* Data structures @@ -81,20 +84,20 @@ it can report a partial size, so that wrapping can be implemented, hit test calculations performed, etc. So GetRangeSize must be implemented for each object. - - */ -#ifndef _WX_RICHTEXTBUFFER_H_ -#define _WX_RICHTEXTBUFFER_H_ + */ /*! * Includes */ -#include "wx/list.h" +#include "wx/defs.h" #if wxUSE_RICHTEXT +#include "wx/list.h" +#include "wx/textctrl.h" +#include "wx/bitmap.h" #include "wx/image.h" #include "wx/cmdproc.h" #include "wx/txtstrm.h" @@ -114,16 +117,16 @@ * Forward declarations */ -class WXDLLIMPEXP_ADV wxRichTextCtrl; -class WXDLLIMPEXP_ADV wxRichTextObject; -class WXDLLIMPEXP_ADV wxRichTextCacheObject; -class WXDLLIMPEXP_ADV wxRichTextObjectList; -class WXDLLIMPEXP_ADV wxRichTextLine; -class WXDLLIMPEXP_ADV wxRichTextParagraph; -class WXDLLIMPEXP_ADV wxRichTextFragment; -class WXDLLIMPEXP_ADV wxRichTextFileHandler; -class WXDLLIMPEXP_ADV wxRichTextStyleSheet; -class WXDLLIMPEXP_ADV wxTextAttrEx; +class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl; +class WXDLLIMPEXP_RICHTEXT wxRichTextObject; +class WXDLLIMPEXP_RICHTEXT wxRichTextCacheObject; +class WXDLLIMPEXP_RICHTEXT wxRichTextObjectList; +class WXDLLIMPEXP_RICHTEXT wxRichTextLine; +class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph; +class WXDLLIMPEXP_RICHTEXT wxRichTextFragment; +class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler; +class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet; +class WXDLLIMPEXP_RICHTEXT wxTextAttrEx; /*! * Flags determining the available space, passed to Layout @@ -134,6 +137,10 @@ class WXDLLIMPEXP_ADV wxTextAttrEx; #define wxRICHTEXT_VARIABLE_WIDTH 0x04 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08 +// Only lay out the part of the buffer that lies within +// the rect passed to Layout. +#define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10 + /*! * Flags returned from hit-testing */ @@ -195,7 +202,7 @@ class WXDLLIMPEXP_ADV wxTextAttrEx; * This stores beginning and end positions for a range of data. */ -class WXDLLIMPEXP_ADV wxRichTextRange +class WXDLLIMPEXP_RICHTEXT wxRichTextRange { public: // Constructors @@ -206,6 +213,7 @@ public: ~wxRichTextRange() {} void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } + bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); } wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); } wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); } @@ -243,15 +251,19 @@ protected: long m_end; }; +#define wxRICHTEXT_ALL wxRichTextRange(-2, -2) +#define wxRICHTEXT_NONE wxRichTextRange(-1, -1) + /*! * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes. */ -class WXDLLIMPEXP_ADV wxTextAttrEx: public wxTextAttr +class WXDLLIMPEXP_RICHTEXT wxTextAttrEx: public wxTextAttr { public: // ctors wxTextAttrEx(const wxTextAttrEx& attr); + wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; } wxTextAttrEx() { Init(); } // Initialise this object. @@ -282,6 +294,12 @@ public: int GetBulletNumber() const { return m_bulletNumber; } wxChar GetBulletSymbol() const { return m_bulletSymbol; } + bool HasWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT) != 0; } + bool HasSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0; } + bool HasItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC) != 0; } + bool HasUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE) != 0; } + bool HasFaceName() const { return (GetFlags() & wxTEXT_ATTR_FONT_FACE) != 0; } + bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER); } bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE); } bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING); } @@ -305,6 +323,14 @@ public: !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() && !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol(); } + + // return the attribute having the valid font and colours: it uses the + // attributes set in attr and falls back first to attrDefault and then to + // the text control font/colours for those attributes which are not set + static wxTextAttrEx CombineEx(const wxTextAttrEx& attr, + const wxTextAttrEx& attrDef, + const wxTextCtrlBase *text); + private: // Paragraph styles int m_paragraphSpacingAfter; @@ -326,7 +352,7 @@ private: * efficient way to query styles. */ -class WXDLLIMPEXP_ADV wxRichTextAttr +class WXDLLIMPEXP_RICHTEXT wxRichTextAttr { public: // ctors @@ -446,6 +472,12 @@ public: !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol(); } + // return the attribute having the valid font and colours: it uses the + // attributes set in attr and falls back first to attrDefault and then to + // the text control font/colours for those attributes which are not set + static wxRichTextAttr Combine(const wxRichTextAttr& attr, + const wxRichTextAttr& attrDef, + const wxTextCtrlBase *text); private: long m_flags; @@ -481,20 +513,20 @@ private: wxString m_paragraphStyleName; }; -#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT) | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR +#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR) -#define wxTEXT_ATTR_PARAGRAPH wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\ +#define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\ wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\ - wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL + wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL) -#define wxTEXT_ATTR_ALL wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH +#define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH) /*! * wxRichTextObject class declaration * This is the base for drawable objects. */ -class WXDLLIMPEXP_ADV wxRichTextObject: public wxObject +class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject { DECLARE_CLASS(wxRichTextObject) public: @@ -527,7 +559,7 @@ public: /// Get the object size for the given range. Returns false if the range /// is invalid for this object. - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const = 0; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const = 0; /// Do a split, returning an object containing the second part, and setting /// the first part in 'this'. @@ -640,14 +672,14 @@ protected: wxTextAttrEx m_attributes; }; -WX_DECLARE_EXPORTED_LIST( wxRichTextObject, wxRichTextObjectList ); +WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT ); /*! * wxRichTextCompositeObject class declaration * Objects of this class can contain other objects. */ -class WXDLLIMPEXP_ADV wxRichTextCompositeObject: public wxRichTextObject +class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject { DECLARE_CLASS(wxRichTextCompositeObject) public: @@ -728,7 +760,7 @@ protected: * This defines a 2D space to lay out objects */ -class WXDLLIMPEXP_ADV wxRichTextBox: public wxRichTextCompositeObject +class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextCompositeObject { DECLARE_DYNAMIC_CLASS(wxRichTextBox) public: @@ -747,7 +779,7 @@ public: /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const; // Accessors @@ -767,7 +799,7 @@ protected: * This box knows how to lay out paragraphs. */ -class WXDLLIMPEXP_ADV wxRichTextParagraphLayoutBox: public wxRichTextBox +class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextBox { DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox) public: @@ -786,7 +818,7 @@ public: /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const; /// Delete range virtual bool DeleteRange(const wxRichTextRange& range); @@ -850,10 +882,10 @@ public: virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const; /// Get the paragraph by number - virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const; + virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const; /// Get the paragraph for a given line - virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const; + virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const; /// Get the length of the paragraph virtual int GetParagraphLength(long paragraphNumber) const; @@ -909,9 +941,6 @@ public: /// Copy void Copy(const wxRichTextParagraphLayoutBox& obj); - /// Clone - virtual wxRichTextObject* Clone() { return new wxRichTextParagraphLayoutBox(*this); } - /// Calculate ranges virtual void UpdateRanges() { long end; CalculateRange(0, end); } @@ -932,9 +961,18 @@ public: /// Get basic (overall) style virtual const wxTextAttrEx& GetBasicStyle() const { return m_attributes; } + /// Invalidate the buffer. With no argument, invalidates whole buffer. + void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); + + /// Get invalid range, rounding to entire paragraphs if argument is true. + wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const; + protected: wxRichTextCtrl* m_ctrl; wxTextAttrEx m_defaultAttributes; + + /// The invalidated range that will need full layout + wxRichTextRange m_invalidRange; }; /*! @@ -943,7 +981,7 @@ protected: * paragraphs for Undo/Redo, for example. */ -class WXDLLIMPEXP_ADV wxRichTextFragment: public wxRichTextParagraphLayoutBox +class WXDLLIMPEXP_RICHTEXT wxRichTextFragment: public wxRichTextParagraphLayoutBox { DECLARE_DYNAMIC_CLASS(wxRichTextFragment) public: @@ -969,7 +1007,7 @@ public: void Copy(const wxRichTextFragment& obj); /// Clone - virtual wxRichTextObject* Clone() { return new wxRichTextFragment(*this); } + virtual wxRichTextObject* Clone() const { return new wxRichTextFragment(*this); } protected: @@ -984,13 +1022,13 @@ protected: * start and end positions of the line. */ -class WXDLLIMPEXP_ADV wxRichTextLine +class WXDLLIMPEXP_RICHTEXT wxRichTextLine { public: // Constructors wxRichTextLine(wxRichTextParagraph* parent); - wxRichTextLine(const wxRichTextLine& obj) { Init(); Copy(obj); } + wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); } virtual ~wxRichTextLine() {} // Overrideables @@ -1008,6 +1046,9 @@ public: const wxRichTextRange& GetRange() const { return m_range; } wxRichTextRange& GetRange() { return m_range; } + /// Get the absolute range + wxRichTextRange GetAbsoluteRange() const; + /// Get/set the line size as calculated by Layout. virtual wxSize GetSize() const { return m_size; } virtual void SetSize(const wxSize& sz) { m_size = sz; } @@ -1029,7 +1070,7 @@ public: // Operations /// Initialisation - void Init(); + void Init(wxRichTextParagraph* parent); /// Copy void Copy(const wxRichTextLine& obj); @@ -1040,6 +1081,7 @@ public: protected: /// The range of the line (start position to end position) + /// This is relative to the parent paragraph. wxRichTextRange m_range; /// Size and position measured relative to top of paragraph @@ -1053,14 +1095,14 @@ protected: wxRichTextParagraph* m_parent; }; -WX_DECLARE_EXPORTED_LIST( wxRichTextLine, wxRichTextLineList ); +WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT ); /*! * wxRichTextParagraph class declaration * This object represents a single paragraph (or in a straight text editor, a line). */ -class WXDLLIMPEXP_ADV wxRichTextParagraph: public wxRichTextBox +class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextBox { DECLARE_DYNAMIC_CLASS(wxRichTextParagraph) public: @@ -1081,7 +1123,7 @@ public: /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const; /// Finds the absolute position and row height for the given character position virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); @@ -1141,6 +1183,12 @@ public: /// Get the bullet text for this paragraph. wxString GetBulletText(); + /// Allocate or reuse a line object + wxRichTextLine* AllocateLine(int pos); + + /// Clear remaining unused line objects, if any + bool ClearUnusedLines(int lineCount); + protected: /// The lines that make up the wrapped paragraph wxRichTextLineList m_cachedLines; @@ -1151,7 +1199,7 @@ protected: * This object represents a single piece of text. */ -class WXDLLIMPEXP_ADV wxRichTextPlainText: public wxRichTextObject +class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject { DECLARE_DYNAMIC_CLASS(wxRichTextPlainText) public: @@ -1170,7 +1218,7 @@ public: /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position/* = wxPoint(0,0)*/) const; /// Get any text in this object for the given range virtual wxString GetTextForRange(const wxRichTextRange& range) const; @@ -1186,7 +1234,7 @@ public: virtual bool DeleteRange(const wxRichTextRange& range); /// Returns true if the object is empty - virtual bool IsEmpty() const { return m_text.IsEmpty(); } + virtual bool IsEmpty() const { return m_text.empty(); } /// Returns true if this object can merge itself with the given one. virtual bool CanMerge(wxRichTextObject* object) const; @@ -1213,6 +1261,8 @@ public: /// Clone virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); } +private: + bool DrawTabbedString(wxDC& dc,const wxRect& rect,wxString& str, wxCoord& x, wxCoord& y, bool selected); protected: wxString m_text; @@ -1225,7 +1275,7 @@ protected: class WXDLLIMPEXP_BASE wxDataInputStream; class WXDLLIMPEXP_BASE wxDataOutputStream; -class WXDLLIMPEXP_ADV wxRichTextImageBlock: public wxObject +class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject { public: wxRichTextImageBlock(); @@ -1240,7 +1290,7 @@ public: // to conserve space. // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to // load the image a 2nd time. - virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = TRUE); + virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = true); // Make an image block from the wxImage in the given // format. @@ -1302,7 +1352,7 @@ protected: * This object represents an image. */ -class WXDLLIMPEXP_ADV wxRichTextImage: public wxRichTextObject +class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject { DECLARE_DYNAMIC_CLASS(wxRichTextImage) public: @@ -1323,7 +1373,7 @@ public: /// Get the object size for the given range. Returns false if the range /// is invalid for this object. - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const; /// Returns true if the object is empty virtual bool IsEmpty() const { return !m_image.Ok(); } @@ -1366,10 +1416,10 @@ protected: * This is a kind of box, used to represent the whole buffer */ -class WXDLLIMPEXP_ADV wxRichTextCommand; -class WXDLLIMPEXP_ADV wxRichTextAction; +class WXDLLIMPEXP_RICHTEXT wxRichTextCommand; +class WXDLLIMPEXP_RICHTEXT wxRichTextAction; -class WXDLLIMPEXP_ADV wxRichTextBuffer: public wxRichTextParagraphLayoutBox +class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox { DECLARE_DYNAMIC_CLASS(wxRichTextBuffer) public: @@ -1465,7 +1515,7 @@ public: virtual void ClearStyleStack(); /// Get the size of the style stack, for example to check correct nesting - virtual int GetStyleStackSize() const { return m_attributeStack.GetCount(); } + virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); } /// Begin using bold bool BeginBold(); @@ -1609,8 +1659,10 @@ public: /// Finds a handler by type static wxRichTextFileHandler *FindHandler(int imageType); - /// Gets a wildcard incorporating all visible handlers - static wxString GetExtWildcard(bool combine = false, bool save = false); + /// Gets a wildcard incorporating all visible handlers. If 'types' is present, + /// will be filled with the file type corresponding to each filter. This can be + /// used to determine the type to pass to LoadFile given a selected filter. + static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL); /// Clean up handlers static void CleanUpHandlers(); @@ -1665,13 +1717,13 @@ enum wxRichTextCommandId * */ -class WXDLLIMPEXP_ADV wxRichTextAction; -class WXDLLIMPEXP_ADV wxRichTextCommand: public wxCommand +class WXDLLIMPEXP_RICHTEXT wxRichTextAction; +class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand { public: // Ctor for one action wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer, - wxRichTextCtrl* ctrl, bool ignoreFirstTime = FALSE); + wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); // Ctor for multiple actions wxRichTextCommand(const wxString& name); @@ -1696,11 +1748,11 @@ protected: * There can be more than one action in a command. */ -class WXDLLIMPEXP_ADV wxRichTextAction: public wxObject +class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject { public: wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer, - wxRichTextCtrl* ctrl, bool ignoreFirstTime = FALSE); + wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); ~wxRichTextAction(); @@ -1762,7 +1814,7 @@ protected: * Base class for file handlers */ -class WXDLLIMPEXP_ADV wxRichTextFileHandler: public wxObject +class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject { DECLARE_CLASS(wxRichTextFileHandler) public: @@ -1771,12 +1823,14 @@ public: { } #if wxUSE_STREAMS - virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0; - virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0; + bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) + { return DoLoadFile(buffer, stream); } + bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) + { return DoSaveFile(buffer, stream); } #endif - virtual bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename); - virtual bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename); + bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename); + bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename); /// Can we handle this filename (if using files)? By default, checks the extension. virtual bool CanHandle(const wxString& filename) const; @@ -1791,18 +1845,31 @@ public: virtual bool IsVisible() const { return m_visible; } virtual void SetVisible(bool visible) { m_visible = visible; } + /// The name of the nandler void SetName(const wxString& name) { m_name = name; } wxString GetName() const { return m_name; } + /// The default extension to recognise void SetExtension(const wxString& ext) { m_extension = ext; } wxString GetExtension() const { return m_extension; } + /// The handler type void SetType(int type) { m_type = type; } int GetType() const { return m_type; } + /// Encoding to use when saving a file. If empty, a suitable encoding is chosen + void SetEncoding(const wxString& encoding) { m_encoding = encoding; } + const wxString& GetEncoding() const { return m_encoding; } + protected: +#if wxUSE_STREAMS + virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0; + virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0; +#endif + wxString m_name; + wxString m_encoding; wxString m_extension; int m_type; bool m_visible; @@ -1813,7 +1880,7 @@ protected: * Plain text handler */ -class WXDLLIMPEXP_ADV wxRichTextPlainTextHandler: public wxRichTextFileHandler +class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler { DECLARE_CLASS(wxRichTextPlainTextHandler) public: @@ -1821,11 +1888,6 @@ public: : wxRichTextFileHandler(name, ext, type) { } -#if wxUSE_STREAMS - virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); - virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); -#endif - /// Can we save using this handler? virtual bool CanSave() const { return true; } @@ -1834,6 +1896,11 @@ public: protected: +#if wxUSE_STREAMS + virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); + virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); +#endif + }; /*! @@ -1865,4 +1932,3 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style); #endif // _WX_RICHTEXTBUFFER_H_ -