-// Copyright (C) 2000-2002, 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://www.cs.unibo.it/helm/mml-widget, or send a mail to
-// <luca.padovani@cs.unibo.it>
+/* This file is part of GtkMathView-Bonobo, a Bonobo wrapper for GtkMathView.
+ * Copyright (C) 2003 Luca Padovani <lpadovan@cs.unibo.it>
+ * Pouria Masoudi <pmasoudi@cs.unibo.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more information, please visit the project's home page
+ * http://helm.cs.unibo.it/gtkmathview-bonobo
+ * or send an email to <lpadovan@cs.unibo.it>
+ */
#include <config.h>
-#include <assert.h>
+
+#include <cassert>
#include <sstream>
#include <GdomeSmartDOM.hh>
+#include "aux.h"
+
#define MATHML_NS_URI "http://www.w3.org/1998/Math/MathML"
namespace DOM = GdomeSmartDOM;
+static DOM::Element
+findElementById(const DOM::Element& el,
+ const DOM::GdomeString& ns, const DOM::GdomeString& name,
+ const DOM::GdomeString& id)
+{
+ assert(el);
+ if (el.getAttributeNS(ns, name) == id)
+ return el;
+ else
+ for (DOM::Node p = el.get_firstChild(); p; p = p.get_nextSibling())
+ if (p.get_nodeType() == DOM::Node::ELEMENT_NODE)
+ if (DOM::Element res = findElementById(p, ns, name, id))
+ return res;
+ return DOM::Element();
+}
+
static unsigned
getDepth(const DOM::Element& elem)
{
}
extern "C" GdomeElement*
-find_self_or_ancestor(GdomeElement* elem, const char* uri, const char* name)
+find_self_or_ancestor(GdomeElement* elem, const gchar* uri, const gchar* name)
{
DOM::Element el(elem);
}
extern "C" GdomeElement*
-find_xref_element(GdomeElement* elem)
+find_element_with_id(GdomeElement* elem, GdomeDOMString* ns_uri, GdomeDOMString* name)
{
- DOM::Element el = findElementWithAttribute(DOM::Element(elem), "xref");
+ assert(name != NULL);
+ DOM::Element el;
+ if (ns_uri != NULL)
+ el = findElementWithAttributeNS(DOM::Element(elem), DOM::GdomeString(ns_uri), DOM::GdomeString(name));
+ else
+ el = findElementWithAttribute(DOM::Element(elem), DOM::GdomeString(name));
return gdome_cast_el(el.gdome_object());
}
extern "C" GdomeDOMString*
find_hyperlink(GdomeElement* elem)
{
- DOM::Element el = findElementWithAttribute(DOM::Element(elem),"href");
- if (el) return el.getAttribute("href").gdome_str();
- else return NULL;
+ DOM::Element el = findElementWithAttribute(DOM::Element(elem),"href");
+ if (el) return el.getAttribute("href").gdome_str();
+ else return NULL;
}
-
-extern "C" void
-delete_element(GdomeElement* elem)
+extern "C" GdomeElement*
+find_element_by_id(GdomeElement* root, GdomeDOMString* ns_uri, GdomeDOMString* name,
+ const gchar* id)
{
- DOM::Element p(elem);
-
- DOM::Element parent = p.get_parentNode();
- assert(parent);
-
- parent.removeChild(p);
+ DOM::Element el = findElementById(DOM::Element(root),
+ DOM::GdomeString(ns_uri), DOM::GdomeString(name),
+ DOM::GdomeString(id));
+ return gdome_cast_el(el.gdome_object());
}