diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index f23f374d47f030284bd43cd7231ff682a158807c..17def7f1554f1a13f6b68d5a2fcc8f6cbf7d3993 100644 (file)
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
-#define __SP_OBJECT_C__
/** \file
* SPObject implementation.
*
/** \file
* SPObject implementation.
*
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Stephen Silver <sasilver@users.sourceforge.net>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Stephen Silver <sasilver@users.sourceforge.net>
+ * Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
*
* Copyright (C) 1999-2008 authors
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Copyright (C) 1999-2008 authors
* Copyright (C) 2001-2002 Ximian, Inc.
#include "helper/sp-marshal.h"
#include "xml/node-event-vector.h"
#include "attributes.h"
#include "helper/sp-marshal.h"
#include "xml/node-event-vector.h"
#include "attributes.h"
+#include "color-profile-fns.h"
#include "document.h"
#include "style.h"
#include "sp-object-repr.h"
#include "document.h"
#include "style.h"
#include "sp-object-repr.h"
# define debug(f, a...) /**/
#endif
# define debug(f, a...) /**/
#endif
-/*static void sp_object_class_init(SPObjectClass *klass);
-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);
-
-* Real handlers of repr signals */
-
-/*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);
-
-static gchar *sp_object_get_unique_id(SPObject *object, gchar const *defid);*/
-
guint update_in_progress = 0; // guard against update-during-update
Inkscape::XML::NodeEventVector object_event_vector = {
guint update_in_progress = 0; // guard against update-during-update
Inkscape::XML::NodeEventVector object_event_vector = {
- SPObject::sp_object_repr_child_added,
+ SPObject::sp_object_repr_child_added,
SPObject::sp_object_repr_child_removed,
SPObject::sp_object_repr_attr_changed,
SPObject::sp_object_repr_content_changed,
SPObject::sp_object_repr_child_removed,
SPObject::sp_object_repr_attr_changed,
SPObject::sp_object_repr_content_changed,
};
};
-//static GObjectClass *parent_class;
-
GObjectClass * SPObjectClass::static_parent_class = 0;
/**
* Registers the SPObject class with Gdk and returns its type number.
*/
GObjectClass * SPObjectClass::static_parent_class = 0;
/**
* Registers the SPObject class with Gdk and returns its type number.
*/
-GType
-SPObject::sp_object_get_type()
+GType SPObject::sp_object_get_type()
{
static GType type = 0;
if (!type) {
{
static GType type = 0;
if (!type) {
/**
* Initializes the SPObject vtable.
*/
/**
* Initializes the SPObject vtable.
*/
-void
-SPObjectClass::sp_object_class_init(SPObjectClass *klass)
+void SPObjectClass::sp_object_class_init(SPObjectClass *klass)
{
GObjectClass *object_class;
object_class = (GObjectClass *) klass;
{
GObjectClass *object_class;
object_class = (GObjectClass *) klass;
- static_parent_class = (GObjectClass *) g_type_class_ref(G_TYPE_OBJECT);
+ static_parent_class = (GObjectClass *) g_type_class_ref(G_TYPE_OBJECT);
object_class->finalize = SPObject::sp_object_finalize;
object_class->finalize = SPObject::sp_object_finalize;
/**
* Callback to initialize the SPObject object.
*/
/**
* Callback to initialize the SPObject object.
*/
-void
-SPObject::sp_object_init(SPObject *object)
+void SPObject::sp_object_init(SPObject *object)
{
debug("id=%x, typename=%s",object, g_type_name_from_instance((GTypeInstance*)object));
{
debug("id=%x, typename=%s",object, g_type_name_from_instance((GTypeInstance*)object));
object->children = object->_last_child = NULL;
object->parent = object->next = NULL;
object->children = object->_last_child = NULL;
object->parent = object->next = NULL;
- //used XML Tree here.
- Inkscape::XML::Node *repr = object->getRepr();
- repr = NULL;
+ //used XML Tree here.
+ Inkscape::XML::Node *repr = object->getRepr();
+ repr = NULL;
SPObjectImpl::setIdNull(object);
object->_collection_policy = SPObject::COLLECT_WITH_PARENT;
SPObjectImpl::setIdNull(object);
object->_collection_policy = SPObject::COLLECT_WITH_PARENT;
/**
* Callback to destroy all members and connections of object and itself.
*/
/**
* Callback to destroy all members and connections of object and itself.
*/
-void
-SPObject::sp_object_finalize(GObject *object)
+void SPObject::sp_object_finalize(GObject *object)
{
SPObject *spobject = (SPObject *)object;
{
SPObject *spobject = (SPObject *)object;
}
Inkscape::XML::Node * SPObject::getRepr() {
}
Inkscape::XML::Node * SPObject::getRepr() {
- return repr;
+ return repr;
}
Inkscape::XML::Node const* SPObject::getRepr() const{
}
Inkscape::XML::Node const* SPObject::getRepr() const{
- return repr;
+ return repr;
}
}
* \return object, NULL is error.
* \pre object points to real object
*/
* \return object, NULL is error.
* \pre object points to real object
*/
-SPObject *
-sp_object_ref(SPObject *object, SPObject *owner)
+SPObject *sp_object_ref(SPObject *object, SPObject *owner)
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
* \return always NULL
* \pre object points to real object
*/
* \return always NULL
* \pre object points to real object
*/
-SPObject *
-sp_object_unref(SPObject *object, SPObject *owner)
+SPObject *sp_object_unref(SPObject *object, SPObject *owner)
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
* \return object, NULL is error
* \pre object points to real object
*/
* \return object, NULL is error
* \pre object points to real object
*/
-SPObject *
-sp_object_href(SPObject *object, gpointer /*owner*/)
+SPObject *sp_object_href(SPObject *object, gpointer /*owner*/)
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
* \return always NULL
* \pre object points to real object and hrefcount>0
*/
* \return always NULL
* \pre object points to real object and hrefcount>0
*/
-SPObject *
-sp_object_hunref(SPObject *object, gpointer /*owner*/)
+SPObject *sp_object_hunref(SPObject *object, gpointer /*owner*/)
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
{
g_return_val_if_fail(object != NULL, NULL);
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
/**
* Adds increment to _total_hrefcount of object and its parents.
*/
/**
* Adds increment to _total_hrefcount of object and its parents.
*/
-void
-SPObject::_updateTotalHRefCount(int increment) {
+void SPObject::_updateTotalHRefCount(int increment) {
SPObject *topmost_collectable = NULL;
SPObject *topmost_collectable = NULL;
- for ( SPObject *iter = this ; iter ; iter = SP_OBJECT_PARENT(iter) ) {
+ for ( SPObject *iter = this ; iter ; iter = iter->parent ) {
iter->_total_hrefcount += increment;
if ( iter->_total_hrefcount < iter->hrefcount ) {
g_critical("HRefs overcounted");
iter->_total_hrefcount += increment;
if ( iter->_total_hrefcount < iter->hrefcount ) {
g_critical("HRefs overcounted");
/**
* True if object is non-NULL and this is some in/direct parent of object.
*/
/**
* True if object is non-NULL and this is some in/direct parent of object.
*/
-bool
-SPObject::isAncestorOf(SPObject const *object) const {
+bool SPObject::isAncestorOf(SPObject const *object) const {
g_return_val_if_fail(object != NULL, false);
g_return_val_if_fail(object != NULL, false);
- object = SP_OBJECT_PARENT(object);
+ object = object->parent;
while (object) {
if ( object == this ) {
return true;
}
while (object) {
if ( object == this ) {
return true;
}
- object = SP_OBJECT_PARENT(object);
+ object = object->parent;
}
return false;
}
}
return false;
}
/**
* Returns youngest object being parent to this and object.
*/
/**
* Returns youngest object being parent to this and object.
*/
-SPObject const *
-SPObject::nearestCommonAncestor(SPObject const *object) const {
+SPObject const *SPObject::nearestCommonAncestor(SPObject const *object) const {
g_return_val_if_fail(object != NULL, NULL);
using Inkscape::Algorithms::longest_common_suffix;
g_return_val_if_fail(object != NULL, NULL);
using Inkscape::Algorithms::longest_common_suffix;
}
SPObject const *AncestorSon(SPObject const *obj, SPObject const *ancestor) {
}
SPObject const *AncestorSon(SPObject const *obj, SPObject const *ancestor) {
- if (obj == NULL || ancestor == NULL)
- return NULL;
- if (SP_OBJECT_PARENT(obj) == ancestor)
- return obj;
- return AncestorSon(SP_OBJECT_PARENT(obj), ancestor);
+ SPObject const *result = 0;
+ if ( obj && ancestor ) {
+ if (obj->parent == ancestor) {
+ result = obj;
+ } else {
+ result = AncestorSon(obj->parent, ancestor);
+ }
+ }
+ return result;
}
/**
}
/**
* 1 first object's position is greater than the second
* -1 first object's position is less than the second \endverbatim
*/
* 1 first object's position is greater than the second
* -1 first object's position is less than the second \endverbatim
*/
-int
-sp_object_compare_position(SPObject const *first, SPObject const *second)
+int sp_object_compare_position(SPObject const *first, SPObject const *second)
{
{
- if (first == second) return 0;
-
- SPObject const *ancestor = first->nearestCommonAncestor(second);
- if (ancestor == NULL) return 0; // cannot compare, no common ancestor!
-
- // we have an object and its ancestor (should not happen when sorting selection)
- if (ancestor == first)
- return 1;
- if (ancestor == second)
- return -1;
-
- SPObject const *to_first = AncestorSon(first, ancestor);
- SPObject const *to_second = AncestorSon(second, ancestor);
+ int result = 0;
+ if (first != second) {
+ SPObject const *ancestor = first->nearestCommonAncestor(second);
+ // Need a common ancestor to be able to compare
+ if ( ancestor ) {
+ // we have an object and its ancestor (should not happen when sorting selection)
+ if (ancestor == first) {
+ result = 1;
+ } else if (ancestor == second) {
+ result = -1;
+ } else {
+ SPObject const *to_first = AncestorSon(first, ancestor);
+ SPObject const *to_second = AncestorSon(second, ancestor);
- g_assert(SP_OBJECT_PARENT(to_second) == SP_OBJECT_PARENT(to_first));
+ g_assert(to_second->parent == to_first->parent);
- return sp_repr_compare_position(SP_OBJECT_REPR(to_first), SP_OBJECT_REPR(to_second));
+ result = sp_repr_compare_position(to_first->getRepr(), to_second->getRepr());
+ }
+ }
+ }
+ return result;
}
}
* Append repr as child of this object.
* \pre this is not a cloned object
*/
* Append repr as child of this object.
* \pre this is not a cloned object
*/
-SPObject *
-SPObject::appendChildRepr(Inkscape::XML::Node *repr) {
- if (!SP_OBJECT_IS_CLONED(this)) {
- SP_OBJECT_REPR(this)->appendChild(repr);
- return SP_OBJECT_DOCUMENT(this)->getObjectByRepr(repr);
+SPObject *SPObject::appendChildRepr(Inkscape::XML::Node *repr) {
+ if ( !cloned ) {
+ getRepr()->appendChild(repr);
+ return document->getObjectByRepr(repr);
} else {
g_critical("Attempt to append repr as child of cloned object");
return NULL;
}
}
} else {
g_critical("Attempt to append repr as child of cloned object");
return NULL;
}
}
-/**
- * Retrieves the children as a GSList object, optionally ref'ing the children
- * in the process, if add_ref is specified.
- */
+void SPObject::setCSS(SPCSSAttr *css, gchar const *attr)
+{
+ g_assert(this->getRepr() != NULL);
+ sp_repr_css_set(this->getRepr(), css, attr);
+}
+
+void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr)
+{
+ g_assert(this->getRepr() != NULL);
+ sp_repr_css_change(this->getRepr(), css, attr);
+}
+
GSList *SPObject::childList(bool add_ref, Action) {
GSList *l = NULL;
GSList *SPObject::childList(bool add_ref, Action) {
GSList *l = NULL;
- for (SPObject *child = this->first_child() ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
- if (add_ref)
+ for ( SPObject *child = firstChild() ; child; child = child->getNext() ) {
+ if (add_ref) {
g_object_ref (G_OBJECT (child));
g_object_ref (G_OBJECT (child));
+ }
l = g_slist_prepend (l, child);
}
l = g_slist_prepend (l, child);
}
/** Gets the label property for the object or a default if no label
* is defined.
*/
/** Gets the label property for the object or a default if no label
* is defined.
*/
-gchar const *
-SPObject::label() const {
+gchar const *SPObject::label() const {
return _label;
}
/** Returns a default label property for the object. */
return _label;
}
/** Returns a default label property for the object. */
-gchar const *
-SPObject::defaultLabel() const {
+gchar const *SPObject::defaultLabel() const {
if (_label) {
return _label;
} else {
if (!_default_label) {
if (_label) {
return _label;
} else {
if (!_default_label) {
- gchar const *id=SP_OBJECT_ID(this);
- if (id) {
- _default_label = g_strdup_printf("#%s", id);
+ if (getId()) {
+ _default_label = g_strdup_printf("#%s", getId());
} else {
} else {
- _default_label = g_strdup_printf("<%s>", SP_OBJECT_REPR(this)->name());
+ _default_label = g_strdup_printf("<%s>", getRepr()->name());
}
}
return _default_label;
}
}
return _default_label;
}
/** Sets the label property for the object */
}
/** Sets the label property for the object */
-void
-SPObject::setLabel(gchar const *label) {
- SP_OBJECT_REPR(this)->setAttribute("inkscape:label", label, false);
+void SPObject::setLabel(gchar const *label) {
+ getRepr()->setAttribute("inkscape:label", label, false);
}
/** Queues the object for orphan collection */
}
/** Queues the object for orphan collection */
-void
-SPObject::requestOrphanCollection() {
+void SPObject::requestOrphanCollection() {
g_return_if_fail(document != NULL);
// do not remove style or script elements (Bug #276244)
g_return_if_fail(document != NULL);
// do not remove style or script elements (Bug #276244)
- if (SP_IS_STYLE_ELEM(this))
- return;
- if (SP_IS_SCRIPT(this))
- return;
-
- document->queueForOrphanCollection(this);
+ if (SP_IS_STYLE_ELEM(this)) {
+ // leave it
+ } else if (SP_IS_SCRIPT(this)) {
+ // leave it
+ } else if (SP_IS_PAINT_SERVER(this) && static_cast<SPPaintServer*>(this)->isSwatch() ) {
+ // leave it
+ } else if (IS_COLORPROFILE(this)) {
+ // leave it
+ } else {
+ document->queueForOrphanCollection(this);
- /** \todo
- * This is a temporary hack added to make fill&stroke rebuild its
- * gradient list when the defs are vacuumed. gradient-vector.cpp
- * listens to the modified signal on defs, and now we give it that
- * signal. Mental says that this should be made automatic by
- * merging SPObjectGroup with SPObject; SPObjectGroup would issue
- * this signal automatically. Or maybe just derive SPDefs from
- * SPObjectGroup?
- */
+ /** \todo
+ * This is a temporary hack added to make fill&stroke rebuild its
+ * gradient list when the defs are vacuumed. gradient-vector.cpp
+ * listens to the modified signal on defs, and now we give it that
+ * signal. Mental says that this should be made automatic by
+ * merging SPObjectGroup with SPObject; SPObjectGroup would issue
+ * this signal automatically. Or maybe just derive SPDefs from
+ * SPObjectGroup?
+ */
- this->requestModified(SP_OBJECT_CHILD_MODIFIED_FLAG);
+ this->requestModified(SP_OBJECT_CHILD_MODIFIED_FLAG);
+ }
}
}
-/** Sends the delete signal to all children of this object recursively */
-void
-SPObject::_sendDeleteSignalRecursive() {
- for (SPObject *child = this->first_child(); child; child = SP_OBJECT_NEXT(child)) {
+void SPObject::_sendDeleteSignalRecursive() {
+ for (SPObject *child = firstChild(); child; child = child->getNext()) {
child->_delete_signal.emit(child);
child->_sendDeleteSignalRecursive();
}
child->_delete_signal.emit(child);
child->_sendDeleteSignalRecursive();
}
* signal. If the \a propagate_descendants parameter is true, it
* recursively sends the delete signal to children.
*/
* signal. If the \a propagate_descendants parameter is true, it
* recursively sends the delete signal to children.
*/
-void
-SPObject::deleteObject(bool propagate, bool propagate_descendants)
+void SPObject::deleteObject(bool propagate, bool propagate_descendants)
{
sp_object_ref(this, NULL);
if (propagate) {
{
sp_object_ref(this, NULL);
if (propagate) {
this->_sendDeleteSignalRecursive();
}
this->_sendDeleteSignalRecursive();
}
- Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
+ Inkscape::XML::Node *repr = getRepr();
if (repr && sp_repr_parent(repr)) {
sp_repr_unparent(repr);
}
if (repr && sp_repr_parent(repr)) {
sp_repr_unparent(repr);
}
* Put object into object tree, under parent, and behind prev;
* also update object's XML space.
*/
* Put object into object tree, under parent, and behind prev;
* also update object's XML space.
*/
-void
-SPObject::attach(SPObject *object, SPObject *prev)
+void SPObject::attach(SPObject *object, SPObject *prev)
{
//g_return_if_fail(parent != NULL);
//g_return_if_fail(SP_IS_OBJECT(parent));
{
//g_return_if_fail(parent != NULL);
//g_return_if_fail(SP_IS_OBJECT(parent));
/**
* In list of object's siblings, move object behind prev.
*/
/**
* In list of object's siblings, move object behind prev.
*/
-void
-SPObject::reorder(SPObject *prev) {
+void SPObject::reorder(SPObject *prev) {
//g_return_if_fail(object != NULL);
//g_return_if_fail(SP_IS_OBJECT(object));
g_return_if_fail(this->parent != NULL);
//g_return_if_fail(object != NULL);
//g_return_if_fail(SP_IS_OBJECT(object));
g_return_if_fail(this->parent != NULL);
/**
* Remove object from parent's children, release and unref it.
*/
/**
* Remove object from parent's children, release and unref it.
*/
-void
-SPObject::detach(SPObject *object) {
+void SPObject::detach(SPObject *object) {
//g_return_if_fail(parent != NULL);
//g_return_if_fail(SP_IS_OBJECT(parent));
g_return_if_fail(object != NULL);
//g_return_if_fail(parent != NULL);
//g_return_if_fail(SP_IS_OBJECT(parent));
g_return_if_fail(object != NULL);
this->children = next;
}
if (!next) {
this->children = next;
}
if (!next) {
- this->_last_child = prev;
+ this->_last_child = prev;
}
object->next = NULL;
}
object->next = NULL;
/**
* Return object's child whose node pointer equals repr.
*/
/**
* Return object's child whose node pointer equals repr.
*/
-SPObject *
-SPObject::get_child_by_repr(Inkscape::XML::Node *repr)
+SPObject *SPObject::get_child_by_repr(Inkscape::XML::Node *repr)
{
{
- //g_return_val_if_fail(object != NULL, NULL);
- //g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
g_return_val_if_fail(repr != NULL, NULL);
g_return_val_if_fail(repr != NULL, NULL);
+ SPObject *result = 0;
- if (this->_last_child && SP_OBJECT_REPR(this->_last_child) == repr)
- return this->_last_child; // optimization for common scenario
- for ( SPObject *child = this->children ; child ; child = child->next ) {
- if ( SP_OBJECT_REPR(child) == repr ) {
- return child;
+ if ( _last_child && (_last_child->getRepr() == repr) ) {
+ result = _last_child; // optimization for common scenario
+ } else {
+ for ( SPObject *child = children ; child ; child = child->next ) {
+ if ( child->getRepr() == repr ) {
+ result = child;
+ break;
+ }
}
}
}
}
-
- return NULL;
+ return result;
}
/**
* Callback for child_added event.
* Invoked whenever the given mutation event happens in the XML tree.
*/
}
/**
* Callback for child_added event.
* Invoked whenever the given mutation event happens in the XML tree.
*/
-void
-SPObject::sp_object_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
+void SPObject::sp_object_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
{
GType type = sp_repr_type_lookup(child);
if (!type) {
{
GType type = sp_repr_type_lookup(child);
if (!type) {
@@ -768,7 +738,7 @@ SPObject::sp_object_child_added(SPObject *object, Inkscape::XML::Node *child, In
object->attach(ochild, prev);
sp_object_unref(ochild, NULL);
object->attach(ochild, prev);
sp_object_unref(ochild, NULL);
- ochild->invoke_build(object->document, child, SP_OBJECT_IS_CLONED(object));
+ ochild->invoke_build(object->document, child, object->cloned);
}
/**
}
/**
* tree, BEFORE removal from the XML tree happens, so grouping
* objects can safely release the child data.
*/
* tree, BEFORE removal from the XML tree happens, so grouping
* objects can safely release the child data.
*/
-void
-SPObject::sp_object_remove_child(SPObject *object, Inkscape::XML::Node *child)
+void SPObject::sp_object_remove_child(SPObject *object, Inkscape::XML::Node *child)
{
debug("id=%x, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object));
SPObject *ochild = object->get_child_by_repr(child);
g_return_if_fail (ochild != NULL || !strcmp("comment", child->name())); // comments have no objects
{
debug("id=%x, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object));
SPObject *ochild = object->get_child_by_repr(child);
g_return_if_fail (ochild != NULL || !strcmp("comment", child->name())); // comments have no objects
- if (ochild)
+ if (ochild) {
object->detach(ochild);
object->detach(ochild);
+ }
}
/**
}
/**
@@ -835,8 +805,7 @@ void SPObject::sp_object_order_changed(SPObject *object, Inkscape::XML::Node *ch
* SPDocument does after the creation of the XML tree).
* \see sp_object_release()
*/
* SPDocument does after the creation of the XML tree).
* \see sp_object_release()
*/
-void
-SPObject::sp_object_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
+void SPObject::sp_object_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
{
/* Nothing specific here */
debug("id=%x, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object));
{
/* Nothing specific here */
debug("id=%x, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object));
@@ -853,7 +822,7 @@ SPObject::sp_object_build(SPObject *object, SPDocument *document, Inkscape::XML:
SPObject *child = SP_OBJECT(g_object_new(type, 0));
object->attach(child, object->lastChild());
sp_object_unref(child, NULL);
SPObject *child = SP_OBJECT(g_object_new(type, 0));
object->attach(child, object->lastChild());
sp_object_unref(child, NULL);
- child->invoke_build(document, rchild, SP_OBJECT_IS_CLONED(object));
+ child->invoke_build(document, rchild, object->cloned);
}
}
}
}
@@ -874,11 +843,12 @@ void SPObject::invoke_build(SPDocument *document, Inkscape::XML::Node *repr, uns
this->document = document;
this->repr = repr;
this->document = document;
this->repr = repr;
- if (!cloned)
+ if (!cloned) {
Inkscape::GC::anchor(repr);
Inkscape::GC::anchor(repr);
+ }
this->cloned = cloned;
this->cloned = cloned;
- if (!SP_OBJECT_IS_CLONED(this)) {
+ if ( !cloned ) {
this->document->bindObjectToRepr(this->repr, this);
if (Inkscape::XML::id_permitted(this->repr)) {
this->document->bindObjectToRepr(this->repr, this);
if (Inkscape::XML::id_permitted(this->repr)) {
@@ -922,19 +892,26 @@ void SPObject::invoke_build(SPDocument *document, Inkscape::XML::Node *repr, uns
long long int SPObject::getIntAttribute(char const *key, long long int def)
{
long long int SPObject::getIntAttribute(char const *key, long long int def)
{
- return sp_repr_get_int_attribute(getRepr(),key,def);
+ return sp_repr_get_int_attribute(getRepr(),key,def);
}
unsigned SPObject::getPosition(){
}
unsigned SPObject::getPosition(){
- g_assert(this->repr);
+ g_assert(this->repr);
- return repr->position();
+ return repr->position();
}
void SPObject::appendChild(Inkscape::XML::Node *child) {
}
void SPObject::appendChild(Inkscape::XML::Node *child) {
- g_assert(this->repr);
+ g_assert(this->repr);
- repr->appendChild(child);
+ repr->appendChild(child);
+}
+
+void SPObject::addChild(Inkscape::XML::Node *child, Inkscape::XML::Node * prev)
+{
+ g_assert(this->repr);
+
+ repr->addChild(child,prev);
}
void SPObject::releaseReferences() {
}
void SPObject::releaseReferences() {
/* all hrefs should be released by the "release" handlers */
g_assert(this->hrefcount == 0);
/* all hrefs should be released by the "release" handlers */
g_assert(this->hrefcount == 0);
- if (!SP_OBJECT_IS_CLONED(this)) {
+ if (!cloned) {
if (this->id) {
this->document->bindObjectToId(this->id, NULL);
}
if (this->id) {
this->document->bindObjectToId(this->id, NULL);
}
}
}
-SPObject *SPObject::getNext()
-{
- return next;
-}
-
SPObject *SPObject::getPrev()
{
SPObject *SPObject::getPrev()
{
- return this->prev();
+ SPObject *prev = 0;
+ for ( SPObject *obj = parent->firstChild(); obj && !prev; obj = obj->getNext() ) {
+ if (obj->getNext() == this) {
+ prev = obj;
+ }
+ }
+ return prev;
}
/**
* Callback for child_added node event.
*/
}
/**
* Callback for child_added node event.
*/
-void
-SPObject::sp_object_repr_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data)
+void SPObject::sp_object_repr_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data)
{
SPObject *object = SP_OBJECT(data);
{
SPObject *object = SP_OBJECT(data);
- if (((SPObjectClass *) G_OBJECT_GET_CLASS(object))->child_added)
+ if (((SPObjectClass *) G_OBJECT_GET_CLASS(object))->child_added) {
(*((SPObjectClass *)G_OBJECT_GET_CLASS(object))->child_added)(object, child, ref);
(*((SPObjectClass *)G_OBJECT_GET_CLASS(object))->child_added)(object, child, ref);
+ }
}
/**
* Callback for remove_child node event.
*/
}
/**
* Callback for remove_child node event.
*/
-void
-SPObject::sp_object_repr_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, Inkscape::XML::Node */*ref*/, gpointer data)
+void SPObject::sp_object_repr_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, Inkscape::XML::Node */*ref*/, gpointer data)
{
SPObject *object = SP_OBJECT(data);
{
SPObject *object = SP_OBJECT(data);
@@ -1018,8 +995,7 @@ SPObject::sp_object_repr_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::
*
* \todo fixme:
*/
*
* \todo fixme:
*/
-void
-SPObject::sp_object_repr_order_changed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, Inkscape::XML::Node *old, Inkscape::XML::Node *newer, gpointer data)
+void SPObject::sp_object_repr_order_changed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, Inkscape::XML::Node *old, Inkscape::XML::Node *newer, gpointer data)
{
SPObject *object = SP_OBJECT(data);
{
SPObject *object = SP_OBJECT(data);
@@ -1031,16 +1007,15 @@ SPObject::sp_object_repr_order_changed(Inkscape::XML::Node */*repr*/, Inkscape::
/**
* Callback for set event.
*/
/**
* Callback for set event.
*/
-void
-SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar const *value)
+void SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar const *value)
{
g_assert(key != SP_ATTR_INVALID);
switch (key) {
case SP_ATTR_ID:
{
g_assert(key != SP_ATTR_INVALID);
switch (key) {
case SP_ATTR_ID:
- //XML Tree being used here.
- if ( !SP_OBJECT_IS_CLONED(object) && object->getRepr()->type() == Inkscape::XML::ELEMENT_NODE ) {
+ //XML Tree being used here.
+ if ( !object->cloned && object->getRepr()->type() == Inkscape::XML::ELEMENT_NODE ) {
SPDocument *document=object->document;
SPObject *conflict=NULL;
SPDocument *document=object->document;
SPObject *conflict=NULL;
@@ -1055,7 +1030,7 @@ SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar const
sp_object_ref(conflict, NULL);
// give the conflicting object a new ID
gchar *new_conflict_id = sp_object_get_unique_id(conflict, NULL);
sp_object_ref(conflict, NULL);
// give the conflicting object a new ID
gchar *new_conflict_id = sp_object_get_unique_id(conflict, NULL);
- SP_OBJECT_REPR(conflict)->setAttribute("id", new_conflict_id);
+ conflict->getRepr()->setAttribute("id", new_conflict_id);
g_free(new_conflict_id);
sp_object_unref(conflict, NULL);
} else {
g_free(new_conflict_id);
sp_object_unref(conflict, NULL);
} else {
@@ -1120,8 +1095,7 @@ SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar const
/**
* Call virtual set() function of object.
*/
/**
* Call virtual set() function of object.
*/
-void
-SPObject::setKeyValue(unsigned int key, gchar const *value)
+void SPObject::setKeyValue(unsigned int key, gchar const *value)
{
//g_assert(object != NULL);
//g_assert(SP_IS_OBJECT(object));
{
//g_assert(object != NULL);
//g_assert(SP_IS_OBJECT(object));
/**
* Read value of key attribute from XML node into object.
*/
/**
* Read value of key attribute from XML node into object.
*/
-void
-SPObject::readAttr(gchar const *key)
+void SPObject::readAttr(gchar const *key)
{
//g_assert(object != NULL);
//g_assert(SP_IS_OBJECT(object));
g_assert(key != NULL);
{
//g_assert(object != NULL);
//g_assert(SP_IS_OBJECT(object));
g_assert(key != NULL);
- //XML Tree being used here.
+ //XML Tree being used here.
g_assert(this->getRepr() != NULL);
unsigned int keyid = sp_attribute_lookup(key);
g_assert(this->getRepr() != NULL);
unsigned int keyid = sp_attribute_lookup(key);
/**
* Callback for attr_changed node event.
*/
/**
* Callback for attr_changed node event.
*/
-void
-SPObject::sp_object_repr_attr_changed(Inkscape::XML::Node */*repr*/, gchar const *key, gchar const */*oldval*/, gchar const */*newval*/, bool is_interactive, gpointer data)
+void SPObject::sp_object_repr_attr_changed(Inkscape::XML::Node */*repr*/, gchar const *key, gchar const */*oldval*/, gchar const */*newval*/, bool is_interactive, gpointer data)
{
SPObject *object = SP_OBJECT(data);
{
SPObject *object = SP_OBJECT(data);
@@ -1173,13 +1145,13 @@ SPObject::sp_object_repr_attr_changed(Inkscape::XML::Node */*repr*/, gchar const
/**
* Callback for content_changed node event.
*/
/**
* Callback for content_changed node event.
*/
-void
-SPObject::sp_object_repr_content_changed(Inkscape::XML::Node */*repr*/, gchar const */*oldcontent*/, gchar const */*newcontent*/, gpointer data)
+void SPObject::sp_object_repr_content_changed(Inkscape::XML::Node */*repr*/, gchar const */*oldcontent*/, gchar const */*newcontent*/, gpointer data)
{
SPObject *object = SP_OBJECT(data);
{
SPObject *object = SP_OBJECT(data);
- if (((SPObjectClass *) G_OBJECT_GET_CLASS(object))->read_content)
+ if (((SPObjectClass *) G_OBJECT_GET_CLASS(object))->read_content) {
(*((SPObjectClass *) G_OBJECT_GET_CLASS(object))->read_content)(object);
(*((SPObjectClass *) G_OBJECT_GET_CLASS(object))->read_content)(object);
+ }
}
/**
}
/**
/**
* Callback for write event.
*/
/**
* Callback for write event.
*/
-Inkscape::XML::Node *
-SPObject::sp_object_private_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
+Inkscape::XML::Node * SPObject::sp_object_private_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
{
if (!repr && (flags & SP_OBJECT_WRITE_BUILD)) {
{
if (!repr && (flags & SP_OBJECT_WRITE_BUILD)) {
- repr = SP_OBJECT_REPR(object)->duplicate(doc);
+ repr = object->getRepr()->duplicate(doc);
if (!( flags & SP_OBJECT_WRITE_EXT )) {
repr->setAttribute("inkscape:collect", NULL);
}
if (!( flags & SP_OBJECT_WRITE_EXT )) {
repr->setAttribute("inkscape:collect", NULL);
}
@@ -1226,7 +1197,7 @@ SPObject::sp_object_private_write(SPObject *object, Inkscape::XML::Document *doc
repr->setAttribute("inkscape:collect", NULL);
}
repr->setAttribute("inkscape:collect", NULL);
}
- SPStyle const *const obj_style = SP_OBJECT_STYLE(object);
+ SPStyle const *const obj_style = object->style;
if (obj_style) {
gchar *s = sp_style_write_string(obj_style, SP_STYLE_FLAG_IFSET);
repr->setAttribute("style", ( *s ? s : NULL ));
if (obj_style) {
gchar *s = sp_style_write_string(obj_style, SP_STYLE_FLAG_IFSET);
repr->setAttribute("style", ( *s ? s : NULL ));
@@ -1265,10 +1236,9 @@ SPObject::sp_object_private_write(SPObject *object, Inkscape::XML::Document *doc
/**
* Update this object's XML node with flags value.
*/
/**
* Update this object's XML node with flags value.
*/
-Inkscape::XML::Node *
-SPObject::updateRepr(unsigned int flags) {
- if (!SP_OBJECT_IS_CLONED(this)) {
- Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
+Inkscape::XML::Node * SPObject::updateRepr(unsigned int flags) {
+ if ( !cloned ) {
+ Inkscape::XML::Node *repr = getRepr();
if (repr) {
return updateRepr(repr->document(), repr, flags);
} else {
if (repr) {
return updateRepr(repr->document(), repr, flags);
} else {
* reprs in another document (e.g. a temporary document used when
* saving as "Plain SVG"
*/
* reprs in another document (e.g. a temporary document used when
* saving as "Plain SVG"
*/
-Inkscape::XML::Node *
-SPObject::updateRepr(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) {
+Inkscape::XML::Node * SPObject::updateRepr(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) {
g_assert(doc != NULL);
g_assert(doc != NULL);
- if (SP_OBJECT_IS_CLONED(this)) {
+ if (cloned) {
/* cloned objects have no repr */
return NULL;
}
if (((SPObjectClass *) G_OBJECT_GET_CLASS(this))->write) {
if (!(flags & SP_OBJECT_WRITE_BUILD) && !repr) {
/* cloned objects have no repr */
return NULL;
}
if (((SPObjectClass *) G_OBJECT_GET_CLASS(this))->write) {
if (!(flags & SP_OBJECT_WRITE_BUILD) && !repr) {
- repr = SP_OBJECT_REPR(this);
+ repr = getRepr();
}
return ((SPObjectClass *) G_OBJECT_GET_CLASS(this))->write(this, doc, repr, flags);
} else {
g_warning("Class %s does not implement ::write", G_OBJECT_TYPE_NAME(this));
if (!repr) {
if (flags & SP_OBJECT_WRITE_BUILD) {
}
return ((SPObjectClass *) G_OBJECT_GET_CLASS(this))->write(this, doc, repr, flags);
} else {
g_warning("Class %s does not implement ::write", G_OBJECT_TYPE_NAME(this));
if (!repr) {
if (flags & SP_OBJECT_WRITE_BUILD) {
- repr = SP_OBJECT_REPR(this)->duplicate(doc);
+ repr = getRepr()->duplicate(doc);
}
/// \todo FIXME: else probably error (Lauris) */
} else {
}
/// \todo FIXME: else probably error (Lauris) */
} else {
- repr->mergeFrom(SP_OBJECT_REPR(this), "id");
+ repr->mergeFrom(getRepr(), "id");
}
return repr;
}
}
return repr;
}
@@ -1319,8 +1288,7 @@ SPObject::updateRepr(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, un
* recursively add CHILD_MODIFIED flag to
* parent and ancestors (as far up as necessary).
*/
* recursively add CHILD_MODIFIED flag to
* parent and ancestors (as far up as necessary).
*/
-void
-SPObject::requestDisplayUpdate(unsigned int flags)
+void SPObject::requestDisplayUpdate(unsigned int flags)
{
g_return_if_fail( this->document != NULL );
{
g_return_if_fail( this->document != NULL );
* don't need to set CHILD_MODIFIED on our ancestors because it's already been done.
*/
if (already_propagated) {
* don't need to set CHILD_MODIFIED on our ancestors because it's already been done.
*/
if (already_propagated) {
- SPObject *parent = SP_OBJECT_PARENT(this);
if (parent) {
parent->requestDisplayUpdate(SP_OBJECT_CHILD_MODIFIED_FLAG);
} else {
if (parent) {
parent->requestDisplayUpdate(SP_OBJECT_CHILD_MODIFIED_FLAG);
} else {
- SP_OBJECT_DOCUMENT(this)->request_modified();
+ document->requestModified();
}
}
}
}
}
}
/**
* Update views
*/
/**
* Update views
*/
-void
-SPObject::updateDisplay(SPCtx *ctx, unsigned int flags)
+void SPObject::updateDisplay(SPCtx *ctx, unsigned int flags)
{
g_return_if_fail(!(flags & ~SP_OBJECT_MODIFIED_CASCADE));
update_in_progress ++;
#ifdef SP_OBJECT_DEBUG_CASCADE
{
g_return_if_fail(!(flags & ~SP_OBJECT_MODIFIED_CASCADE));
update_in_progress ++;
#ifdef SP_OBJECT_DEBUG_CASCADE
- g_print("Update %s:%s %x %x %x\n", g_type_name_from_instance((GTypeInstance *) this), SP_OBJECT_ID(this), flags, this->uflags, this->mflags);
+ g_print("Update %s:%s %x %x %x\n", g_type_name_from_instance((GTypeInstance *) this), getId(), flags, this->uflags, this->mflags);
#endif
/* Get this flags */
#endif
/* Get this flags */
try
{
try
{
- if (((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update)
+ if (((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update) {
((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update(this, ctx, flags);
((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update(this, ctx, flags);
+ }
}
catch(...)
{
}
catch(...)
{
* request display update, which trickles down and relies on the
* flags set during this pass...
*/
* request display update, which trickles down and relies on the
* flags set during this pass...
*/
-void
-SPObject::requestModified(unsigned int flags)
+void SPObject::requestModified(unsigned int flags)
{
g_return_if_fail( this->document != NULL );
{
g_return_if_fail( this->document != NULL );
* don't need to set CHILD_MODIFIED on our ancestors because it's already been done.
*/
if (already_propagated) {
* don't need to set CHILD_MODIFIED on our ancestors because it's already been done.
*/
if (already_propagated) {
- SPObject *parent=SP_OBJECT_PARENT(this);
if (parent) {
parent->requestModified(SP_OBJECT_CHILD_MODIFIED_FLAG);
} else {
if (parent) {
parent->requestModified(SP_OBJECT_CHILD_MODIFIED_FLAG);
} else {
- SP_OBJECT_DOCUMENT(this)->request_modified();
+ document->requestModified();
}
}
}
}
}
}
* later delivery here. Once emitModified() is called, those flags don't
* need to be stored any longer.
*/
* later delivery here. Once emitModified() is called, those flags don't
* need to be stored any longer.
*/
-void
-SPObject::emitModified(unsigned int flags)
+void SPObject::emitModified(unsigned int flags)
{
/* only the MODIFIED_CASCADE flag is legal here */
g_return_if_fail(!(flags & ~SP_OBJECT_MODIFIED_CASCADE));
#ifdef SP_OBJECT_DEBUG_CASCADE
{
/* only the MODIFIED_CASCADE flag is legal here */
g_return_if_fail(!(flags & ~SP_OBJECT_MODIFIED_CASCADE));
#ifdef SP_OBJECT_DEBUG_CASCADE
- g_print("Modified %s:%s %x %x %x\n", g_type_name_from_instance((GTypeInstance *) this), SP_OBJECT_ID(this), flags, this->uflags, this->mflags);
+ g_print("Modified %s:%s %x %x %x\n", g_type_name_from_instance((GTypeInstance *) this), getId(), flags, this->uflags, this->mflags);
#endif
flags |= this->mflags;
#endif
flags |= this->mflags;
g_object_unref(G_OBJECT(this));
}
g_object_unref(G_OBJECT(this));
}
-gchar const *
-SPObject::getTagName(SPException *ex) const
+gchar const *SPObject::getTagName(SPException *ex) const
{
{
- g_assert(repr != NULL);
+ g_assert(repr != NULL);
/* If exception is not clear, return */
if (!SP_EXCEPTION_IS_OK(ex)) {
return NULL;
}
/// \todo fixme: Exception if object is NULL? */
/* If exception is not clear, return */
if (!SP_EXCEPTION_IS_OK(ex)) {
return NULL;
}
/// \todo fixme: Exception if object is NULL? */
- //XML Tree being used here.
+ //XML Tree being used here.
return getRepr()->name();
}
return getRepr()->name();
}
-gchar const *
-SPObject::getAttribute(gchar const *key, SPException *ex) const
+gchar const *SPObject::getAttribute(gchar const *key, SPException *ex) const
{
{
- g_assert(this->repr != NULL);
+ g_assert(this->repr != NULL);
/* If exception is not clear, return */
if (!SP_EXCEPTION_IS_OK(ex)) {
return NULL;
}
/// \todo fixme: Exception if object is NULL? */
/* If exception is not clear, return */
if (!SP_EXCEPTION_IS_OK(ex)) {
return NULL;
}
/// \todo fixme: Exception if object is NULL? */
- //XML Tree being used here.
+ //XML Tree being used here.
return (gchar const *) getRepr()->attribute(key);
}
return (gchar const *) getRepr()->attribute(key);
}
-void
-SPObject::setAttribute(gchar const *key, gchar const *value, SPException *ex)
+void SPObject::setAttribute(gchar const *key, gchar const *value, SPException *ex)
{
{
- g_assert(this->repr != NULL);
+ g_assert(this->repr != NULL);
/* If exception is not clear, return */
g_return_if_fail(SP_EXCEPTION_IS_OK(ex));
/// \todo fixme: Exception if object is NULL? */
/* If exception is not clear, return */
g_return_if_fail(SP_EXCEPTION_IS_OK(ex));
/// \todo fixme: Exception if object is NULL? */
- //XML Tree being used here.
+ //XML Tree being used here.
getRepr()->setAttribute(key, value, false);
}
getRepr()->setAttribute(key, value, false);
}
-void
-SPObject::removeAttribute(gchar const *key, SPException *ex)
+void SPObject::removeAttribute(gchar const *key, SPException *ex)
{
/* If exception is not clear, return */
g_return_if_fail(SP_EXCEPTION_IS_OK(ex));
/// \todo fixme: Exception if object is NULL? */
{
/* If exception is not clear, return */
g_return_if_fail(SP_EXCEPTION_IS_OK(ex));
/// \todo fixme: Exception if object is NULL? */
- //XML Tree being used here.
+ //XML Tree being used here.
getRepr()->setAttribute(key, NULL, false);
}
getRepr()->setAttribute(key, NULL, false);
}
+bool SPObject::storeAsDouble( gchar const *key, double *val ) const
+{
+ g_assert(this->getRepr()!= NULL);
+ return sp_repr_get_double(((Inkscape::XML::Node *)(this->getRepr())),key,val);
+}
+
/* Helper */
/* Helper */
-gchar *
-SPObject::sp_object_get_unique_id(SPObject *object, gchar const *id)
+gchar * SPObject::sp_object_get_unique_id(SPObject *object, gchar const *id)
{
static unsigned long count = 0;
{
static unsigned long count = 0;
count++;
count++;
- //XML Tree being used here.
+ //XML Tree being used here.
gchar const *name = object->getRepr()->name();
g_assert(name != NULL);
gchar const *name = object->getRepr()->name();
g_assert(name != NULL);
* <use> element instead), we should probably make the caller
* responsible for ascending the repr tree as necessary.
*/
* <use> element instead), we should probably make the caller
* responsible for ascending the repr tree as necessary.
*/
-gchar const *
-SPObject::getStyleProperty(gchar const *key, gchar const *def) const
+gchar const * SPObject::getStyleProperty(gchar const *key, gchar const *def) const
{
//g_return_val_if_fail(object != NULL, NULL);
//g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
g_return_val_if_fail(key != NULL, NULL);
{
//g_return_val_if_fail(object != NULL, NULL);
//g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
g_return_val_if_fail(key != NULL, NULL);
- //XML Tree being used here.
+ //XML Tree being used here.
gchar const *style = getRepr()->attribute("style");
if (style) {
size_t const len = strlen(key);
gchar const *style = getRepr()->attribute("style");
if (style) {
size_t const len = strlen(key);
!= NULL )
{
p += len;
!= NULL )
{
p += len;
- while ((*p <= ' ') && *p) p++;
- if (*p++ != ':') break;
- while ((*p <= ' ') && *p) p++;
+ while ((*p <= ' ') && *p) {
+ p++;
+ }
+ if (*p++ != ':') {
+ break;
+ }
+ while ((*p <= ' ') && *p) {
+ p++;
+ }
size_t const inherit_len = sizeof("inherit") - 1;
if (*p
&& !(strneq(p, "inherit", inherit_len)
size_t const inherit_len = sizeof("inherit") - 1;
if (*p
&& !(strneq(p, "inherit", inherit_len)
}
}
}
}
- //XML Tree being used here.
+ //XML Tree being used here.
gchar const *val = getRepr()->attribute(key);
if (val && !streq(val, "inherit")) {
return val;
gchar const *val = getRepr()->attribute(key);
if (val && !streq(val, "inherit")) {
return val;
/**
* Lifts SVG version of all root objects to version.
*/
/**
* Lifts SVG version of all root objects to version.
*/
-void
-SPObject::_requireSVGVersion(Inkscape::Version version) {
+void SPObject::_requireSVGVersion(Inkscape::Version version) {
for ( SPObject::ParentIterator iter=this ; iter ; ++iter ) {
SPObject *object=iter;
if (SP_IS_ROOT(object)) {
for ( SPObject::ParentIterator iter=this ; iter ; ++iter ) {
SPObject *object=iter;
if (SP_IS_ROOT(object)) {
}
}
}
}
-/**
- * Returns previous object in sibling list or NULL.
- */
-SPObject *
-SPObject::prev()
-{
- SPObject *parent = SP_OBJECT_PARENT(this);
- for ( SPObject *i = parent->first_child(); i; i = SP_OBJECT_NEXT(i) ) {
- if (SP_OBJECT_NEXT(i) == this)
- return i;
- }
- return NULL;
-}
-
/* Titles and descriptions */
/* Note:
/* Titles and descriptions */
/* Note:
* The caller must free the returned string using g_free() - see comment
* for getTitleOrDesc() below.
*/
* The caller must free the returned string using g_free() - see comment
* for getTitleOrDesc() below.
*/
-gchar *
-SPObject::title() const
+gchar * SPObject::title() const
{
return getTitleOrDesc("svg:title");
}
{
return getTitleOrDesc("svg:title");
}
* (if any) should be deleted.
* The second argument is optional - see setTitleOrDesc() below for details.
*/
* (if any) should be deleted.
* The second argument is optional - see setTitleOrDesc() below for details.
*/
-bool
-SPObject::setTitle(gchar const *title, bool verbatim)
+bool SPObject::setTitle(gchar const *title, bool verbatim)
{
return setTitleOrDesc(title, "svg:title", verbatim);
}
{
return setTitleOrDesc(title, "svg:title", verbatim);
}
* The caller must free the returned string using g_free() - see comment
* for getTitleOrDesc() below.
*/
* The caller must free the returned string using g_free() - see comment
* for getTitleOrDesc() below.
*/
-gchar *
-SPObject::desc() const
+gchar * SPObject::desc() const
{
return getTitleOrDesc("svg:desc");
}
{
return getTitleOrDesc("svg:desc");
}
* description (if any) should be deleted.
* The second argument is optional - see setTitleOrDesc() below for details.
*/
* description (if any) should be deleted.
* The second argument is optional - see setTitleOrDesc() below for details.
*/
-bool
-SPObject::setDesc(gchar const *desc, bool verbatim)
+bool SPObject::setDesc(gchar const *desc, bool verbatim)
{
return setTitleOrDesc(desc, "svg:desc", verbatim);
}
{
return setTitleOrDesc(desc, "svg:desc", verbatim);
}
* Consequently, the return value is a newly allocated string (or NULL), and
* must be freed (using g_free()) by the caller.
*/
* Consequently, the return value is a newly allocated string (or NULL), and
* must be freed (using g_free()) by the caller.
*/
-gchar *
-SPObject::getTitleOrDesc(gchar const *svg_tagname) const
+gchar * SPObject::getTitleOrDesc(gchar const *svg_tagname) const
{
{
+ gchar *result = 0;
SPObject *elem = findFirstChild(svg_tagname);
SPObject *elem = findFirstChild(svg_tagname);
- if (elem == NULL) return NULL;
- return g_string_free(elem->textualContent(), FALSE);
+ if ( elem ) {
+ result = g_string_free(elem->textualContent(), FALSE);
+ }
+ return result;
}
/**
}
/**
* The return value is true if a change was made to the title/description,
* and usually false otherwise.
*/
* The return value is true if a change was made to the title/description,
* and usually false otherwise.
*/
-bool
-SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verbatim)
+bool SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verbatim)
{
if (!verbatim) {
// If the new title/description is just whitespace,
{
if (!verbatim) {
// If the new title/description is just whitespace,
@@ -1765,7 +1717,9 @@ SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verb
break;
}
}
break;
}
}
- if (just_whitespace) value = NULL;
+ if (just_whitespace) {
+ value = NULL;
+ }
}
// Don't stomp on mark-up if there is no real change.
if (value) {
}
// Don't stomp on mark-up if there is no real change.
if (value) {
@@ -1773,7 +1727,9 @@ SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verb
if (current_value) {
bool different = std::strcmp(current_value, value);
g_free(current_value);
if (current_value) {
bool different = std::strcmp(current_value, value);
g_free(current_value);
- if (!different) return false;
+ if (!different) {
+ return false;
+ }
}
}
}
}
}
}
@@ -1781,7 +1737,9 @@ SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verb
SPObject *elem = findFirstChild(svg_tagname);
if (value == NULL) {
SPObject *elem = findFirstChild(svg_tagname);
if (value == NULL) {
- if (elem == NULL) return false;
+ if (elem == NULL) {
+ return false;
+ }
// delete the title/description(s)
while (elem) {
elem->deleteObject();
// delete the title/description(s)
while (elem) {
elem->deleteObject();
@@ -1790,7 +1748,7 @@ SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verb
return true;
}
return true;
}
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
+ Inkscape::XML::Document *xml_doc = document->getReprDoc();
if (elem == NULL) {
// create a new 'title' or 'desc' element, putting it at the
if (elem == NULL) {
// create a new 'title' or 'desc' element, putting it at the
@@ -1815,13 +1773,14 @@ SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verb
* Find the first child of this object with a given tag name,
* and return it. Returns NULL if there is no matching child.
*/
* Find the first child of this object with a given tag name,
* and return it. Returns NULL if there is no matching child.
*/
-SPObject *
-SPObject::findFirstChild(gchar const *tagname) const
+SPObject * SPObject::findFirstChild(gchar const *tagname) const
{
for (SPObject *child = children; child; child = child->next)
{
if (child->repr->type() == Inkscape::XML::ELEMENT_NODE &&
{
for (SPObject *child = children; child; child = child->next)
{
if (child->repr->type() == Inkscape::XML::ELEMENT_NODE &&
- !strcmp(child->repr->name(), tagname)) return child;
+ !strcmp(child->repr->name(), tagname)) {
+ return child;
+ }
}
return NULL;
}
}
return NULL;
}
* content except the tags).
* Must not be used on anything except elements.
*/
* content except the tags).
* Must not be used on anything except elements.
*/
-GString*
-SPObject::textualContent() const
+GString * SPObject::textualContent() const
{
GString* text = g_string_new("");
{
GString* text = g_string_new("");
fill-column:99
End:
*/
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 :