-/*!
- * 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();
-
- // Assignment from a wxTextAttrEx object
- void operator= (const wxTextAttrEx& attr);
-
- // Assignment from a wxTextAttr object.
- void operator= (const wxTextAttr& attr);
-
- // 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 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 SetBulletSymbol(wxChar symbol) { m_bulletSymbol = symbol; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_SYMBOL); }
-
- const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
- const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
- 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; }
- wxChar GetBulletSymbol() const { return m_bulletSymbol; }
-
- bool HasWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
- bool HasSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0; }
- bool HasItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC) != 0; }
- bool HasUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
- bool HasFaceName() 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 HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); }
- bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); }
- bool HasBulletSymbol() const { return HasFlag(wxTEXT_ATTR_BULLET_SYMBOL); }
-
- // Is this a character style?
- bool IsCharacterStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR))); }
- bool IsParagraphStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|
- wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|
- wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER))); }
-
- // returns false if we have any attributes set, true otherwise
- bool IsDefault() const
- {
- return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
- !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
- !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
- !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
- }
-
- // 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;
- wxChar m_bulletSymbol;
-
- // Character style
- wxString m_characterStyleName;
-
- // Paragraph style
- wxString m_paragraphStyleName;
-};
-
-/*!
- * 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() { Init(); }
- wxRichTextAttr(const wxColour& colText,
- const wxColour& colBack = wxNullColour,
- wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
-
- // Initialise this object.
- void Init();
-
- // 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 ;
-
- // Copy to a wxTextAttr
- void CopyTo(wxTextAttrEx& attr) 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 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 SetBulletSymbol(wxChar symbol) { m_bulletSymbol = symbol; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; }
-
- 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; }
- 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; }
- wxChar GetBulletSymbol() const { return m_bulletSymbol; }
-
- // 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 HasWeight() const { return (m_flags & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
- bool HasSize() const { return (m_flags & wxTEXT_ATTR_FONT_SIZE) != 0; }
- bool HasItalic() const { return (m_flags & wxTEXT_ATTR_FONT_ITALIC) != 0; }
- bool HasUnderlined() const { return (m_flags & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
- bool HasFaceName() 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 HasBulletStyle() const { return (m_flags & wxTEXT_ATTR_BULLET_STYLE) != 0; }
- bool HasBulletNumber() const { return (m_flags & wxTEXT_ATTR_BULLET_NUMBER) != 0; }
- bool HasBulletSymbol() const { return (m_flags & wxTEXT_ATTR_BULLET_SYMBOL) != 0; }
-
- bool HasFlag(long flag) const { return (m_flags & flag) != 0; }
-
- // Is this a character style?
- bool IsCharacterStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR))); }
- bool IsParagraphStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|
- wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|
- wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER))); }
-
- // returns false if we have any attributes set, true otherwise
- bool IsDefault() const
- {
- return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
- !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
- !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
- !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
- }
-
- // 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 wxRichTextAttr Combine(const wxRichTextAttr& attr,
- const wxRichTextAttr& attrDef,
- const wxTextCtrlBase *text);
-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;
-
- int m_paragraphSpacingAfter;
- int m_paragraphSpacingBefore;
- int m_lineSpacing;
- int m_bulletStyle;
- int m_bulletNumber;
- wxChar m_bulletSymbol;
-
- // Character styles
- wxColour m_colText,
- m_colBack;
- int m_fontSize;
- int m_fontStyle;
- int m_fontWeight;
- bool m_fontUnderlined;
- wxString m_fontFaceName;
-
- // Character style
- wxString m_characterStyleName;
-
- // Paragraph style
- wxString m_paragraphStyleName;
-};
-
-#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR)
-
-#define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
- wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
- wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL)
-
-#define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
-