Made performance acceptable for editing large paragraphs on low-powered machines

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53337 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2008-04-24 14:39:33 +00:00
parent 109bfc88a4
commit 4f3d5bc061
2 changed files with 45 additions and 1 deletions

View File

@ -152,6 +152,7 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
#define wxRICHTEXT_FORMATTED 0x01 #define wxRICHTEXT_FORMATTED 0x01
#define wxRICHTEXT_UNFORMATTED 0x02 #define wxRICHTEXT_UNFORMATTED 0x02
#define wxRICHTEXT_CACHE_SIZE 0x04 #define wxRICHTEXT_CACHE_SIZE 0x04
#define wxRICHTEXT_HEIGHT_ONLY 0x08
/*! /*!
* Flags for SetStyle/SetListStyle * Flags for SetStyle/SetListStyle

View File

@ -3238,6 +3238,22 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR
return true; return true;
} }
// Get the range width using partial extents calculated for the whole paragraph.
static int wxRichTextGetRangeWidth(const wxRichTextParagraph& para, const wxRichTextRange& range, const wxArrayInt& partialExtents)
{
wxASSERT(partialExtents.GetCount() >= (size_t) range.GetLength());
int leftMostPos = 0;
if (range.GetStart() - para.GetRange().GetStart() > 0)
leftMostPos = partialExtents[range.GetStart() - para.GetRange().GetStart() - 1];
int rightMostPos = partialExtents[range.GetEnd() - para.GetRange().GetStart()];
int w = rightMostPos - leftMostPos;
return w;
}
/// Lay the item out /// Lay the item out
bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
{ {
@ -3361,7 +3377,15 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
childDescent = child->GetDescent(); childDescent = child->GetDescent();
} }
else else
{
#if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS
// Get height only, then the width using the partial extents
GetRangeSize(wxRichTextRange(lastEndPos+1, lastPosToUse), childSize, childDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_HEIGHT_ONLY);
childSize.x = wxRichTextGetRangeWidth(*this, wxRichTextRange(lastEndPos+1, lastPosToUse), partialExtents);
#else
GetRangeSize(wxRichTextRange(lastEndPos+1, lastPosToUse), childSize, childDescent, dc, wxRICHTEXT_UNFORMATTED, rect.GetPosition()); GetRangeSize(wxRichTextRange(lastEndPos+1, lastPosToUse), childSize, childDescent, dc, wxRICHTEXT_UNFORMATTED, rect.GetPosition());
#endif
}
// Cases: // Cases:
// 1) There was a line break BEFORE the natural break // 1) There was a line break BEFORE the natural break
@ -3390,7 +3414,15 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
// Let's find the actual size of the current line now // Let's find the actual size of the current line now
wxSize actualSize; wxSize actualSize;
wxRichTextRange actualRange(lastCompletedEndPos+1, wrapPosition); wxRichTextRange actualRange(lastCompletedEndPos+1, wrapPosition);
#if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS
// Get height only, then the width using the partial extents
GetRangeSize(actualRange, actualSize, childDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_HEIGHT_ONLY);
actualSize.x = wxRichTextGetRangeWidth(*this, actualRange, partialExtents);
#else
GetRangeSize(actualRange, actualSize, childDescent, dc, wxRICHTEXT_UNFORMATTED); GetRangeSize(actualRange, actualSize, childDescent, dc, wxRICHTEXT_UNFORMATTED);
#endif
currentWidth = actualSize.x; currentWidth = actualSize.x;
lineHeight = wxMax(lineHeight, actualSize.y); lineHeight = wxMax(lineHeight, actualSize.y);
maxDescent = wxMax(childDescent, maxDescent); maxDescent = wxMax(childDescent, maxDescent);
@ -3676,7 +3708,18 @@ bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& siz
rangeToUse.LimitTo(child->GetRange()); rangeToUse.LimitTo(child->GetRange());
int childDescent = 0; int childDescent = 0;
if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags, wxPoint(position.x + sz.x, position.y), p)) // At present wxRICHTEXT_HEIGHT_ONLY is only fast if we're already cached the size,
// but it's only going to be used after caching has taken place.
if ((flags & wxRICHTEXT_HEIGHT_ONLY) && child->GetCachedSize().y != 0)
{
childDescent = child->GetDescent();
childSize = child->GetCachedSize();
sz.y = wxMax(sz.y, childSize.y);
sz.x += childSize.x;
descent = wxMax(descent, childDescent);
}
else if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags, wxPoint(position.x + sz.x, position.y), p))
{ {
sz.y = wxMax(sz.y, childSize.y); sz.y = wxMax(sz.y, childSize.y);
sz.x += childSize.x; sz.x += childSize.x;