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

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53338 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2008-04-24 14:39:54 +00:00
parent 3bc1747441
commit 567197af17
2 changed files with 45 additions and 1 deletions

View File

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

View File

@@ -3357,6 +3357,22 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR
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
bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
{
@@ -3481,7 +3497,15 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
childDescent = child->GetDescent();
}
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), g_GlobalPartialTextExtents);
#else
GetRangeSize(wxRichTextRange(lastEndPos+1, lastPosToUse), childSize, childDescent, dc, wxRICHTEXT_UNFORMATTED, rect.GetPosition());
#endif
}
// Cases:
// 1) There was a line break BEFORE the natural break
@@ -3510,7 +3534,15 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
// Let's find the actual size of the current line now
wxSize actualSize;
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, g_GlobalPartialTextExtents);
#else
GetRangeSize(actualRange, actualSize, childDescent, dc, wxRICHTEXT_UNFORMATTED);
#endif
currentWidth = actualSize.x;
lineHeight = wxMax(lineHeight, actualSize.y);
maxDescent = wxMax(childDescent, maxDescent);
@@ -3790,7 +3822,18 @@ bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& siz
rangeToUse.LimitTo(child->GetRange());
int childDescent = 0;
if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags, wxPoint(position.x + sz.x, position.y)))
// 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)))
{
sz.y = wxMax(sz.y, childSize.y);
sz.x += childSize.x;