- if ((flags & wxTEXT_ATTR_BULLET_STYLE) &&
- (attr1.GetBulletStyle() != attr2.GetBulletStyle()))
- return false;
-
- if ((flags & wxTEXT_ATTR_BULLET_NUMBER) &&
- (attr1.GetBulletNumber() != attr2.GetBulletNumber()))
- return false;
-
- if ((flags & wxTEXT_ATTR_BULLET_TEXT) &&
- (attr1.GetBulletText() != attr2.GetBulletText()) &&
- (attr1.GetBulletFont() != attr2.GetBulletFont()))
- return false;
-
- if ((flags & wxTEXT_ATTR_BULLET_NAME) &&
- (attr1.GetBulletName() != attr2.GetBulletName()))
- return false;
-
- if ((flags & wxTEXT_ATTR_TABS) &&
- !wxRichTextTabsEq(attr1.GetTabs(), attr2.GetTabs()))
- return false;
-
- return true;
-}
-
-/// Compare tabs
-bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2)
-{
- if (tabs1.GetCount() != tabs2.GetCount())
- return false;
-
- size_t i;
- for (i = 0; i < tabs1.GetCount(); i++)
- {
- if (tabs1[i] != tabs2[i])
- return false;
- }
- return true;
-}
-
-
-/// Apply one style to another
-bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style)
-{
- // Whole font
- if (style.GetFont().Ok() && ((style.GetFlags() & (wxTEXT_ATTR_FONT)) == (wxTEXT_ATTR_FONT)))
- destStyle.SetFont(style.GetFont());
- else if (style.GetFont().Ok())
- {
- wxFont font = destStyle.GetFont();
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_FACE)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_FACE);
- font.SetFaceName(style.GetFont().GetFaceName());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_SIZE)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_SIZE);
- font.SetPointSize(style.GetFont().GetPointSize());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_ITALIC)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_ITALIC);
- font.SetStyle(style.GetFont().GetStyle());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_WEIGHT)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_WEIGHT);
- font.SetWeight(style.GetFont().GetWeight());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE);
- font.SetUnderlined(style.GetFont().GetUnderlined());
- }
-
- if (font != destStyle.GetFont())
- {
- int oldFlags = destStyle.GetFlags();
-
- destStyle.SetFont(font);
-
- destStyle.SetFlags(oldFlags);
- }
- }
-
- if ( style.GetTextColour().Ok() && style.HasTextColour())
- destStyle.SetTextColour(style.GetTextColour());
-
- if ( style.GetBackgroundColour().Ok() && style.HasBackgroundColour())
- destStyle.SetBackgroundColour(style.GetBackgroundColour());
-
- if (style.HasAlignment())
- destStyle.SetAlignment(style.GetAlignment());
-
- if (style.HasTabs())
- destStyle.SetTabs(style.GetTabs());
-
- if (style.HasLeftIndent())
- destStyle.SetLeftIndent(style.GetLeftIndent(), style.GetLeftSubIndent());
-
- if (style.HasRightIndent())
- destStyle.SetRightIndent(style.GetRightIndent());
-
- if (style.HasParagraphSpacingAfter())
- destStyle.SetParagraphSpacingAfter(style.GetParagraphSpacingAfter());
-
- if (style.HasParagraphSpacingBefore())
- destStyle.SetParagraphSpacingBefore(style.GetParagraphSpacingBefore());
-
- if (style.HasLineSpacing())
- destStyle.SetLineSpacing(style.GetLineSpacing());
-
- if (style.HasCharacterStyleName())
- destStyle.SetCharacterStyleName(style.GetCharacterStyleName());
-
- if (style.HasParagraphStyleName())
- destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
-
- if (style.HasListStyleName())
- destStyle.SetListStyleName(style.GetListStyleName());
-
- if (style.HasBulletStyle())
- destStyle.SetBulletStyle(style.GetBulletStyle());
-
- if (style.HasBulletText())
- {
- destStyle.SetBulletText(style.GetBulletText());
- destStyle.SetBulletFont(style.GetBulletFont());
- }
-
- if (style.HasBulletName())
- destStyle.SetBulletName(style.GetBulletName());
-
- if (style.HasBulletNumber())
- destStyle.SetBulletNumber(style.GetBulletNumber());
-
- if (style.HasURL())
- destStyle.SetURL(style.GetURL());
-
- return true;
-}
-
-bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style)
-{
- wxTextAttrEx destStyle2;
- destStyle.CopyTo(destStyle2);
- wxRichTextApplyStyle(destStyle2, style);
- destStyle = destStyle2;
- return true;
-}
-
-bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith)
-{
- // Whole font. Avoiding setting individual attributes if possible, since
- // it recreates the font each time.
- if (((style.GetFlags() & (wxTEXT_ATTR_FONT)) == (wxTEXT_ATTR_FONT)) && !compareWith)
- {
- destStyle.SetFont(wxFont(style.GetFontSize(), destStyle.GetFont().Ok() ? destStyle.GetFont().GetFamily() : wxDEFAULT,
- style.GetFontStyle(), style.GetFontWeight(), style.GetFontUnderlined(), style.GetFontFaceName()));
- }
- else if (style.GetFlags() & (wxTEXT_ATTR_FONT))
- {
- wxFont font = destStyle.GetFont();
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_FACE)
- {
- if (compareWith && compareWith->HasFaceName() && compareWith->GetFontFaceName() == style.GetFontFaceName())
- {
- // The same as currently displayed, so don't set
- }
- else
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_FACE);
- font.SetFaceName(style.GetFontFaceName());
- }
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_SIZE)
- {
- if (compareWith && compareWith->HasSize() && compareWith->GetFontSize() == style.GetFontSize())
- {
- // The same as currently displayed, so don't set
- }
- else
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_SIZE);
- font.SetPointSize(style.GetFontSize());
- }
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_ITALIC)
- {
- if (compareWith && compareWith->HasItalic() && compareWith->GetFontStyle() == style.GetFontStyle())
- {
- // The same as currently displayed, so don't set
- }
- else
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_ITALIC);
- font.SetStyle(style.GetFontStyle());
- }
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_WEIGHT)
- {
- if (compareWith && compareWith->HasWeight() && compareWith->GetFontWeight() == style.GetFontWeight())
- {
- // The same as currently displayed, so don't set
- }
- else
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_WEIGHT);
- font.SetWeight(style.GetFontWeight());
- }
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE)
- {
- if (compareWith && compareWith->HasUnderlined() && compareWith->GetFontUnderlined() == style.GetFontUnderlined())
- {
- // The same as currently displayed, so don't set
- }
- else
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE);
- font.SetUnderlined(style.GetFontUnderlined());
- }
- }
-
- if (font != destStyle.GetFont())
- {
- int oldFlags = destStyle.GetFlags();
-
- destStyle.SetFont(font);
-
- destStyle.SetFlags(oldFlags);
- }
- }
-
- if (style.GetTextColour().Ok() && style.HasTextColour())
- {
- if (!(compareWith && compareWith->HasTextColour() && compareWith->GetTextColour() == style.GetTextColour()))
- destStyle.SetTextColour(style.GetTextColour());
- }
-
- if (style.GetBackgroundColour().Ok() && style.HasBackgroundColour())
- {
- if (!(compareWith && compareWith->HasBackgroundColour() && compareWith->GetBackgroundColour() == style.GetBackgroundColour()))
- destStyle.SetBackgroundColour(style.GetBackgroundColour());
- }
-
- if (style.HasAlignment())
- {
- if (!(compareWith && compareWith->HasAlignment() && compareWith->GetAlignment() == style.GetAlignment()))
- destStyle.SetAlignment(style.GetAlignment());
- }
-
- if (style.HasTabs())
- {
- if (!(compareWith && compareWith->HasTabs() && wxRichTextTabsEq(compareWith->GetTabs(), style.GetTabs())))
- destStyle.SetTabs(style.GetTabs());
- }
-
- if (style.HasLeftIndent())
- {
- if (!(compareWith && compareWith->HasLeftIndent() && compareWith->GetLeftIndent() == style.GetLeftIndent()
- && compareWith->GetLeftSubIndent() == style.GetLeftSubIndent()))
- destStyle.SetLeftIndent(style.GetLeftIndent(), style.GetLeftSubIndent());
- }
-
- if (style.HasRightIndent())
- {
- if (!(compareWith && compareWith->HasRightIndent() && compareWith->GetRightIndent() == style.GetRightIndent()))
- destStyle.SetRightIndent(style.GetRightIndent());
- }
-
- if (style.HasParagraphSpacingAfter())
- {
- if (!(compareWith && compareWith->HasParagraphSpacingAfter() && compareWith->GetParagraphSpacingAfter() == style.GetParagraphSpacingAfter()))
- destStyle.SetParagraphSpacingAfter(style.GetParagraphSpacingAfter());
- }
-
- if (style.HasParagraphSpacingBefore())
- {
- if (!(compareWith && compareWith->HasParagraphSpacingBefore() && compareWith->GetParagraphSpacingBefore() == style.GetParagraphSpacingBefore()))
- destStyle.SetParagraphSpacingBefore(style.GetParagraphSpacingBefore());
- }
-
- if (style.HasLineSpacing())
- {
- if (!(compareWith && compareWith->HasLineSpacing() && compareWith->GetLineSpacing() == style.GetLineSpacing()))
- destStyle.SetLineSpacing(style.GetLineSpacing());
- }
-
- if (style.HasCharacterStyleName())
- {
- if (!(compareWith && compareWith->HasCharacterStyleName() && compareWith->GetCharacterStyleName() == style.GetCharacterStyleName()))
- destStyle.SetCharacterStyleName(style.GetCharacterStyleName());
- }
-
- if (style.HasParagraphStyleName())
- {
- if (!(compareWith && compareWith->HasParagraphStyleName() && compareWith->GetParagraphStyleName() == style.GetParagraphStyleName()))
- destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
- }
-
- if (style.HasListStyleName())
- {
- if (!(compareWith && compareWith->HasListStyleName() && compareWith->GetListStyleName() == style.GetListStyleName()))
- destStyle.SetListStyleName(style.GetListStyleName());
- }
-
- if (style.HasBulletStyle())
- {
- if (!(compareWith && compareWith->HasBulletStyle() && compareWith->GetBulletStyle() == style.GetBulletStyle()))
- destStyle.SetBulletStyle(style.GetBulletStyle());
- }
-
- if (style.HasBulletText())
- {
- if (!(compareWith && compareWith->HasBulletText() && compareWith->GetBulletText() == style.GetBulletText()))
- {
- destStyle.SetBulletText(style.GetBulletText());
- destStyle.SetBulletFont(style.GetBulletFont());
- }
- }
-
- if (style.HasBulletNumber())
- {
- if (!(compareWith && compareWith->HasBulletNumber() && compareWith->GetBulletNumber() == style.GetBulletNumber()))
- destStyle.SetBulletNumber(style.GetBulletNumber());
- }
-
- if (style.HasBulletName())
- {
- if (!(compareWith && compareWith->HasBulletName() && compareWith->GetBulletName() == style.GetBulletName()))
- destStyle.SetBulletName(style.GetBulletName());
- }
-
- if (style.HasURL())
- {
- if (!(compareWith && compareWith->HasURL() && compareWith->GetURL() == style.GetURL()))
- destStyle.SetURL(style.GetURL());
- }
-
- return true;
-}
-
-void wxSetFontPreservingStyles(wxTextAttr& attr, const wxFont& font)
-{
- long flags = attr.GetFlags();
- attr.SetFont(font);
- attr.SetFlags(flags);
-}
-
-/// Convert a decimal to Roman numerals
-wxString wxRichTextDecimalToRoman(long n)
-{
- static wxArrayInt decimalNumbers;
- static wxArrayString romanNumbers;
-
- // Clean up arrays
- if (n == -1)
- {
- decimalNumbers.Clear();
- romanNumbers.Clear();
- return wxEmptyString;
- }
-
- if (decimalNumbers.GetCount() == 0)
- {
- #define wxRichTextAddDecRom(n, r) decimalNumbers.Add(n); romanNumbers.Add(r);
-
- wxRichTextAddDecRom(1000, wxT("M"));
- wxRichTextAddDecRom(900, wxT("CM"));
- wxRichTextAddDecRom(500, wxT("D"));
- wxRichTextAddDecRom(400, wxT("CD"));
- wxRichTextAddDecRom(100, wxT("C"));
- wxRichTextAddDecRom(90, wxT("XC"));
- wxRichTextAddDecRom(50, wxT("L"));
- wxRichTextAddDecRom(40, wxT("XL"));
- wxRichTextAddDecRom(10, wxT("X"));
- wxRichTextAddDecRom(9, wxT("IX"));
- wxRichTextAddDecRom(5, wxT("V"));
- wxRichTextAddDecRom(4, wxT("IV"));
- wxRichTextAddDecRom(1, wxT("I"));
- }
-
- int i = 0;
- wxString roman;
-
- while (n > 0 && i < 13)
- {
- if (n >= decimalNumbers[i])
- {
- n -= decimalNumbers[i];
- roman += romanNumbers[i];
- }
- else
- {
- i ++;
- }
- }
- if (roman.IsEmpty())
- roman = wxT("0");
- return roman;
-}
-
-/*!
- * 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_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_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;
-}
-
-// operators
-void wxRichTextAttr::operator= (const wxRichTextAttr& attr)
-{
- Copy(attr);
-}
-
-// operators
-void wxRichTextAttr::operator= (const wxTextAttrEx& attr)
-{
- 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_flags = attr.GetFlags();
-
- 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_urlTarget = attr.GetURL();
-
- if (attr.GetFont().Ok())
- GetFontAttributes(attr.GetFont());
-}
-
-// Making a wxTextAttrEx object.
-wxRichTextAttr::operator wxTextAttrEx () const
-{
- wxTextAttrEx attr;
- CopyTo(attr);
- 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() &&
-
- 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_urlTarget == attr.m_urlTarget;
-}
-
-// Copy to a wxTextAttr
-void wxRichTextAttr::CopyTo(wxTextAttrEx& attr) const
-{
- 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.SetURL(m_urlTarget);
-
- attr.SetFlags(GetFlags()); // Important: set after SetFont and others, since they set flags
-}
-
-// 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());
-
- return newAttr;
-}
-
-/*!
- * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
- */
-
-wxTextAttrEx::wxTextAttrEx(const wxTextAttrEx& attr)
-{
- 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_bulletNumber = 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;
-}
-
-// 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 (
- GetTextColour() == attr.GetTextColour() &&
- GetBackgroundColour() == attr.GetBackgroundColour() &&
- GetFont() == attr.GetFont() &&
- 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() &&
- 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());
-
- return newAttr;
-}
-
-
-/*!
- * wxRichTextFileHandler
- * Base class for file handlers
- */
-
-IMPLEMENT_CLASS(wxRichTextFileHandler, wxObject)
-
-#if wxUSE_STREAMS
-bool wxRichTextFileHandler::LoadFile(wxRichTextBuffer *buffer, const wxString& filename)
-{
- wxFFileInputStream stream(filename);
- if (stream.Ok())
- return LoadFile(buffer, stream);
-
- return false;
-}
-
-bool wxRichTextFileHandler::SaveFile(wxRichTextBuffer *buffer, const wxString& filename)
-{
- wxFFileOutputStream stream(filename);
- if (stream.Ok())
- return SaveFile(buffer, stream);
-
- return false;
-}
-#endif // wxUSE_STREAMS
-
-/// Can we handle this filename (if using files)? By default, checks the extension.
-bool wxRichTextFileHandler::CanHandle(const wxString& filename) const
-{
- wxString path, file, ext;
- wxSplitPath(filename, & path, & file, & ext);
-
- return (ext.Lower() == GetExtension());
-}
-
-/*!
- * wxRichTextTextHandler
- * Plain text handler
- */
-
-IMPLEMENT_CLASS(wxRichTextPlainTextHandler, wxRichTextFileHandler)
-
-#if wxUSE_STREAMS
-bool wxRichTextPlainTextHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
-{
- if (!stream.IsOk())
- return false;
-
- wxString str;
- int lastCh = 0;
-
- while (!stream.Eof())
- {
- int ch = stream.GetC();
-
- if (!stream.Eof())
- {
- if (ch == 10 && lastCh != 13)
- str += wxT('\n');
-
- if (ch > 0 && ch != 10)
- str += wxChar(ch);
-
- lastCh = ch;
- }
- }
-
- buffer->Clear();
- buffer->AddParagraphs(str);
- buffer->UpdateRanges();
-
- return true;
-
-}
-
-bool wxRichTextPlainTextHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
-{
- if (!stream.IsOk())
- return false;
-
- wxString text = buffer->GetText();
- wxCharBuffer buf = text.ToAscii();