📄 richtextbuffer.h
字号:
};
WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT );
/*!
* wxRichTextCompositeObject class declaration
* Objects of this class can contain other objects.
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject
{
DECLARE_CLASS(wxRichTextCompositeObject)
public:
// Constructors
wxRichTextCompositeObject(wxRichTextObject* parent = NULL);
~wxRichTextCompositeObject();
// Overrideables
/// Hit-testing: returns a flag indicating hit test details, plus
/// information about position
virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition);
/// 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);
/// Calculate range
virtual void CalculateRange(long start, long& end);
/// 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;
/// Dump to output stream for debugging
virtual void Dump(wxTextOutputStream& stream);
// Accessors
/// Get the children
wxRichTextObjectList& GetChildren() { return m_children; }
const wxRichTextObjectList& GetChildren() const { return m_children; }
/// Get the child count
size_t GetChildCount() const ;
/// Get the nth child
wxRichTextObject* GetChild(size_t n) const ;
/// Get/set dirty flag
virtual bool GetDirty() const { return m_dirty; }
virtual void SetDirty(bool dirty) { m_dirty = dirty; }
/// Is this composite?
virtual bool IsComposite() const { return true; }
/// Returns true if the buffer is empty
virtual bool IsEmpty() const { return GetChildCount() == 0; }
// Operations
/// Copy
void Copy(const wxRichTextCompositeObject& obj);
/// Append a child, returning the position
size_t AppendChild(wxRichTextObject* child) ;
/// Insert the child in front of the given object, or at the beginning
bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ;
/// Delete the child
bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ;
/// Delete all children
bool DeleteChildren() ;
/// Recursively merge all pieces that can be merged.
bool Defragment();
protected:
wxRichTextObjectList m_children;
};
/*!
* wxRichTextBox class declaration
* This defines a 2D space to lay out objects
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextCompositeObject
{
DECLARE_DYNAMIC_CLASS(wxRichTextBox)
public:
// Constructors
wxRichTextBox(wxRichTextObject* parent = NULL);
wxRichTextBox(const wxRichTextBox& obj): wxRichTextCompositeObject() { 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;
// Accessors
// Operations
/// Clone
virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); }
/// Copy
void Copy(const wxRichTextBox& obj);
protected:
};
/*!
* 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; }
// 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);
/// Convenience function to add an image
virtual wxRichTextRange AddImage(const wxImage& image);
/// Adds multiple paragraphs, based on newlines.
virtual wxRichTextRange AddParagraphs(const wxString& text);
/// 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, bool withUndo = true);
virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, bool withUndo = true);
/// Get the text attributes for this position.
virtual bool GetStyle(long position, wxTextAttrEx& style) const;
virtual bool GetStyle(long position, wxRichTextAttr& style) 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, wxRichTextFragment& fragment);
/// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextFragment& fragment);
/// Copy
void Copy(const wxRichTextParagraphLayoutBox& 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) { style.CopyTo(m_attributes); }
/// 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;
};
/*!
* wxRichTextFragment class declaration
* This is a lind of paragraph layout box used for storing
* paragraphs for Undo/Redo, for example.
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextFragment: public wxRichTextParagraphLayoutBox
{
DECLARE_DYNAMIC_CLASS(wxRichTextFragment)
public:
// Constructors
wxRichTextFragment() { Init(); }
wxRichTextFragment(const wxRichTextFragment& obj):wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
// Accessors
/// Get/set whether the last paragraph is partial or complete
void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; }
bool GetPartialParagraph() const { return m_partialParagraph; }
// Overrideables
// Operations
/// Initialise
void Init();
/// Copy
void Copy(const wxRichTextFragment& obj);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -