-/*!
- * wxRichTextAttr stores attributes without a wxFont object, so is a much more
- * efficient way to query styles.
- */
-
-// ctors
-wxRichTextAttr::wxRichTextAttr(const wxColour& colText,
- const wxColour& colBack,
- wxTextAttrAlignment alignment): m_textAlignment(alignment), m_colText(colText), m_colBack(colBack)
-{
- Init();
-
- if (m_colText.Ok()) m_flags |= wxTEXT_ATTR_TEXT_COLOUR;
- if (m_colBack.Ok()) m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR;
- if (alignment != wxTEXT_ALIGNMENT_DEFAULT)
- m_flags |= wxTEXT_ATTR_ALIGNMENT;
-}
-
-wxRichTextAttr::wxRichTextAttr(const wxTextAttrEx& attr)
-{
- Init();
-
- (*this) = attr;
-}
-
-wxRichTextAttr::wxRichTextAttr(const wxRichTextAttr& attr)
-{
- Copy(attr);
-}
-
-// operations
-void wxRichTextAttr::Init()
-{
- m_textAlignment = wxTEXT_ALIGNMENT_DEFAULT;
- m_flags = 0;
- m_leftIndent = 0;
- m_leftSubIndent = 0;
- m_rightIndent = 0;
-
- m_fontSize = 12;
- m_fontStyle = wxNORMAL;
- m_fontWeight = wxNORMAL;
- m_fontUnderlined = false;
-
- m_paragraphSpacingAfter = 0;
- m_paragraphSpacingBefore = 0;
- m_lineSpacing = 0;
- m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE;
- m_textEffects = wxTEXT_ATTR_EFFECT_NONE;
- m_textEffectFlags = wxTEXT_ATTR_EFFECT_NONE;
- m_outlineLevel = 0;
- m_bulletNumber = 0;
-}
-
-// Copy
-void wxRichTextAttr::Copy(const wxRichTextAttr& attr)
-{
- m_colText = attr.m_colText;
- m_colBack = attr.m_colBack;
- m_textAlignment = attr.m_textAlignment;
- m_leftIndent = attr.m_leftIndent;
- m_leftSubIndent = attr.m_leftSubIndent;
- m_rightIndent = attr.m_rightIndent;
- m_tabs = attr.m_tabs;
- m_flags = attr.m_flags;
-
- m_fontSize = attr.m_fontSize;
- m_fontStyle = attr.m_fontStyle;
- m_fontWeight = attr.m_fontWeight;
- m_fontUnderlined = attr.m_fontUnderlined;
- m_fontFaceName = attr.m_fontFaceName;
- m_textEffects = attr.m_textEffects;
- m_textEffectFlags = attr.m_textEffectFlags;
-
- m_paragraphSpacingAfter = attr.m_paragraphSpacingAfter;
- m_paragraphSpacingBefore = attr.m_paragraphSpacingBefore;
- m_lineSpacing = attr.m_lineSpacing;
- m_characterStyleName = attr.m_characterStyleName;
- m_paragraphStyleName = attr.m_paragraphStyleName;
- m_listStyleName = attr.m_listStyleName;
- m_bulletStyle = attr.m_bulletStyle;
- m_bulletNumber = attr.m_bulletNumber;
- m_bulletText = attr.m_bulletText;
- m_bulletFont = attr.m_bulletFont;
- m_bulletName = attr.m_bulletName;
- m_outlineLevel = attr.m_outlineLevel;
-
- m_urlTarget = attr.m_urlTarget;
-}
-
-// operators
-void wxRichTextAttr::operator= (const wxRichTextAttr& attr)
-{
- Copy(attr);
-}
-
-// operators
-void wxRichTextAttr::operator= (const wxTextAttrEx& attr)
-{
- m_flags = attr.GetFlags();
-
- m_colText = attr.GetTextColour();
- m_colBack = attr.GetBackgroundColour();
- m_textAlignment = attr.GetAlignment();
- m_leftIndent = attr.GetLeftIndent();
- m_leftSubIndent = attr.GetLeftSubIndent();
- m_rightIndent = attr.GetRightIndent();
- m_tabs = attr.GetTabs();
- m_textEffects = attr.GetTextEffects();
- m_textEffectFlags = attr.GetTextEffectFlags();
-
- m_paragraphSpacingAfter = attr.GetParagraphSpacingAfter();
- m_paragraphSpacingBefore = attr.GetParagraphSpacingBefore();
- m_lineSpacing = attr.GetLineSpacing();
- m_characterStyleName = attr.GetCharacterStyleName();
- m_paragraphStyleName = attr.GetParagraphStyleName();
- m_listStyleName = attr.GetListStyleName();
- m_bulletStyle = attr.GetBulletStyle();
- m_bulletNumber = attr.GetBulletNumber();
- m_bulletText = attr.GetBulletText();
- m_bulletName = attr.GetBulletName();
- m_bulletFont = attr.GetBulletFont();
- m_outlineLevel = attr.GetOutlineLevel();
-
- m_urlTarget = attr.GetURL();
-
- if (attr.GetFont().Ok())
- GetFontAttributes(attr.GetFont());
-}
-
-// Making a wxTextAttrEx object.
-wxRichTextAttr::operator wxTextAttrEx () const
-{
- wxTextAttrEx attr;
- attr.SetTextColour(GetTextColour());
- attr.SetBackgroundColour(GetBackgroundColour());
- attr.SetAlignment(GetAlignment());
- attr.SetTabs(GetTabs());
- attr.SetLeftIndent(GetLeftIndent(), GetLeftSubIndent());
- attr.SetRightIndent(GetRightIndent());
- attr.SetFont(CreateFont());
-
- attr.SetParagraphSpacingAfter(m_paragraphSpacingAfter);
- attr.SetParagraphSpacingBefore(m_paragraphSpacingBefore);
- attr.SetLineSpacing(m_lineSpacing);
- attr.SetBulletStyle(m_bulletStyle);
- attr.SetBulletNumber(m_bulletNumber);
- attr.SetBulletText(m_bulletText);
- attr.SetBulletName(m_bulletName);
- attr.SetBulletFont(m_bulletFont);
- attr.SetCharacterStyleName(m_characterStyleName);
- attr.SetParagraphStyleName(m_paragraphStyleName);
- attr.SetListStyleName(m_listStyleName);
- attr.SetTextEffects(m_textEffects);
- attr.SetTextEffectFlags(m_textEffectFlags);
- attr.SetOutlineLevel(m_outlineLevel);
-
- attr.SetURL(m_urlTarget);
-
- attr.SetFlags(GetFlags()); // Important: set after SetFont and others, since they set flags
- return attr;
-}
-
-// Equality test
-bool wxRichTextAttr::operator== (const wxRichTextAttr& attr) const
-{
- return GetFlags() == attr.GetFlags() &&
-
- GetTextColour() == attr.GetTextColour() &&
- GetBackgroundColour() == attr.GetBackgroundColour() &&
-
- GetAlignment() == attr.GetAlignment() &&
- GetLeftIndent() == attr.GetLeftIndent() &&
- GetLeftSubIndent() == attr.GetLeftSubIndent() &&
- GetRightIndent() == attr.GetRightIndent() &&
- wxRichTextTabsEq(GetTabs(), attr.GetTabs()) &&
-
- GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter() &&
- GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore() &&
- GetLineSpacing() == attr.GetLineSpacing() &&
- GetCharacterStyleName() == attr.GetCharacterStyleName() &&
- GetParagraphStyleName() == attr.GetParagraphStyleName() &&
- GetListStyleName() == attr.GetListStyleName() &&
-
- GetBulletStyle() == attr.GetBulletStyle() &&
- GetBulletText() == attr.GetBulletText() &&
- GetBulletNumber() == attr.GetBulletNumber() &&
- GetBulletFont() == attr.GetBulletFont() &&
- GetBulletName() == attr.GetBulletName() &&
-
- GetTextEffects() == attr.GetTextEffects() &&
- GetTextEffectFlags() == attr.GetTextEffectFlags() &&
-
- GetOutlineLevel() == attr.GetOutlineLevel() &&
-
- GetFontSize() == attr.GetFontSize() &&
- GetFontStyle() == attr.GetFontStyle() &&
- GetFontWeight() == attr.GetFontWeight() &&
- GetFontUnderlined() == attr.GetFontUnderlined() &&
- GetFontFaceName() == attr.GetFontFaceName() &&
-
- GetURL() == attr.GetURL();
-}
-
-// Create font from font attributes.
-wxFont wxRichTextAttr::CreateFont() const
-{
- wxFont font(m_fontSize, wxDEFAULT, m_fontStyle, m_fontWeight, m_fontUnderlined, m_fontFaceName);
-#ifdef __WXMAC__
- font.SetNoAntiAliasing(true);
-#endif
- return font;
-}
-
-// Get attributes from font.
-bool wxRichTextAttr::GetFontAttributes(const wxFont& font)
-{
- if (!font.Ok())
- return false;
-
- m_fontSize = font.GetPointSize();
- m_fontStyle = font.GetStyle();
- m_fontWeight = font.GetWeight();
- m_fontUnderlined = font.GetUnderlined();
- m_fontFaceName = font.GetFaceName();
-
- return true;
-}
-
-wxRichTextAttr wxRichTextAttr::Combine(const wxRichTextAttr& attr,
- const wxRichTextAttr& attrDef,
- const wxTextCtrlBase *text)
-{
- wxColour colFg = attr.GetTextColour();
- if ( !colFg.Ok() )
- {
- colFg = attrDef.GetTextColour();
-
- if ( text && !colFg.Ok() )
- colFg = text->GetForegroundColour();
- }
-
- wxColour colBg = attr.GetBackgroundColour();
- if ( !colBg.Ok() )
- {
- colBg = attrDef.GetBackgroundColour();
-
- if ( text && !colBg.Ok() )
- colBg = text->GetBackgroundColour();
- }
-
- wxRichTextAttr newAttr(colFg, colBg);
-
- if (attr.HasWeight())
- newAttr.SetFontWeight(attr.GetFontWeight());
-
- if (attr.HasSize())
- newAttr.SetFontSize(attr.GetFontSize());
-
- if (attr.HasItalic())
- newAttr.SetFontStyle(attr.GetFontStyle());
-
- if (attr.HasUnderlined())
- newAttr.SetFontUnderlined(attr.GetFontUnderlined());
-
- if (attr.HasFaceName())
- newAttr.SetFontFaceName(attr.GetFontFaceName());
-
- if (attr.HasAlignment())
- newAttr.SetAlignment(attr.GetAlignment());
- else if (attrDef.HasAlignment())
- newAttr.SetAlignment(attrDef.GetAlignment());
-
- if (attr.HasTabs())
- newAttr.SetTabs(attr.GetTabs());
- else if (attrDef.HasTabs())
- newAttr.SetTabs(attrDef.GetTabs());
-
- if (attr.HasLeftIndent())
- newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent());
- else if (attrDef.HasLeftIndent())
- newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent());
-
- if (attr.HasRightIndent())
- newAttr.SetRightIndent(attr.GetRightIndent());
- else if (attrDef.HasRightIndent())
- newAttr.SetRightIndent(attrDef.GetRightIndent());
-
- // NEW ATTRIBUTES
-
- if (attr.HasParagraphSpacingAfter())
- newAttr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter());
-
- if (attr.HasParagraphSpacingBefore())
- newAttr.SetParagraphSpacingBefore(attr.GetParagraphSpacingBefore());
-
- if (attr.HasLineSpacing())
- newAttr.SetLineSpacing(attr.GetLineSpacing());
-
- if (attr.HasCharacterStyleName())
- newAttr.SetCharacterStyleName(attr.GetCharacterStyleName());
-
- if (attr.HasParagraphStyleName())
- newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
-
- if (attr.HasListStyleName())
- newAttr.SetListStyleName(attr.GetListStyleName());
-
- if (attr.HasBulletStyle())
- newAttr.SetBulletStyle(attr.GetBulletStyle());
-
- if (attr.HasBulletNumber())
- newAttr.SetBulletNumber(attr.GetBulletNumber());
-
- if (attr.HasBulletName())
- newAttr.SetBulletName(attr.GetBulletName());
-
- if (attr.HasBulletText())
- {
- newAttr.SetBulletText(attr.GetBulletText());
- newAttr.SetBulletFont(attr.GetBulletFont());
- }
-
- if (attr.HasURL())
- newAttr.SetURL(attr.GetURL());
-
- if (attr.HasPageBreak())
- newAttr.SetPageBreak();
-
- if (attr.HasTextEffects())
- {
- newAttr.SetTextEffects(attr.GetTextEffects());
- newAttr.SetTextEffectFlags(attr.GetTextEffectFlags());
- }
-
- if (attr.HasOutlineLevel())
- newAttr.SetOutlineLevel(attr.GetOutlineLevel());
-
- return newAttr;
-}
-
-/*!
- * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
- */
-
-wxTextAttrEx::wxTextAttrEx(const wxTextAttrEx& attr): wxTextAttr()
-{
- Copy(attr);
-}
-
-// Initialise this object.
-void wxTextAttrEx::Init()
-{
- m_paragraphSpacingAfter = 0;
- m_paragraphSpacingBefore = 0;
- m_lineSpacing = 0;
- m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE;
- m_textEffects = wxTEXT_ATTR_EFFECT_NONE;
- m_textEffectFlags = wxTEXT_ATTR_EFFECT_NONE;
- m_bulletNumber = 0;
- m_outlineLevel = 0;
-}
-
-// Copy
-void wxTextAttrEx::Copy(const wxTextAttrEx& attr)
-{
- wxTextAttr::operator= (attr);
-
- m_paragraphSpacingAfter = attr.m_paragraphSpacingAfter;
- m_paragraphSpacingBefore = attr.m_paragraphSpacingBefore;
- m_lineSpacing = attr.m_lineSpacing;
- m_characterStyleName = attr.m_characterStyleName;
- m_paragraphStyleName = attr.m_paragraphStyleName;
- m_listStyleName = attr.m_listStyleName;
- m_bulletStyle = attr.m_bulletStyle;
- m_bulletNumber = attr.m_bulletNumber;
- m_bulletText = attr.m_bulletText;
- m_bulletFont = attr.m_bulletFont;
- m_bulletName = attr.m_bulletName;
- m_urlTarget = attr.m_urlTarget;
- m_textEffects = attr.m_textEffects;
- m_textEffectFlags = attr.m_textEffectFlags;
- m_outlineLevel = attr.m_outlineLevel;
-}
-
-// Assignment from a wxTextAttrEx object
-void wxTextAttrEx::operator= (const wxTextAttrEx& attr)
-{
- Copy(attr);
-}
-
-// Assignment from a wxTextAttr object.
-void wxTextAttrEx::operator= (const wxTextAttr& attr)
-{
- wxTextAttr::operator= (attr);
-}
-
-// Equality test
-bool wxTextAttrEx::operator== (const wxTextAttrEx& attr) const
-{
- return (
- GetFlags() == attr.GetFlags() &&
- GetTextColour() == attr.GetTextColour() &&
- GetBackgroundColour() == attr.GetBackgroundColour() &&
- GetFont() == attr.GetFont() &&
- GetTextEffects() == attr.GetTextEffects() &&
- GetTextEffectFlags() == attr.GetTextEffectFlags() &&
- GetAlignment() == attr.GetAlignment() &&
- GetLeftIndent() == attr.GetLeftIndent() &&
- GetRightIndent() == attr.GetRightIndent() &&
- GetLeftSubIndent() == attr.GetLeftSubIndent() &&
- wxRichTextTabsEq(GetTabs(), attr.GetTabs()) &&
- GetLineSpacing() == attr.GetLineSpacing() &&
- GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter() &&
- GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore() &&
- GetBulletStyle() == attr.GetBulletStyle() &&
- GetBulletNumber() == attr.GetBulletNumber() &&
- GetBulletText() == attr.GetBulletText() &&
- GetBulletName() == attr.GetBulletName() &&
- GetBulletFont() == attr.GetBulletFont() &&
- GetCharacterStyleName() == attr.GetCharacterStyleName() &&
- GetParagraphStyleName() == attr.GetParagraphStyleName() &&
- GetListStyleName() == attr.GetListStyleName() &&
- GetOutlineLevel() == attr.GetOutlineLevel() &&
- GetURL() == attr.GetURL());
-}
-
-wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr,
- const wxTextAttrEx& attrDef,
- const wxTextCtrlBase *text)
-{
- wxTextAttrEx newAttr;
-
- // If attr specifies the complete font, just use that font, overriding all
- // default font attributes.
- if ((attr.GetFlags() & wxTEXT_ATTR_FONT) == wxTEXT_ATTR_FONT)
- newAttr.SetFont(attr.GetFont());
- else
- {
- // First find the basic, default font
- long flags = 0;
-
- wxFont font;
- if (attrDef.HasFont())
- {
- flags = (attrDef.GetFlags() & wxTEXT_ATTR_FONT);
- font = attrDef.GetFont();
- }
- else
- {
- if (text)
- font = text->GetFont();
-
- // We leave flags at 0 because no font attributes have been specified yet
- }
- if (!font.Ok())
- font = *wxNORMAL_FONT;
-
- // Otherwise, if there are font attributes in attr, apply them
- if (attr.GetFlags() & wxTEXT_ATTR_FONT)
- {
- if (attr.HasSize())
- {
- flags |= wxTEXT_ATTR_FONT_SIZE;
- font.SetPointSize(attr.GetFont().GetPointSize());
- }
- if (attr.HasItalic())
- {
- flags |= wxTEXT_ATTR_FONT_ITALIC;;
- font.SetStyle(attr.GetFont().GetStyle());
- }
- if (attr.HasWeight())
- {
- flags |= wxTEXT_ATTR_FONT_WEIGHT;
- font.SetWeight(attr.GetFont().GetWeight());
- }
- if (attr.HasFaceName())
- {
- flags |= wxTEXT_ATTR_FONT_FACE;
- font.SetFaceName(attr.GetFont().GetFaceName());
- }
- if (attr.HasUnderlined())
- {
- flags |= wxTEXT_ATTR_FONT_UNDERLINE;
- font.SetUnderlined(attr.GetFont().GetUnderlined());
- }
- newAttr.SetFont(font);
- newAttr.SetFlags(newAttr.GetFlags()|flags);
- }
- }
-
- // TODO: should really check we are specifying these in the flags,
- // before setting them, as per above; or we will set them willy-nilly.
- // However, we should also check whether this is the intention
- // as per wxTextAttr::Combine, i.e. always to have valid colours
- // in the style.
- wxColour colFg = attr.GetTextColour();
- if ( !colFg.Ok() )
- {
- colFg = attrDef.GetTextColour();
-
- if ( text && !colFg.Ok() )
- colFg = text->GetForegroundColour();
- }
-
- wxColour colBg = attr.GetBackgroundColour();
- if ( !colBg.Ok() )
- {
- colBg = attrDef.GetBackgroundColour();
-
- if ( text && !colBg.Ok() )
- colBg = text->GetBackgroundColour();
- }
-
- newAttr.SetTextColour(colFg);
- newAttr.SetBackgroundColour(colBg);
-
- if (attr.HasAlignment())
- newAttr.SetAlignment(attr.GetAlignment());
- else if (attrDef.HasAlignment())
- newAttr.SetAlignment(attrDef.GetAlignment());
-
- if (attr.HasTabs())
- newAttr.SetTabs(attr.GetTabs());
- else if (attrDef.HasTabs())
- newAttr.SetTabs(attrDef.GetTabs());
-
- if (attr.HasLeftIndent())
- newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent());
- else if (attrDef.HasLeftIndent())
- newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent());
-
- if (attr.HasRightIndent())
- newAttr.SetRightIndent(attr.GetRightIndent());
- else if (attrDef.HasRightIndent())
- newAttr.SetRightIndent(attrDef.GetRightIndent());
-
- // NEW ATTRIBUTES
-
- if (attr.HasParagraphSpacingAfter())
- newAttr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter());
-
- if (attr.HasParagraphSpacingBefore())
- newAttr.SetParagraphSpacingBefore(attr.GetParagraphSpacingBefore());
-
- if (attr.HasLineSpacing())
- newAttr.SetLineSpacing(attr.GetLineSpacing());
-
- if (attr.HasCharacterStyleName())
- newAttr.SetCharacterStyleName(attr.GetCharacterStyleName());
-
- if (attr.HasParagraphStyleName())
- newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
-
- if (attr.HasListStyleName())
- newAttr.SetListStyleName(attr.GetListStyleName());
-
- if (attr.HasBulletStyle())
- newAttr.SetBulletStyle(attr.GetBulletStyle());
-
- if (attr.HasBulletNumber())
- newAttr.SetBulletNumber(attr.GetBulletNumber());
-
- if (attr.HasBulletName())
- newAttr.SetBulletName(attr.GetBulletName());
-
- if (attr.HasBulletText())
- {
- newAttr.SetBulletText(attr.GetBulletText());
- newAttr.SetBulletFont(attr.GetBulletFont());
- }
-
- if (attr.HasURL())
- newAttr.SetURL(attr.GetURL());
-
- if (attr.HasTextEffects())
- {
- newAttr.SetTextEffects(attr.GetTextEffects());
- newAttr.SetTextEffectFlags(attr.GetTextEffectFlags());
- }
-
- if (attr.HasOutlineLevel())
- newAttr.SetOutlineLevel(attr.GetOutlineLevel());
-
- return newAttr;
-}
-
-