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 "LPushLexer.hh"
33 #include "TPushParser.hh"
35 class CCallbackLogger : public ALogger
38 CCallbackLogger(void (*)(int, const char*, void*), void*);
39 virtual ~CCallbackLogger() { };
42 virtual void message(Level, const std::string&);
45 void (*callback)(int, const char*, void*);
49 CCallbackLogger::CCallbackLogger(void (*cb)(int, const char*, void*), void* data) : callback(cb), user_data(data)
55 CCallbackLogger::message(Level l, const std::string& s)
58 callback(l, s.c_str(), user_data);
63 Editor(const char*, const char*, const char*, void (*)(int, const char*, void*), void*, bool);
67 TDictionary* dictionary;
68 DOMX::XSLTStylesheet* tml_mml;
69 DOMX::XSLTStylesheet* tml_tex;
70 AMathMLFactory* factory;
75 Editor::Editor(const char* dict_uri, const char* mml_uri, const char* tex_uri,
76 void (*cb)(int, const char*, void*), void* data, bool alt)
82 logger = new CCallbackLogger(cb, data);
83 dictionary = new TDictionary(*logger);
84 dictionary->load(dict_uri);
85 DOM::DOMImplementation di;
86 DOM::Document mml = di.createDocumentFromURI(mml_uri);
87 DOM::Document tex = di.createDocumentFromURI(tex_uri);
88 tml_mml = new DOMX::XSLTStylesheet(mml);
89 tml_tex = new DOMX::XSLTStylesheet(tex);
90 factory = new CMathMLFactoryXSLT(*logger, *tml_mml);
91 parser = new TPushParser(*logger, *factory, *dictionary);
92 if (alt) lexer = new LPushLexer(*logger, *parser);
93 else lexer = new TPushLexer(*logger, *parser);
107 extern "C" const char*
108 c_mathml_editor_get_default_dictionary_path()
110 return TDictionary::getDefaultDictionaryPath().c_str();
113 extern "C" const char*
114 c_mathml_editor_get_default_mathml_stylesheet_path()
116 return AMathMLFactory::getDefaultMathMLStylesheetPath().c_str();
119 extern "C" const char*
120 c_mathml_editor_get_default_tex_stylesheet_path()
122 return AMathMLFactory::getDefaultTeXStylesheetPath().c_str();
126 c_mathml_editor_new(bool alt,
127 const char* dictionary_uri,
128 const char* tml_mml_uri,
129 const char* tml_tex_uri,
130 void (*log_message_cb)(int, const char*, void*),
133 return new Editor(dictionary_uri, tml_mml_uri, tml_tex_uri, log_message_cb, user_data, alt);
137 c_mathml_editor_destroy(Editor* editor)
144 c_mathml_editor_freeze(Editor* editor)
147 return editor->parser->freeze();
151 c_mathml_editor_thaw(Editor* editor)
154 return editor->parser->thaw();
158 c_mathml_editor_push(Editor* editor, char ch)
161 editor->lexer->push(ch);
165 c_mathml_editor_drop(Editor* editor, int alt)
168 editor->lexer->drop(alt != 0);
172 c_mathml_editor_cursor_hide(Editor* editor)
175 return editor->parser->hideCursor();
179 c_mathml_editor_cursor_show(Editor* editor)
182 return editor->parser->showCursor();
186 c_mathml_editor_get_tex(const Editor* editor)
189 DOM::Document res = editor->tml_tex->apply(editor->parser->document());
192 assert(res.get_firstChild() && res.get_firstChild().get_nodeName() == "#text");
193 return strdup(std::string(res.get_firstChild().get_nodeValue()).c_str());
197 c_mathml_editor_reset(Editor* editor)
200 editor->parser->reset();
203 extern "C" GdomeDocument*
204 c_mathml_editor_get_tml(const Editor* editor)
207 GdomeNode* n = editor->parser->document().cloneNode(true).gdome_object();
208 GdomeDocument* doc = gdome_cast_doc(n);
213 extern "C" GdomeDocument*
214 c_mathml_editor_get_mml(const Editor* editor)
217 GdomeNode* n = editor->factory->document().gdome_object();
218 GdomeDocument* doc = gdome_cast_doc(n);