📄 richtextbuffer.h
字号:
/*! * wxRichTextParagraphBox class declaration * This box knows how to lay out paragraphs. */class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextBox{ DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox)public:// Constructors wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL); wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextBox() { Init(); Copy(obj); }// Overrideables /// Draw the item virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style); /// Lay the item out virtual bool Layout(wxDC& dc, const wxRect& rect, int style); /// 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; /// Delete range virtual bool DeleteRange(const wxRichTextRange& range); /// Get any text in this object for the given range virtual wxString GetTextForRange(const wxRichTextRange& range) const;// Accessors /// Associate a control with the buffer, for operations that for example require refreshing the window. void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_ctrl = ctrl; } /// Get the associated control. wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; } /// Get/set whether the last paragraph is partial or complete void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; } bool GetPartialParagraph() const { return m_partialParagraph; } /// If this is a buffer, returns the current style sheet. The base layout box /// class doesn't have an associated style sheet. virtual wxRichTextStyleSheet* GetStyleSheet() const { return NULL; }// Operations /// Initialize the object. void Init(); /// Clear all children virtual void Clear(); /// Clear and initialize with one blank paragraph virtual void Reset(); /// Convenience function to add a paragraph of text virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL); /// Convenience function to add an image virtual wxRichTextRange AddImage(const wxImage& image, wxTextAttrEx* paraStyle = NULL); /// Adds multiple paragraphs, based on newlines. virtual wxRichTextRange AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle = NULL); /// Get the line at the given position. If caretPosition is true, the position is /// a caret position, which is normally a smaller number. virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const; /// Get the line at the given y pixel position, or the last line. virtual wxRichTextLine* GetLineAtYPosition(int y) const; /// Get the paragraph at the given character or caret position virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const; /// Get the line size at the given position virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const; /// Given a position, get the number of the visible line (potentially many to a paragraph), /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine) /// that indicates whether the caret is being shown at the end of the previous line or at the start /// of the next, since the caret can be shown at 2 visible positions for the same underlying /// position. virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const; /// Given a line number, get the corresponding wxRichTextLine object. virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const; /// Get the leaf object in a paragraph at this position. /// Given a line number, get the corresponding wxRichTextLine object. virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const; /// Get the paragraph by number virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const; /// Get the paragraph for a given line virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const; /// Get the length of the paragraph virtual int GetParagraphLength(long paragraphNumber) const; /// Get the number of paragraphs virtual int GetParagraphCount() const { return GetChildCount(); } /// Get the number of visible lines virtual int GetLineCount() const; /// Get the text of the paragraph virtual wxString GetParagraphText(long paragraphNumber) const; /// Convert zero-based line column and paragraph number to a position. virtual long XYToPosition(long x, long y) const; /// Convert zero-based position to line column and paragraph number virtual bool PositionToXY(long pos, long* x, long* y) const; /// Set text attributes: character and/or paragraph styles. virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); /// Get the conbined text attributes for this position. virtual bool GetStyle(long position, wxTextAttrEx& style); virtual bool GetStyle(long position, wxRichTextAttr& style); /// Get the content (uncombined) attributes for this position. virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style); virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style); /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and /// context attributes. virtual bool DoGetStyle(long position, wxTextAttrEx& style, bool combineStyles = true); /// Get the combined style for a range - if any attribute is different within the range, /// that attribute is not present within the flags virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style); /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of /// content. bool CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes); /// Set list style virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); /// Clear list for given range virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); /// Number/renumber any list elements in the given range. /// def/defName can be NULL/empty to indicate that the existing list style should be used. virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1 /// def/defName can be NULL/empty to indicate that the existing list style should be used. virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously /// def/defName can be NULL/empty to indicate that the existing list style should be used. virtual bool DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); /// Fills in the attributes for numbering a paragraph after previousParagraph. virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const; /// Test if this whole range has character attributes of the specified kind. If any /// of the attributes are different within the range, the test fails. You /// can use this to implement, for example, bold button updating. style must have /// flags indicating which attributes are of interest. virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const; virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; /// Test if this whole range has paragraph attributes of the specified kind. If any /// of the attributes are different within the range, the test fails. You /// can use this to implement, for example, centering button updating. style must have /// flags indicating which attributes are of interest. virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const; virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; /// Clone virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); } /// Insert fragment into this box at the given position. If partialParagraph is true, /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph /// marker. virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment); /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'. virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment); /// Apply the style sheet to the buffer, for example if the styles have changed. virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet); /// Copy void Copy(const wxRichTextParagraphLayoutBox& obj); /// Assignment void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); } /// Calculate ranges virtual void UpdateRanges() { long end; CalculateRange(0, end); } /// Get all the text virtual wxString GetText() const; /// Set default style for new content. Setting it to a default attribute /// makes new content take on the 'basic' style. virtual bool SetDefaultStyle(const wxTextAttrEx& style); /// Get default style virtual const wxTextAttrEx& GetDefaultStyle() const { return m_defaultAttributes; } /// Set basic (overall) style virtual void SetBasicStyle(const wxTextAttrEx& style) { m_attributes = style; } virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; } /// 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; // Is the last paragraph partial or complete? bool m_partialParagraph;};/*! * wxRichTextLine class declaration * This object represents a line in a paragraph, and stores * offsets from the start of the paragraph representing the * start and end positions of the line. */class WXDLLIMPEXP_RICHTEXT wxRichTextLine{public:// Constructors wxRichTextLine(wxRichTextParagraph* parent); wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); } virtual ~wxRichTextLine() {}// Overrideables// Accessors /// Set the range void SetRange(const wxRichTextRange& range) { m_range = range; } void SetRange(long from, long to) { m_range = wxRichTextRange(from, to); } /// Get the parent paragraph wxRichTextParagraph* GetParent() { return m_parent; } /// Get the range 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; } /// Get/set the object position relative to the parent virtual wxPoint GetPosition() const { return m_pos; } virtual void SetPosition(const wxPoint& pos) { m_pos = pos; } /// Get the absolute object position virtual wxPoint GetAbsolutePosition() const; /// Get the rectangle enclosing the line virtual wxRect GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); } /// Set/get stored descent void SetDescent(int descent) { m_descent = descent; } int GetDescent() const { return m_descent; }// Operations /// Initialisation void Init(wxRichTextParagraph* parent); /// Copy void Copy(const wxRichTextLine& obj); /// Clone virtual wxRichTextLine* Clone() const { return new wxRichTextLine(*this); }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 wxPoint m_pos; wxSize m_size;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -