-/// Lay the item out
-bool wxRichTextImage::Layout(wxDC& WXUNUSED(dc), const wxRect& rect, int WXUNUSED(style))
-{
- if (!m_image.Ok())
- LoadFromBlock();
-
- if (m_image.Ok())
- {
- SetCachedSize(wxSize(m_image.GetWidth(), m_image.GetHeight()));
- SetPosition(rect.GetPosition());
- }
-
- return true;
-}
-
-/// Get/set the object size for the given range. Returns false if the range
-/// is invalid for this object.
-bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& WXUNUSED(descent), wxDC& WXUNUSED(dc), int WXUNUSED(flags), wxPoint WXUNUSED(position)) const
-{
- if (!range.IsWithin(GetRange()))
- return false;
-
- if (!m_image.Ok())
- return false;
-
- size.x = m_image.GetWidth();
- size.y = m_image.GetHeight();
-
- return true;
-}
-
-/// Copy
-void wxRichTextImage::Copy(const wxRichTextImage& obj)
-{
- m_image = obj.m_image;
- m_imageBlock = obj.m_imageBlock;
-}
-
-/*!
- * Utilities
- *
- */
-
-/// Compare two attribute objects
-bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2)
-{
- return (
- attr1.GetTextColour() == attr2.GetTextColour() &&
- attr1.GetBackgroundColour() == attr2.GetBackgroundColour() &&
- attr1.GetFont() == attr2.GetFont() &&
- attr1.GetAlignment() == attr2.GetAlignment() &&
- attr1.GetLeftIndent() == attr2.GetLeftIndent() &&
- attr1.GetRightIndent() == attr2.GetRightIndent() &&
- attr1.GetLeftSubIndent() == attr2.GetLeftSubIndent() &&
- attr1.GetTabs().GetCount() == attr2.GetTabs().GetCount() && // heuristic
- attr1.GetLineSpacing() == attr2.GetLineSpacing() &&
- attr1.GetParagraphSpacingAfter() == attr2.GetParagraphSpacingAfter() &&
- attr1.GetParagraphSpacingBefore() == attr2.GetParagraphSpacingBefore() &&
- attr1.GetBulletStyle() == attr2.GetBulletStyle() &&
- attr1.GetBulletNumber() == attr2.GetBulletNumber() &&
- attr1.GetBulletSymbol() == attr2.GetBulletSymbol() &&
- attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() &&
- attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName());
-}
-
-bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2)
-{
- return (
- attr1.GetTextColour() == attr2.GetTextColour() &&
- attr1.GetBackgroundColour() == attr2.GetBackgroundColour() &&
- attr1.GetFont().GetPointSize() == attr2.GetFontSize() &&
- attr1.GetFont().GetStyle() == attr2.GetFontStyle() &&
- attr1.GetFont().GetWeight() == attr2.GetFontWeight() &&
- attr1.GetFont().GetFaceName() == attr2.GetFontFaceName() &&
- attr1.GetFont().GetUnderlined() == attr2.GetFontUnderlined() &&
- attr1.GetAlignment() == attr2.GetAlignment() &&
- attr1.GetLeftIndent() == attr2.GetLeftIndent() &&
- attr1.GetRightIndent() == attr2.GetRightIndent() &&
- attr1.GetLeftSubIndent() == attr2.GetLeftSubIndent() &&
- attr1.GetTabs().GetCount() == attr2.GetTabs().GetCount() && // heuristic
- attr1.GetLineSpacing() == attr2.GetLineSpacing() &&
- attr1.GetParagraphSpacingAfter() == attr2.GetParagraphSpacingAfter() &&
- attr1.GetParagraphSpacingBefore() == attr2.GetParagraphSpacingBefore() &&
- attr1.GetBulletStyle() == attr2.GetBulletStyle() &&
- attr1.GetBulletNumber() == attr2.GetBulletNumber() &&
- attr1.GetBulletSymbol() == attr2.GetBulletSymbol() &&
- attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() &&
- attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName());
-}
-
-/// Compare two attribute objects, but take into account the flags
-/// specifying attributes of interest.
-bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2, int flags)
-{
- if ((flags & wxTEXT_ATTR_TEXT_COLOUR) && attr1.GetTextColour() != attr2.GetTextColour())
- return false;
-
- if ((flags & wxTEXT_ATTR_BACKGROUND_COLOUR) && attr1.GetBackgroundColour() != attr2.GetBackgroundColour())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_FACE) && attr1.GetFont().Ok() && attr2.GetFont().Ok() &&
- attr1.GetFont().GetFaceName() != attr2.GetFont().GetFaceName())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_SIZE) && attr1.GetFont().Ok() && attr2.GetFont().Ok() &&
- attr1.GetFont().GetPointSize() != attr2.GetFont().GetPointSize())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_WEIGHT) && attr1.GetFont().Ok() && attr2.GetFont().Ok() &&
- attr1.GetFont().GetWeight() != attr2.GetFont().GetWeight())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_ITALIC) && attr1.GetFont().Ok() && attr2.GetFont().Ok() &&
- attr1.GetFont().GetStyle() != attr2.GetFont().GetStyle())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_UNDERLINE) && attr1.GetFont().Ok() && attr2.GetFont().Ok() &&
- attr1.GetFont().GetUnderlined() != attr2.GetFont().GetUnderlined())
- return false;
-
- if ((flags & wxTEXT_ATTR_ALIGNMENT) && attr1.GetAlignment() != attr2.GetAlignment())
- return false;
-
- if ((flags & wxTEXT_ATTR_LEFT_INDENT) &&
- ((attr1.GetLeftIndent() != attr2.GetLeftIndent()) || (attr1.GetLeftSubIndent() != attr2.GetLeftSubIndent())))
- return false;
-
- if ((flags & wxTEXT_ATTR_RIGHT_INDENT) &&
- (attr1.GetRightIndent() != attr2.GetRightIndent()))
- return false;
-
- if ((flags & wxTEXT_ATTR_PARA_SPACING_AFTER) &&
- (attr1.GetParagraphSpacingAfter() != attr2.GetParagraphSpacingAfter()))
- return false;
-
- if ((flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) &&
- (attr1.GetParagraphSpacingBefore() != attr2.GetParagraphSpacingBefore()))
- return false;
-
- if ((flags & wxTEXT_ATTR_LINE_SPACING) &&
- (attr1.GetLineSpacing() != attr2.GetLineSpacing()))
- return false;
-
- if ((flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) &&
- (attr1.GetCharacterStyleName() != attr2.GetCharacterStyleName()))
- return false;
-
- if ((flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) &&
- (attr1.GetParagraphStyleName() != attr2.GetParagraphStyleName()))
- return false;
-
- 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_SYMBOL) &&
- (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()))
- return false;
-
-/* TODO
- if ((flags & wxTEXT_ATTR_TABS) &&
- return false;
-*/
-
- return true;
-}
-
-bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2, int flags)
-{
- if ((flags & wxTEXT_ATTR_TEXT_COLOUR) && attr1.GetTextColour() != attr2.GetTextColour())
- return false;
-
- if ((flags & wxTEXT_ATTR_BACKGROUND_COLOUR) && attr1.GetBackgroundColour() != attr2.GetBackgroundColour())
- return false;
-
- if ((flags & (wxTEXT_ATTR_FONT)) && !attr1.GetFont().Ok())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_FACE) && attr1.GetFont().Ok() &&
- attr1.GetFont().GetFaceName() != attr2.GetFontFaceName())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_SIZE) && attr1.GetFont().Ok() &&
- attr1.GetFont().GetPointSize() != attr2.GetFontSize())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_WEIGHT) && attr1.GetFont().Ok() &&
- attr1.GetFont().GetWeight() != attr2.GetFontWeight())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_ITALIC) && attr1.GetFont().Ok() &&
- attr1.GetFont().GetStyle() != attr2.GetFontStyle())
- return false;
-
- if ((flags & wxTEXT_ATTR_FONT_UNDERLINE) && attr1.GetFont().Ok() &&
- attr1.GetFont().GetUnderlined() != attr2.GetFontUnderlined())
- return false;
-
- if ((flags & wxTEXT_ATTR_ALIGNMENT) && attr1.GetAlignment() != attr2.GetAlignment())
- return false;
-
- if ((flags & wxTEXT_ATTR_LEFT_INDENT) &&
- ((attr1.GetLeftIndent() != attr2.GetLeftIndent()) || (attr1.GetLeftSubIndent() != attr2.GetLeftSubIndent())))
- return false;
-
- if ((flags & wxTEXT_ATTR_RIGHT_INDENT) &&
- (attr1.GetRightIndent() != attr2.GetRightIndent()))
- return false;
-
- if ((flags & wxTEXT_ATTR_PARA_SPACING_AFTER) &&
- (attr1.GetParagraphSpacingAfter() != attr2.GetParagraphSpacingAfter()))
- return false;
-
- if ((flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) &&
- (attr1.GetParagraphSpacingBefore() != attr2.GetParagraphSpacingBefore()))
- return false;
-
- if ((flags & wxTEXT_ATTR_LINE_SPACING) &&
- (attr1.GetLineSpacing() != attr2.GetLineSpacing()))
- return false;
-
- if ((flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) &&
- (attr1.GetCharacterStyleName() != attr2.GetCharacterStyleName()))
- return false;
-
- if ((flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) &&
- (attr1.GetParagraphStyleName() != attr2.GetParagraphStyleName()))
- return false;
-
- 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_SYMBOL) &&
- (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()))
- return false;
-
-/* TODO
- if ((flags & wxTEXT_ATTR_TABS) &&
- 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.HasBulletStyle())
- {
- destStyle.SetBulletStyle(style.GetBulletStyle());
- destStyle.SetBulletSymbol(style.GetBulletSymbol());
- }
-
- if (style.HasBulletNumber())
- destStyle.SetBulletNumber(style.GetBulletNumber());
-
- 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)
-{
- // Whole font. Avoiding setting individual attributes if possible, since
- // it recreates the font each time.
- if ((style.GetFlags() & (wxTEXT_ATTR_FONT)) == (wxTEXT_ATTR_FONT))
- {
- 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)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_FACE);
- font.SetFaceName(style.GetFontFaceName());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_SIZE)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_SIZE);
- font.SetPointSize(style.GetFontSize());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_ITALIC)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_ITALIC);
- font.SetStyle(style.GetFontStyle());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_WEIGHT)
- {
- destStyle.SetFlags(destStyle.GetFlags() | wxTEXT_ATTR_FONT_WEIGHT);
- font.SetWeight(style.GetFontWeight());
- }
-
- if (style.GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE)
- {
- 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())
- 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.HasBulletStyle())
- {
- destStyle.SetBulletStyle(style.GetBulletStyle());
- destStyle.SetBulletSymbol(style.GetBulletSymbol());
- }
-
- if (style.HasBulletNumber())
- destStyle.SetBulletNumber(style.GetBulletNumber());
-
- return true;
-}
-
-
-/*!
- * 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)