1 /* This file is part of EdiTeX, an editor of mathematical
2 * expressions based on TeX syntax.
4 * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
5 * 2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * For more information, please visit the project's home page
22 * http://helm.cs.unibo.it/editex/
23 * or send an email to <lpadovan@cs.unibo.it>
26 #include <GdomeSmartDOMXSLT.hh>
29 #include "TDictionary.hh"
30 #include "CMathMLFactoryXSLT.hh"
31 #include "TPushLexer.hh"
32 #include "TPushParser.hh"
34 class CCallbackLogger : public ALogger
37 CCallbackLogger(void (*)(int, const char*, void*), void*);
38 virtual ~CCallbackLogger() { };
41 virtual void message(Level, const std::string&);
44 void (*callback)(int, const char*, void*);
48 CCallbackLogger::CCallbackLogger(void (*cb)(int, const char*, void*), void* data) : callback(cb), user_data(data)
54 CCallbackLogger::message(Level l, const std::string& s)
57 callback(l, s.c_str(), user_data);
62 Editor(const DOM::Document&, const DOM::Document&, const DOM::Document&, void (*)(int, const char*, void*), void*);
66 TDictionary* dictionary;
67 DOMX::XSLTStylesheet* tml_mml;
68 DOMX::XSLTStylesheet* tml_tex;
69 AMathMLFactory* factory;
74 Editor::Editor(const DOM::Document& dict, const DOM::Document& mml, const DOM::Document& tex,
75 void (*cb)(int, const char*, void*), void* data)
78 logger = new CCallbackLogger(cb, data);
79 dictionary = new TDictionary(*logger);
80 dictionary->load(DOM::Document(dict));
81 tml_mml = new DOMX::XSLTStylesheet(mml);
82 tml_tex = new DOMX::XSLTStylesheet(tex);
83 factory = new CMathMLFactoryXSLT(*logger, *tml_mml);
84 parser = new TPushParser(*logger, *factory, *dictionary);
85 lexer = new TPushLexer(*logger, *parser);
100 c_mathml_editor_new(GdomeDocument* dictionary,
101 GdomeDocument* tml_mml,
102 GdomeDocument* tml_tex,
103 void (*log_message_cb)(int, const char*, void*),
106 return new Editor(DOM::Document(dictionary),
107 DOM::Document(tml_mml),
108 DOM::Document(tml_tex), log_message_cb, user_data);
112 c_mathml_editor_destroy(Editor* editor)
119 c_mathml_editor_freeze(Editor* editor)
122 return editor->parser->freeze();
126 c_mathml_editor_thaw(Editor* editor)
129 return editor->parser->thaw();
133 c_mathml_editor_push(Editor* editor, char ch)
136 editor->lexer->push(ch);
140 c_mathml_editor_drop(Editor* editor, int alt)
143 editor->lexer->drop(alt != 0);
147 c_mathml_editor_cursor_hide(Editor* editor)
150 return editor->parser->hideCursor();
154 c_mathml_editor_cursor_show(Editor* editor)
157 return editor->parser->showCursor();
161 c_mathml_editor_get_tex(const Editor* editor)
164 DOM::Document res = editor->tml_tex->apply(editor->parser->document());
167 assert(res.get_firstChild() && res.get_firstChild().get_nodeName() == "#text");
168 return strdup(std::string(res.get_firstChild().get_nodeValue()).c_str());
172 c_mathml_editor_reset(Editor* editor)
175 editor->parser->reset();
178 extern "C" GdomeDocument*
179 c_mathml_editor_get_tml(const Editor* editor)
182 GdomeNode* n = editor->parser->document().cloneNode(true).gdome_object();
183 GdomeDocument* doc = gdome_cast_doc(n);
188 extern "C" GdomeDocument*
189 c_mathml_editor_get_mml(const Editor* editor)
192 GdomeNode* n = editor->factory->document().gdome_object();
193 GdomeDocument* doc = gdome_cast_doc(n);