Kaydet (Commit) 79e247d6 authored tarafından Takeshi Abe's avatar Takeshi Abe

starmath: Prefix members of SmSetSelectionVisitor

Change-Id: I3a5d195d65fe3a9b7b7859e3ad4c1d051628f44d
Reviewed-on: https://gerrit.libreoffice.org/25491Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTakeshi Abe <tabe@fixedpoint.jp>
üst e10a4c1c
...@@ -255,15 +255,15 @@ private: ...@@ -255,15 +255,15 @@ private:
void DefaultVisit( SmNode* pNode ) override; void DefaultVisit( SmNode* pNode ) override;
void VisitCompositionNode( SmNode* pNode ); void VisitCompositionNode( SmNode* pNode );
/** Caret position where the selection starts */ /** Caret position where the selection starts */
SmCaretPos StartPos; SmCaretPos maStartPos;
/** Caret position where the selection ends */ /** Caret position where the selection ends */
SmCaretPos EndPos; SmCaretPos maEndPos;
/** The current state of this visitor /** The current state of this visitor
* This property changes when the visitor meets either StartPos * This property changes when the visitor meets either maStartPos
* or EndPos. This means that anything visited in between will be * or maEndPos. This means that anything visited in between will be
* selected. * selected.
*/ */
bool IsSelecting; bool mbSelecting;
}; };
......
...@@ -551,34 +551,34 @@ void SmDrawingVisitor::DrawChildren( SmNode* pNode ) ...@@ -551,34 +551,34 @@ void SmDrawingVisitor::DrawChildren( SmNode* pNode )
// SmSetSelectionVisitor // SmSetSelectionVisitor
SmSetSelectionVisitor::SmSetSelectionVisitor( SmCaretPos startPos, SmCaretPos endPos, SmNode* pTree) { SmSetSelectionVisitor::SmSetSelectionVisitor( SmCaretPos startPos, SmCaretPos endPos, SmNode* pTree)
StartPos = startPos; : maStartPos(startPos)
EndPos = endPos; , maEndPos(endPos)
IsSelecting = false; , mbSelecting(false)
{
//Assume that pTree is a SmTableNode //Assume that pTree is a SmTableNode
SAL_WARN_IF(pTree->GetType() != NTABLE, "starmath", "pTree should be a SmTableNode!"); SAL_WARN_IF(pTree->GetType() != NTABLE, "starmath", "pTree should be a SmTableNode!");
//Visit root node, this is special as this node cannot be selected, but its children can! //Visit root node, this is special as this node cannot be selected, but its children can!
if(pTree->GetType() == NTABLE){ if(pTree->GetType() == NTABLE){
//Change state if StartPos is in front of this node //Change state if maStartPos is in front of this node
if( StartPos.pSelectedNode == pTree && StartPos.Index == 0 ) if( maStartPos.pSelectedNode == pTree && maStartPos.Index == 0 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
//Change state if EndPos is in front of this node //Change state if maEndPos is in front of this node
if( EndPos.pSelectedNode == pTree && EndPos.Index == 0 ) if( maEndPos.pSelectedNode == pTree && maEndPos.Index == 0 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
SAL_WARN_IF(IsSelecting, "starmath", "Caret positions needed to set IsSelecting about, shouldn't be possible!"); SAL_WARN_IF(mbSelecting, "starmath", "Caret positions needed to set mbSelecting about, shouldn't be possible!");
//Visit lines //Visit lines
SmNodeIterator it( pTree ); SmNodeIterator it( pTree );
while( it.Next( ) ) { while( it.Next( ) ) {
it->Accept( this ); it->Accept( this );
//If we started a selection in this line and it haven't ended, we do that now! //If we started a selection in this line and it haven't ended, we do that now!
if(IsSelecting) { if(mbSelecting) {
IsSelecting = false; mbSelecting = false;
SetSelectedOnAll(it.Current()); SetSelectedOnAll(it.Current());
//Set StartPos and EndPos to invalid positions, this ensures that an unused //Set maStartPos and maEndPos to invalid positions, this ensures that an unused
//start or end (because we forced end above), doesn't start a new selection. //start or end (because we forced end above), doesn't start a new selection.
StartPos = EndPos = SmCaretPos(); maStartPos = maEndPos = SmCaretPos();
} }
} }
//Check if pTree isn't selected //Check if pTree isn't selected
...@@ -600,26 +600,26 @@ void SmSetSelectionVisitor::SetSelectedOnAll( SmNode* pSubTree, bool IsSelected ...@@ -600,26 +600,26 @@ void SmSetSelectionVisitor::SetSelectedOnAll( SmNode* pSubTree, bool IsSelected
} }
void SmSetSelectionVisitor::DefaultVisit( SmNode* pNode ) { void SmSetSelectionVisitor::DefaultVisit( SmNode* pNode ) {
//Change state if StartPos is in front of this node //Change state if maStartPos is in front of this node
if( StartPos.pSelectedNode == pNode && StartPos.Index == 0 ) if( maStartPos.pSelectedNode == pNode && maStartPos.Index == 0 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
//Change state if EndPos is in front of this node //Change state if maEndPos is in front of this node
if( EndPos.pSelectedNode == pNode && EndPos.Index == 0 ) if( maEndPos.pSelectedNode == pNode && maEndPos.Index == 0 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
//Cache current state //Cache current state
bool WasSelecting = IsSelecting; bool WasSelecting = mbSelecting;
bool ChangedState = false; bool ChangedState = false;
//Set selected //Set selected
pNode->SetSelected( IsSelecting ); pNode->SetSelected( mbSelecting );
//Visit children //Visit children
SmNodeIterator it( pNode ); SmNodeIterator it( pNode );
while( it.Next( ) ) while( it.Next( ) )
{ {
it->Accept( this ); it->Accept( this );
ChangedState = ( WasSelecting != IsSelecting ) || ChangedState; ChangedState = ( WasSelecting != mbSelecting ) || ChangedState;
} }
//If state changed //If state changed
...@@ -635,35 +635,35 @@ void SmSetSelectionVisitor::DefaultVisit( SmNode* pNode ) { ...@@ -635,35 +635,35 @@ void SmSetSelectionVisitor::DefaultVisit( SmNode* pNode ) {
SetSelectedOnAll( pNode->GetParent() ); SetSelectedOnAll( pNode->GetParent() );
/* If the equation is: sqrt{2 + 4} + 5 /* If the equation is: sqrt{2 + 4} + 5
* And the selection is: sqrt{2 + [4} +] 5 * And the selection is: sqrt{2 + [4} +] 5
* Where [ denotes StartPos and ] denotes EndPos * Where [ denotes maStartPos and ] denotes maEndPos
* Then the sqrt node should be selected, so that the * Then the sqrt node should be selected, so that the
* effective selection is: [sqrt{2 + 4} +] 5 * effective selection is: [sqrt{2 + 4} +] 5
* The same is the case if we swap StartPos and EndPos. * The same is the case if we swap maStartPos and maEndPos.
*/ */
} }
//Change state if StartPos is after this node //Change state if maStartPos is after this node
if( StartPos.pSelectedNode == pNode && StartPos.Index == 1 ) if( maStartPos.pSelectedNode == pNode && maStartPos.Index == 1 )
{ {
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
} }
//Change state if EndPos is after of this node //Change state if maEndPos is after of this node
if( EndPos.pSelectedNode == pNode && EndPos.Index == 1 ) if( maEndPos.pSelectedNode == pNode && maEndPos.Index == 1 )
{ {
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
} }
} }
void SmSetSelectionVisitor::VisitCompositionNode( SmNode* pNode ) { void SmSetSelectionVisitor::VisitCompositionNode( SmNode* pNode ) {
//Change state if StartPos is in front of this node //Change state if maStartPos is in front of this node
if( StartPos.pSelectedNode == pNode && StartPos.Index == 0 ) if( maStartPos.pSelectedNode == pNode && maStartPos.Index == 0 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
//Change state if EndPos is in front of this node //Change state if maEndPos is in front of this node
if( EndPos.pSelectedNode == pNode && EndPos.Index == 0 ) if( maEndPos.pSelectedNode == pNode && maEndPos.Index == 0 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
//Cache current state //Cache current state
bool WasSelecting = IsSelecting; bool WasSelecting = mbSelecting;
//Visit children //Visit children
SmNodeIterator it( pNode ); SmNodeIterator it( pNode );
...@@ -671,46 +671,46 @@ void SmSetSelectionVisitor::VisitCompositionNode( SmNode* pNode ) { ...@@ -671,46 +671,46 @@ void SmSetSelectionVisitor::VisitCompositionNode( SmNode* pNode ) {
it->Accept( this ); it->Accept( this );
//Set selected, if everything was selected //Set selected, if everything was selected
pNode->SetSelected( WasSelecting && IsSelecting ); pNode->SetSelected( WasSelecting && mbSelecting );
//Change state if StartPos is after this node //Change state if maStartPos is after this node
if( StartPos.pSelectedNode == pNode && StartPos.Index == 1 ) if( maStartPos.pSelectedNode == pNode && maStartPos.Index == 1 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
//Change state if EndPos is after of this node //Change state if maEndPos is after of this node
if( EndPos.pSelectedNode == pNode && EndPos.Index == 1 ) if( maEndPos.pSelectedNode == pNode && maEndPos.Index == 1 )
IsSelecting = !IsSelecting; mbSelecting = !mbSelecting;
} }
void SmSetSelectionVisitor::Visit( SmTextNode* pNode ) { void SmSetSelectionVisitor::Visit( SmTextNode* pNode ) {
long i1 = -1, long i1 = -1,
i2 = -1; i2 = -1;
if( StartPos.pSelectedNode == pNode ) if( maStartPos.pSelectedNode == pNode )
i1 = StartPos.Index; i1 = maStartPos.Index;
if( EndPos.pSelectedNode == pNode ) if( maEndPos.pSelectedNode == pNode )
i2 = EndPos.Index; i2 = maEndPos.Index;
long start, end; long start, end;
pNode->SetSelected(); pNode->SetSelected();
if( i1 != -1 && i2 != -1 ) { if( i1 != -1 && i2 != -1 ) {
start = i1 < i2 ? i1 : i2; //MIN start = i1 < i2 ? i1 : i2; //MIN
end = i1 > i2 ? i1 : i2; //MAX end = i1 > i2 ? i1 : i2; //MAX
} else if( IsSelecting && i1 != -1 ) { } else if( mbSelecting && i1 != -1 ) {
start = 0; start = 0;
end = i1; end = i1;
IsSelecting = false; mbSelecting = false;
} else if( IsSelecting && i2 != -1 ) { } else if( mbSelecting && i2 != -1 ) {
start = 0; start = 0;
end = i2; end = i2;
IsSelecting = false; mbSelecting = false;
} else if( !IsSelecting && i1 != -1 ) { } else if( !mbSelecting && i1 != -1 ) {
start = i1; start = i1;
end = pNode->GetText().getLength(); end = pNode->GetText().getLength();
IsSelecting = true; mbSelecting = true;
} else if( !IsSelecting && i2 != -1 ) { } else if( !mbSelecting && i2 != -1 ) {
start = i2; start = i2;
end = pNode->GetText().getLength(); end = pNode->GetText().getLength();
IsSelecting = true; mbSelecting = true;
} else if( IsSelecting ) { } else if( mbSelecting ) {
start = 0; start = 0;
end = pNode->GetText().getLength(); end = pNode->GetText().getLength();
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment