Code

Connector tool: make connectors avoid the convex hull of shapes.
[inkscape.git] / src / sp-object.h
index e853de097907055d0623422677b10fb8de7212d1..bbb8ecbd0a2d096e14baa0ccffaad3c75dec5f6c 100644 (file)
@@ -1,5 +1,5 @@
-#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
@@ -53,8 +53,6 @@
 #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>
@@ -69,6 +67,7 @@
 namespace Inkscape {
 namespace XML {
 class Node;
+class Document;
 }
 }
 
@@ -158,6 +157,21 @@ struct SPObject : public GObject {
     Inkscape::XML::Node *repr; /* Our xml representation */
     gchar *id; /* Our very own unique id */
 
+    /** @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>
      * attribute, or inherited.
@@ -206,11 +220,15 @@ struct SPObject : public GObject {
     SPObject *lastChild() { return _last_child; }
     SPObject const *lastChild() const { return _last_child; }
 
+    enum Action { ActionGeneral, ActionBBox, ActionUpdate, ActionShow };
+    /** @brief Retrieves children as a GSList */
+    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.
      *
@@ -221,14 +239,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.
@@ -287,6 +305,10 @@ struct SPObject : public GObject {
         }
     }
 
+    /** @brief Check if object is referenced by any other object.
+     */
+    bool isReferenced() { return ( _total_hrefcount > 0 ); }
+
     /** @brief Deletes an object.
      *
      * Detaches the object's repr, and optionally sends notification that the object has been
@@ -353,7 +375,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
      *
@@ -381,7 +403,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.
      *
@@ -437,6 +459,18 @@ 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);
+    }
+
     void _sendDeleteSignalRecursive();
     void _updateTotalHRefCount(int increment);
 
@@ -445,12 +479,22 @@ 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;
+
+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;
 };
 
 /// The SPObject vtable.
@@ -475,7 +519,7 @@ 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);
 };
 
 
@@ -493,23 +537,11 @@ inline SPObject *sp_object_first_child(SPObject *parent) {
 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);
@@ -520,16 +552,14 @@ void sp_object_removeAttribute(SPObject *object, gchar const *key, SPException *
 /* Style */
 
 gchar const *sp_object_get_style_property(SPObject const *object,
-                                         gchar const *key, gchar const *def);
-
-Inkscape::Version sp_object_get_sodipodi_version(SPObject *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
+#endif // SP_OBJECT_H_SEEN
 
 
 /*