X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmathml_editor%2Ftest%2Feditor.cc;h=62435ca788e95322d9ca128f88231a17960039da;hb=387aeebf96181c051b7f527a0901b173cfcdf194;hp=9d548289c6a2625491060ef5b83ae543a492c369;hpb=2f94240bc382ca43017f31b0852f1717fe18090b;p=helm.git diff --git a/helm/DEVEL/mathml_editor/test/editor.cc b/helm/DEVEL/mathml_editor/test/editor.cc index 9d548289c..62435ca78 100644 --- a/helm/DEVEL/mathml_editor/test/editor.cc +++ b/helm/DEVEL/mathml_editor/test/editor.cc @@ -5,36 +5,16 @@ #include "TDictionary.hh" #include "CLoggerConsole.hh" #include "CMathMLFactoryXSLT.hh" +#include "CMathMLFactoryXSLTDiff.hh" #include "AMathMLConsumer.hh" #include "guiGTK.h" -TDictionary dictionary; - extern void *parseMathMLFile(char *); -class CMathMLConsumer : public AMathMLConsumer -{ -public: - CMathMLConsumer(void) { firstTime = true; }; - - virtual void documentModified(const DOM::Document& result) - { - if (firstTime) - { - if (GUI_load_document(gdome_cast_doc(static_cast(result))) < 0) - cerr << "c'e' stato un errore" << endl; - firstTime = false; - } - } - -private: - bool firstTime; -}; - struct Context { - Context(const std::string& s, TPushLexer& l) : buffer(s), i(0), lexer(l) { }; + Context(const std::string& s, TPushLexer& l, TPushParser& p) : buffer(s), i(0), lexer(l), parser(p) { }; void send(void) { @@ -45,6 +25,7 @@ struct Context std::string buffer; unsigned i; TPushLexer& lexer; + TPushParser& parser; }; extern "C" int @@ -58,27 +39,52 @@ edit_timeout(Context* data) } extern "C" void -push_char(Context* context, gchar ch) +edit_push_char(Context* context, gchar ch) { + assert(context != NULL); GUI_freeze(); cout << "*** SENDING " << ch << endl; context->lexer.push(ch); GUI_thaw(); } +extern "C" void +edit_push_string(Context* context, const gchar* s) +{ + assert(context != NULL); + assert(s != NULL); + GUI_freeze(); + context->parser.freeze(); + for (unsigned i = 0; s[i]; i++) context->lexer.push(s[i]); + context->parser.thaw(); + GUI_thaw(); +} + +extern "C" void +edit_drop(Context* context, gboolean alt) +{ + assert(context != NULL); + GUI_freeze(); + context->lexer.drop(alt); + GUI_thaw(); +} + +void main(int argc, char* argv[]) { CLoggerConsole logger; + logger.verbosity(ALogger::Debug); + + TDictionary dictionary(logger); logger.info("loading the dictionary..."); - dictionary.load("dictionary.xml"); + dictionary.load("dictionary-test.xml"); logger.info("loading the stylesheet..."); DOM::DOMImplementation di; DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl"); - DOM::XSLTStylesheet style(docStyle); + DOMX::XSLTStylesheet style(docStyle); - CMathMLConsumer consumer; - CMathMLFactoryXSLT factory(logger, consumer, style); + CMathMLFactoryXSLTDiff factory(logger, style); TPushParser parser(logger, factory, dictionary); TPushLexer lexer(logger, parser); @@ -95,9 +101,10 @@ main(int argc, char* argv[]) style.save(result, stdout); #endif - Context context("", lexer); + Context context("", lexer, parser); GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context); + GUI_load_document(gdome_cast_doc(static_cast(factory.document()))); GUI_run(); GUI_uninit(); GUI_unload_document();