Code

Use subdirectories with icon sizes.
[inkscape.git] / src / sp-object.h
index 054fb6c7af14b6e35a6b932f0a6a2f5176908d0d..8581fd35affd3a645f84466d500106867186c8ab 100644 (file)
@@ -1,11 +1,13 @@
-#ifndef __SP_OBJECT_H__
-#define __SP_OBJECT_H__
+#ifndef SP_OBJECT_H_SEEN
+#define SP_OBJECT_H_SEEN
 
 /** \file
  * Abstract base class for all nodes
  *
  * 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)
-#define SP_OBJECT_TITLE(o) sp_object_title_get((SPObject *) (o))
-#define SP_OBJECT_DESCRIPTION(o) sp_object_description_get((SPObject *) (o))
-
 
 #include <glib-object.h>
 #include <sigc++/connection.h>
 #include "forward.h"
 #include "version.h"
 #include "util/forward-pointer-iterator.h"
+#include "desktop-style.h"
 
 namespace Inkscape {
 namespace XML {
 class Node;
+class Document;
 }
 }
 
@@ -138,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
@@ -155,8 +161,45 @@ struct 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 */
+    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
+     */
+    void releaseReferences();
+
+    /** @brief connects to the release request signal
+     *
+     *  @param slot the slot to connect
+     *
+     *  @returns the sigc::connection formed
+     */
+    sigc::connection connectRelease(sigc::slot<void, SPObject *> slot) {
+        return _release_signal.connect(slot);
+    }
 
     /**
      * Represents the style properties, whether from presentation attributes, the <tt>style</tt>
@@ -199,22 +242,35 @@ 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 */
+    enum Action { ActionGeneral, ActionBBox, ActionUpdate, ActionShow };
+
+    /**
+     * 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);
 
-    /** @brief Gets the author-visible label for this object. */ 
+    /** @brief Gets the author-visible label for this object. */
     gchar const *label() const;
-    /** @brief Returns a default label for this object. */ 
+    /** @brief Returns a default label for this object. */
     gchar const *defaultLabel() const;
     /** @brief Sets the author-visible label for this object.
      *
@@ -225,14 +281,14 @@ struct SPObject : public GObject {
     void setLabel(gchar const *label);
 
     /** Retrieves the title of this object */
-    gchar const *title() const { return NULL; /* TODO */ }
+    gchar *title() const;
     /** Sets the title of this object */
-    void setTitle(gchar const *title) { /* TODO */ }
+    bool setTitle(gchar const *title, bool verbatim=false);
 
     /** Retrieves the description of this object */
-    gchar const *desc() const { return NULL; /* TODO */ }
+    gchar *desc() const;
     /** Sets the description of this object */
-    void setDesc(gchar const *desc) { /* TODO */ }
+    bool setDesc(gchar const *desc, bool verbatim=false);
 
     /** @brief Set the policy under which this object will be
      *         orphan-collected.
@@ -361,7 +417,7 @@ struct SPObject : public GObject {
     /** @brief Updates the object's repr based on the object's state.
      *
      *  This method updates the the repr attached to the object to reflect the object's current
-     *  state; see the two-argument version for details.
+     *  state; see the three-argument version for details.
      *
      *  @param flags object write flags that apply to this update
      *
@@ -389,7 +445,7 @@ struct SPObject : public GObject {
      *
      *  @return the updated repr
      */
-    Inkscape::XML::Node *updateRepr(Inkscape::XML::Node *repr, unsigned int flags);
+    Inkscape::XML::Node *updateRepr(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags);
 
     /** @brief Queues an deferred update of this object's display.
      *
@@ -445,7 +501,21 @@ struct SPObject : public GObject {
      */
     void emitModified(unsigned int flags);
 
+    /** @brief Connects to the modification notification signal
+     *
+     *  @param slot the slot to connect
+     *
+     *  @returns the connection formed thereby
+     */
+    sigc::connection connectModified(
+      sigc::slot<void, SPObject *, unsigned int> slot
+    ) {
+        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) {
@@ -453,16 +523,82 @@ struct SPObject : public GObject {
     }
     void _requireSVGVersion(Inkscape::Version version);
 
+    sigc::signal<void, SPObject *> _release_signal;
     sigc::signal<void, SPObject *> _delete_signal;
     sigc::signal<void, SPObject *> _position_changed_signal;
+    sigc::signal<void, SPObject *, unsigned int> _modified_signal;
     SPObject *_successor;
     CollectionPolicy _collection_policy;
     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().
+    bool setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verbatim);
+    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, SPDocument *doc, Inkscape::XML::Node *repr);
@@ -483,61 +619,20 @@ struct SPObjectClass {
     /* Modification handler */
     void (* modified) (SPObject *object, unsigned int flags);
 
-    Inkscape::XML::Node * (* write) (SPObject *object, Inkscape::XML::Node *repr, unsigned int flags);
-};
+    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);
 
-/*
- * 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_invoke_release(SPObject *object);
-
-void sp_object_set(SPObject *object, unsigned int key, gchar const *value);
-
-void sp_object_read_attr(SPObject *object, gchar const *key);
-
-/*
- * Get and set descriptive parameters.
- *
- * These are inefficent, so they are not intended to be used interactively.
- */
-
-gchar const *sp_object_title_get(SPObject *object);
-gchar const *sp_object_description_get(SPObject *object);
-unsigned int sp_object_title_set(SPObject *object, gchar const *title);
-unsigned int sp_object_description_set(SPObject *object, gchar const *desc);
-
-/* 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);
+    friend class SPObject;
+};
 
-Inkscape::Version sp_object_get_sodipodi_version(SPObject *object);
 
 int sp_object_compare_position(SPObject const *first, SPObject const *second);
 
-SPObject *sp_object_prev(SPObject *child);
-
 
-#endif
+#endif // SP_OBJECT_H_SEEN
 
 
 /*
@@ -549,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 :