]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/test/aux.cc
ocaml 3.09 transition
[helm.git] / helm / DEVEL / mathml_editor / test / aux.cc
index 61f9e5d795e32372c9fa0016c600faa6acf97d08..bb17013fbd78af452af349ae6e4310743d02afc0 100644 (file)
@@ -1,24 +1,27 @@
-// 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 EdiTeX, an editor of mathematical
+ * expressions based on TeX syntax.
+ * 
+ * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
+ *                    2003 Paolo Marinelli <pmarinel@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/editex/
+ * or send an email to <lpadovan@cs.unibo.it>
+ */
 
 #include <config.h>
 #include <assert.h>
@@ -124,6 +127,14 @@ findCommonSiblings(const DOM::Element& first, const DOM::Element& last,
   lastS = q;
 }
 
+static DOM::Element
+findElementWithRef(const DOM::Element& el)
+{
+  DOM::Element p = el;
+  while (p && !p.hasAttribute("xref")) p = p.get_parentNode();
+  return p;
+}
+
 static DOM::Node
 leftmostChild(const DOM::Node& node)
 {
@@ -188,17 +199,14 @@ rightSibling(const DOM::Node& node)
 extern "C" GdomeElement*
 find_common_ancestor(GdomeElement* first, GdomeElement* last)
 {
-  DOM::Element p(first);
-  DOM::Element q(last);
-  if (GdomeElement* res = gdome_cast_el(findCommonAncestor(p, q).gdome_object()))
+  if (GdomeNode* n = findCommonAncestor(DOM::Element(first), DOM::Element(last)).gdome_object())
     {
-      GdomeException exc = 0;
-      gdome_el_ref(res, &exc);
-      assert(exc == 0);
+      GdomeElement* res = gdome_cast_el(n);
+      g_assert(res != NULL);
       return res;
     }
   else
-    return 0;
+    return NULL;
 }
 
 extern "C" void
@@ -214,6 +222,32 @@ find_common_siblings(GdomeElement* first, GdomeElement* last,
   if (lastS != NULL) *lastS = gdome_cast_el(ls.gdome_object());
 }
 
+extern "C" GdomeElement*
+find_element_with_ref(GdomeElement* elem)
+{
+  if (GdomeNode* n = findElementWithRef(DOM::Element(elem)).gdome_object())
+    {
+      GdomeElement* res = gdome_cast_el(n);
+      g_assert(res != NULL);
+      return res;
+    }
+  else
+    return NULL;
+}
+
+extern "C" GdomeElement*
+find_common_ancestor_with_ref(GdomeElement* first, GdomeElement* last)
+{
+  if (GdomeNode* n = findElementWithRef(findCommonAncestor(DOM::Element(first), DOM::Element(last))).gdome_object())
+    {
+      GdomeElement* res = gdome_cast_el(n);
+      g_assert(res != NULL);
+      return res;
+    }
+  else
+    return NULL;
+}
+
 extern "C" void
 delete_element(GdomeElement* elem)
 {