X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c0ea5130fd233b97827e0cb392e68f64968ae32..2d14a14c573db4b8f8959b1460a269cf23defbcf:/include/wx/richtext/richtextbuffer.h diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 871025796f..9d77f5a221 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -74,6 +74,16 @@ #define wxRichTextAttr wxTextAttr #define wxTextAttrEx wxTextAttr +// Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a non-flashing +// cursor reliably without using wxClientDC in case there +// are platform-specific problems with the generic caret. +#define wxRICHTEXT_USE_OWN_CARET 0 + +// Switch off for binary compatibility, on for faster drawing +// Note: this seems to be buggy (overzealous use of extents) so +// don't use for now +#define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0 + /*! * Special characters */ @@ -81,15 +91,17 @@ extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar; /*! - * File types + * File types in wxRichText context. */ - -#define wxRICHTEXT_TYPE_ANY 0 -#define wxRICHTEXT_TYPE_TEXT 1 -#define wxRICHTEXT_TYPE_XML 2 -#define wxRICHTEXT_TYPE_HTML 3 -#define wxRICHTEXT_TYPE_RTF 4 -#define wxRICHTEXT_TYPE_PDF 5 +enum wxRichTextFileType +{ + wxRICHTEXT_TYPE_ANY = 0, + wxRICHTEXT_TYPE_TEXT, + wxRICHTEXT_TYPE_XML, + wxRICHTEXT_TYPE_HTML, + wxRICHTEXT_TYPE_RTF, + wxRICHTEXT_TYPE_PDF +}; /*! * Forward declarations @@ -133,17 +145,23 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; /*! * Flags returned from hit-testing */ +enum wxRichTextHitTestFlags +{ + // The point was not on this object + wxRICHTEXT_HITTEST_NONE = 0x01, -// The point was not on this object -#define wxRICHTEXT_HITTEST_NONE 0x01 -// The point was before the position returned from HitTest -#define wxRICHTEXT_HITTEST_BEFORE 0x02 -// The point was after the position returned from HitTest -#define wxRICHTEXT_HITTEST_AFTER 0x04 -// The point was on the position returned from HitTest -#define wxRICHTEXT_HITTEST_ON 0x08 -// The point was on space outside content -#define wxRICHTEXT_HITTEST_OUTSIDE 0x10 + // The point was before the position returned from HitTest + wxRICHTEXT_HITTEST_BEFORE = 0x02, + + // The point was after the position returned from HitTest + wxRICHTEXT_HITTEST_AFTER = 0x04, + + // The point was on the position returned from HitTest + wxRICHTEXT_HITTEST_ON = 0x08, + + // The point was on space outside content + wxRICHTEXT_HITTEST_OUTSIDE = 0x10 +}; /*! * Flags for GetRangeSize @@ -151,6 +169,8 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; #define wxRICHTEXT_FORMATTED 0x01 #define wxRICHTEXT_UNFORMATTED 0x02 +#define wxRICHTEXT_CACHE_SIZE 0x04 +#define wxRICHTEXT_HEIGHT_ONLY 0x08 /*! * Flags for SetStyle/SetListStyle @@ -202,6 +222,12 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; // flag to InsertFragment and DeleteRange to indicate the appropriate mode. #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000 +/*! + * Default superscript/subscript font multiplication factor + */ + +#define wxSCRIPT_MUL_FACTOR 1.5 + /*! * wxRichTextFontTable * Manages quick access to a pool of fonts for rendering rich text @@ -247,7 +273,7 @@ public: 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); } - bool operator !=(const wxRichTextRange& range) const { return (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); } @@ -332,7 +358,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, wxPoint position = wxPoint(0,0)) const = 0; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const = 0; /// Do a split, returning an object containing the second part, and setting /// the first part in 'this'. @@ -529,7 +555,7 @@ public: bool DeleteChildren() ; /// Recursively merge all pieces that can be merged. - bool Defragment(); + bool Defragment(const wxRichTextRange& range = wxRICHTEXT_ALL); protected: wxRichTextObjectList m_children; @@ -559,7 +585,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, wxPoint position = wxPoint(0,0)) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; // Accessors @@ -598,7 +624,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, wxPoint position = wxPoint(0,0)) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; /// Delete range virtual bool DeleteRange(const wxRichTextRange& range); @@ -679,7 +705,7 @@ public: virtual int GetParagraphLength(long paragraphNumber) const; /// Get the number of paragraphs - virtual int GetParagraphCount() const { return GetChildCount(); } + virtual int GetParagraphCount() const { return static_cast(GetChildCount()); } /// Get the number of visible lines virtual int GetLineCount() const; @@ -712,7 +738,7 @@ public: /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of /// content. - bool CollectStyle(wxTextAttr& currentStyle, const wxTextAttr& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes); + bool CollectStyle(wxTextAttr& currentStyle, const wxTextAttr& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes, int& absentStyleAttributes, int& absentTextEffectAttributes); /// Set list style virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); @@ -858,6 +884,11 @@ public: void SetDescent(int descent) { m_descent = descent; } int GetDescent() const { return m_descent; } +#if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING + wxArrayInt& GetObjectSizes() { return m_objectSizes; } + const wxArrayInt& GetObjectSizes() const { return m_objectSizes; } +#endif + // Operations /// Initialisation @@ -884,6 +915,10 @@ protected: // The parent object wxRichTextParagraph* m_parent; + +#if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING + wxArrayInt m_objectSizes; +#endif }; WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT ); @@ -914,7 +949,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, wxPoint position = wxPoint(0,0)) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) 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); @@ -945,7 +980,7 @@ public: // Implementation /// Apply paragraph styles such as centering to the wrapped lines - virtual void ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect); + virtual void ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect, wxDC& dc); /// Insert text at the given position virtual bool InsertText(long pos, const wxString& text); @@ -966,7 +1001,7 @@ public: /// Find a suitable wrap position. wrapPosition is the last position in the line to the left /// of the split. - bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition); + bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents); /// Find the object at the given position wxRichTextObject* FindObjectAtPosition(long position); @@ -1031,7 +1066,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, wxPoint position/* = wxPoint(0,0)*/) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; /// Get any text in this object for the given range virtual wxString GetTextForRange(const wxRichTextRange& range) const; @@ -1106,11 +1141,12 @@ 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, wxBitmapType imageType, + wxImage& image, bool convertToJPEG = true); // Make an image block from the wxImage in the given // format. - virtual bool MakeImageBlock(wxImage& image, int imageType, int quality = 80); + virtual bool MakeImageBlock(wxImage& image, wxBitmapType imageType, int quality = 80); // Write to a file bool Write(const wxString& filename); @@ -1119,7 +1155,7 @@ public: bool WriteHex(wxOutputStream& stream); // Read data in hex from a stream - bool ReadHex(wxInputStream& stream, int length, int imageType); + bool ReadHex(wxInputStream& stream, int length, wxBitmapType imageType); // Copy from 'block' void Copy(const wxRichTextImageBlock& block); @@ -1134,11 +1170,11 @@ public: unsigned char* GetData() const { return m_data; } size_t GetDataSize() const { return m_dataSize; } - int GetImageType() const { return m_imageType; } + wxBitmapType GetImageType() const { return m_imageType; } void SetData(unsigned char* image) { m_data = image; } void SetDataSize(size_t size) { m_dataSize = size; } - void SetImageType(int imageType) { m_imageType = imageType; } + void SetImageType(wxBitmapType imageType) { m_imageType = imageType; } bool Ok() const { return IsOk(); } bool IsOk() const { return GetData() != NULL; } @@ -1163,7 +1199,7 @@ protected: // This is in the raw, original form such as a JPEG file. unsigned char* m_data; size_t m_dataSize; - int m_imageType; // wxWin type id + wxBitmapType m_imageType; }; @@ -1193,7 +1229,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, wxPoint position = wxPoint(0,0)) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; /// Returns true if the object is empty virtual bool IsEmpty() const { return !m_image.Ok(); } @@ -1281,16 +1317,16 @@ public: virtual void ResetAndClearCommands(); /// Load a file - virtual bool LoadFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY); + virtual bool LoadFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); /// Save a file - virtual bool SaveFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY); + virtual bool SaveFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); /// Load from a stream - virtual bool LoadFile(wxInputStream& stream, int type = wxRICHTEXT_TYPE_ANY); + virtual bool LoadFile(wxInputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); /// Save to a stream - virtual bool SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY); + virtual bool SaveFile(wxOutputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); /// Set the handler flags, controlling loading and saving void SetHandlerFlags(int flags) { m_handlerFlags = flags; } @@ -1529,13 +1565,14 @@ public: static wxRichTextFileHandler *FindHandler(const wxString& name); /// Finds a handler by extension and type - static wxRichTextFileHandler *FindHandler(const wxString& extension, int imageType); + static wxRichTextFileHandler *FindHandler(const wxString& extension, wxRichTextFileType imageType); /// Finds a handler by filename or, if supplied, type - static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, int imageType); + static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, + wxRichTextFileType imageType); /// Finds a handler by type - static wxRichTextFileHandler *FindHandler(int imageType); + static wxRichTextFileHandler *FindHandler(wxRichTextFileType imageType); /// 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 @@ -1678,7 +1715,7 @@ public: /// Update the control appearance void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false, - wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL); + wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL, bool isDoCmd = true); /// Replace the buffer paragraphs with the given fragment. void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment); @@ -1687,6 +1724,9 @@ public: wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; } wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; } + /// Calculate arrays for refresh optimization + void CalculateRefreshOptimizations(wxArrayInt& optimizationLineCharPositions, wxArrayInt& optimizationLineYPositions); + /// Set/get the position used for e.g. insertion void SetPosition(long pos) { m_position = pos; } long GetPosition() const { return m_position; } @@ -1747,6 +1787,10 @@ protected: // in a larger document #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080 +// Convert the more common face names to names that will work on the current platform +// in a larger document +#define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100 + /*! * wxRichTextFileHandler * Base class for file handlers @@ -1829,7 +1873,9 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHand { DECLARE_CLASS(wxRichTextPlainTextHandler) public: - wxRichTextPlainTextHandler(const wxString& name = wxT("Text"), const wxString& ext = wxT("txt"), int type = wxRICHTEXT_TYPE_TEXT) + wxRichTextPlainTextHandler(const wxString& name = wxT("Text"), + const wxString& ext = wxT("txt"), + wxRichTextFileType type = wxRICHTEXT_TYPE_TEXT) : wxRichTextFileHandler(name, ext, type) { } @@ -1859,7 +1905,7 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject: public wxDataObjectSimple public: // ctor doesn't copy the pointer, so it shouldn't go away while this object // is alive - wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = (wxRichTextBuffer*) NULL); + wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = NULL); virtual ~wxRichTextBufferDataObject(); // after a call to this function, the buffer is owned by the caller and it