Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / sp-object.h
index b7b3f9cc48df57dadd0ce5e20a1673baa35b375d..5d3183d9c7245897ad6f2e80930477d2c9bc1b66 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.
@@ -53,13 +55,9 @@ class SPObjectClass;
 #define SP_OBJECT_WRITE_ALL (1 << 2)
 
 /* Convenience stuff */
-#define SP_OBJECT_ID(o) (((SPObject *) (o))->getId())
 #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) (((SPObject *) (o))->prev())
-#define SP_OBJECT_HREFCOUNT(o) (((SPObject *) (o))->hrefcount)
 #define SP_OBJECT_STYLE(o) (((SPObject *) (o))->style)
 
 #include <glib-object.h>
@@ -146,7 +144,7 @@ SPObject *sp_object_hunref(SPObject *object, gpointer owner);
 
 /// A refcounting tree node object.
 class SPObject : public GObject {
-       public:
+public:
     enum CollectionPolicy {
         COLLECT_WITH_PARENT,
         ALWAYS_COLLECT
@@ -163,7 +161,6 @@ class SPObject : public GObject {
     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 */
@@ -175,19 +172,20 @@ public:
      */
     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:        
-       
+    /**
+     * 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
      */
@@ -244,18 +242,28 @@ public:
     /* 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();
+    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);
@@ -505,7 +513,9 @@ public:
         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) {
@@ -521,29 +531,25 @@ public:
     CollectionPolicy _collection_policy;
     gchar *_label;
     mutable gchar *_default_label;
-       void attach(SPObject *object, SPObject *prev);
-       void reorder(SPObject *prev);
-       void detach(SPObject *object);
-       SPObject *get_child_by_repr(Inkscape::XML::Node *repr);
-       SPObject *first_child() {
-                   return firstChild();
-       }
-       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;
-       SPObject *prev();
-       void setCSS(SPCSSAttr *css, gchar const *attr);
-       void changeCSS(SPCSSAttr *css, gchar const *attr);
-       bool storeAsDouble( gchar const *key, double *val ) const;
+    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(),
@@ -553,41 +559,41 @@ private:
     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_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_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_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);
+    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);
+    /* Real handlers of repr signals */
 
-       static void sp_object_repr_content_changed(Inkscape::XML::Node *repr, gchar const *oldcontent, gchar const *newcontent, gpointer data);
+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_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);
+    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 SPObjectClass;
     friend class SPObjectImpl;
 };
 
 /// The SPObject vtable.
 class SPObjectClass {
-       public:
+public:
     GObjectClass parent_class;
 
     void (* build) (SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr);
@@ -610,49 +616,16 @@ class SPObjectClass {
 
     Inkscape::XML::Node * (* write) (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags);
 
-       private:
-       static GObjectClass *static_parent_class;
-       static void sp_object_class_init(SPObjectClass *klass);
+private:
+    static GObjectClass *static_parent_class;
+    static void sp_object_class_init(SPObjectClass *klass);
 
-       friend class SPObject;
+    friend class SPObject;
 };
 
 
-/*
- * 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, SPDocument *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);
-
-/* Style */
-
-//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
 
@@ -666,4 +639,4 @@ int sp_object_compare_position(SPObject const *first, SPObject const *second);
   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 :