Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / sp-item.cpp
index fc605516d51ce3be39976d8788373881434ebb86..755ee0bf40211c2df9cffd0f382776bef83a3a5d 100644 (file)
@@ -6,6 +6,8 @@
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Abhishek Sharma
+ *   Jon A. Cruz <jon@joncruz.org>
  *
  * Copyright (C) 2001-2006 authors
  * Copyright (C) 2001 Ximian, Inc.
@@ -46,6 +48,7 @@
 #include "sp-text.h"
 #include "sp-item-rm-unsatisfied-cns.h"
 #include "sp-pattern.h"
+#include "sp-paint-server.h"
 #include "sp-switch.h"
 #include "sp-guide-constraint.h"
 #include "gradient-chemistry.h"
 
 #define noSP_ITEM_DEBUG_IDLE
 
-//static void sp_item_class_init(SPItemClass *klass);
-//static void sp_item_init(SPItem *item);
-
-//static void sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
-//static void sp_item_release(SPObject *object);
-//static void sp_item_set(SPObject *object, unsigned key, gchar const *value);
-//static void sp_item_update(SPObject *object, SPCtx *ctx, guint flags);
-//static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
-
-//static gchar *sp_item_private_description(SPItem *item);
-//static void sp_item_private_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
-
-//static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
-//static SPItemView *sp_item_view_list_remove(SPItemView *list, SPItemView *view);
-
-//static SPObjectClass *parent_class;
-
-//static void clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item);
-//static void mask_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item);
-
 SPObjectClass * SPItemClass::static_parent_class=0;
 
 /**
@@ -148,40 +131,39 @@ SPItemClass::sp_item_class_init(SPItemClass *klass)
 /**
  * Callback for SPItem object initialization.
  */
-void
-SPItem::sp_item_init(SPItem *item)
+void SPItem::sp_item_init(SPItem *item)
 {
     item->init();
 }
 
 void SPItem::init() {
-    this->sensitive = TRUE;
+    sensitive = TRUE;
 
-    this->transform_center_x = 0;
-    this->transform_center_y = 0;
+    transform_center_x = 0;
+    transform_center_y = 0;
 
-    this->_is_evaluated = true;
-    this->_evaluated_status = StatusUnknown;
+    _is_evaluated = true;
+    _evaluated_status = StatusUnknown;
 
-    this->transform = Geom::identity();
+    transform = Geom::identity();
 
-    this->display = NULL;
+    display = NULL;
 
-    this->clip_ref = new SPClipPathReference(this);
-    sigc::signal<void, SPObject *, SPObject *> cs1=this->clip_ref->changedSignal();
-    sigc::slot2<void,SPObject*, SPObject *> sl1=sigc::bind(sigc::ptr_fun(clip_ref_changed), this);
+    clip_ref = new SPClipPathReference(this);
+    sigc::signal<void, SPObject *, SPObject *> cs1 = clip_ref->changedSignal();
+    sigc::slot2<void,SPObject*, SPObject *> sl1 = sigc::bind(sigc::ptr_fun(clip_ref_changed), this);
     _clip_ref_connection = cs1.connect(sl1);
 
-    this->mask_ref = new SPMaskReference(this);
-    sigc::signal<void, SPObject *, SPObject *> cs2=this->mask_ref->changedSignal();
+    mask_ref = new SPMaskReference(this);
+    sigc::signal<void, SPObject *, SPObject *> cs2 = mask_ref->changedSignal();
     sigc::slot2<void,SPObject*, SPObject *> sl2=sigc::bind(sigc::ptr_fun(mask_ref_changed), this);
     _mask_ref_connection = cs2.connect(sl2);
 
-    this->avoidRef = new SPAvoidRef(this);
+    avoidRef = new SPAvoidRef(this);
 
-    new (&this->constraints) std::vector<SPGuideConstraint>();
+    new (&constraints) std::vector<SPGuideConstraint>();
 
-    new (&this->_transformed_signal) sigc::signal<void, Geom::Matrix const *, SPItem *>();
+    new (&_transformed_signal) sigc::signal<void, Geom::Matrix const *, SPItem *>();
 }
 
 bool SPItem::isVisibleAndUnlocked() const {
@@ -193,16 +175,17 @@ bool SPItem::isVisibleAndUnlocked(unsigned display_key) const {
 }
 
 bool SPItem::isLocked() const {
-    for (SPObject *o = SP_OBJECT(this); o != NULL; o = SP_OBJECT_PARENT(o)) {
-        if (SP_IS_ITEM(o) && !(SP_ITEM(o)->sensitive))
+    for (SPObject const *o = this; o != NULL; o = o->parent) {
+        if (SP_IS_ITEM(o) && !(SP_ITEM(o)->sensitive)) {
             return true;
+        }
     }
     return false;
 }
 
 void SPItem::setLocked(bool locked) {
-    SP_OBJECT_REPR(this)->setAttribute("sodipodi:insensitive",
-                     ( locked ? "1" : NULL ));
+    setAttribute("sodipodi:insensitive",
+                 ( locked ? "1" : NULL ));
     updateRepr();
 }
 
@@ -252,7 +235,6 @@ void SPItem::resetEvaluated() {
             requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
         }
     } if ( StatusSet == _evaluated_status ) {
-        SPObject const *const parent = SP_OBJECT_PARENT(this);
         if (SP_IS_SWITCH(parent)) {
             SP_SWITCH(parent)->resetChildEvaluated();
         }
@@ -271,32 +253,29 @@ bool SPItem::isEvaluated() const {
  * Returns something suitable for the `Hide' checkbox in the Object Properties dialog box.
  *  Corresponds to setExplicitlyHidden.
  */
-bool
-SPItem::isExplicitlyHidden() const
+bool SPItem::isExplicitlyHidden() const
 {
-    return (this->style->display.set
-            && this->style->display.value == SP_CSS_DISPLAY_NONE);
+    return (style->display.set
+            && style->display.value == SP_CSS_DISPLAY_NONE);
 }
 
 /**
  * Sets the display CSS property to `hidden' if \a val is true,
  * otherwise makes it unset
  */
-void
-SPItem::setExplicitlyHidden(bool const val) {
-    this->style->display.set = val;
-    this->style->display.value = ( val ? SP_CSS_DISPLAY_NONE : SP_CSS_DISPLAY_INLINE );
-    this->style->display.computed = this->style->display.value;
-    this->updateRepr();
+void SPItem::setExplicitlyHidden(bool const val) {
+    style->display.set = val;
+    style->display.value = ( val ? SP_CSS_DISPLAY_NONE : SP_CSS_DISPLAY_INLINE );
+    style->display.computed = style->display.value;
+    updateRepr();
 }
 
 /**
  * Sets the transform_center_x and transform_center_y properties to retain the rotation centre
  */
-void
-SPItem::setCenter(Geom::Point object_centre) {
+void SPItem::setCenter(Geom::Point object_centre) {
     // for getBounds() to work
-    SP_OBJECT_DOCUMENT(this)->ensure_up_to_date();
+    document->ensureUpToDate();
 
     Geom::OptRect bbox = getBounds(i2d_affine());
     if (bbox) {
@@ -321,13 +300,13 @@ bool SPItem::isCenterSet() {
 
 Geom::Point SPItem::getCenter() const {
     // for getBounds() to work
-    SP_OBJECT_DOCUMENT(this)->ensure_up_to_date();
+    document->ensureUpToDate();
 
     Geom::OptRect bbox = getBounds(i2d_affine());
     if (bbox) {
-        return to_2geom(bbox->midpoint()) + Geom::Point (this->transform_center_x, this->transform_center_y);
+        return to_2geom(bbox->midpoint()) + Geom::Point (transform_center_x, transform_center_y);
     } else {
-        return Geom::Point (0, 0); // something's wrong!
+        return Geom::Point(0, 0); // something's wrong!
     }
 }
 
@@ -344,22 +323,20 @@ void SPItem::raiseToTop() {
     using Inkscape::Algorithms::find_last_if;
 
     SPObject *topmost=find_last_if<SPObject::SiblingIterator>(
-        SP_OBJECT_NEXT(this), NULL, &is_item
+        next, NULL, &is_item
     );
     if (topmost) {
-        Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
-        sp_repr_parent(repr)->changeOrder(repr, SP_OBJECT_REPR(topmost));
+        getRepr()->parent()->changeOrder( getRepr(), topmost->getRepr() );
     }
 }
 
 void SPItem::raiseOne() {
     SPObject *next_higher=std::find_if<SPObject::SiblingIterator>(
-        SP_OBJECT_NEXT(this), NULL, &is_item
+        next, NULL, &is_item
     );
     if (next_higher) {
-        Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
-        Inkscape::XML::Node *ref=SP_OBJECT_REPR(next_higher);
-        sp_repr_parent(repr)->changeOrder(repr, ref);
+        Inkscape::XML::Node *ref = next_higher->getRepr();
+        getRepr()->parent()->changeOrder(getRepr(), ref);
     }
 }
 
@@ -369,16 +346,15 @@ void SPItem::lowerOne() {
 
     MutableList<SPObject &> next_lower=std::find_if(
         reverse_list<SPObject::SiblingIterator>(
-            SP_OBJECT_PARENT(this)->firstChild(), this
+            parent->firstChild(), this
         ),
         MutableList<SPObject &>(),
         &is_item
     );
     if (next_lower) {
         ++next_lower;
-        Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
-        Inkscape::XML::Node *ref=( next_lower ? SP_OBJECT_REPR(&*next_lower) : NULL );
-        sp_repr_parent(repr)->changeOrder(repr, ref);
+        Inkscape::XML::Node *ref = ( next_lower ? next_lower->getRepr() : NULL );
+        getRepr()->parent()->changeOrder(getRepr(), ref);
     }
 }
 
@@ -389,40 +365,37 @@ void SPItem::lowerToBottom() {
 
     MutableList<SPObject &> bottom=find_last_if(
         reverse_list<SPObject::SiblingIterator>(
-            SP_OBJECT_PARENT(this)->firstChild(), this
+            parent->firstChild(), this
         ),
         MutableList<SPObject &>(),
         &is_item
     );
     if (bottom) {
         ++bottom;
-        Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
-        Inkscape::XML::Node *ref=( bottom ? SP_OBJECT_REPR(&*bottom) : NULL );
-        sp_repr_parent(repr)->changeOrder(repr, ref);
+        Inkscape::XML::Node *ref = ( bottom ? bottom->getRepr() : NULL );
+        getRepr()->parent()->changeOrder(getRepr(), ref);
     }
 }
 
-void
-SPItem::sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
+void SPItem::sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
 {
-    object->readAttr( "style");
-    object->readAttr( "transform");
-    object->readAttr( "clip-path");
-    object->readAttr( "mask");
-    object->readAttr( "sodipodi:insensitive");
-    object->readAttr( "sodipodi:nonprintable");
-    object->readAttr( "inkscape:transform-center-x");
-    object->readAttr( "inkscape:transform-center-y");
-    object->readAttr( "inkscape:connector-avoid");
-    object->readAttr( "inkscape:connection-points");
+    object->readAttr( "style" );
+    object->readAttr( "transform" );
+    object->readAttr( "clip-path" );
+    object->readAttr( "mask" );
+    object->readAttr( "sodipodi:insensitive" );
+    object->readAttr( "sodipodi:nonprintable" );
+    object->readAttr( "inkscape:transform-center-x" );
+    object->readAttr( "inkscape:transform-center-y" );
+    object->readAttr( "inkscape:connector-avoid" );
+    object->readAttr( "inkscape:connection-points" );
 
     if (((SPObjectClass *) (SPItemClass::static_parent_class))->build) {
         (* ((SPObjectClass *) (SPItemClass::static_parent_class))->build)(object, document, repr);
     }
 }
 
-void
-SPItem::sp_item_release(SPObject *object)
+void SPItem::sp_item_release(SPObject *object)
 {
     SPItem *item = (SPItem *) object;
 
@@ -430,7 +403,7 @@ SPItem::sp_item_release(SPObject *object)
     item->_mask_ref_connection.disconnect();
 
     // Note: do this here before the clip_ref is deleted, since calling
-    // sp_document_ensure_up_to_date for triggered routing may reference
+    // ensureUpToDate() for triggered routing may reference
     // the deleted clip_ref.
     if (item->avoidRef) {
         delete item->avoidRef;
@@ -461,8 +434,7 @@ SPItem::sp_item_release(SPObject *object)
     item->_transformed_signal.~signal();
 }
 
-void
-SPItem::sp_item_set(SPObject *object, unsigned key, gchar const *value)
+void SPItem::sp_item_set(SPObject *object, unsigned key, gchar const *value)
 {
     SPItem *item = (SPItem *) object;
 
@@ -556,14 +528,13 @@ SPItem::sp_item_set(SPObject *object, unsigned key, gchar const *value)
     }
 }
 
-void
-SPItem::clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item)
+void SPItem::clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item)
 {
     if (old_clip) {
         SPItemView *v;
         /* Hide clippath */
         for (v = item->display; v != NULL; v = v->next) {
-            SP_CLIPPATH(old_clip)->sp_clippath_hide(NR_ARENA_ITEM_GET_KEY(v->arenaitem));
+            SP_CLIPPATH(old_clip)->hide(NR_ARENA_ITEM_GET_KEY(v->arenaitem));
             nr_arena_item_set_clip(v->arenaitem, NULL);
         }
     }
@@ -574,19 +545,18 @@ SPItem::clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item)
             if (!v->arenaitem->key) {
                 NR_ARENA_ITEM_SET_KEY(v->arenaitem, SPItem::display_key_new(3));
             }
-            NRArenaItem *ai = SP_CLIPPATH(clip)->sp_clippath_show(
+            NRArenaItem *ai = SP_CLIPPATH(clip)->show(
                                                NR_ARENA_ITEM_ARENA(v->arenaitem),
                                                NR_ARENA_ITEM_GET_KEY(v->arenaitem));
             nr_arena_item_set_clip(v->arenaitem, ai);
             nr_arena_item_unref(ai);
-            SP_CLIPPATH(clip)->sp_clippath_set_bbox(NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
-            SP_OBJECT(clip)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+            SP_CLIPPATH(clip)->setBBox(NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
+            clip->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
         }
     }
 }
 
-void
-SPItem::mask_ref_changed(SPObject *old_mask, SPObject *mask, SPItem *item)
+void SPItem::mask_ref_changed(SPObject *old_mask, SPObject *mask, SPItem *item)
 {
     if (old_mask) {
         /* Hide mask */
@@ -608,18 +578,18 @@ SPItem::mask_ref_changed(SPObject *old_mask, SPObject *mask, SPItem *item)
             nr_arena_item_set_mask(v->arenaitem, ai);
             nr_arena_item_unref(ai);
             sp_mask_set_bbox(SP_MASK(mask), NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
-            SP_OBJECT(mask)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+            mask->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
         }
     }
 }
 
-void
-SPItem::sp_item_update(SPObject *object, SPCtx *ctx, guint flags)
+void SPItem::sp_item_update(SPObject *object, SPCtx *ctx, guint flags)
 {
     SPItem *item = SP_ITEM(object);
 
-    if (((SPObjectClass *) (SPItemClass::static_parent_class))->update)
+    if (((SPObjectClass *) (SPItemClass::static_parent_class))->update) {
         (* ((SPObjectClass *) (SPItemClass::static_parent_class))->update)(object, ctx, flags);
+    }
 
     if (flags & (SP_OBJECT_CHILD_MODIFIED_FLAG | SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG)) {
         if (flags & SP_OBJECT_MODIFIED_FLAG) {
@@ -636,7 +606,7 @@ SPItem::sp_item_update(SPObject *object, SPCtx *ctx, guint flags)
             item->invoke_bbox( &bbox, Geom::identity(), TRUE);
             if (clip_path) {
                 for (SPItemView *v = item->display; v != NULL; v = v->next) {
-                    clip_path->sp_clippath_set_bbox(NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
+                    clip_path->setBBox(NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
                 }
             }
             if (mask) {
@@ -671,8 +641,7 @@ SPItem::sp_item_update(SPObject *object, SPCtx *ctx, guint flags)
         item->avoidRef->handleSettingChange();
 }
 
-Inkscape::XML::Node *
-SPItem::sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
+Inkscape::XML::Node *SPItem::sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 {
     SPObject *child;
     SPItem *item = SP_ITEM(object);
@@ -683,7 +652,7 @@ SPItem::sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc,
         Inkscape::XML::Node *crepr;
         GSList *l;
         l = NULL;
-        for (child = object->first_child(); child != NULL; child = SP_OBJECT_NEXT(child) ) {
+        for (child = object->firstChild(); child != NULL; child = child->next ) {
             if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
             crepr = child->updateRepr(xml_doc, NULL, flags);
             if (crepr) l = g_slist_prepend (l, crepr);
@@ -694,7 +663,7 @@ SPItem::sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc,
             l = g_slist_remove (l, l->data);
         }
     } else {
-        for (child = object->first_child() ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+        for (child = object->firstChild() ; child != NULL; child = child->next ) {
             if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
             child->updateRepr(flags);
         }
@@ -743,19 +712,17 @@ Geom::OptRect SPItem::getBounds(Geom::Matrix const &transform,
                                       unsigned int /*dkey*/) const
 {
     Geom::OptRect r;
-    SP_ITEM(this)->invoke_bbox_full( r, transform, type, TRUE);
+    invoke_bbox_full( r, transform, type, TRUE);
     return r;
 }
 
-void
-SPItem::invoke_bbox( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
+void SPItem::invoke_bbox( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
 {
     invoke_bbox_full( bbox, transform, type, clear);
 }
 
 // DEPRECATED to phase out the use of NRRect in favor of Geom::OptRect
-void
-SPItem::invoke_bbox( NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
+void SPItem::invoke_bbox( NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
 {
     invoke_bbox_full( bbox, transform, type, clear);
 }
@@ -767,12 +734,8 @@ SPItem::invoke_bbox( NRRect *bbox, Geom::Matrix const &transform, unsigned const
  * \retval bbox  Note that there is no guarantee that bbox will contain a rectangle when the
  *               function returns. If this item does not have a boundingbox, this might well be empty.
  */
-void
-SPItem::invoke_bbox_full( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear)
+void SPItem::invoke_bbox_full( Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear) const
 {
-    //g_assert(this != NULL);
-    //g_assert(SP_IS_ITEM(this));
-
     if (clear) {
         bbox = Geom::OptRect();
     }
@@ -790,8 +753,8 @@ SPItem::invoke_bbox_full( Geom::OptRect &bbox, Geom::Matrix const &transform, un
 
     // unless this is geometric bbox, extend by filter area and crop the bbox by clip path, if any
     if ((SPItem::BBoxType) flags != SPItem::GEOMETRIC_BBOX) {
-        if (SP_OBJECT_STYLE(this) && SP_OBJECT_STYLE(this)->filter.href) {
-            SPObject *filter = SP_OBJECT_STYLE(this)->getFilter();
+        if ( style && style->filter.href) {
+            SPObject *filter = style->getFilter();
             if (filter && SP_IS_FILTER(filter)) {
                 // default filer area per the SVG spec:
                 double x = -0.1;
@@ -844,9 +807,9 @@ SPItem::invoke_bbox_full( Geom::OptRect &bbox, Geom::Matrix const &transform, un
                 temp_bbox.y1 += dy1;
             }
         }
-        if (this->clip_ref->getObject()) {
+        if (clip_ref->getObject()) {
             NRRect b;
-            SP_CLIPPATH(this->clip_ref->getObject())->sp_clippath_get_bbox(&b, transform, flags);
+            SP_CLIPPATH(clip_ref->getObject())->getBBox(&b, transform, flags);
             nr_rect_d_intersect (&temp_bbox, &temp_bbox, &b);
         }
     }
@@ -875,11 +838,8 @@ SPItem::invoke_bbox_full( Geom::OptRect &bbox, Geom::Matrix const &transform, un
  * unions the resulting bbox with \a bbox. If \a clear is true, empties \a bbox first. Passes the
  * transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
  * clones), in turn, call this function in their bbox methods. */
-void
-SPItem::invoke_bbox_full( NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear)
+void SPItem::invoke_bbox_full( NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear)
 {
-    //g_assert(this != NULL);
-    //g_assert(SP_IS_ITEM(this));
     g_assert(bbox != NULL);
 
     if (clear) {
@@ -897,9 +857,9 @@ SPItem::invoke_bbox_full( NRRect *bbox, Geom::Matrix const &transform, unsigned
     }
 
     // unless this is geometric bbox, crop the bbox by clip path, if any
-    if ((SPItem::BBoxType) flags != SPItem::GEOMETRIC_BBOX && this->clip_ref->getObject()) {
+    if ((SPItem::BBoxType) flags != SPItem::GEOMETRIC_BBOX && clip_ref->getObject()) {
         NRRect b;
-        SP_CLIPPATH(this->clip_ref->getObject())->sp_clippath_get_bbox(&b, transform, flags);
+        SP_CLIPPATH(clip_ref->getObject())->getBBox(&b, transform, flags);
         nr_rect_d_intersect (&this_bbox, &this_bbox, &b);
     }
 
@@ -911,17 +871,13 @@ SPItem::invoke_bbox_full( NRRect *bbox, Geom::Matrix const &transform, unsigned
 
 unsigned SPItem::pos_in_parent()
 {
-    //g_assert(this != NULL);
-    //g_assert(SP_IS_ITEM(this));
-
-    SPObject *parent = SP_OBJECT_PARENT(this);
     g_assert(parent != NULL);
     g_assert(SP_IS_OBJECT(parent));
 
-    SPObject *object = SP_OBJECT(this);
+    SPObject *object = this;
 
     unsigned pos=0;
-    for ( SPObject *iter = parent->first_child() ; iter ; iter = SP_OBJECT_NEXT(iter)) {
+    for ( SPObject *iter = parent->firstChild() ; iter ; iter = iter->next) {
         if ( iter == object ) {
             return pos;
         }
@@ -934,11 +890,8 @@ unsigned SPItem::pos_in_parent()
     return 0;
 }
 
-void
-SPItem::getBboxDesktop(NRRect *bbox, SPItem::BBoxType type)
+void SPItem::getBboxDesktop(NRRect *bbox, SPItem::BBoxType type)
 {
-    //g_assert(item != NULL);
-    //g_assert(SP_IS_ITEM(item));
     g_assert(bbox != NULL);
 
     invoke_bbox( bbox, i2d_affine(), TRUE, type);
@@ -974,9 +927,6 @@ void SPItem::sp_item_private_snappoints(SPItem const *item, std::vector<Inkscape
 
 void SPItem::getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const
 {
-    //g_assert (this != NULL);
-    //g_assert (SP_IS_ITEM(this));
-
     // Get the snappoints of the item
     SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(this);
     if (item_class.snappoints) {
@@ -991,8 +941,8 @@ void SPItem::getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscap
     // Get the snappoints of clipping paths and mask, if any
     std::list<SPObject const *> clips_and_masks;
 
-    clips_and_masks.push_back(SP_OBJECT(clip_ref->getObject()));
-    clips_and_masks.push_back(SP_OBJECT(mask_ref->getObject()));
+    clips_and_masks.push_back(clip_ref->getObject());
+    clips_and_masks.push_back(mask_ref->getObject());
 
     SPDesktop *desktop = inkscape_active_desktop();
     for (std::list<SPObject const *>::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); o++) {
@@ -1016,26 +966,24 @@ void SPItem::getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscap
     }
 }
 
-void
-SPItem::invoke_print(SPPrintContext *ctx)
+void SPItem::invoke_print(SPPrintContext *ctx)
 {
-    if (!this->isHidden()) {
-        if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->print) {
-            if (!this->transform.isIdentity()
-                || SP_OBJECT_STYLE(this)->opacity.value != SP_SCALE24_MAX)
+    if ( !isHidden() ) {
+        if ( reinterpret_cast<SPItemClass *>(G_OBJECT_GET_CLASS(this))->print ) {
+            if (!transform.isIdentity()
+                || style->opacity.value != SP_SCALE24_MAX)
             {
-                sp_print_bind(ctx, this->transform, SP_SCALE24_TO_FLOAT(SP_OBJECT_STYLE(this)->opacity.value));
-                ((SPItemClass *) G_OBJECT_GET_CLASS(this))->print(this, ctx);
+                sp_print_bind(ctx, transform, SP_SCALE24_TO_FLOAT(style->opacity.value));
+                reinterpret_cast<SPItemClass *>(G_OBJECT_GET_CLASS(this))->print(this, ctx);
                 sp_print_release(ctx);
             } else {
-                ((SPItemClass *) G_OBJECT_GET_CLASS(this))->print(this, ctx);
+                reinterpret_cast<SPItemClass *>(G_OBJECT_GET_CLASS(this))->print(this, ctx);
             }
         }
     }
 }
 
-gchar *
-SPItem::sp_item_private_description(SPItem */*item*/)
+gchar *SPItem::sp_item_private_description(SPItem */*item*/)
 {
     return g_strdup(_("Object"));
 }
@@ -1045,12 +993,8 @@ SPItem::sp_item_private_description(SPItem */*item*/)
  *
  * Must be freed by caller.
  */
-gchar *
-SPItem::description()
+gchar *SPItem::description()
 {
-    //g_assert(this != NULL);
-    //g_assert(SP_IS_ITEM(this));
-
     if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->description) {
         gchar *s = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->description(this);
         if (s && clip_ref->getObject()) {
@@ -1063,9 +1007,9 @@ SPItem::description()
             g_free (s);
             s = snew;
         }
-        if (SP_OBJECT_STYLE(this) && SP_OBJECT_STYLE(this)->filter.href && SP_OBJECT_STYLE(this)->filter.href->getObject()) {
-            const gchar *label = SP_OBJECT_STYLE(this)->filter.href->getObject()->label();
-            gchar *snew;
+        if ( style && style->filter.href && style->filter.href->getObject() ) {
+            const gchar *label = style->filter.href->getObject()->label();
+            gchar *snew = 0;
             if (label) {
                 snew = g_strdup_printf (_("%s; <i>filtered (%s)</i>"), s, _(label));
             } else {
@@ -1087,8 +1031,7 @@ SPItem::description()
  * \return First allocated key; hence if the returned key is n
  * you can use n, n + 1, ..., n + (numkeys - 1)
  */
-unsigned
-SPItem::display_key_new(unsigned numkeys)
+unsigned SPItem::display_key_new(unsigned numkeys)
 {
     static unsigned dkey = 0;
 
@@ -1097,11 +1040,8 @@ SPItem::display_key_new(unsigned numkeys)
     return dkey - numkeys;
 }
 
-NRArenaItem *
-SPItem::invoke_show(NRArena *arena, unsigned key, unsigned flags)
+NRArenaItem *SPItem::invoke_show(NRArena *arena, unsigned key, unsigned flags)
 {
-    //g_assert(this != NULL);
-    //g_assert(SP_IS_ITEM(this));
     g_assert(arena != NULL);
     g_assert(NR_IS_ARENA(arena));
 
@@ -1113,7 +1053,7 @@ SPItem::invoke_show(NRArena *arena, unsigned key, unsigned flags)
     if (ai != NULL) {
         display = sp_item_view_new_prepend(display, this, flags, key, ai);
         nr_arena_item_set_transform(ai, transform);
-        nr_arena_item_set_opacity(ai, SP_SCALE24_TO_FLOAT(SP_OBJECT_STYLE(this)->opacity.value));
+        nr_arena_item_set_opacity(ai, SP_SCALE24_TO_FLOAT(style->opacity.value));
         nr_arena_item_set_visible(ai, !isHidden());
         nr_arena_item_set_sensitive(ai, sensitive);
         if (clip_ref->getObject()) {
@@ -1125,15 +1065,15 @@ SPItem::invoke_show(NRArena *arena, unsigned key, unsigned flags)
             int clip_key = NR_ARENA_ITEM_GET_KEY(display->arenaitem);
 
             // Show and set clip
-            NRArenaItem *ac = cp->sp_clippath_show(arena, clip_key);
+            NRArenaItem *ac = cp->show(arena, clip_key);
             nr_arena_item_set_clip(ai, ac);
             nr_arena_item_unref(ac);
 
             // Update bbox, in case the clip uses bbox units
             NRRect bbox;
             invoke_bbox( &bbox, Geom::identity(), TRUE);
-            SP_CLIPPATH(cp)->sp_clippath_set_bbox(clip_key, &bbox);
-            SP_OBJECT(cp)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+            SP_CLIPPATH(cp)->setBBox(clip_key, &bbox);
+            cp->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
         }
         if (mask_ref->getObject()) {
             SPMask *mask = mask_ref->getObject();
@@ -1152,7 +1092,7 @@ SPItem::invoke_show(NRArena *arena, unsigned key, unsigned flags)
             NRRect bbox;
             invoke_bbox( &bbox, Geom::identity(), TRUE);
             sp_mask_set_bbox(SP_MASK(mask), mask_key, &bbox);
-            SP_OBJECT(mask)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+            mask->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
         }
         NR_ARENA_ITEM_SET_DATA(ai, this);
         Geom::OptRect item_bbox;
@@ -1163,12 +1103,8 @@ SPItem::invoke_show(NRArena *arena, unsigned key, unsigned flags)
     return ai;
 }
 
-void
-SPItem::invoke_hide(unsigned key)
+void SPItem::invoke_hide(unsigned key)
 {
-    //g_assert(this != NULL);
-    //g_assert(SP_IS_ITEM(this));
-
     if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->hide) {
         ((SPItemClass *) G_OBJECT_GET_CLASS(this))->hide(this, key);
     }
@@ -1179,7 +1115,7 @@ SPItem::invoke_hide(unsigned key)
         SPItemView *next = v->next;
         if (v->key == key) {
             if (clip_ref->getObject()) {
-                (clip_ref->getObject())->sp_clippath_hide(NR_ARENA_ITEM_GET_KEY(v->arenaitem));
+                (clip_ref->getObject())->hide(NR_ARENA_ITEM_GET_KEY(v->arenaitem));
                 nr_arena_item_set_clip(v->arenaitem, NULL);
             }
             if (mask_ref->getObject()) {
@@ -1203,37 +1139,30 @@ SPItem::invoke_hide(unsigned key)
 
 // Adjusters
 
-void
-SPItem::adjust_pattern (Geom::Matrix const &postmul, bool set)
+void SPItem::adjust_pattern (Geom::Matrix const &postmul, bool set)
 {
-    SPStyle *style = SP_OBJECT_STYLE (this);
-
     if (style && (style->fill.isPaintserver())) {
-        SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (this);
-        if (SP_IS_PATTERN (server)) {
-            SPPattern *pattern = sp_pattern_clone_if_necessary (this, SP_PATTERN (server), "fill");
-            sp_pattern_transform_multiply (pattern, postmul, set);
+        SPObject *server = style->getFillPaintServer();
+        if ( SP_IS_PATTERN(server) ) {
+            SPPattern *pattern = sp_pattern_clone_if_necessary(this, SP_PATTERN(server), "fill");
+            sp_pattern_transform_multiply(pattern, postmul, set);
         }
     }
 
     if (style && (style->stroke.isPaintserver())) {
-        SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (this);
-        if (SP_IS_PATTERN (server)) {
-            SPPattern *pattern = sp_pattern_clone_if_necessary (this, SP_PATTERN (server), "stroke");
-            sp_pattern_transform_multiply (pattern, postmul, set);
+        SPObject *server = style->getStrokePaintServer();
+        if ( SP_IS_PATTERN(server) ) {
+            SPPattern *pattern = sp_pattern_clone_if_necessary(this, SP_PATTERN(server), "stroke");
+            sp_pattern_transform_multiply(pattern, postmul, set);
         }
     }
-
 }
 
-void
-SPItem::adjust_gradient (Geom::Matrix const &postmul, bool set)
+void SPItem::adjust_gradient( Geom::Matrix const &postmul, bool set )
 {
-    SPStyle *style = SP_OBJECT_STYLE (this);
-
-    if (style && (style->fill.isPaintserver())) {
-        SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(this);
-        if (SP_IS_GRADIENT (server)) {
+    if ( style && style->fill.isPaintserver() ) {
+        SPPaintServer *server = style->getFillPaintServer();
+        if ( SP_IS_GRADIENT(server) ) {
 
             /**
              * \note Bbox units for a gradient are generally a bad idea because
@@ -1244,51 +1173,45 @@ SPItem::adjust_gradient (Geom::Matrix const &postmul, bool set)
              * \todo FIXME: convert back to bbox units after transforming with
              * the item, so as to preserve the original units.
              */
-            SPGradient *gradient = sp_gradient_convert_to_userspace (SP_GRADIENT (server), this, "fill");
+            SPGradient *gradient = sp_gradient_convert_to_userspace( SP_GRADIENT(server), this, "fill" );
 
-            sp_gradient_transform_multiply (gradient, postmul, set);
+            sp_gradient_transform_multiply( gradient, postmul, set );
         }
     }
 
-    if (style && (style->stroke.isPaintserver())) {
-        SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER(this);
-        if (SP_IS_GRADIENT (server)) {
-            SPGradient *gradient = sp_gradient_convert_to_userspace (SP_GRADIENT (server), this, "stroke");
-            sp_gradient_transform_multiply (gradient, postmul, set);
+    if ( style && style->stroke.isPaintserver() ) {
+        SPPaintServer *server = style->getStrokePaintServer();
+        if ( SP_IS_GRADIENT(server) ) {
+            SPGradient *gradient = sp_gradient_convert_to_userspace( SP_GRADIENT(server), this, "stroke");
+            sp_gradient_transform_multiply( gradient, postmul, set );
         }
     }
 }
 
-void
-SPItem::adjust_stroke (gdouble ex)
+void SPItem::adjust_stroke( gdouble ex )
 {
-    SPStyle *style = SP_OBJECT_STYLE (this);
-
-    if (style && !style->stroke.isNone() && !NR_DF_TEST_CLOSE (ex, 1.0, NR_EPSILON)) {
-
+    if ( style && !style->stroke.isNone() && !NR_DF_TEST_CLOSE(ex, 1.0, NR_EPSILON) ) {
         style->stroke_width.computed *= ex;
         style->stroke_width.set = TRUE;
 
-        if (style->stroke_dash.n_dash != 0) {
-            int i;
-            for (i = 0; i < style->stroke_dash.n_dash; i++) {
+        if ( style->stroke_dash.n_dash != 0 ) {
+            for (int i = 0; i < style->stroke_dash.n_dash; i++) {
                 style->stroke_dash.dash[i] *= ex;
             }
             style->stroke_dash.offset *= ex;
         }
 
-        SP_OBJECT(this)->updateRepr();
+        updateRepr();
     }
 }
 
 /**
  * Find out the inverse of previous transform of an item (from its repr)
  */
-Geom::Matrix
-sp_item_transform_repr (SPItem *item)
+Geom::Matrix sp_item_transform_repr (SPItem *item)
 {
     Geom::Matrix t_old(Geom::identity());
-    gchar const *t_attr = SP_OBJECT_REPR(item)->attribute("transform");
+    gchar const *t_attr = item->getRepr()->attribute("transform");
     if (t_attr) {
         Geom::Matrix t;
         if (sp_svg_transform_read(t_attr, &t)) {
@@ -1303,18 +1226,17 @@ sp_item_transform_repr (SPItem *item)
 /**
  * Recursively scale stroke width in \a item and its children by \a expansion.
  */
-void
-SPItem::adjust_stroke_width_recursive(double expansion)
+void SPItem::adjust_stroke_width_recursive(double expansion)
 {
     adjust_stroke (expansion);
 
 // A clone's child is the ghost of its original - we must not touch it, skip recursion
-    if (this && SP_IS_USE(this))
-        return;
-
-    for (SPObject *o = SP_OBJECT(this)->children; o != NULL; o = o->next) {
-        if (SP_IS_ITEM(o))
-            SP_ITEM(o)->adjust_stroke_width_recursive(expansion);
+    if ( !SP_IS_USE(this) ) {
+        for ( SPObject *o = children; o; o = o->getNext() ) {
+            if (SP_IS_ITEM(o)) {
+                SP_ITEM(o)->adjust_stroke_width_recursive(expansion);
+            }
+        }
     }
 }
 
@@ -1328,7 +1250,7 @@ sp_item_adjust_rects_recursive(SPItem *item, Geom::Matrix advertized_transform)
         sp_rect_compensate_rxry (SP_RECT(item), advertized_transform);
     }
 
-    for (SPObject *o = SP_OBJECT(item)->children; o != NULL; o = o->next) {
+    for (SPObject *o = item->children; o != NULL; o = o->next) {
         if (SP_IS_ITEM(o))
             sp_item_adjust_rects_recursive(SP_ITEM(o), advertized_transform);
     }
@@ -1337,8 +1259,7 @@ sp_item_adjust_rects_recursive(SPItem *item, Geom::Matrix advertized_transform)
 /**
  * Recursively compensate pattern or gradient transform.
  */
-void
-SPItem::adjust_paint_recursive (Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern)
+void SPItem::adjust_paint_recursive (Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern)
 {
 // _Before_ full pattern/gradient transform: t_paint * t_item * t_ancestors
 // _After_ full pattern/gradient transform: t_paint_new * t_item * t_ancestors * advertised_transform
@@ -1350,7 +1271,7 @@ SPItem::adjust_paint_recursive (Geom::Matrix advertized_transform, Geom::Matrix
 // also we do not recurse into clones, because a clone's child is the ghost of its original -
 // we must not touch it
     if (!(this && (SP_IS_TEXT(this) || SP_IS_USE(this)))) {
-        for (SPObject *o = SP_OBJECT(this)->children; o != NULL; o = o->next) {
+        for (SPObject *o = children; o != NULL; o = o->next) {
             if (SP_IS_ITEM(o)) {
 // At the level of the transformed item, t_ancestors is identity;
 // below it, it is the accmmulated chain of transforms from this level to the top level
@@ -1364,31 +1285,29 @@ SPItem::adjust_paint_recursive (Geom::Matrix advertized_transform, Geom::Matrix
 // and paintservers on leaves inheriting their values from ancestors could adjust themselves properly
 // before ancestors themselves are adjusted, probably differently (bug 1286535)
 
-    if (is_pattern)
-        adjust_pattern (paint_delta);
-    else
-        adjust_gradient (paint_delta);
-
+    if (is_pattern) {
+        adjust_pattern(paint_delta);
+    } else {
+        adjust_gradient(paint_delta);
+    }
 }
 
-void
-SPItem::adjust_livepatheffect (Geom::Matrix const &postmul, bool set)
+void SPItem::adjust_livepatheffect (Geom::Matrix const &postmul, bool set)
 {
-    if ( !SP_IS_LPE_ITEM(this) )
-        return;
-
-    SPLPEItem *lpeitem = SP_LPE_ITEM (this);
-    if ( sp_lpe_item_has_path_effect(lpeitem) ) {
-        sp_lpe_item_fork_path_effects_if_necessary(lpeitem);
-
-        // now that all LPEs are forked_if_necessary, we can apply the transform
-        PathEffectList effect_list =  sp_lpe_item_get_effect_list(lpeitem);
-        for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); it++)
-        {
-            LivePathEffectObject *lpeobj = (*it)->lpeobject;
-            if (lpeobj && lpeobj->get_lpe()) {
-                Inkscape::LivePathEffect::Effect * effect = lpeobj->get_lpe();
-                effect->transform_multiply(postmul, set);
+    if ( SP_IS_LPE_ITEM(this) ) {
+        SPLPEItem *lpeitem = SP_LPE_ITEM (this);
+        if ( sp_lpe_item_has_path_effect(lpeitem) ) {
+            sp_lpe_item_fork_path_effects_if_necessary(lpeitem);
+
+            // now that all LPEs are forked_if_necessary, we can apply the transform
+            PathEffectList effect_list =  sp_lpe_item_get_effect_list(lpeitem);
+            for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); it++)
+            {
+                LivePathEffectObject *lpeobj = (*it)->lpeobject;
+                if (lpeobj && lpeobj->get_lpe()) {
+                    Inkscape::LivePathEffect::Effect * effect = lpeobj->get_lpe();
+                    effect->transform_multiply(postmul, set);
+                }
             }
         }
     }
@@ -1402,11 +1321,8 @@ SPItem::adjust_livepatheffect (Geom::Matrix const &postmul, bool set)
  * stored optimized. Send _transformed_signal. Invoke _write method so that
  * the repr is updated with the new transform.
  */
-void
-SPItem::doWriteTransform(Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv, bool compensate)
+void SPItem::doWriteTransform(Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv, bool compensate)
 {
-    //g_return_if_fail(this != NULL);
-    //g_return_if_fail(SP_IS_ITEM(this));
     g_return_if_fail(repr != NULL);
 
     // calculate the relative transform, if not given by the adv attribute
@@ -1454,7 +1370,7 @@ SPItem::doWriteTransform(Inkscape::XML::Node *repr, Geom::Matrix const &transfor
              !preserve && // user did not chose to preserve all transforms
              !clip_ref->getObject() && // the object does not have a clippath
              !mask_ref->getObject() && // the object does not have a mask
-         !(!transform.isTranslation() && SP_OBJECT_STYLE(this) && SP_OBJECT_STYLE(this)->getFilter())
+         !(!transform.isTranslation() && style && style->getFilter())
              // the object does not have a filter, or the transform is translation (which is supposed to not affect filters)
         ) {
         transform_attr = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->set_transform(this, transform);
@@ -1465,21 +1381,17 @@ SPItem::doWriteTransform(Inkscape::XML::Node *repr, Geom::Matrix const &transfor
     // it causes clone SPUse's copy of the original object to brought up to
     // date with the original.  Otherwise, sp_use_bbox returns incorrect
     // values if called in code handling the transformed signal.
-    SP_OBJECT(this)->updateRepr();
+    updateRepr();
 
     // send the relative transform with a _transformed_signal
     _transformed_signal.emit(&advertized_transform, this);
 }
 
-gint
-SPItem::emitEvent(SPEvent &event)
+gint SPItem::emitEvent(SPEvent &event)
 {
-    //g_return_val_if_fail(this != NULL, FALSE);
-    //g_return_val_if_fail(SP_IS_ITEM(this), FALSE);
-    //g_return_val_if_fail((&event) != NULL, FALSE);
-
-    if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->event)
+    if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->event) {
         return ((SPItemClass *) G_OBJECT_GET_CLASS(this))->event(this, &event);
+    }
 
     return FALSE;
 }
@@ -1488,12 +1400,8 @@ SPItem::emitEvent(SPEvent &event)
  * Sets item private transform (not propagated to repr), without compensating stroke widths,
  * gradients, patterns as sp_item_write_transform does.
  */
-void
-SPItem::set_item_transform(Geom::Matrix const &transform_matrix)
+void SPItem::set_item_transform(Geom::Matrix const &transform_matrix)
 {
-    g_return_if_fail(this != NULL);
-    g_return_if_fail(SP_IS_ITEM(this));
-
     if (!matrix_equalp(transform_matrix, transform, NR_EPSILON)) {
         transform = transform_matrix;
         /* The SP_OBJECT_USER_MODIFIED_FLAG_B is used to mark the fact that it's only a
@@ -1503,20 +1411,15 @@ SPItem::set_item_transform(Geom::Matrix const &transform_matrix)
     }
 }
 
-void
-SPItem::convert_item_to_guides() {
-    g_return_if_fail(this != NULL);
-    g_return_if_fail(SP_IS_ITEM(this));
-
-    /* Use derived method if present ... */
+void SPItem::convert_item_to_guides() {
+    // Use derived method if present ...
     if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides) {
         (*((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides)(this);
-        return;
-    }
-
-    /* .. otherwise simply place the guides around the item's bounding box */
+    } else {
+        // .. otherwise simply place the guides around the item's bounding box
 
-    convert_to_guides();
+        convert_to_guides();
+    }
 }
 
 
@@ -1536,7 +1439,7 @@ i2anc_affine(SPObject const *object, SPObject const *const ancestor) {
         } else {
             ret *= SP_ITEM(object)->transform;
         }
-        object = SP_OBJECT_PARENT(object);
+        object = object->parent;
     }
     return ret;
 }
@@ -1566,25 +1469,19 @@ Geom::Matrix SPItem::i2doc_affine() const
  */
 Geom::Matrix SPItem::i2d_affine() const
 {
-    //g_assert(item != NULL);
-    //g_assert(SP_IS_ITEM(item));
-
     Geom::Matrix const ret( i2doc_affine()
                           * Geom::Scale(1, -1)
-                          * Geom::Translate(0, SP_OBJECT_DOCUMENT(this)->getHeight()) );
+                          * Geom::Translate(0, document->getHeight()) );
     return ret;
 }
 
 void SPItem::set_i2d_affine(Geom::Matrix const &i2dt)
 {
-    //g_return_if_fail( item != NULL );
-    //g_return_if_fail( SP_IS_ITEM(item) );
-
     Geom::Matrix dt2p; /* desktop to item parent transform */
-    if (SP_OBJECT_PARENT(this)) {
-        dt2p = static_cast<SPItem *>(SP_OBJECT_PARENT(this))->i2d_affine().inverse();
+    if (parent) {
+        dt2p = static_cast<SPItem *>(parent)->i2d_affine().inverse();
     } else {
-        dt2p = ( Geom::Translate(0, -SP_OBJECT_DOCUMENT(this)->getHeight())
+        dt2p = ( Geom::Translate(0, -document->getHeight())
                  * Geom::Scale(1, -1) );
     }
 
@@ -1596,8 +1493,7 @@ void SPItem::set_i2d_affine(Geom::Matrix const &i2dt)
 /**
  * should rather be named "sp_item_d2i_affine" to match "sp_item_i2d_affine" (or vice versa)
  */
-Geom::Matrix
-SPItem::dt2i_affine() const
+Geom::Matrix SPItem::dt2i_affine() const
 {
     /* fixme: Implement the right way (Lauris) */
     return i2d_affine().inverse();
@@ -1605,17 +1501,14 @@ SPItem::dt2i_affine() const
 
 /* Item views */
 
-SPItemView *
-SPItem::sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem)
+SPItemView *SPItem::sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem)
 {
-    SPItemView *new_view;
-
     g_assert(item != NULL);
     g_assert(SP_IS_ITEM(item));
     g_assert(arenaitem != NULL);
     g_assert(NR_IS_ARENA_ITEM(arenaitem));
 
-    new_view = g_new(SPItemView, 1);
+    SPItemView *new_view = g_new(SPItemView, 1);
 
     new_view->next = list;
     new_view->flags = flags;
@@ -1625,8 +1518,7 @@ SPItem::sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags,
     return new_view;
 }
 
-SPItemView *
-SPItem::sp_item_view_list_remove(SPItemView *list, SPItemView *view)
+SPItemView *SPItem::sp_item_view_list_remove(SPItemView *list, SPItemView *view)
 {
     if (view == list) {
         list = list->next;
@@ -1647,8 +1539,7 @@ SPItem::sp_item_view_list_remove(SPItemView *list, SPItemView *view)
  * Return the arenaitem corresponding to the given item in the display
  * with the given key
  */
-NRArenaItem *
-SPItem::get_arenaitem(unsigned key)
+NRArenaItem *SPItem::get_arenaitem(unsigned key)
 {
     for ( SPItemView *iv = display ; iv ; iv = iv->next ) {
         if ( iv->key == key ) {
@@ -1659,28 +1550,27 @@ SPItem::get_arenaitem(unsigned key)
     return NULL;
 }
 
-int
-sp_item_repr_compare_position(SPItem *first, SPItem *second)
+int sp_item_repr_compare_position(SPItem *first, SPItem *second)
 {
-    return sp_repr_compare_position(SP_OBJECT_REPR(first),
-                                    SP_OBJECT_REPR(second));
+    return sp_repr_compare_position(first->getRepr(),
+                                    second->getRepr());
 }
 
-SPItem *
-sp_item_first_item_child (SPObject *obj)
+SPItem *sp_item_first_item_child(SPObject *obj)
 {
-    for ( SPObject *iter = obj->first_child() ; iter ; iter = SP_OBJECT_NEXT(iter)) {
-        if (SP_IS_ITEM (iter))
-            return SP_ITEM (iter);
+    SPItem *child = 0;
+    for ( SPObject *iter = obj->firstChild() ; iter ; iter = iter->next ) {
+        if ( SP_IS_ITEM(iter) ) {
+            child = SP_ITEM(iter);
+            break;
+        }
     }
-    return NULL;
+    return child;
 }
 
-void
-SPItem::convert_to_guides() {
+void SPItem::convert_to_guides() {
     SPDesktop *dt = inkscape_active_desktop();
-    SPNamedView *nv = sp_desktop_namedview(dt);
-    (void)nv;
+    sp_desktop_namedview(dt);
 
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     int prefs_bbox = prefs->getInt("/tools/bounding_box", 0);