~wxRichTextRange() {}
void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
+ bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); }
wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); }
wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); }
/// Lay the item out at the specified position with the given size constraint.
/// Layout must set the cached size.
- virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style) = 0;
+ virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0;
/// Hit-testing: returns a flag indicating hit test details, plus
/// information about position
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
/// Get basic (overall) style
virtual const wxTextAttrEx& GetBasicStyle() const { return m_attributes; }
+ /// Invalidate the buffer. With no argument, invalidates whole buffer.
+ void Invalidate(const wxRichTextRange& invalidRange = wxRichTextRange(-1, -1));
+
+ /// Get invalid range, rounding to entire paragraphs if argument is true.
+ wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const;
+
protected:
wxRichTextCtrl* m_ctrl;
wxTextAttrEx m_defaultAttributes;
+
+ /// The invalidated range that will need full layout
+ wxRichTextRange m_invalidRange;
};
/*!
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
/// Get the object size for the given range. Returns false if the range
/// is invalid for this object.
}
/// Lay the item out
-bool wxRichTextBox::Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style)
+bool wxRichTextBox::Layout(wxDC& dc, const wxRect& rect, int style)
{
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxRichTextObject* child = node->GetData();
- child->Layout(dc, rect, affected, style);
+ child->Layout(dc, rect, style);
node = node->GetNext();
}
// For now, assume is the only box and has no initial size.
m_range = wxRichTextRange(0, -1);
+ m_invalidRange.SetRange(-1, -1);
m_leftMargin = 4;
m_rightMargin = 4;
m_topMargin = 4;
}
/// Lay the item out
-bool wxRichTextParagraphLayoutBox::Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style)
+bool wxRichTextParagraphLayoutBox::Layout(wxDC& dc, const wxRect& rect, int style)
{
wxRect availableSpace(rect.x + m_leftMargin,
rect.y + m_topMargin,
int maxWidth = 0;
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
-
- // If we know what range is affected, start laying out from that point on.
- if (affected.GetStart() > GetRange().GetStart())
+
+ bool layoutAll = true;
+
+ // Get invalid range, rounding to paragraph start/end.
+ wxRichTextRange invalidRange = GetInvalidRange(true);
+
+ if (invalidRange == wxRichTextRange(-1, -1))
+ layoutAll = true;
+ else // If we know what range is affected, start laying out from that point on.
+ if (invalidRange.GetStart() > GetRange().GetStart())
{
- wxRichTextParagraph* firstParagraph = GetParagraphAtPosition(affected.GetStart());
+ wxRichTextParagraph* firstParagraph = GetParagraphAtPosition(invalidRange.GetStart());
if (firstParagraph)
{
wxRichTextObjectList::compatibility_iterator firstNode = m_children.Find(firstParagraph);
wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph);
wxASSERT (child != NULL);
- if (child && !child->GetRange().IsOutside(affected))
+ if (child && (layoutAll || !child->GetRange().IsOutside(invalidRange)))
{
- child->Layout(dc, availableSpace, affected, style);
+ child->Layout(dc, availableSpace, style);
// Layout must set the cached size
availableSpace.y += child->GetCachedSize().y;
if (child)
{
if (child->GetLines().GetCount() == 0)
- child->Layout(dc, availableSpace, affected, style);
+ child->Layout(dc, availableSpace, style);
else
child->SetPosition(wxPoint(child->GetPosition().x, child->GetPosition().y + inc));
SetCachedSize(wxSize(maxWidth, availableSpace.y));
m_dirty = false;
+ m_invalidRange = wxRichTextRange(-1, -1);
return true;
}
AddParagraph(wxEmptyString);
}
+/// Invalidate the buffer. With no argument, invalidates whole buffer.
+void wxRichTextParagraphLayoutBox::Invalidate(const wxRichTextRange& invalidRange)
+{
+ SetDirty(true);
+
+ if (invalidRange == wxRichTextRange(-1, -1))
+ {
+ m_invalidRange = invalidRange;
+ return;
+ }
+
+ if (invalidRange.GetStart() < m_invalidRange.GetStart())
+ m_invalidRange.SetStart(invalidRange.GetStart());
+ if (invalidRange.GetEnd() > m_invalidRange.GetEnd())
+ m_invalidRange.SetEnd(invalidRange.GetEnd());
+}
+
+/// Get invalid range, rounding to entire paragraphs if argument is true.
+wxRichTextRange wxRichTextParagraphLayoutBox::GetInvalidRange(bool wholeParagraphs) const
+{
+ if (m_invalidRange == wxRichTextRange(-1, -1))
+ return m_invalidRange;
+
+ wxRichTextRange range = m_invalidRange;
+
+ if (wholeParagraphs)
+ {
+ wxRichTextParagraph* para1 = GetParagraphAtPosition(range.GetStart());
+ wxRichTextParagraph* para2 = GetParagraphAtPosition(range.GetEnd());
+ if (para1)
+ range.SetStart(para1->GetRange().GetStart());
+ if (para2)
+ range.SetEnd(para2->GetRange().GetEnd());
+ }
+ return range;
+}
+
/*!
* wxRichTextFragment class declaration
* This is a lind of paragraph layout box used for storing
}
/// Lay the item out
-bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style)
+bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
{
ClearLines();
// can't tell the position until the size is determined. So possibly introduce
// another layout phase.
- child->Layout(dc, rect, affected, style);
+ child->Layout(dc, rect, style);
// Available width depends on whether we're on the first or subsequent lines
int availableSpaceForText = (lineCount == 0 ? availableTextSpaceFirstLine : availableTextSpaceSubsequentLines);
}
/// Lay the item out
-bool wxRichTextPlainText::Layout(wxDC& dc, const wxRect& WXUNUSED(rect), const wxRichTextRange& WXUNUSED(affected), int WXUNUSED(style))
+bool wxRichTextPlainText::Layout(wxDC& dc, const wxRect& WXUNUSED(rect), int WXUNUSED(style))
{
if (GetAttributes().GetFont().Ok())
dc.SetFont(GetAttributes().GetFont());
}
/// Lay the item out
-bool wxRichTextImage::Layout(wxDC& WXUNUSED(dc), const wxRect& rect, const wxRichTextRange& WXUNUSED(affected), int WXUNUSED(style))
+bool wxRichTextImage::Layout(wxDC& WXUNUSED(dc), const wxRect& rect, int WXUNUSED(style))
{
if (!m_image.Ok())
LoadFromBlock();