Code

Add a warning to sp-object.h to not use some of the new methods
[inkscape.git] / src / sp-object.h
index 2932da728583d4e491d63edeb14ebdab34931856..8581fd35affd3a645f84466d500106867186c8ab 100644 (file)
@@ -6,6 +6,8 @@
  *
  * Authors:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 1999-2002 authors
  * Copyright (C) 2001-2002 Ximian, Inc.
 
 /* SPObject flags */
 
+class SPObject;
+class SPObjectClass;
+
+#define SP_TYPE_OBJECT (SPObject::sp_object_get_type ())
+#define SP_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_OBJECT, SPObject))
+#define SP_OBJECT_CLASS(clazz) (G_TYPE_CHECK_CLASS_CAST((clazz), SP_TYPE_OBJECT, SPObjectClass))
+#define SP_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_OBJECT))
+
 /* Async modification flags */
 #define SP_OBJECT_MODIFIED_FLAG (1 << 0)
 #define SP_OBJECT_CHILD_MODIFIED_FLAG (1 << 1)
 #define SP_OBJECT_WRITE_ALL (1 << 2)
 
 /* Convenience stuff */
-#define SP_OBJECT_ID(o) (((SPObject *) (o))->id)
-#define SP_OBJECT_REPR(o) (((SPObject *) (o))->repr)
+#define SP_OBJECT_REPR(o) (((SPObject *) (o))->getRepr())
 #define SP_OBJECT_DOCUMENT(o) (((SPObject *) (o))->document)
 #define SP_OBJECT_PARENT(o) (((SPObject *) (o))->parent)
-#define SP_OBJECT_NEXT(o) (((SPObject *) (o))->next)
-#define SP_OBJECT_PREV(o) (sp_object_prev((SPObject *) (o)))
-#define SP_OBJECT_HREFCOUNT(o) (((SPObject *) (o))->hrefcount)
 #define SP_OBJECT_STYLE(o) (((SPObject *) (o))->style)
 
-
 #include <glib-object.h>
 #include <sigc++/connection.h>
 #include <sigc++/functors/slot.h>
@@ -63,6 +68,7 @@
 #include "forward.h"
 #include "version.h"
 #include "util/forward-pointer-iterator.h"
+#include "desktop-style.h"
 
 namespace Inkscape {
 namespace XML {
@@ -137,7 +143,8 @@ SPObject *sp_object_href(SPObject *object, gpointer owner);
 SPObject *sp_object_hunref(SPObject *object, gpointer owner);
 
 /// A refcounting tree node object.
-struct SPObject : public GObject {
+class SPObject : public GObject {
+public:
     enum CollectionPolicy {
         COLLECT_WITH_PARENT,
         ALWAYS_COLLECT
@@ -149,13 +156,35 @@ struct SPObject : public GObject {
     SPIXmlSpace xml_space;
     unsigned int hrefcount; /* number of xlink:href references */
     unsigned int _total_hrefcount; /* our hrefcount + total descendants */
-    Document *document; /* Document we are part of */
+    SPDocument *document; /* Document we are part of */
     SPObject *parent; /* Our parent (only one allowed) */
     SPObject *children; /* Our children */
     SPObject *_last_child; /* Remembered last child */
     SPObject *next; /* Next object in linked list */
-    Inkscape::XML::Node *repr; /* Our xml representation */
+
+private:
     gchar *id; /* Our very own unique id */
+    Inkscape::XML::Node *repr; /* Our xml representation */
+public:
+
+    /**
+     * Returns the objects current ID string.
+     */
+    gchar const* getId() const;
+
+    /**
+     * Returns the XML representation of tree
+     */
+    //Inkscape::XML::Node const* getRepr() const;
+//protected:
+    Inkscape::XML::Node * getRepr();
+
+    /**
+     * Returns the XML representation of tree
+     */
+    Inkscape::XML::Node const* getRepr() const;
+
+public:
 
     /** @brief cleans up an SPObject, releasing its references and
      *         requesting that references to it be released
@@ -213,15 +242,28 @@ struct SPObject : public GObject {
     /* A non-const version can be similarly constructed if you want one.
      * (Don't just cast away the constness, which would be ill-formed.) */
 
+    SPObject *getNext() {return next;}
+    SPObject const *getNext() const {return next;}
+
+    /**
+     * Returns previous object in sibling list or NULL.
+     */
+    SPObject *getPrev();
+
     bool hasChildren() const { return ( children != NULL ); }
 
     SPObject *firstChild() { return children; }
     SPObject const *firstChild() const { return children; }
+
     SPObject *lastChild() { return _last_child; }
     SPObject const *lastChild() const { return _last_child; }
 
     enum Action { ActionGeneral, ActionBBox, ActionUpdate, ActionShow };
-    /** @brief Retrieves children as a GSList */
+
+    /**
+     * Retrieves the children as a GSList object, optionally ref'ing the children
+     * in the process, if add_ref is specified.
+     */
     GSList *childList(bool add_ref, Action action = ActionGeneral);
 
     SPObject *appendChildRepr(Inkscape::XML::Node *repr);
@@ -429,7 +471,7 @@ struct SPObject : public GObject {
 
     /** @brief Updates the object's display immediately
      *
-     *  This method is called during the idle loop by Document in order to update the object's
+     *  This method is called during the idle loop by SPDocument in order to update the object's
      *  display.
      *
      *  One additional flag is legal here:
@@ -471,7 +513,9 @@ struct SPObject : public GObject {
         return _modified_signal.connect(slot);
     }
 
+    /** Sends the delete signal to all children of this object recursively */
     void _sendDeleteSignalRecursive();
+
     void _updateTotalHRefCount(int increment);
 
     void _requireSVGVersion(unsigned major, unsigned minor) {
@@ -488,6 +532,30 @@ struct SPObject : public GObject {
     gchar *_label;
     mutable gchar *_default_label;
 
+    // WARNING:
+    // Methods below should not be used outside of the SP tree,
+    // as they operate directly on the XML representation.
+    // In future, they will be made protected.
+    void attach(SPObject *object, SPObject *prev);
+    void reorder(SPObject *prev);
+    void detach(SPObject *object);
+    SPObject *get_child_by_repr(Inkscape::XML::Node *repr);
+    void invoke_build(SPDocument *document, Inkscape::XML::Node *repr, unsigned int cloned);
+    long long int getIntAttribute(char const *key, long long int def);
+    unsigned getPosition();
+    gchar const * getAttribute(gchar const *name,SPException *ex=0) const;
+    void appendChild(Inkscape::XML::Node *child);
+    void addChild(Inkscape::XML::Node *child,Inkscape::XML::Node *prev=0);
+    void setKeyValue(unsigned int key, gchar const *value);
+    void setAttribute(gchar const *key, gchar const *value, SPException *ex=0);
+    void readAttr(gchar const *key);
+    gchar const *getTagName(SPException *ex) const;
+    void removeAttribute(gchar const *key, SPException *ex=0);
+    gchar const *getStyleProperty(gchar const *key, gchar const *def) const;
+    void setCSS(SPCSSAttr *css, gchar const *attr);
+    void changeCSS(SPCSSAttr *css, gchar const *attr);
+    bool storeAsDouble( gchar const *key, double *val ) const;
+
 private:
     // Private member functions used in the definitions of setTitle(),
     // setDesc(), title() and desc().
@@ -495,13 +563,45 @@ private:
     gchar * getTitleOrDesc(gchar const *svg_tagname) const;
     SPObject * findFirstChild(gchar const *tagname) const;
     GString * textualContent() const;
+
+    static void sp_object_init(SPObject *object);
+    static void sp_object_finalize(GObject *object);
+
+    static void sp_object_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
+    static void sp_object_remove_child(SPObject *object, Inkscape::XML::Node *child);
+    static void sp_object_order_changed(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref);
+
+    static void sp_object_release(SPObject *object);
+    static void sp_object_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
+
+    static void sp_object_private_set(SPObject *object, unsigned int key, gchar const *value);
+    static Inkscape::XML::Node *sp_object_private_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
+    static gchar *sp_object_get_unique_id(SPObject *object, gchar const *defid);
+
+    /* Real handlers of repr signals */
+
+public:
+    static GType sp_object_get_type();
+    static void sp_object_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gchar const *oldval, gchar const *newval, bool is_interactive, gpointer data);
+
+    static void sp_object_repr_content_changed(Inkscape::XML::Node *repr, gchar const *oldcontent, gchar const *newcontent, gpointer data);
+
+    static void sp_object_repr_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data);
+    static void sp_object_repr_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void *data);
+
+    static void sp_object_repr_order_changed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *old, Inkscape::XML::Node *newer, gpointer data);
+
+
+    friend class SPObjectClass;
+    friend class SPObjectImpl;
 };
 
 /// The SPObject vtable.
-struct SPObjectClass {
+class SPObjectClass {
+public:
     GObjectClass parent_class;
 
-    void (* build) (SPObject *object, Document *doc, Inkscape::XML::Node *repr);
+    void (* build) (SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr);
     void (* release) (SPObject *object);
 
     /* Virtual handlers of repr signals */
@@ -520,44 +620,17 @@ struct SPObjectClass {
     void (* modified) (SPObject *object, unsigned int flags);
 
     Inkscape::XML::Node * (* write) (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags);
-};
-
 
-/*
- * Attaching/detaching
- */
-
-void sp_object_attach(SPObject *parent, SPObject *object, SPObject *prev);
-void sp_object_reorder(SPObject *object, SPObject *prev);
-void sp_object_detach(SPObject *parent, SPObject *object);
-
-inline SPObject *sp_object_first_child(SPObject *parent) {
-    return parent->firstChild();
-}
-SPObject *sp_object_get_child_by_repr(SPObject *object, Inkscape::XML::Node *repr);
-
-void sp_object_invoke_build(SPObject *object, Document *document, Inkscape::XML::Node *repr, unsigned int cloned);
-
-void sp_object_set(SPObject *object, unsigned int key, gchar const *value);
-
-void sp_object_read_attr(SPObject *object, gchar const *key);
-
-/* Public */
-
-gchar const *sp_object_tagName_get(SPObject const *object, SPException *ex);
-gchar const *sp_object_getAttribute(SPObject const *object, gchar const *key, SPException *ex);
-void sp_object_setAttribute(SPObject *object, gchar const *key, gchar const *value, SPException *ex);
-void sp_object_removeAttribute(SPObject *object, gchar const *key, SPException *ex);
+private:
+    static GObjectClass *static_parent_class;
+    static void sp_object_class_init(SPObjectClass *klass);
 
-/* Style */
+    friend class SPObject;
+};
 
-gchar const *sp_object_get_style_property(SPObject const *object,
-                                          gchar const *key, gchar const *def);
 
 int sp_object_compare_position(SPObject const *first, SPObject const *second);
 
-SPObject *sp_object_prev(SPObject *child);
-
 
 #endif // SP_OBJECT_H_SEEN
 
@@ -571,4 +644,4 @@ SPObject *sp_object_prev(SPObject *child);
   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 :