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 char*, const char*, const char*, 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 char* dict_uri, const char* mml_uri, const char* tex_uri,
75 void (*cb)(int, const char*, void*), void* data)
81 logger = new CCallbackLogger(cb, data);
82 dictionary = new TDictionary(*logger);
83 dictionary->load(dict_uri);
84 DOM::DOMImplementation di;
85 DOM::Document mml = di.createDocumentFromURI(mml_uri);
86 DOM::Document tex = di.createDocumentFromURI(tex_uri);
87 tml_mml = new DOMX::XSLTStylesheet(mml);
88 tml_tex = new DOMX::XSLTStylesheet(tex);
89 factory = new CMathMLFactoryXSLT(*logger, *tml_mml);
90 parser = new TPushParser(*logger, *factory, *dictionary);
91 lexer = new TPushLexer(*logger, *parser);
105 extern "C" const char*
106 c_mathml_editor_get_default_dictionary_path()
108 return TDictionary::getDefaultDictionaryPath().c_str();
111 extern "C" const char*
112 c_mathml_editor_get_default_mathml_stylesheet_path()
114 return AMathMLFactory::getDefaultMathMLStylesheetPath().c_str();
117 extern "C" const char*
118 c_mathml_editor_get_default_tex_stylesheet_path()
120 return AMathMLFactory::getDefaultTeXStylesheetPath().c_str();
124 c_mathml_editor_new(const char* dictionary_uri,
125 const char* tml_mml_uri,
126 const char* tml_tex_uri,
127 void (*log_message_cb)(int, const char*, void*),
130 return new Editor(dictionary_uri, tml_mml_uri, tml_tex_uri, log_message_cb, user_data);
134 c_mathml_editor_destroy(Editor* editor)
141 c_mathml_editor_freeze(Editor* editor)
144 return editor->parser->freeze();
148 c_mathml_editor_thaw(Editor* editor)
151 return editor->parser->thaw();
155 c_mathml_editor_push(Editor* editor, char ch)
158 editor->lexer->push(ch);
162 c_mathml_editor_drop(Editor* editor, int alt)
165 editor->lexer->drop(alt != 0);
169 c_mathml_editor_cursor_hide(Editor* editor)
172 return editor->parser->hideCursor();
176 c_mathml_editor_cursor_show(Editor* editor)
179 return editor->parser->showCursor();
183 c_mathml_editor_get_tex(const Editor* editor)
186 DOM::Document res = editor->tml_tex->apply(editor->parser->document());
189 assert(res.get_firstChild() && res.get_firstChild().get_nodeName() == "#text");
190 return strdup(std::string(res.get_firstChild().get_nodeValue()).c_str());
194 c_mathml_editor_reset(Editor* editor)
197 editor->parser->reset();
200 extern "C" GdomeDocument*
201 c_mathml_editor_get_tml(const Editor* editor)
204 GdomeNode* n = editor->parser->document().cloneNode(true).gdome_object();
205 GdomeDocument* doc = gdome_cast_doc(n);
210 extern "C" GdomeDocument*
211 c_mathml_editor_get_mml(const Editor* editor)
214 GdomeNode* n = editor->factory->document().gdome_object();
215 GdomeDocument* doc = gdome_cast_doc(n);