2 #include <GdomeSmartDOMXSLT.hh>
5 #include "TDictionary.hh"
6 #include "CMathMLFactoryXSLT.hh"
7 #include "TPushLexer.hh"
8 #include "TPushParser.hh"
10 class CCallbackLogger : public ALogger
13 CCallbackLogger(void (*)(int, const char*, void*), void*);
14 virtual ~CCallbackLogger() { };
17 virtual void message(Level, const std::string&);
20 void (*callback)(int, const char*, void*);
24 CCallbackLogger::CCallbackLogger(void (*cb)(int, const char*, void*), void* data) : callback(cb), user_data(data)
30 CCallbackLogger::message(Level l, const std::string& s)
33 callback(l, s.c_str(), user_data);
38 Editor(const DOM::Document&, const DOM::Document&, const DOM::Document&, void (*)(int, const char*, void*), void*);
42 TDictionary* dictionary;
43 DOMX::XSLTStylesheet* tml_mml;
44 DOMX::XSLTStylesheet* tml_tex;
45 AMathMLFactory* factory;
50 Editor::Editor(const DOM::Document& dict, const DOM::Document& mml, const DOM::Document& tex,
51 void (*cb)(int, const char*, void*), void* data)
54 logger = new CCallbackLogger(cb, data);
55 dictionary = new TDictionary(*logger);
56 dictionary->load(DOM::Document(dict));
57 tml_mml = new DOMX::XSLTStylesheet(mml);
58 tml_tex = new DOMX::XSLTStylesheet(tex);
59 factory = new CMathMLFactoryXSLT(*logger, *tml_mml);
60 parser = new TPushParser(*logger, *factory, *dictionary);
61 lexer = new TPushLexer(*logger, *parser);
76 c_mathml_editor_new(GdomeDocument* dictionary,
77 GdomeDocument* tml_mml,
78 GdomeDocument* tml_tex,
79 void (*log_message_cb)(int, const char*, void*),
82 return new Editor(DOM::Document(dictionary),
83 DOM::Document(tml_mml),
84 DOM::Document(tml_tex), log_message_cb, user_data);
88 c_mathml_editor_destroy(Editor* editor)
95 c_mathml_editor_freeze(Editor* editor)
98 return editor->parser->freeze();
102 c_mathml_editor_thaw(Editor* editor)
105 return editor->parser->thaw();
109 c_mathml_editor_push(Editor* editor, char ch)
112 editor->lexer->push(ch);
116 c_mathml_editor_drop(Editor* editor, int alt)
119 editor->lexer->drop(alt != 0);
123 c_mathml_editor_get_tex(const Editor* editor)
126 DOM::Document res = editor->tml_tex->apply(editor->parser->document());
127 DOM::Element root = res.get_documentElement();
128 return strdup(std::string(root.get_nodeValue()).c_str());
132 c_mathml_editor_reset(Editor* editor)
135 editor->parser->reset();
138 extern "C" GdomeDocument*
139 c_mathml_editor_get_tml(const Editor* editor)
142 GdomeNode* n = editor->parser->document().cloneNode(true).gdome_object();
143 GdomeDocument* doc = gdome_cast_doc(n);
148 extern "C" GdomeDocument*
149 c_mathml_editor_get_mml(const Editor* editor)
152 GdomeNode* n = editor->factory->document().gdome_object();
153 GdomeDocument* doc = gdome_cast_doc(n);