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>
30 #include "TDictionary.hh"
31 #include "CMathMLFactoryXSLT.hh"
32 #include "TPushLexer.hh"
33 #include "LPushLexer.hh"
34 #include "TPushParser.hh"
36 class CCallbackLogger : public ALogger
39 CCallbackLogger(void (*)(int, const char*, void*), void*);
40 virtual ~CCallbackLogger() { };
43 virtual void message(Level, const std::string&);
46 void (*callback)(int, const char*, void*);
50 CCallbackLogger::CCallbackLogger(void (*cb)(int, const char*, void*), void* data) : callback(cb), user_data(data)
56 CCallbackLogger::message(Level l, const std::string& s)
59 callback(l, s.c_str(), user_data);
64 Editor(const char*, const char*, const char*, void (*)(int, const char*, void*), void*, bool);
68 TDictionary* dictionary;
69 DOMX::XSLTStylesheet* tml_mml;
70 DOMX::XSLTStylesheet* tml_tex;
71 AMathMLFactory* factory;
76 Editor::Editor(const char* dict_uri, const char* mml_uri, const char* tex_uri,
77 void (*cb)(int, const char*, void*), void* data, bool alt)
83 logger = new CCallbackLogger(cb, data);
84 dictionary = new TDictionary(*logger);
85 dictionary->load(dict_uri);
86 DOM::DOMImplementation di;
87 DOM::Document mml = di.createDocumentFromURI(mml_uri);
88 DOM::Document tex = di.createDocumentFromURI(tex_uri);
89 tml_mml = new DOMX::XSLTStylesheet(mml);
90 tml_tex = new DOMX::XSLTStylesheet(tex);
91 factory = new CMathMLFactoryXSLT(*logger, *tml_mml);
92 parser = new TPushParser(*logger, *factory, *dictionary);
93 if (alt) lexer = new LPushLexer(*logger, *parser);
94 else lexer = new TPushLexer(*logger, *parser);
108 extern "C" const char*
109 c_mathml_editor_get_default_dictionary_path()
111 return TDictionary::getDefaultDictionaryPath().c_str();
114 extern "C" const char*
115 c_mathml_editor_get_default_mathml_stylesheet_path()
117 return AMathMLFactory::getDefaultMathMLStylesheetPath().c_str();
120 extern "C" const char*
121 c_mathml_editor_get_default_tex_stylesheet_path()
123 return AMathMLFactory::getDefaultTeXStylesheetPath().c_str();
127 c_mathml_editor_new(bool alt,
128 const char* dictionary_uri,
129 const char* tml_mml_uri,
130 const char* tml_tex_uri,
131 void (*log_message_cb)(int, const char*, void*),
134 return new Editor(dictionary_uri, tml_mml_uri, tml_tex_uri, log_message_cb, user_data, alt);
138 c_mathml_editor_destroy(Editor* editor)
145 c_mathml_editor_freeze(Editor* editor)
148 return editor->parser->freeze();
152 c_mathml_editor_thaw(Editor* editor)
155 return editor->parser->thaw();
159 c_mathml_editor_push(Editor* editor, char ch)
162 editor->lexer->push(ch);
166 c_mathml_editor_drop(Editor* editor, int alt)
169 editor->lexer->drop(alt != 0);
173 c_mathml_editor_cursor_hide(Editor* editor)
176 return editor->parser->hideCursor();
180 c_mathml_editor_cursor_show(Editor* editor)
183 return editor->parser->showCursor();
187 c_mathml_editor_get_tex(const Editor* editor)
190 DOM::Document res = editor->tml_tex->apply(editor->parser->document());
193 assert(res.get_firstChild() && res.get_firstChild().get_nodeName() == "#text");
194 return strdup(std::string(res.get_firstChild().get_nodeValue()).c_str());
198 c_mathml_editor_reset(Editor* editor)
201 editor->lexer->reset();
202 editor->parser->reset();
205 extern "C" GdomeDocument*
206 c_mathml_editor_get_tml(const Editor* editor)
209 GdomeNode* n = editor->parser->document().cloneNode(true).gdome_object();
210 GdomeDocument* doc = gdome_cast_doc(n);
215 extern "C" GdomeDocument*
216 c_mathml_editor_get_mml(const Editor* editor)
219 GdomeNode* n = editor->factory->document().gdome_object();
220 GdomeDocument* doc = gdome_cast_doc(n);