- // We'll replace the existing paragraph by finding the paragraph at this position,
- // delete its node data, and setting a copy as the new node data.
- // TODO: make more efficient by simply swapping old and new paragraph objects.
-
- wxRichTextParagraph* existingPara = m_buffer->GetParagraphAtPosition(para->GetRange().GetStart());
- if (existingPara)
- {
- wxRichTextObjectList::compatibility_iterator bufferParaNode = m_buffer->GetChildren().Find(existingPara);
- if (bufferParaNode)
- {
- wxRichTextParagraph* newPara = new wxRichTextParagraph(*para);
- newPara->SetParent(m_buffer);
-
- bufferParaNode->SetData(newPara);
-
- delete existingPara;
- }
- }
-
- node = node->GetNext();
- }
-}
-
-
-/*!
- * wxRichTextRange
- * This stores beginning and end positions for a range of data.
- */
-
-/// Limit this range to be within 'range'
-bool wxRichTextRange::LimitTo(const wxRichTextRange& range)
-{
- if (m_start < range.m_start)
- m_start = range.m_start;
-
- if (m_end > range.m_end)
- m_end = range.m_end;
-
- return true;
-}
-
-/*!
- * wxRichTextImage implementation
- * This object represents an image.
- */
-
-IMPLEMENT_DYNAMIC_CLASS(wxRichTextImage, wxRichTextObject)
-
-wxRichTextImage::wxRichTextImage(const wxImage& image, wxRichTextObject* parent):
- wxRichTextObject(parent)
-{
- m_image = image;
-}
-
-wxRichTextImage::wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent):
- wxRichTextObject(parent)
-{
- m_imageBlock = imageBlock;
- m_imageBlock.Load(m_image);
-}
-
-/// Load wxImage from the block
-bool wxRichTextImage::LoadFromBlock()
-{
- m_imageBlock.Load(m_image);
- return m_imageBlock.Ok();
-}
-
-/// Make block from the wxImage
-bool wxRichTextImage::MakeBlock()
-{
- if (m_imageBlock.GetImageType() == wxBITMAP_TYPE_ANY || m_imageBlock.GetImageType() == -1)
- m_imageBlock.SetImageType(wxBITMAP_TYPE_PNG);
-
- m_imageBlock.MakeImageBlock(m_image, m_imageBlock.GetImageType());
- return m_imageBlock.Ok();
-}
-
-
-/// Draw the item
-bool wxRichTextImage::Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int WXUNUSED(descent), int WXUNUSED(style))
-{
- if (!m_image.Ok() && m_imageBlock.Ok())
- LoadFromBlock();
-
- if (!m_image.Ok())
- return false;
-
- if (m_image.Ok() && !m_bitmap.Ok())
- m_bitmap = wxBitmap(m_image);
-
- int y = rect.y + (rect.height - m_image.GetHeight());
-
- if (m_bitmap.Ok())
- dc.DrawBitmap(m_bitmap, rect.x, y, true);
-
- if (selectionRange.Contains(range.GetStart()))
- {
- dc.SetBrush(*wxBLACK_BRUSH);
- dc.SetPen(*wxBLACK_PEN);
- dc.SetLogicalFunction(wxINVERT);
- dc.DrawRectangle(rect);
- dc.SetLogicalFunction(wxCOPY);
- }
-
- return true;
-}
-
-/// 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)
-{
- wxRichTextObject::Copy(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 == attr2);
-}
-
-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() &&
- wxRichTextTabsEq(attr1.GetTabs(), attr2.GetTabs()) &&
- attr1.GetLineSpacing() == attr2.GetLineSpacing() &&
- attr1.GetParagraphSpacingAfter() == attr2.GetParagraphSpacingAfter() &&
- attr1.GetParagraphSpacingBefore() == attr2.GetParagraphSpacingBefore() &&
- attr1.GetBulletStyle() == attr2.GetBulletStyle() &&
- attr1.GetBulletNumber() == attr2.GetBulletNumber() &&
- attr1.GetBulletText() == attr2.GetBulletText() &&
- attr1.GetBulletName() == attr2.GetBulletName() &&
- attr1.GetBulletFont() == attr2.GetBulletFont() &&
- attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() &&
- attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName() &&
- attr1.GetListStyleName() == attr2.GetListStyleName());
-}
-
-/// 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;