📄 richtextbuffer.h
字号:
/// Gets the length of the range long GetLength() const { return m_end - m_start + 1; } /// Swaps the start and end void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; } /// Convert to internal form: (n, n) is the range of a single character. wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); } /// Convert from internal to public API form: (n, n+1) is the range of a single character. wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); }protected: long m_start; 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_RICHTEXT wxTextAttrEx: public wxTextAttr{public: // ctors wxTextAttrEx(const wxTextAttrEx& attr); wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; } wxTextAttrEx() { Init(); } // Initialise this object void Init(); // Copy void Copy(const wxTextAttrEx& attr); // Assignment from a wxTextAttrEx object void operator= (const wxTextAttrEx& attr); // Assignment from a wxTextAttr object void operator= (const wxTextAttr& attr); // Equality test bool operator== (const wxTextAttrEx& attr) const; // setters void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_CHARACTER_STYLE_NAME); } void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME); } void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); } void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_AFTER); } void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_BEFORE); } void SetLineSpacing(int spacing) { m_lineSpacing = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_LINE_SPACING); } void SetBulletStyle(int style) { m_bulletStyle = style; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_STYLE); } void SetBulletNumber(int n) { m_bulletNumber = n; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NUMBER); } void SetBulletText(const wxString& text) { m_bulletText = text; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_TEXT); } void SetBulletName(const wxString& name) { m_bulletName = name; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NAME); } void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; } void SetURL(const wxString& url) { m_urlTarget = url; SetFlags(GetFlags() | wxTEXT_ATTR_URL); } void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); } void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); } void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; } void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); } const wxString& GetCharacterStyleName() const { return m_characterStyleName; } const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; } const wxString& GetListStyleName() const { return m_listStyleName; } int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; } int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; } int GetLineSpacing() const { return m_lineSpacing; } int GetBulletStyle() const { return m_bulletStyle; } int GetBulletNumber() const { return m_bulletNumber; } const wxString& GetBulletText() const { return m_bulletText; } const wxString& GetBulletName() const { return m_bulletName; } const wxString& GetBulletFont() const { return m_bulletFont; } const wxString& GetURL() const { return m_urlTarget; } int GetTextEffects() const { return m_textEffects; } int GetTextEffectFlags() const { return m_textEffectFlags; } int GetOutlineLevel() const { return m_outlineLevel; } bool HasFontWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT) != 0; } bool HasFontSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0; } bool HasFontItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC) != 0; } bool HasFontUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE) != 0; } bool HasFontFaceName() 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); } bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME) && !m_characterStyleName.IsEmpty(); } bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) && !m_paragraphStyleName.IsEmpty(); } bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); } bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); } bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); } bool HasBulletText() const { return HasFlag(wxTEXT_ATTR_BULLET_TEXT); } bool HasBulletName() const { return HasFlag(wxTEXT_ATTR_BULLET_NAME); } bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); } bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); } bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); } bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); } bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); } // Is this a character style? bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER)); } bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH)); } // returns false if we have any attributes set, true otherwise bool IsDefault() const { return (GetFlags() == 0); } // 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; int m_paragraphSpacingBefore; int m_lineSpacing; int m_bulletStyle; int m_bulletNumber; int m_textEffects; int m_textEffectFlags; int m_outlineLevel; wxString m_bulletText; wxString m_bulletFont; wxString m_bulletName; wxString m_urlTarget; // Character style wxString m_characterStyleName; // Paragraph style wxString m_paragraphStyleName; // List style wxString m_listStyleName;};/*! * wxRichTextAttr stores attributes without a wxFont object, so is a much more * efficient way to query styles. */class WXDLLIMPEXP_RICHTEXT wxRichTextAttr{public: // ctors wxRichTextAttr(const wxTextAttrEx& attr); wxRichTextAttr(const wxRichTextAttr& attr); wxRichTextAttr() { Init(); } wxRichTextAttr(const wxColour& colText, const wxColour& colBack = wxNullColour, wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT); // Initialise this object. void Init(); // Copy void Copy(const wxRichTextAttr& attr); // Assignment from a wxRichTextAttr object. void operator= (const wxRichTextAttr& attr); // Assignment from a wxTextAttrEx object. void operator= (const wxTextAttrEx& attr); // Equality test bool operator== (const wxRichTextAttr& attr) const; // Making a wxTextAttrEx object. operator wxTextAttrEx () const ; // Create font from font attributes. wxFont CreateFont() const; // Get attributes from font. bool GetFontAttributes(const wxFont& font); // setters void SetTextColour(const wxColour& colText) { m_colText = colText; m_flags |= wxTEXT_ATTR_TEXT_COLOUR; } void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR; } void SetAlignment(wxTextAttrAlignment alignment) { m_textAlignment = alignment; m_flags |= wxTEXT_ATTR_ALIGNMENT; } void SetTabs(const wxArrayInt& tabs) { m_tabs = tabs; m_flags |= wxTEXT_ATTR_TABS; } void SetLeftIndent(int indent, int subIndent = 0) { m_leftIndent = indent; m_leftSubIndent = subIndent; m_flags |= wxTEXT_ATTR_LEFT_INDENT; } void SetRightIndent(int indent) { m_rightIndent = indent; m_flags |= wxTEXT_ATTR_RIGHT_INDENT; } void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags |= wxTEXT_ATTR_FONT_SIZE; } void SetFontStyle(int fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; } void SetFontWeight(int fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; } void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; } void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; } void SetFlags(long flags) { m_flags = flags; } void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; m_flags |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; } void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; m_flags |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; } void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); } void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_AFTER; } void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE; } void SetLineSpacing(int spacing) { m_lineSpacing = spacing; m_flags |= wxTEXT_ATTR_LINE_SPACING; } void SetBulletStyle(int style) { m_bulletStyle = style; m_flags |= wxTEXT_ATTR_BULLET_STYLE; } void SetBulletNumber(int n) { m_bulletNumber = n; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; } void SetBulletText(const wxString& text) { m_bulletText = text; m_flags |= wxTEXT_ATTR_BULLET_TEXT; } void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; } void SetBulletName(const wxString& name) { m_bulletName = name; m_flags |= wxTEXT_ATTR_BULLET_NAME; } void SetURL(const wxString& url) { m_urlTarget = url; m_flags |= wxTEXT_ATTR_URL; } void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); } void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); } void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; } void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); } const wxColour& GetTextColour() const { return m_colText; } const wxColour& GetBackgroundColour() const { return m_colBack; } wxTextAttrAlignment GetAlignment() const { return m_textAlignment; } const wxArrayInt& GetTabs() const { return m_tabs; } long GetLeftIndent() const { return m_leftIndent; } long GetLeftSubIndent() const { return m_leftSubIndent; } long GetRightIndent() const { return m_rightIndent; } long GetFlags() const { return m_flags; } int GetFontSize() const { return m_fontSize; } int GetFontStyle() const { return m_fontStyle; } int GetFontWeight() const { return m_fontWeight; } bool GetFontUnderlined() const { return m_fontUnderlined; } const wxString& GetFontFaceName() const { return m_fontFaceName; } const wxString& GetCharacterStyleName() const { return m_characterStyleName; } const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; } const wxString& GetListStyleName() const { return m_listStyleName; } int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; } int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; } int GetLineSpacing() const { return m_lineSpacing; } int GetBulletStyle() const { return m_bulletStyle; } int GetBulletNumber() const { return m_bulletNumber; } const wxString& GetBulletText() const { return m_bulletText; } const wxString& GetBulletFont() const { return m_bulletFont; } const wxString& GetBulletName() const { return m_bulletName; } const wxString& GetURL() const { return m_urlTarget; } int GetTextEffects() const { return m_textEffects; } int GetTextEffectFlags() const { return m_textEffectFlags; } int GetOutlineLevel() const { return m_outlineLevel; } // accessors bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; } bool HasBackgroundColour() const { return m_colBack.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; } bool HasAlignment() const { return (m_textAlignment != wxTEXT_ALIGNMENT_DEFAULT) || ((m_flags & wxTEXT_ATTR_ALIGNMENT) != 0) ; } bool HasTabs() const { return (m_flags & wxTEXT_ATTR_TABS) != 0 ; } bool HasLeftIndent() const { return (m_flags & wxTEXT_ATTR_LEFT_INDENT) != 0 ; } bool HasRightIndent() const { return (m_flags & wxTEXT_ATTR_RIGHT_INDENT) != 0 ; } bool HasFontWeight() const { return (m_flags & wxTEXT_ATTR_FONT_WEIGHT) != 0; } bool HasFontSize() const { return (m_flags & wxTEXT_ATTR_FONT_SIZE) != 0; } bool HasFontItalic() const { return (m_flags & wxTEXT_ATTR_FONT_ITALIC) != 0; } bool HasFontUnderlined() const { return (m_flags & wxTEXT_ATTR_FONT_UNDERLINE) != 0; } bool HasFontFaceName() const { return (m_flags & wxTEXT_ATTR_FONT_FACE) != 0; } bool HasFont() const { return (m_flags & (wxTEXT_ATTR_FONT)) != 0; } bool HasParagraphSpacingAfter() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_AFTER) != 0; } bool HasParagraphSpacingBefore() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) != 0; } bool HasLineSpacing() const { return (m_flags & wxTEXT_ATTR_LINE_SPACING) != 0; } bool HasCharacterStyleName() const { return (m_flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) != 0 && !m_characterStyleName.IsEmpty(); } bool HasParagraphStyleName() const { return (m_flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) != 0 && !m_paragraphStyleName.IsEmpty(); } bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); } bool HasBulletStyle() const { return (m_flags & wxTEXT_ATTR_BULLET_STYLE) != 0; } bool HasBulletNumber() const { return (m_flags & wxTEXT_ATTR_BULLET_NUMBER) != 0; } bool HasBulletText() const { return (m_flags & wxTEXT_ATTR_BULLET_TEXT) != 0; } bool HasBulletName() const { return (m_flags & wxTEXT_ATTR_BULLET_NAME) != 0; } bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); } bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); } bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); } bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); } bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); } bool HasFlag(long flag) const { return (m_flags & flag) != 0; } // Is this a character style? bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER)); } bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH)); } // returns false if we have any attributes set, true otherwise bool IsDefault() const { return GetFlags() == 0; } // Merges the given attributes. Does not affect 'this'. If compareWith // is non-NULL, then it will be used to mask out those attributes that are the same in style // and compareWith, for situations where we don't want to explicitly set inherited attributes. bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL); // Merges the given attributes and returns the result. Does not affect 'this'. If compareWith // is non-NULL, then it will be used to mask out those attributes that are the same in style // and compareWith, for situations where we don't want to explicitly set inherited attributes. wxRichTextAttr Combine(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL) const;private: long m_flags; // Paragraph styles wxArrayInt m_tabs; // array of int: tab stops in 1/10 mm int m_leftIndent; // left indent in 1/10 mm int m_leftSubIndent; // left indent for all but the first // line in a paragraph relative to the // first line, in 1/10 mm int m_rightIndent; // right indent in 1/10 mm wxTextAttrAlignment m_textAlignment;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -