diff --git starmath/inc/node.hxx starmath/inc/node.hxx index dabb503..ab64749 100644 --- starmath/inc/node.hxx +++ starmath/inc/node.hxx @@ -31,6 +31,7 @@ #include +#include #include "parse.hxx" #include "types.hxx" @@ -97,6 +98,9 @@ class SmNode : public SmRect nAttributes; BOOL bIsPhantom, bIsDebug; + + /** parent of this node or NULL if root */ + SmNode * aParentNode; protected: SmNode(SmNodeType eNodeType, const SmToken &rNodeToken); @@ -180,6 +184,28 @@ public: const SmNode * FindTokenAt(USHORT nRow, USHORT nCol) const; const SmNode * FindRectClosestTo(const Point &rPoint) const; + + /** Get the parent SmNode of this node or NULL if this is the root node */ + SmNode * GetParent() { + DBG_ASSERT(aParentNode || GetType() == SmTableNode, "parent must be set or this should have type NROOT"); + return aParentNode; + } + /** Set the parent of this node, should be set if this is not the root */ + void SetParent(SmNode* parent) { aParentNode = parent; } + + /** The tree as dot graph for graphviz, usable for debugging + Convert the output to a image using $ dot graph.gv -Tpng > graph.png + */ + void DumpAsDot(std::ostream &out, String* label = NULL, int number = -1) const; +protected: + /** Assign this node as parent to its subnodes */ + void ClaimPaternity(){ + SmNode *pNode; + USHORT nSize = GetNumSubNodes(); + for (USHORT i = 0; i < nSize; i++) + if (NULL != (pNode = GetSubNode(i))) + pNode->SetParent(this); + } }; diff --git starmath/inc/rect.hxx starmath/inc/rect.hxx index 35bd51b..64965c9 100644 --- starmath/inc/rect.hxx +++ starmath/inc/rect.hxx @@ -38,6 +38,8 @@ #include "format.hxx" +//Enable fancy rectangles... +//#define SM_RECT_DEBUG BOOL SmGetGlyphBoundRect(const OutputDevice &rDev, const XubString &rText, Rectangle &rRect); diff --git starmath/source/node.cxx starmath/source/node.cxx index b243ced..d42e1f3 100644 --- starmath/source/node.cxx +++ starmath/source/node.cxx @@ -51,9 +51,10 @@ #include #include +#include // define this to draw rectangles for debugging -//#define SM_RECT_DEBUG +//#define SM_RECT_DEBUG (Activate this in rect.hxx //////////////////////////////////////// // SmTmpDevice @@ -144,6 +145,15 @@ SmNode::SmNode(SmNodeType eNodeType, const SmToken &rNodeToken) eScaleMode = SCALE_NONE; aNodeToken = rNodeToken; nAccIndex = -1; + /* This is only valid if eType == NROOT, but will be set later. + Ideally this should be done using constructors in the parser, + however this would require large rewrite and who knows what + effect this would have on import/export stuff... So modifying + SmStructureNode where nodes can aquire subnodes is probably easier. + I even doubt doing this in the parser using the constructor would + be easy... + */ + aParentNode = NULL; } @@ -570,6 +580,97 @@ const SmNode * SmNode::FindNodeWithAccessibleIndex(xub_StrLen nAccIdx) const return pResult; } +void SmNode::DumpAsDot(std::ostream &out, String* label, int number) const +{ + //If this is the root start the file + if(number == -1){ + out<<"digraph {"< n"< n"<GetText(), RTL_TEXTENCODING_UTF8).GetBuffer(); + break; + case NSPECIAL: out<<"SmSpecialNode"; break; + case NGLYPH_SPECIAL: out<<"SmGlyphSpecialNode"; break; + case NMATH: + out<<"SmMathSymbolNode: "; + out<< ByteString( ((SmMathSymbolNode*)this)->GetText(), RTL_TEXTENCODING_UTF8).GetBuffer(); + break; + case NBLANK: out<<"SmBlankNode"; break; + case NERROR: out<<"SmErrorNode"; break; + case NLINE: out<<"SmLineNode"; break; + case NEXPRESSION: out<<"SmExpressionNode"; break; + case NPOLYLINE: out<<"SmPolyLineNode"; break; + case NROOT: out<<"SmRootNode"; break; + case NROOTSYMBOL: out<<"SmRootSymbolNode"; break; + case NRECTANGLE: out<<"SmRectangleNode"; break; + case NVERTICAL_BRACE: out<<"SmVerticalBraceNode"; break; + default: + out<<"Unknown Node"; + } + out<<"\"];"<DumpAsDot(out, NULL, i); + + //If this is the root end the file + if( number == -1 ) + out<<"}"<GrabFocus(); + //pEdit->GrabFocus(); //Disabled with patch for visual editing... } } + //Let this controller grab focus... So now we get keyinput + GrabFocus(); } void SmGraphicWindow::GetFocus() @@ -340,11 +342,29 @@ void SmGraphicWindow::SetTotalSize () ScrollableWindow::SetTotalSize( aTmp ); } +#include void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt) { - if (! (GetView() && GetView()->KeyInput(rKEvt)) ) - ScrollableWindow::KeyInput(rKEvt); + if (! (GetView() && GetView()->KeyInput(rKEvt)) ){ + //Handle right key, for more keycode see: http://docs.go-oo.org/vcl/html/keycodes_8hxx.html + if ( (rKEvt.GetKeyCode().GetCode() & KEY_RETURN) != 0 ) { + //Open stream... + std::fstream file("/tmp/smath-dump.gv", std::fstream::out); + + //Dump the tree on enter + const SmNode *pTree = pViewShell->GetDoc()->GetFormulaTree(); + String label(pViewShell->GetDoc()->GetText()); + pTree->DumpAsDot(file, &label); + file.flush(); + file.close(); + + //Just playing with cursor position... doubt col and row will do for representation + SetCursorPos(2,1); + this->Update(); + } else + ScrollableWindow::KeyInput(rKEvt); + } }