lib

oasiscreationstrategy.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqdom.h>
21
22#include "bracketelement.h"
23#include "elementtype.h"
24#include "fractionelement.h"
25#include "indexelement.h"
26#include "matrixelement.h"
27#include "rootelement.h"
28#include "sequenceelement.h"
29#include "spaceelement.h"
30#include "symbolelement.h"
31#include "textelement.h"
32#include "glyphelement.h"
33#include "styleelement.h"
34#include "numberelement.h"
35#include "identifierelement.h"
36#include "operatorelement.h"
37#include "stringelement.h"
38#include "paddedelement.h"
39#include "errorelement.h"
40#include "phantomelement.h"
41#include "actionelement.h"
42#include "encloseelement.h"
43
44#include "oasiscreationstrategy.h"
45
46KFORMULA_NAMESPACE_BEGIN
47
48BasicElement* OasisCreationStrategy::createElement( TQString type, const TQDomElement& element )
49{
50
51 // TODO
52 // mlabeledtr
53 // maligngroup
54 // malignmark
55 // Content elements
56 // mtr and mtd are currently managed inside MatrixElement
57 kdDebug( DEBUGID ) << type << endl;
58
59 // Token Elements ( Section 3.1.6.1 )
60 if ( type == "mi" ) return new IdentifierElement();
61 else if ( type == "mo" ) return createOperatorElement( element );
62 else if ( type == "mn" ) return new NumberElement();
63 else if ( type == "mtext" ) return new TokenElement();
64 else if ( type == "ms" ) return new StringElement();
65 else if ( type == "mspace" ) return new SpaceElement();
66 else if ( type == "mglyph" ) return new GlyphElement();
67
68 // General Layout Schemata ( Section 3.1.6.2 )
69 else if ( type == "mrow" ) return new SequenceElement();
70 else if ( type == "mfrac" ) return new FractionElement();
71 else if ( type == "msqrt"
72 || type == "mroot" ) return new RootElement();
73 else if ( type == "mstyle" ) return new StyleElement();
74 else if ( type == "merror" ) return new ErrorElement();
75 else if ( type == "mpadded" ) return new PaddedElement();
76 else if ( type == "mphantom" ) return new PhantomElement();
77 else if ( type == "mfenced" ) return new BracketElement();
78 else if ( type == "menclose" ) return new EncloseElement();
79
80 // Script and Limit Schemata ( Section 3.1.6.3 )
81 else if ( type == "msub"
82 || type == "msup"
83 || type == "msubsup"
84 || type == "munder"
85 || type == "mover"
86 || type == "munderover"
87 || type == "mmultiscripts" ) return new IndexElement();
88
89 // Tables and Matrices ( Section 3.1.6.4 )
90 else if ( type == "mtable" ) return new MatrixElement();
91
92 // Enlivening Expressions ( Section 3.1.6.5 )
93 else if ( type == "maction" ) return new ActionElement();
94 return 0;
95}
96
97
99{
100 return new TextElement( ch, symbol );
101}
102
103EmptyElement* OasisCreationStrategy::createEmptyElement()
104{
105 return new EmptyElement;
106}
107
108NameSequence* OasisCreationStrategy::createNameSequence()
109{
110 return new NameSequence;
111}
112
113BracketElement* OasisCreationStrategy::createBracketElement( SymbolType lhs, SymbolType rhs )
114{
115 return new BracketElement( lhs, rhs );
116}
117
118OverlineElement* OasisCreationStrategy::createOverlineElement()
119{
120 return new OverlineElement;
121}
122
123UnderlineElement* OasisCreationStrategy::createUnderlineElement()
124{
125 return new UnderlineElement;
126}
127
128MultilineElement* OasisCreationStrategy::createMultilineElement()
129{
130 return new MultilineElement;
131}
132
133SpaceElement* OasisCreationStrategy::createSpaceElement( SpaceWidth width )
134{
135 return new SpaceElement( width );
136}
137
138FractionElement* OasisCreationStrategy::createFractionElement()
139{
140 return new FractionElement;
141}
142
143RootElement* OasisCreationStrategy::createRootElement()
144{
145 return new RootElement;
146}
147
148SymbolElement* OasisCreationStrategy::createSymbolElement( SymbolType type )
149{
150 return new SymbolElement( type );
151}
152
154{
155 return new MatrixElement( rows, columns );
156}
157
158IndexElement* OasisCreationStrategy::createIndexElement()
159{
160 return new IndexElement;
161}
162
163BasicElement* OasisCreationStrategy::createOperatorElement( const TQDomElement& element )
164{
165 TQDomNode n = element.firstChild();
166 if ( n.isNull() )
167 return 0;
168 if ( n.isEntityReference() ) {
169 TQString name = n.nodeName();
170 if ( name == "CloseCurlyDoubleQuote"
171 || name == "CloseCurlyQuote"
172 || name == "LeftAngleBracket"
173 || name == "LeftCeiling"
174 || name == "LeftDoubleBracket"
175 || name == "LeftFloor"
176 || name == "OpenCurlyDoubleQuote"
177 || name == "OpenCurlyQuote"
178 || name == "RightAngleBracket"
179 || name == "RightCeiling"
180 || name == "RightDoubleBracket"
181 || name == "RightFloor" ) {
182 return new BracketElement();
183 }
184 return new OperatorElement();
185 }
186 if ( n.isText() ) {
187 TQString text = n.toText().data();
188 if ( text.length() == 1 && TQString("()[]{}").contains(text[0]) ) {
189 return new BracketElement();
190 }
191 }
192 return new OperatorElement();
193}
194
195IdentifierElement* OasisCreationStrategy::createIdentifierElement()
196{
197 return new IdentifierElement();
198}
199
200OperatorElement* OasisCreationStrategy::createOperatorElement()
201{
202 return new OperatorElement();
203}
204
205NumberElement* OasisCreationStrategy::createNumberElement()
206{
207 return new NumberElement();
208}
209
210KFORMULA_NAMESPACE_END
Basis of every formula element.
A left and/or right bracket around one child.
An element that represents an empty box.
The element with up to four indexes in the four corners.
Any number of lines.
The sequence thats a name.
virtual TextElement * createTextElement(const TQChar &ch, bool symbol=false)
there must always be a TextElement, so this can never return 0
virtual MatrixElement * createMatrixElement(uint rows, uint columns)
when this gets called the user has seen the matrix dialog and expects a matrix!
A line above the content.
A nice graphical root.
Definition rootelement.h:35
A element that represents a space.
A symbol is simply a piece of art.
An element that represents one char.
Definition textelement.h:37
A line below the content.
const char * name(StdAction id)