summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorJonas Finnemann Jensen <jopsen@gmail.com>2010-10-03 16:16:52 +0200
committerJonas Finnemann Jensen <jopsen@gmail.com>2010-10-03 16:16:52 +0200
commit2d415c9854fb6111ac924ee95044c7e1a931433c (patch)
tree624a7ca19d7a8e1ba0d1d2dc4c345f6ae06f4f94 /starmath
parent11ddbed837eab61d2ff1dcbbf4c978c037a58ac9 (diff)
Fixed issue with moving in/out of binom and stack.
Rewrote handling of SmTableNode in SmCaretPosGraphBuildingVisitor, so that the special case where NTABLE is used as root node is handled in the constructor, and NSTACK and NBINOM is handled in the visiting method.
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/visitors.hxx43
-rw-r--r--starmath/source/cursor.cxx4
-rw-r--r--starmath/source/visitors.cxx77
3 files changed, 75 insertions, 49 deletions
diff --git a/starmath/inc/visitors.hxx b/starmath/inc/visitors.hxx
index e2be49dedf..aeed3f6ca8 100644
--- a/starmath/inc/visitors.hxx
+++ b/starmath/inc/visitors.hxx
@@ -276,31 +276,30 @@ private:
/////////////////////////////// SmCaretPosGraphBuildingVisitor ////////////////////////////////
-/** A visitor for building a SmCaretPosGraph */
+/** A visitor for building a SmCaretPosGraph
+ *
+ * Visit invariant:
+ * Each pNode, except SmExpressionNode, SmBinHorNode and a few others, constitues an entry
+ * in a line. Consider the line entry "H", this entry creates one carat position, here
+ * denoted by | in "H|".
+ *
+ * Parameter variables:
+ * The following variables are used to transfer parameters in to calls and results out
+ * of calls.
+ * pRightMost : SmCaretPosGraphEntry*
+ *
+ * Prior to a Visit call:
+ * pRightMost: A pointer to right most position infront of the current line entry.
+ *
+ * After a Visit call:
+ * pRightMost: A pointer to the right most position in the called line entry, if no there's
+ * no caret positions in called line entry don't change this variable.
+ */
class SmCaretPosGraphBuildingVisitor : public SmVisitor
{
public:
- SmCaretPosGraphBuildingVisitor( ){
- pRightMost = NULL;
- pGraph = new SmCaretPosGraph( );
- }
- /* Visit invariant:
- * Each pNode, except SmExpressionNode, SmBinHorNode and a few others, constitues an entry
- * in a line. Consider the line entry "H", this entry creates one carat position, here
- * denoted by | in "H|".
- *
- * Parameter variables:
- * The following variables are used to transfer parameters in to calls and results out
- * of calls.
- * pRightMost : SmCaretPosGraphEntry*
- *
- * Prior to a Visit call:
- * pRightMost: A pointer to right most position infront of the current line entry.
- *
- * After a Visit call:
- * pRightMost: A pointer to the right most position in the called line entry, if no there's
- * no caret positions in called line entry don't change this variable.
- */
+ /** Builds a caret position graph for pRootNode */
+ SmCaretPosGraphBuildingVisitor( SmNode* pRootNode );
void Visit( SmTableNode* pNode );
void Visit( SmBraceNode* pNode );
void Visit( SmBracebodyNode* pNode );
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index 9637889781..3b5022c9d1 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -113,9 +113,7 @@ void SmCursor::BuildGraph(){
pGraph = NULL;
//Build the new graph
- SmCaretPosGraphBuildingVisitor builder;
- pTree->Accept(&builder);
- pGraph = builder.Graph();
+ pGraph = SmCaretPosGraphBuildingVisitor(pTree).Graph();
//Restore anchor and position pointers
if(_anchor.IsValid() || _position.IsValid()){
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index f39825fb36..f7418c08d9 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -949,36 +949,65 @@ void SmSetSelectionVisitor::Visit( SmFontNode* pNode )
/////////////////////////////// SmCaretPosGraphBuildingVisitor ////////////////////////////////
+SmCaretPosGraphBuildingVisitor::SmCaretPosGraphBuildingVisitor( SmNode* pRootNode ){
+ pRightMost = NULL;
+ pGraph = new SmCaretPosGraph( );
+ //pRootNode should always be a table
+ j_assert( pRootNode->GetType( ) == NTABLE, "pRootNode must be a table node");
+ //Handle the special case where NTABLE is used a rootnode
+ if( pRootNode->GetType( ) == NTABLE ){
+ //Children are SmLineNodes
+ //Or so I thought... Aparently, the children can be instances of SmExpression
+ //especially if there's a error in the formula... So he we go, a simple work around.
+ SmNodeIterator it( pRootNode );
+ while( it.Next( ) ){
+ //There's a special invariant between this method and the Visit( SmLineNode* )
+ //Usually pRightMost may not be NULL, to avoid this pRightMost should here be
+ //set to a new SmCaretPos infront of it.Current( ), however, if it.Current( ) is
+ //an instance of SmLineNode we let SmLineNode create this position infront of
+ //the visual line.
+ //The argument for doing this is that we now don't have to worry about SmLineNode
+ //being a visual line composition node. Thus, no need for yet another special case
+ //in SmCursor::IsLineCompositionNode and everywhere this method is used.
+ if( it->GetType( ) != NLINE )
+ pRightMost = pGraph->Add( SmCaretPos( it.Current( ), 0 ) );
+ it->Accept( this );
+ }
+ }else
+ pRootNode->Accept(this);
+}
-//Needs special care:
-void SmCaretPosGraphBuildingVisitor::Visit( SmTableNode* pNode )
-{
- //Children are SmLineNodes
- //Or so I thought... Aparently, the children can be instances of SmExpression
- //especially if there's a error in the formula... So he we go, a simple work around.
+void SmCaretPosGraphBuildingVisitor::Visit( SmLineNode* pNode ){
+ pRightMost = NULL;
SmNodeIterator it( pNode );
while( it.Next( ) ){
- //There's a special invariant between this method and the Visit( SmLineNode* )
- //Usually pRightMost may not be NULL, to avoid this pRightMost should here be
- //set to a new SmCaretPos infront of it.Current( ), however, if it.Current( ) is
- //an instance of SmLineNode we let SmLineNode create this position infront of
- //the visual line.
- //The argument for doing this is that we now don't have to worry about SmLineNode
- //being a visual line composition node. Thus no need for yet another special case
- //in SmCursor::IsLineCompositionNode and everywhere this method is used.
- if( it->GetType( ) != NLINE )
+ if( !pRightMost )
pRightMost = pGraph->Add( SmCaretPos( it.Current( ), 0 ) );
it->Accept( this );
}
}
-void SmCaretPosGraphBuildingVisitor::Visit( SmLineNode* pNode ){
- pRightMost = NULL;
+
+/** Build SmCaretPosGraph for SmTableNode
+ * This method covers cases where SmTableNode is used in a binom or stack,
+ * the special case where it is used as root node for the entire formula is
+ * handled in the constructor.
+ */
+void SmCaretPosGraphBuildingVisitor::Visit( SmTableNode* pNode ){
+ SmCaretPosGraphEntry *left = pRightMost,
+ *right = pGraph->Add( SmCaretPos( pNode, 1) );
+ BOOL bIsFirst = TRUE;
SmNodeIterator it( pNode );
- while( it.Next( ) ){
- if( !pRightMost )
- pRightMost = pGraph->Add( SmCaretPos( it.Current( ), 0 ) );
+ while( it.Next() ){
+ pRightMost = pGraph->Add( SmCaretPos( it.Current(), 0 ), left);
+ if(bIsFirst)
+ left->SetRight(pRightMost);
it->Accept( this );
+ pRightMost->SetRight(right);
+ if(bIsFirst)
+ right->SetLeft(pRightMost);
+ bIsFirst = FALSE;
}
+ pRightMost = right;
}
/** Build SmCaretPosGraph for SmSubSupNode
@@ -1305,10 +1334,10 @@ void SmCaretPosGraphBuildingVisitor::Visit( SmBinVerNode* pNode )
SmNode *pNum = pNode->GetSubNode( 0 ),
*pDenom = pNode->GetSubNode( 2 );
- SmCaretPosGraphEntry *left,
- *right,
- *numLeft,
- *denomLeft;
+ SmCaretPosGraphEntry *left,
+ *right,
+ *numLeft,
+ *denomLeft;
//Set left
left = pRightMost;