Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / gradient-drag.cpp
index 246573e3f3fc0d05de413632b0f68b5c257404a6..fe8297286c2489562352fa06cd128a7c384a910a 100644 (file)
@@ -1,14 +1,14 @@
-#define __GRADIENT_DRAG_C__
-
 /*
  * On-canvas gradient dragging
  *
  * Authors:
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2007 Johan Engelen
- * Copyright (C) 2005 Authors
+ * Copyright (C) 2005,2010 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -25,6 +25,7 @@
 #include "selection.h"
 #include "desktop.h"
 #include "desktop-style.h"
+#include "desktop-handles.h"
 #include "document.h"
 #include "display/sp-ctrlline.h"
 #include "display/sp-canvas-util.h"
@@ -45,6 +46,8 @@
 #include "sp-namedview.h"
 #include "selection-chemistry.h"
 
+using Inkscape::DocumentUndo;
+
 #define GR_KNOT_COLOR_NORMAL 0xffffff00
 #define GR_KNOT_COLOR_MOUSEOVER 0xff000000
 #define GR_KNOT_COLOR_SELECTED 0x0000ff00
@@ -177,41 +180,91 @@ gr_drag_style_query (SPStyle *style, int property, gpointer data)
     }
 }
 
-bool
-gr_drag_style_set (const SPCSSAttr *css, gpointer data)
+Glib::ustring GrDrag::makeStopSafeColor( gchar const *str, bool &isNull )
 {
-    GrDrag *drag = (GrDrag *) data;
+    Glib::ustring colorStr;
+    if ( str ) {
+        isNull = false;
+        colorStr = str;
+        Glib::ustring::size_type pos = colorStr.find("url(#");
+        if ( pos != Glib::ustring::npos ) {
+            Glib::ustring targetName = colorStr.substr(pos + 5, colorStr.length() - 6);
+            const GSList *gradients = desktop->doc()->getResourceList("gradient");
+            for (const GSList *item = gradients; item; item = item->next) {
+                SPGradient* grad = SP_GRADIENT(item->data);
+                if ( targetName == grad->getId() ) {
+                    SPGradient *vect = grad->getVector();
+                    SPStop *firstStop = (vect) ? vect->getFirstStop() : grad->getFirstStop();
+                    if (firstStop) {
+                        Glib::ustring stopColorStr;
+                        if (firstStop->currentColor) {
+                            stopColorStr = firstStop->getStyleProperty("color", NULL);
+                        } else {
+                            stopColorStr = firstStop->specified_color.toString();
+                        }
+                        if ( !stopColorStr.empty() ) {
+                            colorStr = stopColorStr;
+                        }
+                    }
+                    break;
+                }
+            }
+        }
+    } else {
+        isNull = true;
+    }
+
+    return colorStr;
+}
 
-    if (!drag->selected)
+bool GrDrag::styleSet( const SPCSSAttr *css )
+{
+    if (!selected) {
         return false;
+    }
 
-    SPCSSAttr *stop = sp_repr_css_attr_new ();
+    SPCSSAttr *stop = sp_repr_css_attr_new();
 
     // See if the css contains interesting properties, and if so, translate them into the format
     // acceptable for gradient stops
 
     // any of color properties, in order of increasing priority:
-    if (css->attribute("flood-color"))
+    if (css->attribute("flood-color")) {
         sp_repr_css_set_property (stop, "stop-color", css->attribute("flood-color"));
+    }
 
-    if (css->attribute("lighting-color"))
+    if (css->attribute("lighting-color")) {
         sp_repr_css_set_property (stop, "stop-color", css->attribute("lighting-color"));
+    }
 
-    if (css->attribute("color"))
+    if (css->attribute("color")) {
         sp_repr_css_set_property (stop, "stop-color", css->attribute("color"));
+    }
 
-    if (css->attribute("stroke") && strcmp(css->attribute("stroke"), "none"))
+    if (css->attribute("stroke") && strcmp(css->attribute("stroke"), "none")) {
         sp_repr_css_set_property (stop, "stop-color", css->attribute("stroke"));
+    }
 
-    if (css->attribute("fill") && strcmp(css->attribute("fill"), "none"))
+    if (css->attribute("fill") && strcmp(css->attribute("fill"), "none")) {
         sp_repr_css_set_property (stop, "stop-color", css->attribute("fill"));
+    }
 
-    if (css->attribute("stop-color"))
+    if (css->attribute("stop-color")) {
         sp_repr_css_set_property (stop, "stop-color", css->attribute("stop-color"));
+    }
+
+    // Make sure the style is allowed for gradient stops.
+    if ( !sp_repr_css_property_is_unset( stop, "stop-color") ) {
+        bool stopIsNull = false;
+        Glib::ustring tmp = makeStopSafeColor( sp_repr_css_property( stop, "stop-color", "" ), stopIsNull );
+        if ( !stopIsNull && !tmp.empty() ) {
+            sp_repr_css_set_property( stop, "stop-color", tmp.c_str() );
+        }
+    }
 
 
     if (css->attribute("stop-opacity")) { // direct setting of stop-opacity has priority
-        sp_repr_css_set_property (stop, "stop-opacity", css->attribute("stop-opacity"));
+        sp_repr_css_set_property(stop, "stop-opacity", css->attribute("stop-opacity"));
     } else {  // multiply all opacity properties:
         gdouble accumulated = 1.0;
         accumulated *= sp_svg_read_percentage(css->attribute("flood-opacity"), 1.0);
@@ -221,11 +274,12 @@ gr_drag_style_set (const SPCSSAttr *css, gpointer data)
 
         Inkscape::CSSOStringStream os;
         os << accumulated;
-        sp_repr_css_set_property (stop, "stop-opacity", os.str().c_str());
+        sp_repr_css_set_property(stop, "stop-opacity", os.str().c_str());
 
         if ((css->attribute("fill") && !css->attribute("stroke") && !strcmp(css->attribute("fill"), "none")) ||
-            (css->attribute("stroke") && !css->attribute("fill") && !strcmp(css->attribute("stroke"), "none")))
-            sp_repr_css_set_property (stop, "stop-opacity", "0"); // if a single fill/stroke property is set to none, don't change color, set opacity to 0
+            (css->attribute("stroke") && !css->attribute("fill") && !strcmp(css->attribute("stroke"), "none"))) {
+            sp_repr_css_set_property(stop, "stop-opacity", "0"); // if a single fill/stroke property is set to none, don't change color, set opacity to 0
+        }
     }
 
     if (!stop->attributeList()) { // nothing for us here, pass it on
@@ -233,13 +287,13 @@ gr_drag_style_set (const SPCSSAttr *css, gpointer data)
         return false;
     }
 
-    for (GList const* sel = drag->selected; sel != NULL; sel = sel->next) { // for all selected draggers
-        GrDragger* dragger = (GrDragger*) sel->data;
+    for (GList const* sel = selected; sel != NULL; sel = sel->next) { // for all selected draggers
+        GrDragger* dragger = reinterpret_cast<GrDragger*>(sel->data);
         for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger
-               GrDraggable *draggable = (GrDraggable *) i->data;
+            GrDraggable *draggable = reinterpret_cast<GrDraggable *>(i->data);
 
-               drag->local_change = true;
-               sp_item_gradient_stop_set_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke, stop);
+            local_change = true;
+            sp_item_gradient_stop_set_style(draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke, stop);
         }
     }
 
@@ -332,12 +386,12 @@ GrDrag::addStopNearPoint (SPItem *item, Geom::Point mouse_p, double tolerance)
 
     if (addknot) {
         SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
-        SPStop* prev_stop = sp_first_stop(vector);
-        SPStop* next_stop = sp_next_stop(prev_stop);
+        SPStop* prev_stop = vector->getFirstStop();
+        SPStop* next_stop = prev_stop->getNextStop();
         guint i = 1;
         while ( (next_stop) && (next_stop->offset < offset) ) {
             prev_stop = next_stop;
-            next_stop = sp_next_stop(next_stop);
+            next_stop = next_stop->getNextStop();
             i++;
         }
         if (!next_stop) {
@@ -347,7 +401,7 @@ GrDrag::addStopNearPoint (SPItem *item, Geom::Point mouse_p, double tolerance)
 
 
         SPStop *newstop = sp_vector_add_stop (vector, prev_stop, next_stop, offset);
-        sp_gradient_ensure_vector (gradient);
+        gradient->ensureVector();
         updateDraggers();
 
         return newstop;
@@ -360,14 +414,18 @@ GrDrag::addStopNearPoint (SPItem *item, Geom::Point mouse_p, double tolerance)
 bool
 GrDrag::dropColor(SPItem */*item*/, gchar const *c, Geom::Point p)
 {
+    // Note: not sure if a null pointer can come in for the style, but handle that just in case
+    bool stopIsNull = false;
+    Glib::ustring toUse = makeStopSafeColor( c, stopIsNull );
+
     // first, see if we can drop onto one of the existing draggers
     for (GList *i = draggers; i != NULL; i = i->next) { // for all draggables of dragger
         GrDragger *d = (GrDragger *) i->data;
 
         if (Geom::L2(p - d->point)*desktop->current_zoom() < 5) {
            SPCSSAttr *stop = sp_repr_css_attr_new ();
-           sp_repr_css_set_property (stop, "stop-color", c);
-           sp_repr_css_set_property (stop, "stop-opacity", "1");
+           sp_repr_css_set_property( stop, "stop-color", stopIsNull ? 0 : toUse.c_str() );
+           sp_repr_css_set_property( stop, "stop-opacity", "1" );
            for (GSList *j = d->draggables; j != NULL; j = j->next) { // for all draggables of dragger
                GrDraggable *draggable = (GrDraggable *) j->data;
                local_change = true;
@@ -390,8 +448,8 @@ GrDrag::dropColor(SPItem */*item*/, gchar const *c, Geom::Point p)
                 SPStop *stop = addStopNearPoint (line->item, p, 5/desktop->current_zoom());
                 if (stop) {
                     SPCSSAttr *css = sp_repr_css_attr_new ();
-                    sp_repr_css_set_property (css, "stop-color", c);
-                    sp_repr_css_set_property (css, "stop-opacity", "1");
+                    sp_repr_css_set_property( css, "stop-color", stopIsNull ? 0 : toUse.c_str() );
+                    sp_repr_css_set_property( css, "stop-opacity", "1" );
                     sp_repr_css_change (SP_OBJECT_REPR (stop), css, "style");
                     return true;
                 }
@@ -403,51 +461,47 @@ GrDrag::dropColor(SPItem */*item*/, gchar const *c, Geom::Point p)
 }
 
 
-GrDrag::GrDrag(SPDesktop *desktop) {
-
-    this->desktop = desktop;
-
-    this->selection = sp_desktop_selection(desktop);
-
-    this->draggers = NULL;
-    this->lines = NULL;
-    this->selected = NULL;
-
-    this->hor_levels.clear();
-    this->vert_levels.clear();
-
-    this->local_change = false;
-
-    this->sel_changed_connection = this->selection->connectChanged(
-        sigc::bind (
+GrDrag::GrDrag(SPDesktop *desktop) :
+    selected(0),
+    keep_selection(false),
+    local_change(false),
+    desktop(desktop),
+    hor_levels(),
+    vert_levels(),
+    draggers(0),
+    lines(0),
+    selection(sp_desktop_selection(desktop)),
+    sel_changed_connection(),
+    sel_modified_connection(),
+    style_set_connection(),
+    style_query_connection()
+{
+    sel_changed_connection = selection->connectChanged(
+        sigc::bind(
             sigc::ptr_fun(&gr_drag_sel_changed),
             (gpointer)this )
 
         );
-    this->sel_modified_connection = this->selection->connectModified(
+    sel_modified_connection = selection->connectModified(
         sigc::bind(
             sigc::ptr_fun(&gr_drag_sel_modified),
             (gpointer)this )
         );
 
-    this->style_set_connection = this->desktop->connectSetStyle(
-        sigc::bind(
-            sigc::ptr_fun(&gr_drag_style_set),
-            (gpointer)this )
-        );
+    style_set_connection = desktop->connectSetStyle( sigc::mem_fun(*this, &GrDrag::styleSet) );
 
-    this->style_query_connection = this->desktop->connectQueryStyle(
+    style_query_connection = desktop->connectQueryStyle(
         sigc::bind(
             sigc::ptr_fun(&gr_drag_style_query),
             (gpointer)this )
         );
 
-    this->updateDraggers ();
-    this->updateLines ();
-    this->updateLevels ();
+    updateDraggers();
+    updateLines();
+    updateLevels();
 
     if (desktop->gr_item) {
-        this->setSelected (getDraggerFor (desktop->gr_item, desktop->gr_point_type, desktop->gr_point_i, desktop->gr_fill_or_stroke));
+        setSelected(getDraggerFor(desktop->gr_item, desktop->gr_point_type, desktop->gr_point_i, desktop->gr_fill_or_stroke));
     }
 }
 
@@ -502,35 +556,20 @@ GrDraggable::~GrDraggable ()
 }
 
 
-SPObject *
-GrDraggable::getServer ()
+SPObject *GrDraggable::getServer()
 {
-    if (!item)
+    if (!item) {
         return NULL;
+    }
 
     SPObject *server = NULL;
-    if (fill_or_stroke)
-        server = SP_OBJECT_STYLE_FILL_SERVER (item);
-    else
-        server = SP_OBJECT_STYLE_STROKE_SERVER (item);
-
-    return server;
-}
-
-static
-boost::optional<Geom::Point>
-get_snap_vector (Geom::Point p, Geom::Point o, double snap, double initial)
-{
-    double r = L2 (p - o);
-    if (r < 1e-3) {
-        return boost::optional<Geom::Point>();
+    if (fill_or_stroke) {
+        server = item->style->getFillPaintServer();
+    }else {
+        server = item->style->getStrokePaintServer();
     }
 
-    double angle = atan2 (p - o);
-    // snap angle to snaps increments, starting from initial:
-    double a_snapped = initial + floor((angle - initial)/snap + 0.5) * snap;
-    // calculate the new position and subtract p to get the vector:
-    return (o + r * Geom::Point(cos(a_snapped), sin(a_snapped)) - p);
+    return server;
 }
 
 static void
@@ -587,22 +626,24 @@ gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gp
                 d_new->updateKnotShape ();
                 d_new->updateTip ();
                 d_new->updateDependencies(true);
-                sp_document_done (sp_desktop_document (d_new->parent->desktop), SP_VERB_CONTEXT_GRADIENT,
-                                  _("Merge gradient handles"));
+                DocumentUndo::done(sp_desktop_document (d_new->parent->desktop), SP_VERB_CONTEXT_GRADIENT,
+                                   _("Merge gradient handles"));
                 return;
             }
         }
     }
 
-    m.setup(desktop);
     if (!((state & GDK_SHIFT_MASK) || (state & GDK_CONTROL_MASK))) {
+        m.setup(desktop);
         Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE));
+        m.unSetup();
         if (s.getSnapped()) {
             p = s.getPoint();
             sp_knot_moveto (knot, p);
         }
     } else if (state & GDK_CONTROL_MASK) {
         SnappedConstraints sc;
+        Inkscape::SnapCandidatePoint scp = Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
         unsigned snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12));
         /* 0 means no snapping. */
@@ -648,36 +689,38 @@ gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gp
                 dr_snap = dragger->point_original;
             }
 
-            boost::optional<Geom::Point> snap_vector;
+            // dr_snap contains the origin of the gradient, whereas p will be the new endpoint which we will try to snap now
+            Inkscape::SnappedPoint sp;
             if (dr_snap.isFinite()) {
+                m.setup(desktop);
                 if (state & GDK_MOD1_MASK) {
                     // with Alt, snap to the original angle and its perpendiculars
-                    snap_vector = get_snap_vector (p, dr_snap, M_PI/2, Geom::atan2 (dragger->point_original - dr_snap));
+                    sp = m.constrainedAngularSnap(scp, dragger->point_original, dr_snap, 2);
                 } else {
                     // with Ctrl, snap to M_PI/snaps
-                    snap_vector = get_snap_vector (p, dr_snap, M_PI/snaps, 0);
-                }
-                if (snap_vector) {
-                    Inkscape::Snapper::ConstraintLine cl(dr_snap, p + *snap_vector - dr_snap);
-                    Inkscape::SnappedPoint s = m.constrainedSnap(Inkscape::SnapCandidatePoint(p + *snap_vector, Inkscape::SNAPSOURCE_OTHER_HANDLE), cl);
-                    if (s.getSnapped()) {
-                        s.setTransformation(s.getPoint() - p);
-                        sc.points.push_back(s);
-                    } else {
-                        Inkscape::SnappedPoint dummy(p + *snap_vector, Inkscape::SNAPSOURCE_OTHER_HANDLE, 0, Inkscape::SNAPTARGET_CONSTRAINED_ANGLE, Geom::L2(*snap_vector), 10000, true, false);
-                        dummy.setTransformation(*snap_vector);
-                        sc.points.push_back(dummy);
-                    }
+                    sp = m.constrainedAngularSnap(scp, boost::optional<Geom::Point>(), dr_snap, snaps);
                 }
+                m.unSetup();
+                sc.points.push_back(sp);
             }
         }
 
-        Inkscape::SnappedPoint bsp = m.findBestSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE), sc, true); // snap indicator will be displayed if needed
-
-        if (bsp.getSnapped()) {
-            p += bsp.getTransformation();
-            sp_knot_moveto (knot, p);
+        m.setup(desktop, false); // turn of the snap indicator temporarily
+        Inkscape::SnappedPoint bsp = m.findBestSnap(scp, sc, true);
+        m.unSetup();
+        if (!bsp.getSnapped()) {
+            // If we didn't truly snap to an object or to a grid, then we will still have to look for the
+            // closest projection onto one of the constraints. findBestSnap() will not do this for us
+            for (std::list<Inkscape::SnappedPoint>::const_iterator i = sc.points.begin(); i != sc.points.end(); i++) {
+                if (i == sc.points.begin() || (Geom::L2((*i).getPoint() - p) < Geom::L2(bsp.getPoint() - p))) {
+                    bsp.setPoint((*i).getPoint());
+                    bsp.setTarget(Inkscape::SNAPTARGET_CONSTRAINED_ANGLE);
+                }
+            }
         }
+        //p = sc.points.front().getPoint();
+        p = bsp.getPoint();
+        sp_knot_moveto (knot, p);
     }
 
     drag->keep_selection = (bool) g_list_find(drag->selected, dragger);
@@ -808,10 +851,12 @@ gr_knot_moved_midpoint_handler(SPKnot */*knot*/, Geom::Point const &ppointer, gu
     } else {
         p = snap_vector_midpoint (p, low_lim, high_lim, 0);
         if (!(state & GDK_SHIFT_MASK)) {
+            Inkscape::Snapper::SnapConstraint cl(low_lim, high_lim - low_lim);
             SPDesktop *desktop = dragger->parent->desktop;
             SnapManager &m = desktop->namedview->snap_manager;
-            Inkscape::Snapper::ConstraintLine cl(low_lim, high_lim - low_lim);
+            m.setup(desktop);
             m.constrainedSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE, cl);
+            m.unSetup();
         }
     }
     Geom::Point displacement = p - dragger->point;
@@ -886,8 +931,8 @@ gr_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, gpointer data)
     dragger->updateDependencies(true);
 
     // we did an undoable action
-    sp_document_done (sp_desktop_document (dragger->parent->desktop), SP_VERB_CONTEXT_GRADIENT,
-                      _("Move gradient handle"));
+    DocumentUndo::done(sp_desktop_document (dragger->parent->desktop), SP_VERB_CONTEXT_GRADIENT,
+                       _("Move gradient handle"));
 }
 
 /**
@@ -904,15 +949,15 @@ gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data)
     if ( (state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK ) ) {
     // delete this knot from vector
         SPGradient *gradient = sp_item_gradient (draggable->item, draggable->fill_or_stroke);
-        gradient = sp_gradient_get_vector (gradient, false);
+        gradient = gradient->getVector();
         if (gradient->vector.stops.size() > 2) { // 2 is the minimum
             SPStop *stop = NULL;
             switch (draggable->point_type) {  // if we delete first or last stop, move the next/previous to the edge
             case POINT_LG_BEGIN:
             case POINT_RG_CENTER:
-                stop = sp_first_stop(gradient);
+                stop = gradient->getFirstStop();
                 {
-                    SPStop *next = sp_next_stop (stop);
+                    SPStop *next = stop->getNextStop();
                     if (next) {
                         next->offset = 0;
                         sp_repr_set_css_double (SP_OBJECT_REPR (next), "offset", 0);
@@ -924,7 +969,7 @@ gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data)
             case POINT_RG_R2:
                 stop = sp_last_stop(gradient);
                 {
-                    SPStop *prev = sp_prev_stop (stop, gradient);
+                    SPStop *prev = stop->getPrevStop();
                     if (prev) {
                         prev->offset = 1;
                         sp_repr_set_css_double (SP_OBJECT_REPR (prev), "offset", 1);
@@ -939,8 +984,8 @@ gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data)
             }
 
             SP_OBJECT_REPR(gradient)->removeChild(SP_OBJECT_REPR(stop));
-            sp_document_done (SP_OBJECT_DOCUMENT (gradient), SP_VERB_CONTEXT_GRADIENT,
-                      _("Delete gradient stop"));
+            DocumentUndo::done(SP_OBJECT_DOCUMENT (gradient), SP_VERB_CONTEXT_GRADIENT,
+                               _("Delete gradient stop"));
         }
     } else {
     // select the dragger
@@ -1099,7 +1144,7 @@ GrDragger::updateTip ()
 
     if (g_slist_length (this->draggables) == 1) {
         GrDraggable *draggable = (GrDraggable *) this->draggables->data;
-        char *item_desc = sp_item_description(draggable->item);
+        char *item_desc = draggable->item->description();
         switch (draggable->point_type) {
             case POINT_LG_MID:
             case POINT_RG_MID1:
@@ -1622,41 +1667,43 @@ GrDrag::grabKnot (SPItem *item, gint point_type, gint point_i, bool fill_or_stro
 Regenerates the draggers list from the current selection; is called when selection is changed or
 modified, also when a radial dragger needs to update positions of other draggers in the gradient
 */
-void
-GrDrag::updateDraggers ()
+void GrDrag::updateDraggers ()
 {
     while (selected) {
         selected = g_list_remove(selected, selected->data);
     }
     // delete old draggers
     for (GList const* i = this->draggers; i != NULL; i = i->next) {
-        delete ((GrDragger *) i->data);
+        delete static_cast<GrDragger *>(i->data);
     }
-    g_list_free (this->draggers);
+    g_list_free(this->draggers);
     this->draggers = NULL;
 
-    g_return_if_fail (this->selection != NULL);
+    g_return_if_fail(this->selection != NULL);
 
     for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) {
-
         SPItem *item = SP_ITEM(i->data);
-        SPStyle *style = SP_OBJECT_STYLE (item);
+        SPStyle *style = item->style;
 
         if (style && (style->fill.isPaintserver())) {
-            SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
-            if (SP_IS_LINEARGRADIENT (server)) {
-                addDraggersLinear (SP_LINEARGRADIENT (server), item, true);
-            } else if (SP_IS_RADIALGRADIENT (server)) {
-                addDraggersRadial (SP_RADIALGRADIENT (server), item, true);
+            SPPaintServer *server = style->getFillPaintServer();
+            if ( server && server->isSolid() ) {
+                // Suppress "gradientness" of solid paint
+            } else if ( SP_IS_LINEARGRADIENT(server) ) {
+                addDraggersLinear( SP_LINEARGRADIENT(server), item, true );
+            } else if ( SP_IS_RADIALGRADIENT(server) ) {
+                addDraggersRadial( SP_RADIALGRADIENT(server), item, true );
             }
         }
 
         if (style && (style->stroke.isPaintserver())) {
-            SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
-            if (SP_IS_LINEARGRADIENT (server)) {
-                addDraggersLinear (SP_LINEARGRADIENT (server), item, false);
-            } else if (SP_IS_RADIALGRADIENT (server)) {
-                addDraggersRadial (SP_RADIALGRADIENT (server), item, false);
+            SPPaintServer *server = style->getStrokePaintServer();
+            if ( server && server->isSolid() ) {
+                // Suppress "gradientness" of solid paint
+            } else if ( SP_IS_LINEARGRADIENT(server) ) {
+                addDraggersLinear( SP_LINEARGRADIENT(server), item, false );
+            } else if ( SP_IS_RADIALGRADIENT(server) ) {
+                addDraggersRadial( SP_RADIALGRADIENT(server), item, false );
             }
         }
     }
@@ -1701,10 +1748,12 @@ GrDrag::updateLines ()
         SPStyle *style = SP_OBJECT_STYLE (item);
 
         if (style && (style->fill.isPaintserver())) {
-            SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
-            if (SP_IS_LINEARGRADIENT (server)) {
+            SPPaintServer *server = item->style->getFillPaintServer();
+            if ( server && server->isSolid() ) {
+                // Suppress "gradientness" of solid paint
+            } else if ( SP_IS_LINEARGRADIENT(server) ) {
                 this->addLine (item, sp_item_gradient_get_coords (item, POINT_LG_BEGIN, 0, true), sp_item_gradient_get_coords (item, POINT_LG_END, 0, true), GR_LINE_COLOR_FILL);
-            } else if (SP_IS_RADIALGRADIENT (server)) {
+            } else if ( SP_IS_RADIALGRADIENT(server) ) {
                 Geom::Point center = sp_item_gradient_get_coords (item, POINT_RG_CENTER, 0, true);
                 this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R1, 0, true), GR_LINE_COLOR_FILL);
                 this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R2, 0, true), GR_LINE_COLOR_FILL);
@@ -1712,10 +1761,12 @@ GrDrag::updateLines ()
         }
 
         if (style && (style->stroke.isPaintserver())) {
-            SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
-            if (SP_IS_LINEARGRADIENT (server)) {
+            SPPaintServer *server = item->style->getStrokePaintServer();
+            if ( server && server->isSolid() ) {
+                // Suppress "gradientness" of solid paint
+            } else if ( SP_IS_LINEARGRADIENT(server) ) {
                 this->addLine (item, sp_item_gradient_get_coords (item, POINT_LG_BEGIN, 0, false), sp_item_gradient_get_coords (item, POINT_LG_END, 0, false), GR_LINE_COLOR_STROKE);
-            } else if (SP_IS_RADIALGRADIENT (server)) {
+            } else if ( SP_IS_RADIALGRADIENT(server) ) {
                 Geom::Point center = sp_item_gradient_get_coords (item, POINT_RG_CENTER, 0, false);
                 this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R1, 0, false), GR_LINE_COLOR_STROKE);
                 this->addLine (item, center, sp_item_gradient_get_coords (item, POINT_RG_R2, 0, false), GR_LINE_COLOR_STROKE);
@@ -1737,7 +1788,7 @@ GrDrag::updateLevels ()
 
     for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) {
         SPItem *item = SP_ITEM(i->data);
-        Geom::OptRect rect = sp_item_bbox_desktop (item);
+        Geom::OptRect rect = item->getBboxDesktop ();
         if (rect) {
             // Remember the edges of the bbox and the center axis
             hor_levels.push_back(rect->min()[Geom::Y]);
@@ -1816,7 +1867,7 @@ GrDrag::selected_move (double x, double y, bool write_repr, bool scale_radial)
 
     if (write_repr && did) {
         // we did an undoable action
-        sp_document_maybe_done (sp_desktop_document (desktop), "grmoveh", SP_VERB_CONTEXT_GRADIENT,
+        DocumentUndo::maybeDone(sp_desktop_document (desktop), "grmoveh", SP_VERB_CONTEXT_GRADIENT,
                                 _("Move gradient handle(s)"));
         return;
     }
@@ -1852,7 +1903,7 @@ GrDrag::selected_move (double x, double y, bool write_repr, bool scale_radial)
 
         if (write_repr && did) {
             // we did an undoable action
-            sp_document_maybe_done (sp_desktop_document (desktop), "grmovem", SP_VERB_CONTEXT_GRADIENT,
+            DocumentUndo::maybeDone(sp_desktop_document (desktop), "grmovem", SP_VERB_CONTEXT_GRADIENT,
                                     _("Move gradient mid stop(s)"));
         }
     }
@@ -1955,7 +2006,7 @@ GrDrag::deleteSelected (bool just_one)
                     {
                         SPStop *stop = NULL;
                         if ( (draggable->point_type == POINT_LG_BEGIN) || (draggable->point_type == POINT_RG_CENTER) ) {
-                            stop = sp_first_stop(vector);
+                            stop = vector->getFirstStop();
                         } else {
                             stop = sp_last_stop(vector);
                         }
@@ -2000,11 +2051,11 @@ GrDrag::deleteSelected (bool just_one)
         // cannot use vector->vector.stops.size() because the vector might be invalidated by deletion of a midstop
         // manually count the children, don't know if there already exists a function for this...
         int len = 0;
-        for ( SPObject *child = sp_object_first_child(stopinfo->vector) ;
-              child != NULL ;
-              child = SP_OBJECT_NEXT(child) )
+        for ( SPObject *child = (stopinfo->vector)->firstChild() ; child ; child = child->getNext() )
         {
-            if ( SP_IS_STOP(child) )  len ++;
+            if ( SP_IS_STOP(child) ) {
+                len ++;
+            }
         }
         if (len > 2)
         {
@@ -2016,7 +2067,7 @@ GrDrag::deleteSelected (bool just_one)
                         SPLinearGradient *lg = SP_LINEARGRADIENT(stopinfo->gradient);
                         Geom::Point oldbegin = Geom::Point (lg->x1.computed, lg->y1.computed);
                         Geom::Point end = Geom::Point (lg->x2.computed, lg->y2.computed);
-                        SPStop *stop = sp_first_stop(stopinfo->vector);
+                        SPStop *stop = stopinfo->vector->getFirstStop();
                         gdouble offset = stop->offset;
                         Geom::Point newbegin = oldbegin + offset * (end - oldbegin);
                         lg->x1.computed = newbegin[Geom::X];
@@ -2030,11 +2081,11 @@ GrDrag::deleteSelected (bool just_one)
 
                         // iterate through midstops to set new offset values such that they won't move on canvas.
                         SPStop *laststop = sp_last_stop(stopinfo->vector);
-                        stop = sp_next_stop(stop);
+                        stop = stop->getNextStop();
                         while ( stop != laststop ) {
                             stop->offset = (stop->offset - offset)/(1 - offset);
                             sp_repr_set_css_double (SP_OBJECT_REPR (stop), "offset", stop->offset);
-                            stop = sp_next_stop(stop);
+                            stop = stop->getNextStop();
                         }
                     }
                     break;
@@ -2058,18 +2109,18 @@ GrDrag::deleteSelected (bool just_one)
                         sp_repr_set_css_double (SP_OBJECT_REPR (laststop), "offset", 1);
 
                         // iterate through midstops to set new offset values such that they won't move on canvas.
-                        SPStop *stop = sp_first_stop(stopinfo->vector);
-                        stop = sp_next_stop(stop);
+                        SPStop *stop = stopinfo->vector->getFirstStop();
+                        stop = stop->getNextStop();
                         while ( stop != laststop ) {
                             stop->offset = stop->offset / offset;
                             sp_repr_set_css_double (SP_OBJECT_REPR (stop), "offset", stop->offset);
-                            stop = sp_next_stop(stop);
+                            stop = stop->getNextStop();
                         }
                     }
                     break;
                 case POINT_RG_CENTER:
                     {
-                        SPStop *newfirst = sp_next_stop (stopinfo->spstop);
+                        SPStop *newfirst = stopinfo->spstop->getNextStop();
                         if (newfirst) {
                             newfirst->offset = 0;
                             sp_repr_set_css_double (SP_OBJECT_REPR (newfirst), "offset", 0);
@@ -2094,12 +2145,12 @@ GrDrag::deleteSelected (bool just_one)
                         sp_repr_set_css_double (SP_OBJECT_REPR (laststop), "offset", 1);
 
                         // iterate through midstops to set new offset values such that they won't move on canvas.
-                        SPStop *stop = sp_first_stop(stopinfo->vector);
-                        stop = sp_next_stop(stop);
+                        SPStop *stop = stopinfo->vector->getFirstStop();
+                        stop = stop->getNextStop();
                         while ( stop != laststop ) {
                             stop->offset = stop->offset / offset;
                             sp_repr_set_css_double (SP_OBJECT_REPR (stop), "offset", stop->offset);
-                            stop = sp_next_stop(stop);
+                            stop = stop->getNextStop();
                         }
                         break;
             }
@@ -2141,7 +2192,7 @@ GrDrag::deleteSelected (bool just_one)
     }
 
     if (document) {
-        sp_document_done ( document, SP_VERB_CONTEXT_GRADIENT, _("Delete gradient stop(s)") );
+        DocumentUndo::done( document, SP_VERB_CONTEXT_GRADIENT, _("Delete gradient stop(s)") );
     }
 }