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_cursor_hide(Editor* editor)
126 return editor->parser->hideCursor();
130 c_mathml_editor_cursor_show(Editor* editor)
133 return editor->parser->showCursor();
137 c_mathml_editor_get_tex(const Editor* editor)
140 DOM::Document res = editor->tml_tex->apply(editor->parser->document());
143 assert(res.get_firstChild() && res.get_firstChild().get_nodeName() == "#text");
144 return strdup(std::string(res.get_firstChild().get_nodeValue()).c_str());
148 c_mathml_editor_reset(Editor* editor)
151 editor->parser->reset();
154 extern "C" GdomeDocument*
155 c_mathml_editor_get_tml(const Editor* editor)
158 GdomeNode* n = editor->parser->document().cloneNode(true).gdome_object();
159 GdomeDocument* doc = gdome_cast_doc(n);
164 extern "C" GdomeDocument*
165 c_mathml_editor_get_mml(const Editor* editor)
168 GdomeNode* n = editor->factory->document().gdome_object();
169 GdomeDocument* doc = gdome_cast_doc(n);