Further optimizations
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53335 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -539,7 +539,7 @@ public:
|
|||||||
bool DeleteChildren() ;
|
bool DeleteChildren() ;
|
||||||
|
|
||||||
/// Recursively merge all pieces that can be merged.
|
/// Recursively merge all pieces that can be merged.
|
||||||
bool Defragment();
|
bool Defragment(const wxRichTextRange& range = wxRICHTEXT_ALL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxRichTextObjectList m_children;
|
wxRichTextObjectList m_children;
|
||||||
|
@@ -425,26 +425,31 @@ wxString wxRichTextCompositeObject::GetTextForRange(const wxRichTextRange& range
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively merge all pieces that can be merged.
|
/// Recursively merge all pieces that can be merged.
|
||||||
bool wxRichTextCompositeObject::Defragment()
|
bool wxRichTextCompositeObject::Defragment(const wxRichTextRange& range)
|
||||||
{
|
{
|
||||||
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
|
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
|
||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxRichTextObject* child = node->GetData();
|
wxRichTextObject* child = node->GetData();
|
||||||
wxRichTextCompositeObject* composite = wxDynamicCast(child, wxRichTextCompositeObject);
|
if (!child->GetRange().IsOutside(range))
|
||||||
if (composite)
|
|
||||||
composite->Defragment();
|
|
||||||
|
|
||||||
if (node->GetNext())
|
|
||||||
{
|
{
|
||||||
wxRichTextObject* nextChild = node->GetNext()->GetData();
|
wxRichTextCompositeObject* composite = wxDynamicCast(child, wxRichTextCompositeObject);
|
||||||
if (child->CanMerge(nextChild) && child->Merge(nextChild))
|
if (composite)
|
||||||
{
|
composite->Defragment();
|
||||||
nextChild->Dereference();
|
|
||||||
m_children.Erase(node->GetNext());
|
|
||||||
|
|
||||||
// Don't set node -- we'll see if we can merge again with the next
|
if (node->GetNext())
|
||||||
// child.
|
{
|
||||||
|
wxRichTextObject* nextChild = node->GetNext()->GetData();
|
||||||
|
if (child->CanMerge(nextChild) && child->Merge(nextChild))
|
||||||
|
{
|
||||||
|
nextChild->Dereference();
|
||||||
|
m_children.Erase(node->GetNext());
|
||||||
|
|
||||||
|
// Don't set node -- we'll see if we can merge again with the next
|
||||||
|
// child.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
@@ -4800,6 +4805,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool haveDescent = false;
|
||||||
int startPos = range.GetStart() - GetRange().GetStart();
|
int startPos = range.GetStart() - GetRange().GetStart();
|
||||||
long len = range.GetLength();
|
long len = range.GetLength();
|
||||||
|
|
||||||
@@ -4836,23 +4842,39 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
|
|||||||
|
|
||||||
while (stringChunk.Find(wxT('\t')) >= 0)
|
while (stringChunk.Find(wxT('\t')) >= 0)
|
||||||
{
|
{
|
||||||
|
int absoluteWidth = 0;
|
||||||
|
|
||||||
// the string has a tab
|
// the string has a tab
|
||||||
// break up the string at the Tab
|
// break up the string at the Tab
|
||||||
wxString stringFragment = stringChunk.BeforeFirst(wxT('\t'));
|
wxString stringFragment = stringChunk.BeforeFirst(wxT('\t'));
|
||||||
stringChunk = stringChunk.AfterFirst(wxT('\t'));
|
stringChunk = stringChunk.AfterFirst(wxT('\t'));
|
||||||
int oldWidth = width;
|
|
||||||
dc.GetTextExtent(stringFragment, & w, & h);
|
|
||||||
width += w;
|
|
||||||
int absoluteWidth = width + position.x;
|
|
||||||
|
|
||||||
if (partialExtents)
|
if (partialExtents)
|
||||||
{
|
{
|
||||||
|
int oldWidth;
|
||||||
|
if (partialExtents->GetCount() > 0)
|
||||||
|
oldWidth = (*partialExtents)[partialExtents->GetCount()-1];
|
||||||
|
else
|
||||||
|
oldWidth = 0;
|
||||||
|
|
||||||
// Add these partial extents
|
// Add these partial extents
|
||||||
wxArrayInt p;
|
wxArrayInt p;
|
||||||
dc.GetPartialTextExtents(stringFragment, p);
|
dc.GetPartialTextExtents(stringFragment, p);
|
||||||
size_t j;
|
size_t j;
|
||||||
for (j = 0; j < p.GetCount(); j++)
|
for (j = 0; j < p.GetCount(); j++)
|
||||||
partialExtents->Add(oldWidth + p[j]);
|
partialExtents->Add(oldWidth + p[j]);
|
||||||
|
|
||||||
|
if (partialExtents->GetCount() > 0)
|
||||||
|
absoluteWidth = (*partialExtents)[(*partialExtents).GetCount()-1] + position.x;
|
||||||
|
else
|
||||||
|
absoluteWidth = position.x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dc.GetTextExtent(stringFragment, & w, & h);
|
||||||
|
width += w;
|
||||||
|
absoluteWidth = width + position.x;
|
||||||
|
haveDescent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notFound = true;
|
bool notFound = true;
|
||||||
@@ -4883,12 +4905,14 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
|
|||||||
|
|
||||||
if (!stringChunk.IsEmpty())
|
if (!stringChunk.IsEmpty())
|
||||||
{
|
{
|
||||||
dc.GetTextExtent(stringChunk, & w, & h, & descent);
|
|
||||||
int oldWidth = width;
|
|
||||||
width += w;
|
|
||||||
|
|
||||||
if (partialExtents)
|
if (partialExtents)
|
||||||
{
|
{
|
||||||
|
int oldWidth;
|
||||||
|
if (partialExtents->GetCount() > 0)
|
||||||
|
oldWidth = (*partialExtents)[partialExtents->GetCount()-1];
|
||||||
|
else
|
||||||
|
oldWidth = 0;
|
||||||
|
|
||||||
// Add these partial extents
|
// Add these partial extents
|
||||||
wxArrayInt p;
|
wxArrayInt p;
|
||||||
dc.GetPartialTextExtents(stringChunk, p);
|
dc.GetPartialTextExtents(stringChunk, p);
|
||||||
@@ -4896,13 +4920,34 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
|
|||||||
for (j = 0; j < p.GetCount(); j++)
|
for (j = 0; j < p.GetCount(); j++)
|
||||||
partialExtents->Add(oldWidth + p[j]);
|
partialExtents->Add(oldWidth + p[j]);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dc.GetTextExtent(stringChunk, & w, & h, & descent);
|
||||||
|
width += w;
|
||||||
|
haveDescent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (partialExtents)
|
||||||
|
{
|
||||||
|
int charHeight = dc.GetCharHeight();
|
||||||
|
if ((*partialExtents).GetCount() > 0)
|
||||||
|
w = (*partialExtents)[partialExtents->GetCount()-1];
|
||||||
|
else
|
||||||
|
w = 0;
|
||||||
|
size = wxSize(w, charHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = wxSize(width, dc.GetCharHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!haveDescent)
|
||||||
|
dc.GetTextExtent(wxT("X"), & w, & h, & descent);
|
||||||
|
|
||||||
if ( bScript )
|
if ( bScript )
|
||||||
dc.SetFont(font);
|
dc.SetFont(font);
|
||||||
|
|
||||||
size = wxSize(width, dc.GetCharHeight());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6655,7 +6700,6 @@ void wxRichTextAction::UpdateAppearance(long caretPosition, bool sendUpdateEvent
|
|||||||
if (!m_ctrl->IsFrozen())
|
if (!m_ctrl->IsFrozen())
|
||||||
{
|
{
|
||||||
m_ctrl->LayoutContent();
|
m_ctrl->LayoutContent();
|
||||||
m_ctrl->PositionCaret();
|
|
||||||
|
|
||||||
#if wxRICHTEXT_USE_OPTIMIZED_DRAWING
|
#if wxRICHTEXT_USE_OPTIMIZED_DRAWING
|
||||||
// Find refresh rectangle if we are in a position to optimise refresh
|
// Find refresh rectangle if we are in a position to optimise refresh
|
||||||
|
@@ -1140,7 +1140,9 @@ bool wxRichTextCtrl::ScrollIntoView(long position, int keyCode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PositionCaret();
|
|
||||||
|
if (scrolled)
|
||||||
|
PositionCaret();
|
||||||
|
|
||||||
return scrolled;
|
return scrolled;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user