Further wxRichTextCtrl performance improvements
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53382 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -364,14 +364,10 @@ void wxRichTextCtrl::OnLeftClick(wxMouseEvent& event)
|
||||
|
||||
if (event.ShiftDown())
|
||||
{
|
||||
bool extendSel = false;
|
||||
if (m_selectionRange.GetStart() == -2)
|
||||
extendSel = ExtendSelection(oldCaretPos, m_caretPosition, wxRICHTEXT_SHIFT_DOWN);
|
||||
ExtendSelection(oldCaretPos, m_caretPosition, wxRICHTEXT_SHIFT_DOWN);
|
||||
else
|
||||
extendSel = ExtendSelection(m_caretPosition, m_caretPosition, wxRICHTEXT_SHIFT_DOWN);
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
ExtendSelection(m_caretPosition, m_caretPosition, wxRICHTEXT_SHIFT_DOWN);
|
||||
}
|
||||
else
|
||||
SelectNone();
|
||||
@@ -500,13 +496,10 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
|
||||
|
||||
if (m_caretPosition != position)
|
||||
{
|
||||
bool extendSel = ExtendSelection(m_caretPosition, position, wxRICHTEXT_SHIFT_DOWN);
|
||||
ExtendSelection(m_caretPosition, position, wxRICHTEXT_SHIFT_DOWN);
|
||||
|
||||
MoveCaret(position, caretAtLineStart);
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1006,6 +999,8 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
|
||||
{
|
||||
if (flags & wxRICHTEXT_SHIFT_DOWN)
|
||||
{
|
||||
wxRichTextRange oldSelection = m_selectionRange;
|
||||
|
||||
// If not currently selecting, start selecting
|
||||
if (m_selectionRange.GetStart() == -2)
|
||||
{
|
||||
@@ -1026,6 +1021,8 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
|
||||
m_selectionRange.SetRange(newPos+1, m_selectionAnchor);
|
||||
}
|
||||
|
||||
RefreshForSelectionChange(oldSelection, m_selectionRange);
|
||||
|
||||
if (m_selectionRange.GetStart() > m_selectionRange.GetEnd())
|
||||
{
|
||||
wxLogDebug(wxT("Strange selection range"));
|
||||
@@ -1297,8 +1294,6 @@ bool wxRichTextCtrl::MoveRight(int noPositions, int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -1326,8 +1321,6 @@ bool wxRichTextCtrl::MoveLeft(int noPositions, int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -1417,8 +1410,6 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1440,8 +1431,6 @@ bool wxRichTextCtrl::MoveToParagraphEnd(int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1463,8 +1452,6 @@ bool wxRichTextCtrl::MoveToParagraphStart(int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1488,8 +1475,6 @@ bool wxRichTextCtrl::MoveToLineEnd(int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1515,8 +1500,6 @@ bool wxRichTextCtrl::MoveToLineStart(int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1536,8 +1519,6 @@ bool wxRichTextCtrl::MoveHome(int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -1559,8 +1540,6 @@ bool wxRichTextCtrl::MoveEnd(int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -1600,8 +1579,6 @@ bool wxRichTextCtrl::PageDown(int noPages, int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1719,8 +1696,6 @@ bool wxRichTextCtrl::WordLeft(int WXUNUSED(n), int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1743,8 +1718,6 @@ bool wxRichTextCtrl::WordRight(int WXUNUSED(n), int flags)
|
||||
PositionCaret();
|
||||
SetDefaultStyleToCursorStyle();
|
||||
|
||||
if (extendSel)
|
||||
Refresh(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1831,14 +1804,31 @@ void wxRichTextCtrl::SetupScrollbars(bool atTop)
|
||||
if (!atTop)
|
||||
GetViewStart(& startX, & startY);
|
||||
|
||||
int maxPositionX = 0; // wxMax(sz.x - clientSize.x, 0);
|
||||
int maxPositionX = 0;
|
||||
int maxPositionY = (int) ((((float)(wxMax((unitsY*pixelsPerUnit) - clientSize.y, 0)))/((float)pixelsPerUnit)) + 0.5);
|
||||
|
||||
int newStartX = wxMin(maxPositionX, startX);
|
||||
int newStartY = wxMin(maxPositionY, startY);
|
||||
|
||||
int oldPPUX, oldPPUY;
|
||||
int oldStartX, oldStartY;
|
||||
int oldVirtualSizeX = 0, oldVirtualSizeY = 0;
|
||||
GetScrollPixelsPerUnit(& oldPPUX, & oldPPUY);
|
||||
GetViewStart(& oldStartX, & oldStartY);
|
||||
GetVirtualSize(& oldVirtualSizeX, & oldVirtualSizeY);
|
||||
if (oldPPUY > 0)
|
||||
oldVirtualSizeY /= oldPPUY;
|
||||
|
||||
if (oldPPUX == 0 && oldPPUY == pixelsPerUnit && oldVirtualSizeY == unitsY && oldStartX == newStartX && oldStartY == newStartY)
|
||||
return;
|
||||
|
||||
// Don't set scrollbars if there were none before, and there will be none now.
|
||||
if (oldPPUY != 0 && (oldVirtualSizeY < clientSize.y) && (unitsY*pixelsPerUnit < clientSize.y))
|
||||
return;
|
||||
|
||||
// Move to previous scroll position if
|
||||
// possible
|
||||
SetScrollbars(0, pixelsPerUnit,
|
||||
0, unitsY,
|
||||
wxMin(maxPositionX, startX), wxMin(maxPositionY, startY));
|
||||
SetScrollbars(0, pixelsPerUnit, 0, unitsY, newStartX, newStartY);
|
||||
}
|
||||
|
||||
/// Paint the background
|
||||
@@ -1957,8 +1947,11 @@ void wxRichTextCtrl::SelectNone()
|
||||
{
|
||||
if (!(GetSelectionRange() == wxRichTextRange(-2, -2)))
|
||||
{
|
||||
Refresh(false);
|
||||
wxRichTextRange oldSelection = m_selectionRange;
|
||||
|
||||
m_selectionRange = wxRichTextRange(-2, -2);
|
||||
|
||||
RefreshForSelectionChange(oldSelection, m_selectionRange);
|
||||
}
|
||||
m_selectionAnchor = -2;
|
||||
}
|
||||
@@ -2357,12 +2350,13 @@ void wxRichTextCtrl::DoSetSelection(long from, long to, bool WXUNUSED(scrollCare
|
||||
}
|
||||
else
|
||||
{
|
||||
wxRichTextRange oldSelection = m_selectionRange;
|
||||
m_selectionAnchor = from;
|
||||
m_selectionRange.SetRange(from, to-1);
|
||||
if (from > -2)
|
||||
m_caretPosition = from-1;
|
||||
|
||||
Refresh(false);
|
||||
RefreshForSelectionChange(oldSelection, m_selectionRange);
|
||||
PositionCaret();
|
||||
}
|
||||
}
|
||||
@@ -3195,5 +3189,53 @@ void wxRichTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
// Refresh the area affected by a selection change
|
||||
bool wxRichTextCtrl::RefreshForSelectionChange(const wxRichTextRange& oldSelection, const wxRichTextRange& newSelection)
|
||||
{
|
||||
// Calculate the refresh rectangle - just the affected lines
|
||||
long firstPos, lastPos;
|
||||
if (oldSelection.GetStart() == -2 && newSelection.GetStart() != -2)
|
||||
{
|
||||
firstPos = newSelection.GetStart();
|
||||
lastPos = newSelection.GetEnd();
|
||||
}
|
||||
else if (oldSelection.GetStart() != -2 && newSelection.GetStart() == -2)
|
||||
{
|
||||
firstPos = oldSelection.GetStart();
|
||||
lastPos = oldSelection.GetEnd();
|
||||
}
|
||||
else if (oldSelection.GetStart() == -2 && newSelection.GetStart() == -2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstPos = wxMin(oldSelection.GetStart(), newSelection.GetStart());
|
||||
lastPos = wxMax(oldSelection.GetEnd(), newSelection.GetEnd());
|
||||
}
|
||||
|
||||
wxRichTextLine* firstLine = GetBuffer().GetLineAtPosition(firstPos);
|
||||
wxRichTextLine* lastLine = GetBuffer().GetLineAtPosition(lastPos);
|
||||
|
||||
if (firstLine && lastLine)
|
||||
{
|
||||
wxSize clientSize = GetClientSize();
|
||||
wxPoint pt1 = GetPhysicalPoint(firstLine->GetAbsolutePosition());
|
||||
wxPoint pt2 = GetPhysicalPoint(lastLine->GetAbsolutePosition()) + wxPoint(0, lastLine->GetSize().y);
|
||||
|
||||
pt1.x = 0;
|
||||
pt1.y = wxMax(0, pt1.y);
|
||||
pt2.x = 0;
|
||||
pt2.y = wxMin(clientSize.y, pt2.y);
|
||||
|
||||
wxRect rect(pt1, wxSize(clientSize.x, pt2.y - pt1.y));
|
||||
RefreshRect(rect, false);
|
||||
}
|
||||
else
|
||||
Refresh(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
// wxUSE_RICHTEXT
|
||||
|
Reference in New Issue
Block a user