1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
// Copyright (C) 2000-2004, Luca Padovani <luca.padovani@cs.unibo.it>.
//
// This file is part of GtkMathView, a Gtk widget for MathML.
//
// GtkMathView is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// GtkMathView is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GtkMathView; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For details, see the GtkMathView World-Wide-Web page,
// http://helm.cs.unibo.it/mml-widget/, or send a mail to
// <lpadovan@cs.unibo.it>
#include <config.h>
#include "AbstractLogger.hh"
#include "libxml2_MathView.hh"
#include "libxml2_Model.hh"
#include "libxml2_Setup.hh"
#include "libxml2_Builder.hh"
libxml2_MathView::libxml2_MathView(const SmartPtr<AbstractLogger>& logger)
: View(logger), currentDoc(0), docOwner(false)
{
setBuilder(libxml2_Builder::create());
}
libxml2_MathView::~libxml2_MathView()
{
if (docOwner && currentDoc) xmlFreeDoc(currentDoc);
currentDoc = 0;
docOwner = false;
}
SmartPtr<libxml2_MathView>
libxml2_MathView::create(const SmartPtr<AbstractLogger>& logger)
{ return new libxml2_MathView(logger); }
void
libxml2_MathView::unload()
{
resetRootElement();
if (docOwner && currentDoc) xmlFreeDoc(currentDoc);
currentDoc = 0;
docOwner = false;
if (SmartPtr<libxml2_Builder> builder = smart_cast<libxml2_Builder>(getBuilder()))
builder->setRootModelElement(0);
}
bool
libxml2_MathView::loadURI(const char* name)
{
assert(name);
if (xmlDoc* doc = libxml2_Model::document(*getLogger(), name, true))
{
if (loadDocument(doc))
{
docOwner = true;
return true;
}
else
{
resetRootElement();
xmlFreeDoc(doc);
return false;
}
}
unload();
return false;
}
bool
libxml2_MathView::loadBuffer(const char* buffer)
{
assert(buffer);
if (xmlDoc* doc = libxml2_Model::documentFromBuffer(*getLogger(), buffer, true))
{
if (loadDocument(doc))
{
docOwner = true;
return true;
}
else
{
resetRootElement();
xmlFreeDoc(doc);
return false;
}
}
unload();
return false;
}
bool
libxml2_MathView::loadDocument(xmlDoc* doc)
{
assert(doc);
if (xmlNode* root = xmlDocGetRootElement(doc))
{
const bool res = loadRootElement((xmlElement*) root);
if (res) currentDoc = doc;
return res;
}
unload();
return false;
}
bool
libxml2_MathView::loadRootElement(xmlElement* elem)
{
assert(elem);
if (SmartPtr<libxml2_Builder> builder = smart_cast<libxml2_Builder>(getBuilder()))
{
resetRootElement();
builder->setRootModelElement(elem);
return true;
}
unload();
return false;
}
SmartPtr<Element>
libxml2_MathView::elementOfModelElement(xmlElement* el) const
{
if (SmartPtr<libxml2_Builder> builder = smart_cast<libxml2_Builder>(getBuilder()))
return builder->findElement(el);
else
return 0;
}
xmlElement*
libxml2_MathView::modelElementOfElement(const SmartPtr<Element>& elem) const
{
if (SmartPtr<libxml2_Builder> builder = smart_cast<libxml2_Builder>(getBuilder()))
return (xmlElement*) builder->findSelfOrAncestorModelElement(elem);
else
return 0;
}
bool
libxml2_MathView::notifyStructureChanged(xmlElement* el) const
{
if (SmartPtr<libxml2_Builder> builder = smart_cast<libxml2_Builder>(getBuilder()))
return builder->notifyStructureChanged(el);
else
return false;
}
bool
libxml2_MathView::notifyAttributeChanged(xmlElement* el, const xmlChar* name) const
{
if (SmartPtr<libxml2_Builder> builder = smart_cast<libxml2_Builder>(getBuilder()))
return builder->notifyAttributeChanged(el, name);
else
return false;
}
bool
libxml2_MathView::loadConfiguration(const SmartPtr<AbstractLogger>& logger,
const SmartPtr<Configuration>& configuration, const String& path)
{ return libxml2_Setup::loadConfiguration(*logger, *configuration, path); }
bool
libxml2_MathView::loadOperatorDictionary(const SmartPtr<AbstractLogger>& logger,
const SmartPtr<MathMLOperatorDictionary>& dictionary, const String& path)
{ return libxml2_Setup::loadOperatorDictionary(*logger, *dictionary, path); }
|