summaryrefslogtreecommitdiff
path: root/starmath/source/cursor.cxx
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2016-05-31 15:01:49 +0900
committerMichael Stahl <mstahl@redhat.com>2016-05-31 16:15:30 +0000
commit09981cd6383ecb99e4b6c83b98b03af5cf3ff59b (patch)
treed06db24d172ea9f7e5b8c052618e268d3014cfe9 /starmath/source/cursor.cxx
parenta61063ca2cce4753a061693a50cccab95865ad6b (diff)
Use std::vector for SmCaretPosGraph
instead of employing ad hoc linked list and its iterator. Change-Id: Ibc4709a2e67aa805cf54117303c47d9a8a5eede9 Reviewed-on: https://gerrit.libreoffice.org/25699 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'starmath/source/cursor.cxx')
-rw-r--r--starmath/source/cursor.cxx47
1 files changed, 24 insertions, 23 deletions
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index de4439c1e84d..617e100670d6 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -36,12 +36,12 @@ void SmCursor::Move(OutputDevice* pDev, SmMovementDirection direction, bool bMov
best_line, //Best approximated line found so far
curr_line; //Current line
long dbp_sq = 0; //Distance squared to best line
- SmCaretPosGraphIterator it = mpGraph->GetIterator();
- while(it.Next()){
+ for(auto &pEntry : *mpGraph)
+ {
//Reject it if it's the current position
- if(it->CaretPos == mpPosition->CaretPos) continue;
+ if(pEntry->CaretPos == mpPosition->CaretPos) continue;
//Compute caret line
- curr_line = SmCaretPos2LineVisitor(pDev, it->CaretPos).GetResult();
+ curr_line = SmCaretPos2LineVisitor(pDev, pEntry->CaretPos).GetResult();
//Reject anything above if we're moving down
if(curr_line.GetTop() <= from_line.GetTop() && direction == MoveDown) continue;
//Reject anything below if we're moving up
@@ -57,7 +57,7 @@ void SmCursor::Move(OutputDevice* pDev, SmMovementDirection direction, bool bMov
}
//Take current line as the best
best_line = curr_line;
- NewPos = it.Current();
+ NewPos = pEntry.get();
//Update distance to best line
dbp_sq = best_line.SquaredDistanceX(from_line) * HORIZONTICAL_DISTANCE_FACTOR +
best_line.SquaredDistanceY(from_line);
@@ -80,11 +80,11 @@ void SmCursor::MoveTo(OutputDevice* pDev, Point pos, bool bMoveAnchor){
SmCaretPosGraphEntry* NewPos = nullptr;
long dp_sq = 0, //Distance to current line squared
dbp_sq = 1; //Distance to best line squared
- SmCaretPosGraphIterator it = mpGraph->GetIterator();
- while(it.Next()){
- OSL_ENSURE(it->CaretPos.IsValid(), "The caret position graph may not have invalid positions!");
+ for(auto &pEntry : *mpGraph)
+ {
+ OSL_ENSURE(pEntry->CaretPos.IsValid(), "The caret position graph may not have invalid positions!");
//Compute current line
- curr_line = SmCaretPos2LineVisitor(pDev, it->CaretPos).GetResult();
+ curr_line = SmCaretPos2LineVisitor(pDev, pEntry->CaretPos).GetResult();
//If we have a position compare to it
if(NewPos){
//Compute squared distance to current line
@@ -94,7 +94,7 @@ void SmCursor::MoveTo(OutputDevice* pDev, Point pos, bool bMoveAnchor){
}
//Accept current position as the best
best_line = curr_line;
- NewPos = it.Current();
+ NewPos = pEntry.get();
//Update distance to best line
dbp_sq = best_line.SquaredDistanceX(pos) + best_line.SquaredDistanceY(pos);
}
@@ -126,18 +126,18 @@ void SmCursor::BuildGraph(){
//Restore anchor and position pointers
if(_anchor.IsValid() || _position.IsValid()){
- SmCaretPosGraphIterator it = mpGraph->GetIterator();
- while(it.Next()){
- if(_anchor == it->CaretPos)
- mpAnchor = it.Current();
- if(_position == it->CaretPos)
- mpPosition = it.Current();
+ for(auto &pEntry : *mpGraph)
+ {
+ if(_anchor == pEntry->CaretPos)
+ mpAnchor = pEntry.get();
+ if(_position == pEntry->CaretPos)
+ mpPosition = pEntry.get();
}
}
//Set position and anchor to first caret position
- SmCaretPosGraphIterator it = mpGraph->GetIterator();
+ auto it = mpGraph->begin();
if(!mpPosition)
- mpPosition = it.Next();
+ mpPosition = (it == mpGraph->end()) ? nullptr : it->get();
if(!mpAnchor)
mpAnchor = mpPosition;
@@ -146,11 +146,12 @@ void SmCursor::BuildGraph(){
}
bool SmCursor::SetCaretPosition(SmCaretPos pos){
- SmCaretPosGraphIterator it = mpGraph->GetIterator();
- while(it.Next()){
- if(it->CaretPos == pos){
- mpPosition = it.Current();
- mpAnchor = it.Current();
+ for(auto &pEntry : *mpGraph)
+ {
+ if(pEntry->CaretPos == pos)
+ {
+ mpPosition = pEntry.get();
+ mpAnchor = pEntry.get();
return true;
}
}