X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5d7836c47de679f03b1b7e738c77164c11bd3689..d8fd7acb8b877599b410e07a4c26dde92a676a82:/include/wx/richtext/richtextbuffer.h diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index f0b9a90dac..3a5e25f8e1 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -1,10 +1,10 @@ ///////////////////////////////////////////////////////////////////////////// -// 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 ///////////////////////////////////////////////////////////////////////////// @@ -81,7 +81,7 @@ 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_ @@ -134,6 +134,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 */ @@ -206,6 +210,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,6 +248,9 @@ 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. */ @@ -640,7 +648,7 @@ protected: wxTextAttrEx m_attributes; }; -WX_DECLARE_EXPORTED_LIST( wxRichTextObject, wxRichTextObjectList ); +WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_ADV ); /*! * wxRichTextCompositeObject class declaration @@ -850,10 +858,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 +917,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 +937,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; }; /*! @@ -969,7 +983,7 @@ public: void Copy(const wxRichTextFragment& obj); /// Clone - virtual wxRichTextObject* Clone() { return new wxRichTextFragment(*this); } + virtual wxRichTextObject* Clone() const { return new wxRichTextFragment(*this); } protected: @@ -990,7 +1004,7 @@ 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 +1022,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 +1046,7 @@ public: // Operations /// Initialisation - void Init(); + void Init(wxRichTextParagraph* parent); /// Copy void Copy(const wxRichTextLine& obj); @@ -1040,6 +1057,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,7 +1071,7 @@ protected: wxRichTextParagraph* m_parent; }; -WX_DECLARE_EXPORTED_LIST( wxRichTextLine, wxRichTextLineList ); +WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_ADV ); /*! * wxRichTextParagraph class declaration @@ -1141,6 +1159,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; @@ -1186,7 +1210,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; @@ -1240,7 +1264,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. @@ -1609,8 +1633,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(); @@ -1671,7 +1697,7 @@ class WXDLLIMPEXP_ADV 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); @@ -1700,7 +1726,7 @@ class WXDLLIMPEXP_ADV 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(); @@ -1771,12 +1797,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; @@ -1802,6 +1830,11 @@ public: 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_extension; int m_type; @@ -1821,11 +1854,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 +1862,11 @@ public: protected: +#if wxUSE_STREAMS + virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); + virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); +#endif + }; /*! @@ -1865,4 +1898,3 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style); #endif // _WX_RICHTEXTBUFFER_H_ -