Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / xml / repr.h
index 162451a0fb304f61c22238a7b7a4c1f831e846be..bde3e533f07b6b458bc8e6eb80d0d5f0f9220342 100644 (file)
@@ -1,17 +1,18 @@
-#ifndef __SP_REPR_H__
-#define __SP_REPR_H__
-
-/** \file
- * C facade to Inkscape::XML::Node.
- *
- * Authors:
+/** @file
+ * @brief C facade to Inkscape::XML::Node
+ */
+/* Authors:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
  * Copyright (C) 1999-2002 authors
  * Copyright (C) 2000-2002 Ximian, Inc.
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
+#ifndef SEEN_SP_REPR_H
+#define SEEN_SP_REPR_H
 
 #include <stdio.h>
 #include <glib/gtypes.h>
@@ -22,7 +23,7 @@
 #include "xml/sp-css-attr.h"
 #include "io/inkscapestream.h"
 
-#include <2geom/point.h>
+#include <2geom/forward.h>
 
 #define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
 #define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
 #define SP_OLD_CC_NS_URI "http://web.resource.org/cc/"
 #define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/"
 
-/**
- * \note NB! Unless explicitly stated all methods are noref/nostrcpy
- */
-
-/** \todo
- * Though Inkscape::XML::Node provides "signals" for notification when 
- * individual nodes change, there is no mechanism to receive notification 
- * for overall document changes.
- * However, with the addition of the transactions code, it would not be
- * very hard to implement if you wanted it.
- * 
- * \class Inkscape::XML::Node
- * \note
- * Inkscape::XML::Node itself doesn't use GObject signals at present -- 
- * Inkscape::XML::Nodes maintain lists of Inkscape::XML::NodeEventVectors 
- * (added via sp_repr_add_listener), which are used to specify callbacks 
- * when something changes.
- *
- * Here are the current callbacks in an event vector (they may be NULL):
- *
- * void (* child_added)(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, 
- * Inkscape::XML::Node *ref, void *data); Called once a child has been added.
- *
- * void (* child_removed)(Inkscape::XML::Node *repr, 
- * Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void *data);
- * Called after a child is removed; ref is the child that used to precede
- * the removed child.
- *
- * void (* attr_changed)(Inkscape::XML::Node *repr, gchar const *key, 
- * gchar const *oldval, gchar const *newval, void *data);
- * Called after an attribute has been changed.
- *
- * void (* content_changed)(Inkscape::XML::Node *repr, gchar const *oldcontent,
- * gchar const *newcontent, void *data);
- * Called after an element's content has been changed.
- *
- * void (* order_changed)(Inkscape::XML::Node *repr, Inkscape::XML::Node *child,
- * Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref, void *data);
- * Called once the child has been moved to its new position in the child order.
- *
- * <b> Inkscape::XML::Node mini-FAQ </b>
- *
- * Since I'm not very familiar with this section of code but I need to use
- * it heavily for the RDF work, I'm going to answer various questions I run
- * into with my best-guess answers so others can follow along too.
- *
- * \arg
- * Q: How do I find the root Inkscape::XML::Node? <br>
- * A: If you have an SPDocument, use doc->rroot.  For example: 
- * 
- * \code    SP_ACTIVE_DOCUMENT->rroot       \endcode <br>
- * 
- * (but it's better to arrange for your caller to pass in the relevent
- * document rather than assuming it's necessarily the active one and
- * using SP_ACTIVE_DOCUMENT)
- *
- * \arg
- * Q: How do I find an Inkscape::XML::Node by unique key/value? <br>
- * A: Use sp_repr_lookup_child
- *
- * \arg
- * Q: How do I find an Inkscape::XML::Node by unique namespace name? <br>
- * A: Use sp_repr_lookup_name
- *
- * \arg
- * Q: How do I make an Inkscape::XML::Node namespace prefix constant in 
- * the application? <br>
- * A: Add the XML namespace URL as a #define to repr.h at the top with the
- * other SP_<NAMESPACE>_NS_URI #define's, and then in repr-util.cpp,
- * in sp_xml_ns_register_defaults, bump "defaults" up in size one, and
- * add another section.  Don't forget to increment the array offset and
- * keep ".next" pointed to the next (if any) array entry.
- *
- * \arg
- * Q: How do I create a new Inkscape::XML::Node? <br>
- * A: Use the appropriate create* method on Inkscape::XML::Document,
- * parent->appendChild(child), and then use Inkscape::GC::release(child) to
- * let go of it (the parent will hold it in memory).
- *
- * \arg
- * Q: How do I destroy an Inkscape::XML::Node?
- * A: Just call "sp_repr_unparent" on it and release any references
- * you may be retaining to it.  Any attached SPObjects will
- * clean themselves up automatically, as will any children.
- *
- * \arg
- * Q: What about listeners? <br>
- * A: I have no idea yet...
- *
- * \arg
- * Q: How do I add a namespace to a newly created document?  <br>
- * A: The current hack is in document.cpp:sp_document_create
- *
- * Kees Cook  2004-07-01, updated MenTaLguY 2005-01-25
- */
-
-namespace Geom {
-class Point;
-}
-
 /* SPXMLNs */
 char const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested);
 char const *sp_xml_ns_prefix_uri(gchar const *prefix);
@@ -141,44 +42,52 @@ char const *sp_xml_ns_prefix_uri(gchar const *prefix);
 Inkscape::XML::Document *sp_repr_document_new(gchar const *rootname);
 
 /* Tree */
-/// Returns the node's parent.
+/// @deprecated Use the equivalent member function Inkscape::XML::Node::parent()
 inline Inkscape::XML::Node *sp_repr_parent(Inkscape::XML::Node const *repr) {
     return const_cast<Inkscape::XML::Node *>(repr->parent());
 }
 
-/// Returns first child of node, resets iterator.
+/// @deprecated Use the equivalent member function Inkscape::XML::Node::firstChild()
 inline Inkscape::XML::Node const *sp_repr_children(Inkscape::XML::Node const *repr) {
     return ( repr ? repr->firstChild() : NULL );
 }
 
-/// Returns first child of node, resets iterator.
+/// @deprecated Use the equivalent member function Inkscape::XML::Node::firstChild()
 inline Inkscape::XML::Node *sp_repr_children(Inkscape::XML::Node *repr) {
     return ( repr ? repr->firstChild() : NULL );
 }
 
-/// Returns next child of node or NULL.
+/// @deprecated Use the equivalent member function Inkscape::XML::Node::next()
 inline Inkscape::XML::Node const *sp_repr_next(Inkscape::XML::Node const *repr) {
     return ( repr ? repr->next() : NULL );
 }
 
-/// Returns next child of node or NULL.
+/// @deprecated Use the equivalent member function Inkscape::XML::Node::next()
 inline Inkscape::XML::Node *sp_repr_next(Inkscape::XML::Node *repr) {
     return ( repr ? repr->next() : NULL );
 }
 
+
 /* IO */
 
 Inkscape::XML::Document *sp_repr_read_file(gchar const *filename, gchar const *default_ns);
 Inkscape::XML::Document *sp_repr_read_mem(gchar const *buffer, int length, gchar const *default_ns);
-void sp_repr_write_stream (Inkscape::XML::Node *repr, Inkscape::IO::Writer &out,
-                 gint indent_level,  bool add_whitespace, Glib::QueryQuark elide_prefix,
-                                int inlineattrs, int indent);
+void sp_repr_write_stream(Inkscape::XML::Node *repr, Inkscape::IO::Writer &out,
+                          gint indent_level,  bool add_whitespace, Glib::QueryQuark elide_prefix,
+                          int inlineattrs, int indent,
+                          gchar const *old_href_base = NULL,
+                          gchar const *new_href_base = NULL);
 Inkscape::XML::Document *sp_repr_read_buf (const Glib::ustring &buf, const gchar *default_ns);
 Glib::ustring sp_repr_save_buf(Inkscape::XML::Document *doc);
-void sp_repr_save_stream(Inkscape::XML::Document *doc, FILE *to_file, gchar const *default_ns=NULL, bool compress = false);
+void sp_repr_save_stream(Inkscape::XML::Document *doc, FILE *to_file,
+                         gchar const *default_ns = NULL, bool compress = false,
+                         gchar const *old_href_base = NULL,
+                         gchar const *new_href_base = NULL);
 bool sp_repr_save_file(Inkscape::XML::Document *doc, gchar const *filename, gchar const *default_ns=NULL);
+bool sp_repr_save_rebased_file(Inkscape::XML::Document *doc, gchar const *filename_utf8,
+                               gchar const *default_ns,
+                               gchar const *old_base, gchar const *new_base_filename);
 
-void sp_repr_print(Inkscape::XML::Node *repr);
 
 /* CSS stuff */
 
@@ -211,6 +120,8 @@ inline void sp_repr_unparent(Inkscape::XML::Node *repr) {
     }
 }
 
+bool sp_repr_is_meta_element(const Inkscape::XML::Node *node);
+
 /* Convenience */
 unsigned sp_repr_get_boolean(Inkscape::XML::Node *repr, gchar const *key, unsigned *val);
 unsigned sp_repr_get_int(Inkscape::XML::Node *repr, gchar const *key, int *val);
@@ -219,21 +130,37 @@ unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, gchar const *key, unsign
 unsigned sp_repr_set_int(Inkscape::XML::Node *repr, gchar const *key, int val);
 unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, gchar const *key, double val);
 unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val);
-unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val);
+unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point const & val);
 unsigned sp_repr_get_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point *val);
 
-/// \deprecated !
+/// \deprecated Use sp_repr_get_double to check for success
 double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, double def);
-/// \deprecated !
+/// \deprecated Use sp_repr_get_int to check for success
 long long int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, gchar const *key, long long int def);
-/* End Deprecated? */
 
-int sp_repr_compare_position(Inkscape::XML::Node *first, Inkscape::XML::Node *second);
+int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second);
 
-/* Searching */
+// Searching
+/**
+ * @brief Find an element node with the given name
+ *
+ * This function searches the descendants of the specified node depth-first for
+ * the first XML node with the specified name.
+ *
+ * @param repr The node to start from
+ * @param name The name of the element node to find
+ * @param maxdepth Maximum search depth, or -1 for an unlimited depth
+ * @return  A pointer to the matching Inkscape::XML::Node
+ * @relatesalso Inkscape::XML::Node
+ */
 Inkscape::XML::Node *sp_repr_lookup_name(Inkscape::XML::Node *repr,
                                          gchar const *name,
                                          gint maxdepth = -1);
+
+Inkscape::XML::Node const *sp_repr_lookup_name(Inkscape::XML::Node const *repr,
+                                               gchar const *name,
+                                               gint maxdepth = -1);
+
 Inkscape::XML::Node *sp_repr_lookup_child(Inkscape::XML::Node *repr,
                                           gchar const *key,
                                           gchar const *value);
@@ -243,9 +170,7 @@ inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document
     return const_cast<Inkscape::XML::Node *>(doc->firstChild());
 }
 
-#endif
-
-
+#endif // SEEN_SP_REPR_H
 /*
   Local Variables:
   mode:c++
@@ -255,4 +180,4 @@ inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :